configuration.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include "configuration.h"
  2. #include <SmingCore.h>
  3. ClockConfig ActiveConfig;
  4. ClockConfig loadConfig(void)
  5. {
  6. DynamicJsonDocument doc(1024);
  7. ClockConfig cfg;
  8. if(Json::loadFromFile(doc, CLOCK_CONFIG_FILE)) {
  9. JsonObject network = doc["network"];
  10. cfg.NetworkSSID = network["ssid"].as<const char*>();
  11. cfg.NetworkPassword = network["password"].as<const char*>();
  12. JsonObject correction = doc["correction"];
  13. cfg.AddTZ = correction["TZ"];
  14. JsonObject bright = doc["bright"];
  15. cfg.BrightnessLow = bright["low"];
  16. cfg.BrightnessMiddle = bright["mid"];
  17. cfg.BrightnessHigh = bright["high"];
  18. } else {
  19. cfg.NetworkSSID = WIFI_SSID;
  20. cfg.NetworkPassword = WIFI_PWD;
  21. }
  22. return cfg;
  23. }
  24. void saveConfig(ClockConfig& cfg)
  25. {
  26. ActiveConfig = cfg;
  27. DynamicJsonDocument doc(1024);
  28. auto network = doc.createNestedObject("network");
  29. network["ssid"] = cfg.NetworkSSID;
  30. network["password"] = cfg.NetworkPassword;
  31. auto correction = doc.createNestedObject("correction");
  32. correction["TZ"] = cfg.AddTZ;
  33. auto bright = doc.createNestedObject("bright");
  34. bright["low"] = cfg.BrightnessLow;
  35. bright["mid"] = cfg.BrightnessMiddle;
  36. bright["high"] = cfg.BrightnessHigh;
  37. Json::saveToFile(doc, CLOCK_CONFIG_FILE, Json::Pretty);
  38. }