Merge companion and firmware notes, and get them from the server (#5530)
[opentx.git] / radio / src / gui / 212x64 / view_statistics.cpp
blobe980092bece3e24fe5a337f6235eec0a4f889382
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 STATS_1ST_COLUMN FW/2
24 #define STATS_2ND_COLUMN 12*FW+FW/2
25 #define STATS_3RD_COLUMN 24*FW+FW/2
26 #define STATS_LABEL_WIDTH 4*FW
28 void menuStatisticsView(event_t event)
30 TITLE(STR_MENUSTAT);
32 switch(event)
34 case EVT_KEY_FIRST(KEY_UP):
35 case EVT_KEY_BREAK(KEY_PAGE):
36 chainMenu(menuStatisticsDebug);
37 break;
39 case EVT_KEY_FIRST(KEY_DOWN):
40 case EVT_KEY_LONG(KEY_PAGE):
41 killEvents(event);
42 #if defined(DEBUG_TRACE_BUFFER)
43 chainMenu(menuTraceBuffer);
44 #else
45 chainMenu(menuStatisticsDebug2);
46 #endif
47 break;
49 case EVT_KEY_LONG(KEY_MENU): // historical
50 case EVT_KEY_LONG(KEY_ENTER):
51 g_eeGeneral.globalTimer = 0;
52 storageDirty(EE_GENERAL);
53 sessionTimer = 0;
54 break;
56 case EVT_KEY_FIRST(KEY_EXIT):
57 chainMenu(menuMainView);
58 break;
61 // Session and Total timers
62 lcdDrawText(STATS_1ST_COLUMN, FH*1+1, "SES", BOLD);
63 drawTimer(STATS_1ST_COLUMN + STATS_LABEL_WIDTH, FH*1+1, sessionTimer, 0, 0);
64 lcdDrawText(STATS_1ST_COLUMN, FH*2+1, "TOT", BOLD);
65 drawTimer(STATS_1ST_COLUMN + STATS_LABEL_WIDTH, FH*2+1, g_eeGeneral.globalTimer + sessionTimer, TIMEHOUR, 0);
67 // Throttle special timers
68 lcdDrawText(STATS_2ND_COLUMN, FH*0+1, "THR", BOLD);
69 drawTimer(STATS_2ND_COLUMN + STATS_LABEL_WIDTH, FH*0+1, s_timeCumThr, 0, 0);
70 lcdDrawText(STATS_2ND_COLUMN, FH*1+1, "TH%", BOLD);
71 drawTimer(STATS_2ND_COLUMN + STATS_LABEL_WIDTH, FH*1+1, s_timeCum16ThrP/16, 0, 0);
73 // Timers
74 for (int i=0; i<TIMERS; i++) {
75 drawStringWithIndex(STATS_3RD_COLUMN, FH*i+1, "TM", i+1, BOLD);
76 if (timersStates[i].val > 3600)
77 drawTimer(STATS_3RD_COLUMN + STATS_LABEL_WIDTH, FH*i+1, timersStates[i].val, TIMEHOUR, 0);
78 else
79 drawTimer(STATS_3RD_COLUMN + STATS_LABEL_WIDTH, FH*i+1, timersStates[i].val, 0, 0);
82 #if defined(THRTRACE)
83 const coord_t x = 5;
84 const coord_t y = 60;
85 lcdDrawSolidHorizontalLine(x-3, y, MAXTRACE+3+3);
86 lcdDrawSolidVerticalLine(x, y-32, 32+3);
87 for (coord_t i=0; i<MAXTRACE; i+=6) {
88 lcdDrawSolidVerticalLine(x+i+6, y-1, 3);
91 uint16_t traceRd = s_traceWr > MAXTRACE ? s_traceWr - MAXTRACE : 0;
92 for (coord_t i=1; i<=MAXTRACE && traceRd<s_traceWr; i++, traceRd++) {
93 uint8_t h = s_traceBuf[traceRd % MAXTRACE];
94 lcdDrawSolidVerticalLine(x+i, y-h, h);
96 #endif
99 #define MENU_DEBUG_COL1_OFS (11*FW-2)
100 #define MENU_DEBUG_ROW1 (2*FH-3)
101 #define MENU_DEBUG_ROW2 (3*FH-2)
102 #define MENU_DEBUG_ROW3 (4*FH-1)
103 #define MENU_DEBUG_ROW4 (5*FH)
104 #define MENU_DEBUG_ROW5 (6*FH)
106 void menuStatisticsDebug(event_t event)
108 TITLE(STR_MENUDEBUG);
110 #if defined(WATCHDOG_TEST)
111 if (warningResult) {
112 warningResult = 0;
113 // do a user requested watchdog test
114 TRACE("Performing watchdog test");
115 pausePulses();
117 #endif
119 switch(event)
121 case EVT_KEY_LONG(KEY_ENTER):
122 g_eeGeneral.globalTimer = 0;
123 storageDirty(EE_GENERAL);
124 sessionTimer = 0;
125 killEvents(event);
126 break;
127 case EVT_KEY_FIRST(KEY_ENTER):
128 #if defined(LUA)
129 maxLuaInterval = 0;
130 maxLuaDuration = 0;
131 #endif
132 maxMixerDuration = 0;
133 break;
135 case EVT_KEY_FIRST(KEY_DOWN):
136 case EVT_KEY_LONG(KEY_PAGE):
137 killEvents(event);
138 chainMenu(menuStatisticsView);
139 break;
141 case EVT_KEY_FIRST(KEY_UP):
142 case EVT_KEY_BREAK(KEY_PAGE):
143 chainMenu(menuStatisticsDebug2);
144 break;
146 case EVT_KEY_FIRST(KEY_EXIT):
147 chainMenu(menuMainView);
148 break;
149 #if defined(WATCHDOG_TEST)
150 case EVT_KEY_LONG(KEY_MENU):
152 POPUP_CONFIRMATION("Test the watchdog?");
153 const char * w = "The radio will reset!";
154 SET_WARNING_INFO(w, strlen(w), 0);
156 break;
157 #endif
160 lcdDrawTextAlignedLeft(MENU_DEBUG_ROW3, "Free Mem");
161 lcdDrawNumber(MENU_DEBUG_COL1_OFS, MENU_DEBUG_ROW3, availableMemory(), LEFT);
162 lcdDrawText(lcdLastRightPos, MENU_DEBUG_ROW3, "b");
164 #if defined(LUA)
165 lcdDrawTextAlignedLeft(MENU_DEBUG_ROW2, "Lua scripts");
166 lcdDrawText(MENU_DEBUG_COL1_OFS, MENU_DEBUG_ROW2+1, "[Duration]", SMLSIZE);
167 lcdDrawNumber(lcdLastRightPos, MENU_DEBUG_ROW2, 10*maxLuaDuration, LEFT);
168 lcdDrawText(lcdLastRightPos+2, MENU_DEBUG_ROW2+1, "[Interval]", SMLSIZE);
169 lcdDrawNumber(lcdLastRightPos, MENU_DEBUG_ROW2, 10*maxLuaInterval, LEFT);
170 #endif
172 lcdDrawTextAlignedLeft(MENU_DEBUG_ROW1, STR_TMIXMAXMS);
173 lcdDrawNumber(MENU_DEBUG_COL1_OFS, MENU_DEBUG_ROW1, DURATION_MS_PREC2(maxMixerDuration), PREC2|LEFT);
174 lcdDrawText(lcdLastRightPos, MENU_DEBUG_ROW1, "ms");
176 #if !defined(SIMU) && defined(DEBUG)
177 lcdDrawTextAlignedLeft(MENU_DEBUG_ROW4, "Usb");
178 lcdDrawNumber(MENU_DEBUG_COL1_OFS, MENU_DEBUG_ROW4, charsWritten, LEFT);
179 lcdDrawText(lcdLastRightPos, MENU_DEBUG_ROW4, " ");
180 lcdDrawNumber(lcdLastRightPos, MENU_DEBUG_ROW4, APP_Rx_ptr_in, LEFT);
181 lcdDrawText(lcdLastRightPos, MENU_DEBUG_ROW4, " ");
182 lcdDrawNumber(lcdLastRightPos, MENU_DEBUG_ROW4, APP_Rx_ptr_out, LEFT);
183 lcdDrawText(lcdLastRightPos, MENU_DEBUG_ROW4, " ");
184 lcdDrawNumber(lcdLastRightPos, MENU_DEBUG_ROW4, usbWraps, LEFT);
185 #endif
187 lcdDrawTextAlignedLeft(MENU_DEBUG_ROW5, STR_FREESTACKMINB);
188 lcdDrawText(MENU_DEBUG_COL1_OFS, MENU_DEBUG_ROW5+1, "[M]", SMLSIZE);
189 lcdDrawNumber(lcdLastRightPos, MENU_DEBUG_ROW5, menusStack.available(), LEFT);
190 lcdDrawText(lcdLastRightPos+2, MENU_DEBUG_ROW5+1, "[X]", SMLSIZE);
191 lcdDrawNumber(lcdLastRightPos, MENU_DEBUG_ROW5, mixerStack.available(), LEFT);
192 lcdDrawText(lcdLastRightPos+2, MENU_DEBUG_ROW5+1, "[A]", SMLSIZE);
193 lcdDrawNumber(lcdLastRightPos, MENU_DEBUG_ROW5, audioStack.available(), LEFT);
194 lcdDrawText(lcdLastRightPos+2, MENU_DEBUG_ROW5+1, "[I]", SMLSIZE);
195 lcdDrawNumber(lcdLastRightPos, MENU_DEBUG_ROW5, stackAvailable(), LEFT);
197 lcdDrawText(3*FW, 7*FH+1, STR_MENUTORESET);
198 lcdInvertLastLine();
201 void menuStatisticsDebug2(event_t event)
203 TITLE(STR_MENUDEBUG);
205 switch(event)
210 case EVT_KEY_FIRST(KEY_UP):
211 case EVT_KEY_BREAK(KEY_PAGE):
212 #if defined(DEBUG_TRACE_BUFFER)
213 chainMenu(menuTraceBuffer);
214 #else
215 chainMenu(menuStatisticsView);
216 #endif
217 return;
219 case EVT_KEY_FIRST(KEY_DOWN):
220 case EVT_KEY_LONG(KEY_PAGE):
221 killEvents(event);
222 chainMenu(menuStatisticsDebug);
223 break;
226 case EVT_KEY_FIRST(KEY_EXIT):
227 chainMenu(menuMainView);
228 break;
230 case EVT_KEY_LONG(KEY_ENTER):
231 telemetryErrors = 0;
232 break;
235 // UART statistics
236 lcdDrawTextAlignedLeft(MENU_DEBUG_ROW1, "Tlm RX Err");
237 lcdDrawNumber(MENU_DEBUG_COL1_OFS, MENU_DEBUG_ROW1, telemetryErrors, RIGHT);
240 lcdDrawText(3*FW, 7*FH+1, STR_MENUTORESET);
241 lcdInvertLastLine();
244 #if defined(DEBUG_TRACE_BUFFER)
245 void menuTraceBuffer(event_t event)
247 switch(event)
249 case EVT_KEY_LONG(KEY_ENTER):
250 dumpTraceBuffer();
251 killEvents(event);
252 break;
254 case EVT_KEY_FIRST(KEY_DOWN):
255 case EVT_KEY_LONG(KEY_PAGE):
256 killEvents(event);
257 chainMenu(menuStatisticsDebug2);
258 break;
260 case EVT_KEY_FIRST(KEY_UP):
261 case EVT_KEY_BREAK(KEY_PAGE):
262 chainMenu(menuStatisticsView);
263 return;
266 SIMPLE_SUBMENU("Trace Buffer", TRACE_BUFFER_LEN);
267 /* RTC time */
268 drawRtcTime(LCD_W+1, 0, LEFT|TIMEBLINK);
270 uint8_t y = 0;
271 uint8_t k = 0;
272 int8_t sub = menuVerticalPosition;
274 lcdDrawChar(0, FH, '#');
275 lcdDrawText(4*FW, FH, "Time");
276 lcdDrawText(14*FW, FH, "Event");
277 lcdDrawText(20*FW, FH, "Data");
279 for (uint8_t i=0; i<LCD_LINES-2; i++) {
280 y = 1 + (i+2)*FH;
281 k = i+menuVerticalOffset;
283 //item
284 lcdDrawNumber(0, y, k, LEFT | (sub==k ? INVERS : 0));
286 const struct TraceElement * te = getTraceElement(k);
287 if (te) {
288 //time
289 putstime_t tme = te->time % SECS_PER_DAY;
290 drawTimer(4*FW, y, tme, TIMEHOUR|LEFT, TIMEHOUR|LEFT);
291 //event
292 lcdDrawNumber(14*FW, y, te->event, LEADING0|LEFT, 3);
293 //data
294 lcdDrawSizedText (20*FW, y, "0x", 2);
295 lcdDrawHexNumber(22*FW-2, y, (uint16_t)(te->data >> 16));
296 lcdDrawHexNumber(25*FW, y, (uint16_t)(te->data & 0xFFFF));
303 #endif //#if defined(DEBUG_TRACE_BUFFER)