diff --git a/Core/Inc/main.h b/Core/Inc/main.h index 9f0ffbe..604de43 100644 --- a/Core/Inc/main.h +++ b/Core/Inc/main.h @@ -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 ------------------------------------------------------------*/ diff --git a/Core/Inc/vehicle_state.h b/Core/Inc/vehicle_state.h index 60c8ef8..635baf0 100644 --- a/Core/Inc/vehicle_state.h +++ b/Core/Inc/vehicle_state.h @@ -5,6 +5,7 @@ extern "C" { #endif +#include "params.h" #include "stw_defines.h" #include @@ -168,6 +169,8 @@ typedef struct { float desired_speed; ConePosition cone_pos[NUM_CONES]; + + ParamType last_param_confirmed; } VehicleState; extern VehicleState vehicle_state; diff --git a/Core/Src/vehicle.c b/Core/Src/vehicle.c index 732d553..d5a0f42 100644 --- a/Core/Src/vehicle.c +++ b/Core/Src/vehicle.c @@ -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]; diff --git a/TouchGFX/gui/include/gui/containers/ConfigItem.hpp b/TouchGFX/gui/include/gui/containers/ConfigItem.hpp index 4bcc82a..25dbd4c 100644 --- a/TouchGFX/gui/include/gui/containers/ConfigItem.hpp +++ b/TouchGFX/gui/include/gui/containers/ConfigItem.hpp @@ -14,6 +14,7 @@ public: virtual void initialize() override; void setSelected(int selected); + void setDirty(bool dirty); protected: private: diff --git a/TouchGFX/gui/include/gui/model/ModelListener.hpp b/TouchGFX/gui/include/gui/model/ModelListener.hpp index 41d8ce4..a77a55d 100644 --- a/TouchGFX/gui/include/gui/model/ModelListener.hpp +++ b/TouchGFX/gui/include/gui/model/ModelListener.hpp @@ -15,6 +15,7 @@ public: virtual void vehicleStateUpdated(){}; virtual void nextScreen(){}; + virtual void paramConfirmed(){}; protected: Model *model; diff --git a/TouchGFX/gui/include/gui/vehicleconfig_screen/VehicleConfigPresenter.hpp b/TouchGFX/gui/include/gui/vehicleconfig_screen/VehicleConfigPresenter.hpp index 84d6b85..1aeb756 100644 --- a/TouchGFX/gui/include/gui/vehicleconfig_screen/VehicleConfigPresenter.hpp +++ b/TouchGFX/gui/include/gui/vehicleconfig_screen/VehicleConfigPresenter.hpp @@ -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(); diff --git a/TouchGFX/gui/include/gui/vehicleconfig_screen/VehicleConfigView.hpp b/TouchGFX/gui/include/gui/vehicleconfig_screen/VehicleConfigView.hpp index 5c23390..39ddf33 100644 --- a/TouchGFX/gui/include/gui/vehicleconfig_screen/VehicleConfigView.hpp +++ b/TouchGFX/gui/include/gui/vehicleconfig_screen/VehicleConfigView.hpp @@ -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); }; diff --git a/TouchGFX/gui/src/containers/ConfigItem.cpp b/TouchGFX/gui/src/containers/ConfigItem.cpp index 26b57bd..566369b 100644 --- a/TouchGFX/gui/src/containers/ConfigItem.cpp +++ b/TouchGFX/gui/src/containers/ConfigItem.cpp @@ -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: diff --git a/TouchGFX/gui/src/model/Model.cpp b/TouchGFX/gui/src/model/Model.cpp index 9e65e3a..2fdb033 100644 --- a/TouchGFX/gui/src/model/Model.cpp +++ b/TouchGFX/gui/src/model/Model.cpp @@ -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 diff --git a/TouchGFX/gui/src/vehicleconfig_screen/VehicleConfigPresenter.cpp b/TouchGFX/gui/src/vehicleconfig_screen/VehicleConfigPresenter.cpp index af7c3a4..dbde045 100644 --- a/TouchGFX/gui/src/vehicleconfig_screen/VehicleConfigPresenter.cpp +++ b/TouchGFX/gui/src/vehicleconfig_screen/VehicleConfigPresenter.cpp @@ -1,3 +1,4 @@ +#include "vehicle_state.h" #include #include @@ -12,3 +13,7 @@ void VehicleConfigPresenter::nextScreen() { static_cast(Application::getInstance()) ->gotoDebugViewScreenNoTransition(); } + +void VehicleConfigPresenter::paramConfirmed() { + view.abxParamConfirmed(vehicle_state.last_param_confirmed); +} diff --git a/TouchGFX/gui/src/vehicleconfig_screen/VehicleConfigView.cpp b/TouchGFX/gui/src/vehicleconfig_screen/VehicleConfigView.cpp index c5ccd1d..234e59a 100644 --- a/TouchGFX/gui/src/vehicleconfig_screen/VehicleConfigView.cpp +++ b/TouchGFX/gui/src/vehicleconfig_screen/VehicleConfigView.cpp @@ -18,6 +18,7 @@ void VehicleConfigView::tearDownScreen() { void VehicleConfigView::paramsUpdateItem(ConfigItem &item, int16_t itemIndex) { item.setType(static_cast(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(selectedParam)); + paramsDirty[selectedParam] = true; params.itemChanged(selectedParam); } void VehicleConfigView::incParam() { params_inc(static_cast(selectedParam)); + paramsDirty[selectedParam] = true; params.itemChanged(selectedParam); } @@ -45,6 +48,11 @@ void VehicleConfigView::confirmParam() { params_broadcast(static_cast(selectedParam)); } +void VehicleConfigView::abxParamConfirmed(ParamType param) { + paramsDirty[param] = false; + params.itemChanged(param); +} + void VehicleConfigView::updateSelectedParam(int select) { int previousSelected = selectedParam; selectedParam = select;