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.

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