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

89 lines
2.6 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. NOTICE_FORMAT("read", "%d, %s, %d, %d, %d, %d, %d, %B, %s", value.seed, value.version, value.firstEntry, value.lastEntry, value.alertBatteryLevel1, value.alertBatteryLevel2, value.alertBatteryLevelClear, value.activeAlerts, value.contactPhone);
  16. #if BACKUP_ENABLE_NETWORK
  17. NOTICE_FORMAT("read", "%d, %d, %s, %s", value.network.saveThreshold, value.network.lastSavedEntry, value.network.apn, value.network.url);
  18. //networkConfig_t c = {
  19. // POSITIONS_CONFIG_NET_DEFAULT_SAVE_THRESHOLD,
  20. // 0xFFFF,
  21. // POSITIONS_CONFIG_NET_DEFAULT_APN,
  22. // POSITIONS_CONFIG_NET_DEFAULT_URL,
  23. //};
  24. //value.network = c;
  25. #endif
  26. /*strcpy(value.version, VERSION);
  27. value.alertBatteryLevel1 = CONFIG_DEFAULT_BATTERY_ALERT_LEVEL1;
  28. value.alertBatteryLevel2 = CONFIG_DEFAULT_BATTERY_ALERT_LEVEL2;
  29. value.alertBatteryLevelClear = CONFIG_DEFAULT_BATTERY_ALERT_CLEAR;
  30. value.activeAlerts = 0;
  31. strcpy(value.contactPhone, CONFIG_DEFAULT_CONTACT_PHONE);*/
  32. }
  33. void write() {
  34. NOTICE_FORMAT("write", "%d, %s, %d, %d, %d, %d, %d, %B, %s", value.seed, value.version, value.firstEntry, value.lastEntry, value.alertBatteryLevel1, value.alertBatteryLevel2, value.alertBatteryLevelClear, value.activeAlerts, value.contactPhone);
  35. #if BACKUP_ENABLE_NETWORK
  36. NOTICE_FORMAT("write", "%d, %d, %s, %s", value.network.saveThreshold, value.network.lastSavedEntry, value.network.apn, value.network.url);
  37. #endif
  38. hardware::i2c::powerOn();
  39. int written = hardware::i2c::eeprom.writeBlock(CONFIG_ADDR, value);
  40. hardware::i2c::powerOff();
  41. }
  42. }
  43. void setup() {
  44. details::read();
  45. //details::write();
  46. }
  47. void save() {
  48. details::write();
  49. }
  50. void reset() {
  51. VERBOSE("reset");
  52. config_t config = {
  53. CONFIG_SEED,
  54. VERSION,
  55. 0xFFFF,
  56. 0xFFFF,
  57. #if BACKUP_ENABLE_NETWORK
  58. {
  59. POSITIONS_CONFIG_NET_DEFAULT_SAVE_THRESHOLD,
  60. 0xFFFF,
  61. POSITIONS_CONFIG_NET_DEFAULT_APN,
  62. POSITIONS_CONFIG_NET_DEFAULT_URL,
  63. },
  64. CONFIG_DEFAULT_BATTERY_ALERT_LEVEL1,
  65. CONFIG_DEFAULT_BATTERY_ALERT_LEVEL2,
  66. CONFIG_DEFAULT_BATTERY_ALERT_CLEAR,
  67. 0,
  68. CONFIG_DEFAULT_CONTACT_PHONE
  69. #endif
  70. };
  71. value = config;
  72. save();
  73. }
  74. }
  75. }