Merge pull request #1269 from pkendall64/crsf-max-output
[ExpressLRS.git] / src / lib / SCREEN / screen.cpp
blob0c11101815f3f7dc8dd55bdaaa89cdf1cc74efd5
1 #include "screen.h"
3 #if defined(USE_OLED_SPI) || defined(USE_OLED_I2C) || defined(USE_OLED_SPI_SMALL) || defined(HAS_TFT_SCREEN)
5 void Screen::nullCallback(int updateType) {}
6 void (*Screen::updatecallback)(int updateType) = &nullCallback;
9 #ifdef Regulatory_Domain_ISM_2400
10 const char *Screen::rate_string[RATE_MAX_NUMBER] = {
11 "500Hz",
12 "250Hz",
13 "150Hz",
14 "50Hz"
16 #else
17 const char *Screen::rate_string[RATE_MAX_NUMBER] = {
18 "200Hz",
19 "100Hz",
20 "50Hz",
21 "25Hz"
23 #endif
25 const char *Screen::power_string[POWER_MAX_NUMBER] = {
26 "10mW",
27 "25mW",
28 "50mW",
29 "100mW",
30 "250mW",
31 "500mW",
32 "1000mW",
33 "2000mW"
36 const char *Screen::ratio_string[RATIO_MAX_NUMBER] = {
37 "Off",
38 "1:128",
39 "1:64",
40 "1:32",
41 "1:16",
42 "1:8",
43 "1:4",
44 "1:2"
47 const char *Screen::powersaving_string[POWERSAVING_MAX_NUMBER] = {
48 "OFF",
49 "ON"
52 const char *Screen::smartfan_string[SMARTFAN_MAX_NUMBER] = {
53 "AUTO",
54 "ON",
55 "OFF"
58 const char *Screen::main_menu_line_1[] = {
59 "PACKET",
60 "TX",
61 "TELEM",
62 "MOTION",
63 "FAN",
64 "BIND",
65 "UPDATE"
68 const char *Screen::main_menu_line_2[] = {
69 "RATE",
70 "POWER",
71 "RATIO",
72 "DETECT",
73 "CONTROL",
74 "MODE",
75 "FW"
78 void Screen::doMainMenuPage(int action)
80 int index = main_menu_page_index;
81 if(action == USER_ACTION_UP)
83 index--;
84 #ifndef HAS_THERMAL
85 if (index == MAIN_MENU_SMARTFAN_INDEX) index--;
86 #endif
87 #ifndef HAS_GSENSOR
88 if (index == MAIN_MENU_POWERSAVING_INDEX) index--;
89 #endif
91 if(action == USER_ACTION_DOWN)
93 index++;
94 #ifndef HAS_GSENSOR
95 if (index == MAIN_MENU_POWERSAVING_INDEX) index++;
96 #endif
97 #ifndef HAS_THERMAL
98 if (index == MAIN_MENU_SMARTFAN_INDEX) index++;
99 #endif
101 if(index < MAIN_MENU_RATE_INDEX)
103 index = MAIN_MENU_UPDATEFW_INDEX;
105 if(index > MAIN_MENU_UPDATEFW_INDEX)
107 index = MAIN_MENU_RATE_INDEX;
109 main_menu_page_index = index;
111 updateMainMenuPage();
114 void Screen::doPageBack()
116 if(current_page_index == PAGE_MAIN_MENU_INDEX)
118 idleScreen();
120 else if((current_page_index == PAGE_SUB_RATE_INDEX) ||
121 (current_page_index == PAGE_SUB_POWER_INDEX) ||
122 (current_page_index == PAGE_SUB_RATIO_INDEX) ||
123 (current_page_index == PAGE_SUB_POWERSAVING_INDEX) ||
124 (current_page_index == PAGE_SUB_SMARTFAN_INDEX))
126 current_page_index = PAGE_MAIN_MENU_INDEX;
127 doMainMenuPage(USER_ACTION_NONE);
129 else if(current_page_index == PAGE_SUB_BIND_INDEX)
131 current_page_index = PAGE_MAIN_MENU_INDEX;
132 doMainMenuPage(USER_ACTION_NONE);
134 else if(current_page_index == PAGE_SUB_BINDING_INDEX)
136 current_page_index = PAGE_SUB_BIND_INDEX;
137 updateSubBindConfirmPage();
138 updatecallback(USER_UPDATE_TYPE_EXIT_BINDING);
140 current_screen_status = SCREEN_STATUS_WORK;
142 else if(current_page_index == PAGE_SUB_UPDATEFW_INDEX)
144 current_page_index = PAGE_MAIN_MENU_INDEX;
145 doMainMenuPage(USER_ACTION_NONE);
146 updatecallback(USER_UPDATE_TYPE_EXIT_WIFI);
150 void Screen::doPageForward()
152 if(current_page_index == PAGE_MAIN_MENU_INDEX)
154 if((main_menu_page_index == MAIN_MENU_RATE_INDEX) ||
155 (main_menu_page_index == MAIN_MENU_POWER_INDEX) ||
156 (main_menu_page_index == MAIN_MENU_RATIO_INDEX) ||
157 (main_menu_page_index == MAIN_MENU_POWERSAVING_INDEX) ||
158 (main_menu_page_index == MAIN_MENU_SMARTFAN_INDEX))
160 current_page_index = main_menu_page_index;
161 updateSubFunctionPage();
163 else if(main_menu_page_index == MAIN_MENU_UPDATEFW_INDEX)
165 current_page_index = PAGE_SUB_UPDATEFW_INDEX;
166 updateSubWIFIModePage();
168 else if(main_menu_page_index == MAIN_MENU_BIND_INDEX)
170 current_page_index = PAGE_SUB_BIND_INDEX;
171 updateSubBindConfirmPage();
174 else if((current_page_index == PAGE_SUB_RATE_INDEX) ||
175 (current_page_index == PAGE_SUB_POWER_INDEX) ||
176 (current_page_index == PAGE_SUB_RATIO_INDEX) ||
177 (current_page_index == PAGE_SUB_POWERSAVING_INDEX) ||
178 (current_page_index == PAGE_SUB_SMARTFAN_INDEX))
180 current_page_index = PAGE_MAIN_MENU_INDEX;
181 doMainMenuPage(USER_ACTION_NONE);
183 else if(current_page_index == PAGE_SUB_BIND_INDEX)
185 current_page_index = PAGE_SUB_BINDING_INDEX;
186 updateSubBindingPage();
190 void Screen::doValueConfirm()
192 if(current_page_index == PAGE_SUB_RATE_INDEX)
194 updatecallback(USER_UPDATE_TYPE_RATE);
196 else if(current_page_index == PAGE_SUB_POWER_INDEX)
198 updatecallback(USER_UPDATE_TYPE_POWER);
200 else if(current_page_index == PAGE_SUB_RATIO_INDEX)
202 updatecallback(USER_UPDATE_TYPE_RATIO);
204 else if(current_page_index == PAGE_SUB_SMARTFAN_INDEX)
206 updatecallback(USER_UPDATE_TYPE_SMARTFAN);
208 else if(current_page_index == PAGE_SUB_POWERSAVING_INDEX)
210 updatecallback(USER_UPDATE_TYPE_POWERSAVING);
213 doPageForward();
216 void Screen::doUserAction(int action)
218 if(action == USER_ACTION_LEFT)
220 doPageBack();
222 else if(action == USER_ACTION_RIGHT)
224 doPageForward();
226 else if(action == USER_ACTION_CONFIRM)
228 doValueConfirm();
230 else
232 doValueSelection(action);
236 void Screen::activeScreen()
238 doMainMenuPage(USER_ACTION_NONE);
240 current_screen_status = SCREEN_STATUS_WORK;
241 current_page_index = PAGE_MAIN_MENU_INDEX;
244 void Screen::doValueSelection(int action)
246 if(current_page_index == PAGE_MAIN_MENU_INDEX)
248 doMainMenuPage(action);
250 else if(current_page_index == PAGE_SUB_RATE_INDEX)
252 doRateValueSelect(action);
254 else if(current_page_index == PAGE_SUB_POWER_INDEX)
256 doPowerValueSelect(action);
258 else if(current_page_index == PAGE_SUB_RATIO_INDEX)
260 doRatioValueSelect(action);
262 else if(current_page_index == PAGE_SUB_POWERSAVING_INDEX)
264 doPowerSavingValueSelect(action);
266 else if(current_page_index == PAGE_SUB_SMARTFAN_INDEX)
268 doSmartFanValueSelect(action);
272 void Screen::nextIndex(int &index, int action, int min, int max)
274 if(action == USER_ACTION_UP)
276 index--;
278 if(action == USER_ACTION_DOWN)
280 index++;
283 if(index < min)
285 index = max - 1;
287 if(index > max - 1)
289 index = min;
293 void Screen::setInWifiMode()
295 current_screen_status = SCREEN_STATUS_WORK;
296 main_menu_page_index = MAIN_MENU_UPDATEFW_INDEX;
297 current_page_index = PAGE_SUB_UPDATEFW_INDEX;
298 updateSubWIFIModePage();
301 #endif