From 3f6eeaad92624d6aceafffa079670d51194be1f6 Mon Sep 17 00:00:00 2001 From: Markus Kalkbrenner Date: Mon, 15 Jan 2024 18:30:10 +0100 Subject: [PATCH] fixed minPulseTime and holdTime --- src/EventDispatcher/EventDispatcher.cpp | 6 +++--- src/IOBoardController.h | 6 +++--- src/IODevices/PwmDevices.cpp | 10 ++++++---- src/IODevices/PwmDevices.h | 16 ++++++++-------- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/EventDispatcher/EventDispatcher.cpp b/src/EventDispatcher/EventDispatcher.cpp index f172498..3e43a56 100644 --- a/src/EventDispatcher/EventDispatcher.cpp +++ b/src/EventDispatcher/EventDispatcher.cpp @@ -191,9 +191,9 @@ void EventDispatcher::update() { byte topic = hwSerial[i]->read(); byte index = hwSerial[i]->read(); byte key = hwSerial[i]->read(); - int value = (hwSerial[i]->read() << 24) + - (hwSerial[i]->read() << 16) + - (hwSerial[i]->read() << 8) + hwSerial[i]->read(); + uint32_t value = (((uint32_t)hwSerial[i]->read()) << 24) + + (((uint32_t)hwSerial[i]->read()) << 16) + + (((uint32_t)hwSerial[i]->read()) << 8) + hwSerial[i]->read(); byte stopByte = hwSerial[i]->read(); if (stopByte == 0b10101010) { stopByte = hwSerial[i]->read(); diff --git a/src/IOBoardController.h b/src/IOBoardController.h index bfa26a9..24c4bc2 100644 --- a/src/IOBoardController.h +++ b/src/IOBoardController.h @@ -58,10 +58,10 @@ class IOBoardController : public EventListener { byte port = 0; byte number = 0; byte power = 0; - byte minPulseTime = 0; - byte maxPulseTime = 0; + uint16_t minPulseTime = 0; + uint16_t maxPulseTime = 0; byte holdPower = 0; - byte holdPowerActivationTime = 0; + uint16_t holdPowerActivationTime = 0; byte fastSwitch = 0; byte type = 0; diff --git a/src/IODevices/PwmDevices.cpp b/src/IODevices/PwmDevices.cpp index 6e40f3a..a79c320 100644 --- a/src/IODevices/PwmDevices.cpp +++ b/src/IODevices/PwmDevices.cpp @@ -1,7 +1,8 @@ #include "PwmDevices.h" -void PwmDevices::registerSolenoid(byte p, byte n, byte pow, byte minPT, - byte maxPT, byte hP, byte hPAT, byte fS) { +void PwmDevices::registerSolenoid(byte p, byte n, byte pow, uint16_t minPT, + uint16_t maxPT, byte hP, uint16_t hPAT, + byte fS) { if (last < MAX_PWM_OUTPUTS) { port[last] = p; number[last] = n; @@ -71,7 +72,8 @@ void PwmDevices::update() { for (byte i = 0; i < last; i++) { if (activated[i] > 0) { // The output is active. - if ((scheduled[i] && ((_ms - activated[i]) > minPulseTime[i])) || + if ((scheduled[i] && (minPulseTime[i] > 0) && + ((_ms - activated[i]) > minPulseTime[i])) || ((maxPulseTime[i] > 0) && ((_ms - activated[i]) > maxPulseTime[i]))) { // Deactivate the output if it is scheduled for delayed deactivation and // the minimum pulse time is reached. Deactivate the output if the @@ -101,7 +103,7 @@ void PwmDevices::updateSolenoidOrFlasher(bool targetState, byte i) { } else if (!targetState && activated[i] > 0) { // Event received to deactivate the output. // Check if a minimum pulse time is configured for this output. - if (_ms > activated[i] && minPulseTime[i] > 0 && + if ((_ms >= activated[i]) && (minPulseTime[i] > 0) && (_ms - activated[i]) < minPulseTime[i]) { // A minimum pulse time is configured for this output. // Don't deactivate it immediately but schedule its later deactivation. diff --git a/src/IODevices/PwmDevices.h b/src/IODevices/PwmDevices.h index db75e3c..f7d034a 100644 --- a/src/IODevices/PwmDevices.h +++ b/src/IODevices/PwmDevices.h @@ -25,13 +25,13 @@ class PwmDevices : public EventListener { eventDispatcher->addListener(this, EVENT_SOURCE_SWITCH); // Adjust PWM properties if needed. - //analogWriteFreq(5000); - //analogWriteRange(65535); - //analogWriteResolution(16); + // analogWriteFreq(5000); + // analogWriteRange(65535); + // analogWriteResolution(16); } - void registerSolenoid(byte p, byte n, byte pow, byte minPT, byte maxPT, - byte hP, byte hPAT, byte fS); + void registerSolenoid(byte p, byte n, byte pow, uint16_t minPT, + uint16_t maxPT, byte hP, uint16_t hPAT, byte fS); void registerFlasher(byte p, byte n, byte pow); void registerLamp(byte p, byte n, byte pow); @@ -48,10 +48,10 @@ class PwmDevices : public EventListener { byte port[MAX_PWM_OUTPUTS] = {0}; byte number[MAX_PWM_OUTPUTS] = {0}; byte power[MAX_PWM_OUTPUTS] = {0}; - byte minPulseTime[MAX_PWM_OUTPUTS] = {0}; - byte maxPulseTime[MAX_PWM_OUTPUTS] = {0}; + uint16_t minPulseTime[MAX_PWM_OUTPUTS] = {0}; + uint16_t maxPulseTime[MAX_PWM_OUTPUTS] = {0}; byte holdPower[MAX_PWM_OUTPUTS] = {0}; - byte holdPowerActivationTime[MAX_PWM_OUTPUTS] = {0}; + uint16_t holdPowerActivationTime[MAX_PWM_OUTPUTS] = {0}; byte fastSwitch[MAX_PWM_OUTPUTS] = {0}; byte type[MAX_PWM_OUTPUTS] = {0}; unsigned long activated[MAX_PWM_OUTPUTS] = {0};