Selaa lähdekoodia

Rework some code to use timestamp_t struct (saves 72 bytes)

João Brázio 9 vuotta sitten
vanhempi
commit
23043a1e05
2 muutettua tiedostoa jossa 18 lisäystä ja 32 poistoa
  1. 6
    12
      Marlin/Marlin_main.cpp
  2. 12
    20
      Marlin/printcounter.cpp

+ 6
- 12
Marlin/Marlin_main.cpp Näytä tiedosto

@@ -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"
@@ -4055,22 +4056,15 @@ inline void gcode_M17() {
4055 4056
  * M31: Get the time since the start of SD Print (or last M109)
4056 4057
  */
4057 4058
 inline void gcode_M31() {
4058
-  millis_t t = print_job_timer.duration();
4059
-  int d = int(t / 60 / 60 / 24),
4060
-      h = int(t / 60 / 60) % 60,
4061
-      m = int(t / 60) % 60,
4062
-      s = int(t % 60);
4063
-  char time[18];                                          // 123456789012345678
4064
-  if (d)
4065
-    sprintf_P(time, PSTR("%id %ih %im %is"), d, h, m, s); // 99d 23h 59m 59s
4066
-  else
4067
-    sprintf_P(time, PSTR("%ih %im %is"), h, m, s);        // 23h 59m 59s
4059
+  char buffer[21];
4060
+  timestamp_t time(print_job_timer.duration());
4061
+  time.toString(buffer);
4068 4062
 
4069
-  lcd_setstatus(time);
4063
+  lcd_setstatus(buffer);
4070 4064
 
4071 4065
   SERIAL_ECHO_START;
4072 4066
   SERIAL_ECHOPGM(MSG_PRINT_TIME " ");
4073
-  SERIAL_ECHOLN(time);
4067
+  SERIAL_ECHOLN(buffer);
4074 4068
 
4075 4069
   thermalManager.autotempShutdown();
4076 4070
 }

+ 12
- 20
Marlin/printcounter.cpp Näytä tiedosto

@@ -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(" (");

Loading…
Peruuta
Tallenna