增加光栅指示灯功能
This commit is contained in:
parent
714273f0fc
commit
c7f3052bd3
|
@ -1,4 +1,5 @@
|
||||||
#include "IOK0612.h"
|
#include "IOK0612.h"
|
||||||
|
#include "Drivers\Esp8266\Esp8266.h"
|
||||||
|
|
||||||
IOK0612* IOK0612::Current = nullptr;
|
IOK0612* IOK0612::Current = nullptr;
|
||||||
|
|
||||||
|
@ -6,7 +7,7 @@ IOK0612::IOK0612()
|
||||||
{
|
{
|
||||||
LedPins.Clear();
|
LedPins.Clear();
|
||||||
ButtonPins.Clear();
|
ButtonPins.Clear();
|
||||||
LedPins.Add(PB7);
|
LedPins.Add(PB10);
|
||||||
ButtonPins.Add(PB6);
|
ButtonPins.Add(PB6);
|
||||||
|
|
||||||
Esp.Com = COM2;
|
Esp.Com = COM2;
|
||||||
|
@ -17,7 +18,90 @@ IOK0612::IOK0612()
|
||||||
|
|
||||||
Current = this;
|
Current = this;
|
||||||
}
|
}
|
||||||
|
static bool ledstat2 = false;
|
||||||
|
|
||||||
|
//重写指示灯默认倒置
|
||||||
|
void IOK0612::InitLeds()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < LedPins.Count(); i++)
|
||||||
|
{
|
||||||
|
auto port = new OutputPort(LedPins[i], LedInvert);
|
||||||
|
//auto port = new OutputPort(LedPins[i], false);
|
||||||
|
port->Open();
|
||||||
|
port->Write(false);
|
||||||
|
Leds.Add(port);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void IOK0612::FlushLed()
|
||||||
|
{
|
||||||
|
if (LedsShow == 0) // 启动时候20秒
|
||||||
|
{
|
||||||
|
auto esp = dynamic_cast<Esp8266*>(Host);
|
||||||
|
if (esp && esp->Linked) // 8266 初始化完成 且 连接完成
|
||||||
|
{
|
||||||
|
Sys.SetTaskPeriod(LedsTaskId, 500); // 慢闪
|
||||||
|
}
|
||||||
|
|
||||||
|
Leds[0]->Write(ledstat2);
|
||||||
|
ledstat2 = !ledstat2;
|
||||||
|
|
||||||
|
if (Sys.Ms() > 20000)
|
||||||
|
{
|
||||||
|
Leds[0]->Write(false);
|
||||||
|
LedsShow = 2; // 置为无效状态
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool stat = false;
|
||||||
|
// 3分钟内 Client还活着则表示 联网OK
|
||||||
|
if (Client && Client->LastActive + 180000 > Sys.Ms() && LedsShow == 1)stat = true;
|
||||||
|
Leds[1]->Write(stat);
|
||||||
|
if (LedsShow == 2)Sys.SetTask(LedsTaskId, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
byte IOK0612::LedStat(byte showmode)
|
||||||
|
{
|
||||||
|
auto esp = dynamic_cast<Esp8266*>(Host);
|
||||||
|
if (esp)
|
||||||
|
{
|
||||||
|
if (showmode == 1)
|
||||||
|
{
|
||||||
|
esp->RemoveLed();
|
||||||
|
esp->SetLed(*Leds[0]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
esp->RemoveLed();
|
||||||
|
// 维护状态为false
|
||||||
|
Leds[0]->Write(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showmode != 2)
|
||||||
|
{
|
||||||
|
if (!LedsTaskId)
|
||||||
|
{
|
||||||
|
LedsTaskId = Sys.AddTask(&IOK0612::FlushLed, this, 500, 100, "CltLedStat");
|
||||||
|
debug_printf("AddTask(IOK027X:FlushLed)\r\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Sys.SetTask(LedsTaskId, true);
|
||||||
|
if (showmode == 1)Sys.SetTaskPeriod(LedsTaskId, 500);
|
||||||
|
}
|
||||||
|
LedsShow = showmode;
|
||||||
|
}
|
||||||
|
if (showmode == 2)
|
||||||
|
{
|
||||||
|
// 由任务自己结束,顺带维护输出状态为false
|
||||||
|
// if (LedsTaskId)Sys.SetTask(LedsTaskId, false);
|
||||||
|
LedsShow = 2;
|
||||||
|
|
||||||
|
}
|
||||||
|
return LedsShow;
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
NRF24L01+ (SPI3)
|
NRF24L01+ (SPI3)
|
||||||
NSS |
|
NSS |
|
||||||
|
|
|
@ -7,7 +7,13 @@
|
||||||
class IOK0612 : public B8266
|
class IOK0612 : public B8266
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
byte LedsShow; // LED 显示状态开关 0 刚启动时候的20秒 1 使能 2 失能
|
||||||
|
uint LedsTaskId;
|
||||||
|
|
||||||
IOK0612();
|
IOK0612();
|
||||||
|
void InitLeds();
|
||||||
|
void FlushLed(); // 刷新led状态输出
|
||||||
|
byte LedStat(byte showmode);
|
||||||
|
|
||||||
static IOK0612* Current;
|
static IOK0612* Current;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue