Sys.Delay里面,50us太小,至少1000us才执行调度
This commit is contained in:
parent
acf1971e1d
commit
3e1c8fd6e0
|
@ -1,7 +1,6 @@
|
||||||
#include "Sys.h"
|
#include "Sys.h"
|
||||||
#include "Task.h"
|
#include "Task.h"
|
||||||
#include "Port.h"
|
#include "Port.h"
|
||||||
#include "TTime.h"
|
|
||||||
|
|
||||||
#include "Timer.h"
|
#include "Timer.h"
|
||||||
|
|
||||||
|
@ -197,15 +196,15 @@ bool Button_GrayLevel::GetValue() { return _Value; }
|
||||||
bool CheckZero(InputPort* port)
|
bool CheckZero(InputPort* port)
|
||||||
{
|
{
|
||||||
// 过零检测代码有风险 强制执行喂狗任务确保不出问题
|
// 过零检测代码有风险 强制执行喂狗任务确保不出问题
|
||||||
Task* feeddgtask = Task::Scheduler()->FindTask(WatchDog::FeedDogTask);
|
auto feeddgtask = Task::Scheduler()->FindTask(WatchDog::FeedDogTask);
|
||||||
feeddgtask->Execute(Sys.Ms());
|
feeddgtask->Execute(Sys.Ms());
|
||||||
|
|
||||||
int retry = 200;
|
int retry = 200;
|
||||||
while (*port == false && retry-- > 0) Time.Delay(100); // 检测下降沿 先去掉低电平 while(io==false)
|
while (*port == false && retry-- > 0) Sys.Delay(100); // 检测下降沿 先去掉低电平 while(io==false)
|
||||||
if (retry <= 0) return false;
|
if (retry <= 0) return false;
|
||||||
|
|
||||||
retry = 200;
|
retry = 200;
|
||||||
while (*port == true && retry-- > 0) Time.Delay(100); // 当检测到 高电平结束 就是下降沿的到来
|
while (*port == true && retry-- > 0) Sys.Delay(100); // 当检测到 高电平结束 就是下降沿的到来
|
||||||
if (retry <= 0) return false;
|
if (retry <= 0) return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -217,7 +216,7 @@ void Button_GrayLevel::SetValue(bool value)
|
||||||
|
|
||||||
if (ACZero && ACZero->Opened)
|
if (ACZero && ACZero->Opened)
|
||||||
{
|
{
|
||||||
if (CheckZero(ACZero)) Time.Delay(ACZeroAdjTime);
|
if (CheckZero(ACZero)) Sys.Delay(ACZeroAdjTime);
|
||||||
// 经检测 过零检测电路的信号是 高电平12ms 低电平7ms 即下降沿后8.5ms 是下一个过零点
|
// 经检测 过零检测电路的信号是 高电平12ms 低电平7ms 即下降沿后8.5ms 是下一个过零点
|
||||||
// 从给出信号到继电器吸合 测量得到的时间是 6.4ms 继电器抖动 1ms左右 即 平均在7ms上下
|
// 从给出信号到继电器吸合 测量得到的时间是 6.4ms 继电器抖动 1ms左右 即 平均在7ms上下
|
||||||
// 故这里添加1ms延时
|
// 故这里添加1ms延时
|
||||||
|
|
|
@ -36,9 +36,9 @@ void PulsePort::Open()
|
||||||
{
|
{
|
||||||
if(_Port == nullptr)return;
|
if(_Port == nullptr)return;
|
||||||
if(Handler == nullptr)return;
|
if(Handler == nullptr)return;
|
||||||
|
|
||||||
ShkPulse = ShakeTime/Intervals;
|
ShkPulse = ShakeTime/Intervals;
|
||||||
|
|
||||||
if(Opened)return;
|
if(Opened)return;
|
||||||
_Port->HardEvent = true;
|
_Port->HardEvent = true;
|
||||||
if (!_Port->Register([](InputPort* port, bool down, void* param) {((PulsePort*)param)->OnHandler(port, down); },this))
|
if (!_Port->Register([](InputPort* port, bool down, void* param) {((PulsePort*)param)->OnHandler(port, down); },this))
|
||||||
|
@ -47,23 +47,23 @@ void PulsePort::Open()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_Port->Open();
|
_Port->Open();
|
||||||
|
|
||||||
_task = Sys.AddTask(
|
_task = Sys.AddTask(
|
||||||
[](void* param)
|
[](void* param)
|
||||||
{
|
{
|
||||||
auto port = (PulsePort*)param;
|
auto port = (PulsePort*)param;
|
||||||
|
|
||||||
// 从无到有一定是去抖的结果
|
// 从无到有一定是去抖的结果
|
||||||
// 从有到无一定是超时的结果
|
// 从有到无一定是超时的结果
|
||||||
// 不是去抖的结果 肯定是从有到无
|
// 不是去抖的结果 肯定是从有到无
|
||||||
if(port->ShkStat== false)
|
if(port->ShkStat== false)
|
||||||
port->Value = false;
|
port->Value = false;
|
||||||
|
|
||||||
Sys.SetTask(port->_task,false);
|
Sys.SetTask(port->_task,false);
|
||||||
port->Handler(port,port->Value,port->Param);
|
port->Handler(port,port->Value,port->Param);
|
||||||
},
|
},
|
||||||
this, ShakeTime, ShakeTime, "PulsePort触发任务");
|
this, ShakeTime, ShakeTime, "PulsePort触发任务");
|
||||||
|
|
||||||
Opened = true;
|
Opened = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,15 +86,16 @@ void PulsePort::Register(PulsePortHandler handler, void* param)
|
||||||
|
|
||||||
void PulsePort::OnHandler(InputPort* port,bool down)
|
void PulsePort::OnHandler(InputPort* port,bool down)
|
||||||
{
|
{
|
||||||
if(down)return;
|
if(down) return;
|
||||||
|
|
||||||
// 取UTC时间的MS值
|
// 取UTC时间的MS值
|
||||||
UInt64 now = Sys.Seconds()*1000 + Sys.Ms() - Time.Milliseconds;
|
UInt64 now = Sys.Seconds() * 1000 + Sys.Ms() - Time.Milliseconds;
|
||||||
|
|
||||||
if(Value)
|
if(Value)
|
||||||
{
|
{
|
||||||
LastTriTime = now;
|
LastTriTime = now;
|
||||||
// 有连续脉冲情况下 一定是不用去抖的
|
// 有连续脉冲情况下 一定是不用去抖的
|
||||||
ShkStat = false;
|
ShkStat = false;
|
||||||
// 丢失脉冲,使用定时器来做 如果定时到了 说明中间都没有脉冲
|
// 丢失脉冲,使用定时器来做 如果定时到了 说明中间都没有脉冲
|
||||||
if(_task)Sys.SetTask(_task, true, ShakeTime);
|
if(_task)Sys.SetTask(_task, true, ShakeTime);
|
||||||
}
|
}
|
||||||
|
@ -103,9 +104,9 @@ void PulsePort::OnHandler(InputPort* port,bool down)
|
||||||
// 丢失脉冲后 重新来脉冲需要考虑 去抖 (也许是干扰脉冲)
|
// 丢失脉冲后 重新来脉冲需要考虑 去抖 (也许是干扰脉冲)
|
||||||
if(!ShkStat) // 断掉脉冲 && Shake去抖没开始
|
if(!ShkStat) // 断掉脉冲 && Shake去抖没开始
|
||||||
{
|
{
|
||||||
ShkTmeStar = now;
|
ShkTmeStar = now;
|
||||||
ShkStat = true;
|
ShkStat = true;
|
||||||
ShkCnt = 1;
|
ShkCnt = 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -107,15 +107,15 @@ void AP0801::InitButtons(InputPort::IOReadHandler press)
|
||||||
{
|
{
|
||||||
for (int i = 0; i<ButtonPins.Count(); i++)
|
for (int i = 0; i<ButtonPins.Count(); i++)
|
||||||
{
|
{
|
||||||
auto port = new InputPort(ButtonPins[i]);
|
auto btn = new InputPort(ButtonPins[i]);
|
||||||
port->Mode = InputPort::Both;
|
btn->Mode = InputPort::Both;
|
||||||
port->Invert = true;
|
btn->Invert = true;
|
||||||
if (press)
|
if (press)
|
||||||
port->Register(press, (void*)i);
|
btn->Register(press, (void*)i);
|
||||||
else
|
else
|
||||||
port->Register(ButtonOnpress, (void*)i);
|
btn->Register(ButtonOnpress, (void*)i);
|
||||||
port->Open();
|
btn->Open();
|
||||||
Buttons.Add(port);
|
Buttons.Add(btn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,7 +194,7 @@ void AP0801::InitClient()
|
||||||
tc->Register("Gateway/SetRemote", &TokenClient::InvokeSetRemote, tc);
|
tc->Register("Gateway/SetRemote", &TokenClient::InvokeSetRemote, tc);
|
||||||
// 获取远程配置信息
|
// 获取远程配置信息
|
||||||
tc->Register("Gateway/GetRemote", &TokenClient::InvokeGetRemote, tc);
|
tc->Register("Gateway/GetRemote", &TokenClient::InvokeGetRemote, tc);
|
||||||
// 获取所有Ivoke命令
|
// 获取所有Invoke命令
|
||||||
tc->Register("Api/All", &TokenClient::InvokeGetAllApi, tc);
|
tc->Register("Api/All", &TokenClient::InvokeGetAllApi, tc);
|
||||||
|
|
||||||
if(Data && Size > 0)
|
if(Data && Size > 0)
|
||||||
|
@ -203,6 +203,8 @@ void AP0801::InitClient()
|
||||||
ds.Data.Set(Data, Size);
|
ds.Data.Set(Data, Size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tc->UseLocal();
|
||||||
|
|
||||||
// 如果若干分钟后仍然没有打开令牌客户端,则重启系统
|
// 如果若干分钟后仍然没有打开令牌客户端,则重启系统
|
||||||
Sys.AddTask(
|
Sys.AddTask(
|
||||||
[](void* p){
|
[](void* p){
|
||||||
|
|
|
@ -207,7 +207,7 @@ void TSys::Delay(uint us) const
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// 在这段时间里面,去处理一下别的任务
|
// 在这段时间里面,去处理一下别的任务
|
||||||
if(Sys.Started && us != 0 && us >= 50)
|
if(Sys.Started && us != 0 && us >= 1000)
|
||||||
{
|
{
|
||||||
bool cancel = false;
|
bool cancel = false;
|
||||||
auto ct = Task::Scheduler()->ExecuteForWait(us / 1000, cancel);
|
auto ct = Task::Scheduler()->ExecuteForWait(us / 1000, cancel);
|
||||||
|
|
Loading…
Reference in New Issue