[firmware][gui] Extended limits fixes, issue #4447 (#4453)
[opentx.git] / radio / src / gui / 128x64 / view_main.cpp
blob04e97391ce1ec6b52896e46fc1b78dc96b445a48
1 /*
2 * Copyright (C) OpenTX
4 * Based on code named
5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #include "opentx.h"
23 #define BIGSIZE DBLSIZE
24 #if defined (PCBX7)
25 #define LBOX_CENTERX (LCD_W/4 + 14)
26 #define RBOX_CENTERX (3*LCD_W/4 - 13)
27 #else
28 #define LBOX_CENTERX (LCD_W/4 + 10)
29 #define RBOX_CENTERX (3*LCD_W/4 - 10)
30 #endif
31 #define MODELNAME_X (2*FW-2)
32 #define MODELNAME_Y (0)
33 #define PHASE_X (6*FW-1)
34 #define PHASE_Y (2*FH)
35 #define PHASE_FLAGS 0
36 #define VBATT_X (6*FW)
37 #define VBATT_Y (2*FH)
38 #define VBATTUNIT_X (VBATT_X-1)
39 #define VBATTUNIT_Y (3*FH)
40 #define REBOOT_X (20*FW-3)
41 #define BAR_HEIGHT (BOX_WIDTH-1)
42 #define TRIM_LH_X (LCD_W*1/4+2)
43 #define TRIM_LV_X 3
44 #define TRIM_RV_X (LCD_W-4)
45 #define TRIM_RH_X (LCD_W*3/4-2)
46 #define TRIM_LH_NEG (TRIM_LH_X+1*FW)
47 #define TRIM_LH_POS (TRIM_LH_X-4*FW)
48 #define TRIM_RH_NEG (TRIM_RH_X+1*FW)
49 #define TRIM_RH_POS (TRIM_RH_X-4*FW)
51 #define TRIM_LEN 23
53 void drawPotsBars()
55 // Optimization by Mike Blandford
56 for (uint8_t x=LCD_W/2 - (NUM_POTS+NUM_SLIDERS-1) * 5 / 2, i=NUM_STICKS; i<NUM_STICKS+NUM_POTS+NUM_SLIDERS; x+=5, i++) {
57 if (IS_POT_SLIDER_AVAILABLE(i)) {
58 uint8_t len = ((calibratedAnalogs[i]+RESX)*BAR_HEIGHT/(RESX*2))+1l; // calculate once per loop
59 V_BAR(x, LCD_H-8, len);
64 void doMainScreenGraphics()
66 int16_t calibStickVert = calibratedAnalogs[CONVERT_MODE(1)];
67 if (g_model.throttleReversed && CONVERT_MODE(1) == THR_STICK)
68 calibStickVert = -calibStickVert;
69 drawStick(LBOX_CENTERX, calibratedAnalogs[CONVERT_MODE(0)], calibStickVert);
71 calibStickVert = calibratedAnalogs[CONVERT_MODE(2)];
72 if (g_model.throttleReversed && CONVERT_MODE(2) == THR_STICK)
73 calibStickVert = -calibStickVert;
74 drawStick(RBOX_CENTERX, calibratedAnalogs[CONVERT_MODE(3)], calibStickVert);
76 drawPotsBars();
79 void displayTrims(uint8_t phase)
81 for (uint8_t i=0; i<4; i++) {
82 static coord_t x[4] = {TRIM_LH_X, TRIM_LV_X, TRIM_RV_X, TRIM_RH_X};
83 static uint8_t vert[4] = {0,1,1,0};
84 coord_t xm, ym;
85 uint8_t stickIndex = CONVERT_MODE(i);
86 xm = x[stickIndex];
87 uint8_t att = ROUND;
88 int16_t val = getTrimValue(phase, i);
90 #if !defined(CPUM64) || !defined(TELEMETRY_FRSKY)
91 int16_t dir = val;
92 bool exttrim = false;
93 if (val < TRIM_MIN || val > TRIM_MAX) {
94 exttrim = true;
96 #endif
97 if (val < -(TRIM_LEN+1)*4) {
98 val = -(TRIM_LEN+1);
100 else if (val > (TRIM_LEN+1)*4) {
101 val = TRIM_LEN+1;
103 else {
104 val /= 4;
107 if (vert[i]) {
108 ym = 31;
109 lcdDrawSolidVerticalLine(xm, ym-TRIM_LEN, TRIM_LEN*2);
110 if (i!=2 || !g_model.thrTrim) {
111 lcdDrawSolidVerticalLine(xm-1, ym-1, 3);
112 lcdDrawSolidVerticalLine(xm+1, ym-1, 3);
114 ym -= val;
115 #if !defined(CPUM64) || !defined(TELEMETRY_FRSKY)
116 lcdDrawFilledRect(xm-3, ym-3, 7, 7, SOLID, att|ERASE);
117 if (dir >= 0) {
118 lcdDrawSolidHorizontalLine(xm-1, ym-1, 3);
120 if (dir <= 0) {
121 lcdDrawSolidHorizontalLine(xm-1, ym+1, 3);
123 if (exttrim) {
124 lcdDrawSolidHorizontalLine(xm-1, ym, 3);
126 #endif
127 #if defined(CPUARM)
128 if (g_model.displayTrims != DISPLAY_TRIMS_NEVER && dir != 0) {
129 if (g_model.displayTrims == DISPLAY_TRIMS_ALWAYS || (trimsDisplayTimer > 0 && (trimsDisplayMask & (1<<i)))) {
130 lcdDrawNumber(dir>0 ? 12 : 40, xm-2, -abs(dir/5), TINSIZE|VERTICAL);
133 #endif
135 else {
136 ym = 60;
137 lcdDrawSolidHorizontalLine(xm-TRIM_LEN, ym, TRIM_LEN*2);
138 lcdDrawSolidHorizontalLine(xm-1, ym-1, 3);
139 lcdDrawSolidHorizontalLine(xm-1, ym+1, 3);
140 xm += val;
141 #if !defined(CPUM64) || !defined(TELEMETRY_FRSKY)
142 lcdDrawFilledRect(xm-3, ym-3, 7, 7, SOLID, att|ERASE);
143 if (dir >= 0) {
144 lcdDrawSolidVerticalLine(xm+1, ym-1, 3);
146 if (dir <= 0) {
147 lcdDrawSolidVerticalLine(xm-1, ym-1, 3);
149 if (exttrim) {
150 lcdDrawSolidVerticalLine(xm, ym-1, 3);
152 #endif
153 #if defined(CPUARM)
154 if (g_model.displayTrims != DISPLAY_TRIMS_NEVER && dir != 0) {
155 if (g_model.displayTrims == DISPLAY_TRIMS_ALWAYS || (trimsDisplayTimer > 0 && (trimsDisplayMask & (1<<i)))) {
156 lcdDrawNumber((stickIndex==0 ? (dir>0 ? TRIM_LH_POS : TRIM_LH_NEG) : (dir>0 ? TRIM_RH_POS : TRIM_RH_NEG)), ym-2, -abs(dir/5), TINSIZE);
159 #endif
161 lcdDrawSquare(xm-3, ym-3, 7, att);
165 void drawTimerWithMode(coord_t x, coord_t y, uint8_t index)
167 // Main timer
168 if (g_model.timers[index].mode) {
169 const TimerState & timerState = timersStates[index];
170 LcdFlags att = RIGHT | DBLSIZE | (timerState.val<0 ? BLINK|INVERS : 0);
171 drawTimer(x, y, timerState.val, att, att);
172 #if defined(CPUARM)
173 uint8_t xLabel = (timerState.val >= 0 ? x-49 : x-56);
174 uint8_t len = zlen(g_model.timers[index].name, LEN_TIMER_NAME);
175 if (len > 0) {
176 lcdDrawSizedText(xLabel, y+FH, g_model.timers[index].name, len, RIGHT | ZCHAR);
178 else {
179 drawTimerMode(xLabel, y+FH, g_model.timers[index].mode, RIGHT);
181 #else
182 uint8_t xLabel = (timerState.val >= 0 ? x-69 : x-76);
183 drawTimerMode(xLabel, y+FH, g_model.timers[index].mode);
184 #endif
188 void displayBattVoltage()
190 #if defined(BATTGRAPH)
191 putsVBat(VBATT_X-8, VBATT_Y+1, RIGHT);
192 lcdDrawSolidFilledRect(VBATT_X-25, VBATT_Y+9, 21, 5);
193 lcdDrawSolidVerticalLine(VBATT_X-4, VBATT_Y+10, 3);
194 uint8_t count = GET_TXBATT_BARS();
195 for (uint8_t i=0; i<count; i+=2)
196 lcdDrawSolidVerticalLine(VBATT_X-24+i, VBATT_Y+10, 3);
197 if (!IS_TXBATT_WARNING() || BLINK_ON_PHASE)
198 lcdDrawSolidFilledRect(VBATT_X-26, VBATT_Y, 24, 15);
199 #else
200 LcdFlags att = (IS_TXBATT_WARNING() ? BLINK|INVERS : 0) | BIGSIZE;
201 putsVBat(VBATT_X-1, VBATT_Y, att|NO_UNIT);
202 lcdDrawChar(VBATT_X, VBATTUNIT_Y, 'V');
203 #endif
206 #if defined(PCBSKY9X)
207 void displayVoltageOrAlarm()
209 if (g_eeGeneral.temperatureWarn && getTemperature() >= g_eeGeneral.temperatureWarn) {
210 drawValueWithUnit(6*FW-1, 2*FH, getTemperature(), UNIT_TEMPERATURE, BLINK|INVERS|DBLSIZE|RIGHT);
212 else if (g_eeGeneral.mAhWarn && (g_eeGeneral.mAhUsed + Current_used * (488 + g_eeGeneral.txCurrentCalibration)/8192/36) / 500 >= g_eeGeneral.mAhWarn) {
213 drawValueWithUnit(7*FW-1, 2*FH, (g_eeGeneral.mAhUsed + Current_used*(488 + g_eeGeneral.txCurrentCalibration)/8192/36)/10, UNIT_MAH, BLINK|INVERS|DBLSIZE|RIGHT);
215 else {
216 displayBattVoltage();
219 #else
220 #define displayVoltageOrAlarm() displayBattVoltage()
221 #endif
223 #if defined(PCBX7)
224 #define EVT_KEY_CONTEXT_MENU EVT_KEY_LONG(KEY_ENTER)
225 #define EVT_KEY_NEXT_VIEW EVT_KEY_BREAK(KEY_PAGE)
226 #define EVT_KEY_NEXT_PAGE EVT_ROTARY_RIGHT
227 #define EVT_KEY_PREVIOUS_PAGE EVT_ROTARY_LEFT
228 #define EVT_KEY_MODEL_MENU EVT_KEY_BREAK(KEY_MENU)
229 #define EVT_KEY_GENERAL_MENU EVT_KEY_LONG(KEY_MENU)
230 #define EVT_KEY_TELEMETRY EVT_KEY_LONG(KEY_PAGE)
231 #else
232 #define EVT_KEY_CONTEXT_MENU EVT_KEY_BREAK(KEY_MENU)
233 #define EVT_KEY_PREVIOUS_VIEW EVT_KEY_BREAK(KEY_UP)
234 #define EVT_KEY_NEXT_VIEW EVT_KEY_BREAK(KEY_DOWN)
235 #define EVT_KEY_NEXT_PAGE EVT_KEY_BREAK(KEY_RIGHT)
236 #define EVT_KEY_PREVIOUS_PAGE EVT_KEY_BREAK(KEY_LEFT)
237 #define EVT_KEY_MODEL_MENU EVT_KEY_LONG(KEY_RIGHT)
238 #define EVT_KEY_GENERAL_MENU EVT_KEY_LONG(KEY_LEFT)
239 #define EVT_KEY_LAST_MENU EVT_KEY_LONG(KEY_MENU)
240 #define EVT_KEY_TELEMETRY EVT_KEY_LONG(KEY_DOWN)
241 #define EVT_KEY_STATISTICS EVT_KEY_LONG(KEY_UP)
242 #endif
244 #if defined(NAVIGATION_MENUS)
245 void onMainViewMenu(const char *result)
247 if (result == STR_RESET_TIMER1) {
248 timerReset(0);
250 else if (result == STR_RESET_TIMER2) {
251 timerReset(1);
253 #if TIMERS > 2
254 else if (result == STR_RESET_TIMER3) {
255 timerReset(2);
257 #endif
258 #if defined(CPUARM)
259 else if (result == STR_VIEW_NOTES) {
260 pushModelNotes();
262 else if (result == STR_RESET_SUBMENU) {
263 POPUP_MENU_ADD_ITEM(STR_RESET_FLIGHT);
264 POPUP_MENU_ADD_ITEM(STR_RESET_TIMER1);
265 POPUP_MENU_ADD_ITEM(STR_RESET_TIMER2);
266 POPUP_MENU_ADD_ITEM(STR_RESET_TIMER3);
267 #if defined(TELEMETRY_FRSKY)
268 POPUP_MENU_ADD_ITEM(STR_RESET_TELEMETRY);
269 #endif
271 #endif
272 #if defined(TELEMETRY_FRSKY)
273 else if (result == STR_RESET_TELEMETRY) {
274 telemetryReset();
276 #endif
277 else if (result == STR_RESET_FLIGHT) {
278 flightReset();
280 else if (result == STR_STATISTICS) {
281 chainMenu(menuStatisticsView);
283 #if defined(CPUARM)
284 else if (result == STR_ABOUT_US) {
285 chainMenu(menuAboutView);
287 #endif
289 #endif
291 void menuMainView(event_t event)
293 STICK_SCROLL_DISABLE();
295 uint8_t view = g_eeGeneral.view;
296 uint8_t view_base = view & 0x0f;
298 switch (event) {
299 case EVT_ENTRY:
300 killEvents(KEY_EXIT);
301 killEvents(KEY_UP);
302 killEvents(KEY_DOWN);
303 break;
305 /* TODO if timer2 is OFF, it's possible to use this timer2 as in er9x...
306 case EVT_KEY_BREAK(KEY_MENU):
307 if (view_base == VIEW_TIMER2) {
308 Timer2_running = !Timer2_running;
309 AUDIO_KEYPAD_UP();
311 break;
314 case EVT_KEY_NEXT_PAGE:
315 case EVT_KEY_PREVIOUS_PAGE:
316 if (view_base <= VIEW_INPUTS) {
317 #if defined(CPUARM)
318 if (view_base == VIEW_INPUTS)
319 g_eeGeneral.view ^= ALTERNATE_VIEW;
320 else
321 g_eeGeneral.view = (g_eeGeneral.view + (4*ALTERNATE_VIEW) + ((event==EVT_KEY_PREVIOUS_PAGE) ? -ALTERNATE_VIEW : ALTERNATE_VIEW)) % (4*ALTERNATE_VIEW);
322 #else
323 g_eeGeneral.view ^= ALTERNATE_VIEW;
324 #endif
325 storageDirty(EE_GENERAL);
326 AUDIO_KEY_PRESS();
328 break;
330 #if defined(NAVIGATION_MENUS)
331 case EVT_KEY_CONTEXT_MENU:
332 killEvents(event);
334 #if defined(CPUARM)
335 if (modelHasNotes()) {
336 POPUP_MENU_ADD_ITEM(STR_VIEW_NOTES);
338 #endif
340 #if defined(CPUARM)
341 POPUP_MENU_ADD_ITEM(STR_RESET_SUBMENU);
342 #else
343 POPUP_MENU_ADD_ITEM(STR_RESET_TIMER1);
344 POPUP_MENU_ADD_ITEM(STR_RESET_TIMER2);
345 #if defined(TELEMETRY_FRSKY)
346 POPUP_MENU_ADD_ITEM(STR_RESET_TELEMETRY);
347 #endif
348 POPUP_MENU_ADD_ITEM(STR_RESET_FLIGHT);
349 #endif
351 POPUP_MENU_ADD_ITEM(STR_STATISTICS);
352 #if defined(CPUARM)
353 POPUP_MENU_ADD_ITEM(STR_ABOUT_US);
354 #endif
355 POPUP_MENU_START(onMainViewMenu);
356 break;
357 #endif
359 #if MENUS_LOCK != 2 /*no menus*/
360 #if defined(EVT_KEY_LAST_MENU)
361 case EVT_KEY_LAST_MENU:
362 pushMenu(lastPopMenu());
363 killEvents(event);
364 break;
365 #endif
367 CASE_EVT_ROTARY_BREAK
368 case EVT_KEY_MODEL_MENU:
369 pushMenu(menuModelSelect);
370 killEvents(event);
371 break;
373 CASE_EVT_ROTARY_LONG
374 case EVT_KEY_GENERAL_MENU:
375 pushMenu(menuRadioSetup);
376 killEvents(event);
377 break;
378 #endif
380 #if defined(EVT_KEY_PREVIOUS_VIEW)
381 // TODO try to split those 2 cases on 9X
382 case EVT_KEY_PREVIOUS_VIEW:
383 case EVT_KEY_NEXT_VIEW:
384 // TODO try to split those 2 cases on 9X
385 g_eeGeneral.view = (event == EVT_KEY_PREVIOUS_VIEW ? (view_base == VIEW_COUNT-1 ? 0 : view_base+1) : (view_base == 0 ? VIEW_COUNT-1 : view_base-1));
386 storageDirty(EE_GENERAL);
387 break;
388 #else
389 case EVT_KEY_NEXT_VIEW:
390 g_eeGeneral.view = (view_base == 0 ? VIEW_COUNT-1 : view_base-1);
391 storageDirty(EE_GENERAL);
392 break;
393 #endif
395 #if defined(EVT_KEY_STATISTICS)
396 case EVT_KEY_STATISTICS:
397 chainMenu(menuStatisticsView);
398 killEvents(event);
399 break;
400 #endif
402 case EVT_KEY_TELEMETRY:
403 #if defined(TELEMETRY_FRSKY)
404 if (!IS_FAI_ENABLED())
405 chainMenu(menuViewTelemetryFrsky);
406 #elif defined(TELEMETRY_JETI)
407 JETI_EnableRXD(); // enable JETI-Telemetry reception
408 chainMenu(menuViewTelemetryJeti);
409 #elif defined(TELEMETRY_ARDUPILOT)
410 ARDUPILOT_EnableRXD(); // enable ArduPilot-Telemetry reception
411 chainMenu(menuViewTelemetryArduPilot);
412 #elif defined(TELEMETRY_NMEA)
413 NMEA_EnableRXD(); // enable NMEA-Telemetry reception
414 chainMenu(menuViewTelemetryNMEA);
415 #elif defined(TELEMETRY_MAVLINK)
416 chainMenu(menuViewTelemetryMavlink);
417 #else
418 chainMenu(menuStatisticsDebug);
419 #endif
420 killEvents(event);
421 break;
423 case EVT_KEY_FIRST(KEY_EXIT):
424 #if defined(GVARS) && !defined(PCBSTD)
425 if (gvarDisplayTimer > 0) {
426 gvarDisplayTimer = 0;
428 #endif
429 #if !defined(NAVIGATION_MENUS)
430 if (view == VIEW_TIMER2) {
431 timerReset(1);
433 #endif
434 break;
436 #if !defined(NAVIGATION_MENUS)
437 case EVT_KEY_LONG(KEY_EXIT):
438 flightReset();
439 break;
440 #endif
444 // Flight Mode Name
445 uint8_t mode = mixerCurrentFlightMode;
446 lcdDrawSizedText(PHASE_X, PHASE_Y, g_model.flightModeData[mode].name, sizeof(g_model.flightModeData[mode].name), ZCHAR|PHASE_FLAGS);
448 // Model Name
449 putsModelName(MODELNAME_X, MODELNAME_Y, g_model.header.name, g_eeGeneral.currModel, BIGSIZE);
451 // Main Voltage (or alarm if any)
452 displayVoltageOrAlarm();
454 // Timer 1
455 drawTimerWithMode(120, 2*FH, 0);
457 // Trims sliders
458 displayTrims(mode);
461 if (view_base < VIEW_INPUTS) {
462 // scroll bar
463 lcdDrawHorizontalLine(38, 34, 54, DOTTED);
464 #if defined(CPUARM)
465 lcdDrawSolidHorizontalLine(38 + (g_eeGeneral.view / ALTERNATE_VIEW) * 13, 34, 13, SOLID);
466 #else
467 lcdDrawSolidHorizontalLine((g_eeGeneral.view & ALTERNATE_VIEW) ? 64 : 38, 34, 26, SOLID);
468 #endif
470 for (uint8_t i=0; i<8; i++) {
471 uint8_t x0,y0;
472 #if defined(CPUARM)
473 uint8_t chan = 8*(g_eeGeneral.view / ALTERNATE_VIEW) + i;
474 #else
475 uint8_t chan = (g_eeGeneral.view & ALTERNATE_VIEW) ? 8+i : i;
476 #endif
478 int16_t val = channelOutputs[chan];
480 switch (view_base) {
481 case VIEW_OUTPUTS_VALUES:
482 x0 = (i%4*9+3)*FW/2;
483 y0 = i/4*FH+40;
484 #if defined(PPM_UNIT_US)
485 lcdDrawNumber(x0+4*FW , y0, PPM_CH_CENTER(chan)+val/2, RIGHT);
486 #elif defined(PPM_UNIT_PERCENT_PREC1)
487 lcdDrawNumber(x0+4*FW , y0, calcRESXto1000(val), RIGHT|PREC1);
488 #else
489 lcdDrawNumber(x0+4*FW , y0, calcRESXto1000(val)/10, RIGHT); // G: Don't like the decimal part*
490 #endif
491 break;
493 case VIEW_OUTPUTS_BARS:
494 #define WBAR2 (50/2)
495 x0 = i<4 ? LCD_W/4+2 : LCD_W*3/4-2;
496 y0 = 38+(i%4)*5;
498 const uint16_t lim = (g_model.extendedLimits ? 512 * uint8_t(LIMIT_EXT_PERCENT / 100) : 512) * 2;
499 int8_t len = (abs(val) * WBAR2 + lim/2) / lim;
501 if (len>WBAR2)
502 len = WBAR2; // prevent bars from going over the end - comment for debugging
503 lcdDrawHorizontalLine(x0-WBAR2, y0, WBAR2*2+1, DOTTED);
504 lcdDrawSolidVerticalLine(x0, y0-2,5 );
505 if (val > 0)
506 x0 += 1;
507 else
508 x0 -= len;
509 lcdDrawSolidHorizontalLine(x0, y0+1, len);
510 lcdDrawSolidHorizontalLine(x0, y0-1, len);
511 break;
515 else if (view_base == VIEW_INPUTS) {
516 if (view == VIEW_INPUTS) {
517 // Sticks + Pots
518 doMainScreenGraphics();
520 // Switches
521 #if defined(PCBX7)
522 for (int i=0; i<NUM_SWITCHES; ++i) {
523 if (SWITCH_EXISTS(i)) {
524 uint8_t x = 2*FW-2, y = 4*FH+i*FH+1;
525 if (i >= NUM_SWITCHES/2) {
526 x = 16*FW+1;
527 y -= 3*FH;
529 getvalue_t val = getValue(MIXSRC_FIRST_SWITCH+i);
530 getvalue_t sw = ((val < 0) ? 3*i+1 : ((val == 0) ? 3*i+2 : 3*i+3));
531 drawSwitch(x, y, sw, 0);
534 #else
535 // The ID0 3-POS switch is merged with the TRN switch
536 for (uint8_t i=SWSRC_THR; i<=SWSRC_TRN; i++) {
537 int8_t sw = (i == SWSRC_TRN ? (switchState(SW_ID0) ? SWSRC_ID0 : (switchState(SW_ID1) ? SWSRC_ID1 : SWSRC_ID2)) : i);
538 uint8_t x = 2*FW-2, y = i*FH+1;
539 if (i >= SWSRC_AIL) {
540 x = 17*FW-1;
541 y -= 3*FH;
543 drawSwitch(x, y, sw, getSwitch(i) ? INVERS : 0);
545 #endif
547 else {
548 #if defined(PCBMEGA2560) && defined(ROTARY_ENCODERS)
549 for (uint8_t i=0; i<NUM_ROTARY_ENCODERS; i++) {
550 int16_t val = getRotaryEncoder(i);
551 int8_t len = limit((int16_t)0, (int16_t)(((val+1024) * BAR_HEIGHT) / 2048), (int16_t)BAR_HEIGHT);
552 #if ROTARY_ENCODERS > 2
553 #define V_BAR_W 5
554 V_BAR(LCD_W/2-8+V_BAR_W*i, LCD_H-8, len);
555 #else
556 #define V_BAR_W 5
557 V_BAR(LCD_W/2-3+V_BAR_W*i, LCD_H-8, len);
558 #endif
560 #endif // PCBGRUVIN9X && ROTARY_ENCODERS
562 // Logical Switches
563 #if defined(CPUARM)
564 uint8_t index = 0;
565 uint8_t y = LCD_H-20;
566 for (uint8_t line=0; line<2; line++) {
567 for (uint8_t column=0; column<MAX_LOGICAL_SWITCHES/2; column++) {
568 int8_t len = getSwitch(SWSRC_SW1+index) ? 10 : 1;
569 uint8_t x = (16 + 3*column);
570 lcdDrawSolidVerticalLine(x-1, y-len, len);
571 lcdDrawSolidVerticalLine(x, y-len, len);
572 index++;
574 y += 12;
576 #elif defined(CPUM2560)
577 for (uint8_t i=0; i<MAX_LOGICAL_SWITCHES; i++) {
578 drawSwitch(2*FW-3 + (i/3)*(i/3>2 ? 3*FW+2 : (3*FW-1)) + (i/3>2 ? 2*FW : 0), 4*FH+1 + (i%3)*FH, SWSRC_SW1+i, getSwitch(SWSRC_SW1+i) ? INVERS : 0);
580 #elif !defined(PCBSTD)
581 for (uint8_t i=0; i<MAX_LOGICAL_SWITCHES; i++) {
582 drawSwitch(2*FW-2 + (i/3)*(4*FW-1), 4*FH+1 + (i%3)*FH, SWSRC_SW1+i, getSwitch(SWSRC_SW1+i) ? INVERS : 0);
584 #else
585 for (uint8_t i=0; i<MAX_LOGICAL_SWITCHES; i++) {
586 drawSwitch(2*FW-3 + (i/3)*(4*FW), 4*FH+1 + (i%3)*FH, SWSRC_SW1+i, getSwitch(SWSRC_SW1+i) ? INVERS : 0);
588 #endif
591 else {
592 // Timer2
593 drawTimerWithMode(87, 5*FH, 1);
596 // And ! in case of unexpected shutdown
597 #if defined(LOG_TELEMETRY) || defined(WATCHDOG_DISABLED)
598 lcdDrawChar(REBOOT_X, 0*FH, '!', INVERS);
599 #else
600 if (unexpectedShutdown) {
601 lcdDrawChar(REBOOT_X, 0*FH, '!', INVERS);
603 #endif
605 #if defined(GVARS) && !defined(PCBSTD)
606 if (gvarDisplayTimer > 0) {
607 gvarDisplayTimer--;
608 warningText = STR_GLOBAL_VAR;
609 drawMessageBox();
610 lcdDrawSizedText(16, 5*FH, g_model.gvars[gvarLastChanged].name, LEN_GVAR_NAME, ZCHAR);
611 lcdDrawText(16+7*FW, 5*FH, PSTR("[\010]"), BOLD);
613 lcdDrawNumber(16+7*FW+4*FW+FW/2, 5*FH, GVAR_VALUE(gvarLastChanged, getGVarFlightMode(mixerCurrentFlightMode, gvarLastChanged)), BOLD);
614 warningText = NULL;
616 #endif
618 #if defined(DSM2)
619 if (moduleFlag[0] == MODULE_BIND) {
620 // Issue 98
621 lcdDrawText(15*FW, 0, PSTR("BIND"), 0);
623 #endif
626 #undef EVT_KEY_CONTEXT_MENU
627 #undef EVT_KEY_PREVIOUS_VIEW
628 #undef EVT_KEY_NEXT_VIEW
629 #undef EVT_KEY_NEXT_PAGE
630 #undef EVT_KEY_PREVIOUS_PAGE
631 #undef EVT_KEY_MODEL_MENU
632 #undef EVT_KEY_GENERAL_MENU
633 #undef EVT_KEY_LAST_MENU
634 #undef EVT_KEY_TELEMETRY
635 #undef EVT_KEY_STATISTICS