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.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 = 0,
  16. Pressed = 1,
  17. Click = 2,
  18. DoubleClick = 3,
  19. LongClick = 4,
  20. LongLongClick = 5,
  21. TripleClick = 6
  22. };
  23. struct button_actions_t {
  24. button_action_t pressed;
  25. button_action_t click;
  26. button_action_t dblclick;
  27. button_action_t lngclick;
  28. button_action_t lnglngclick;
  29. button_action_t trplclick;
  30. };
  31. struct button_event_delays_t {
  32. button_event_delays_t();
  33. button_event_delays_t(unsigned long debounce, unsigned long repeat, unsigned long lngclick, unsigned long lnglngclick);
  34. const unsigned long debounce;
  35. const unsigned long repeat;
  36. const unsigned long lngclick;
  37. const unsigned long lnglngclick;
  38. };
  39. struct button_t {
  40. button_t(unsigned char relayID, const button_actions_t& actions, const button_event_delays_t& delays);
  41. button_t(std::shared_ptr<BasePin> pin, const debounce_event::types::Config& config,
  42. unsigned char relayID, const button_actions_t& actions, const button_event_delays_t& delays);
  43. bool state();
  44. button_event_t loop();
  45. std::unique_ptr<debounce_event::EventEmitter> event_emitter;
  46. const button_event_delays_t event_delays;
  47. const button_actions_t actions;
  48. const unsigned char relayID;
  49. };
  50. BrokerDeclare(ButtonBroker, void(unsigned char id, button_event_t event));
  51. bool buttonState(unsigned char id);
  52. button_action_t buttonAction(unsigned char id, const button_event_t event);
  53. void buttonMQTT(unsigned char id, button_event_t event);
  54. void buttonEvent(unsigned char id, button_event_t event);
  55. unsigned char buttonCount();
  56. void buttonSetup();