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.

65 rivejä
1.3 KiB

  1. #include "Config.h"
  2. #include "Debug.h"
  3. #include "Hardware.h"
  4. #define LOGGER_NAME "Config"
  5. namespace config {
  6. namespace main {
  7. config_t value;
  8. namespace details {
  9. void read() {
  10. VERBOSE("read");
  11. hardware::i2c::powerOn();
  12. hardware::i2c::eeprom.readBlock(CONFIG_ADDR, value);
  13. if (CONFIG_SEED != value.seed) reset(); //todo : reset network if seed for network is not right
  14. hardware::i2c::powerOff();
  15. }
  16. void write() {
  17. VERBOSE_FORMAT("write", "%d, %s, %s, %d, %d", value.seed, value.version, value.firstEntry, value.lastEntry);
  18. hardware::i2c::powerOn();
  19. int written = hardware::i2c::eeprom.writeBlock(CONFIG_ADDR, value);
  20. hardware::i2c::powerOff();
  21. }
  22. }
  23. config_t get() {
  24. if (value.seed == 0) details::read();
  25. VERBOSE_FORMAT("get", "%d, %s, %s, %d, %d", value.seed, value.version, value.firstEntry, value.lastEntry);
  26. return value;
  27. }
  28. void set(const config_t config) {
  29. value = config;
  30. details::write();
  31. }
  32. void reset() {
  33. VERBOSE("reset");
  34. config_t config = {
  35. CONFIG_SEED,
  36. VERSION,
  37. 0xFFFF,
  38. 0xFFFF,
  39. #if BACKUP_ENABLE_NETWORK
  40. {
  41. POSITIONS_CONFIG_DEFAULT_SAVE_THRESHOLD,
  42. 0xFFFF,
  43. POSITIONS_CONFIG_DEFAULT_APN,
  44. POSITIONS_CONFIG_DEFAULT_URL,
  45. },
  46. #endif
  47. };
  48. value = config;
  49. details::write();
  50. }
  51. }
  52. }