5 #if defined(USE_OLED_SPI) || defined(USE_OLED_SPI_SMALL) || defined(USE_OLED_I2C) || defined(HAS_TFT_SCREEN)
10 #include "POWERMGNT.h"
14 #include "TFT/tftscreen.h"
17 #include "OLED/oledscreen.h"
21 #ifdef HAS_FIVE_WAY_BUTTON
22 #include "FiveWayButton/FiveWayButton.h"
23 FiveWayButton fivewaybutton
;
25 static uint32_t none_input_start_time
= 0;
26 static bool isUserInputCheck
= false;
31 extern Gsensor gsensor
;
32 static bool is_screen_flipped
= false;
33 static bool is_pre_screen_flipped
= false;
38 extern Thermal thermal
;
40 #define UPDATE_TEMP_TIMEOUT 5000
41 uint32_t update_temp_start_time
= 0;
44 #define SCREEN_DURATION 20
46 #define LOGO_DISPLAY_TIMEOUT 5000
47 static bool isLogoDisplayed
= false;
49 #define SCREEN_IDLE_TIMEOUT 20000
51 extern bool ICACHE_RAM_ATTR
IsArmed();
52 extern void EnterBindingMode();
53 extern void ExitBindingMode();
55 #if defined(TARGET_TX)
56 extern TxConfig config
;
58 extern RxConfig config
;
62 extern unsigned long rebootTime
;
65 #define BINDING_MODE_TIME_OUT 5000
66 static uint32_t binding_mode_start_time
= 0;
69 static void ScreenUpdateCallback(int updateType
)
73 case USER_UPDATE_TYPE_RATE
:
74 DBGLN("User set AirRate %d", screen
.getUserRateIndex());
75 config
.SetRate(screen
.getUserRateIndex());
77 case USER_UPDATE_TYPE_POWER
:
78 DBGLN("User set Power %d", screen
.getUserPowerIndex());
79 config
.SetPower(screen
.getUserPowerIndex());
81 case USER_UPDATE_TYPE_RATIO
:
82 DBGLN("User set TLM RATIO %d", screen
.getUserRatioIndex());
83 config
.SetTlm(screen
.getUserRatioIndex());
85 case USER_UPDATE_TYPE_BINDING
:
86 DBGLN("User request binding!");
88 binding_mode_start_time
= millis();
90 case USER_UPDATE_TYPE_EXIT_BINDING
:
91 DBGLN("User request exit binding!");
94 case USER_UPDATE_TYPE_WIFI
:
95 DBGLN("User request Wifi Update Mode!");
96 connectionState
= wifiUpdate
;
98 case USER_UPDATE_TYPE_EXIT_WIFI
:
99 DBGLN("User request exit Wifi Update Mode!");
100 #ifdef PLATFORM_ESP32
101 if (connectionState
== wifiUpdate
) {
102 rebootTime
= millis() + 200;
107 case USER_UPDATE_TYPE_SMARTFAN
:
108 DBGLN("User request SMART FAN Mode!");
109 config
.SetFanMode(screen
.getUserSmartFanIndex());
113 case USER_UPDATE_TYPE_POWERSAVING
:
114 DBGLN("User request Power Saving Mode!");
115 config
.SetMotionMode(screen
.getUserPowerSavingIndex());
119 DBGLN("Error handle user request %d", updateType
);
124 #ifdef HAS_FIVE_WAY_BUTTON
125 static int handle(void)
127 #if defined(JOY_ADC_VALUES) && defined(PLATFORM_ESP32)
128 // if we are using analog joystick then we can't cancel because WiFi is using the ADC2 (i.e. channel >= 8)!
129 if (connectionState
== wifiUpdate
&& digitalPinToAnalogChannel(GPIO_PIN_JOYSTICK
) >= 8)
131 return DURATION_NEVER
;
136 is_screen_flipped
= gsensor
.isFlipped();
138 if ((is_screen_flipped
== true) && (is_pre_screen_flipped
== false))
140 screen
.doScreenBackLight(SCREEN_BACKLIGHT_OFF
);
142 else if ((is_screen_flipped
== false) && (is_pre_screen_flipped
== true))
144 screen
.doScreenBackLight(SCREEN_BACKLIGHT_ON
);
146 is_pre_screen_flipped
= is_screen_flipped
;
147 if (is_screen_flipped
)
149 return 100; // no need to check as often if the screen is off!
157 fivewaybutton
.handle();
158 fivewaybutton
.getKeyState(&key
, &isLongPressed
);
159 if(screen
.getScreenStatus() == SCREEN_STATUS_IDLE
)
162 if(millis() - update_temp_start_time
> UPDATE_TEMP_TIMEOUT
)
164 screen
.doTemperatureUpdate(thermal
.getTempValue());
165 update_temp_start_time
= millis();
170 screen
.activeScreen();
173 else if(screen
.getScreenStatus() == SCREEN_STATUS_WORK
)
175 if(!isUserInputCheck
)
177 none_input_start_time
= millis();
178 isUserInputCheck
= true;
181 if (key
!= INPUT_KEY_NO_PRESS
)
183 DBGLN("user key = %d", key
);
184 isUserInputCheck
= false;
185 if(key
== INPUT_KEY_DOWN_PRESS
)
187 screen
.doUserAction(USER_ACTION_DOWN
);
189 else if(key
== INPUT_KEY_UP_PRESS
)
191 screen
.doUserAction(USER_ACTION_UP
);
193 else if(key
== INPUT_KEY_LEFT_PRESS
)
195 screen
.doUserAction(USER_ACTION_LEFT
);
197 else if(key
== INPUT_KEY_RIGHT_PRESS
)
199 screen
.doUserAction(USER_ACTION_RIGHT
);
201 else if(key
== INPUT_KEY_OK_PRESS
)
203 screen
.doUserAction(USER_ACTION_CONFIRM
);
206 else if((millis() - none_input_start_time
) > SCREEN_IDLE_TIMEOUT
)
208 isUserInputCheck
= false;
212 else if(screen
.getScreenStatus() == SCREEN_STATUS_BINDING
)
214 if((millis() - binding_mode_start_time
) > BINDING_MODE_TIME_OUT
)
216 screen
.doUserAction(USER_ACTION_LEFT
);
220 return SCREEN_DURATION
;
223 static int handle(void)
225 return DURATION_NEVER
;
229 static void initialize()
231 #ifdef HAS_FIVE_WAY_BUTTON
232 fivewaybutton
.init();
234 screen
.updatecallback
= &ScreenUpdateCallback
;
235 #if defined(PLATFORM_ESP32)
236 screen
.init(esp_reset_reason() == ESP_RST_SW
);
244 if (screen
.getScreenStatus() == SCREEN_STATUS_INIT
)
246 screen
.doParamUpdate(config
.GetRate(), (uint8_t)(POWERMGNT::currPower()), config
.GetTlm(), config
.GetMotionMode(), config
.GetFanMode());
247 return LOGO_DISPLAY_TIMEOUT
;
249 return DURATION_IMMEDIATELY
;
254 if (connectionState
== wifiUpdate
)
256 screen
.setInWifiMode();
260 screen
.doParamUpdate(config
.GetRate(), (uint8_t)(POWERMGNT::currPower()), config
.GetTlm(), config
.GetMotionMode(), config
.GetFanMode());
263 return DURATION_IGNORE
;
268 if(screen
.getScreenStatus() == SCREEN_STATUS_INIT
)
270 isLogoDisplayed
= true;
277 device_t Screen_device
= {
278 .initialize
= initialize
,