diff --git a/src/led.cpp b/src/led.cpp index 2fe301a..ca1a18e 100644 --- a/src/led.cpp +++ b/src/led.cpp @@ -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) { @@ -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(); }); + } } diff --git a/src/led.h b/src/led.h index 9c52ddc..74bcfee 100644 --- a/src/led.h +++ b/src/led.h @@ -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; }; }; diff --git a/src/vehicle.cpp b/src/vehicle.cpp index cdc4534..3791a7c 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -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();