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

This commit is contained in:
João Brázio 2016-07-22 15:47:56 +01:00 committed by Scott Lahteine
parent 9388dcfa49
commit 23043a1e05
2 changed files with 18 additions and 32 deletions

View file

@ -60,6 +60,7 @@
#include "pins_arduino.h"
#include "math.h"
#include "nozzle.h"
#include "timestamp_t.h"
#if ENABLED(USE_WATCHDOG)
#include "watchdog.h"
@ -4055,22 +4056,15 @@ inline void gcode_M17() {
* M31: Get the time since the start of SD Print (or last M109)
*/
inline void gcode_M31() {
millis_t t = print_job_timer.duration();
int d = int(t / 60 / 60 / 24),
h = int(t / 60 / 60) % 60,
m = int(t / 60) % 60,
s = int(t % 60);
char time[18]; // 123456789012345678
if (d)
sprintf_P(time, PSTR("%id %ih %im %is"), d, h, m, s); // 99d 23h 59m 59s
else
sprintf_P(time, PSTR("%ih %im %is"), h, m, s); // 23h 59m 59s
char buffer[21];
timestamp_t time(print_job_timer.duration());
time.toString(buffer);
lcd_setstatus(time);
lcd_setstatus(buffer);
SERIAL_ECHO_START;
SERIAL_ECHOPGM(MSG_PRINT_TIME " ");
SERIAL_ECHOLN(time);
SERIAL_ECHOLN(buffer);
thermalManager.autotempShutdown();
}

View file

@ -22,6 +22,7 @@
#include "Marlin.h"
#include "printcounter.h"
#include "timestamp_t.h"
PrintCounter::PrintCounter(): super() {
this->loadStats();
@ -92,6 +93,9 @@ void PrintCounter::saveStats() {
}
void PrintCounter::showStats() {
char buffer[21];
timestamp_t time;
SERIAL_PROTOCOLPGM(MSG_STATS);
SERIAL_ECHOPGM("Prints: ");
@ -107,17 +111,11 @@ void PrintCounter::showStats() {
SERIAL_EOL;
SERIAL_PROTOCOLPGM(MSG_STATS);
uint32_t t = this->data.printTime / 60;
time.timestamp = this->data.printTime;
time.toString(buffer);
SERIAL_ECHOPGM("Total time: ");
SERIAL_ECHO(t / 60 / 24);
SERIAL_ECHOPGM("d ");
SERIAL_ECHO((t / 60) % 24);
SERIAL_ECHOPGM("h ");
SERIAL_ECHO(t % 60);
SERIAL_ECHOPGM("min");
SERIAL_ECHO(buffer);
#if ENABLED(DEBUG_PRINTCOUNTER)
SERIAL_ECHOPGM(" (");
@ -125,17 +123,11 @@ void PrintCounter::showStats() {
SERIAL_ECHOPGM(")");
#endif
uint32_t l = this->data.longestPrint / 60;
time.timestamp = this->data.longestPrint;
time.toString(buffer);
SERIAL_ECHOPGM(", Longest job: ");
SERIAL_ECHO(l / 60 / 24);
SERIAL_ECHOPGM("d ");
SERIAL_ECHO((l / 60) % 24);
SERIAL_ECHOPGM("h ");
SERIAL_ECHO(l % 60);
SERIAL_ECHOPGM("min");
SERIAL_ECHO(buffer);
#if ENABLED(DEBUG_PRINTCOUNTER)
SERIAL_ECHOPGM(" (");