Massive cleaning (#5538)
[opentx.git] / radio / src / gui / 212x64 / view_channels.cpp
blobf8a183eb1e0ad6b1090d39ee2ee519c108529ac1
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 void menuChannelsView(event_t event)
25 static bool longNames = false;
26 static bool secondPage = false;
27 static bool mixersView = false;
28 uint8_t ch = 0;
29 uint8_t wbar = (longNames ? 54 : 64);
30 int16_t limits = 512 * 2;
32 #if defined(PPM_UNIT_PERCENT_PREC1)
33 wbar -= 6;
34 #endif
36 switch(event)
38 case EVT_KEY_BREAK(KEY_EXIT):
39 popMenu();
40 break;
41 case EVT_KEY_FIRST(KEY_RIGHT):
42 case EVT_KEY_FIRST(KEY_LEFT):
43 #if defined(ROTARY_ENCODER_NAVIGATION)
44 case EVT_ROTARY_LEFT:
45 case EVT_ROTARY_RIGHT:
46 #endif
47 secondPage = !secondPage;
48 break;
49 case EVT_KEY_FIRST(KEY_ENTER):
50 mixersView = !mixersView;
51 break;
54 if (secondPage)
55 ch = 16;
57 if (mixersView)
58 limits *= 2; // this could be handled nicer, but slower, by checking actual range for this mixer
59 else if (g_model.extendedLimits)
60 limits *= LIMIT_EXT_PERCENT / 100;
62 if (mixersView)
63 lcdDrawTextAlignedCenter(0, MIXERS_MONITOR);
64 else
65 lcdDrawTextAlignedCenter(0, CHANNELS_MONITOR);
67 lcdInvertLine(0);
69 // Column separator
70 lcdDrawSolidVerticalLine(LCD_W/2, FH, LCD_H-FH);
72 for (uint8_t col=0; col < 2; col++) {
73 const uint8_t x = col * LCD_W / 2 + 1;
74 const uint8_t ofs = (col ? 0 : 1);
76 // Channels
77 for (uint8_t line=0; line < 8; line++) {
78 const uint8_t y = 9 + line * 7;
79 const int32_t val = mixersView ? ex_chans[ch] : channelOutputs[ch];
80 const uint8_t lenLabel = ZLEN(g_model.limitData[ch].name);
82 // Channel name if present, number if not
83 if (lenLabel > 0) {
84 if (lenLabel > 4)
85 longNames = true;
86 lcdDrawSizedText(x+1-ofs, y, g_model.limitData[ch].name, sizeof(g_model.limitData[ch].name), ZCHAR | SMLSIZE);
88 else {
89 putsChn(x+1-ofs, y, ch+1, SMLSIZE);
92 // Value
93 #if defined(PPM_UNIT_US)
94 lcdDrawNumber(x+LCD_W/2-3-wbar-ofs, y+1, PPM_CH_CENTER(ch)+val/2, TINSIZE|RIGHT);
95 #elif defined(PPM_UNIT_PERCENT_PREC1)
96 lcdDrawNumber(x+LCD_W/2-3-wbar-ofs, y+1, calcRESXto1000(val), PREC1|TINSIZE|RIGHT);
97 #else
98 lcdDrawNumber(x+LCD_W/2-3-wbar-ofs, y+1, calcRESXto1000(val)/10, TINSIZE|RIGHT);
99 #endif
101 // Gauge
102 drawGauge(x+LCD_W/2-3-wbar-ofs, y, wbar, 6, val, limits);
104 ++ch;