Browse Source

Merge pull request #4298 from jbrazio/feature/filament-counter

Adds filamentUsed and longestPrint stats to PrintCounter
Scott Lahteine 8 years ago
parent
commit
02285662f5
4 changed files with 87 additions and 20 deletions
  1. 6
    0
      Marlin/Marlin_main.cpp
  2. 1
    0
      Marlin/language.h
  3. 68
    18
      Marlin/printcounter.cpp
  4. 12
    2
      Marlin/printcounter.h

+ 6
- 0
Marlin/Marlin_main.cpp View File

2564
     else
2564
     else
2565
       destination[i] = current_position[i];
2565
       destination[i] = current_position[i];
2566
   }
2566
   }
2567
+
2567
   if (code_seen('F') && code_value_linear_units() > 0.0)
2568
   if (code_seen('F') && code_value_linear_units() > 0.0)
2568
     feedrate = code_value_linear_units();
2569
     feedrate = code_value_linear_units();
2570
+
2571
+  #if ENABLED(PRINTCOUNTER)
2572
+    if(!DEBUGGING(DRYRUN))
2573
+      print_job_timer.incFilamentUsed(destination[E_AXIS] - current_position[E_AXIS]);
2574
+  #endif
2569
 }
2575
 }
2570
 
2576
 
2571
 void unknown_command_error() {
2577
 void unknown_command_error() {

+ 1
- 0
Marlin/language.h View File

119
 #define MSG_PLANNER_BUFFER_BYTES            "  PlannerBufferBytes: "
119
 #define MSG_PLANNER_BUFFER_BYTES            "  PlannerBufferBytes: "
120
 #define MSG_OK                              "ok"
120
 #define MSG_OK                              "ok"
121
 #define MSG_WAIT                            "wait"
121
 #define MSG_WAIT                            "wait"
122
+#define MSG_STATS                           "Stats: "
122
 #define MSG_FILE_SAVED                      "Done saving file."
123
 #define MSG_FILE_SAVED                      "Done saving file."
123
 #define MSG_ERR_LINE_NO                     "Line Number is not Last Line Number+1, Last Line: "
124
 #define MSG_ERR_LINE_NO                     "Line Number is not Last Line Number+1, Last Line: "
124
 #define MSG_ERR_CHECKSUM_MISMATCH           "checksum mismatch, Last Line: "
125
 #define MSG_ERR_CHECKSUM_MISMATCH           "checksum mismatch, Last Line: "

+ 68
- 18
Marlin/printcounter.cpp View File

41
   return this->loaded;
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
 void PrintCounter::initStats() {
56
 void PrintCounter::initStats() {
45
   #if ENABLED(DEBUG_PRINTCOUNTER)
57
   #if ENABLED(DEBUG_PRINTCOUNTER)
46
     PrintCounter::debug(PSTR("initStats"));
58
     PrintCounter::debug(PSTR("initStats"));
47
   #endif
59
   #endif
48
 
60
 
49
   this->loaded = true;
61
   this->loaded = true;
50
-  this->data = { 0, 0, 0, 0 };
62
+  this->data = { 0, 0, 0, 0, 0.0 };
51
 
63
 
52
   this->saveStats();
64
   this->saveStats();
53
   eeprom_write_byte((uint8_t *) this->address, 0x16);
65
   eeprom_write_byte((uint8_t *) this->address, 0x16);
60
 
72
 
61
   // Checks if the EEPROM block is initialized
73
   // Checks if the EEPROM block is initialized
62
   if (eeprom_read_byte((uint8_t *) this->address) != 0x16) this->initStats();
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
   this->loaded = true;
78
   this->loaded = true;
66
 }
79
 }
70
     PrintCounter::debug(PSTR("saveStats"));
83
     PrintCounter::debug(PSTR("saveStats"));
71
   #endif
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
   if (!this->isLoaded()) return;
87
   if (!this->isLoaded()) return;
75
 
88
 
76
   // Saves the struct to EEPROM
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
 void PrintCounter::showStats() {
94
 void PrintCounter::showStats() {
81
-  SERIAL_ECHOPGM("Print statistics: Total: ");
95
+  SERIAL_PROTOCOLPGM(MSG_STATS);
96
+
97
+  SERIAL_ECHOPGM("Prints: ");
82
   SERIAL_ECHO(this->data.totalPrints);
98
   SERIAL_ECHO(this->data.totalPrints);
83
 
99
 
84
   SERIAL_ECHOPGM(", Finished: ");
100
   SERIAL_ECHOPGM(", Finished: ");
85
   SERIAL_ECHO(this->data.finishedPrints);
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
   SERIAL_ECHO(this->data.totalPrints - this->data.finishedPrints
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
   SERIAL_ECHOPGM("h ");
117
   SERIAL_ECHOPGM("h ");
96
-  SERIAL_ECHO(t % 60); // minutes
97
 
118
 
119
+  SERIAL_ECHO(t % 60);
98
   SERIAL_ECHOPGM("min");
120
   SERIAL_ECHOPGM("min");
99
 
121
 
100
   #if ENABLED(DEBUG_PRINTCOUNTER)
122
   #if ENABLED(DEBUG_PRINTCOUNTER)
103
     SERIAL_ECHOPGM(")");
125
     SERIAL_ECHOPGM(")");
104
   #endif
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
   SERIAL_EOL;
153
   SERIAL_EOL;
108
 }
154
 }
109
 
155
 
110
 void PrintCounter::tick() {
156
 void PrintCounter::tick() {
111
   if (!this->isRunning()) return;
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
   millis_t now = millis();
162
   millis_t now = millis();
117
 
163
 
118
   // Trying to get the amount of calculations down to the bare min
164
   // Trying to get the amount of calculations down to the bare min
119
   const static uint16_t i = this->updateInterval * 1000;
165
   const static uint16_t i = this->updateInterval * 1000;
120
 
166
 
121
-  if (now - update_before >= i) {
167
+  if (now - update_last >= i) {
122
     #if ENABLED(DEBUG_PRINTCOUNTER)
168
     #if ENABLED(DEBUG_PRINTCOUNTER)
123
       PrintCounter::debug(PSTR("tick"));
169
       PrintCounter::debug(PSTR("tick"));
124
     #endif
170
     #endif
125
 
171
 
126
     this->data.printTime += this->deltaDuration();
172
     this->data.printTime += this->deltaDuration();
127
-    update_before = now;
173
+    update_last = now;
128
   }
174
   }
129
 
175
 
130
   // Trying to get the amount of calculations down to the bare min
176
   // Trying to get the amount of calculations down to the bare min
131
   const static millis_t j = this->saveInterval * 1000;
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
     this->saveStats();
180
     this->saveStats();
135
   }
181
   }
136
 }
182
 }
162
   if (super::stop()) {
208
   if (super::stop()) {
163
     this->data.finishedPrints++;
209
     this->data.finishedPrints++;
164
     this->data.printTime += this->deltaDuration();
210
     this->data.printTime += this->deltaDuration();
211
+
212
+    if (this->duration() > this->data.longestPrint)
213
+      this->data.longestPrint = this->duration();
214
+
165
     this->saveStats();
215
     this->saveStats();
166
     return true;
216
     return true;
167
   }
217
   }

+ 12
- 2
Marlin/printcounter.h View File

24
 #define PRINTCOUNTER_H
24
 #define PRINTCOUNTER_H
25
 
25
 
26
 #include "macros.h"
26
 #include "macros.h"
27
+#include "language.h"
27
 #include "stopwatch.h"
28
 #include "stopwatch.h"
28
 #include <avr/eeprom.h>
29
 #include <avr/eeprom.h>
29
 
30
 
35
   //const uint8_t magic;    // Magic header, it will always be 0x16
36
   //const uint8_t magic;    // Magic header, it will always be 0x16
36
   uint16_t totalPrints;     // Number of prints
37
   uint16_t totalPrints;     // Number of prints
37
   uint16_t finishedPrints;  // Number of complete prints
38
   uint16_t finishedPrints;  // Number of complete prints
38
-  millis_t printTime;       // Total printing time
39
-  millis_t longestPrint;    // Longest print job - not in use
39
+  uint32_t printTime;       // Accumulated printing time
40
+  uint32_t longestPrint;    // Longest successfull print job
41
+  double   filamentUsed;    // Accumulated filament consumed in mm
40
 };
42
 };
41
 
43
 
42
 class PrintCounter: public Stopwatch {
44
 class PrintCounter: public Stopwatch {
106
     bool isLoaded();
108
     bool isLoaded();
107
 
109
 
108
     /**
110
     /**
111
+     * @brief Increments the total filament used
112
+     * @details The total filament used counter will be incremented by "amount".
113
+     *
114
+     * @param amount The amount of filament used in mm
115
+     */
116
+    void incFilamentUsed(double const &amount);
117
+
118
+    /**
109
      * @brief Resets the Print Statistics
119
      * @brief Resets the Print Statistics
110
      * @details Resets the statistics to zero and saves them to EEPROM creating
120
      * @details Resets the statistics to zero and saves them to EEPROM creating
111
      * also the magic header.
121
      * also the magic header.

Loading…
Cancel
Save