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.

83 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 "espurna.h"
  7. #include <vector>
  8. #include <memory>
  9. constexpr size_t LedsMax = 8;
  10. enum class LedMode {
  11. NetworkAutoconfig,
  12. NetworkConnected,
  13. NetworkConnectedInverse,
  14. NetworkConfig,
  15. NetworkConfigInverse,
  16. NetworkIdle,
  17. None
  18. };
  19. enum class led_delay_mode_t {
  20. Finite,
  21. Infinite,
  22. None
  23. };
  24. struct led_delay_t {
  25. led_delay_t() = delete;
  26. led_delay_t(unsigned long on_ms, unsigned long off_ms);
  27. led_delay_t(unsigned long on_ms, unsigned long off_ms, unsigned char repeats);
  28. led_delay_mode_t type;
  29. unsigned long on;
  30. unsigned long off;
  31. unsigned char repeats;
  32. };
  33. struct led_pattern_t {
  34. led_pattern_t() = default;
  35. led_pattern_t(const std::vector<led_delay_t>& delays);
  36. void start();
  37. void stop();
  38. bool started();
  39. bool ready();
  40. std::vector<led_delay_t> delays;
  41. std::vector<led_delay_t> queue;
  42. unsigned long clock_last;
  43. unsigned long clock_delay;
  44. };
  45. struct led_t {
  46. led_t() = delete;
  47. led_t(unsigned char pin, bool inverse, unsigned char mode, unsigned char relayID);
  48. bool status();
  49. bool status(bool new_status);
  50. bool toggle();
  51. unsigned char pin;
  52. bool inverse;
  53. unsigned char mode;
  54. unsigned char relayID;
  55. led_pattern_t pattern;
  56. };
  57. void ledUpdate(bool do_update);
  58. unsigned char ledCount();
  59. bool ledStatus(unsigned char id, bool status);
  60. bool ledStatus(unsigned char id);
  61. void ledSetup();