85 lines
2.2 KiB
C++
85 lines
2.2 KiB
C++
#include <gui/model/Model.hpp>
|
|
#include <gui/model/ModelListener.hpp>
|
|
|
|
Model::Model() : modelListener(0) {}
|
|
|
|
#ifdef SIMULATOR
|
|
void bounce(float &value, bool &rising, float step, float lower, float upper) {
|
|
if (rising) {
|
|
value += step;
|
|
if (value > upper) {
|
|
value = upper;
|
|
rising = false;
|
|
}
|
|
} else {
|
|
value -= step;
|
|
if (value < lower) {
|
|
value = lower;
|
|
rising = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
void Model::tick() {
|
|
static float last_lap_delta = 0;
|
|
static bool lap_delta_rising = true;
|
|
static float overall_delta = 0;
|
|
static bool overall_delta_rising = false;
|
|
static float power_limit = 20;
|
|
static bool power_limit_rising = false;
|
|
static float speed_limit = 70;
|
|
static bool speed_limit_rising = true;
|
|
static float soc = 100;
|
|
static bool soc_rising = false;
|
|
static float bat_temp = 13;
|
|
static bool bat_temp_rising = true;
|
|
|
|
static int iter = 0;
|
|
if (iter++ % 5 != 0) {
|
|
return;
|
|
}
|
|
bounce(last_lap_delta, lap_delta_rising, 0.2, -12, 12);
|
|
bounce(overall_delta, overall_delta_rising, 0.1, -12, 12);
|
|
bounce(power_limit, power_limit_rising, 0.1, 5, 30);
|
|
bounce(speed_limit, speed_limit_rising, 0.2, 50, 100);
|
|
bounce(soc, soc_rising, 0.5, 0, 100);
|
|
bounce(bat_temp, bat_temp_rising, 0.2, 10, 59);
|
|
vehicle_state.bat_delta_last = last_lap_delta;
|
|
vehicle_state.bat_delta_overall = overall_delta;
|
|
vehicle_state.power_limit = power_limit;
|
|
vehicle_state.speed_limit = speed_limit;
|
|
vehicle_state.soc_ts = soc;
|
|
vehicle_state.max_cell_temp = bat_temp;
|
|
|
|
vehicle_state.active_mission = MISSION_MANUAL;
|
|
modelListener->vehicleStateUpdated();
|
|
}
|
|
#else
|
|
|
|
#include "main.h"
|
|
#include "stm32h7xx_hal.h"
|
|
#include "stm32h7xx_hal_gpio.h"
|
|
#include "stw_defines.h"
|
|
#include "tx_api.h"
|
|
#include "ui.h"
|
|
#include "vehicle_state.h"
|
|
|
|
void Model::tick() {
|
|
ULONG events;
|
|
if (tx_event_flags_get(&gui_update_events, GUI_UPDATE_ALL, TX_OR_CLEAR,
|
|
&events, TX_NO_WAIT) != TX_SUCCESS) {
|
|
return;
|
|
}
|
|
if (events & GUI_UPDATE_NEXT_SCREEN) {
|
|
modelListener->nextScreen();
|
|
}
|
|
if (events & GUI_UPDATE_VEHICLE_STATE) {
|
|
modelListener->vehicleStateUpdated();
|
|
}
|
|
if (events & GUI_UPDATE_PARAM_CONFIRMED) {
|
|
modelListener->paramConfirmed();
|
|
}
|
|
}
|
|
|
|
#endif // SIMULATOR
|