This commit is contained in:
WangQiang 2016-08-28 11:44:55 +00:00
parent 32521037ee
commit 828927aca7
2 changed files with 40 additions and 14 deletions

View File

@ -13,8 +13,9 @@ IOK0612* IOK0612::Current = nullptr;
IOK0612::IOK0612() IOK0612::IOK0612()
{ {
//LedPins.Add(PA0);
//LedPins.Add(PA4); //LedPins.Add(PA4);
ButtonPins.Add(PB6);
LedPins.Add(PB7);
LedsShow = false; LedsShow = false;
LedsTaskId = 0; LedsTaskId = 0;
@ -88,10 +89,32 @@ void IOK0612::InitLeds()
} }
} }
void ButtonOnpress(InputPort* port, bool down, void* param)
{
if (port->PressTime > 1000)
IOK0612::OnLongPress(port, down);
}
void IOK0612::InitButtons(InputPort::IOReadHandler press)
{
for (int i = 0; i < ButtonPins.Count(); i++)
{
auto port = new InputPort(ButtonPins[i]);
port->Mode = InputPort::Both;
port->Invert = true;
if (press)
port->Register(press, (void*)i);
else
port->Register(ButtonOnpress, (void*)i);
port->Open();
Buttons.Add(port);
}
}
ISocketHost* IOK0612::Create8266() ISocketHost* IOK0612::Create8266()
{ {
// auto host = new Esp8266(COM2, PB2, PA1); // 触摸开关的 // auto host = new Esp8266(COM2, PB2, PA1); // 触摸开关的
auto host = new Esp8266(COM2, PB2, PA1); auto host = new Esp8266(COM2, PB12, PA1);
// 初次需要指定模式 否则为 Wire // 初次需要指定模式 否则为 Wire
bool join = host->SSID && *host->SSID; bool join = host->SSID && *host->SSID;
@ -343,17 +366,17 @@ void IOK0612::OnLongPress(InputPort* port, bool down)
return; return;
} }
if (time >= 9000 && time < 14000) // if (time >= 9000 && time < 14000)
{ // {
LedStat(!LedsShow); // LedStat(!LedsShow);
return; // return;
} // }
//
if (time >= 14000) // if (time >= 14000)
{ // {
Restore(); // Restore();
return; // return;
} // }
} }
/* /*

View File

@ -14,6 +14,8 @@ class IOK0612
public: public:
List<Pin> LedPins; List<Pin> LedPins;
List<OutputPort*> Leds; List<OutputPort*> Leds;
List<Pin> ButtonPins;
List<InputPort*> Buttons;
bool LedsShow; // LED 显示状态开关 bool LedsShow; // LED 显示状态开关
@ -31,6 +33,7 @@ public:
void InitLeds(); void InitLeds();
void FlushLed(); // 刷新led状态输出 void FlushLed(); // 刷新led状态输出
void InitButtons(InputPort::IOReadHandler press = nullptr);
bool LedStat(bool enable); bool LedStat(bool enable);
@ -41,7 +44,7 @@ public:
void InitAlarm(); void InitAlarm();
void Restore(); void Restore();
void OnLongPress(InputPort* port, bool down); static void OnLongPress(InputPort* port, bool down);
static IOK0612* Current; static IOK0612* Current;