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.

172 lines
3.4 KiB

  1. /*
  2. SYSTEM MODULE
  3. Copyright (C) 2019 by Xose Pérez <xose dot perez at gmail dot com>
  4. */
  5. #pragma once
  6. #include <Arduino.h>
  7. #include <chrono>
  8. #include <cstdint>
  9. extern "C" {
  10. #include "user_interface.h"
  11. extern struct rst_info resetInfo;
  12. }
  13. struct HeapStats {
  14. uint32_t available;
  15. uint16_t usable;
  16. uint8_t frag_pct;
  17. };
  18. enum class CustomResetReason : uint8_t {
  19. None,
  20. Button,
  21. Factory,
  22. Hardware,
  23. Mqtt,
  24. Ota,
  25. Rpc,
  26. Rule,
  27. Scheduler,
  28. Terminal,
  29. Web
  30. };
  31. namespace heartbeat {
  32. using Mask = int32_t;
  33. using Callback = bool(*)(Mask);
  34. using Seconds = std::chrono::duration<unsigned long>;
  35. using Milliseconds = std::chrono::duration<unsigned long, std::milli>;
  36. enum class Mode {
  37. None,
  38. Once,
  39. Repeat
  40. };
  41. enum class Report : Mask {
  42. Status = 1 << 1,
  43. Ssid = 1 << 2,
  44. Ip = 1 << 3,
  45. Mac = 1 << 4,
  46. Rssi = 1 << 5,
  47. Uptime = 1 << 6,
  48. Datetime = 1 << 7,
  49. Freeheap = 1 << 8,
  50. Vcc = 1 << 9,
  51. Relay = 1 << 10,
  52. Light = 1 << 11,
  53. Hostname = 1 << 12,
  54. App = 1 << 13,
  55. Version = 1 << 14,
  56. Board = 1 << 15,
  57. Loadavg = 1 << 16,
  58. Interval = 1 << 17,
  59. Description = 1 << 18,
  60. Range = 1 << 19,
  61. RemoteTemp = 1 << 20,
  62. Bssid = 1 << 21
  63. };
  64. constexpr Mask operator*(Report lhs, Mask rhs) {
  65. return static_cast<Mask>(lhs) * rhs;
  66. }
  67. constexpr Mask operator*(Mask lhs, Report rhs) {
  68. return lhs * static_cast<Mask>(rhs);
  69. }
  70. constexpr Mask operator|(Report lhs, Report rhs) {
  71. return static_cast<Mask>(lhs) | static_cast<Mask>(rhs);
  72. }
  73. constexpr Mask operator|(Report lhs, Mask rhs) {
  74. return static_cast<Mask>(lhs) | rhs;
  75. }
  76. constexpr Mask operator|(Mask lhs, Report rhs) {
  77. return lhs | static_cast<Mask>(rhs);
  78. }
  79. constexpr Mask operator&(Report lhs, Mask rhs) {
  80. return static_cast<Mask>(lhs) & rhs;
  81. }
  82. constexpr Mask operator&(Mask lhs, Report rhs) {
  83. return lhs & static_cast<Mask>(rhs);
  84. }
  85. constexpr Mask operator&(Report lhs, Report rhs) {
  86. return static_cast<Mask>(lhs) & static_cast<Mask>(rhs);
  87. }
  88. Seconds currentInterval();
  89. Milliseconds currentIntervalMs();
  90. Mask currentValue();
  91. Mode currentMode();
  92. } // namespace heartbeat
  93. namespace settings {
  94. namespace internal {
  95. template <>
  96. heartbeat::Mode convert(const String& value);
  97. template <>
  98. heartbeat::Milliseconds convert(const String& value);
  99. template <>
  100. heartbeat::Seconds convert(const String& value);
  101. } // namespace internal
  102. } // namespace settings
  103. unsigned long systemFreeStack();
  104. HeapStats systemHeapStats();
  105. void systemHeapStats(HeapStats&);
  106. unsigned long systemFreeHeap();
  107. unsigned long systemInitialFreeHeap();
  108. bool eraseSDKConfig();
  109. void factoryReset();
  110. uint32_t systemResetReason();
  111. uint8_t systemStabilityCounter();
  112. void systemStabilityCounter(uint8_t count);
  113. void systemCheck(bool stable);
  114. bool systemCheck();
  115. void customResetReason(CustomResetReason reason);
  116. CustomResetReason customResetReason();
  117. String customResetReasonToPayload(CustomResetReason reason);
  118. void deferredReset(unsigned long delay, CustomResetReason reason);
  119. bool checkNeedsReset();
  120. unsigned char systemLoadAverage();
  121. heartbeat::Seconds systemHeartbeatInterval();
  122. void systemScheduleHeartbeat();
  123. void systemStopHeartbeat(heartbeat::Callback);
  124. void systemHeartbeat(heartbeat::Callback, heartbeat::Mode, heartbeat::Seconds interval);
  125. void systemHeartbeat(heartbeat::Callback, heartbeat::Mode);
  126. void systemHeartbeat(heartbeat::Callback);
  127. bool systemHeartbeat();
  128. unsigned long systemUptime();
  129. void systemSetup();