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.

82 lines
1.9 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 "espurna.h"
  7. #include "broker.h"
  8. #include "libs/BasePin.h"
  9. #include "libs/DebounceEvent.h"
  10. #include <memory>
  11. constexpr size_t ButtonsPresetMax = 8;
  12. constexpr size_t ButtonsMax = 32;
  13. using button_action_t = uint8_t;
  14. enum class button_event_t {
  15. None,
  16. Pressed,
  17. Released,
  18. Click,
  19. DoubleClick,
  20. LongClick,
  21. LongLongClick,
  22. TripleClick
  23. };
  24. struct button_actions_t {
  25. button_action_t pressed;
  26. button_action_t released;
  27. button_action_t click;
  28. button_action_t dblclick;
  29. button_action_t lngclick;
  30. button_action_t lnglngclick;
  31. button_action_t trplclick;
  32. };
  33. struct button_event_delays_t {
  34. button_event_delays_t();
  35. button_event_delays_t(unsigned long debounce, unsigned long repeat, unsigned long lngclick, unsigned long lnglngclick);
  36. const unsigned long debounce;
  37. const unsigned long repeat;
  38. const unsigned long lngclick;
  39. const unsigned long lnglngclick;
  40. };
  41. struct button_t {
  42. button_t(unsigned char relayID, const button_actions_t& actions, const button_event_delays_t& delays);
  43. button_t(std::shared_ptr<BasePin> pin, const debounce_event::types::Config& config,
  44. unsigned char relayID, const button_actions_t& actions, const button_event_delays_t& delays);
  45. bool state();
  46. button_event_t loop();
  47. std::unique_ptr<debounce_event::EventEmitter> event_emitter;
  48. const button_event_delays_t event_delays;
  49. const button_actions_t actions;
  50. const unsigned char relayID;
  51. };
  52. BrokerDeclare(ButtonBroker, void(unsigned char id, button_event_t event));
  53. bool buttonState(unsigned char id);
  54. button_action_t buttonAction(unsigned char id, const button_event_t event);
  55. void buttonEvent(unsigned char id, button_event_t event);
  56. unsigned char buttonCount();
  57. void buttonSetup();