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.

122 lines
4.3 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
  1. /*
  2. COMPATIBILITY BETWEEN 2.3.0 and latest versions
  3. */
  4. #pragma once
  5. #include "espurna.h"
  6. // -----------------------------------------------------------------------------
  7. // Core version 2.4.2 and higher changed the cont_t structure to a pointer:
  8. // https://github.com/esp8266/Arduino/commit/5d5ea92a4d004ab009d5f642629946a0cb8893dd#diff-3fa12668b289ccb95b7ab334833a4ba8L35
  9. // Core version 2.5.0 introduced EspClass helper method:
  10. // https://github.com/esp8266/Arduino/commit/0e0e34c614fe8a47544c9998201b1d9b3c24eb18
  11. // -----------------------------------------------------------------------------
  12. extern "C" {
  13. #include <cont.h>
  14. #if defined(ARDUINO_ESP8266_RELEASE_2_3_0) \
  15. || defined(ARDUINO_ESP8266_RELEASE_2_4_0) \
  16. || defined(ARDUINO_ESP8266_RELEASE_2_4_1)
  17. extern cont_t g_cont;
  18. #define getFreeStack() cont_get_free_stack(&g_cont)
  19. #elif defined(ARDUINO_ESP8266_RELEASE_2_4_2)
  20. extern cont_t* g_pcont;
  21. #define getFreeStack() cont_get_free_stack(g_pcont)
  22. #else
  23. #define getFreeStack() ESP.getFreeContStack()
  24. #endif
  25. }
  26. #include <pgmspace.h>
  27. // -----------------------------------------------------------------------------
  28. // ref: https://github.com/esp8266/Arduino/blob/master/tools/sdk/libc/xtensa-lx106-elf/include/sys/pgmspace.h
  29. // __STRINGIZE && __STRINGIZE_NX && PROGMEM definitions port
  30. // -----------------------------------------------------------------------------
  31. // Do not replace macros unless running version older than 2.5.0
  32. #if defined(ARDUINO_ESP8266_RELEASE_2_3_0) \
  33. || defined(ARDUINO_ESP8266_RELEASE_2_4_0) \
  34. || defined(ARDUINO_ESP8266_RELEASE_2_4_1) \
  35. || defined(ARDUINO_ESP8266_RELEASE_2_4_2)
  36. // Quoting esp8266/Arduino comments:
  37. // "Since __section__ is supposed to be only use for global variables,
  38. // there could be conflicts when a static/inlined function has them in the
  39. // same file as a non-static PROGMEM object.
  40. // Ref: https://gcc.gnu.org/onlinedocs/gcc-3.2/gcc/Variable-Attributes.html
  41. // Place each progmem object into its own named section, avoiding conflicts"
  42. #define __TO_STR_(A) #A
  43. #define __TO_STR(A) __TO_STR_(A)
  44. #undef PROGMEM
  45. #define PROGMEM __attribute__((section( "\".irom.text." __FILE__ "." __TO_STR(__LINE__) "." __TO_STR(__COUNTER__) "\"")))
  46. // "PSTR() macro modified to start on a 32-bit boundary. This adds on average
  47. // 1.5 bytes/string, but in return memcpy_P and strcpy_P will work 4~8x faster"
  48. #undef PSTR
  49. #define PSTR(s) (__extension__({static const char __c[] __attribute__((__aligned__(4))) PROGMEM = (s); &__c[0];}))
  50. #endif
  51. // -----------------------------------------------------------------------------
  52. // Division by zero bug
  53. // https://github.com/esp8266/Arduino/pull/2397
  54. // https://github.com/esp8266/Arduino/pull/2408
  55. // -----------------------------------------------------------------------------
  56. #if defined(ARDUINO_ESP8266_RELEASE_2_3_0)
  57. long __attribute__((deprecated("Please avoid using map() with Core 2.3.0"))) map(long x, long in_min, long in_max, long out_min, long out_max);
  58. #endif
  59. // -----------------------------------------------------------------------------
  60. // Proxy min & max same as the latest Arduino.h
  61. // -----------------------------------------------------------------------------
  62. #if defined(ARDUINO_ESP8266_RELEASE_2_3_0)
  63. #undef min
  64. #undef max
  65. #undef _min
  66. #undef _max
  67. #include <algorithm>
  68. using std::min;
  69. using std::max;
  70. using std::isinf;
  71. using std::isnan;
  72. #define _min(a,b) ({ decltype(a) _a = (a); decltype(b) _b = (b); _a < _b? _a : _b; })
  73. #define _max(a,b) ({ decltype(a) _a = (a); decltype(b) _b = (b); _a > _b? _a : _b; })
  74. #endif
  75. // -----------------------------------------------------------------------------
  76. // std::make_unique backport for C++11, since we still use it
  77. // -----------------------------------------------------------------------------
  78. #if 201103L >= __cplusplus
  79. #include <memory>
  80. namespace std {
  81. template<typename T, typename... Args>
  82. std::unique_ptr<T> make_unique(Args&&... args) {
  83. return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
  84. }
  85. }
  86. #endif
  87. // -----------------------------------------------------------------------------
  88. // Make sure all INPUT modes are available to the source
  89. // (even if those do nothing)
  90. // -----------------------------------------------------------------------------
  91. // TODO: esp8266/Arduino issue
  92. #if defined(ESP8266) and not defined(INPUT_PULLDOWN)
  93. #define INPUT_PULLDOWN 0x3
  94. #endif