Skip to content

Commit e4431f0

Browse files
authored
Merge pull request #229 from LeeLeahy2/uptime
Display the uptime in the system menu
2 parents ee50be2 + 59bf347 commit e4431f0

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

Firmware/RTK_Surveyor/RTK_Surveyor.ino

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ const int FIRMWARE_VERSION_MINOR = 3;
4545
#define IDLE_COUNT_PER_SECOND 196289
4646
#define IDLE_TIME_DISPLAY_SECONDS 5
4747
#define MAX_IDLE_TIME_COUNT (IDLE_TIME_DISPLAY_SECONDS * IDLE_COUNT_PER_SECOND)
48+
#define MILLISECONDS_IN_A_SECOND 1000
49+
#define MILLISECONDS_IN_A_MINUTE (60 * MILLISECONDS_IN_A_SECOND)
50+
#define MILLISECONDS_IN_AN_HOUR (60 * MILLISECONDS_IN_A_MINUTE)
51+
#define MILLISECONDS_IN_A_DAY (24 * MILLISECONDS_IN_AN_HOUR)
4852

4953
//Hardware connections
5054
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
@@ -425,6 +429,9 @@ uint32_t cpuIdleCount[MAX_CPU_CORES];
425429
TaskHandle_t idleTaskHandle[MAX_CPU_CORES];
426430
uint32_t cpuLastIdleDisplayTime;
427431

432+
uint64_t uptime;
433+
uint32_t previousMilliseconds;
434+
428435
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
429436

430437
void setup()
@@ -482,6 +489,9 @@ void setup()
482489

483490
void loop()
484491
{
492+
uint32_t delayTime;
493+
uint32_t currentMilliseconds;
494+
485495
if (online.gnss == true)
486496
{
487497
i2cGNSS.checkUblox(); //Regularly poll to get latest data and any RTCM
@@ -520,6 +530,13 @@ void loop()
520530
if (settings.enablePrintIdleTime)
521531
printIdleTimes();
522532

533+
//Monitor the days in uptime
534+
currentMilliseconds = millis();
535+
uptime = (uptime & 0xffffffff00000000ull) | currentMilliseconds;
536+
if (currentMilliseconds < previousMilliseconds)
537+
uptime += 0x100000000ull;
538+
previousMilliseconds = currentMilliseconds;
539+
523540
//A small delay prevents panic if no other I2C or functions are called
524541
delay(10);
525542
}

Firmware/RTK_Surveyor/menuSystem.ino

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ void menuSystem()
6565
//Display MAC address
6666
char macAddress[5];
6767
sprintf(macAddress, "%02X%02X", unitMACAddress[4], unitMACAddress[5]);
68-
6968
Serial.print(F("Bluetooth ("));
7069
Serial.print(macAddress);
7170
Serial.print(F("): "));
@@ -103,6 +102,36 @@ void menuSystem()
103102
}
104103
Serial.println();
105104

105+
//Display the uptime
106+
uint64_t uptimeMilliseconds = uptime;
107+
uint32_t uptimeDays = 0;
108+
while (uptimeMilliseconds >= MILLISECONDS_IN_A_DAY) {
109+
uptimeMilliseconds -= MILLISECONDS_IN_A_DAY;
110+
uptimeDays += 1;
111+
}
112+
byte uptimeHours = 0;
113+
while (uptimeMilliseconds >= MILLISECONDS_IN_AN_HOUR) {
114+
uptimeMilliseconds -= MILLISECONDS_IN_AN_HOUR;
115+
uptimeHours += 1;
116+
}
117+
byte uptimeMinutes = 0;
118+
while (uptimeMilliseconds >= MILLISECONDS_IN_A_MINUTE) {
119+
uptimeMilliseconds -= MILLISECONDS_IN_A_MINUTE;
120+
uptimeMinutes += 1;
121+
}
122+
byte uptimeSeconds = 0;
123+
while (uptimeMilliseconds >= MILLISECONDS_IN_A_SECOND) {
124+
uptimeMilliseconds -= MILLISECONDS_IN_A_SECOND;
125+
uptimeSeconds += 1;
126+
}
127+
Serial.print(F("Uptime: "));
128+
Serial.printf("%d %02d:%02d:%02d.%03ld\r\n",
129+
uptimeDays,
130+
uptimeHours,
131+
uptimeMinutes,
132+
uptimeSeconds,
133+
uptimeMilliseconds);
134+
106135
if (settings.enableSD == true)
107136
{
108137
Serial.println(F("f) Display microSD Files"));

0 commit comments

Comments
 (0)