Change screens if both left and right are pressed
This commit is contained in:
parent
78c3c38988
commit
fe58a68b96
|
@ -47,6 +47,8 @@ extern TX_EVENT_FLAGS_GROUP gui_update_events;
|
||||||
extern FDCAN_HandleTypeDef hfdcan1;
|
extern FDCAN_HandleTypeDef hfdcan1;
|
||||||
|
|
||||||
#define GUI_UPDATE_VEHICLE_STATE (1 << 0)
|
#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)
|
||||||
/* USER CODE END EC */
|
/* USER CODE END EC */
|
||||||
|
|
||||||
/* Exported macro ------------------------------------------------------------*/
|
/* Exported macro ------------------------------------------------------------*/
|
||||||
|
|
|
@ -12,7 +12,7 @@ extern "C" {
|
||||||
#define BUTTON_MIN_INTERVAL 50 // ms
|
#define BUTTON_MIN_INTERVAL 50 // ms
|
||||||
#define ENC_MAX_PHASE 50 // ms
|
#define ENC_MAX_PHASE 50 // ms
|
||||||
|
|
||||||
typedef enum { UMK_BTN_RELEASED, UMK_ENC_CW, UMK_ENC_CCW } ButtonMessageKind;
|
typedef enum { UMK_BTN_PRESSED, UMK_ENC_CW, UMK_ENC_CCW } ButtonMessageKind;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
ButtonMessageKind kind;
|
ButtonMessageKind kind;
|
||||||
|
|
|
@ -10,7 +10,7 @@ bool STWButtonController::sample(uint8_t &key) {
|
||||||
ButtonMessage msg;
|
ButtonMessage msg;
|
||||||
if (tx_queue_receive(&gui_button_queue, &msg, TX_NO_WAIT) == TX_SUCCESS) {
|
if (tx_queue_receive(&gui_button_queue, &msg, TX_NO_WAIT) == TX_SUCCESS) {
|
||||||
switch (msg.kind) {
|
switch (msg.kind) {
|
||||||
case UMK_BTN_RELEASED:
|
case UMK_BTN_PRESSED:
|
||||||
key = KEY_BTN1 + msg.number;
|
key = KEY_BTN1 + msg.number;
|
||||||
break;
|
break;
|
||||||
case UMK_ENC_CW: {
|
case UMK_ENC_CW: {
|
||||||
|
|
|
@ -20,6 +20,7 @@ void ui_thread_entry(ULONG _) {
|
||||||
uint32_t button_press_times[NUM_BUTTONS] = {HAL_GetTick()};
|
uint32_t button_press_times[NUM_BUTTONS] = {HAL_GetTick()};
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
int press_event = -1;
|
||||||
for (int i = 0; i < NUM_BUTTONS; i++) {
|
for (int i = 0; i < NUM_BUTTONS; i++) {
|
||||||
GPIO_PinState state = HAL_GPIO_ReadPin(button_ports[i], button_pins[i]);
|
GPIO_PinState state = HAL_GPIO_ReadPin(button_ports[i], button_pins[i]);
|
||||||
if (state != button_states[i]) {
|
if (state != button_states[i]) {
|
||||||
|
@ -27,13 +28,18 @@ void ui_thread_entry(ULONG _) {
|
||||||
if (state == GPIO_PIN_SET &&
|
if (state == GPIO_PIN_SET &&
|
||||||
now - button_press_times[i] >= BUTTON_MIN_INTERVAL) {
|
now - button_press_times[i] >= BUTTON_MIN_INTERVAL) {
|
||||||
// Button press event!
|
// Button press event!
|
||||||
|
press_event = i;
|
||||||
button_press_times[i] = now;
|
button_press_times[i] = now;
|
||||||
ButtonMessage msg = {.kind = UMK_BTN_RELEASED, .number = i};
|
ButtonMessage msg = {.kind = UMK_BTN_PRESSED, .number = i};
|
||||||
tx_queue_send(&gui_button_queue, &msg, TX_NO_WAIT);
|
tx_queue_send(&gui_button_queue, &msg, TX_NO_WAIT);
|
||||||
}
|
}
|
||||||
button_states[i] = state;
|
button_states[i] = state;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ((press_event == 1 || press_event == 2) && button_states[1] &&
|
||||||
|
button_states[2]) {
|
||||||
|
tx_event_flags_set(&gui_update_events, GUI_UPDATE_NEXT_SCREEN, TX_OR);
|
||||||
|
}
|
||||||
vehicle_broadcast_buttons(button_states);
|
vehicle_broadcast_buttons(button_states);
|
||||||
// Release so other threads can get scheduled
|
// Release so other threads can get scheduled
|
||||||
tx_thread_sleep(1);
|
tx_thread_sleep(1);
|
||||||
|
|
|
@ -27,7 +27,8 @@ public:
|
||||||
|
|
||||||
virtual ~DebugViewPresenter(){};
|
virtual ~DebugViewPresenter(){};
|
||||||
|
|
||||||
virtual void vehicleStateUpdated() override;
|
void vehicleStateUpdated() override;
|
||||||
|
void nextScreen() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DebugViewPresenter();
|
DebugViewPresenter();
|
||||||
|
|
|
@ -30,6 +30,7 @@ public:
|
||||||
virtual ~DriverViewPresenter(){};
|
virtual ~DriverViewPresenter(){};
|
||||||
|
|
||||||
void vehicleStateUpdated() override;
|
void vehicleStateUpdated() override;
|
||||||
|
void nextScreen() override;
|
||||||
|
|
||||||
void setFieldType(size_t i, DataFieldType type);
|
void setFieldType(size_t i, DataFieldType type);
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ public:
|
||||||
void bind(Model *m) { model = m; }
|
void bind(Model *m) { model = m; }
|
||||||
|
|
||||||
virtual void vehicleStateUpdated(){};
|
virtual void vehicleStateUpdated(){};
|
||||||
|
virtual void nextScreen(){};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Model *model;
|
Model *model;
|
||||||
|
|
|
@ -8,29 +8,32 @@ using namespace touchgfx;
|
||||||
|
|
||||||
class VehicleConfigView;
|
class VehicleConfigView;
|
||||||
|
|
||||||
class VehicleConfigPresenter : public touchgfx::Presenter, public ModelListener
|
class VehicleConfigPresenter : public touchgfx::Presenter,
|
||||||
{
|
public ModelListener {
|
||||||
public:
|
public:
|
||||||
VehicleConfigPresenter(VehicleConfigView& v);
|
VehicleConfigPresenter(VehicleConfigView &v);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The activate function is called automatically when this screen is "switched in"
|
* The activate function is called automatically when this screen is "switched
|
||||||
* (ie. made active). Initialization logic can be placed here.
|
* in" (ie. made active). Initialization logic can be placed here.
|
||||||
*/
|
*/
|
||||||
virtual void activate();
|
virtual void activate();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The deactivate function is called automatically when this screen is "switched out"
|
* The deactivate function is called automatically when this screen is
|
||||||
* (ie. made inactive). Teardown functionality can be placed here.
|
* "switched out" (ie. made inactive). Teardown functionality can be placed
|
||||||
*/
|
* here.
|
||||||
virtual void deactivate();
|
*/
|
||||||
|
virtual void deactivate();
|
||||||
|
|
||||||
virtual ~VehicleConfigPresenter() {};
|
virtual ~VehicleConfigPresenter(){};
|
||||||
|
|
||||||
|
void nextScreen() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
VehicleConfigPresenter();
|
VehicleConfigPresenter();
|
||||||
|
|
||||||
VehicleConfigView& view;
|
VehicleConfigView &view;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // VEHICLECONFIGPRESENTER_HPP
|
#endif // VEHICLECONFIGPRESENTER_HPP
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#include <gui/debugview_screen/DebugViewPresenter.hpp>
|
#include <gui/debugview_screen/DebugViewPresenter.hpp>
|
||||||
#include <gui/debugview_screen/DebugViewView.hpp>
|
#include <gui/debugview_screen/DebugViewView.hpp>
|
||||||
|
|
||||||
|
|
||||||
DebugViewPresenter::DebugViewPresenter(DebugViewView &v) : view(v) {}
|
DebugViewPresenter::DebugViewPresenter(DebugViewView &v) : view(v) {}
|
||||||
|
|
||||||
void DebugViewPresenter::activate() {}
|
void DebugViewPresenter::activate() {}
|
||||||
|
@ -9,3 +8,8 @@ void DebugViewPresenter::activate() {}
|
||||||
void DebugViewPresenter::deactivate() {}
|
void DebugViewPresenter::deactivate() {}
|
||||||
|
|
||||||
void DebugViewPresenter::vehicleStateUpdated() { view.updateFieldValues(); }
|
void DebugViewPresenter::vehicleStateUpdated() { view.updateFieldValues(); }
|
||||||
|
|
||||||
|
void DebugViewPresenter::nextScreen() {
|
||||||
|
static_cast<FrontendApplication *>(Application::getInstance())
|
||||||
|
->gotoDriverViewScreenNoTransition();
|
||||||
|
}
|
||||||
|
|
|
@ -32,6 +32,11 @@ void DriverViewPresenter::vehicleStateUpdated() {
|
||||||
view.updateFieldValues();
|
view.updateFieldValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DriverViewPresenter::nextScreen() {
|
||||||
|
static_cast<FrontendApplication *>(Application::getInstance())
|
||||||
|
->gotoVehicleConfigScreenNoTransition();
|
||||||
|
}
|
||||||
|
|
||||||
void DriverViewPresenter::setFieldType(size_t i, DataFieldType type) {
|
void DriverViewPresenter::setFieldType(size_t i, DataFieldType type) {
|
||||||
fields[i] = type;
|
fields[i] = type;
|
||||||
view.setFieldType(i, type);
|
view.setFieldType(i, type);
|
||||||
|
|
|
@ -13,10 +13,14 @@ Model::Model() : modelListener(0) {}
|
||||||
|
|
||||||
void Model::tick() {
|
void Model::tick() {
|
||||||
ULONG events;
|
ULONG events;
|
||||||
if (tx_event_flags_get(&gui_update_events, GUI_UPDATE_VEHICLE_STATE,
|
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) {
|
TX_OR_CLEAR, &events, TX_NO_WAIT) != TX_SUCCESS) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (events & GUI_UPDATE_NEXT_SCREEN) {
|
||||||
|
modelListener->nextScreen();
|
||||||
|
}
|
||||||
if (events & GUI_UPDATE_VEHICLE_STATE) {
|
if (events & GUI_UPDATE_VEHICLE_STATE) {
|
||||||
modelListener->vehicleStateUpdated();
|
modelListener->vehicleStateUpdated();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,14 @@
|
||||||
#include <gui/vehicleconfig_screen/VehicleConfigView.hpp>
|
|
||||||
#include <gui/vehicleconfig_screen/VehicleConfigPresenter.hpp>
|
#include <gui/vehicleconfig_screen/VehicleConfigPresenter.hpp>
|
||||||
|
#include <gui/vehicleconfig_screen/VehicleConfigView.hpp>
|
||||||
|
|
||||||
VehicleConfigPresenter::VehicleConfigPresenter(VehicleConfigView& v)
|
VehicleConfigPresenter::VehicleConfigPresenter(VehicleConfigView &v)
|
||||||
: view(v)
|
: view(v) {}
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void VehicleConfigPresenter::activate()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void VehicleConfigPresenter::deactivate()
|
|
||||||
{
|
|
||||||
|
|
||||||
|
void VehicleConfigPresenter::activate() {}
|
||||||
|
|
||||||
|
void VehicleConfigPresenter::deactivate() {}
|
||||||
|
|
||||||
|
void VehicleConfigPresenter::nextScreen() {
|
||||||
|
static_cast<FrontendApplication *>(Application::getInstance())
|
||||||
|
->gotoDebugViewScreenNoTransition();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue