Browse Source

Merge pull request #3625 from jbrazio/feature/print-counter

Print job statistics
Scott Lahteine 8 years ago
parent
commit
c3ef9993b9

+ 7
- 1
.travis.yml View File

@@ -139,7 +139,7 @@ script:
139 139
   ### I2C PANELS ###
140 140
   #
141 141
   # LCD_I2C_SAINSMART_YWROBOT
142
-  # Failing at the moment needs different library 
142
+  # Failing at the moment needs different library
143 143
   #- restore_configs
144 144
   #- opt_enable LCD_I2C_SAINSMART_YWROBOT
145 145
   #- build_marlin
@@ -199,6 +199,12 @@ script:
199 199
   - opt_set_adv Z2_MAX_PIN 2
200 200
   - build_marlin
201 201
   #
202
+  # Test PRINTCOUNTER
203
+  #
204
+  - restore_configs
205
+  - opt_enable PRINTCOUNTER
206
+  - build_marlin
207
+  #
202 208
   #
203 209
   ######## Example Configurations ##############
204 210
   #

+ 13
- 0
Marlin/Configuration.h View File

@@ -757,6 +757,19 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l
757 757
 #define ABS_PREHEAT_HPB_TEMP 110
758 758
 #define ABS_PREHEAT_FAN_SPEED 0   // Insert Value between 0 and 255
759 759
 
760
+
761
+//
762
+// Print Counter
763
+//
764
+// When enabled Marlin will keep track of some print statistical data such as:
765
+//  - Total print jobs
766
+//  - Total successful print jobs
767
+//  - Total failed print jobs
768
+//  - Total time printing
769
+//
770
+// This information can be viewed by the M78 command.
771
+//#define PRINTCOUNTER
772
+
760 773
 //=============================================================================
761 774
 //============================= LCD and SD support ============================
762 775
 //=============================================================================

+ 10
- 2
Marlin/Marlin.h View File

@@ -65,7 +65,11 @@ typedef unsigned long millis_t;
65 65
 
66 66
 #include "WString.h"
67 67
 
68
-#include "stopwatch.h"
68
+#if ENABLED(PRINTCOUNTER)
69
+  #include "printcounter.h"
70
+#else
71
+  #include "stopwatch.h"
72
+#endif
69 73
 
70 74
 #ifdef USBCON
71 75
   #if ENABLED(BLUETOOTH)
@@ -364,7 +368,11 @@ extern bool axis_homed[3]; // axis[n].is_homed
364 368
 #endif
365 369
 
366 370
 // Print job timer
367
-extern Stopwatch print_job_timer;
371
+#if ENABLED(PRINTCOUNTER)
372
+  extern PrintCounter print_job_timer;
373
+#else
374
+  extern Stopwatch print_job_timer;
375
+#endif
368 376
 
369 377
 // Handling multiple extruders pins
370 378
 extern uint8_t active_extruder;

+ 27
- 1
Marlin/Marlin_main.cpp View File

@@ -137,6 +137,10 @@
137 137
  * M33  - Get the longname version of a path
138 138
  * M42  - Change pin status via gcode Use M42 Px Sy to set pin x to value y, when omitting Px the onboard led will be used.
139 139
  * M48  - Measure Z_Probe repeatability. M48 [P # of points] [X position] [Y position] [V_erboseness #] [E_ngage Probe] [L # of legs of travel]
140
+ * M75  - Start the print job timer
141
+ * M76  - Pause the print job timer
142
+ * M77  - Stop the print job timer
143
+ * M78  - Show statistical information about the print jobs
140 144
  * M80  - Turn on Power Supply
141 145
  * M81  - Turn off Power Supply
142 146
  * M82  - Set E codes absolute (default)
@@ -327,7 +331,11 @@ static millis_t max_inactive_time = 0;
327 331
 static millis_t stepper_inactive_time = (DEFAULT_STEPPER_DEACTIVE_TIME) * 1000UL;
328 332
 
329 333
 // Print Job Timer
330
-Stopwatch print_job_timer = Stopwatch();
334
+#if ENABLED(PRINTCOUNTER)
335
+  PrintCounter print_job_timer = PrintCounter();
336
+#else
337
+  Stopwatch print_job_timer = Stopwatch();
338
+#endif
331 339
 
332 340
 static uint8_t target_extruder;
333 341
 
@@ -4252,6 +4260,15 @@ inline void gcode_M77() {
4252 4260
   print_job_timer.stop();
4253 4261
 }
4254 4262
 
4263
+#if ENABLED(PRINTCOUNTER)
4264
+  /*+
4265
+   * M78: Show print statistics
4266
+   */
4267
+  inline void gcode_M78() {
4268
+    print_job_timer.showStats();
4269
+  }
4270
+#endif
4271
+
4255 4272
 /**
4256 4273
  * M104: Set hot end temperature
4257 4274
  */
@@ -6641,6 +6658,12 @@ void process_next_command() {
6641 6658
         gcode_M77();
6642 6659
         break;
6643 6660
 
6661
+      #if ENABLED(PRINTCOUNTER)
6662
+        case 78: // Show print statistics
6663
+          gcode_M78();
6664
+          break;
6665
+      #endif
6666
+
6644 6667
       #if ENABLED(M100_FREE_MEMORY_WATCHER)
6645 6668
         case 100:
6646 6669
           gcode_M100();
@@ -7755,6 +7778,9 @@ void idle(
7755 7778
   );
7756 7779
   host_keepalive();
7757 7780
   lcd_update();
7781
+  #if ENABLED(PRINTCOUNTER)
7782
+      print_job_timer.tick();
7783
+  #endif
7758 7784
 }
7759 7785
 
7760 7786
 /**

+ 13
- 0
Marlin/example_configurations/Felix/Configuration.h View File

@@ -739,6 +739,19 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l
739 739
 #define ABS_PREHEAT_HPB_TEMP 100
740 740
 #define ABS_PREHEAT_FAN_SPEED 255   // Insert Value between 0 and 255
741 741
 
742
+
743
+//
744
+// Print Counter
745
+//
746
+// When enabled Marlin will keep track of some print statistical data such as:
747
+//  - Total print jobs
748
+//  - Total successful print jobs
749
+//  - Total failed print jobs
750
+//  - Total time printing
751
+//
752
+// This information can be viewed by the M78 command.
753
+//#define PRINTCOUNTER
754
+
742 755
 //=============================================================================
743 756
 //============================= LCD and SD support ============================
744 757
 //=============================================================================

+ 13
- 0
Marlin/example_configurations/Hephestos/Configuration.h View File

@@ -748,6 +748,19 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = true; // set to true to invert the lo
748 748
 #define ABS_PREHEAT_HPB_TEMP 100
749 749
 #define ABS_PREHEAT_FAN_SPEED 255   // Insert Value between 0 and 255
750 750
 
751
+
752
+//
753
+// Print Counter
754
+//
755
+// When enabled Marlin will keep track of some print statistical data such as:
756
+//  - Total print jobs
757
+//  - Total successful print jobs
758
+//  - Total failed print jobs
759
+//  - Total time printing
760
+//
761
+// This information can be viewed by the M78 command.
762
+//#define PRINTCOUNTER
763
+
751 764
 //=============================================================================
752 765
 //============================= LCD and SD support ============================
753 766
 //=============================================================================

+ 13
- 0
Marlin/example_configurations/Hephestos_2/Configuration.h View File

@@ -750,6 +750,19 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l
750 750
 #define ABS_PREHEAT_HPB_TEMP    110
751 751
 #define ABS_PREHEAT_FAN_SPEED   0   // Insert Value between 0 and 255
752 752
 
753
+
754
+//
755
+// Print Counter
756
+//
757
+// When enabled Marlin will keep track of some print statistical data such as:
758
+//  - Total print jobs
759
+//  - Total successful print jobs
760
+//  - Total failed print jobs
761
+//  - Total time printing
762
+//
763
+// This information can be viewed by the M78 command.
764
+//#define PRINTCOUNTER
765
+
753 766
 //=============================================================================
754 767
 //============================= LCD and SD support ============================
755 768
 //=============================================================================

+ 13
- 0
Marlin/example_configurations/K8200/Configuration.h View File

@@ -773,6 +773,19 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l
773 773
 #define ABS_PREHEAT_HPB_TEMP 60 // K8200: set back to 110 if you have an upgraded heatbed power supply
774 774
 #define ABS_PREHEAT_FAN_SPEED 0   // Insert Value between 0 and 255
775 775
 
776
+
777
+//
778
+// Print Counter
779
+//
780
+// When enabled Marlin will keep track of some print statistical data such as:
781
+//  - Total print jobs
782
+//  - Total successful print jobs
783
+//  - Total failed print jobs
784
+//  - Total time printing
785
+//
786
+// This information can be viewed by the M78 command.
787
+//#define PRINTCOUNTER
788
+
776 789
 //=============================================================================
777 790
 //============================= LCD and SD support ============================
778 791
 //=============================================================================

+ 13
- 0
Marlin/example_configurations/RepRapWorld/Megatronics/Configuration.h View File

@@ -756,6 +756,19 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l
756 756
 #define ABS_PREHEAT_HPB_TEMP 110
757 757
 #define ABS_PREHEAT_FAN_SPEED 0   // Insert Value between 0 and 255
758 758
 
759
+
760
+//
761
+// Print Counter
762
+//
763
+// When enabled Marlin will keep track of some print statistical data such as:
764
+//  - Total print jobs
765
+//  - Total successful print jobs
766
+//  - Total failed print jobs
767
+//  - Total time printing
768
+//
769
+// This information can be viewed by the M78 command.
770
+//#define PRINTCOUNTER
771
+
759 772
 //=============================================================================
760 773
 //============================= LCD and SD support ============================
761 774
 //=============================================================================

+ 14
- 1
Marlin/example_configurations/RigidBot/Configuration.h View File

@@ -1,4 +1,4 @@
1
-/**
1
+f/**
2 2
  * Marlin 3D Printer Firmware
3 3
  * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4 4
  *
@@ -751,6 +751,19 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l
751 751
 #define ABS_PREHEAT_HPB_TEMP 110
752 752
 #define ABS_PREHEAT_FAN_SPEED 255   // Insert Value between 0 and 255
753 753
 
754
+
755
+//
756
+// Print Counter
757
+//
758
+// When enabled Marlin will keep track of some print statistical data such as:
759
+//  - Total print jobs
760
+//  - Total successful print jobs
761
+//  - Total failed print jobs
762
+//  - Total time printing
763
+//
764
+// This information can be viewed by the M78 command.
765
+//#define PRINTCOUNTER
766
+
754 767
 //=============================================================================
755 768
 //============================= LCD and SD support ============================
756 769
 //=============================================================================

+ 13
- 0
Marlin/example_configurations/SCARA/Configuration.h View File

@@ -764,6 +764,19 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l
764 764
 #define ABS_PREHEAT_HPB_TEMP 100
765 765
 #define ABS_PREHEAT_FAN_SPEED 255   // Insert Value between 0 and 255
766 766
 
767
+
768
+//
769
+// Print Counter
770
+//
771
+// When enabled Marlin will keep track of some print statistical data such as:
772
+//  - Total print jobs
773
+//  - Total successful print jobs
774
+//  - Total failed print jobs
775
+//  - Total time printing
776
+//
777
+// This information can be viewed by the M78 command.
778
+//#define PRINTCOUNTER
779
+
767 780
 //=============================================================================
768 781
 //============================= LCD and SD support ============================
769 782
 //=============================================================================

+ 13
- 0
Marlin/example_configurations/TAZ4/Configuration.h View File

@@ -777,6 +777,19 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l
777 777
 #define ABS_PREHEAT_HPB_TEMP 110
778 778
 #define ABS_PREHEAT_FAN_SPEED 0   // Insert Value between 0 and 255
779 779
 
780
+
781
+//
782
+// Print Counter
783
+//
784
+// When enabled Marlin will keep track of some print statistical data such as:
785
+//  - Total print jobs
786
+//  - Total successful print jobs
787
+//  - Total failed print jobs
788
+//  - Total time printing
789
+//
790
+// This information can be viewed by the M78 command.
791
+//#define PRINTCOUNTER
792
+
780 793
 //=============================================================================
781 794
 //============================= LCD and SD support ============================
782 795
 //=============================================================================

+ 13
- 0
Marlin/example_configurations/WITBOX/Configuration.h View File

@@ -748,6 +748,19 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = true; // set to true to invert the lo
748 748
 #define ABS_PREHEAT_HPB_TEMP 100
749 749
 #define ABS_PREHEAT_FAN_SPEED 255   // Insert Value between 0 and 255
750 750
 
751
+
752
+//
753
+// Print Counter
754
+//
755
+// When enabled Marlin will keep track of some print statistical data such as:
756
+//  - Total print jobs
757
+//  - Total successful print jobs
758
+//  - Total failed print jobs
759
+//  - Total time printing
760
+//
761
+// This information can be viewed by the M78 command.
762
+//#define PRINTCOUNTER
763
+
751 764
 //=============================================================================
752 765
 //============================= LCD and SD support ============================
753 766
 //=============================================================================

+ 13
- 0
Marlin/example_configurations/adafruit/ST7565/Configuration.h View File

@@ -756,6 +756,19 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l
756 756
 #define ABS_PREHEAT_HPB_TEMP 110
757 757
 #define ABS_PREHEAT_FAN_SPEED 0   // Insert Value between 0 and 255
758 758
 
759
+
760
+//
761
+// Print Counter
762
+//
763
+// When enabled Marlin will keep track of some print statistical data such as:
764
+//  - Total print jobs
765
+//  - Total successful print jobs
766
+//  - Total failed print jobs
767
+//  - Total time printing
768
+//
769
+// This information can be viewed by the M78 command.
770
+//#define PRINTCOUNTER
771
+
759 772
 //=============================================================================
760 773
 //============================= LCD and SD support ============================
761 774
 //=============================================================================

+ 13
- 0
Marlin/example_configurations/delta/biv2.5/Configuration.h View File

@@ -885,6 +885,19 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = true; // set to true to invert the lo
885 885
 #define ABS_PREHEAT_HPB_TEMP 100
886 886
 #define ABS_PREHEAT_FAN_SPEED 255   // Insert Value between 0 and 255
887 887
 
888
+
889
+//
890
+// Print Counter
891
+//
892
+// When enabled Marlin will keep track of some print statistical data such as:
893
+//  - Total print jobs
894
+//  - Total successful print jobs
895
+//  - Total failed print jobs
896
+//  - Total time printing
897
+//
898
+// This information can be viewed by the M78 command.
899
+//#define PRINTCOUNTER
900
+
888 901
 //=============================================================================
889 902
 //============================= LCD and SD support ============================
890 903
 //=============================================================================

+ 13
- 0
Marlin/example_configurations/delta/generic/Configuration.h View File

@@ -885,6 +885,19 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = true; // set to true to invert the lo
885 885
 #define ABS_PREHEAT_HPB_TEMP 100
886 886
 #define ABS_PREHEAT_FAN_SPEED 255   // Insert Value between 0 and 255
887 887
 
888
+
889
+//
890
+// Print Counter
891
+//
892
+// When enabled Marlin will keep track of some print statistical data such as:
893
+//  - Total print jobs
894
+//  - Total successful print jobs
895
+//  - Total failed print jobs
896
+//  - Total time printing
897
+//
898
+// This information can be viewed by the M78 command.
899
+//#define PRINTCOUNTER
900
+
888 901
 //=============================================================================
889 902
 //============================= LCD and SD support ============================
890 903
 //=============================================================================

+ 13
- 0
Marlin/example_configurations/delta/kossel_mini/Configuration.h View File

@@ -889,6 +889,19 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l
889 889
 #define ABS_PREHEAT_HPB_TEMP 100
890 890
 #define ABS_PREHEAT_FAN_SPEED 255   // Insert Value between 0 and 255
891 891
 
892
+
893
+//
894
+// Print Counter
895
+//
896
+// When enabled Marlin will keep track of some print statistical data such as:
897
+//  - Total print jobs
898
+//  - Total successful print jobs
899
+//  - Total failed print jobs
900
+//  - Total time printing
901
+//
902
+// This information can be viewed by the M78 command.
903
+//#define PRINTCOUNTER
904
+
892 905
 //=============================================================================
893 906
 //============================= LCD and SD support ============================
894 907
 //=============================================================================

+ 13
- 0
Marlin/example_configurations/delta/kossel_pro/Configuration.h View File

@@ -882,6 +882,19 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l
882 882
 #define ABS_PREHEAT_HPB_TEMP 100
883 883
 #define ABS_PREHEAT_FAN_SPEED 255   // Insert Value between 0 and 255
884 884
 
885
+
886
+//
887
+// Print Counter
888
+//
889
+// When enabled Marlin will keep track of some print statistical data such as:
890
+//  - Total print jobs
891
+//  - Total successful print jobs
892
+//  - Total failed print jobs
893
+//  - Total time printing
894
+//
895
+// This information can be viewed by the M78 command.
896
+//#define PRINTCOUNTER
897
+
885 898
 //=============================================================================
886 899
 //============================= LCD and SD support ============================
887 900
 //=============================================================================

+ 13
- 0
Marlin/example_configurations/delta/kossel_xl/Configuration.h View File

@@ -890,6 +890,19 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l
890 890
 #define ABS_PREHEAT_HPB_TEMP 100
891 891
 #define ABS_PREHEAT_FAN_SPEED 255   // Insert Value between 0 and 255
892 892
 
893
+
894
+//
895
+// Print Counter
896
+//
897
+// When enabled Marlin will keep track of some print statistical data such as:
898
+//  - Total print jobs
899
+//  - Total successful print jobs
900
+//  - Total failed print jobs
901
+//  - Total time printing
902
+//
903
+// This information can be viewed by the M78 command.
904
+//#define PRINTCOUNTER
905
+
893 906
 //=============================================================================
894 907
 //============================= LCD and SD support ============================
895 908
 //=============================================================================

+ 13
- 0
Marlin/example_configurations/makibox/Configuration.h View File

@@ -759,6 +759,19 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l
759 759
 #define ABS_PREHEAT_HPB_TEMP 100
760 760
 #define ABS_PREHEAT_FAN_SPEED 255   // Insert Value between 0 and 255
761 761
 
762
+
763
+//
764
+// Print Counter
765
+//
766
+// When enabled Marlin will keep track of some print statistical data such as:
767
+//  - Total print jobs
768
+//  - Total successful print jobs
769
+//  - Total failed print jobs
770
+//  - Total time printing
771
+//
772
+// This information can be viewed by the M78 command.
773
+//#define PRINTCOUNTER
774
+
762 775
 //=============================================================================
763 776
 //============================= LCD and SD support ============================
764 777
 //=============================================================================

+ 13
- 0
Marlin/example_configurations/tvrrug/Round2/Configuration.h View File

@@ -750,6 +750,19 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = true; // set to true to invert the lo
750 750
 #define ABS_PREHEAT_HPB_TEMP 100
751 751
 #define ABS_PREHEAT_FAN_SPEED 255   // Insert Value between 0 and 255
752 752
 
753
+
754
+//
755
+// Print Counter
756
+//
757
+// When enabled Marlin will keep track of some print statistical data such as:
758
+//  - Total print jobs
759
+//  - Total successful print jobs
760
+//  - Total failed print jobs
761
+//  - Total time printing
762
+//
763
+// This information can be viewed by the M78 command.
764
+//#define PRINTCOUNTER
765
+
753 766
 //=============================================================================
754 767
 //============================= LCD and SD support ============================
755 768
 //=============================================================================

+ 179
- 0
Marlin/printcounter.cpp View File

@@ -0,0 +1,179 @@
1
+/*
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+#include "Marlin.h"
24
+#include "printcounter.h"
25
+#include <avr/eeprom.h>
26
+
27
+PrintCounter::PrintCounter(): super() {
28
+  this->loadStats();
29
+}
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
+
41
+bool PrintCounter::isLoaded() {
42
+  return this->loaded;
43
+}
44
+
45
+void PrintCounter::initStats() {
46
+  #if ENABLED(DEBUG_PRINTCOUNTER)
47
+    PrintCounter::debug(PSTR("initStats"));
48
+  #endif
49
+
50
+  this->loaded = true;
51
+  this->data = { 0, 0, 0, 0 };
52
+
53
+  this->saveStats();
54
+  eeprom_write_byte((uint8_t *) this->address, 0x16);
55
+}
56
+
57
+void PrintCounter::loadStats() {
58
+  #if ENABLED(DEBUG_PRINTCOUNTER)
59
+    PrintCounter::debug(PSTR("loadStats"));
60
+  #endif
61
+
62
+  // Checks if the EEPROM block is initialized
63
+  if (eeprom_read_byte((uint8_t *) this->address) != 0x16) this->initStats();
64
+  else eeprom_read_block(&this->data, (void *)(this->address + sizeof(uint8_t)), sizeof(printStatistics));
65
+
66
+  this->loaded = true;
67
+}
68
+
69
+void PrintCounter::saveStats() {
70
+  #if ENABLED(DEBUG_PRINTCOUNTER)
71
+    PrintCounter::debug(PSTR("saveStats"));
72
+  #endif
73
+
74
+  // Refuses to save data is object is not loaded
75
+  if (!this->isLoaded()) return;
76
+
77
+  eeprom_update_block(&this->data, (void *)(this->address + sizeof(uint8_t)), sizeof(printStatistics));
78
+}
79
+
80
+void PrintCounter::showStats() {
81
+  SERIAL_ECHOPGM("Print statistics: Total: ");
82
+  SERIAL_ECHO(this->data.totalPrints);
83
+
84
+  SERIAL_ECHOPGM(", Finished: ");
85
+  SERIAL_ECHO(this->data.finishedPrints);
86
+
87
+  SERIAL_ECHOPGM(", Failed: ");
88
+  SERIAL_ECHO(this->data.totalPrints - this->data.finishedPrints
89
+    - (this->isRunning() || this->isPaused()) ? 1 : 0); // Removes 1 from failures with an active counter
90
+
91
+  uint32_t t = this->data.printTime /60;
92
+  SERIAL_ECHOPGM(", Total print time: ");
93
+  SERIAL_ECHO(t / 60);
94
+
95
+  SERIAL_ECHOPGM("h ");
96
+  SERIAL_ECHO(t % 60);
97
+
98
+  SERIAL_ECHOPGM("min");
99
+
100
+  #if ENABLED(DEBUG_PRINTCOUNTER)
101
+    SERIAL_ECHOPGM(" (");
102
+    SERIAL_ECHO(this->data.printTime);
103
+    SERIAL_ECHOPGM(")");
104
+  #endif
105
+
106
+  // @todo longestPrint missing implementation
107
+  SERIAL_EOL;
108
+}
109
+
110
+void PrintCounter::tick() {
111
+  if (!this->isRunning()) return;
112
+
113
+  static uint32_t update_before = millis(),
114
+                  eeprom_before = millis();
115
+
116
+  uint32_t now = millis();
117
+
118
+  // Trying to get the amount of calculations down to the bare min
119
+  const static uint16_t i = this->updateInterval * 1000;
120
+
121
+  if (now - update_before >= i) {
122
+    #if ENABLED(DEBUG_PRINTCOUNTER)
123
+      PrintCounter::debug(PSTR("tick"));
124
+    #endif
125
+
126
+    uint16_t t = this->duration();;
127
+    this->data.printTime += this->deltaDuration();
128
+    update_before = now;
129
+  }
130
+
131
+  // Trying to get the amount of calculations down to the bare min
132
+  const static uint16_t j = this->saveInterval * 1000;
133
+
134
+  if (now - eeprom_before >= j) {
135
+    eeprom_before = now;
136
+    this->saveStats();
137
+  }
138
+}
139
+
140
+void PrintCounter::start() {
141
+  #if ENABLED(DEBUG_PRINTCOUNTER)
142
+    PrintCounter::debug(PSTR("start"));
143
+  #endif
144
+
145
+  if (!this->isPaused()) this->data.totalPrints++;
146
+  super::start();
147
+}
148
+
149
+void PrintCounter::stop() {
150
+  #if ENABLED(DEBUG_PRINTCOUNTER)
151
+    PrintCounter::debug(PSTR("stop"));
152
+  #endif
153
+
154
+  super::stop();
155
+  this->data.finishedPrints++;
156
+  this->data.printTime += this->deltaDuration();
157
+  this->saveStats();
158
+}
159
+
160
+void PrintCounter::reset() {
161
+  #if ENABLED(DEBUG_PRINTCOUNTER)
162
+    PrintCounter::debug(PSTR("stop"));
163
+  #endif
164
+
165
+  this->lastDuration = 0;
166
+  super::reset();
167
+}
168
+
169
+#if ENABLED(DEBUG_PRINTCOUNTER)
170
+
171
+  void PrintCounter::debug(const char func[]) {
172
+    if (DEBUGGING(INFO)) {
173
+      SERIAL_ECHOPGM("PrintCounter::");
174
+      serialprintPGM(func);
175
+      SERIAL_ECHOLNPGM("()");
176
+    }
177
+  }
178
+
179
+#endif

+ 154
- 0
Marlin/printcounter.h View File

@@ -0,0 +1,154 @@
1
+/*
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+#ifndef PRINTCOUNTER_H
24
+#define PRINTCOUNTER_H
25
+
26
+#include "macros.h"
27
+#include "stopwatch.h"
28
+
29
+// Print debug messages with M111 S2
30
+//#define DEBUG_PRINTCOUNTER
31
+
32
+struct printStatistics {    // 13 bytes
33
+  //const uint8_t magic;    // Magic header, it will always be 0x16
34
+  uint16_t totalPrints;     // Number of prints
35
+  uint16_t finishedPrints;  // Number of complete prints
36
+  uint32_t printTime;       // Total printing time
37
+  uint32_t longestPrint;    // Longest print job - not in use
38
+};
39
+
40
+class PrintCounter: public Stopwatch {
41
+  private:
42
+    typedef Stopwatch super;
43
+
44
+    printStatistics data;
45
+
46
+    /**
47
+     * @brief EEPROM address
48
+     * @details Defines the start offset address where the data is stored.
49
+     */
50
+    const uint16_t address = 0x32;
51
+
52
+    /**
53
+     * @brief Interval in seconds between counter updates
54
+     * @details This const value defines what will be the time between each
55
+     * accumulator update. This is different from the EEPROM save interval.
56
+     */
57
+    const uint16_t updateInterval = 10;
58
+
59
+    /**
60
+     * @brief Interval in seconds between EEPROM saves
61
+     * @details This const value defines what will be the time between each
62
+     * EEPROM save cycle, the development team recommends to set this value
63
+     * no lower than 3600 secs (1 hour).
64
+     */
65
+    const uint16_t saveInterval = 3600;
66
+
67
+    /**
68
+     * @brief Timestamp of the last call to deltaDuration()
69
+     * @details Stores the timestamp of the last deltaDuration(), this is
70
+     * required due to the updateInterval cycle.
71
+     */
72
+    uint16_t lastDuration;
73
+
74
+    /**
75
+     * @brief Stats were loaded from EERPROM
76
+     * @details If set to true it indicates if the statistical data was already
77
+     * loaded from the EEPROM.
78
+     */
79
+    bool loaded = false;
80
+
81
+  protected:
82
+    /**
83
+     * @brief dT since the last call
84
+     * @details Returns the elapsed time in seconds since the last call, this is
85
+     * used internally for print statistics accounting is not intended to be a
86
+     * user callable function.
87
+     */
88
+    uint16_t deltaDuration();
89
+
90
+  public:
91
+    /**
92
+     * @brief Class constructor
93
+     */
94
+    PrintCounter();
95
+
96
+    /**
97
+     * @brief Checks if Print Statistics has been loaded
98
+     * @details Returns true if the statistical data has been loaded.
99
+     * @return bool
100
+     */
101
+    bool isLoaded();
102
+
103
+    /**
104
+     * @brief Resets the Print Statistics
105
+     * @details Resets the statistics to zero and saves them to EEPROM creating
106
+     * also the magic header.
107
+     */
108
+    void initStats();
109
+
110
+    /**
111
+     * @brief Loads the Print Statistics
112
+     * @details Loads the statistics from EEPROM
113
+     */
114
+    void loadStats();
115
+
116
+    /**
117
+     * @brief Saves the Print Statistics
118
+     * @details Saves the statistics to EEPROM
119
+     */
120
+    void saveStats();
121
+
122
+    /**
123
+     * @brief Serial output the Print Statistics
124
+     * @details This function may change in the future, for now it directly
125
+     * prints the statistical data to serial.
126
+     */
127
+    void showStats();
128
+
129
+    /**
130
+     * @brief Loop function
131
+     * @details This function should be called at loop, it will take care of
132
+     * periodically save the statistical data to EEPROM and do time keeping.
133
+     */
134
+    void tick();
135
+
136
+    /**
137
+     * The following functions are being overridden
138
+     */
139
+    void start();
140
+    void stop();
141
+    void reset();
142
+
143
+    #if ENABLED(DEBUG_PRINTCOUNTER)
144
+
145
+      /**
146
+       * @brief Prints a debug message
147
+       * @details Prints a simple debug message "PrintCounter::function"
148
+       */
149
+      static void debug(const char func[]);
150
+
151
+    #endif
152
+};
153
+
154
+#endif // PRINTCOUNTER_H

+ 4
- 4
Marlin/stopwatch.cpp View File

@@ -29,7 +29,7 @@ Stopwatch::Stopwatch() {
29 29
 
30 30
 void Stopwatch::stop() {
31 31
   #if ENABLED(DEBUG_STOPWATCH)
32
-    debug(PSTR("stop"));
32
+    Stopwatch::debug(PSTR("stop"));
33 33
   #endif
34 34
 
35 35
   if (!this->isRunning()) return;
@@ -40,7 +40,7 @@ void Stopwatch::stop() {
40 40
 
41 41
 void Stopwatch::pause() {
42 42
   #if ENABLED(DEBUG_STOPWATCH)
43
-    debug(PSTR("pause"));
43
+    Stopwatch::debug(PSTR("pause"));
44 44
   #endif
45 45
 
46 46
   if (!this->isRunning()) return;
@@ -51,7 +51,7 @@ void Stopwatch::pause() {
51 51
 
52 52
 void Stopwatch::start() {
53 53
   #if ENABLED(DEBUG_STOPWATCH)
54
-    debug(PSTR("start"));
54
+    Stopwatch::debug(PSTR("start"));
55 55
   #endif
56 56
 
57 57
   if (this->isRunning()) return;
@@ -65,7 +65,7 @@ void Stopwatch::start() {
65 65
 
66 66
 void Stopwatch::reset() {
67 67
   #if ENABLED(DEBUG_STOPWATCH)
68
-    debug(PSTR("reset"));
68
+    Stopwatch::debug(PSTR("reset"));
69 69
   #endif
70 70
 
71 71
   this->state = STPWTCH_STOPPED;

Loading…
Cancel
Save