改进数据区使用方式,优化阿波罗系列

This commit is contained in:
大石头 2017-03-27 16:00:44 +08:00
parent e2895f841b
commit dad33f88f5
9 changed files with 74 additions and 30 deletions

View File

@ -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);
}
}

View File

@ -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();

View File

@ -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()

View File

@ -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();

View File

@ -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;

View File

@ -40,8 +40,6 @@ public:
NetworkInterface* Create8266();
void SetStore(void* data, int len);
void InitClient();
void InitNet();
void InitAlarm();

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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);