Skip to content

Commit

Permalink
WOW bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
rusefillc committed May 4, 2024
1 parent 54a34f5 commit e256e77
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
23 changes: 18 additions & 5 deletions digital-inputs/firmware/can.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ bool isHappyCanTest() {
static void handleCounter(Counter *cnt, bool *isHappy, bool *eventExpected, const char *suffix) {
if (!eventExpected[cnt->canFrameIndex])
return;
if (cnt->nonZero) {
if (cnt->isHappy()) {
setGreenText();
chprintf(chp, "* HAPPY %s %s counter!\r\n", cnt->name, suffix);
setNormalText();
Expand All @@ -91,7 +91,7 @@ static void handleCounter(Counter *cnt, bool *isHappy, bool *eventExpected, cons
chprintf(chp, "* ZERO %s %s counter!\r\n", cnt->name, suffix);
setNormalText();
}
*isHappy = *isHappy && cnt->nonZero;
*isHappy = *isHappy && cnt->isHappy();
}

bool checkDigitalInputCounterStatus() {
Expand Down Expand Up @@ -221,21 +221,34 @@ static void receiveRawAnalog(const uint8_t msg[CAN_FRAME_SIZE], size_t offset) {
}
}

bool Counter::isHappy() const {
return seenTwoDifferentNonZeroValue;
}

void Counter::applyNewValue(int value) {
if (firstNonZeroValue == 0 && value != 0) {
firstNonZeroValue = value;
}
if (value != 0 && firstNonZeroValue != 0 && value != firstNonZeroValue) {
seenTwoDifferentNonZeroValue = true;
}
}

static void receiveEventCounters(const uint8_t msg[CAN_FRAME_SIZE]) {
for (auto & evtCnt : counterStatus.eventCounters) {
evtCnt.nonZero = evtCnt.nonZero || (msg[evtCnt.canFrameIndex] > 0);
evtCnt.applyNewValue(msg[evtCnt.canFrameIndex]);
}
}

static void receiveButtonCounters(const uint8_t msg[CAN_FRAME_SIZE]) {
for (auto & btnCnt : counterStatus.buttonCounters) {
btnCnt.nonZero = btnCnt.nonZero || (msg[btnCnt.canFrameIndex] > 0);
btnCnt.applyNewValue(msg[btnCnt.canFrameIndex]);
}
}

static void receiveAuxDigitalCounters(const uint8_t msg[CAN_FRAME_SIZE]) {
for (auto & cnt : counterStatus.auxDigitalCounters) {
cnt.nonZero = cnt.nonZero || (msg[cnt.canFrameIndex] > 0);
cnt.applyNewValue(msg[cnt.canFrameIndex]);
}
}

Expand Down
5 changes: 4 additions & 1 deletion digital-inputs/firmware/test_logic.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ class Counter {
public:
int canFrameIndex;
const char *name;
bool nonZero = false;
bool seenTwoDifferentNonZeroValue = false;
int firstNonZeroValue = 0;
bool isHappy() const;
void applyNewValue(int value);
};

#define EVENT_ENUM_SIZE 7
Expand Down

0 comments on commit e256e77

Please sign in to comment.