|
@@ -31,6 +31,7 @@ Stopwatch print_job_timer; // Global Print Job Timer instance
|
31
|
31
|
|
32
|
32
|
#include "printcounter.h"
|
33
|
33
|
#include "../Marlin.h"
|
|
34
|
+#include "../HAL/persistent_store_api.h"
|
34
|
35
|
|
35
|
36
|
PrintCounter print_job_timer; // Global Print Job Timer instance
|
36
|
37
|
|
|
@@ -73,7 +74,12 @@ void PrintCounter::initStats() {
|
73
|
74
|
data = { 0, 0, 0, 0, 0.0 };
|
74
|
75
|
|
75
|
76
|
saveStats();
|
76
|
|
- eeprom_write_byte((uint8_t*)address, 0x16);
|
|
77
|
+
|
|
78
|
+ uint16_t crc = 0;
|
|
79
|
+ int a = address;
|
|
80
|
+ persistentStore.access_start();
|
|
81
|
+ persistentStore.write_data(a, (uint8_t*)0x16, sizeof(uint8_t), &crc);
|
|
82
|
+ persistentStore.access_finish();
|
77
|
83
|
}
|
78
|
84
|
|
79
|
85
|
void PrintCounter::loadStats() {
|
|
@@ -81,11 +87,18 @@ void PrintCounter::loadStats() {
|
81
|
87
|
debug(PSTR("loadStats"));
|
82
|
88
|
#endif
|
83
|
89
|
|
84
|
|
- // Checks if the EEPROM block is initialized
|
85
|
|
- if (eeprom_read_byte((uint8_t*)address) != 0x16) initStats();
|
86
|
|
- else eeprom_read_block(&data,
|
87
|
|
- (void*)(address + sizeof(uint8_t)), sizeof(printStatistics));
|
88
|
|
-
|
|
90
|
+ // Check if the EEPROM block is initialized
|
|
91
|
+ uint16_t crc = 0;
|
|
92
|
+ int a = address;
|
|
93
|
+ uint8_t value;
|
|
94
|
+ 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
|
+ }
|
|
101
|
+ persistentStore.access_finish();
|
89
|
102
|
loaded = true;
|
90
|
103
|
}
|
91
|
104
|
|
|
@@ -98,8 +111,11 @@ void PrintCounter::saveStats() {
|
98
|
111
|
if (!isLoaded()) return;
|
99
|
112
|
|
100
|
113
|
// Saves the struct to EEPROM
|
101
|
|
- eeprom_update_block(&data,
|
102
|
|
- (void*)(address + sizeof(uint8_t)), sizeof(printStatistics));
|
|
114
|
+ uint16_t crc = 0;
|
|
115
|
+ int a = (address + sizeof(uint8_t));
|
|
116
|
+ persistentStore.access_start();
|
|
117
|
+ persistentStore.write_data(a, (uint8_t*)&data, sizeof(printStatistics), &crc);
|
|
118
|
+ persistentStore.access_finish();
|
103
|
119
|
}
|
104
|
120
|
|
105
|
121
|
void PrintCounter::showStats() {
|