Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds short format to timestamp_t #4376

Merged
merged 4 commits into from
Jul 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Member

@thinkyhead thinkyhead Jul 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These strings can't be so long! Please be more concise. Use a "ruler":

12345678901234567890
Total print time: 1h 44m 23s

Copy link

@ghost ghost Jul 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, current (newest RCBugFix) displaying of "Total time" is as follows for some reason...
By #4374? or the others?
Isn't it intended?
dscn1715

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right. That was a @petrzjunior contribution, I believe. Only way it fits, pretty much.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it was my idea. Looks weird on graphical LCD, but on 16x2 you can't do much about it. This fits perfectly in 16 chars with 5-digit year number, which is the limit for int32.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These strings can't be so long! Please be more concise. Use a "ruler":

Those can be big because the output is on the next line.

#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"
Copy link
Member

@thinkyhead thinkyhead Jul 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These strings were padded to align their values and give a cleaner appearance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The padding is now on the LCD display code which makes much more sense.

#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
Copy link
Member

@thinkyhead thinkyhead Jul 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A note on terminology. It's not really a "timestamp" (a point in time) but rather a "duration" or an "interval." And this function doesn't really "format" the interval (a string operation). Rather, it returns the number of total years in the interval.

* @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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is customarily called "digital" time format in English.

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