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.

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