Browse Source

Merge pull request #4376 from jbrazio/timestamp_t-short

Adds short format to timestamp_t
pull/1/head
Scott Lahteine 8 years ago
committed by GitHub
parent
commit
1766b990b8
  1. 21
      Marlin/language_en.h
  2. 52
      Marlin/timestamp_t.h
  3. 34
      Marlin/ultralcd.cpp
  4. 14
      Marlin/ultralcd_impl_DOGM.h
  5. 16
      Marlin/ultralcd_impl_HD44780.h

21
Marlin/language_en.h

@ -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

52
Marlin/timestamp_t.h

@ -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,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
*/
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
*/
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
*/
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
*/
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
*/
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
*
* @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
@ -99,19 +101,27 @@ struct timestamp_t {
* 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);
}
}
};

34
Marlin/ultralcd.cpp

@ -31,6 +31,7 @@
#if ENABLED(PRINTCOUNTER)
#include "printcounter.h"
#include "timestamp_t.h"
#endif
int preheatHotendTemp1, preheatBedTemp1, preheatFanSpeed1,
@ -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

14
Marlin/ultralcd_impl_DOGM.h

@ -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
@ -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

16
Marlin/ultralcd_impl_HD44780.h

@ -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.
////////////////////////////////////
@ -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

Loading…
Cancel
Save