您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

42 行
976 B

  1. #include "Config.h"
  2. #include "Debug.h"
  3. #include "Hardware.h"
  4. #define LOGGER_NAME "Config"
  5. namespace config {
  6. Config value;
  7. void write() {
  8. VERBOSE_FORMAT("writeConfig", "%s, %s, %d, %d", value.seed, value.version, value.firstEntry, value.lastEntry);
  9. hardware::i2c::eepromPowerOn();
  10. int written = hardware::i2c::eeprom.writeBlock(CONFIG_ADDR, value);
  11. hardware::i2c::eepromPowerOff();
  12. }
  13. void reset() {
  14. VERBOSE("resetConfig");
  15. Config config = {
  16. CONFIG_SEED,
  17. VERSION,
  18. 0,
  19. 0
  20. };
  21. value = config;
  22. write();
  23. VERBOSE_FORMAT("resetConfig", "value : %s, %s, %d, %d", value.seed, value.version, value.firstEntry, value.lastEntry);
  24. }
  25. void read() {
  26. hardware::i2c::eepromPowerOn();
  27. hardware::i2c::eeprom.readBlock(CONFIG_ADDR, value);
  28. if (!String(CONFIG_SEED).equals(value.seed)) reset();
  29. hardware::i2c::eepromPowerOff();
  30. VERBOSE_FORMAT("readConfig", "%s, %s, %d, %d", value.seed, value.version, value.firstEntry, value.lastEntry);
  31. }
  32. }