led.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include <Arduino.h>
  2. #include "led.h"
  3. #include "board_config.h"
  4. Led led;
  5. void Led::init(void)
  6. {
  7. if (done_init) {
  8. return;
  9. }
  10. done_init = true;
  11. #ifdef PIN_STATUS_LED
  12. pinMode(PIN_STATUS_LED, OUTPUT);
  13. #endif
  14. #ifdef WS2812_LED_PIN
  15. pinMode(WS2812_LED_PIN, OUTPUT);
  16. ledStrip.begin();
  17. #endif
  18. }
  19. void Led::update(void)
  20. {
  21. init();
  22. const uint32_t now_ms = millis();
  23. #ifdef PIN_STATUS_LED
  24. switch (state) {
  25. case LedState::ARM_OK: {
  26. digitalWrite(PIN_STATUS_LED, STATUS_LED_OK);
  27. last_led_trig_ms = now_ms;
  28. break;
  29. }
  30. default:
  31. if (now_ms - last_led_trig_ms > 100) {
  32. digitalWrite(PIN_STATUS_LED, !digitalRead(PIN_STATUS_LED));
  33. last_led_trig_ms = now_ms;
  34. }
  35. break;
  36. }
  37. #endif
  38. #ifdef WS2812_LED_PIN
  39. ledStrip.clear();
  40. switch (state) {
  41. case LedState::ARM_OK:
  42. ledStrip.setPixelColor(0, ledStrip.Color(0, 255, 0));
  43. ledStrip.setPixelColor(0, ledStrip.Color(1, 255, 0)); //for db210pro, set the second LED to have the same output (for now)
  44. break;
  45. default:
  46. ledStrip.setPixelColor(0, ledStrip.Color(255, 0, 0));
  47. ledStrip.setPixelColor(1, ledStrip.Color(255, 0, 0)); //for db210pro, set the second LED to have the same output (for now)
  48. break;
  49. }
  50. if (now_ms - last_led_strip_ms >= 200) {
  51. last_led_strip_ms = now_ms;
  52. ledStrip.show();
  53. }
  54. #endif
  55. }