diff --git a/Core/Modules/CANCallbacks.c b/Core/Modules/CANCallbacks.c index 12fc8dd8..f4a22063 100644 --- a/Core/Modules/CANCallbacks.c +++ b/Core/Modules/CANCallbacks.c @@ -64,9 +64,10 @@ void EventDataCallback(iCommsMessage_t* msg) { LogCanMessagePairValue(aggregatorWrapper, EVENT_DATA_ID, code, msg->data[0], CAN_DECIMAL); if (code == STOP_COUNTDOWN) { - + SetCountDownTime(aggregatorWrapper, msg->data[0]); } - } else { + } + else { DebugPrint("Received corrupted event CAN message."); } } diff --git a/Core/Src/main.c b/Core/Src/main.c index 58a6d906..af355485 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -145,7 +145,8 @@ int main(void) { tft_init(); touchpad_init(); #define N_CAN_MESSAGES_IN_LOG 8 - DataAggregatorWrapper* wrapper = DataAggregator_Create(10, 10, 10, 10, 10, N_CAN_MESSAGES_IN_LOG); + DataAggregatorWrapper* wrapper = DataAggregator_Create(10, 10, 10, 10, 10, + N_CAN_MESSAGES_IN_LOG, 1); CAN_SetAggregator(wrapper); Application_Create(wrapper); diff --git a/Core/UI/Data/DataAggregator.hpp b/Core/UI/Data/DataAggregator.hpp index 95ab4f6a..bdc3a64c 100644 --- a/Core/UI/Data/DataAggregator.hpp +++ b/Core/UI/Data/DataAggregator.hpp @@ -25,13 +25,15 @@ using namespace std; */ class DataAggregator { public: - explicit DataAggregator(uint8_t motorVelocitiesSize, uint8_t batteryVoltagesSize, uint8_t throttleSize, uint8_t lapEfficienciesSize, uint8_t lapTimesSize, uint8_t canLogMessagesSize, bool prefillLapTimes = true): + explicit DataAggregator(uint8_t motorVelocitiesSize, uint8_t batteryVoltagesSize, uint8_t throttleSize, uint8_t lapEfficienciesSize, uint8_t lapTimesSize, uint8_t canLogMessagesSize, + uint8_t countdownTimeSize, bool prefillLapTimes = true): motorVelocities(motorVelocitiesSize), batteryVoltages(batteryVoltagesSize), throttlePositions(throttleSize), lapEfficiencies(lapEfficienciesSize), lapTimes(lapTimesSize), - canLogEntries(canLogMessagesSize) { + canLogEntries(canLogMessagesSize), + countdownTime(countdownTimeSize){ if (prefillLapTimes) { for (uint8_t i = 0; i < lapTimesSize; i++){ lapTimes.add(0); @@ -50,6 +52,8 @@ class DataAggregator { ObservedDataQueue throttlePositions; /** The observed object that holds pointers to logged can messages; */ ObservedDataQueue canLogEntries; + /** The observed object that holds the amount of seconds to countdown from */ + ObservedDataQueue countdownTime; }; /** Returns a reference to the data aggregator object from a given wrapper. diff --git a/Core/UI/Data/DataAggregatorWrapper.cpp b/Core/UI/Data/DataAggregatorWrapper.cpp index 293cb4b4..11001950 100644 --- a/Core/UI/Data/DataAggregatorWrapper.cpp +++ b/Core/UI/Data/DataAggregatorWrapper.cpp @@ -7,24 +7,22 @@ struct DataAggregatorWrapper { DataAggregator aggregator; - - explicit DataAggregatorWrapper(uint8_t motorVelocitiesSize, uint8_t batteryVoltagesSize, - uint8_t lapEfficienciesSize, uint8_t lapTimesSize, uint8_t throttleSize, - uint8_t canLogSize) : - aggregator(motorVelocitiesSize, batteryVoltagesSize, throttleSize, lapEfficienciesSize, lapTimesSize, - canLogSize) {} + //TODO: LAP EFFICIENCIES DOESN'T GET USED + explicit DataAggregatorWrapper(uint8_t motorVelocitiesSize, uint8_t batteryVoltagesSize, uint8_t lapEfficienciesSize, uint8_t lapTimesSize, uint8_t throttleSize, uint8_t canLogSize, + uint8_t countdownTimeSize) : + aggregator(motorVelocitiesSize, batteryVoltagesSize, throttleSize, lapEfficienciesSize, lapTimesSize, canLogSize, countdownTimeSize) {} }; -DataAggregatorWrapper* -DataAggregator_Create(uint8_t motorVelocitiesSize, uint8_t batteryVoltagesSize, uint8_t lapEfficienciesSize, - uint8_t lapTimesSize, uint8_t throttleSize, uint8_t canLogSize) { - auto* wrapper = new DataAggregatorWrapper(motorVelocitiesSize, batteryVoltagesSize, lapEfficienciesSize, - lapTimesSize, throttleSize, canLogSize); +DataAggregatorWrapper* DataAggregator_Create(uint8_t motorVelocitiesSize, uint8_t batteryVoltagesSize, uint8_t lapEfficienciesSize, uint8_t lapTimesSize, uint8_t throttleSize, uint8_t canLogSize, + uint8_t countdownTimeSize) { + auto* wrapper = new DataAggregatorWrapper(motorVelocitiesSize, batteryVoltagesSize, lapEfficienciesSize, lapTimesSize, throttleSize, canLogSize, countdownTimeSize); return wrapper; } -void SetCountDownTime() +void SetCountDownTime(DataAggregatorWrapper* wrapper, seconds_t time){ + wrapper->aggregator.countdownTime.add(time); +} void SetMotorRPM(DataAggregatorWrapper* wrapper, velocity_t rpm) { wrapper->aggregator.motorVelocities.add(rpm); @@ -38,13 +36,11 @@ void SetLapTime(DataAggregatorWrapper* wrapper, ms_t time) { wrapper->aggregator.lapTimes.add(time); } -void -LogCanMessage(DataAggregatorWrapper* wrapper, ICommsMessageLookUpIndex type, uint32_t value, CANLogEntryFormat style) { +void LogCanMessage(DataAggregatorWrapper* wrapper, ICommsMessageLookUpIndex type, uint32_t value, CANLogEntryFormat style) { wrapper->aggregator.canLogEntries.add(new CANLogEntry(type, value, style)); } -void LogCanMessagePairValue(DataAggregatorWrapper* wrapper, ICommsMessageLookUpIndex type, uint32_t a, uint32_t b, - CANLogEntryFormat style) { +void LogCanMessagePairValue(DataAggregatorWrapper* wrapper, ICommsMessageLookUpIndex type, uint32_t a, uint32_t b, CANLogEntryFormat style) { wrapper->aggregator.canLogEntries.add(new CANLogEntry(type, a, b, style)); } diff --git a/Core/UI/Data/DataAggregatorWrapper.h b/Core/UI/Data/DataAggregatorWrapper.h index 4470b5c9..5f81ba4c 100644 --- a/Core/UI/Data/DataAggregatorWrapper.h +++ b/Core/UI/Data/DataAggregatorWrapper.h @@ -17,7 +17,7 @@ extern "C" { * Creates a data aggregator wrapper object and returns a pointer to it. * @return A pointer to the data aggregator wrapper object. */ -DataAggregatorWrapper* DataAggregator_Create(uint8_t motorVelocitiesSize, uint8_t batteryVoltagesSize, uint8_t lapEfficienciesSize, uint8_t lapTimesSize, uint8_t throttleSize, uint8_t canLogSize); +DataAggregatorWrapper* DataAggregator_Create(uint8_t motorVelocitiesSize, uint8_t batteryVoltagesSize, uint8_t lapEfficienciesSize, uint8_t lapTimesSize, uint8_t throttleSize, uint8_t canLogSize, uint8_t countdownTimeSize); /** @ingroup core-modules * Sets the motor RPM data in the data aggregator object from a given wrapper. @@ -26,6 +26,8 @@ DataAggregatorWrapper* DataAggregator_Create(uint8_t motorVelocitiesSize, uint8_ */ void SetMotorRPM(DataAggregatorWrapper* wrapper, velocity_t rpm); +void SetCountDownTime(DataAggregatorWrapper* wrapper, seconds_t time); + /** @ingroup core-modules * Sets the battery voltage data in the data aggregator object from a given wrapper. * @param wrapper The pointer to the wrapper that contains the data aggregator object. diff --git a/Core/UI/HomeView.cpp b/Core/UI/HomeView.cpp index 5b98f87e..6afa6491 100644 --- a/Core/UI/HomeView.cpp +++ b/Core/UI/HomeView.cpp @@ -9,8 +9,7 @@ static lv_obj_t * stopCountMeter; -static void set_value(lv_meter_indicator_t * indic, int32_t v) -{ +static void set_value(lv_meter_indicator_t * indic, int32_t v){ lv_meter_set_indicator_end_value(stopCountMeter, indic, v); } @@ -37,11 +36,11 @@ HomeView::HomeView(lv_obj_t* parent, DataAggregator& aggregator) : View(parent, lv_label_set_text(lapTimeLabel, "0m 0s"); lv_obj_add_style(lapTimeLabel, styles->GetExtraLargeTextStyle(), LV_PART_MAIN);*/ -// batteryVoltageLabel = lv_label_create(bottomRow); -// lv_label_set_text(batteryVoltageLabel, "2V"); -// lv_obj_add_style(batteryVoltageLabel, styles->GetExtraLargeTextStyle(), LV_PART_MAIN | LV_STATE_DEFAULT); -// lv_obj_center(batteryVoltageLabel); -// lv_obj_align(batteryVoltageLabel, LV_ALIGN_BOTTOM_MID, 0, 0); +/* batteryVoltageLabel = lv_label_create(bottomRow); + lv_label_set_text(batteryVoltageLabel, "2V"); + lv_obj_add_style(batteryVoltageLabel, styles->GetExtraLargeTextStyle(), LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_center(batteryVoltageLabel); + lv_obj_align(batteryVoltageLabel, LV_ALIGN_BOTTOM_MID, 0, 0);*/ /* motorRPMLabel = lv_label_create(bottomRow); lv_label_set_text(motorRPMLabel, "0 RPM"); @@ -73,12 +72,13 @@ HomeView::HomeView(lv_obj_t* parent, DataAggregator& aggregator) : View(parent, lv_anim_start(secs); -// lapEfficiencyLabel = lv_label_create(bottomRow); -// lv_label_set_text(lapEfficiencyLabel, "+99%"); -// lv_obj_add_style(lapEfficiencyLabel, styles->GetLargeTextStyle(), LV_PART_MAIN | LV_STATE_DEFAULT); -// lv_obj_align(lapEfficiencyLabel, LV_ALIGN_CENTER, 0, 0); - /*lapTimeBarGraph = lv_chart_create(bottomRow); +/* lapEfficiencyLabel = lv_label_create(bottomRow); + lv_label_set_text(lapEfficiencyLabel, "+99%"); + lv_obj_add_style(lapEfficiencyLabel, styles->GetLargeTextStyle(), LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_align(lapEfficiencyLabel, LV_ALIGN_CENTER, 0, 0);*/ + +/* lapTimeBarGraph = lv_chart_create(bottomRow); lv_chart_set_type(lapTimeBarGraph, LV_CHART_TYPE_BAR); lv_obj_set_size(lapTimeBarGraph, 200, 150); lv_obj_center(lapTimeBarGraph); @@ -120,16 +120,16 @@ HomeView::HomeView(lv_obj_t* parent, DataAggregator& aggregator) : View(parent, lv_chart_refresh(lapTimeBarGraph); });*/ -// getDataAggregator().throttlePositions.addListenerForLatest([this](const percentage_t& throttle) { -// lv_anim_t a; -// lv_anim_init(&a); -// lv_anim_set_var(&a, throttleArc); -// lv_anim_set_exec_cb(&a, reinterpret_cast(setArcValue)); -// lv_anim_set_time(&a, 100); -// lv_anim_set_values(&a, lv_arc_get_value(throttleArc), throttle); -// lv_anim_start(&a); -// lv_label_set_text_fmt(lapTimeLabel, "%d", throttle); - // }); +/* getDataAggregator().throttlePositions.addListenerForLatest([this](const percentage_t& throttle) { + lv_anim_t a; + lv_anim_init(&a); + lv_anim_set_var(&a, throttleArc); + lv_anim_set_exec_cb(&a, reinterpret_cast(setArcValue)); + lv_anim_set_time(&a, 100); + lv_anim_set_values(&a, lv_arc_get_value(throttleArc), throttle); + lv_anim_start(&a); + lv_label_set_text_fmt(lapTimeLabel, "%d", throttle); + });*/ /* lv_timer_t * timer = lv_timer_create([](lv_timer_t * timer) {lv_anim_t a;