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.

73 lines
1.7 KiB

  1. /*
  2. BUTTON MODULE
  3. Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>
  4. */
  5. #pragma once
  6. #include "libs/BasePin.h"
  7. #include "libs/DebounceEvent.h"
  8. #include <memory>
  9. constexpr size_t ButtonsPresetMax = 8;
  10. constexpr size_t ButtonsMax = 32;
  11. enum class button_event_t {
  12. None = 0,
  13. Pressed = 1,
  14. Click = 2,
  15. DoubleClick = 3,
  16. LongClick = 4,
  17. LongLongClick = 5,
  18. TripleClick = 6
  19. };
  20. struct button_actions_t {
  21. uint16_t pressed;
  22. uint16_t click;
  23. uint16_t dblclick;
  24. uint16_t lngclick;
  25. uint16_t lnglngclick;
  26. uint16_t trplclick;
  27. };
  28. struct button_event_delays_t {
  29. button_event_delays_t();
  30. button_event_delays_t(unsigned long debounce, unsigned long repeat, unsigned long lngclick, unsigned long lnglngclick);
  31. const unsigned long debounce;
  32. const unsigned long repeat;
  33. const unsigned long lngclick;
  34. const unsigned long lnglngclick;
  35. };
  36. struct button_t {
  37. button_t(unsigned char relayID, const button_actions_t& actions, const button_event_delays_t& delays);
  38. button_t(std::shared_ptr<BasePin> pin, const debounce_event::types::Config& config,
  39. unsigned char relayID, const button_actions_t& actions, const button_event_delays_t& delays);
  40. bool state();
  41. button_event_t loop();
  42. std::unique_ptr<debounce_event::EventEmitter> event_emitter;
  43. const button_event_delays_t event_delays;
  44. const button_actions_t actions;
  45. const unsigned char relayID;
  46. };
  47. bool buttonState(unsigned char id);
  48. uint16_t buttonAction(unsigned char id, const button_event_t event);
  49. void buttonMQTT(unsigned char id, button_event_t event);
  50. void buttonEvent(unsigned char id, button_event_t event);
  51. unsigned char buttonCount();
  52. void buttonSetup();