Browse Source

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

pull/1/head
Nils Hasenbanck 6 years ago
committed by Scott Lahteine
parent
commit
b37bfeffeb
  1. 6
      Marlin/src/HAL/shared/persistent_store_api.h
  2. 5
      Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp
  3. 23
      Marlin/src/module/printcounter.cpp

6
Marlin/src/HAL/shared/persistent_store_api.h

@ -33,13 +33,15 @@ public:
static bool read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing=true); static bool read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing=true);
static size_t capacity(); static size_t capacity();
static inline bool write_data(const int pos, uint8_t* value, const size_t size) { static inline bool write_data(const int pos, const uint8_t* value, const size_t size=sizeof(uint8_t)) {
int data_pos = pos; int data_pos = pos;
uint16_t crc = 0; uint16_t crc = 0;
return write_data(data_pos, value, size, &crc); return write_data(data_pos, value, size, &crc);
} }
static inline bool read_data(const int pos, uint8_t* value, const size_t size) { static inline bool write_data(const int pos, const uint8_t value) { return write_data(pos, &value); }
static inline bool read_data(const int pos, uint8_t* value, const size_t size=1) {
int data_pos = pos; int data_pos = pos;
uint16_t crc = 0; uint16_t crc = 0;
return read_data(data_pos, value, size, &crc); return read_data(data_pos, value, size, &crc);

5
Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp

@ -1169,8 +1169,6 @@
*/ */
void unified_bed_leveling::g29_eeprom_dump() { void unified_bed_leveling::g29_eeprom_dump() {
uint8_t cccc; uint8_t cccc;
int kkkk;
uint16_t crc = 0;
SERIAL_ECHO_START(); SERIAL_ECHO_START();
SERIAL_ECHOLNPGM("EEPROM Dump:"); SERIAL_ECHOLNPGM("EEPROM Dump:");
@ -1180,8 +1178,7 @@
print_hex_word(i); print_hex_word(i);
SERIAL_ECHOPGM(": "); SERIAL_ECHOPGM(": ");
for (uint16_t j = 0; j < 16; j++) { for (uint16_t j = 0; j < 16; j++) {
kkkk = i + j; persistentStore.read_data(i + j, &cccc, sizeof(uint8_t));
persistentStore.read_data(kkkk, &cccc, sizeof(uint8_t), &crc);
print_hex_byte(cccc); print_hex_byte(cccc);
SERIAL_ECHO(' '); SERIAL_ECHO(' ');
} }

23
Marlin/src/module/printcounter.cpp

@ -75,10 +75,8 @@ void PrintCounter::initStats() {
saveStats(); saveStats();
uint16_t crc = 0;
int a = address;
persistentStore.access_start(); persistentStore.access_start();
persistentStore.write_data(a, (uint8_t*)0x16, sizeof(uint8_t), &crc); persistentStore.write_data(address, (uint8_t)0x16);
persistentStore.access_finish(); persistentStore.access_finish();
} }
@ -88,16 +86,13 @@ void PrintCounter::loadStats() {
#endif #endif
// Check if the EEPROM block is initialized // Check if the EEPROM block is initialized
uint16_t crc = 0; uint8_t value = 0;
int a = address;
uint8_t value;
persistentStore.access_start(); persistentStore.access_start();
persistentStore.read_data(a, &value, sizeof(uint8_t), &crc); persistentStore.read_data(address, &value, sizeof(uint8_t));
if (value != 0x16) initStats(); if (value != 0x16)
else { initStats();
a = address + sizeof(uint8_t); else
persistentStore.read_data(a, (uint8_t*)&data, sizeof(printStatistics), &crc); persistentStore.read_data(address + sizeof(uint8_t), (uint8_t*)&data, sizeof(printStatistics));
}
persistentStore.access_finish(); persistentStore.access_finish();
loaded = true; loaded = true;
} }
@ -111,10 +106,8 @@ void PrintCounter::saveStats() {
if (!isLoaded()) return; if (!isLoaded()) return;
// Saves the struct to EEPROM // Saves the struct to EEPROM
uint16_t crc = 0;
int a = (address + sizeof(uint8_t));
persistentStore.access_start(); persistentStore.access_start();
persistentStore.write_data(a, (uint8_t*)&data, sizeof(printStatistics), &crc); persistentStore.write_data(address + sizeof(uint8_t), (uint8_t*)&data, sizeof(printStatistics));
persistentStore.access_finish(); persistentStore.access_finish();
} }

Loading…
Cancel
Save