端口类继承Object,提供ToString支持

数据操作通过ToString获取名称
Zigbee门窗磁测试通过
This commit is contained in:
nnhy 2015-09-28 12:25:08 +00:00
parent 4938b8edc8
commit 1a8cee5e9d
5 changed files with 24 additions and 2 deletions

View File

@ -40,7 +40,7 @@ public:
public:
// 构造函数。指示灯和继电器一般开漏输出,需要倒置
Button_GrayLevel();
~Button_GrayLevel();
virtual ~Button_GrayLevel();
void Set(Pin key, Pin relay = P0, bool relayInvert = true);
void Set(Pin key, Pin relay);

View File

@ -181,7 +181,10 @@ int ByteDataPort::Write(byte* data)
//Show(true);
Object* obj = dynamic_cast<Object*>(this);
if(obj)
{
debug_printf(" ");
obj->Show(true);
}
else
debug_printf("\r\n");
#endif

View File

@ -82,7 +82,7 @@ protected:
#include "Port.h"
// 数据输出口
class DataOutputPort : public ByteDataPort
class DataOutputPort : public ByteDataPort, public Object
{
public:
OutputPort* Port;
@ -92,6 +92,8 @@ public:
protected:
virtual int OnWrite(byte data) { Port->Write(data); return OnRead(); };
virtual byte OnRead() { return Port->Read() ? 1 : 0; };
virtual String& ToStr(String& str) const { return Port->ToStr(str); }
};
#endif

View File

@ -33,6 +33,21 @@ Port::~Port()
Close();
}
String& Port::ToStr(String& str) const
{
str.SetAt(0, 'P');
if(_Pin == P0)
{
str.SetAt(1, '0');
}
else
{
str.SetAt(1, 'A' + (_Pin >> 4));
str.Append(_Pin & 0x0F);
}
return str;
}
// 单一引脚初始化
Port& Port::Set(Pin pin)
{

2
Port.h
View File

@ -42,6 +42,8 @@ public:
static bool IsBusy(Pin pin); // 引脚是否被保护
#endif
virtual String& ToStr(String& str) const;
protected:
Port();
virtual ~Port();