Skip to content

Commit

Permalink
Merge pull request #4376 from jbrazio/timestamp_t-short
Browse files Browse the repository at this point in the history
Adds short format to timestamp_t
  • Loading branch information
thinkyhead authored Jul 23, 2016
2 parents 6da3729 + 9e5dbf6 commit 1766b99
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 55 deletions.
21 changes: 17 additions & 4 deletions Marlin/language_en.h
Original file line number Diff line number Diff line change
Expand Up @@ -561,22 +561,35 @@
#define MSG_INFO_PRINT_COUNT "Print Count"
#endif
#ifndef MSG_INFO_COMPLETED_PRINTS
#define MSG_INFO_COMPLETED_PRINTS "Completed "
#define MSG_INFO_COMPLETED_PRINTS "Completed"
#endif
#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
#else
#ifndef MSG_INFO_PRINT_COUNT
#define MSG_INFO_PRINT_COUNT "Prints "
#define MSG_INFO_PRINT_COUNT "Prints"
#endif
#ifndef MSG_INFO_COMPLETED_PRINTS
#define MSG_INFO_COMPLETED_PRINTS "Completed"
#endif
#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

#ifndef MSG_INFO_MIN_TEMP
#define MSG_INFO_MIN_TEMP "Min Temp"
#endif
Expand Down
52 changes: 31 additions & 21 deletions Marlin/timestamp_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ struct timestamp_t {
uint32_t timestamp;

/**
* @brief Date time blank constructor
* @brief Timestamp blank constructor
*/
timestamp_t()
: timestamp_t(0) {};

/**
* @brief Date time constructor
* @briefTimestamp constructor
* @details Initializes the timestamp_t structure based on a number of seconds
*
* @param seconds The number of seconds
Expand All @@ -46,72 +46,82 @@ struct timestamp_t {
}

/**
* @brief Formats the date as number of years
* @brief Formats the timestamp in years
* @return The number of years
*/
inline uint8_t year() const {
return this->day() / 365;
}

/**
* @brief Formats the date as number of days
* @brief Formats the timestamp in days
* @return The number of days
*/
inline uint16_t day() const {
return this->hour() / 24;
}

/**
* @brief Formats the date as number of hours
* @brief Formats the timestamp in hours
* @return The number of hours
*/
inline uint32_t hour() const {
return this->minute() / 60;
}

/**
* @brief Formats the date as number of minutes
* @brief Formats the timestamp in minutes
* @return The number of minutes
*/
inline uint32_t minute() const {
return this->second() / 60;
}

/**
* @brief Formats the date as number of seconds
* @brief Formats the timestamp in seconds
* @return The number of seconds
*/
inline uint32_t second() const {
return this->timestamp;
}

/**
* @brief Formats the date as a string
* @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
* @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)
* 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) const {
int y = this->year(),
d = this->day() % 365,
h = this->hour() % 24,
m = this->minute() % 60,
s = this->second() % 60;
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);
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);
}
}
};

Expand Down
34 changes: 19 additions & 15 deletions Marlin/ultralcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#if ENABLED(PRINTCOUNTER)
#include "printcounter.h"
#include "timestamp_t.h"
#endif

int preheatHotendTemp1, preheatBedTemp1, preheatFanSpeed1,
Expand Down Expand Up @@ -1971,23 +1972,26 @@ void kill_screen(const char* lcd_msg) {
static void lcd_info_stats_menu() {
if (LCD_CLICKED) { lcd_goto_previous_menu(true); return; }

PrintCounter print_job_counter = PrintCounter();
print_job_counter.loadStats();
printStatistics stats = print_job_counter.getStats();
char buffer[21];
printStatistics stats = print_job_timer.getStats();

char timeString[14];
sprintf_P(timeString,
PSTR("%i" MSG_SHORT_DAY " %i" MSG_SHORT_HOUR " %i" MSG_SHORT_MINUTE),
int(stats.printTime / 60 / 60 / 24),
int((stats.printTime / 60 / 60) % 24),
int((stats.printTime / 60) % 60)
);
START_SCREEN(); // 12345678901234567890
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

timestamp_t time(stats.printTime);
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
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_PRINT_TIME ": ", false, false); // Total Time :
STATIC_ITEM(" ", false, false, timeString); // 12345d 12h 34m
sprintf_P(buffer, PSTR("%im"), stats.filamentUsed / 1000);
STATIC_ITEM(MSG_INFO_PRINT_FILAMENT ": ", false, false); // Extruded total:
STATIC_ITEM("", false, false, buffer); // 125m
END_SCREEN();
}
#endif // PRINTCOUNTER
Expand Down
14 changes: 8 additions & 6 deletions Marlin/ultralcd_impl_DOGM.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
#include "ultralcd_st7920_u8glib_rrd.h"
#include "Configuration.h"

#include "timestamp_t.h"

#if DISABLED(MAPPER_C2C3) && DISABLED(MAPPER_NON) && ENABLED(USE_BIG_EDIT_FONT)
#undef USE_BIG_EDIT_FONT
#endif
Expand Down Expand Up @@ -387,12 +389,12 @@ static void lcd_implementation_status_screen() {
}

u8g.setPrintPos(80,48);
millis_t time = print_job_timer.duration() / 60;
if (time != 0) {
lcd_print(itostr2(time/60));
lcd_print(':');
lcd_print(itostr2(time%60));
}

char buffer[10];
timestamp_t time(print_job_timer.duration());
time.toString(buffer, true);
if (time.timestamp != 0) lcd_print(buffer);
else lcd_printPGM(PSTR("--:--"));
#endif

// Extruders
Expand Down
16 changes: 7 additions & 9 deletions Marlin/ultralcd_impl_HD44780.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
* 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.

////////////////////////////////////
Expand Down Expand Up @@ -760,15 +762,11 @@ static void lcd_implementation_status_screen() {
lcd.setCursor(LCD_WIDTH - 6, 2);
lcd.print(LCD_STR_CLOCK[0]);

uint16_t time = print_job_timer.duration() / 60;
if (time != 0) {
lcd.print(itostr2(time / 60));
lcd.print(':');
lcd.print(itostr2(time % 60));
}
else {
lcd_printPGM(PSTR("--:--"));
}
char buffer[10];
timestamp_t time(print_job_timer.duration());
time.toString(buffer, true);
if (time.timestamp != 0) lcd_print(buffer);
else lcd_printPGM(PSTR("--:--"));

#endif // LCD_HEIGHT > 3

Expand Down

0 comments on commit 1766b99

Please sign in to comment.