25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.2 KiB

  1. #include "Config.h"
  2. #include "Debug.h"
  3. #include "Hardware.h"
  4. #define LOGGER_NAME "Config"
  5. namespace config {
  6. Config value;
  7. namespace details {
  8. void read() {
  9. VERBOSE("read");
  10. hardware::i2c::powerOn();
  11. hardware::i2c::eeprom.readBlock(CONFIG_ADDR, value);
  12. if (!String(CONFIG_SEED).equals(value.seed)) reset();
  13. hardware::i2c::powerOff();
  14. }
  15. void write() {
  16. VERBOSE_FORMAT("write", "%s, %s, %d, %d", value.seed, value.version, value.firstEntry, value.lastEntry);
  17. hardware::i2c::powerOn();
  18. int written = hardware::i2c::eeprom.writeBlock(CONFIG_ADDR, value);
  19. hardware::i2c::powerOff();
  20. }
  21. }
  22. Config get() {
  23. if (value.seed[0] == '\0') details::read();
  24. VERBOSE_FORMAT("get", "%s, %s, %d, %d", value.seed, value.version, value.firstEntry, value.lastEntry);
  25. return value;
  26. }
  27. void set(Config config) {
  28. value = config;
  29. details::write();
  30. }
  31. void reset() {
  32. VERBOSE("reset");
  33. Config config = {
  34. CONFIG_SEED,
  35. VERSION,
  36. "Vodafone", //TODO : read from SD
  37. 0xFFFF,
  38. 0xFFFF,
  39. };
  40. value = config;
  41. details::write();
  42. VERBOSE_FORMAT("reset", "value : %s, %s, %d, %d", value.seed, value.version, value.firstEntry, value.lastEntry);
  43. }
  44. }