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.

299 lines
8.2 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
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
Rework settings (#2282) * wip based on early draft. todo benchmarking * fixup eraser, assume keys are unique * fix cursor copy, test removal at random * small benchmark via permutations. todo lambdas and novirtual * fix empty condition / reset * overwrite optimizations, fix move offsets overflows * ...erase using 0xff instead of 0 * test the theory with code, different length kv were bugged * try to check for out-of-bounds writes / reads * style * trying to fix mover again * clarify length, defend against reading len on edge * fix uncommited rewind change * prove space assumptions * more concise traces, fix move condition (agrh!!!) * slightly more internal knowledge (estimates API?) * make sure cursor is only valid within the range * ensure 0 does not blow things * go back up * cursor comments * comments * rewrite writes through cursor * in del too * estimate kv storage requirements, return available size * move raw erase / move into a method, allow ::set to avoid scanning storage twice * refactor naming, use in code * amend storage slicing test * fix crash handler offsets, cleanup configuration * start -> begin * eeprom readiness * dependencies * unused * SPI_FLASH constants for older Core * vtables -> templates * less include dependencies * gcov help, move estimate outside of the class * writer position can never match, use begin + offset * tweak save_crash to trigger only once in a serious crash * doh, header function should be inline * foreach api, tweak structs for public api * use test helper class * when not using foreach, move cursor reset closer to the loop using read_kv * coverage comments, fix typo in tests decltype * ensure set() does not break with offset * make codacy happy again
3 years ago
Rework settings (#2282) * wip based on early draft. todo benchmarking * fixup eraser, assume keys are unique * fix cursor copy, test removal at random * small benchmark via permutations. todo lambdas and novirtual * fix empty condition / reset * overwrite optimizations, fix move offsets overflows * ...erase using 0xff instead of 0 * test the theory with code, different length kv were bugged * try to check for out-of-bounds writes / reads * style * trying to fix mover again * clarify length, defend against reading len on edge * fix uncommited rewind change * prove space assumptions * more concise traces, fix move condition (agrh!!!) * slightly more internal knowledge (estimates API?) * make sure cursor is only valid within the range * ensure 0 does not blow things * go back up * cursor comments * comments * rewrite writes through cursor * in del too * estimate kv storage requirements, return available size * move raw erase / move into a method, allow ::set to avoid scanning storage twice * refactor naming, use in code * amend storage slicing test * fix crash handler offsets, cleanup configuration * start -> begin * eeprom readiness * dependencies * unused * SPI_FLASH constants for older Core * vtables -> templates * less include dependencies * gcov help, move estimate outside of the class * writer position can never match, use begin + offset * tweak save_crash to trigger only once in a serious crash * doh, header function should be inline * foreach api, tweak structs for public api * use test helper class * when not using foreach, move cursor reset closer to the loop using read_kv * coverage comments, fix typo in tests decltype * ensure set() does not break with offset * make codacy happy again
3 years ago
Rework settings (#2282) * wip based on early draft. todo benchmarking * fixup eraser, assume keys are unique * fix cursor copy, test removal at random * small benchmark via permutations. todo lambdas and novirtual * fix empty condition / reset * overwrite optimizations, fix move offsets overflows * ...erase using 0xff instead of 0 * test the theory with code, different length kv were bugged * try to check for out-of-bounds writes / reads * style * trying to fix mover again * clarify length, defend against reading len on edge * fix uncommited rewind change * prove space assumptions * more concise traces, fix move condition (agrh!!!) * slightly more internal knowledge (estimates API?) * make sure cursor is only valid within the range * ensure 0 does not blow things * go back up * cursor comments * comments * rewrite writes through cursor * in del too * estimate kv storage requirements, return available size * move raw erase / move into a method, allow ::set to avoid scanning storage twice * refactor naming, use in code * amend storage slicing test * fix crash handler offsets, cleanup configuration * start -> begin * eeprom readiness * dependencies * unused * SPI_FLASH constants for older Core * vtables -> templates * less include dependencies * gcov help, move estimate outside of the class * writer position can never match, use begin + offset * tweak save_crash to trigger only once in a serious crash * doh, header function should be inline * foreach api, tweak structs for public api * use test helper class * when not using foreach, move cursor reset closer to the loop using read_kv * coverage comments, fix typo in tests decltype * ensure set() does not break with offset * make codacy happy again
3 years ago
Rework settings (#2282) * wip based on early draft. todo benchmarking * fixup eraser, assume keys are unique * fix cursor copy, test removal at random * small benchmark via permutations. todo lambdas and novirtual * fix empty condition / reset * overwrite optimizations, fix move offsets overflows * ...erase using 0xff instead of 0 * test the theory with code, different length kv were bugged * try to check for out-of-bounds writes / reads * style * trying to fix mover again * clarify length, defend against reading len on edge * fix uncommited rewind change * prove space assumptions * more concise traces, fix move condition (agrh!!!) * slightly more internal knowledge (estimates API?) * make sure cursor is only valid within the range * ensure 0 does not blow things * go back up * cursor comments * comments * rewrite writes through cursor * in del too * estimate kv storage requirements, return available size * move raw erase / move into a method, allow ::set to avoid scanning storage twice * refactor naming, use in code * amend storage slicing test * fix crash handler offsets, cleanup configuration * start -> begin * eeprom readiness * dependencies * unused * SPI_FLASH constants for older Core * vtables -> templates * less include dependencies * gcov help, move estimate outside of the class * writer position can never match, use begin + offset * tweak save_crash to trigger only once in a serious crash * doh, header function should be inline * foreach api, tweak structs for public api * use test helper class * when not using foreach, move cursor reset closer to the loop using read_kv * coverage comments, fix typo in tests decltype * ensure set() does not break with offset * make codacy happy again
3 years ago
Rework settings (#2282) * wip based on early draft. todo benchmarking * fixup eraser, assume keys are unique * fix cursor copy, test removal at random * small benchmark via permutations. todo lambdas and novirtual * fix empty condition / reset * overwrite optimizations, fix move offsets overflows * ...erase using 0xff instead of 0 * test the theory with code, different length kv were bugged * try to check for out-of-bounds writes / reads * style * trying to fix mover again * clarify length, defend against reading len on edge * fix uncommited rewind change * prove space assumptions * more concise traces, fix move condition (agrh!!!) * slightly more internal knowledge (estimates API?) * make sure cursor is only valid within the range * ensure 0 does not blow things * go back up * cursor comments * comments * rewrite writes through cursor * in del too * estimate kv storage requirements, return available size * move raw erase / move into a method, allow ::set to avoid scanning storage twice * refactor naming, use in code * amend storage slicing test * fix crash handler offsets, cleanup configuration * start -> begin * eeprom readiness * dependencies * unused * SPI_FLASH constants for older Core * vtables -> templates * less include dependencies * gcov help, move estimate outside of the class * writer position can never match, use begin + offset * tweak save_crash to trigger only once in a serious crash * doh, header function should be inline * foreach api, tweak structs for public api * use test helper class * when not using foreach, move cursor reset closer to the loop using read_kv * coverage comments, fix typo in tests decltype * ensure set() does not break with offset * make codacy happy again
3 years ago
Rework settings (#2282) * wip based on early draft. todo benchmarking * fixup eraser, assume keys are unique * fix cursor copy, test removal at random * small benchmark via permutations. todo lambdas and novirtual * fix empty condition / reset * overwrite optimizations, fix move offsets overflows * ...erase using 0xff instead of 0 * test the theory with code, different length kv were bugged * try to check for out-of-bounds writes / reads * style * trying to fix mover again * clarify length, defend against reading len on edge * fix uncommited rewind change * prove space assumptions * more concise traces, fix move condition (agrh!!!) * slightly more internal knowledge (estimates API?) * make sure cursor is only valid within the range * ensure 0 does not blow things * go back up * cursor comments * comments * rewrite writes through cursor * in del too * estimate kv storage requirements, return available size * move raw erase / move into a method, allow ::set to avoid scanning storage twice * refactor naming, use in code * amend storage slicing test * fix crash handler offsets, cleanup configuration * start -> begin * eeprom readiness * dependencies * unused * SPI_FLASH constants for older Core * vtables -> templates * less include dependencies * gcov help, move estimate outside of the class * writer position can never match, use begin + offset * tweak save_crash to trigger only once in a serious crash * doh, header function should be inline * foreach api, tweak structs for public api * use test helper class * when not using foreach, move cursor reset closer to the loop using read_kv * coverage comments, fix typo in tests decltype * ensure set() does not break with offset * make codacy happy again
3 years ago
Rework settings (#2282) * wip based on early draft. todo benchmarking * fixup eraser, assume keys are unique * fix cursor copy, test removal at random * small benchmark via permutations. todo lambdas and novirtual * fix empty condition / reset * overwrite optimizations, fix move offsets overflows * ...erase using 0xff instead of 0 * test the theory with code, different length kv were bugged * try to check for out-of-bounds writes / reads * style * trying to fix mover again * clarify length, defend against reading len on edge * fix uncommited rewind change * prove space assumptions * more concise traces, fix move condition (agrh!!!) * slightly more internal knowledge (estimates API?) * make sure cursor is only valid within the range * ensure 0 does not blow things * go back up * cursor comments * comments * rewrite writes through cursor * in del too * estimate kv storage requirements, return available size * move raw erase / move into a method, allow ::set to avoid scanning storage twice * refactor naming, use in code * amend storage slicing test * fix crash handler offsets, cleanup configuration * start -> begin * eeprom readiness * dependencies * unused * SPI_FLASH constants for older Core * vtables -> templates * less include dependencies * gcov help, move estimate outside of the class * writer position can never match, use begin + offset * tweak save_crash to trigger only once in a serious crash * doh, header function should be inline * foreach api, tweak structs for public api * use test helper class * when not using foreach, move cursor reset closer to the loop using read_kv * coverage comments, fix typo in tests decltype * ensure set() does not break with offset * make codacy happy again
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
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
Rework settings (#2282) * wip based on early draft. todo benchmarking * fixup eraser, assume keys are unique * fix cursor copy, test removal at random * small benchmark via permutations. todo lambdas and novirtual * fix empty condition / reset * overwrite optimizations, fix move offsets overflows * ...erase using 0xff instead of 0 * test the theory with code, different length kv were bugged * try to check for out-of-bounds writes / reads * style * trying to fix mover again * clarify length, defend against reading len on edge * fix uncommited rewind change * prove space assumptions * more concise traces, fix move condition (agrh!!!) * slightly more internal knowledge (estimates API?) * make sure cursor is only valid within the range * ensure 0 does not blow things * go back up * cursor comments * comments * rewrite writes through cursor * in del too * estimate kv storage requirements, return available size * move raw erase / move into a method, allow ::set to avoid scanning storage twice * refactor naming, use in code * amend storage slicing test * fix crash handler offsets, cleanup configuration * start -> begin * eeprom readiness * dependencies * unused * SPI_FLASH constants for older Core * vtables -> templates * less include dependencies * gcov help, move estimate outside of the class * writer position can never match, use begin + offset * tweak save_crash to trigger only once in a serious crash * doh, header function should be inline * foreach api, tweak structs for public api * use test helper class * when not using foreach, move cursor reset closer to the loop using read_kv * coverage comments, fix typo in tests decltype * ensure set() does not break with offset * make codacy happy again
3 years ago
  1. /*
  2. SETTINGS MODULE
  3. Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>
  4. Copyright (C) 2020-2021 by Maxim Prokhorov <prokhorov dot max at outlook dot com>
  5. */
  6. #pragma once
  7. #include <Arduino.h>
  8. #include <functional>
  9. #include <utility>
  10. #include <vector>
  11. #include <type_traits>
  12. #include <ArduinoJson.h>
  13. #include "storage_eeprom.h"
  14. #include "settings_helpers.h"
  15. #include "settings_embedis.h"
  16. #include "terminal.h"
  17. // --------------------------------------------------------------------------
  18. void resetSettings();
  19. void saveSettings();
  20. void autosaveSettings();
  21. namespace settings {
  22. class EepromStorage {
  23. public:
  24. uint8_t read(size_t pos) {
  25. return eepromRead(pos);
  26. }
  27. void write(size_t pos, uint8_t value) {
  28. eepromWrite(pos, value);
  29. }
  30. void commit() {
  31. autosaveSettings();
  32. }
  33. };
  34. using kvs_type = embedis::KeyValueStore<EepromStorage>;
  35. extern kvs_type kv_store;
  36. } // namespace settings
  37. // --------------------------------------------------------------------------
  38. using settings_move_key_t = std::pair<SettingsKey, SettingsKey>;
  39. using settings_filter_t = std::function<String(String& value)>;
  40. struct settings_cfg_t {
  41. String& setting;
  42. const char* key;
  43. const char* default_value;
  44. };
  45. using settings_cfg_list_t = std::initializer_list<settings_cfg_t>;
  46. // --------------------------------------------------------------------------
  47. namespace settings {
  48. namespace internal {
  49. template <typename T>
  50. using is_arduino_string = std::is_same<String, typename std::decay<T>::type>;
  51. template <typename T>
  52. using enable_if_arduino_string = std::enable_if<is_arduino_string<T>::value>;
  53. template <typename T>
  54. using enable_if_not_arduino_string = std::enable_if<!is_arduino_string<T>::value>;
  55. // --------------------------------------------------------------------------
  56. template <typename T>
  57. T convert(const String& value);
  58. template <>
  59. float convert(const String& value);
  60. template <>
  61. double convert(const String& value);
  62. template <>
  63. signed char convert(const String& value);
  64. template <>
  65. short convert(const String& value);
  66. template <>
  67. int convert(const String& value);
  68. template <>
  69. long convert(const String& value);
  70. template <>
  71. bool convert(const String& value);
  72. template <>
  73. unsigned long convert(const String& value);
  74. template <>
  75. unsigned int convert(const String& value);
  76. template <>
  77. unsigned short convert(const String& value);
  78. template <>
  79. unsigned char convert(const String& value);
  80. inline String serialize(uint8_t value, int base = 10) {
  81. return String(value, base);
  82. }
  83. inline String serialize(uint16_t value, int base = 10) {
  84. return String(value, base);
  85. }
  86. String serialize(uint32_t value, int base = 10);
  87. inline String serialize(unsigned long value, int base = 10) {
  88. static_assert(sizeof(unsigned long) == sizeof(uint32_t), "");
  89. static_assert(sizeof(unsigned int) == sizeof(unsigned long), "");
  90. return serialize(static_cast<unsigned int>(value), base);
  91. }
  92. inline String serialize(int16_t value, int base = 10) {
  93. return String(value, base);
  94. }
  95. inline String serialize(int8_t value, int base = 10) {
  96. return serialize(static_cast<int16_t>(value), base);
  97. }
  98. inline String serialize(long value, int base = 10) {
  99. return String(value, base);
  100. }
  101. inline String serialize(int value, int base = 10) {
  102. static_assert(sizeof(long) == sizeof(int32_t), "");
  103. static_assert(sizeof(int) == sizeof(long), "");
  104. return serialize(static_cast<long>(value), base);
  105. }
  106. inline String serialize(float value) {
  107. return String(value, 3);
  108. }
  109. inline String serialize(double value) {
  110. return String(value, 3);
  111. }
  112. inline String serialize(bool value) {
  113. return value ? "true" : "false";
  114. }
  115. } // namespace internal
  116. } // namespace settings
  117. // --------------------------------------------------------------------------
  118. struct settings_key_match_t {
  119. using match_f = bool(*)(const char* key);
  120. using key_f = const String(*)(const String& key);
  121. match_f match;
  122. key_f key;
  123. };
  124. void settingsRegisterDefaults(const settings_key_match_t& matcher);
  125. String settingsQueryDefaults(const String& key);
  126. // --------------------------------------------------------------------------
  127. void moveSetting(const String& from, const String& to);
  128. void moveSetting(const String& from, const String& to, unsigned int index);
  129. void moveSettings(const String& from, const String& to);
  130. template <typename T, typename = typename settings::internal::enable_if_not_arduino_string<T>::type>
  131. T getSetting(const SettingsKey& key, T defaultValue) __attribute__((noinline));
  132. template <typename T, typename = typename settings::internal::enable_if_not_arduino_string<T>::type>
  133. T getSetting(const SettingsKey& key, T defaultValue) {
  134. auto result = settings::kv_store.get(key.value());
  135. if (result) {
  136. return settings::internal::convert<T>(result.ref());
  137. }
  138. return defaultValue;
  139. }
  140. String getSetting(const char* key);
  141. String getSetting(const String& key);
  142. String getSetting(const __FlashStringHelper* key);
  143. String getSetting(const SettingsKey& key);
  144. String getSetting(const SettingsKey& key, const char* defaultValue);
  145. String getSetting(const SettingsKey& key, const __FlashStringHelper* defaultValue);
  146. String getSetting(const SettingsKey& key, const String& defaultValue);
  147. String getSetting(const SettingsKey& key, const String& defaultValue);
  148. String getSetting(const SettingsKey& key, String&& defaultValue);
  149. template<typename T, typename = typename settings::internal::enable_if_arduino_string<T>::type>
  150. bool setSetting(const SettingsKey& key, T&& value) {
  151. return settings::kv_store.set(key.value(), value);
  152. }
  153. template<typename T, typename = typename settings::internal::enable_if_not_arduino_string<T>::type>
  154. bool setSetting(const SettingsKey& key, T value) {
  155. return setSetting(key, std::move(String(value)));
  156. }
  157. bool delSetting(const char* key);
  158. bool delSetting(const String& key);
  159. bool delSetting(const __FlashStringHelper* key);
  160. bool delSetting(const SettingsKey& key);
  161. void delSettingPrefix(const std::initializer_list<const char*>&);
  162. void delSettingPrefix(const char* prefix);
  163. void delSettingPrefix(const String& prefix);
  164. bool hasSetting(const char* key);
  165. bool hasSetting(const String& key);
  166. bool hasSetting(const __FlashStringHelper* key);
  167. bool hasSetting(const SettingsKey& key);
  168. void settingsGetJson(JsonObject& data);
  169. bool settingsRestoreJson(char* json_string, size_t json_buffer_size = 1024);
  170. bool settingsRestoreJson(JsonObject& data);
  171. size_t settingsKeyCount();
  172. std::vector<String> settingsKeys();
  173. void settingsProcessConfig(const settings_cfg_list_t& config, settings_filter_t filter = nullptr);
  174. size_t settingsSize();
  175. void settingsSetup();
  176. // -----------------------------------------------------------------------------
  177. // Configuration updates
  178. // -----------------------------------------------------------------------------
  179. int migrateVersion();
  180. void migrate();
  181. // -----------------------------------------------------------------------------
  182. // Deprecated implementation
  183. // -----------------------------------------------------------------------------
  184. template <typename T>
  185. String getSetting(const String& key, unsigned char index, T defaultValue)
  186. __attribute__((deprecated("getSetting({key, index}, default) should be used instead")));
  187. template<typename T>
  188. bool setSetting(const String& key, unsigned char index, T value)
  189. __attribute__((deprecated("setSetting({key, index}, value) should be used instead")));
  190. template<typename T>
  191. bool hasSetting(const String& key, unsigned char index)
  192. __attribute__((deprecated("hasSetting({key, index}) should be used instead")));
  193. template<typename T>
  194. bool delSetting(const String& key, unsigned char index)
  195. __attribute__((deprecated("delSetting({key, index}) should be used instead")));
  196. // --------------------------------------------------------------------------
  197. template<typename T>
  198. String getSetting(const String& key, unsigned char index, T defaultValue) {
  199. return getSetting({key, index}, defaultValue);
  200. }
  201. template<typename T>
  202. bool setSetting(const String& key, unsigned char index, T value) {
  203. return setSetting({key, index}, value);
  204. }
  205. template<typename T>
  206. bool hasSetting(const String& key, unsigned char index) {
  207. return hasSetting({key, index});
  208. }
  209. template<typename T>
  210. bool delSetting(const String& key, unsigned char index) {
  211. return delSetting({key, index});
  212. }