Skip to content

Commit

Permalink
fixed minPulseTime and holdTime
Browse files Browse the repository at this point in the history
  • Loading branch information
mkalkbrenner committed Jan 15, 2024
1 parent cfdc4bd commit 3f6eeaa
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
6 changes: 3 additions & 3 deletions src/EventDispatcher/EventDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions src/IOBoardController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
10 changes: 6 additions & 4 deletions src/IODevices/PwmDevices.cpp
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
16 changes: 8 additions & 8 deletions src/IODevices/PwmDevices.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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};
Expand Down

0 comments on commit 3f6eeaa

Please sign in to comment.