Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

73 Zeilen
1.3 KiB

  1. #include "SdPositionsConfig.h"
  2. #include "SdCard.h"
  3. #include "RawSdFile.h"
  4. #include "Debug.h"
  5. using namespace sd;
  6. #define LOGGER_NAME "Config::backup::sd"
  7. namespace config {
  8. namespace backup {
  9. namespace sd {
  10. SdPositionConfig_t value;
  11. File configFile;
  12. namespace details {
  13. void ensureOpened() {
  14. if (!configFile.isOpen()) {
  15. hardware::sdcard::filesystem.chdir();
  16. configFile.open(POSITIONS_CONFIG_FILENAME, O_RDWR | O_CREAT);
  17. }
  18. configFile.rewind();
  19. }
  20. void read() {
  21. VERBOSE("read");
  22. ensureOpened();
  23. configFile.read((void*)&value, sizeof(value));
  24. if (value.seed != POSITIONS_CONFIG_SEED) reset();
  25. }
  26. void write() {
  27. VERBOSE("write");
  28. ensureOpened();
  29. configFile.write((void*)&value, sizeof(value));
  30. }
  31. }
  32. void setup() { }
  33. SdPositionConfig_t get() {
  34. if (value.seed != POSITIONS_CONFIG_SEED) details::read();
  35. return value;
  36. }
  37. void set(SdPositionConfig_t config) {
  38. value = config;
  39. details::write();
  40. }
  41. void reset() {
  42. VERBOSE("reset");
  43. SdPositionConfig_t config = {
  44. POSITIONS_CONFIG_SEED,
  45. POSITIONS_CONFIG_DeFAULT_SAVE_THRESHOLD,
  46. 0xFFFF,
  47. 0,
  48. 0,
  49. 0
  50. };
  51. value = config;
  52. details::write();
  53. }
  54. }
  55. }
  56. }