fix time display

This commit is contained in:
Thomas Göttgens 2023-02-05 01:46:16 +01:00
parent 9e1f7c4f56
commit fb611ef986
2 changed files with 19 additions and 13 deletions

View File

@ -70,6 +70,8 @@ static char btPIN[16] = "888888";
uint32_t logo_timeout = 5000; // 4 seconds for EACH logo
uint32_t hours_in_month = 730; // 730 hours in a month
// This image definition is here instead of images.h because it's modified dynamically by the drawBattery function
uint8_t imgBattery[16] = {0xFF, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xE7, 0x3C};
@ -386,10 +388,11 @@ static void drawTextMessageFrame(OLEDDisplay *display, OLEDDisplayUiState *state
uint32_t days = hours / 24;
if (config.display.heading_bold) {
display->drawStringf(1 + x, 0 + y, tempBuf, "%s ago from %s", screen->drawTimeDelta(days, hours, minutes, seconds),
display->drawStringf(1 + x, 0 + y, tempBuf, "%s ago from %s",
screen->drawTimeDelta(days, hours, minutes, seconds).c_str(),
(node && node->has_user) ? node->user.short_name : "???");
}
display->drawStringf(0 + x, 0 + y, tempBuf, "%s ago from %s", screen->drawTimeDelta(days, hours, minutes, seconds),
display->drawStringf(0 + x, 0 + y, tempBuf, "%s ago from %s", screen->drawTimeDelta(days, hours, minutes, seconds).c_str(),
(node && node->has_user) ? node->user.short_name : "???");
display->setColor(WHITE);
@ -1336,17 +1339,20 @@ void Screen::blink()
dispdev.setBrightness(brightness);
}
String Screen::drawTimeDelta(uint32_t days, uint32_t hours, uint32_t minutes, uint32_t seconds)
std::string Screen::drawTimeDelta(uint32_t days, uint32_t hours, uint32_t minutes, uint32_t seconds)
{
String uptime;
if (days >= 2)
uptime = String(days) + "d";
std::string uptime;
if (days > (hours_in_month * 6))
uptime = "?";
else if (days >= 2)
uptime = std::to_string(days) + "d";
else if (hours >= 2)
uptime = String(hours) + "h";
uptime = std::to_string(hours) + "h";
else if (minutes >= 1)
uptime = String(minutes) + "m";
uptime = std::to_string(minutes) + "m";
else
uptime = String(seconds) + "s";
uptime = std::to_string(seconds) + "s";
return uptime;
}
@ -1714,7 +1720,7 @@ void DebugInfo::drawFrameSettings(OLEDDisplay *display, OLEDDisplayUiState *stat
display->setColor(WHITE);
// Show uptime as days, hours, minutes OR seconds
String uptime = screen->drawTimeDelta(days, hours, minutes, seconds);
std::string uptime = screen->drawTimeDelta(days, hours, minutes, seconds);
uint32_t rtc_sec = getValidTime(RTCQuality::RTCQualityDevice);
if (rtc_sec > 0) {
@ -1729,12 +1735,12 @@ void DebugInfo::drawFrameSettings(OLEDDisplay *display, OLEDDisplayUiState *stat
int min = (hms % SEC_PER_HOUR) / SEC_PER_MIN;
int sec = (hms % SEC_PER_HOUR) % SEC_PER_MIN; // or hms % SEC_PER_MIN
char timebuf[9];
char timebuf[10];
snprintf(timebuf, sizeof(timebuf), " %02d:%02d:%02d", hour, min, sec);
uptime += timebuf;
}
display->drawString(x, y + FONT_HEIGHT_SMALL * 1, uptime);
display->drawString(x, y + FONT_HEIGHT_SMALL * 1, uptime.c_str());
// Display Channel Utilization
char chUtil[13];

View File

@ -207,7 +207,7 @@ class Screen : public concurrency::OSThread
}
/// generates a very brief time delta display
String drawTimeDelta(uint32_t days, uint32_t hours, uint32_t minutes, uint32_t seconds);
std::string drawTimeDelta(uint32_t days, uint32_t hours, uint32_t minutes, uint32_t seconds);
/// Overrides the default utf8 character conversion, to replace empty space with question marks
static char customFontTableLookup(const uint8_t ch)