Getting comfy with uptime, new event timestamp done and tested

This commit is contained in:
Cabooman 2024-04-26 23:07:33 +02:00
parent cee1e11bff
commit 7d11a7d4ed
3 changed files with 20 additions and 5 deletions

View file

@ -8,6 +8,11 @@
#include "../../lib/Uptime_Library/src/uptime.h"
#include "timer.h"
// Time conversion macros
#define DAYS_TO_SECS 86400 // 24 * 60 * 60
#define HOURS_TO_SECS 3600 // 60 * 60
#define MINUTES_TO_SECS 60
#define EE_NOF_EVENT_ENTRIES 30
#define EE_EVENT_ENTRY_SIZE sizeof(EVENT_LOG_ENTRY_TYPE)
#define EE_WRITE_PERIOD_MINUTES 10
@ -45,7 +50,7 @@ typedef struct {
typedef struct {
EVENTS_STRUCT_TYPE entries[EVENT_NOF_EVENTS];
uint32_t time_seconds;
unsigned long time_seconds;
MyTimer second_timer;
MyTimer ee_timer;
MyTimer update_timer;
@ -356,10 +361,17 @@ static void update_event_time(void) {
// This should run roughly 2 times per second
if (events.second_timer.elapsed() == true) {
uptime::calculateUptime(); // millis() overflows every 50 days, so update occasionally to adjust
events.time_seconds = uptime::getSeconds();
events.time_seconds = uptime::getDays() * DAYS_TO_SECS;
events.time_seconds += uptime::getHours() * HOURS_TO_SECS;
events.time_seconds += uptime::getMinutes() * MINUTES_TO_SECS;
events.time_seconds += uptime::getSeconds();
}
}
unsigned long get_current_event_time_secs(void) {
return events.time_seconds;
}
static void log_event(EVENTS_ENUM_TYPE event, uint8_t data) {
// Update head with wrap to 0
if (++events.event_log_head_index == EE_NOF_EVENT_ENTRIES) {