Browse Source

Made all stopwatch::debug() calls static

João Brázio 8 years ago
parent
commit
26b166d7cf
No account linked to committer's email address
3 changed files with 206 additions and 4 deletions
  1. 109
    0
      Marlin/printcounter.cpp
  2. 93
    0
      Marlin/printcounter.h
  3. 4
    4
      Marlin/stopwatch.cpp

+ 109
- 0
Marlin/printcounter.cpp View File

@@ -0,0 +1,109 @@
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
+
29
+void PrintCounter::tick() {
30
+  if (!this->isRunning()) return;
31
+
32
+  static uint32_t update_before = millis(),
33
+                  eeprom_before = millis();
34
+
35
+  uint32_t now = millis();
36
+
37
+  // Trying to get the amount of calculations down to the bare min
38
+  const static uint16_t i = this->updateInterval * 1000;
39
+
40
+  if (now - update_before >= i) {
41
+    //this->addToTimeCounter((uint16_t) (now - update_before) / 1000);
42
+    update_before = now;
43
+    PrintCounter::debug(PSTR("tick1"));
44
+  }
45
+
46
+  // Trying to get the amount of calculations down to the bare min
47
+  const static uint16_t j = this->saveInterval * 1000;
48
+
49
+  if (now - eeprom_before >= j) {
50
+    eeprom_before = now;
51
+    this->save();
52
+  }
53
+}
54
+
55
+void PrintCounter::load() {
56
+  uint16_t pos = this->addr;
57
+
58
+  this->data.successPrints= eeprom_read_word ((uint16_t*) pos);
59
+  this->data.failedPrints = eeprom_read_word ((uint16_t*) pos);
60
+  this->data.printTime    = eeprom_read_dword((uint32_t*) pos);
61
+  this->data.longestPrint = eeprom_read_dword((uint32_t*) pos);
62
+
63
+  SERIAL_ECHOPGM("successPrints: ");
64
+  SERIAL_ECHOLN(this->data.successPrints);
65
+
66
+  SERIAL_ECHOPGM("failedPrints: ");
67
+  SERIAL_ECHOLN(this->data.failedPrints);
68
+
69
+  SERIAL_ECHOPGM("printTime: ");
70
+  SERIAL_ECHOLN(this->data.printTime);
71
+
72
+  SERIAL_ECHOPGM("longestPrint: ");
73
+  SERIAL_ECHOLN(this->data.longestPrint);
74
+}
75
+
76
+void PrintCounter::save() {
77
+  #if ENABLED(DEBUG_PRINTCOUNTER)
78
+    PrintCounter::debug(PSTR("save"));
79
+  #endif
80
+
81
+  uint16_t pos = this->addr;
82
+
83
+  eeprom_write_word ((uint16_t*) pos, this->data.successPrints);
84
+  eeprom_write_word ((uint16_t*) pos, this->data.failedPrints);
85
+  eeprom_write_dword((uint32_t*) pos, this->data.printTime);
86
+  eeprom_write_dword((uint32_t*) pos, this->data.longestPrint);
87
+}
88
+
89
+void PrintCounter::start() {
90
+  super::start();
91
+  this->load();
92
+}
93
+
94
+void PrintCounter::stop() {
95
+  super::stop();
96
+  this->save();
97
+}
98
+
99
+#if ENABLED(DEBUG_PRINTCOUNTER)
100
+
101
+  void PrintCounter::debug(const char func[]) {
102
+    if (DEBUGGING(INFO)) {
103
+      SERIAL_ECHOPGM("PrintCounter::");
104
+      serialprintPGM(func);
105
+      SERIAL_ECHOLNPGM("()");
106
+    }
107
+  }
108
+
109
+#endif

+ 93
- 0
Marlin/printcounter.h View File

@@ -0,0 +1,93 @@
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 {  // 12 bytes
33
+  uint16_t successPrints; // Total number of prints
34
+  uint16_t failedPrints;  // Total number of aborted prints - not in use
35
+  uint32_t printTime;     // Total time printing
36
+  uint32_t longestPrint;  // Longest print job - not in use
37
+};
38
+
39
+class PrintCounter: public Stopwatch {
40
+  private:
41
+    typedef Stopwatch super;
42
+
43
+    printStatistics data;
44
+
45
+    /**
46
+     * @brief EEPROM address
47
+     * @details Defines the start offset address where the data is stored.
48
+     */
49
+    const uint16_t addr = 60;
50
+
51
+    /**
52
+     * @brief Interval in seconds between counter updates
53
+     * @details This const value defines what will be the time between each
54
+     * accumulator update. This is different from the EEPROM save interval
55
+     * which is user defined at the Configuration.h file.
56
+     */
57
+    const uint16_t updateInterval = 2;
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 = PRINTCOUNTER_SAVE_INTERVAL;
66
+
67
+  public:
68
+    /**
69
+     * @brief Class constructor
70
+     */
71
+    PrintCounter();
72
+
73
+    void tick();
74
+    void save();
75
+    void load();
76
+    void addToTimeCounter(uint16_t const &minutes);
77
+    void addToPrintCounter(uint8_t const &prints);
78
+
79
+    void start();
80
+    void stop();
81
+
82
+    #if ENABLED(DEBUG_PRINTCOUNTER)
83
+
84
+      /**
85
+       * @brief Prints a debug message
86
+       * @details Prints a simple debug message "PrintCounter::function"
87
+       */
88
+      static void debug(const char func[]);
89
+
90
+    #endif
91
+};
92
+
93
+#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