Show if parameter change has been confirmed by ABX

This commit is contained in:
Jasper Blanckenburg 2023-08-02 00:33:43 +02:00
parent c32e2b71cd
commit d5b65828aa
11 changed files with 48 additions and 6 deletions

View File

@ -48,7 +48,10 @@ extern FDCAN_HandleTypeDef hfdcan1;
#define GUI_UPDATE_VEHICLE_STATE (1 << 0)
#define GUI_UPDATE_NEXT_SCREEN (1 << 1)
#define GUI_UPDATE_ALL (GUI_UPDATE_VEHICLE_STATE | GUI_UPDATE_NEXT_SCREEN)
#define GUI_UPDATE_PARAM_CONFIRMED (1 << 2)
#define GUI_UPDATE_ALL \
(GUI_UPDATE_VEHICLE_STATE | GUI_UPDATE_NEXT_SCREEN | \
GUI_UPDATE_PARAM_CONFIRMED)
/* USER CODE END EC */
/* Exported macro ------------------------------------------------------------*/

View File

@ -5,6 +5,7 @@
extern "C" {
#endif
#include "params.h"
#include "stw_defines.h"
#include <stdint.h>
@ -168,6 +169,8 @@ typedef struct {
float desired_speed;
ConePosition cone_pos[NUM_CONES];
ParamType last_param_confirmed;
} VehicleState;
extern VehicleState vehicle_state;

View File

@ -28,6 +28,7 @@
#define CAN_ID_STW_PARAM_SET 0x402
#define CAN_ID_AS_MISSION_FB 0x410
#define CAN_ID_STW_STATUS 0x412
#define CAN_ID_ABX_PARAM_CONFIRMED 0x413
#define CAN_ID_STW_CONES_BASE 0x414
#define CAN_ID_STW_CONES_MASK 0x7FC
#define CAN_ID_SHUNT_CURRENT 0x521
@ -62,6 +63,7 @@ void vehicle_thread_entry(ULONG hfdcan_addr) {
ftcan_add_filter(CAN_ID_EPSC_OUT, 0x7FF);
ftcan_add_filter(CAN_ID_AS_MISSION_FB, 0x7FF);
ftcan_add_filter(CAN_ID_STW_STATUS, 0x7FF);
ftcan_add_filter(CAN_ID_ABX_PARAM_CONFIRMED, 0x7FF);
ftcan_add_filter(CAN_ID_STW_CONES_BASE, CAN_ID_STW_CONES_MASK);
ftcan_add_filter(CAN_ID_SHUNT_CURRENT, 0x7FF);
ftcan_add_filter(CAN_ID_SHUNT_VOLTAGE1, 0x7FF);
@ -205,6 +207,10 @@ void ftcan_msg_received_cb(uint16_t id, size_t datalen, const uint8_t *data) {
vehicle_state.errors.err_invl = (data[5] >> 3) & 1;
vehicle_state.errors.err_invr = (data[5] >> 4) & 1;
break;
case CAN_ID_ABX_PARAM_CONFIRMED:
vehicle_state.last_param_confirmed = data[0];
tx_event_flags_set(&gui_update_events, GUI_UPDATE_PARAM_CONFIRMED, TX_OR);
break;
case CAN_ID_SHUNT_CURRENT: {
// The first two bytes of shunt result messages are metadata
const uint8_t *result_ptr = &data[2];

View File

@ -14,6 +14,7 @@ public:
virtual void initialize() override;
void setSelected(int selected);
void setDirty(bool dirty);
protected:
private:

View File

@ -15,6 +15,7 @@ public:
virtual void vehicleStateUpdated(){};
virtual void nextScreen(){};
virtual void paramConfirmed(){};
protected:
Model *model;

View File

@ -17,18 +17,19 @@ public:
* The activate function is called automatically when this screen is "switched
* in" (ie. made active). Initialization logic can be placed here.
*/
virtual void activate();
virtual void activate() override;
/**
* The deactivate function is called automatically when this screen is
* "switched out" (ie. made inactive). Teardown functionality can be placed
* here.
*/
virtual void deactivate();
virtual void deactivate() override;
virtual ~VehicleConfigPresenter(){};
void nextScreen() override;
void paramConfirmed() override;
private:
VehicleConfigPresenter();

View File

@ -19,10 +19,14 @@ public:
void incParam() override;
void confirmParam() override;
void abxParamConfirmed(ParamType param);
protected:
private:
int selectedParam;
bool paramsDirty[ParamType_COUNT] = {false};
void updateSelectedParam(int select);
};

View File

@ -13,6 +13,14 @@ void ConfigItem::setSelected(int selected) {
bg.invalidate();
}
void ConfigItem::setDirty(bool dirty) {
if (dirty) {
value.setColor(touchgfx::Color::getColorFromRGB(0xFF, 0x00, 0x00));
} else {
value.setColor(touchgfx::Color::getColorFromRGB(0xFF, 0xFF, 0xFF));
}
}
void ConfigItem::typeUpdated() {
switch (desc->kind) {
case NamedFieldKind::Float:

View File

@ -17,9 +17,8 @@ void Model::tick() { modelListener->vehicleStateUpdated(); }
void Model::tick() {
ULONG events;
if (tx_event_flags_get(&gui_update_events,
GUI_UPDATE_VEHICLE_STATE | GUI_UPDATE_NEXT_SCREEN,
TX_OR_CLEAR, &events, TX_NO_WAIT) != TX_SUCCESS) {
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) {
@ -28,6 +27,9 @@ void Model::tick() {
if (events & GUI_UPDATE_VEHICLE_STATE) {
modelListener->vehicleStateUpdated();
}
if (events & GUI_UPDATE_PARAM_CONFIRMED) {
modelListener->paramConfirmed();
}
}
#endif // SIMULATOR

View File

@ -1,3 +1,4 @@
#include "vehicle_state.h"
#include <gui/vehicleconfig_screen/VehicleConfigPresenter.hpp>
#include <gui/vehicleconfig_screen/VehicleConfigView.hpp>
@ -12,3 +13,7 @@ void VehicleConfigPresenter::nextScreen() {
static_cast<FrontendApplication *>(Application::getInstance())
->gotoDebugViewScreenNoTransition();
}
void VehicleConfigPresenter::paramConfirmed() {
view.abxParamConfirmed(vehicle_state.last_param_confirmed);
}

View File

@ -18,6 +18,7 @@ void VehicleConfigView::tearDownScreen() {
void VehicleConfigView::paramsUpdateItem(ConfigItem &item, int16_t itemIndex) {
item.setType(static_cast<ParamType>(itemIndex));
item.setSelected(itemIndex == selectedParam);
item.setDirty(paramsDirty[itemIndex]);
}
void VehicleConfigView::selectPrevParam() {
@ -34,10 +35,12 @@ void VehicleConfigView::selectNextParam() {
void VehicleConfigView::decParam() {
params_dec(static_cast<ParamType>(selectedParam));
paramsDirty[selectedParam] = true;
params.itemChanged(selectedParam);
}
void VehicleConfigView::incParam() {
params_inc(static_cast<ParamType>(selectedParam));
paramsDirty[selectedParam] = true;
params.itemChanged(selectedParam);
}
@ -45,6 +48,11 @@ void VehicleConfigView::confirmParam() {
params_broadcast(static_cast<ParamType>(selectedParam));
}
void VehicleConfigView::abxParamConfirmed(ParamType param) {
paramsDirty[param] = false;
params.itemChanged(param);
}
void VehicleConfigView::updateSelectedParam(int select) {
int previousSelected = selectedParam;
selectedParam = select;