mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-03 09:49:32 +02:00
Some cleanup before more surgery
This commit is contained in:
parent
6bc253ff6e
commit
32378df03e
5 changed files with 17 additions and 13 deletions
|
@ -194,7 +194,7 @@ void loop() {
|
|||
#ifdef DUAL_CAN
|
||||
send_can2();
|
||||
#endif
|
||||
update_event_timestamps();
|
||||
run_event_handling();
|
||||
}
|
||||
|
||||
// Initialization functions
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
# add_library(utils_library 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),
|
||||
|
|
|
@ -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__
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue