Use an event flag group for GUI updates
This commit is contained in:
parent
41dbfa73ee
commit
f0254b92ee
|
@ -69,7 +69,7 @@ TX_THREAD app_thread;
|
|||
TX_THREAD ui_thread;
|
||||
TX_THREAD vehicle_thread;
|
||||
TX_QUEUE gui_button_queue;
|
||||
TX_QUEUE vehicle_update_queue;
|
||||
TX_EVENT_FLAGS_GROUP gui_update_events;
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
|
@ -184,15 +184,7 @@ VOID tx_application_define(VOID *first_unused_memory) {
|
|||
Error_Handler();
|
||||
}
|
||||
|
||||
void *vehicle_update_queue_start = mem;
|
||||
ULONG vehicle_update_msg_size = sizeof(VehicleUpdate) / sizeof(ULONG);
|
||||
if (sizeof(VehicleUpdate) % sizeof(ULONG) != 0) {
|
||||
vehicle_update_msg_size++;
|
||||
}
|
||||
mem += VEHICLE_UPDATE_QUEUE_SIZE * vehicle_update_msg_size;
|
||||
if (tx_queue_create(&vehicle_update_queue, "Vehicle Update Queue",
|
||||
vehicle_update_msg_size, vehicle_update_queue_start,
|
||||
VEHICLE_UPDATE_QUEUE_SIZE * vehicle_update_msg_size) !=
|
||||
if (tx_event_flags_create(&gui_update_events, "GUI Update Events") !=
|
||||
TX_SUCCESS) {
|
||||
Error_Handler();
|
||||
}
|
||||
|
|
|
@ -43,8 +43,10 @@ extern "C" {
|
|||
/* USER CODE BEGIN EC */
|
||||
extern volatile int ltdc_cb_triggered;
|
||||
extern TX_QUEUE gui_button_queue;
|
||||
extern TX_QUEUE vehicle_update_queue;
|
||||
extern TX_EVENT_FLAGS_GROUP gui_update_events;
|
||||
extern FDCAN_HandleTypeDef hfdcan1;
|
||||
|
||||
#define GUI_UPDATE_VEHICLE_STATE (1 << 0)
|
||||
/* USER CODE END EC */
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
|
|
|
@ -102,15 +102,6 @@ typedef struct {
|
|||
|
||||
extern VehicleState vehicle_state;
|
||||
|
||||
typedef enum {
|
||||
VEH_UPD_AMS,
|
||||
VEH_UPD_MISSION,
|
||||
VEH_UPD_STATUS,
|
||||
VEH_UPD_TS_CURRENT,
|
||||
VEH_UPD_TS_VOLTAGE_VEH,
|
||||
VEH_UPD_TS_VOLTAGE_BAT
|
||||
} VehicleUpdate;
|
||||
|
||||
void vehicle_thread_entry(ULONG hfdcan_addr);
|
||||
|
||||
void vehicle_select_mission(Mission mission);
|
||||
|
|
|
@ -45,7 +45,6 @@ void vehicle_select_mission(Mission mission) {
|
|||
}
|
||||
|
||||
void ftcan_msg_received_cb(uint16_t id, size_t datalen, const uint8_t *data) {
|
||||
VehicleUpdate msg;
|
||||
switch (id) {
|
||||
case CAN_ID_AMS_STATUS:
|
||||
vehicle_state.ts_state = data[0] & 0x7F;
|
||||
|
@ -55,11 +54,9 @@ void ftcan_msg_received_cb(uint16_t id, size_t datalen, const uint8_t *data) {
|
|||
ftcan_unmarshal_unsigned(&ptr, 2) * CAN_AMS_STATUS_VOLTAGE_FACTOR;
|
||||
vehicle_state.max_cell_temp =
|
||||
ftcan_unmarshal_signed(&ptr, 2) * CAN_AMS_STATUS_TEMP_FACTOR;
|
||||
msg = VEH_UPD_AMS;
|
||||
break;
|
||||
case CAN_ID_AS_MISSION_FB:
|
||||
vehicle_state.active_mission = data[0] & 0b111;
|
||||
msg = VEH_UPD_MISSION;
|
||||
break;
|
||||
case CAN_ID_STW_STATUS:
|
||||
vehicle_state.as_state = data[0] & 0b111;
|
||||
|
@ -85,20 +82,16 @@ void ftcan_msg_received_cb(uint16_t id, size_t datalen, const uint8_t *data) {
|
|||
vehicle_state.errors.err_res = (data[5] >> 2) & 1;
|
||||
vehicle_state.errors.err_invl = (data[5] >> 3) & 1;
|
||||
vehicle_state.errors.err_invr = (data[5] >> 4) & 1;
|
||||
msg = VEH_UPD_STATUS;
|
||||
break;
|
||||
case CAN_ID_SHUNT_CURRENT:
|
||||
vehicle_state.ts_current = ftcan_unmarshal_signed(&data, 6) * 1e-3;
|
||||
msg = VEH_UPD_TS_CURRENT;
|
||||
break;
|
||||
case CAN_ID_SHUNT_VOLTAGE2:
|
||||
vehicle_state.ts_voltage_veh = ftcan_unmarshal_signed(&data, 6) * 1e-3;
|
||||
msg = VEH_UPD_TS_VOLTAGE_VEH;
|
||||
break;
|
||||
case CAN_ID_SHUNT_VOLTAGE3:
|
||||
vehicle_state.ts_voltage_bat = ftcan_unmarshal_signed(&data, 6) * 1e-3;
|
||||
msg = VEH_UPD_TS_VOLTAGE_BAT;
|
||||
break;
|
||||
}
|
||||
tx_queue_send(&vehicle_update_queue, &msg, TX_NO_WAIT);
|
||||
tx_event_flags_set(&gui_update_events, GUI_UPDATE_VEHICLE_STATE, TX_OR);
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ public:
|
|||
|
||||
virtual ~AMIPresenter(){};
|
||||
|
||||
void missionUpdated() override;
|
||||
void vehicleStateUpdated() override;
|
||||
|
||||
private:
|
||||
AMIPresenter();
|
||||
|
|
|
@ -27,7 +27,7 @@ public:
|
|||
|
||||
virtual ~DriverViewPresenter(){};
|
||||
|
||||
void amsUpdated() override;
|
||||
void vehicleStateUpdated() override;
|
||||
|
||||
private:
|
||||
DriverViewPresenter();
|
||||
|
|
|
@ -28,7 +28,7 @@ public:
|
|||
|
||||
virtual ~MissionSelectPresenter(){};
|
||||
|
||||
void missionUpdated() override;
|
||||
void vehicleStateUpdated() override;
|
||||
|
||||
private:
|
||||
MissionSelectPresenter();
|
||||
|
|
|
@ -13,12 +13,7 @@ public:
|
|||
|
||||
void bind(Model *m) { model = m; }
|
||||
|
||||
virtual void amsUpdated(){};
|
||||
virtual void missionUpdated(){};
|
||||
virtual void statusUpdated(){};
|
||||
virtual void tsCurrentUpdated(){};
|
||||
virtual void tsVoltageVehicleUpdated(){};
|
||||
virtual void tsVoltageBatteryUpdated(){};
|
||||
virtual void vehicleStateUpdated(){};
|
||||
|
||||
protected:
|
||||
Model *model;
|
||||
|
|
|
@ -6,10 +6,10 @@
|
|||
|
||||
AMIPresenter::AMIPresenter(AMIView &v) : view(v) {}
|
||||
|
||||
void AMIPresenter::activate() { missionUpdated(); }
|
||||
void AMIPresenter::activate() { vehicleStateUpdated(); }
|
||||
|
||||
void AMIPresenter::deactivate() {}
|
||||
|
||||
void AMIPresenter::missionUpdated() {
|
||||
void AMIPresenter::vehicleStateUpdated() {
|
||||
view.setMission(vehicle_state.active_mission);
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ void DriverViewPresenter::activate() {}
|
|||
|
||||
void DriverViewPresenter::deactivate() {}
|
||||
|
||||
void DriverViewPresenter::amsUpdated() {
|
||||
void DriverViewPresenter::vehicleStateUpdated() {
|
||||
view.setTSSoC(vehicle_state.soc);
|
||||
view.setMinCellVolt(vehicle_state.min_cell_volt);
|
||||
}
|
||||
|
|
|
@ -12,12 +12,17 @@ void MissionSelectPresenter::activate() {}
|
|||
|
||||
void MissionSelectPresenter::deactivate() {}
|
||||
|
||||
void MissionSelectPresenter::missionUpdated() {
|
||||
void MissionSelectPresenter::vehicleStateUpdated() {
|
||||
FrontendApplication *app =
|
||||
static_cast<FrontendApplication *>(FrontendApplication::getInstance());
|
||||
if (vehicle_state.active_mission == MISSION_MANUAL) {
|
||||
switch (vehicle_state.active_mission) {
|
||||
case MISSION_NONE:
|
||||
// Do nothing
|
||||
break;
|
||||
case MISSION_MANUAL:
|
||||
app->gotoDriverViewScreenNoTransition();
|
||||
} else {
|
||||
break;
|
||||
default:
|
||||
app->gotoAMIScreenNoTransition();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,28 +12,12 @@
|
|||
Model::Model() : modelListener(0) {}
|
||||
|
||||
void Model::tick() {
|
||||
VehicleUpdate msg;
|
||||
while (tx_queue_receive(&vehicle_update_queue, &msg, TX_NO_WAIT) ==
|
||||
TX_SUCCESS) {
|
||||
switch (msg) {
|
||||
case VEH_UPD_AMS:
|
||||
modelListener->amsUpdated();
|
||||
break;
|
||||
case VEH_UPD_MISSION:
|
||||
modelListener->missionUpdated();
|
||||
break;
|
||||
case VEH_UPD_STATUS:
|
||||
modelListener->statusUpdated();
|
||||
break;
|
||||
case VEH_UPD_TS_CURRENT:
|
||||
modelListener->tsCurrentUpdated();
|
||||
break;
|
||||
case VEH_UPD_TS_VOLTAGE_VEH:
|
||||
modelListener->tsVoltageVehicleUpdated();
|
||||
break;
|
||||
case VEH_UPD_TS_VOLTAGE_BAT:
|
||||
modelListener->tsVoltageBatteryUpdated();
|
||||
break;
|
||||
}
|
||||
ULONG events;
|
||||
if (tx_event_flags_get(&gui_update_events, GUI_UPDATE_VEHICLE_STATE,
|
||||
TX_OR_CLEAR, &events, TX_NO_WAIT) != TX_SUCCESS) {
|
||||
return;
|
||||
}
|
||||
if (events & GUI_UPDATE_VEHICLE_STATE) {
|
||||
modelListener->vehicleStateUpdated();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue