Browse Source

Renamed timestamp_t to duration_t

João Brázio 8 years ago
parent
commit
62d96d72f3

+ 3
- 3
Marlin/Marlin_main.cpp View File

@@ -60,7 +60,7 @@
60 60
 #include "pins_arduino.h"
61 61
 #include "math.h"
62 62
 #include "nozzle.h"
63
-#include "timestamp_t.h"
63
+#include "duration_t.h"
64 64
 
65 65
 #if ENABLED(USE_WATCHDOG)
66 66
   #include "watchdog.h"
@@ -4058,8 +4058,8 @@ inline void gcode_M17() {
4058 4058
  */
4059 4059
 inline void gcode_M31() {
4060 4060
   char buffer[21];
4061
-  timestamp_t time(print_job_timer.duration());
4062
-  time.toString(buffer);
4061
+  duration_t elapsed = print_job_timer.duration();
4062
+  elapsed.toString(buffer);
4063 4063
 
4064 4064
   lcd_setstatus(buffer);
4065 4065
 

+ 155
- 0
Marlin/duration_t.h View File

@@ -0,0 +1,155 @@
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 __DURATION_T__
24
+#define __DURATION_T__
25
+
26
+struct duration_t {
27
+  /**
28
+   * @brief Duration is stored in seconds
29
+   */
30
+  uint32_t value;
31
+
32
+  /**
33
+   * @brief Constructor
34
+   */
35
+  duration_t()
36
+    : duration_t(0) {};
37
+
38
+  /**
39
+   * @brief Constructor
40
+   *
41
+   * @param seconds The number of seconds
42
+   */
43
+  duration_t(uint32_t const &seconds) {
44
+    this->value = seconds;
45
+  }
46
+
47
+  /**
48
+   * @brief Equality comparison
49
+   * @details Overloads the equality comparison operator
50
+   *
51
+   * @param value The number of seconds to compare to
52
+   * @return True if both durations are equal
53
+   */
54
+  bool operator==(const uint32_t &value) const {
55
+    return (this->value == value);
56
+  }
57
+
58
+  /**
59
+   * @brief Inequality comparison
60
+   * @details Overloads the inequality comparison operator
61
+   *
62
+   * @param value The number of seconds to compare to
63
+   * @return False if both durations are equal
64
+   */
65
+  bool operator!=(const uint32_t &value) const {
66
+    return ! this->operator==(value);
67
+  }
68
+
69
+  /**
70
+   * @brief Formats the duration as years
71
+   * @return The number of years
72
+   */
73
+  inline uint8_t year() const {
74
+    return this->day() / 365;
75
+  }
76
+
77
+  /**
78
+   * @brief Formats the duration as days
79
+   * @return The number of days
80
+   */
81
+  inline uint16_t day() const {
82
+    return this->hour() / 24;
83
+  }
84
+
85
+  /**
86
+   * @brief Formats the duration as hours
87
+   * @return The number of hours
88
+   */
89
+  inline uint32_t hour() const {
90
+    return this->minute() / 60;
91
+  }
92
+
93
+  /**
94
+   * @brief Formats the duration as minutes
95
+   * @return The number of minutes
96
+   */
97
+  inline uint32_t minute() const {
98
+    return this->second() / 60;
99
+  }
100
+
101
+  /**
102
+   * @brief Formats the duration as seconds
103
+   * @return The number of seconds
104
+   */
105
+  inline uint32_t second() const {
106
+    return this->value;
107
+  }
108
+
109
+  /**
110
+   * @brief Formats the duration as a string
111
+   * @details String will be formated using a "full" representation of duration
112
+   *
113
+   * @param buffer The array pointed to must be able to accommodate 21 bytes
114
+   *
115
+   * Output examples:
116
+   *  123456789012345678901 (strlen)
117
+   *  135y 364d 23h 59m 59s
118
+   *  364d 23h 59m 59s
119
+   *  23h 59m 59s
120
+   *  59m 59s
121
+   *  59s
122
+   */
123
+  void toString(char *buffer) const {
124
+    int y = this->year(),
125
+        d = this->day() % 365,
126
+        h = this->hour() % 24,
127
+        m = this->minute() % 60,
128
+        s = this->second() % 60;
129
+
130
+    if (y) sprintf_P(buffer, PSTR("%iy %id %ih %im %is"), y, d, h, m, s);
131
+    else if (d) sprintf_P(buffer, PSTR("%id %ih %im %is"), d, h, m, s);
132
+    else if (h) sprintf_P(buffer, PSTR("%ih %im %is"), h, m, s);
133
+    else if (m) sprintf_P(buffer, PSTR("%im %is"), m, s);
134
+    else sprintf_P(buffer, PSTR("%is"), s);
135
+  }
136
+
137
+  /**
138
+   * @brief Formats the duration as a string
139
+   * @details String will be formated using a "digital" representation of duration
140
+   *
141
+   * @param buffer The array pointed to must be able to accommodate 10 bytes
142
+   *
143
+   * Output examples:
144
+   *  1234567890 (strlen)
145
+   *  1193046:59
146
+   */
147
+  void toDigital(char *buffer) const {
148
+    int h = this->hour() % 24,
149
+        m = this->minute() % 60;
150
+
151
+    sprintf_P(buffer, PSTR("%02i:%02i"), h, m);
152
+  }
153
+};
154
+
155
+#endif // __DURATION_T__

+ 6
- 6
Marlin/printcounter.cpp View File

@@ -22,7 +22,7 @@
22 22
 
23 23
 #include "Marlin.h"
24 24
 #include "printcounter.h"
25
-#include "timestamp_t.h"
25
+#include "duration_t.h"
26 26
 
27 27
 PrintCounter::PrintCounter(): super() {
28 28
   this->loadStats();
@@ -94,7 +94,7 @@ void PrintCounter::saveStats() {
94 94
 
95 95
 void PrintCounter::showStats() {
96 96
   char buffer[21];
97
-  timestamp_t time;
97
+  duration_t elapsed;
98 98
 
99 99
   SERIAL_PROTOCOLPGM(MSG_STATS);
100 100
 
@@ -111,8 +111,8 @@ void PrintCounter::showStats() {
111 111
   SERIAL_EOL;
112 112
   SERIAL_PROTOCOLPGM(MSG_STATS);
113 113
 
114
-  time.timestamp = this->data.printTime;
115
-  time.toString(buffer);
114
+  elapsed = this->data.printTime;
115
+  elapsed.toString(buffer);
116 116
 
117 117
   SERIAL_ECHOPGM("Total time: ");
118 118
   SERIAL_ECHO(buffer);
@@ -123,8 +123,8 @@ void PrintCounter::showStats() {
123 123
     SERIAL_ECHOPGM(")");
124 124
   #endif
125 125
 
126
-  time.timestamp = this->data.longestPrint;
127
-  time.toString(buffer);
126
+  elapsed = this->data.longestPrint;
127
+  elapsed.toString(buffer);
128 128
 
129 129
   SERIAL_ECHOPGM(", Longest job: ");
130 130
   SERIAL_ECHO(buffer);

+ 0
- 128
Marlin/timestamp_t.h View File

@@ -1,128 +0,0 @@
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 __TIMESTAMP_T__
24
-#define __TIMESTAMP_T__
25
-
26
-struct timestamp_t {
27
-  /**
28
-   * @brief Number of seconds
29
-   */
30
-  uint32_t timestamp;
31
-
32
-  /**
33
-   * @brief Timestamp blank constructor
34
-   */
35
-  timestamp_t()
36
-    : timestamp_t(0) {};
37
-
38
-  /**
39
-   * @briefTimestamp constructor
40
-   * @details Initializes the timestamp_t structure based on a number of seconds
41
-   *
42
-   * @param seconds The number of seconds
43
-   */
44
-  timestamp_t(uint32_t const &seconds) {
45
-    this->timestamp = seconds;
46
-  }
47
-
48
-  /**
49
-   * @brief Formats the timestamp in years
50
-   * @return The number of years
51
-   */
52
-  inline uint8_t year() const {
53
-    return this->day() / 365;
54
-  }
55
-
56
-  /**
57
-   * @brief Formats the timestamp in days
58
-   * @return The number of days
59
-   */
60
-  inline uint16_t day() const {
61
-    return this->hour() / 24;
62
-  }
63
-
64
-  /**
65
-   * @brief Formats the timestamp in hours
66
-   * @return The number of hours
67
-   */
68
-  inline uint32_t hour() const {
69
-    return this->minute() / 60;
70
-  }
71
-
72
-  /**
73
-   * @brief Formats the timestamp in minutes
74
-   * @return The number of minutes
75
-   */
76
-  inline uint32_t minute() const {
77
-    return this->second() / 60;
78
-  }
79
-
80
-  /**
81
-   * @brief Formats the timestamp in seconds
82
-   * @return The number of seconds
83
-   */
84
-  inline uint32_t second() const {
85
-    return this->timestamp;
86
-  }
87
-
88
-  /**
89
-   * @brief Formats the timestamp as a string
90
-   * @details Returns the timestamp formated as a string
91
-   *
92
-   * @param buffer The array pointed to must be able to accommodate 21 bytes when
93
-   *               on standard mode or 10 bytes otherwise.
94
-   * @param shorty If true a short representation will be returned.
95
-   *
96
-   * Standard toString() output examples:
97
-   *  123456789012345678901 (strlen)
98
-   *  135y 364d 23h 59m 59s
99
-   *  364d 23h 59m 59s
100
-   *  23h 59m 59s
101
-   *  59m 59s
102
-   *  59s
103
-   *
104
-   * Short toString() output examples:
105
-   *  1234567890 (strlen)
106
-   *  1193046:59
107
-   *
108
-   */
109
-  void toString(char *buffer, bool const &shorty = false) const {
110
-    int h = this->hour() % 24,
111
-        m = this->minute() % 60;
112
-
113
-    if (shorty) sprintf_P(buffer, PSTR("%02i:%02i"), h, m);
114
-    else {
115
-      int y = this->year(),
116
-          d = this->day() % 365,
117
-          s = this->second() % 60;
118
-
119
-      if (y) sprintf_P(buffer, PSTR("%iy %id %ih %im %is"), y, d, h, m, s);
120
-      else if (d) sprintf_P(buffer, PSTR("%id %ih %im %is"), d, h, m, s);
121
-      else if (h) sprintf_P(buffer, PSTR("%ih %im %is"), h, m, s);
122
-      else if (m) sprintf_P(buffer, PSTR("%im %is"), m, s);
123
-      else sprintf_P(buffer, PSTR("%is"), s);
124
-    }
125
-  }
126
-};
127
-
128
-#endif // __TIMESTAMP_T__

+ 7
- 5
Marlin/ultralcd.cpp View File

@@ -31,7 +31,7 @@
31 31
 
32 32
 #if ENABLED(PRINTCOUNTER)
33 33
   #include "printcounter.h"
34
-  #include "timestamp_t.h"
34
+  #include "duration_t.h"
35 35
 #endif
36 36
 
37 37
 int preheatHotendTemp1, preheatBedTemp1, preheatFanSpeed1,
@@ -1979,13 +1979,15 @@ void kill_screen(const char* lcd_msg) {
1979 1979
         STATIC_ITEM(MSG_INFO_PRINT_COUNT ": ", false, false, itostr3left(stats.totalPrints));          // Print Count: 999
1980 1980
         STATIC_ITEM(MSG_INFO_COMPLETED_PRINTS"  : ", false, false, itostr3left(stats.finishedPrints)); // Completed  : 666
1981 1981
 
1982
-        timestamp_t time(stats.printTime);
1983
-        time.toString(buffer);
1982
+        duration_t elapsed = stats.printTime;
1983
+        elapsed.toString(buffer);
1984
+
1984 1985
         STATIC_ITEM(MSG_INFO_PRINT_TIME ": ", false, false);                                           // Total print Time:
1985 1986
         STATIC_ITEM("", false, false, buffer);                                                         // 99y 364d 23h 59m 59s
1986 1987
 
1987
-        time.timestamp = stats.longestPrint;
1988
-        time.toString(buffer);
1988
+        elapsed = stats.longestPrint;
1989
+        elapsed.toString(buffer);
1990
+
1989 1991
         STATIC_ITEM(MSG_INFO_PRINT_LONGEST ": ", false, false);                                        // Longest job time:
1990 1992
         STATIC_ITEM("", false, false, buffer);                                                         // 99y 364d 23h 59m 59s
1991 1993
 

+ 5
- 5
Marlin/ultralcd_impl_DOGM.h View File

@@ -58,7 +58,7 @@
58 58
 #include "ultralcd_st7920_u8glib_rrd.h"
59 59
 #include "Configuration.h"
60 60
 
61
-#include "timestamp_t.h"
61
+#include "duration_t.h"
62 62
 
63 63
 #if DISABLED(MAPPER_C2C3) && DISABLED(MAPPER_NON) && ENABLED(USE_BIG_EDIT_FONT)
64 64
   #undef USE_BIG_EDIT_FONT
@@ -391,10 +391,10 @@ static void lcd_implementation_status_screen() {
391 391
     u8g.setPrintPos(80,48);
392 392
 
393 393
     char buffer[10];
394
-    timestamp_t time(print_job_timer.duration());
395
-    time.toString(buffer, true);
396
-    if (time.timestamp != 0) lcd_print(buffer);
397
-    else lcd_printPGM(PSTR("--:--"));
394
+    duration_t elapsed = print_job_timer.duration();
395
+    elapsed.toDigital(buffer);
396
+    lcd_print(buffer);
397
+
398 398
   #endif
399 399
 
400 400
   // Extruders

+ 4
- 5
Marlin/ultralcd_impl_HD44780.h View File

@@ -27,7 +27,7 @@
27 27
 * Implementation of the LCD display routines for a Hitachi HD44780 display. These are common LCD character displays.
28 28
 **/
29 29
 
30
-#include "timestamp_t.h"
30
+#include "duration_t.h"
31 31
 
32 32
 extern volatile uint8_t buttons;  //an extended version of the last checked buttons in a bit array.
33 33
 
@@ -763,10 +763,9 @@ static void lcd_implementation_status_screen() {
763 763
     lcd.print(LCD_STR_CLOCK[0]);
764 764
 
765 765
     char buffer[10];
766
-    timestamp_t time(print_job_timer.duration());
767
-    time.toString(buffer, true);
768
-    if (time.timestamp != 0) lcd_print(buffer);
769
-    else lcd_printPGM(PSTR("--:--"));
766
+    duration_t elapsed = print_job_timer.duration();
767
+    elapsed.toDigital(buffer);
768
+    lcd_print(buffer);
770 769
 
771 770
   #endif // LCD_HEIGHT > 3
772 771
 

Loading…
Cancel
Save