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 fivewaybutton
.handle();
133 fivewaybutton
.getKeyState(&key
, &isLongPressed
);
134 if(screen
.getScreenStatus() == SCREEN_STATUS_IDLE
)
137 if(millis() - update_temp_start_time
> UPDATE_TEMP_TIMEOUT
)
139 screen
.doTemperatureUpdate(thermal
.getTempValue());
140 update_temp_start_time
= millis();
145 screen
.activeScreen();
148 else if(screen
.getScreenStatus() == SCREEN_STATUS_WORK
)
150 if(!isUserInputCheck
)
152 none_input_start_time
= millis();
153 isUserInputCheck
= true;
156 if(key
!= INPUT_KEY_NO_PRESS
)
158 DBGLN("user key = %d", key
);
159 isUserInputCheck
= false;
160 if(key
== INPUT_KEY_DOWN_PRESS
)
162 screen
.doUserAction(USER_ACTION_DOWN
);
164 else if(key
== INPUT_KEY_UP_PRESS
)
166 screen
.doUserAction(USER_ACTION_UP
);
168 else if(key
== INPUT_KEY_LEFT_PRESS
)
170 screen
.doUserAction(USER_ACTION_LEFT
);
172 else if(key
== INPUT_KEY_RIGHT_PRESS
)
174 screen
.doUserAction(USER_ACTION_RIGHT
);
176 else if(key
== INPUT_KEY_OK_PRESS
)
178 screen
.doUserAction(USER_ACTION_CONFIRM
);
183 if((millis() - none_input_start_time
) > SCREEN_IDLE_TIMEOUT
)
185 isUserInputCheck
= false;
190 else if(screen
.getScreenStatus() == SCREEN_STATUS_BINDING
)
192 if((millis() - binding_mode_start_time
) > BINDING_MODE_TIME_OUT
)
194 screen
.doUserAction(USER_ACTION_LEFT
);
199 is_screen_flipped
= gsensor
.isFlipped();
201 if((is_screen_flipped
== true) && (is_pre_screen_flipped
== false))
203 screen
.doScreenBackLight(SCREEN_BACKLIGHT_OFF
);
205 else if((is_screen_flipped
== false) && (is_pre_screen_flipped
== true))
207 screen
.doScreenBackLight(SCREEN_BACKLIGHT_ON
);
209 is_pre_screen_flipped
= is_screen_flipped
;
211 return SCREEN_DURATION
;
214 static int handle(void)
216 return DURATION_NEVER
;
220 static void initialize()
222 #ifdef HAS_FIVE_WAY_BUTTON
223 fivewaybutton
.init();
225 screen
.updatecallback
= &ScreenUpdateCallback
;
226 #if defined(PLATFORM_ESP32)
227 screen
.init(esp_reset_reason() == ESP_RST_SW
);
235 if (screen
.getScreenStatus() == SCREEN_STATUS_INIT
)
237 screen
.doParamUpdate(config
.GetRate(), (uint8_t)(POWERMGNT::currPower()), config
.GetTlm(), config
.GetMotionMode(), config
.GetFanMode());
238 return LOGO_DISPLAY_TIMEOUT
;
240 return DURATION_IMMEDIATELY
;
245 if(connectionState
!= wifiUpdate
)
247 screen
.doParamUpdate(config
.GetRate(), (uint8_t)(POWERMGNT::currPower()), config
.GetTlm(), config
.GetMotionMode(), config
.GetFanMode());
250 return DURATION_IGNORE
;
255 if(screen
.getScreenStatus() == SCREEN_STATUS_INIT
)
257 isLogoDisplayed
= true;
264 device_t Screen_device
= {
265 .initialize
= initialize
,