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,8 +2564,14 @@ void gcode_get_destination() {
2564 2564
     else
2565 2565
       destination[i] = current_position[i];
2566 2566
   }
2567
+
2567 2568
   if (code_seen('F') && code_value_linear_units() > 0.0)
2568 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 2577
 void unknown_command_error() {

+ 1
- 0
Marlin/language.h View File

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

+ 68
- 18
Marlin/printcounter.cpp View File

@@ -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
   }

+ 12
- 2
Marlin/printcounter.h View File

@@ -24,6 +24,7 @@
24 24
 #define PRINTCOUNTER_H
25 25
 
26 26
 #include "macros.h"
27
+#include "language.h"
27 28
 #include "stopwatch.h"
28 29
 #include <avr/eeprom.h>
29 30
 
@@ -35,8 +36,9 @@ struct printStatistics {    // 13 bytes
35 36
   //const uint8_t magic;    // Magic header, it will always be 0x16
36 37
   uint16_t totalPrints;     // Number of prints
37 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 44
 class PrintCounter: public Stopwatch {
@@ -106,6 +108,14 @@ class PrintCounter: public Stopwatch {
106 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 119
      * @brief Resets the Print Statistics
110 120
      * @details Resets the statistics to zero and saves them to EEPROM creating
111 121
      * also the magic header.

Loading…
Cancel
Save