Skip to content

Commit

Permalink
Update to activity LED flashing to hopefully fix crach in esp_timer r…
Browse files Browse the repository at this point in the history
…eported in issue ratgdo#30
  • Loading branch information
dkerr64 committed Jan 7, 2025
1 parent 0b952d3 commit e4f7d7a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
16 changes: 8 additions & 8 deletions src/led.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@
LED led(LED_BUILTIN);
LED laser(LASER_PIN);

void LEDtimerCallback(LED *led)
{
led->idle();
}

// Constructor for LED class
LED::LED(uint8_t gpio_num, uint8_t state)
{
Expand Down Expand Up @@ -74,8 +69,13 @@ void LED::setIdleState(uint8_t state)
}
}

void LED::flash(unsigned long ms)
void LED::flash(uint64_t ms)
{
digitalWrite(pin, activeState);
LEDtimer.once_ms(ms, LEDtimerCallback, this);
if (!LEDtimer.active())
{
// Don't flash if we are already in a flash.
digitalWrite(pin, activeState);
LEDtimer.once_ms(ms, [this]()
{ this->idle(); });
}
}
2 changes: 1 addition & 1 deletion src/led.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class LED
void off();
void idle();
bool state() { return (currentState == onState); };
void flash(unsigned long ms = FLASH_MS);
void flash(uint64_t ms = FLASH_MS);
void setIdleState(uint8_t state);
uint8_t getIdleState() { return idleState; };
};
Expand Down
1 change: 0 additions & 1 deletion src/vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ void calculatePresence(int16_t distance)
vehicleDetected = false;
if (vehicleDetected != priorVehicleDetected)
{
led.flash();
// if change occurs with arrival/departure window then record motion,
// presence timer is set when door opens.
lastChangeAt = millis64();
Expand Down

1 comment on commit e4f7d7a

@mullender
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes a lot of sense, let's wait and see if this fixes the random crash.

Thank you for fixing this!

Please sign in to comment.