status_led.cpp 719 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include "status_led.h"
  2. #include <Arduino.h>
  3. #define WAKE_LED_OFF ((WAKE_LED_ON) == HIGH ? LOW : HIGH)
  4. #define PULSE_MS 500u // wake flash duration
  5. static unsigned long g_pulseMs = 0;
  6. static bool g_lit = false;
  7. static void ledWrite(int level)
  8. {
  9. digitalWrite(WAKE_LED_PIN_A, level);
  10. digitalWrite(WAKE_LED_PIN_B, level);
  11. }
  12. void ledInit()
  13. {
  14. pinMode(WAKE_LED_PIN_A, OUTPUT);
  15. pinMode(WAKE_LED_PIN_B, OUTPUT);
  16. ledWrite(WAKE_LED_OFF);
  17. }
  18. void ledWakePulse()
  19. {
  20. g_pulseMs = millis();
  21. g_lit = true;
  22. // light immediately at the remoteWakeup() call site, not on the next loop
  23. ledWrite(WAKE_LED_ON);
  24. }
  25. void ledTask()
  26. {
  27. if (g_lit && millis() - g_pulseMs >= PULSE_MS) {
  28. g_lit = false;
  29. ledWrite(WAKE_LED_OFF);
  30. }
  31. }