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.

72 lines
1.5 KiB

  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 <bitset>
  7. #include "utils.h"
  8. constexpr size_t RELAYS_MAX = 32;
  9. enum class RelayStatus : unsigned char {
  10. OFF = 0,
  11. ON = 1,
  12. TOGGLE = 2,
  13. UNKNOWN = 0xFF
  14. };
  15. struct RelayMask {
  16. explicit RelayMask(const String& string) :
  17. as_string(string),
  18. as_u32(u32fromString(string))
  19. {}
  20. explicit RelayMask(String&& string) :
  21. as_string(std::move(string)),
  22. as_u32(u32fromString(as_string))
  23. {}
  24. explicit RelayMask(uint32_t value) :
  25. as_string(std::move(u32toString(value, 2))),
  26. as_u32(value)
  27. {}
  28. explicit RelayMask(std::bitset<RELAYS_MAX> bitset) :
  29. RelayMask(bitset.to_ulong())
  30. {}
  31. RelayMask(String&& string, uint32_t value) :
  32. as_string(std::move(string)),
  33. as_u32(value)
  34. {}
  35. const String as_string;
  36. uint32_t as_u32;
  37. };
  38. RelayStatus relayParsePayload(const char * payload);
  39. bool relayStatus(unsigned char id, bool status, bool report, bool group_report);
  40. bool relayStatus(unsigned char id, bool status);
  41. bool relayStatus(unsigned char id);
  42. void relayToggle(unsigned char id, bool report, bool group_report);
  43. void relayToggle(unsigned char id);
  44. unsigned char relayCount();
  45. const String& relayPayloadOn();
  46. const String& relayPayloadOff();
  47. const String& relayPayloadToggle();
  48. const char* relayPayload(RelayStatus status);
  49. void relaySetupDummy(size_t size, bool reconfigure = false);