Test stability: uptime clock

This commit is contained in:
Sassa NF
2024-10-01 19:32:46 +01:00
parent ad7ad3d8af
commit 645e9988c8
3 changed files with 48 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
#include "charts.h"
void UptimeClock::draw(uint64_t t)
{
t1 = t;
draw();
}
void UptimeClock::draw()
{
uint64_t uptime = t1 - t0;
int mils = uptime % 1000;
int seconds = (uptime / 1000) % 60;
int minutes = (uptime / 60000) % 60;
int hours = uptime / 3600000;
String s = String(hours) + (minutes < 10 ? ":0" : ":") + String(minutes) +
(seconds < 10 ? ":0" : ":") + String(seconds) +
(mils < 10 ? ".00"
: mils < 100 ? ".0"
: ".") +
String(mils);
int w = display.getStringWidth(s);
display.setColor(BLACK);
display.fillRect((display.width() - w) / 2, display.height() / 2 - 3, w, 7);
display.setColor(WHITE);
display.setTextAlignment(TEXT_ALIGN_CENTER_BOTH);
display.drawString(display.width() / 2, display.height() / 2, s);
}

View File

@@ -153,4 +153,14 @@ struct WaterfallChart : Chart
int x2pos(float x);
};
struct UptimeClock : Chart
{
uint64_t t0;
uint64_t t1;
UptimeClock(OLEDDisplay &d, uint64_t t0) : Chart(d, 0, 0, 0, 0), t0(t0), t1(t0) {};
void draw(uint64_t t);
virtual void draw() override;
};
#endif

View File

@@ -371,6 +371,8 @@ DecoratedBarChart *bar;
WaterfallChart *waterChart;
StackedChart stacked(display, 0, 0, 0, 0);
UptimeClock *uptime;
void init_radio()
{
// initialize SX1262 FSK modem at the initial frequency
@@ -684,6 +686,10 @@ void setup(void)
stacked.setHeight(c, stacked.height - WATERFALL_START);
stacked.setHeight(b, stacked.height);
#ifdef UPTIME_CLOCK
uptime = new UptimeClock(display, millis());
#endif
}
// Formula to translate 33 bin to approximate RSSI value
@@ -1271,6 +1277,10 @@ void loop(void)
stacked.draw();
// Render display data here
#ifdef UPTIME_CLOCK
uptime->draw(millis());
#endif
display.display();
#ifdef OSD_ENABLED
// Sometimes OSD prints entire screen with the digits.