Skip to content

Commit

Permalink
added countdown to data aggregator, fixed formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
AnniqueG committed Feb 5, 2024
1 parent e0fb547 commit c0214f8
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 44 deletions.
5 changes: 3 additions & 2 deletions Core/Modules/CANCallbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}
Expand Down
3 changes: 2 additions & 1 deletion Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
8 changes: 6 additions & 2 deletions Core/UI/Data/DataAggregator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -50,6 +52,8 @@ class DataAggregator {
ObservedDataQueue<percentage_t> throttlePositions;
/** The observed object that holds pointers to logged can messages; */
ObservedDataQueue<CANLogEntry*> canLogEntries;
/** The observed object that holds the amount of seconds to countdown from */
ObservedDataQueue<seconds_t> countdownTime;
};

/** Returns a reference to the data aggregator object from a given wrapper.
Expand Down
28 changes: 12 additions & 16 deletions Core/UI/Data/DataAggregatorWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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));
}

Expand Down
4 changes: 3 additions & 1 deletion Core/UI/Data/DataAggregatorWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
44 changes: 22 additions & 22 deletions Core/UI/HomeView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<lv_anim_exec_xcb_t>(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<lv_anim_exec_xcb_t>(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;
Expand Down

0 comments on commit c0214f8

Please sign in to comment.