Skip to content

Commit

Permalink
Fixing timing of events in LED events aggregator.
Browse files Browse the repository at this point in the history
  • Loading branch information
krulis-martin committed Feb 23, 2024
1 parent a2deacc commit 39176a0
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions shared/led_display.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,11 @@ class LedsEventsAggregator : public EventConsumer<BitArray<LEDS>>
*/
state_t mLastState;

/**
* Time when the last state was recorded.
*/
logtime_t mLastStateTime;

/**
* Last state emitted to the next consumer.
*/
Expand Down Expand Up @@ -506,9 +511,8 @@ class LedsEventsAggregator : public EventConsumer<BitArray<LEDS>>
mLastEmittedState = mLastState;
if (this->nextConsumer() != nullptr) {
// emit event for following consumers
this->nextConsumer()->addEvent(mNextMarker, mLastEmittedState);
this->nextConsumer()->addEvent(mLastStateTime, mLastEmittedState);
}
mNextMarker += mTimeWindow; // time window shifts one place
}
else if (this->nextConsumer() != nullptr) {
// advance time for the following consumer
Expand All @@ -522,10 +526,13 @@ class LedsEventsAggregator : public EventConsumer<BitArray<LEDS>>
void doAddEvent(logtime_t time, state_t state) override
{
updateOpenedWindow(time); // update, possibly close current window
mLastState = state;
if (!isWindowOpen()) {
// the event triggers opening of a new window
mNextMarker = time + mTimeWindow;
if (mLastState != state) {
mLastState = state;
mLastStateTime = time; // the state actually changed, record when
if (!isWindowOpen()) {
// the event triggers opening of a new window
mNextMarker = time + mTimeWindow;
}
}
}

Expand All @@ -542,6 +549,7 @@ class LedsEventsAggregator : public EventConsumer<BitArray<LEDS>>
{
mNextMarker = this->mLastTime;
mLastState.fill(OFF);
mLastStateTime = this->mLastTime;
mLastEmittedState.fill(OFF);
EventConsumer<BitArray<LEDS>>::doClear();
}
Expand All @@ -554,6 +562,7 @@ class LedsEventsAggregator : public EventConsumer<BitArray<LEDS>>
mTimeWindow(timeWindow),
mNextMarker(0),
mLastState(OFF),
mLastStateTime(0),
mLastEmittedState(OFF)
{
if (mTimeWindow == 0) {
Expand Down

0 comments on commit 39176a0

Please sign in to comment.