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.

193 lines
6.5 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
Terminal: change command-line parser (#2247) Change the underlying command line handling: - switch to a custom parser, inspired by redis / sds - update terminalRegisterCommand signature, pass only bare minimum - clean-up `help` & `commands`. update settings `set`, `get` and `del` - allow our custom test suite to run command-line tests - clean-up Stream IO to allow us to print large things into debug stream (for example, `eeprom.dump`) - send parsing errors to the debug log As a proof of concept, introduce `TERMINAL_MQTT_SUPPORT` and `TERMINAL_WEB_API_SUPPORT` - MQTT subscribes to the `<root>/cmd/set` and sends response to the `<root>/cmd`. We can't output too much, as we don't have any large-send API. - Web API listens to the `/api/cmd?apikey=...&line=...` (or PUT, params inside the body). This one is intended as a possible replacement of the `API_SUPPORT`. Internals introduce a 'task' around the AsyncWebServerRequest object that will simulate what WiFiClient does and push data into it continuously, switching between CONT and SYS. Both are experimental. We only accept a single command and not every command is updated to use Print `ctx.output` object. We are also somewhat limited by the Print / Stream overall, perhaps I am overestimating the usefulness of Arduino compatibility to such an extent :) Web API handler can also sometimes show only part of the result, whenever the command tries to yield() by itself waiting for something. Perhaps we would need to create a custom request handler for that specific use-case.
4 years ago
  1. //------------------------------------------------------------------------------
  2. // Do not change this file unless you know what you are doing
  3. // Configuration settings are in the general.h file
  4. //------------------------------------------------------------------------------
  5. #pragma once
  6. //------------------------------------------------------------------------------
  7. // Various modules configuration
  8. #if DEBUG_TELNET_SUPPORT
  9. #undef TELNET_SUPPORT
  10. #define TELNET_SUPPORT 1
  11. #endif
  12. #if not WEB_SUPPORT
  13. #undef DEBUG_WEB_SUPPORT
  14. #define DEBUG_WEB_SUPPORT 0
  15. #endif
  16. #if not WEB_SUPPORT
  17. #undef API_SUPPORT
  18. #define API_SUPPORT 0 // API support requires web support
  19. #endif
  20. #if not WEB_SUPPORT
  21. #undef SSDP_SUPPORT
  22. #define SSDP_SUPPORT 0 // SSDP support requires web support
  23. #endif
  24. #if UART_MQTT_SUPPORT
  25. #undef MQTT_SUPPORT
  26. #define MQTT_SUPPORT 1 // UART<->MQTT requires MQTT and no serial debug
  27. #undef DEBUG_SERIAL_SUPPORT
  28. #define DEBUG_SERIAL_SUPPORT 0 // TODO: compare UART_MQTT_PORT with DEBUG_PORT? (as strings)
  29. #endif
  30. #if ALEXA_SUPPORT
  31. #undef RELAY_SUPPORT
  32. #define RELAY_SUPPORT 1 // and switches
  33. #endif
  34. #if RPN_RULES_SUPPORT
  35. #undef MQTT_SUPPORT
  36. #define MQTT_SUPPORT 1
  37. #endif
  38. #if DOMOTICZ_SUPPORT
  39. #undef MQTT_SUPPORT
  40. #define MQTT_SUPPORT 1 // If Domoticz enabled enable MQTT
  41. #endif
  42. #if HOMEASSISTANT_SUPPORT
  43. #undef MQTT_SUPPORT
  44. #define MQTT_SUPPORT 1 // If Home Assistant enabled enable MQTT
  45. #endif
  46. #if THERMOSTAT_SUPPORT
  47. #undef MQTT_USE_JSON
  48. #define MQTT_USE_JSON 1 // Thermostat depends on group messages in a JSON body
  49. #undef RELAY_SUPPORT
  50. #define RELAY_SUPPORT 1 // Thermostat depends on switches
  51. #endif
  52. #if SCHEDULER_SUPPORT
  53. #undef NTP_SUPPORT
  54. #define NTP_SUPPORT 1 // Scheduler needs NTP to work
  55. #undef RELAY_SUPPORT
  56. #define RELAY_SUPPORT 1 // Scheduler needs relays
  57. #endif
  58. #if TUYA_SUPPORT
  59. #undef LIGHT_TRANSITION_TIME
  60. #define LIGHT_TRANSITION_TIME 1600 // longer transition than the default
  61. #undef LIGHT_TRANSITION_STEP
  62. #define LIGHT_TRANSITION_STEP 200 // step can't be 10ms since most tuya serial connections are not fast
  63. #undef LIGHT_USE_TRANSITIONS
  64. #define LIGHT_USE_TRANSITIONS 0 // also, disable transitions unless set at runtime
  65. #endif
  66. #if TUYA_SUPPORT
  67. #undef RELAY_SUPPORT
  68. #define RELAY_SUPPORT 1 // Most of the time we require it
  69. #endif
  70. #if TERMINAL_WEB_API_SUPPORT
  71. #undef TERMINAL_SUPPORT
  72. #define TERMINAL_SUPPORT 1 // Need terminal command line parser and commands
  73. #undef WEB_SUPPORT
  74. #define WEB_SUPPORT 1 // Registered as web server request handler
  75. #endif
  76. #if TERMINAL_MQTT_SUPPORT
  77. #undef TERMINAL_SUPPORT
  78. #define TERMINAL_SUPPORT 1 // Need terminal command line parser and commands
  79. #undef MQTT_SUPPORT
  80. #define MQTT_SUPPORT 1 // Subscribe and publish things
  81. #endif
  82. #if IFAN_SUPPORT
  83. #undef RELAY_SUPPORT
  84. #define RELAY_SUPPORT 1 // Need relays to manage general state
  85. #endif
  86. //------------------------------------------------------------------------------
  87. // Hint about ESPAsyncTCP options and our internal one
  88. // TODO: clean-up SSL_ENABLED and USE_SSL settings for 1.15.0
  89. #if ASYNC_TCP_SSL_ENABLED && SECURE_CLIENT == SECURE_CLIENT_NONE
  90. #undef SECURE_CLIENT
  91. #define SECURE_CLIENT SECURE_CLIENT_AXTLS
  92. #endif
  93. #if THINGSPEAK_USE_SSL && THINGSPEAK_USE_ASYNC && (!ASYNC_TCP_SSL_ENABLED)
  94. #warning "Thingspeak in ASYNC mode requires a globally defined ASYNC_TCP_SSL_ENABLED=1"
  95. #undef THINGSPEAK_SUPPORT
  96. #define THINGSPEAK_SUPPORT 0 // Thingspeak in ASYNC mode requires ASYNC_TCP_SSL_ENABLED
  97. #endif
  98. #if WEB_SUPPORT && WEB_SSL_ENABLED && (!ASYNC_TCP_SSL_ENABLED)
  99. #warning "WEB_SUPPORT with SSL requires a globally defined ASYNC_TCP_SSL_ENABLED=1"
  100. #undef WEB_SSL_ENABLED
  101. #define WEB_SSL_ENABLED 0 // WEB_SUPPORT mode th SSL requires ASYNC_TCP_SSL_ENABLED
  102. #endif
  103. #if !DEBUG_SUPPORT
  104. #undef DEBUG_LOG_BUFFER_SUPPORT
  105. #define DEBUG_LOG_BUFFER_SUPPORT 0 // Can't buffer if there is no debugging enabled.
  106. // Helps to avoid checking twice for both DEBUG_SUPPORT and BUFFER_LOG_SUPPORT
  107. #endif
  108. //------------------------------------------------------------------------------
  109. // These depend on newest Core libraries
  110. #if LLMNR_SUPPORT && defined(ARDUINO_ESP8266_RELEASE_2_3_0)
  111. #undef LLMNR_SUPPORT
  112. #define LLMNR_SUPPORT 0
  113. #endif
  114. #if NETBIOS_SUPPORT && defined(ARDUINO_ESP8266_RELEASE_2_3_0)
  115. #undef NETBIOS_SUPPORT
  116. #define NETBIOS_SUPPORT 0
  117. #endif
  118. #if SSDP_SUPPORT && defined(ARDUINO_ESP8266_RELEASE_2_3_0)
  119. #undef SSDP_SUPPORT
  120. #define SSDP_SUPPORT 0
  121. #endif
  122. //------------------------------------------------------------------------------
  123. // It looks more natural that one click will enable display
  124. // and long click will switch relay
  125. #if THERMOSTAT_DISPLAY_SUPPORT
  126. #undef BUTTON1_CLICK
  127. #define BUTTON1_CLICK BUTTON_ACTION_DISPLAY_ON
  128. #undef BUTTON1_LNGCLICK
  129. #define BUTTON1_LNGCLICK BUTTON_ACTION_TOGGLE
  130. #endif
  131. //------------------------------------------------------------------------------
  132. // We should always set MQTT_MAX_PACKET_SIZE
  133. #if MQTT_LIBRARY == MQTT_LIBRARY_PUBSUBCLIENT
  134. #if not defined(MQTT_MAX_PACKET_SIZE)
  135. #warning "MQTT_MAX_PACKET_SIZE should be set in `build_flags = ...` of the environment! Default value is used instead."
  136. #endif
  137. #endif
  138. //------------------------------------------------------------------------------
  139. // Disable BME680 support if using Core version 2.3.0 due to memory constraints.
  140. #if BME680_SUPPORT && defined(ARDUINO_ESP8266_RELEASE_2_3_0)
  141. #warning "BME680_SUPPORT is not available when using Arduino Core 2.3.0 due to memory constraints. Please use Arduino Core 2.6.3+ instead (or set `platform = ${common.platform_latest}` for the latest version)."
  142. #undef BME680_SUPPORT
  143. #define BME680_SUPPORT 0
  144. #endif
  145. //------------------------------------------------------------------------------
  146. // Prometheus needs web server + request handler API
  147. #if PROMETHEUS_SUPPORT
  148. #undef WEB_SUPPORT
  149. #define WEB_SUPPORT 1
  150. #endif
  151. //------------------------------------------------------------------------------
  152. // Analog pin needs ADC_TOUT mode set up at compile time
  153. #if BUTTON_PROVIDER_ANALOG_SUPPORT
  154. #undef ADC_MODE_VALUE
  155. #define ADC_MODE_VALUE ADC_TOUT
  156. #endif