Sfoglia il codice sorgente

Merge pull request #4374 from thinkyhead/rc_jbrazio_timestamp_t

Implements timestamp_t structure
Scott Lahteine 9 anni fa
parent
commit
179e091473
4 ha cambiato i file con 168 aggiunte e 33 eliminazioni
  1. 6
    12
      Marlin/Marlin_main.cpp
  2. 32
    1
      Marlin/point_t.h
  3. 12
    20
      Marlin/printcounter.cpp
  4. 118
    0
      Marlin/timestamp_t.h

+ 6
- 12
Marlin/Marlin_main.cpp Vedi File

@@ -60,6 +60,7 @@
60 60
 #include "pins_arduino.h"
61 61
 #include "math.h"
62 62
 #include "nozzle.h"
63
+#include "timestamp_t.h"
63 64
 
64 65
 #if ENABLED(USE_WATCHDOG)
65 66
   #include "watchdog.h"
@@ -4052,22 +4053,15 @@ inline void gcode_M17() {
4052 4053
  * M31: Get the time since the start of SD Print (or last M109)
4053 4054
  */
4054 4055
 inline void gcode_M31() {
4055
-  millis_t t = print_job_timer.duration();
4056
-  int d = int(t / 60 / 60 / 24),
4057
-      h = int(t / 60 / 60) % 60,
4058
-      m = int(t / 60) % 60,
4059
-      s = int(t % 60);
4060
-  char time[18];                                          // 123456789012345678
4061
-  if (d)
4062
-    sprintf_P(time, PSTR("%id %ih %im %is"), d, h, m, s); // 99d 23h 59m 59s
4063
-  else
4064
-    sprintf_P(time, PSTR("%ih %im %is"), h, m, s);        // 23h 59m 59s
4056
+  char buffer[21];
4057
+  timestamp_t time(print_job_timer.duration());
4058
+  time.toString(buffer);
4065 4059
 
4066
-  lcd_setstatus(time);
4060
+  lcd_setstatus(buffer);
4067 4061
 
4068 4062
   SERIAL_ECHO_START;
4069 4063
   SERIAL_ECHOPGM(MSG_PRINT_TIME " ");
4070
-  SERIAL_ECHOLN(time);
4064
+  SERIAL_ECHOLN(buffer);
4071 4065
 
4072 4066
   thermalManager.autotempShutdown();
4073 4067
 }

+ 32
- 1
Marlin/point_t.h Vedi File

@@ -23,18 +23,49 @@
23 23
 #ifndef __POINT_T__
24 24
 #define __POINT_T__
25 25
 
26
+/**
27
+ * @brief Cartesian Point
28
+ * @details Represents a three dimensional point on Cartesian coordinate system,
29
+ *          using an additional fourth dimension for the extrusion length.
30
+ *
31
+ * @param x The x-coordinate of the point.
32
+ * @param y The y-coordinate of the point.
33
+ * @param z The z-coordinate of the point.
34
+ * @param e The e-coordinate of the point.
35
+ */
26 36
 struct point_t {
27 37
   float x;
28 38
   float y;
29 39
   float z;
30 40
   float e;
31 41
 
42
+  /**
43
+   * @brief Two dimensional point constructor
44
+   *
45
+   * @param x The x-coordinate of the point.
46
+   * @param y The y-coordinate of the point.
47
+   */
32 48
   point_t(float const x, float const y)
33 49
     : point_t(x, y, NAN, NAN) {}
34 50
 
51
+  /**
52
+   * @brief Three dimensional point constructor
53
+   *
54
+   * @param x The x-coordinate of the point.
55
+   * @param y The y-coordinate of the point.
56
+   * @param z The z-coordinate of the point.
57
+   */
35 58
   point_t(float const x, float const y, float const z)
36 59
     : point_t(x, y, z, NAN) {}
37 60
 
61
+  /**
62
+   * @brief Tree dimensional point constructor with extrusion length
63
+   *
64
+   * @param x The x-coordinate of the point.
65
+   * @param y The y-coordinate of the point.
66
+   * @param z The z-coordinate of the point.
67
+   * @param e The e-coordinate of the point.
68
+   */
38 69
   point_t(float const x, float const y, float const z, float const e) {
39 70
     this->x = x;
40 71
     this->y = y;
@@ -43,4 +74,4 @@ struct point_t {
43 74
   }
44 75
 };
45 76
 
46
-#endif
77
+#endif // __POINT_T__

+ 12
- 20
Marlin/printcounter.cpp Vedi File

@@ -22,6 +22,7 @@
22 22
 
23 23
 #include "Marlin.h"
24 24
 #include "printcounter.h"
25
+#include "timestamp_t.h"
25 26
 
26 27
 PrintCounter::PrintCounter(): super() {
27 28
   this->loadStats();
@@ -92,6 +93,9 @@ void PrintCounter::saveStats() {
92 93
 }
93 94
 
94 95
 void PrintCounter::showStats() {
96
+  char buffer[21];
97
+  timestamp_t time;
98
+
95 99
   SERIAL_PROTOCOLPGM(MSG_STATS);
96 100
 
97 101
   SERIAL_ECHOPGM("Prints: ");
@@ -107,17 +111,11 @@ void PrintCounter::showStats() {
107 111
   SERIAL_EOL;
108 112
   SERIAL_PROTOCOLPGM(MSG_STATS);
109 113
 
110
-  uint32_t t = this->data.printTime / 60;
111
-  SERIAL_ECHOPGM("Total time: ");
112
-
113
-  SERIAL_ECHO(t / 60 / 24);
114
-  SERIAL_ECHOPGM("d ");
114
+  time.timestamp = this->data.printTime;
115
+  time.toString(buffer);
115 116
 
116
-  SERIAL_ECHO((t / 60) % 24);
117
-  SERIAL_ECHOPGM("h ");
118
-
119
-  SERIAL_ECHO(t % 60);
120
-  SERIAL_ECHOPGM("min");
117
+  SERIAL_ECHOPGM("Total time: ");
118
+  SERIAL_ECHO(buffer);
121 119
 
122 120
   #if ENABLED(DEBUG_PRINTCOUNTER)
123 121
     SERIAL_ECHOPGM(" (");
@@ -125,17 +123,11 @@ void PrintCounter::showStats() {
125 123
     SERIAL_ECHOPGM(")");
126 124
   #endif
127 125
 
128
-  uint32_t l = this->data.longestPrint / 60;
129
-  SERIAL_ECHOPGM(", Longest job: ");
130
-
131
-  SERIAL_ECHO(l / 60 / 24);
132
-  SERIAL_ECHOPGM("d ");
126
+  time.timestamp = this->data.longestPrint;
127
+  time.toString(buffer);
133 128
 
134
-  SERIAL_ECHO((l / 60) % 24);
135
-  SERIAL_ECHOPGM("h ");
136
-
137
-  SERIAL_ECHO(l % 60);
138
-  SERIAL_ECHOPGM("min");
129
+  SERIAL_ECHOPGM(", Longest job: ");
130
+  SERIAL_ECHO(buffer);
139 131
 
140 132
   #if ENABLED(DEBUG_PRINTCOUNTER)
141 133
     SERIAL_ECHOPGM(" (");

+ 118
- 0
Marlin/timestamp_t.h Vedi File

@@ -0,0 +1,118 @@
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 Date time blank constructor
34
+   */
35
+  timestamp_t()
36
+    : timestamp_t(0) {};
37
+
38
+  /**
39
+   * @brief Date time 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 date as number of 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 date as number of 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 date as number of 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 date as number of 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 date as number of 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 date 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
93
+   *
94
+   * String output examples:
95
+   *  123456789012345678901 (strlen)
96
+   *  135y 364d 23h 59m 59s
97
+   *  364d 23h 59m 59s
98
+   *  23h 59m 59s
99
+   *  59m 59s
100
+   *  59s
101
+   *
102
+   */
103
+  void toString(char *buffer) const {
104
+    int y = this->year(),
105
+        d = this->day() % 365,
106
+        h = this->hour() % 24,
107
+        m = this->minute() % 60,
108
+        s = this->second() % 60;
109
+
110
+    if (y) sprintf_P(buffer, PSTR("%iy %id %ih %im %is"), y, d, h, m, s);
111
+    else if (d) sprintf_P(buffer, PSTR("%id %ih %im %is"), d, h, m, s);
112
+    else if (h) sprintf_P(buffer, PSTR("%ih %im %is"), h, m, s);
113
+    else if (m) sprintf_P(buffer, PSTR("%im %is"), m, s);
114
+    else sprintf_P(buffer, PSTR("%is"), s);
115
+  }
116
+};
117
+
118
+#endif // __TIMESTAMP_T__

Loading…
Annulla
Salva