platform_config.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #pragma once
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include "nvs.h"
  5. #include "assert.h"
  6. #include "cJSON.h"
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. #ifdef __cplusplus
  11. }
  12. #endif
  13. #define DECLARE_SET_DEFAULT(t) void config_set_default_## t (const char *key, t value);
  14. #define DECLARE_GET_NUM(t) esp_err_t config_get_## t (const char *key, t * value);
  15. #ifndef FREE_RESET
  16. #define FREE_RESET(p) if(p!=NULL) { free(p); p=NULL; }
  17. #endif
  18. DECLARE_SET_DEFAULT(uint8_t);
  19. DECLARE_SET_DEFAULT(uint16_t);
  20. DECLARE_SET_DEFAULT(uint32_t);
  21. DECLARE_SET_DEFAULT(int8_t);
  22. DECLARE_SET_DEFAULT(int16_t);
  23. DECLARE_SET_DEFAULT(int32_t);
  24. DECLARE_GET_NUM(uint8_t);
  25. DECLARE_GET_NUM(uint16_t);
  26. DECLARE_GET_NUM(uint32_t);
  27. DECLARE_GET_NUM(int8_t);
  28. DECLARE_GET_NUM(int16_t);
  29. DECLARE_GET_NUM(int32_t);
  30. bool config_has_changes();
  31. void config_commit_to_nvs();
  32. void config_start_timer();
  33. void config_init();
  34. void * config_alloc_get_default(nvs_type_t type, const char *key, void * default_value, size_t blob_size);
  35. void * config_alloc_get_str(const char *key, char *lead, char *fallback);
  36. void config_delete_key(const char *key);
  37. void config_set_default(nvs_type_t type, const char *key, void * default_value, size_t blob_size);
  38. void * config_alloc_get(nvs_type_t nvs_type, const char *key) ;
  39. bool wait_for_commit();
  40. char * config_alloc_get_json(bool bFormatted);
  41. esp_err_t config_set_value(nvs_type_t nvs_type, const char *key, const void * value);
  42. nvs_type_t config_get_item_type(cJSON * entry);
  43. void * config_safe_alloc_get_entry_value(nvs_type_t nvs_type, cJSON * entry);