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.

102 lines
2.2 KiB

providers: relays, lights and buttons refactoring (#2414) - gpio module now tracks the known providers (right now, hardware and mcp expander) - refactored relay struct to use 'Provider' implementing setup,notify,change,boot instead of just BasePin actions - refactored button module to use gpio provider instead of referencing types itself - removed dual & stm code from buttons, migrate both to relay module - added status notify and change callbacks for relayStatus (i.e. 'notify' when relay status was called, but not changed. and 'changed' when it did) - relays runtime configuration keys - relay command now shows configured relays and current & target statuses - refactor the code using relayStatus(0, blah) under LIGHT_PROVIDER check to use lightState instead - remove rfbridge code form relay module. implement through a basic state listener in the rfbridge module, depend on RELAY_SUPPORT - allow to bind rf codes to real relays - drop tuya-specific lights provider, remove tuya code from relays and lights modules - integrate tuya via relay listeners and providers, use lights custom provider - implement channel transitions for tuya. disabled by default, and transition time and step are overridden to 2000 + 100. needs to be set to some value below the total time (i.e. `total transition time / step time == number of steps`, we need to figure out a correct time that serial comms could handle) - lights custom provider (global, not per-pin) and state listeners - remove lights code from relay module. implement through providers & listeners in the lights module, depend on RELAY_SUPPORT - lights per-channel relay provider (unused atm), depend on RELAY_SUPPORT - refactored channel transition - calculate step only once, make sure time + step values are sane, generate quick transitions with very small delay (10ms hardcoded) for transitions during OFF state i.e. we no longer waste 500ms (or whatever transition time is set to) on boot doing nothing - transition time + step parameter for the lightUpdate - report mask parameter for the lightUpdate - minor fixes across the board resolve #2222
3 years ago
providers: relays, lights and buttons refactoring (#2414) - gpio module now tracks the known providers (right now, hardware and mcp expander) - refactored relay struct to use 'Provider' implementing setup,notify,change,boot instead of just BasePin actions - refactored button module to use gpio provider instead of referencing types itself - removed dual & stm code from buttons, migrate both to relay module - added status notify and change callbacks for relayStatus (i.e. 'notify' when relay status was called, but not changed. and 'changed' when it did) - relays runtime configuration keys - relay command now shows configured relays and current & target statuses - refactor the code using relayStatus(0, blah) under LIGHT_PROVIDER check to use lightState instead - remove rfbridge code form relay module. implement through a basic state listener in the rfbridge module, depend on RELAY_SUPPORT - allow to bind rf codes to real relays - drop tuya-specific lights provider, remove tuya code from relays and lights modules - integrate tuya via relay listeners and providers, use lights custom provider - implement channel transitions for tuya. disabled by default, and transition time and step are overridden to 2000 + 100. needs to be set to some value below the total time (i.e. `total transition time / step time == number of steps`, we need to figure out a correct time that serial comms could handle) - lights custom provider (global, not per-pin) and state listeners - remove lights code from relay module. implement through providers & listeners in the lights module, depend on RELAY_SUPPORT - lights per-channel relay provider (unused atm), depend on RELAY_SUPPORT - refactored channel transition - calculate step only once, make sure time + step values are sane, generate quick transitions with very small delay (10ms hardcoded) for transitions during OFF state i.e. we no longer waste 500ms (or whatever transition time is set to) on boot doing nothing - transition time + step parameter for the lightUpdate - report mask parameter for the lightUpdate - minor fixes across the board resolve #2222
3 years ago
  1. /*
  2. RELAY 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 "rpc.h"
  8. constexpr size_t RelaysMax = 32;
  9. enum class RelayPulse : uint8_t {
  10. None,
  11. Off,
  12. On
  13. };
  14. enum class RelayLock : uint8_t {
  15. None,
  16. Off,
  17. On
  18. };
  19. enum class RelayType : int {
  20. Normal,
  21. Inverse,
  22. Latched,
  23. LatchedInverse
  24. };
  25. enum class RelayProvider: int {
  26. None,
  27. Dummy,
  28. Gpio,
  29. Dual,
  30. Stm
  31. };
  32. class RelayProviderBase {
  33. public:
  34. RelayProviderBase() = default;
  35. virtual ~RelayProviderBase();
  36. virtual void dump();
  37. // whether the provider is ready
  38. virtual bool setup();
  39. // status requested at boot
  40. virtual void boot(bool status);
  41. // when 'status' was requested, but target status remains the same or is canceled
  42. virtual void notify(bool status);
  43. // when relay 'status' is changed from target to current
  44. virtual void change(bool status) = 0;
  45. // unique id of the provider
  46. virtual const char* id() const = 0;
  47. };
  48. PayloadStatus relayParsePayload(const char * payload);
  49. bool relayStatus(unsigned char id, bool status, bool report, bool group_report);
  50. bool relayStatus(unsigned char id, bool status);
  51. // gets either current or target status, where current is the status that we are
  52. // actually in and target is the status we would be, eventually, unless
  53. // relayStatus(id, relayStatus()) is called
  54. bool relayStatus(unsigned char id);
  55. bool relayStatusTarget(unsigned char id);
  56. void relayToggle(unsigned char id, bool report, bool group_report);
  57. void relayToggle(unsigned char id);
  58. unsigned char relayCount();
  59. const String& relayPayloadOn();
  60. const String& relayPayloadOff();
  61. const String& relayPayloadToggle();
  62. const char* relayPayload(PayloadStatus status);
  63. void relayMQTT(unsigned char id);
  64. void relayMQTT();
  65. void relayPulse(unsigned char id);
  66. void relaySync(unsigned char id);
  67. void relaySave(bool persist);
  68. using RelayStatusCallback = void(*)(unsigned char id, bool status);
  69. bool relayAdd(std::unique_ptr<RelayProviderBase>&& provider);
  70. void relaySetStatusNotify(RelayStatusCallback);
  71. void relaySetStatusChange(RelayStatusCallback);
  72. void relaySetupDummy(size_t size, bool reconfigure = false);
  73. void relaySetup();