-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
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
Changes from all commits
ecd4802
b4aad85
86d9311
9e5dbf6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -46,72 +46,82 @@ struct timestamp_t { | |
} | ||
|
||
/** | ||
* @brief Formats the date as number of years | ||
* @brief Formats the timestamp in years | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
} | ||
}; | ||
|
||
|
There was a problem hiding this comment.
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":
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those can be big because the output is on the next line.