Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
1.5 KiB

  1. /*
  2. LED MODULE
  3. Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>
  4. */
  5. #pragma once
  6. #include <vector>
  7. #include <memory>
  8. constexpr const size_t LedsMax = 8;
  9. enum class LedMode {
  10. NetworkAutoconfig,
  11. NetworkConnected,
  12. NetworkConnectedInverse,
  13. NetworkConfig,
  14. NetworkConfigInverse,
  15. NetworkIdle,
  16. None
  17. };
  18. enum class led_delay_mode_t {
  19. Finite,
  20. Infinite,
  21. None
  22. };
  23. struct led_delay_t {
  24. led_delay_t() = delete;
  25. led_delay_t(unsigned long on_ms, unsigned long off_ms);
  26. led_delay_t(unsigned long on_ms, unsigned long off_ms, unsigned char repeats);
  27. led_delay_mode_t type;
  28. unsigned long on;
  29. unsigned long off;
  30. unsigned char repeats;
  31. };
  32. struct led_pattern_t {
  33. led_pattern_t() = default;
  34. led_pattern_t(const std::vector<led_delay_t>& delays);
  35. void start();
  36. void stop();
  37. bool started();
  38. bool ready();
  39. std::vector<led_delay_t> delays;
  40. std::vector<led_delay_t> queue;
  41. unsigned long clock_last;
  42. unsigned long clock_delay;
  43. };
  44. struct led_t {
  45. led_t() = delete;
  46. led_t(unsigned char pin, bool inverse, unsigned char mode, unsigned char relayID);
  47. bool status();
  48. bool status(bool new_status);
  49. bool toggle();
  50. unsigned char pin;
  51. bool inverse;
  52. unsigned char mode;
  53. unsigned char relayID;
  54. led_pattern_t pattern;
  55. };
  56. void ledUpdate(bool do_update);
  57. unsigned char ledCount();
  58. bool ledStatus(unsigned char id, bool status);
  59. bool ledStatus(unsigned char id);
  60. void ledSetup();