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.

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