改进数据区使用方式,优化阿波罗系列
This commit is contained in:
parent
e2895f841b
commit
dad33f88f5
|
@ -96,11 +96,14 @@ void* AP0801::InitData(void* data, int size)
|
|||
return data;
|
||||
}
|
||||
|
||||
void AP0801::SetStore(void*data, int len)
|
||||
// 写入数据区并上报
|
||||
void AP0801::Write(uint offset, byte data)
|
||||
{
|
||||
if (!Client)return;
|
||||
auto client = Client;
|
||||
if (!client) return;
|
||||
|
||||
Client->Store.Data.Set(data, len);
|
||||
client->Store.Write(offset, data);
|
||||
client->ReportAsync(offset, 1);
|
||||
}
|
||||
|
||||
void AP0801::InitLeds()
|
||||
|
@ -123,13 +126,14 @@ void AP0801::InitButtons(const Delegate2<InputPort&, bool>& press)
|
|||
{
|
||||
for (int i = 0; i < ButtonPins.Count(); i++)
|
||||
{
|
||||
auto port = new InputPort(ButtonPins[i]);
|
||||
port->Invert = true;
|
||||
port->ShakeTime = 40;
|
||||
auto port = new InputPort();
|
||||
port->Index = i;
|
||||
port->Init(ButtonPins[i], true);
|
||||
//port->ShakeTime = 40;
|
||||
port->Press = press;
|
||||
port->UsePress();
|
||||
port->Open();
|
||||
|
||||
Buttons.Add(port);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,8 +35,8 @@ public:
|
|||
|
||||
// 设置数据区
|
||||
void* InitData(void* data, int size);
|
||||
// 设置TokenClient数据区
|
||||
void SetStore(void*data, int len);
|
||||
// 写入数据区并上报
|
||||
void Write(uint offset, byte data);
|
||||
//获取客户端的状态0,未握手,1已握手,2已经登陆
|
||||
int GetStatus();
|
||||
|
||||
|
|
|
@ -85,11 +85,14 @@ void* AP0803::InitData(void* data, int size)
|
|||
return data;
|
||||
}
|
||||
|
||||
void AP0803::SetStore(void*data, int len)
|
||||
// 写入数据区并上报
|
||||
void AP0803::Write(uint offset, byte data)
|
||||
{
|
||||
if (!Client)return;
|
||||
auto client = Client;
|
||||
if (!client) return;
|
||||
|
||||
Client->Store.Data.Set(data, len);
|
||||
client->Store.Write(offset, data);
|
||||
client->ReportAsync(offset, 1);
|
||||
}
|
||||
|
||||
void AP0803::InitLeds()
|
||||
|
|
|
@ -28,8 +28,8 @@ public:
|
|||
|
||||
// 设置数据区
|
||||
void* InitData(void* data, int size);
|
||||
// 设置TokenClient数据区
|
||||
void SetStore(void*data, int len);
|
||||
// 写入数据区并上报
|
||||
void Write(uint offset, byte data);
|
||||
//获取客户端的状态0,未握手,1已握手,2已经登陆
|
||||
int GetStatus();
|
||||
|
||||
|
|
|
@ -149,12 +149,6 @@ NetworkInterface* NH3_0317::Create8266()
|
|||
|
||||
/******************************** Token ********************************/
|
||||
|
||||
void NH3_0317::SetStore(void*data, int len)
|
||||
{
|
||||
if (!Client)return;
|
||||
Client->Store.Data.Set(data, len);
|
||||
}
|
||||
|
||||
void NH3_0317::InitClient()
|
||||
{
|
||||
if (Client) return;
|
||||
|
|
|
@ -40,8 +40,6 @@ public:
|
|||
|
||||
NetworkInterface* Create8266();
|
||||
|
||||
void SetStore(void* data, int len);
|
||||
|
||||
void InitClient();
|
||||
void InitNet();
|
||||
void InitAlarm();
|
||||
|
|
|
@ -76,6 +76,16 @@ void* PA0903::InitData(void* data, int size)
|
|||
return data;
|
||||
}
|
||||
|
||||
// 写入数据区并上报
|
||||
void PA0903::Write(uint offset, byte data)
|
||||
{
|
||||
auto client = Client;
|
||||
if (!client) return;
|
||||
|
||||
client->Store.Write(offset, data);
|
||||
client->ReportAsync(offset, 1);
|
||||
}
|
||||
|
||||
void PA0903::InitLeds()
|
||||
{
|
||||
for (int i = 0; i < LedPins.Count(); i++)
|
||||
|
@ -86,6 +96,22 @@ void PA0903::InitLeds()
|
|||
}
|
||||
}
|
||||
|
||||
void PA0903::InitButtons(const Delegate2<InputPort&, bool>& press)
|
||||
{
|
||||
for (int i = 0; i < ButtonPins.Count(); i++)
|
||||
{
|
||||
auto port = new InputPort();
|
||||
port->Index = i;
|
||||
port->Init(ButtonPins[i], true);
|
||||
//port->ShakeTime = 40;
|
||||
port->Press = press;
|
||||
port->UsePress();
|
||||
port->Open();
|
||||
|
||||
Buttons.Add(port);
|
||||
}
|
||||
}
|
||||
|
||||
NetworkInterface* PA0903::Create5500()
|
||||
{
|
||||
debug_printf("\r\nW5500::Create \r\n");
|
||||
|
@ -226,4 +252,22 @@ void PA0903::Restore()
|
|||
if (Client) Client->Reset("按键重置");
|
||||
}
|
||||
|
||||
//auto host = (W5500*)Create5500(Spi1, PA8, PA0, led);
|
||||
|
||||
void PA0903::OnLongPress(InputPort* port, bool down)
|
||||
{
|
||||
if (down) return;
|
||||
|
||||
debug_printf("Press P%c%d Time=%d ms\r\n", _PIN_NAME(port->_Pin), port->PressTime);
|
||||
|
||||
ushort time = port->PressTime;
|
||||
auto client = Client;
|
||||
if (time >= 5000 && time < 10000)
|
||||
{
|
||||
if (client) client->Reset("按键重置");
|
||||
}
|
||||
else if (time >= 3000)
|
||||
{
|
||||
if (client) client->Reboot("按键重启");
|
||||
Sys.Reboot(1000);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,13 +14,12 @@ class PA0903
|
|||
{
|
||||
public:
|
||||
List<Pin> LedPins;
|
||||
List<Pin> ButtonPins;
|
||||
List<OutputPort*> Leds;
|
||||
List<InputPort*> Buttons;
|
||||
|
||||
//List<Pin> ButtonPins;
|
||||
//List<InputPort*> Buttons;
|
||||
|
||||
List<OutputPort*> Outputs;
|
||||
List<InputPort*> Inputs;
|
||||
//List<OutputPort*> Outputs;
|
||||
//List<InputPort*> Inputs;
|
||||
|
||||
ProxyFactory* ProxyFac; // 透传管理器
|
||||
Alarm* AlarmObj;
|
||||
|
@ -32,11 +31,12 @@ public:
|
|||
|
||||
// 设置数据区
|
||||
void* InitData(void* data, int size);
|
||||
// 写入数据区并上报
|
||||
void Write(uint offset, byte data);
|
||||
void Register(int index, IDataPort& dp);
|
||||
|
||||
void InitLeds();
|
||||
//void InitButtons();
|
||||
//void InitPort();
|
||||
void InitButtons(const Delegate2<InputPort&, bool>& press);
|
||||
|
||||
// 打开以太网W5500
|
||||
NetworkInterface* Create5500();
|
||||
|
@ -51,7 +51,7 @@ public:
|
|||
void InitAlarm();
|
||||
|
||||
void Restore();
|
||||
//void OnLongPress(InputPort* port, bool down);
|
||||
void OnLongPress(InputPort* port, bool down);
|
||||
|
||||
static PA0903* Current;
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ public:
|
|||
|
||||
// 写入数据 offset 为虚拟地址
|
||||
int Write(uint offset, const Buffer& bs);
|
||||
int Write(uint offset, byte data) { return Write(offset, Buffer(&data, 1)); }
|
||||
// 读取数据 offset 为虚拟地址
|
||||
int Read(uint offset, Buffer& bs);
|
||||
|
||||
|
|
Loading…
Reference in New Issue