Browse Source

Merge pull request #4390 from jbrazio/duration_t

Renamed timestamp_t to duration_t
pull/1/head
Scott Lahteine 8 years ago
committed by GitHub
parent
commit
2839c56f5a
  1. 8
      Marlin/Marlin_main.cpp
  2. 155
      Marlin/duration_t.h
  3. 12
      Marlin/printcounter.cpp
  4. 128
      Marlin/timestamp_t.h
  5. 12
      Marlin/ultralcd.cpp
  6. 10
      Marlin/ultralcd_impl_DOGM.h
  7. 9
      Marlin/ultralcd_impl_HD44780.h

8
Marlin/Marlin_main.cpp

@ -60,7 +60,7 @@
#include "pins_arduino.h" #include "pins_arduino.h"
#include "math.h" #include "math.h"
#include "nozzle.h" #include "nozzle.h"
#include "timestamp_t.h" #include "duration_t.h"
#if ENABLED(USE_WATCHDOG) #if ENABLED(USE_WATCHDOG)
#include "watchdog.h" #include "watchdog.h"
@ -4058,13 +4058,13 @@ inline void gcode_M17() {
*/ */
inline void gcode_M31() { inline void gcode_M31() {
char buffer[21]; char buffer[21];
timestamp_t time(print_job_timer.duration()); duration_t elapsed = print_job_timer.duration();
time.toString(buffer); elapsed.toString(buffer);
lcd_setstatus(buffer); lcd_setstatus(buffer);
SERIAL_ECHO_START; SERIAL_ECHO_START;
SERIAL_ECHOPGM(MSG_PRINT_TIME " "); SERIAL_ECHOPGM("Print time: ");
SERIAL_ECHOLN(buffer); SERIAL_ECHOLN(buffer);
thermalManager.autotempShutdown(); thermalManager.autotempShutdown();

155
Marlin/duration_t.h

@ -0,0 +1,155 @@
/**
* Marlin 3D Printer Firmware
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef __DURATION_T__
#define __DURATION_T__
struct duration_t {
/**
* @brief Duration is stored in seconds
*/
uint32_t value;
/**
* @brief Constructor
*/
duration_t()
: duration_t(0) {};
/**
* @brief Constructor
*
* @param seconds The number of seconds
*/
duration_t(uint32_t const &seconds) {
this->value = seconds;
}
/**
* @brief Equality comparison
* @details Overloads the equality comparison operator
*
* @param value The number of seconds to compare to
* @return True if both durations are equal
*/
bool operator==(const uint32_t &value) const {
return (this->value == value);
}
/**
* @brief Inequality comparison
* @details Overloads the inequality comparison operator
*
* @param value The number of seconds to compare to
* @return False if both durations are equal
*/
bool operator!=(const uint32_t &value) const {
return ! this->operator==(value);
}
/**
* @brief Formats the duration as years
* @return The number of years
*/
inline uint8_t year() const {
return this->day() / 365;
}
/**
* @brief Formats the duration as days
* @return The number of days
*/
inline uint16_t day() const {
return this->hour() / 24;
}
/**
* @brief Formats the duration as hours
* @return The number of hours
*/
inline uint32_t hour() const {
return this->minute() / 60;
}
/**
* @brief Formats the duration as minutes
* @return The number of minutes
*/
inline uint32_t minute() const {
return this->second() / 60;
}
/**
* @brief Formats the duration as seconds
* @return The number of seconds
*/
inline uint32_t second() const {
return this->value;
}
/**
* @brief Formats the duration as a string
* @details String will be formated using a "full" representation of duration
*
* @param buffer The array pointed to must be able to accommodate 21 bytes
*
* Output examples:
* 123456789012345678901 (strlen)
* 135y 364d 23h 59m 59s
* 364d 23h 59m 59s
* 23h 59m 59s
* 59m 59s
* 59s
*/
void toString(char *buffer) const {
int y = this->year(),
d = this->day() % 365,
h = this->hour() % 24,
m = this->minute() % 60,
s = this->second() % 60;
if (y) sprintf_P(buffer, PSTR("%iy %id %ih %im %is"), y, d, h, m, s);
else if (d) sprintf_P(buffer, PSTR("%id %ih %im %is"), d, h, m, s);
else if (h) sprintf_P(buffer, PSTR("%ih %im %is"), h, m, s);
else if (m) sprintf_P(buffer, PSTR("%im %is"), m, s);
else sprintf_P(buffer, PSTR("%is"), s);
}
/**
* @brief Formats the duration as a string
* @details String will be formated using a "digital" representation of duration
*
* @param buffer The array pointed to must be able to accommodate 10 bytes
*
* Output examples:
* 1234567890 (strlen)
* 1193046:59
*/
void toDigital(char *buffer) const {
int h = this->hour() % 24,
m = this->minute() % 60;
sprintf_P(buffer, PSTR("%02i:%02i"), h, m);
}
};
#endif // __DURATION_T__

12
Marlin/printcounter.cpp

@ -22,7 +22,7 @@
#include "Marlin.h" #include "Marlin.h"
#include "printcounter.h" #include "printcounter.h"
#include "timestamp_t.h" #include "duration_t.h"
PrintCounter::PrintCounter(): super() { PrintCounter::PrintCounter(): super() {
this->loadStats(); this->loadStats();
@ -94,7 +94,7 @@ void PrintCounter::saveStats() {
void PrintCounter::showStats() { void PrintCounter::showStats() {
char buffer[21]; char buffer[21];
timestamp_t time; duration_t elapsed;
SERIAL_PROTOCOLPGM(MSG_STATS); SERIAL_PROTOCOLPGM(MSG_STATS);
@ -111,8 +111,8 @@ void PrintCounter::showStats() {
SERIAL_EOL; SERIAL_EOL;
SERIAL_PROTOCOLPGM(MSG_STATS); SERIAL_PROTOCOLPGM(MSG_STATS);
time.timestamp = this->data.printTime; elapsed = this->data.printTime;
time.toString(buffer); elapsed.toString(buffer);
SERIAL_ECHOPGM("Total time: "); SERIAL_ECHOPGM("Total time: ");
SERIAL_ECHO(buffer); SERIAL_ECHO(buffer);
@ -123,8 +123,8 @@ void PrintCounter::showStats() {
SERIAL_ECHOPGM(")"); SERIAL_ECHOPGM(")");
#endif #endif
time.timestamp = this->data.longestPrint; elapsed = this->data.longestPrint;
time.toString(buffer); elapsed.toString(buffer);
SERIAL_ECHOPGM(", Longest job: "); SERIAL_ECHOPGM(", Longest job: ");
SERIAL_ECHO(buffer); SERIAL_ECHO(buffer);

128
Marlin/timestamp_t.h

@ -1,128 +0,0 @@
/**
* Marlin 3D Printer Firmware
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef __TIMESTAMP_T__
#define __TIMESTAMP_T__
struct timestamp_t {
/**
* @brief Number of seconds
*/
uint32_t timestamp;
/**
* @brief Timestamp blank constructor
*/
timestamp_t()
: timestamp_t(0) {};
/**
* @briefTimestamp constructor
* @details Initializes the timestamp_t structure based on a number of seconds
*
* @param seconds The number of seconds
*/
timestamp_t(uint32_t const &seconds) {
this->timestamp = seconds;
}
/**
* @brief Formats the timestamp in years
* @return The number of years
*/
inline uint8_t year() const {
return this->day() / 365;
}
/**
* @brief Formats the timestamp in days
* @return The number of days
*/
inline uint16_t day() const {
return this->hour() / 24;
}
/**
* @brief Formats the timestamp in hours
* @return The number of hours
*/
inline uint32_t hour() const {
return this->minute() / 60;
}
/**
* @brief Formats the timestamp in minutes
* @return The number of minutes
*/
inline uint32_t minute() const {
return this->second() / 60;
}
/**
* @brief Formats the timestamp in seconds
* @return The number of seconds
*/
inline uint32_t second() const {
return this->timestamp;
}
/**
* @brief Formats the timestamp as a string
* @details Returns the timestamp formated as a string
*
* @param buffer The array pointed to must be able to accommodate 21 bytes when
* on standard mode or 10 bytes otherwise.
* @param shorty If true a short representation will be returned.
*
* Standard toString() output examples:
* 123456789012345678901 (strlen)
* 135y 364d 23h 59m 59s
* 364d 23h 59m 59s
* 23h 59m 59s
* 59m 59s
* 59s
*
* Short toString() output examples:
* 1234567890 (strlen)
* 1193046:59
*
*/
void toString(char *buffer, bool const &shorty = false) const {
int h = this->hour() % 24,
m = this->minute() % 60;
if (shorty) sprintf_P(buffer, PSTR("%02i:%02i"), h, m);
else {
int y = this->year(),
d = this->day() % 365,
s = this->second() % 60;
if (y) sprintf_P(buffer, PSTR("%iy %id %ih %im %is"), y, d, h, m, s);
else if (d) sprintf_P(buffer, PSTR("%id %ih %im %is"), d, h, m, s);
else if (h) sprintf_P(buffer, PSTR("%ih %im %is"), h, m, s);
else if (m) sprintf_P(buffer, PSTR("%im %is"), m, s);
else sprintf_P(buffer, PSTR("%is"), s);
}
}
};
#endif // __TIMESTAMP_T__

12
Marlin/ultralcd.cpp

@ -31,7 +31,7 @@
#if ENABLED(PRINTCOUNTER) #if ENABLED(PRINTCOUNTER)
#include "printcounter.h" #include "printcounter.h"
#include "timestamp_t.h" #include "duration_t.h"
#endif #endif
int preheatHotendTemp1, preheatBedTemp1, preheatFanSpeed1, int preheatHotendTemp1, preheatBedTemp1, preheatFanSpeed1,
@ -1979,13 +1979,15 @@ void kill_screen(const char* lcd_msg) {
STATIC_ITEM(MSG_INFO_PRINT_COUNT ": ", false, false, itostr3left(stats.totalPrints)); // Print Count: 999 STATIC_ITEM(MSG_INFO_PRINT_COUNT ": ", false, false, itostr3left(stats.totalPrints)); // Print Count: 999
STATIC_ITEM(MSG_INFO_COMPLETED_PRINTS" : ", false, false, itostr3left(stats.finishedPrints)); // Completed : 666 STATIC_ITEM(MSG_INFO_COMPLETED_PRINTS" : ", false, false, itostr3left(stats.finishedPrints)); // Completed : 666
timestamp_t time(stats.printTime); duration_t elapsed = stats.printTime;
time.toString(buffer); elapsed.toString(buffer);
STATIC_ITEM(MSG_INFO_PRINT_TIME ": ", false, false); // Total print Time: STATIC_ITEM(MSG_INFO_PRINT_TIME ": ", false, false); // Total print Time:
STATIC_ITEM("", false, false, buffer); // 99y 364d 23h 59m 59s STATIC_ITEM("", false, false, buffer); // 99y 364d 23h 59m 59s
time.timestamp = stats.longestPrint; elapsed = stats.longestPrint;
time.toString(buffer); elapsed.toString(buffer);
STATIC_ITEM(MSG_INFO_PRINT_LONGEST ": ", false, false); // Longest job time: STATIC_ITEM(MSG_INFO_PRINT_LONGEST ": ", false, false); // Longest job time:
STATIC_ITEM("", false, false, buffer); // 99y 364d 23h 59m 59s STATIC_ITEM("", false, false, buffer); // 99y 364d 23h 59m 59s

10
Marlin/ultralcd_impl_DOGM.h

@ -58,7 +58,7 @@
#include "ultralcd_st7920_u8glib_rrd.h" #include "ultralcd_st7920_u8glib_rrd.h"
#include "Configuration.h" #include "Configuration.h"
#include "timestamp_t.h" #include "duration_t.h"
#if DISABLED(MAPPER_C2C3) && DISABLED(MAPPER_NON) && ENABLED(USE_BIG_EDIT_FONT) #if DISABLED(MAPPER_C2C3) && DISABLED(MAPPER_NON) && ENABLED(USE_BIG_EDIT_FONT)
#undef USE_BIG_EDIT_FONT #undef USE_BIG_EDIT_FONT
@ -391,10 +391,10 @@ static void lcd_implementation_status_screen() {
u8g.setPrintPos(80,48); u8g.setPrintPos(80,48);
char buffer[10]; char buffer[10];
timestamp_t time(print_job_timer.duration()); duration_t elapsed = print_job_timer.duration();
time.toString(buffer, true); elapsed.toDigital(buffer);
if (time.timestamp != 0) lcd_print(buffer); lcd_print(buffer);
else lcd_printPGM(PSTR("--:--"));
#endif #endif
// Extruders // Extruders

9
Marlin/ultralcd_impl_HD44780.h

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

Loading…
Cancel
Save