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延时
|
||||||
|
|
|
@ -86,9 +86,10 @@ 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)
|
||||||
{
|
{
|
||||||
|
|
|
@ -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