|
@@ -28,6 +28,16 @@ PrintCounter::PrintCounter(): super() {
|
28
|
28
|
this->loadStats();
|
29
|
29
|
}
|
30
|
30
|
|
|
31
|
+uint16_t PrintCounter::deltaDuration() {
|
|
32
|
+ #if ENABLED(DEBUG_PRINTCOUNTER)
|
|
33
|
+ PrintCounter::debug(PSTR("deltaDuration"));
|
|
34
|
+ #endif
|
|
35
|
+
|
|
36
|
+ uint16_t tmp = this->lastDuration;
|
|
37
|
+ this->lastDuration = this->duration();
|
|
38
|
+ return this->lastDuration - tmp;
|
|
39
|
+}
|
|
40
|
+
|
31
|
41
|
bool PrintCounter::isLoaded() {
|
32
|
42
|
return this->loaded;
|
33
|
43
|
}
|
|
@@ -38,9 +48,7 @@ void PrintCounter::initStats() {
|
38
|
48
|
#endif
|
39
|
49
|
|
40
|
50
|
this->loaded = true;
|
41
|
|
- this->data = {
|
42
|
|
- 0, 0, 0, 0
|
43
|
|
- };
|
|
51
|
+ this->data = { 0, 0, 0, 0 };
|
44
|
52
|
|
45
|
53
|
this->saveStats();
|
46
|
54
|
eeprom_write_byte((uint8_t*) this->addr, 0x16);
|
|
@@ -51,28 +59,9 @@ void PrintCounter::loadStats() {
|
51
|
59
|
PrintCounter::debug(PSTR("loadStats"));
|
52
|
60
|
#endif
|
53
|
61
|
|
54
|
|
- uint16_t addr = this->addr;
|
55
|
|
-
|
56
|
62
|
// Checks if the EEPROM block is initialized
|
57
|
|
- if (eeprom_read_byte((uint8_t*) addr) != 0x16) this->initStats();
|
58
|
|
-
|
59
|
|
- else {
|
60
|
|
- // Skip the magic header byte
|
61
|
|
- addr += sizeof(uint8_t);
|
62
|
|
-
|
63
|
|
- // @todo This section will need rewrite once the ConfigurationStore
|
64
|
|
- // and/or PersistentStorage object comes along.
|
65
|
|
- this->data.totalPrints = eeprom_read_word((uint16_t*) addr);
|
66
|
|
- addr += sizeof(uint16_t);
|
67
|
|
-
|
68
|
|
- this->data.finishedPrints = eeprom_read_word((uint16_t*) addr);
|
69
|
|
- addr += sizeof(uint16_t);
|
70
|
|
-
|
71
|
|
- this->data.printTime = eeprom_read_dword((uint32_t*) addr);
|
72
|
|
- addr += sizeof(uint32_t);
|
73
|
|
-
|
74
|
|
- this->data.longestPrint = eeprom_read_dword((uint32_t*) addr);
|
75
|
|
- }
|
|
63
|
+ if (eeprom_read_byte((uint8_t*) this->addr) != 0x16) this->initStats();
|
|
64
|
+ else eeprom_read_block(&this->data, (void *)(this->addr + sizeof(uint8_t)), sizeof(printStatistics));
|
76
|
65
|
|
77
|
66
|
this->loaded = true;
|
78
|
67
|
}
|
|
@@ -85,21 +74,7 @@ void PrintCounter::saveStats() {
|
85
|
74
|
// Refuses to save data is object is not loaded
|
86
|
75
|
if (!this->isLoaded()) return;
|
87
|
76
|
|
88
|
|
- // Skip the magic header byte
|
89
|
|
- uint16_t addr = this->addr + sizeof(uint8_t);
|
90
|
|
-
|
91
|
|
- // @todo This section will need rewrite once the ConfigurationStore
|
92
|
|
- // and/or PersistentStorage object comes along.
|
93
|
|
- eeprom_write_word ((uint16_t*) addr, this->data.totalPrints);
|
94
|
|
- addr += sizeof(uint16_t);
|
95
|
|
-
|
96
|
|
- eeprom_write_word ((uint16_t*) addr, this->data.finishedPrints);
|
97
|
|
- addr += sizeof(uint16_t);
|
98
|
|
-
|
99
|
|
- eeprom_write_dword((uint32_t*) addr, this->data.printTime);
|
100
|
|
- addr += sizeof(uint32_t);
|
101
|
|
-
|
102
|
|
- eeprom_write_dword((uint32_t*) addr, this->data.longestPrint);
|
|
77
|
+ eeprom_write_block(&this->data, (void *)(this->addr + sizeof(uint8_t)), sizeof(printStatistics));
|
103
|
78
|
}
|
104
|
79
|
|
105
|
80
|
void PrintCounter::showStats() {
|
|
@@ -110,7 +85,8 @@ void PrintCounter::showStats() {
|
110
|
85
|
SERIAL_ECHO(this->data.finishedPrints);
|
111
|
86
|
|
112
|
87
|
SERIAL_ECHOPGM(", Failed: ");
|
113
|
|
- SERIAL_ECHO(this->data.totalPrints - this->data.finishedPrints);
|
|
88
|
+ SERIAL_ECHO(this->data.totalPrints - this->data.finishedPrints
|
|
89
|
+ - (this->isRunning() || this->isPaused()) ? 1 : 0); // Removes 1 from failures with an active counter
|
114
|
90
|
|
115
|
91
|
uint32_t t = this->data.printTime /60;
|
116
|
92
|
SERIAL_ECHOPGM(", Total print time: ");
|
|
@@ -148,8 +124,7 @@ void PrintCounter::tick() {
|
148
|
124
|
#endif
|
149
|
125
|
|
150
|
126
|
uint16_t t = this->duration();;
|
151
|
|
- this->data.printTime += t - this->lastUpdate;
|
152
|
|
- this->lastUpdate = t;
|
|
127
|
+ this->data.printTime += this->deltaDuration();
|
153
|
128
|
update_before = now;
|
154
|
129
|
}
|
155
|
130
|
|
|
@@ -178,7 +153,7 @@ void PrintCounter::stop() {
|
178
|
153
|
|
179
|
154
|
super::stop();
|
180
|
155
|
this->data.finishedPrints++;
|
181
|
|
- this->data.printTime += this->duration() - this->lastUpdate;
|
|
156
|
+ this->data.printTime += this->deltaDuration();
|
182
|
157
|
this->saveStats();
|
183
|
158
|
}
|
184
|
159
|
|
|
@@ -187,7 +162,7 @@ void PrintCounter::reset() {
|
187
|
162
|
PrintCounter::debug(PSTR("stop"));
|
188
|
163
|
#endif
|
189
|
164
|
|
190
|
|
- this->lastUpdate = 0;
|
|
165
|
+ this->lastDuration = 0;
|
191
|
166
|
super::reset();
|
192
|
167
|
}
|
193
|
168
|
|