Bladeren bron

[2.0.x] Use the new const functions of the persistentStore api (#11544)

Nils Hasenbanck 6 jaren geleden
bovenliggende
commit
b37bfeffeb

+ 4
- 2
Marlin/src/HAL/shared/persistent_store_api.h Bestand weergeven

@@ -33,13 +33,15 @@ public:
33 33
   static bool read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing=true);
34 34
   static size_t capacity();
35 35
 
36
-  static inline bool write_data(const int pos, uint8_t* value, const size_t size) {
36
+  static inline bool write_data(const int pos, const uint8_t* value, const size_t size=sizeof(uint8_t)) {
37 37
     int data_pos = pos;
38 38
     uint16_t crc = 0;
39 39
     return write_data(data_pos, value, size, &crc);
40 40
   }
41 41
 
42
-  static inline bool read_data(const int pos, uint8_t* value, const size_t size) {
42
+  static inline bool write_data(const int pos, const uint8_t value) { return write_data(pos, &value); }
43
+
44
+  static inline bool read_data(const int pos, uint8_t* value, const size_t size=1) {
43 45
     int data_pos = pos;
44 46
     uint16_t crc = 0;
45 47
     return read_data(data_pos, value, size, &crc);

+ 1
- 4
Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp Bestand weergeven

@@ -1169,8 +1169,6 @@
1169 1169
    */
1170 1170
   void unified_bed_leveling::g29_eeprom_dump() {
1171 1171
     uint8_t cccc;
1172
-    int kkkk;
1173
-    uint16_t crc = 0;
1174 1172
 
1175 1173
     SERIAL_ECHO_START();
1176 1174
     SERIAL_ECHOLNPGM("EEPROM Dump:");
@@ -1180,8 +1178,7 @@
1180 1178
       print_hex_word(i);
1181 1179
       SERIAL_ECHOPGM(": ");
1182 1180
       for (uint16_t j = 0; j < 16; j++) {
1183
-        kkkk = i + j;
1184
-        persistentStore.read_data(kkkk, &cccc, sizeof(uint8_t), &crc);
1181
+        persistentStore.read_data(i + j, &cccc, sizeof(uint8_t));
1185 1182
         print_hex_byte(cccc);
1186 1183
         SERIAL_ECHO(' ');
1187 1184
       }

+ 8
- 15
Marlin/src/module/printcounter.cpp Bestand weergeven

@@ -75,10 +75,8 @@ void PrintCounter::initStats() {
75 75
 
76 76
   saveStats();
77 77
 
78
-  uint16_t crc = 0;
79
-  int a = address;
80 78
   persistentStore.access_start();
81
-  persistentStore.write_data(a, (uint8_t*)0x16, sizeof(uint8_t), &crc);
79
+  persistentStore.write_data(address, (uint8_t)0x16);
82 80
   persistentStore.access_finish();
83 81
 }
84 82
 
@@ -88,16 +86,13 @@ void PrintCounter::loadStats() {
88 86
   #endif
89 87
 
90 88
   // Check if the EEPROM block is initialized
91
-  uint16_t crc = 0;
92
-  int a = address;
93
-  uint8_t value;
89
+  uint8_t value = 0;
94 90
   persistentStore.access_start();
95
-  persistentStore.read_data(a, &value, sizeof(uint8_t), &crc);
96
-  if (value != 0x16) initStats();
97
-  else {
98
-    a = address + sizeof(uint8_t);
99
-    persistentStore.read_data(a, (uint8_t*)&data, sizeof(printStatistics), &crc);
100
-  }
91
+  persistentStore.read_data(address, &value, sizeof(uint8_t));
92
+  if (value != 0x16)
93
+    initStats();
94
+  else
95
+    persistentStore.read_data(address + sizeof(uint8_t), (uint8_t*)&data, sizeof(printStatistics));
101 96
   persistentStore.access_finish();
102 97
   loaded = true;
103 98
 }
@@ -111,10 +106,8 @@ void PrintCounter::saveStats() {
111 106
   if (!isLoaded()) return;
112 107
 
113 108
   // Saves the struct to EEPROM
114
-  uint16_t crc = 0;
115
-  int a = (address + sizeof(uint8_t));
116 109
   persistentStore.access_start();
117
-  persistentStore.write_data(a, (uint8_t*)&data, sizeof(printStatistics), &crc);
110
+  persistentStore.write_data(address + sizeof(uint8_t), (uint8_t*)&data, sizeof(printStatistics));
118 111
   persistentStore.access_finish();
119 112
 }
120 113
 

Laden…
Annuleren
Opslaan