|
@@ -41,13 +41,25 @@ bool PrintCounter::isLoaded() {
|
41
|
41
|
return this->loaded;
|
42
|
42
|
}
|
43
|
43
|
|
|
44
|
+void PrintCounter::incFilamentUsed(double const &amount) {
|
|
45
|
+ #if ENABLED(DEBUG_PRINTCOUNTER)
|
|
46
|
+ PrintCounter::debug(PSTR("incFilamentUsed"));
|
|
47
|
+ #endif
|
|
48
|
+
|
|
49
|
+ // Refuses to update data if object is not loaded
|
|
50
|
+ if (!this->isLoaded()) return;
|
|
51
|
+
|
|
52
|
+ this->data.filamentUsed += amount; // mm
|
|
53
|
+}
|
|
54
|
+
|
|
55
|
+
|
44
|
56
|
void PrintCounter::initStats() {
|
45
|
57
|
#if ENABLED(DEBUG_PRINTCOUNTER)
|
46
|
58
|
PrintCounter::debug(PSTR("initStats"));
|
47
|
59
|
#endif
|
48
|
60
|
|
49
|
61
|
this->loaded = true;
|
50
|
|
- this->data = { 0, 0, 0, 0 };
|
|
62
|
+ this->data = { 0, 0, 0, 0, 0.0 };
|
51
|
63
|
|
52
|
64
|
this->saveStats();
|
53
|
65
|
eeprom_write_byte((uint8_t *) this->address, 0x16);
|
|
@@ -60,7 +72,8 @@ void PrintCounter::loadStats() {
|
60
|
72
|
|
61
|
73
|
// Checks if the EEPROM block is initialized
|
62
|
74
|
if (eeprom_read_byte((uint8_t *) this->address) != 0x16) this->initStats();
|
63
|
|
- else eeprom_read_block(&this->data, (void *)(this->address + sizeof(uint8_t)), sizeof(printStatistics));
|
|
75
|
+ else eeprom_read_block(&this->data,
|
|
76
|
+ (void *)(this->address + sizeof(uint8_t)), sizeof(printStatistics));
|
64
|
77
|
|
65
|
78
|
this->loaded = true;
|
66
|
79
|
}
|
|
@@ -70,31 +83,40 @@ void PrintCounter::saveStats() {
|
70
|
83
|
PrintCounter::debug(PSTR("saveStats"));
|
71
|
84
|
#endif
|
72
|
85
|
|
73
|
|
- // Refuses to save data is object is not loaded
|
|
86
|
+ // Refuses to save data if object is not loaded
|
74
|
87
|
if (!this->isLoaded()) return;
|
75
|
88
|
|
76
|
89
|
// Saves the struct to EEPROM
|
77
|
|
- eeprom_update_block(&this->data, (void *)(this->address + sizeof(uint8_t)), sizeof(printStatistics));
|
|
90
|
+ eeprom_update_block(&this->data,
|
|
91
|
+ (void *)(this->address + sizeof(uint8_t)), sizeof(printStatistics));
|
78
|
92
|
}
|
79
|
93
|
|
80
|
94
|
void PrintCounter::showStats() {
|
81
|
|
- SERIAL_ECHOPGM("Print statistics: Total: ");
|
|
95
|
+ SERIAL_PROTOCOLPGM(MSG_STATS);
|
|
96
|
+
|
|
97
|
+ SERIAL_ECHOPGM("Prints: ");
|
82
|
98
|
SERIAL_ECHO(this->data.totalPrints);
|
83
|
99
|
|
84
|
100
|
SERIAL_ECHOPGM(", Finished: ");
|
85
|
101
|
SERIAL_ECHO(this->data.finishedPrints);
|
86
|
102
|
|
87
|
|
- SERIAL_ECHOPGM(", Failed: ");
|
|
103
|
+ SERIAL_ECHOPGM(", Failed: "); // Note: Removes 1 from failures with an active counter
|
88
|
104
|
SERIAL_ECHO(this->data.totalPrints - this->data.finishedPrints
|
89
|
|
- - ((this->isRunning() || this->isPaused()) ? 1 : 0)); // Removes 1 from failures with an active counter
|
|
105
|
+ - ((this->isRunning() || this->isPaused()) ? 1 : 0));
|
|
106
|
+
|
|
107
|
+ SERIAL_EOL;
|
|
108
|
+ SERIAL_PROTOCOLPGM(MSG_STATS);
|
90
|
109
|
|
91
|
|
- millis_t t = this->data.printTime / 60; // minutes from seconds
|
92
|
|
- SERIAL_ECHOPGM(", Total print time: ");
|
93
|
|
- SERIAL_ECHO(t / 60); // hours
|
|
110
|
+ uint32_t t = this->data.printTime / 60;
|
|
111
|
+ SERIAL_ECHOPGM("Total time: ");
|
94
|
112
|
|
|
113
|
+ SERIAL_ECHO(t / 60 / 24);
|
|
114
|
+ SERIAL_ECHOPGM("d ");
|
|
115
|
+
|
|
116
|
+ SERIAL_ECHO((t / 60) % 24);
|
95
|
117
|
SERIAL_ECHOPGM("h ");
|
96
|
|
- SERIAL_ECHO(t % 60); // minutes
|
97
|
118
|
|
|
119
|
+ SERIAL_ECHO(t % 60);
|
98
|
120
|
SERIAL_ECHOPGM("min");
|
99
|
121
|
|
100
|
122
|
#if ENABLED(DEBUG_PRINTCOUNTER)
|
|
@@ -103,34 +125,58 @@ void PrintCounter::showStats() {
|
103
|
125
|
SERIAL_ECHOPGM(")");
|
104
|
126
|
#endif
|
105
|
127
|
|
106
|
|
- // @todo longestPrint missing implementation
|
|
128
|
+ uint32_t l = this->data.longestPrint / 60;
|
|
129
|
+ SERIAL_ECHOPGM(", Longest job: ");
|
|
130
|
+
|
|
131
|
+ SERIAL_ECHO(l / 60 / 24);
|
|
132
|
+ SERIAL_ECHOPGM("d ");
|
|
133
|
+
|
|
134
|
+ SERIAL_ECHO((l / 60) % 24);
|
|
135
|
+ SERIAL_ECHOPGM("h ");
|
|
136
|
+
|
|
137
|
+ SERIAL_ECHO(l % 60);
|
|
138
|
+ SERIAL_ECHOPGM("min");
|
|
139
|
+
|
|
140
|
+ #if ENABLED(DEBUG_PRINTCOUNTER)
|
|
141
|
+ SERIAL_ECHOPGM(" (");
|
|
142
|
+ SERIAL_ECHO(this->data.longestPrint);
|
|
143
|
+ SERIAL_ECHOPGM(")");
|
|
144
|
+ #endif
|
|
145
|
+
|
|
146
|
+ SERIAL_EOL;
|
|
147
|
+ SERIAL_PROTOCOLPGM(MSG_STATS);
|
|
148
|
+
|
|
149
|
+ SERIAL_ECHOPGM("Filament used: ");
|
|
150
|
+ SERIAL_ECHO(this->data.filamentUsed / 1000);
|
|
151
|
+ SERIAL_ECHOPGM("m");
|
|
152
|
+
|
107
|
153
|
SERIAL_EOL;
|
108
|
154
|
}
|
109
|
155
|
|
110
|
156
|
void PrintCounter::tick() {
|
111
|
157
|
if (!this->isRunning()) return;
|
112
|
158
|
|
113
|
|
- static millis_t update_before = millis(),
|
114
|
|
- eeprom_before = millis();
|
|
159
|
+ static uint32_t update_last = millis(),
|
|
160
|
+ eeprom_last = millis();
|
115
|
161
|
|
116
|
162
|
millis_t now = millis();
|
117
|
163
|
|
118
|
164
|
// Trying to get the amount of calculations down to the bare min
|
119
|
165
|
const static uint16_t i = this->updateInterval * 1000;
|
120
|
166
|
|
121
|
|
- if (now - update_before >= i) {
|
|
167
|
+ if (now - update_last >= i) {
|
122
|
168
|
#if ENABLED(DEBUG_PRINTCOUNTER)
|
123
|
169
|
PrintCounter::debug(PSTR("tick"));
|
124
|
170
|
#endif
|
125
|
171
|
|
126
|
172
|
this->data.printTime += this->deltaDuration();
|
127
|
|
- update_before = now;
|
|
173
|
+ update_last = now;
|
128
|
174
|
}
|
129
|
175
|
|
130
|
176
|
// Trying to get the amount of calculations down to the bare min
|
131
|
177
|
const static millis_t j = this->saveInterval * 1000;
|
132
|
|
- if (now - eeprom_before >= j) {
|
133
|
|
- eeprom_before = now;
|
|
178
|
+ if (now - eeprom_last >= j) {
|
|
179
|
+ eeprom_last = now;
|
134
|
180
|
this->saveStats();
|
135
|
181
|
}
|
136
|
182
|
}
|
|
@@ -162,6 +208,10 @@ bool PrintCounter::stop() {
|
162
|
208
|
if (super::stop()) {
|
163
|
209
|
this->data.finishedPrints++;
|
164
|
210
|
this->data.printTime += this->deltaDuration();
|
|
211
|
+
|
|
212
|
+ if (this->duration() > this->data.longestPrint)
|
|
213
|
+ this->data.longestPrint = this->duration();
|
|
214
|
+
|
165
|
215
|
this->saveStats();
|
166
|
216
|
return true;
|
167
|
217
|
}
|