diff --git a/App/PulsePort.cpp b/App/PulsePort.cpp index 9c460c9b..00f871cb 100644 --- a/App/PulsePort.cpp +++ b/App/PulsePort.cpp @@ -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; // 两次脉冲的间隔必须在一个范围内才算作有效 diff --git a/App/PulsePort.h b/App/PulsePort.h index 50a10c7f..6fccc854 100644 --- a/App/PulsePort.h +++ b/App/PulsePort.h @@ -14,6 +14,8 @@ public: uint Min; // 最小时间间隔 单位 ms uint Max; // 最大时间间隔 单位 ms + bool Filter; //是否过滤形脉冲 + UInt64 Start; // 开始遮挡时间 UInt64 Last; // 上一次脉冲时间 uint Time; // 遮挡时间 diff --git a/App/Raster.cpp b/App/Raster.cpp index 3404888d..dc1c57fb 100644 --- a/App/Raster.cpp +++ b/App/Raster.cpp @@ -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; } diff --git a/App/Raster.h b/App/Raster.h index 0677621e..5e5f7c64 100644 --- a/App/Raster.h +++ b/App/Raster.h @@ -43,6 +43,10 @@ public: Raster(Pin pinA, Pin pinB); ~Raster(); + uint Min; // 最小时间间隔 单位 ms + uint Max; // 最大时间间隔 单位 ms + bool Filter = false; //是否过滤脉冲 + bool Open(); Delegate OnReport;