3 #if defined(PLATFORM_ESP32)
10 #include "OLED/oleddisplay.h"
11 #include "TFT/tftdisplay.h"
13 #include "devButton.h"
16 FiniteStateMachine
state_machine(entry_fsm
);
20 #include "FiveWayButton/FiveWayButton.h"
21 FiveWayButton fivewaybutton
;
24 extern Gsensor gsensor
;
25 static bool is_screen_flipped
= false;
26 static bool is_pre_screen_flipped
= false;
28 #define SCREEN_DURATION 20
30 extern void jumpToWifiRunning();
31 extern void jumpToBleRunning();
33 static bool jumpToBandSelect
= false;
34 static bool jumpToChannelSelect
= false;
36 static int handle(void)
38 is_screen_flipped
= gsensor
.isFlipped();
40 if ((is_screen_flipped
== true) && (is_pre_screen_flipped
== false))
42 display
->doScreenBackLight(SCREEN_BACKLIGHT_OFF
);
44 else if ((is_screen_flipped
== false) && (is_pre_screen_flipped
== true))
46 display
->doScreenBackLight(SCREEN_BACKLIGHT_ON
);
47 state_machine
.start(millis(), STATE_IDLE
);
49 is_pre_screen_flipped
= is_screen_flipped
;
50 if (is_screen_flipped
)
52 return 100; // no need to check as often if the screen is off!
54 uint32_t now
= millis();
56 if (state_machine
.getParentState() != STATE_WIFI_TX
&& connectionState
== wifiUpdate
)
61 if (state_machine
.getParentState() != STATE_JOYSTICK
&& connectionState
== bleJoystick
)
66 if (!handset
->IsArmed())
70 // if we are using analog joystick then we can't cancel because WiFi is using the ADC2 (i.e. channel >= 8)!
71 if (connectionState
== wifiUpdate
&& digitalPinToAnalogChannel(GPIO_PIN_JOYSTICK
) >= 8)
73 key
= INPUT_KEY_NO_PRESS
;
77 fivewaybutton
.update(&key
, &isLongPressed
);
79 fsm_event_t fsm_event
;
82 case INPUT_KEY_DOWN_PRESS
:
83 fsm_event
= EVENT_DOWN
;
85 case INPUT_KEY_UP_PRESS
:
88 case INPUT_KEY_LEFT_PRESS
:
89 fsm_event
= EVENT_LEFT
;
91 case INPUT_KEY_RIGHT_PRESS
:
92 fsm_event
= EVENT_RIGHT
;
94 case INPUT_KEY_OK_PRESS
:
95 fsm_event
= EVENT_ENTER
;
97 default: // INPUT_KEY_NO_PRESS
98 fsm_event
= EVENT_TIMEOUT
;
100 if (fsm_event
!= EVENT_TIMEOUT
&& isLongPressed
)
102 fsm_event
= (fsm_event
| LONG_PRESSED
);
104 #if defined(DEBUG_SCREENSHOT)
105 if (key
== INPUT_KEY_DOWN_PRESS
&& isLongPressed
)
107 DBGLN("state_%d", state_machine
.getCurrentState());
108 Display::printScreenshot();
111 if (jumpToBandSelect
)
113 state_machine
.jumpTo(vtx_menu_fsm
, STATE_VTX_BAND
);
114 state_machine
.jumpTo(value_select_fsm
, STATE_VALUE_INIT
);
115 jumpToBandSelect
= false;
117 else if (jumpToChannelSelect
)
119 state_machine
.jumpTo(vtx_menu_fsm
, STATE_VTX_CHANNEL
);
120 state_machine
.jumpTo(value_select_fsm
, STATE_VALUE_INIT
);
121 jumpToChannelSelect
= false;
125 state_machine
.handleEvent(now
, fsm_event
);
130 state_machine
.handleEvent(now
, EVENT_TIMEOUT
);
133 return SCREEN_DURATION
;
136 static void initialize()
140 fivewaybutton
.init();
141 if (OPT_HAS_TFT_SCREEN
)
143 display
= new TFTDisplay();
147 display
= new OLEDDisplay();
150 state_machine
.start(millis(), getInitialState());
152 registerButtonFunction(ACTION_GOTO_VTX_BAND
, [](){
153 jumpToBandSelect
= true;
154 devicesTriggerEvent();
156 registerButtonFunction(ACTION_GOTO_VTX_CHANNEL
, [](){
157 jumpToChannelSelect
= true;
158 devicesTriggerEvent();
167 return DURATION_IMMEDIATELY
;
169 return DURATION_NEVER
;
178 return DURATION_NEVER
;
187 return DURATION_NEVER
;
190 device_t Screen_device
= {
191 .initialize
= initialize
,