调整脉冲触发条件

This commit is contained in:
cdyong 2016-10-31 09:33:17 +00:00
parent 39e3b045d3
commit bece991bb4
4 changed files with 29 additions and 9 deletions

View File

@ -21,7 +21,7 @@ PulsePort::~PulsePort()
static void OnPressTask(void* param)
{
auto port = (PulsePort*)param;
auto port = (PulsePort*)param;
port->Press(*port);
}
@ -32,7 +32,7 @@ void PulsePort::Open()
if (!Port) return;
// 如果使用了硬件事件,则这里使用任务来触发外部事件
if(Port->HardEvent) _task = Sys.AddTask(OnPressTask, this, -1, -1,"脉冲事件");
if (Port->HardEvent) _task = Sys.AddTask(OnPressTask, this, -1, -1, "脉冲事件");
Port->HardEvent = true;
Port->Press.Bind(&PulsePort::OnPress, this);
@ -65,8 +65,15 @@ void PulsePort::OnPress(InputPort& port, bool down)
return;
}
// 计算上一次脉冲以来的遮挡时间,两个有效脉冲的间隔
auto st = Last;
auto time = (uint)(now - st);
auto st = Last;
uint time = 0;
//过滤形状的光栅需要两个信号的时间差
if (Filter)
time = (uint)(now - st);
else
time = port.PressTime;
// 无论如何都更新最后一次时间,避免连续超长
Last = now;
// 两次脉冲的间隔必须在一个范围内才算作有效

View File

@ -14,6 +14,8 @@ public:
uint Min; // 最小时间间隔 单位 ms
uint Max; // 最大时间间隔 单位 ms
bool Filter; //是否过滤形脉冲
UInt64 Start; // 开始遮挡时间
UInt64 Last; // 上一次脉冲时间
uint Time; // 遮挡时间

View File

@ -8,13 +8,14 @@ static Stream* _Cache = nullptr; //实际送的数据
static uint _RasterTask = 0;
static int _Ras = 0;
static PulsePort* Create(Pin pin)
static PulsePort* Create(Pin pin, uint min, uint max, bool filter)
{
auto pp = new PulsePort();
pp->Port = new InputPort(pin);
pp->Port->HardEvent = true;
pp->Min = 100;
pp->Max = 2000;
pp->Min = min;
pp->Max = max;
pp->Filter = filter;
return pp;
}
@ -23,8 +24,9 @@ Raster::Raster(Pin pinA, Pin pinB)
{
Init();
RasterA = Create(pinA);
RasterB = Create(pinB);
RasterA = Create(pinA, Min, Max, Filter);
RasterB = Create(pinB, Min, Max, Filter);
_Ras++;
}
@ -57,6 +59,11 @@ void Raster::Init()
FlagA.Time = 0;
FlagA.Count = 0;
Min = 100; // 最小时间间隔 单位 ms
Max = 2000; // 最大时间间隔 单位 ms
Filter = false;
Count = 0;
}

View File

@ -43,6 +43,10 @@ public:
Raster(Pin pinA, Pin pinB);
~Raster();
uint Min; // 最小时间间隔 单位 ms
uint Max; // 最大时间间隔 单位 ms
bool Filter = false; //是否过滤脉冲
bool Open();
Delegate<Stream&> OnReport;