diff --git a/Software/Software.ino b/Software/Software.ino index eb65591a..779b6aed 100644 --- a/Software/Software.ino +++ b/Software/Software.ino @@ -194,7 +194,7 @@ void loop() { #ifdef DUAL_CAN send_can2(); #endif - update_event_timestamps(); + run_event_handling(); } // Initialization functions diff --git a/Software/src/devboard/utils/CMakeLists.txt b/Software/src/devboard/utils/CMakeLists.txt deleted file mode 100644 index bded7cb0..00000000 --- a/Software/src/devboard/utils/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -# add_library(utils_library events.cpp) diff --git a/Software/src/devboard/utils/events.cpp b/Software/src/devboard/utils/events.cpp index 06963830..bbdf51ea 100644 --- a/Software/src/devboard/utils/events.cpp +++ b/Software/src/devboard/utils/events.cpp @@ -17,10 +17,15 @@ static uint8_t total_led_color = GREEN; static char event_message[256]; /* Local function prototypes */ +static void update_event_time(void); static void set_event_message(EVENTS_ENUM_TYPE event); static void update_led_color(EVENTS_ENUM_TYPE event); /* Exported functions */ +void run_event_handling(void) { + update_event_time(); +} + void init_events(void) { for (uint8_t i = 0; i < EVENT_NOF_EVENTS; i++) { entries[i].timestamp = 0; @@ -49,7 +54,8 @@ void set_event(EVENTS_ENUM_TYPE event, uint8_t data) { #endif } -void update_event_timestamps(void) { +/* Local functions */ +static void update_event_time(void) { unsigned long new_millis = millis(); if (new_millis - previous_millis >= 1000) { time_seconds++; @@ -57,7 +63,6 @@ void update_event_timestamps(void) { } } -/* Local functions */ static void update_led_color(EVENTS_ENUM_TYPE event) { total_led_color = (total_led_color == RED) ? RED : entries[event].led_color; } @@ -81,7 +86,7 @@ static void set_event_message(EVENTS_ENUM_TYPE event) { "12V battery source below required voltage to safely close contactors. Inspect the supply/battery!"); break; case EVENT_SOC_PLAUSIBILITY_ERROR: - snprintf(event_message, sizeof(event_message), "ERROR: SOC% reported by battery not plausible. Restart battery!"); + snprintf(event_message, sizeof(event_message), "ERROR: SOC reported by battery not plausible. Restart battery!"); break; case EVENT_KWH_PLAUSIBILITY_ERROR: snprintf(event_message, sizeof(event_message), diff --git a/Software/src/devboard/utils/events.h b/Software/src/devboard/utils/events.h index 58abb58e..1b2daf5f 100644 --- a/Software/src/devboard/utils/events.h +++ b/Software/src/devboard/utils/events.h @@ -30,6 +30,6 @@ typedef enum { void init_events(void); void set_event(EVENTS_ENUM_TYPE event, uint8_t data); -void update_event_timestamps(void); +void run_event_handling(void); #endif // __MYTIMER_H__ diff --git a/test/utils/events_test.cpp b/test/utils/events_test.cpp index 1d6c0748..1afae2ed 100644 --- a/test/utils/events_test.cpp +++ b/test/utils/events_test.cpp @@ -1,5 +1,5 @@ // The test library must be included first! -#include "test_lib.h" +#include "../test_lib.h" #include "events.cpp" @@ -16,35 +16,35 @@ TEST(init_events_test) { } } -TEST(update_event_timestamps_test) { +TEST(update_event_time_test) { // Reset init_events(); time_seconds = 0; // No delta, so time shouldn't increase testlib_millis = 0; - update_event_timestamps(); + update_event_time(); ASSERT_EQ(time_seconds, 0); // Almost time to bump the seconds testlib_millis = 999; - update_event_timestamps(); + update_event_time(); ASSERT_EQ(time_seconds, 0); ASSERT_EQ(previous_millis, 0); // millis == 1000, so we should add a second testlib_millis = 1000; - update_event_timestamps(); + update_event_time(); ASSERT_EQ(time_seconds, 1); ASSERT_EQ(previous_millis, 1000); // We shouldn't add more seconds until 2000 now testlib_millis = 1999; - update_event_timestamps(); + update_event_time(); ASSERT_EQ(time_seconds, 1); ASSERT_EQ(previous_millis, 1000); testlib_millis = 2000; - update_event_timestamps(); + update_event_time(); ASSERT_EQ(time_seconds, 2); ASSERT_EQ(previous_millis, 2000); }