Merge pull request #4376 from jbrazio/timestamp_t-short

Adds short format to timestamp_t
master
Scott Lahteine 8 years ago committed by GitHub
commit 1766b990b8

@ -561,22 +561,35 @@
#define MSG_INFO_PRINT_COUNT "Print Count" #define MSG_INFO_PRINT_COUNT "Print Count"
#endif #endif
#ifndef MSG_INFO_COMPLETED_PRINTS #ifndef MSG_INFO_COMPLETED_PRINTS
#define MSG_INFO_COMPLETED_PRINTS "Completed " #define MSG_INFO_COMPLETED_PRINTS "Completed"
#endif #endif
#ifndef MSG_INFO_PRINT_TIME #ifndef MSG_INFO_PRINT_TIME
#define MSG_INFO_PRINT_TIME "Total Time " #define MSG_INFO_PRINT_TIME "Total print time"
#endif
#ifndef MSG_INFO_PRINT_LONGEST
#define MSG_INFO_PRINT_LONGEST "Longest job time"
#endif
#ifndef MSG_INFO_PRINT_FILAMENT
#define MSG_INFO_PRINT_FILAMENT "Extruded total"
#endif #endif
#else #else
#ifndef MSG_INFO_PRINT_COUNT #ifndef MSG_INFO_PRINT_COUNT
#define MSG_INFO_PRINT_COUNT "Prints " #define MSG_INFO_PRINT_COUNT "Prints"
#endif #endif
#ifndef MSG_INFO_COMPLETED_PRINTS #ifndef MSG_INFO_COMPLETED_PRINTS
#define MSG_INFO_COMPLETED_PRINTS "Completed" #define MSG_INFO_COMPLETED_PRINTS "Completed"
#endif #endif
#ifndef MSG_INFO_PRINT_TIME #ifndef MSG_INFO_PRINT_TIME
#define MSG_INFO_PRINT_TIME "Duration " #define MSG_INFO_PRINT_TIME "Total"
#endif
#ifndef MSG_INFO_PRINT_LONGEST
#define MSG_INFO_PRINT_LONGEST "Longest"
#endif
#ifndef MSG_INFO_PRINT_FILAMENT
#define MSG_INFO_PRINT_FILAMENT "Extruded"
#endif #endif
#endif #endif
#ifndef MSG_INFO_MIN_TEMP #ifndef MSG_INFO_MIN_TEMP
#define MSG_INFO_MIN_TEMP "Min Temp" #define MSG_INFO_MIN_TEMP "Min Temp"
#endif #endif

@ -30,13 +30,13 @@ struct timestamp_t {
uint32_t timestamp; uint32_t timestamp;
/** /**
* @brief Date time blank constructor * @brief Timestamp blank constructor
*/ */
timestamp_t() timestamp_t()
: timestamp_t(0) {}; : timestamp_t(0) {};
/** /**
* @brief Date time constructor * @briefTimestamp constructor
* @details Initializes the timestamp_t structure based on a number of seconds * @details Initializes the timestamp_t structure based on a number of seconds
* *
* @param seconds The number of seconds * @param seconds The number of seconds
@ -46,7 +46,7 @@ struct timestamp_t {
} }
/** /**
* @brief Formats the date as number of years * @brief Formats the timestamp in years
* @return The number of years * @return The number of years
*/ */
inline uint8_t year() const { inline uint8_t year() const {
@ -54,7 +54,7 @@ struct timestamp_t {
} }
/** /**
* @brief Formats the date as number of days * @brief Formats the timestamp in days
* @return The number of days * @return The number of days
*/ */
inline uint16_t day() const { inline uint16_t day() const {
@ -62,7 +62,7 @@ struct timestamp_t {
} }
/** /**
* @brief Formats the date as number of hours * @brief Formats the timestamp in hours
* @return The number of hours * @return The number of hours
*/ */
inline uint32_t hour() const { inline uint32_t hour() const {
@ -70,7 +70,7 @@ struct timestamp_t {
} }
/** /**
* @brief Formats the date as number of minutes * @brief Formats the timestamp in minutes
* @return The number of minutes * @return The number of minutes
*/ */
inline uint32_t minute() const { inline uint32_t minute() const {
@ -78,7 +78,7 @@ struct timestamp_t {
} }
/** /**
* @brief Formats the date as number of seconds * @brief Formats the timestamp in seconds
* @return The number of seconds * @return The number of seconds
*/ */
inline uint32_t second() const { inline uint32_t second() const {
@ -86,12 +86,14 @@ struct timestamp_t {
} }
/** /**
* @brief Formats the date as a string * @brief Formats the timestamp as a string
* @details Returns the timestamp formated as a string * @details Returns the timestamp formated as a string
* *
* @param buffer The array pointed to must be able to accommodate 21 bytes * @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.
* *
* String output examples: * Standard toString() output examples:
* 123456789012345678901 (strlen) * 123456789012345678901 (strlen)
* 135y 364d 23h 59m 59s * 135y 364d 23h 59m 59s
* 364d 23h 59m 59s * 364d 23h 59m 59s
@ -99,19 +101,27 @@ struct timestamp_t {
* 59m 59s * 59m 59s
* 59s * 59s
* *
* Short toString() output examples:
* 1234567890 (strlen)
* 1193046:59
*
*/ */
void toString(char *buffer) const { void toString(char *buffer, bool const &shorty = false) const {
int y = this->year(), int h = this->hour() % 24,
d = this->day() % 365, m = this->minute() % 60;
h = this->hour() % 24,
m = this->minute() % 60, if (shorty) sprintf_P(buffer, PSTR("%02i:%02i"), h, m);
s = this->second() % 60; 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); 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 (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 (h) sprintf_P(buffer, PSTR("%ih %im %is"), h, m, s);
else if (m) sprintf_P(buffer, PSTR("%im %is"), m, s); else if (m) sprintf_P(buffer, PSTR("%im %is"), m, s);
else sprintf_P(buffer, PSTR("%is"), s); else sprintf_P(buffer, PSTR("%is"), s);
}
} }
}; };

@ -31,6 +31,7 @@
#if ENABLED(PRINTCOUNTER) #if ENABLED(PRINTCOUNTER)
#include "printcounter.h" #include "printcounter.h"
#include "timestamp_t.h"
#endif #endif
int preheatHotendTemp1, preheatBedTemp1, preheatFanSpeed1, int preheatHotendTemp1, preheatBedTemp1, preheatFanSpeed1,
@ -1971,23 +1972,26 @@ void kill_screen(const char* lcd_msg) {
static void lcd_info_stats_menu() { static void lcd_info_stats_menu() {
if (LCD_CLICKED) { lcd_goto_previous_menu(true); return; } if (LCD_CLICKED) { lcd_goto_previous_menu(true); return; }
PrintCounter print_job_counter = PrintCounter(); char buffer[21];
print_job_counter.loadStats(); printStatistics stats = print_job_timer.getStats();
printStatistics stats = print_job_counter.getStats();
char timeString[14]; START_SCREEN(); // 12345678901234567890
sprintf_P(timeString, STATIC_ITEM(MSG_INFO_PRINT_COUNT ": ", false, false, itostr3left(stats.totalPrints)); // Print Count: 999
PSTR("%i" MSG_SHORT_DAY " %i" MSG_SHORT_HOUR " %i" MSG_SHORT_MINUTE), STATIC_ITEM(MSG_INFO_COMPLETED_PRINTS" : ", false, false, itostr3left(stats.finishedPrints)); // Completed : 666
int(stats.printTime / 60 / 60 / 24),
int((stats.printTime / 60 / 60) % 24), timestamp_t time(stats.printTime);
int((stats.printTime / 60) % 60) time.toString(buffer);
); STATIC_ITEM(MSG_INFO_PRINT_TIME ": ", false, false); // Total print Time:
STATIC_ITEM("", false, false, buffer); // 99y 364d 23h 59m 59s
time.timestamp = stats.longestPrint;
time.toString(buffer);
STATIC_ITEM(MSG_INFO_PRINT_LONGEST ": ", false, false); // Longest job time:
STATIC_ITEM("", false, false, buffer); // 99y 364d 23h 59m 59s
START_SCREEN(); // 12345678901234567890 sprintf_P(buffer, PSTR("%im"), stats.filamentUsed / 1000);
STATIC_ITEM(MSG_INFO_PRINT_COUNT ": ", false, false, itostr3left(stats.totalPrints)); // Print Count: 999 STATIC_ITEM(MSG_INFO_PRINT_FILAMENT ": ", false, false); // Extruded total:
STATIC_ITEM(MSG_INFO_COMPLETED_PRINTS": ", false, false, itostr3left(stats.finishedPrints)); // Completed : 666 STATIC_ITEM("", false, false, buffer); // 125m
STATIC_ITEM(MSG_INFO_PRINT_TIME ": ", false, false); // Total Time :
STATIC_ITEM(" ", false, false, timeString); // 12345d 12h 34m
END_SCREEN(); END_SCREEN();
} }
#endif // PRINTCOUNTER #endif // PRINTCOUNTER

@ -58,6 +58,8 @@
#include "ultralcd_st7920_u8glib_rrd.h" #include "ultralcd_st7920_u8glib_rrd.h"
#include "Configuration.h" #include "Configuration.h"
#include "timestamp_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
#endif #endif
@ -387,12 +389,12 @@ static void lcd_implementation_status_screen() {
} }
u8g.setPrintPos(80,48); u8g.setPrintPos(80,48);
millis_t time = print_job_timer.duration() / 60;
if (time != 0) { char buffer[10];
lcd_print(itostr2(time/60)); timestamp_t time(print_job_timer.duration());
lcd_print(':'); time.toString(buffer, true);
lcd_print(itostr2(time%60)); if (time.timestamp != 0) lcd_print(buffer);
} else lcd_printPGM(PSTR("--:--"));
#endif #endif
// Extruders // Extruders

@ -27,6 +27,8 @@
* 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"
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.
//////////////////////////////////// ////////////////////////////////////
@ -760,15 +762,11 @@ static void lcd_implementation_status_screen() {
lcd.setCursor(LCD_WIDTH - 6, 2); lcd.setCursor(LCD_WIDTH - 6, 2);
lcd.print(LCD_STR_CLOCK[0]); lcd.print(LCD_STR_CLOCK[0]);
uint16_t time = print_job_timer.duration() / 60; char buffer[10];
if (time != 0) { timestamp_t time(print_job_timer.duration());
lcd.print(itostr2(time / 60)); time.toString(buffer, true);
lcd.print(':'); if (time.timestamp != 0) lcd_print(buffer);
lcd.print(itostr2(time % 60)); else lcd_printPGM(PSTR("--:--"));
}
else {
lcd_printPGM(PSTR("--:--"));
}
#endif // LCD_HEIGHT > 3 #endif // LCD_HEIGHT > 3

Loading…
Cancel
Save