X7 and X9E have been left out ! (#5199)
[opentx.git] / radio / src / gui / 212x64 / view_statistics.cpp
blobd8b1d5bd6d87a471c00ee493e8586fae0b1392fb
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_FIRST(KEY_MENU):
36 chainMenu(menuStatisticsDebug);
37 break;
39 case EVT_KEY_LONG(KEY_MENU):
40 g_eeGeneral.globalTimer = 0;
41 storageDirty(EE_GENERAL);
42 sessionTimer = 0;
43 break;
45 case EVT_KEY_FIRST(KEY_EXIT):
46 chainMenu(menuMainView);
47 break;
50 // Session and Total timers
51 lcdDrawText(STATS_1ST_COLUMN, FH*1+1, "SES", BOLD);
52 drawTimer(STATS_1ST_COLUMN + STATS_LABEL_WIDTH, FH*1+1, sessionTimer, 0, 0);
53 lcdDrawText(STATS_1ST_COLUMN, FH*2+1, "TOT", BOLD);
54 drawTimer(STATS_1ST_COLUMN + STATS_LABEL_WIDTH, FH*2+1, g_eeGeneral.globalTimer + sessionTimer, TIMEHOUR, 0);
56 // Throttle special timers
57 lcdDrawText(STATS_2ND_COLUMN, FH*0+1, "THR", BOLD);
58 drawTimer(STATS_2ND_COLUMN + STATS_LABEL_WIDTH, FH*0+1, s_timeCumThr, 0, 0);
59 lcdDrawText(STATS_2ND_COLUMN, FH*1+1, "TH%", BOLD);
60 drawTimer(STATS_2ND_COLUMN + STATS_LABEL_WIDTH, FH*1+1, s_timeCum16ThrP/16, 0, 0);
62 // Timers
63 for (int i=0; i<TIMERS; i++) {
64 drawStringWithIndex(STATS_3RD_COLUMN, FH*i+1, "TM", i+1, BOLD);
65 if (timersStates[i].val > 3600)
66 drawTimer(STATS_3RD_COLUMN + STATS_LABEL_WIDTH, FH*i+1, timersStates[i].val, TIMEHOUR, 0);
67 else
68 drawTimer(STATS_3RD_COLUMN + STATS_LABEL_WIDTH, FH*i+1, timersStates[i].val, 0, 0);
71 #if defined(THRTRACE)
72 const coord_t x = 5;
73 const coord_t y = 60;
74 lcdDrawSolidHorizontalLine(x-3, y, MAXTRACE+3+3);
75 lcdDrawSolidVerticalLine(x, y-32, 32+3);
76 for (coord_t i=0; i<MAXTRACE; i+=6) {
77 lcdDrawSolidVerticalLine(x+i+6, y-1, 3);
80 uint16_t traceRd = s_traceWr > MAXTRACE ? s_traceWr - MAXTRACE : 0;
81 for (coord_t i=1; i<=MAXTRACE && traceRd<s_traceWr; i++, traceRd++) {
82 uint8_t h = s_traceBuf[traceRd % MAXTRACE];
83 lcdDrawSolidVerticalLine(x+i, y-h, h);
85 #endif
88 #define MENU_DEBUG_COL1_OFS (11*FW-2)
89 #define MENU_DEBUG_Y_MIXMAX (2*FH-3)
90 #define MENU_DEBUG_Y_LUA (3*FH-2)
91 #define MENU_DEBUG_Y_FREE_RAM (4*FH-1)
92 #define MENU_DEBUG_Y_USB (5*FH)
93 #define MENU_DEBUG_Y_RTOS (6*FH)
95 #if defined(USB_SERIAL)
96 extern uint16_t usbWraps;
97 extern uint16_t charsWritten;
98 extern "C" volatile uint32_t APP_Rx_ptr_in;
99 extern "C" volatile uint32_t APP_Rx_ptr_out;
100 #endif
102 void menuStatisticsDebug(event_t event)
104 TITLE(STR_MENUDEBUG);
106 #if defined(WATCHDOG_TEST)
107 if (warningResult) {
108 warningResult = 0;
109 // do a user requested watchdog test
110 TRACE("Performing watchdog test");
111 pausePulses();
113 #endif
115 switch(event)
117 case EVT_KEY_LONG(KEY_ENTER):
118 g_eeGeneral.globalTimer = 0;
119 storageDirty(EE_GENERAL);
120 sessionTimer = 0;
121 killEvents(event);
122 break;
123 case EVT_KEY_FIRST(KEY_ENTER):
124 #if defined(LUA)
125 maxLuaInterval = 0;
126 maxLuaDuration = 0;
127 #endif
128 maxMixerDuration = 0;
129 break;
131 #if defined(DEBUG_TRACE_BUFFER)
132 case EVT_KEY_FIRST(KEY_UP):
133 pushMenu(menuTraceBuffer);
134 return;
135 #endif
137 case EVT_KEY_FIRST(KEY_DOWN):
138 chainMenu(menuStatisticsView);
139 break;
140 case EVT_KEY_FIRST(KEY_EXIT):
141 chainMenu(menuMainView);
142 break;
143 #if defined(WATCHDOG_TEST)
144 case EVT_KEY_LONG(KEY_MENU):
146 POPUP_CONFIRMATION("Test the watchdog?");
147 const char * w = "The radio will reset!";
148 SET_WARNING_INFO(w, strlen(w), 0);
150 break;
151 #endif
154 lcdDrawTextAlignedLeft(MENU_DEBUG_Y_FREE_RAM, "Free Mem");
155 lcdDrawNumber(MENU_DEBUG_COL1_OFS, MENU_DEBUG_Y_FREE_RAM, availableMemory(), LEFT);
156 lcdDrawText(lcdLastRightPos, MENU_DEBUG_Y_FREE_RAM, "b");
158 #if defined(LUA)
159 lcdDrawTextAlignedLeft(MENU_DEBUG_Y_LUA, "Lua scripts");
160 lcdDrawText(MENU_DEBUG_COL1_OFS, MENU_DEBUG_Y_LUA+1, "[Duration]", SMLSIZE);
161 lcdDrawNumber(lcdLastRightPos, MENU_DEBUG_Y_LUA, 10*maxLuaDuration, LEFT);
162 lcdDrawText(lcdLastRightPos+2, MENU_DEBUG_Y_LUA+1, "[Interval]", SMLSIZE);
163 lcdDrawNumber(lcdLastRightPos, MENU_DEBUG_Y_LUA, 10*maxLuaInterval, LEFT);
164 #endif
166 lcdDrawTextAlignedLeft(MENU_DEBUG_Y_MIXMAX, STR_TMIXMAXMS);
167 lcdDrawNumber(MENU_DEBUG_COL1_OFS, MENU_DEBUG_Y_MIXMAX, DURATION_MS_PREC2(maxMixerDuration), PREC2|LEFT);
168 lcdDrawText(lcdLastRightPos, MENU_DEBUG_Y_MIXMAX, "ms");
170 #if !defined(SIMU) && defined(USB_SERIAL)
171 lcdDrawTextAlignedLeft(MENU_DEBUG_Y_USB, "Usb");
172 lcdDrawNumber(MENU_DEBUG_COL1_OFS, MENU_DEBUG_Y_USB, charsWritten, LEFT);
173 lcdDrawText(lcdLastRightPos, MENU_DEBUG_Y_USB, " ");
174 lcdDrawNumber(lcdLastRightPos, MENU_DEBUG_Y_USB, APP_Rx_ptr_in, LEFT);
175 lcdDrawText(lcdLastRightPos, MENU_DEBUG_Y_USB, " ");
176 lcdDrawNumber(lcdLastRightPos, MENU_DEBUG_Y_USB, APP_Rx_ptr_out, LEFT);
177 lcdDrawText(lcdLastRightPos, MENU_DEBUG_Y_USB, " ");
178 lcdDrawNumber(lcdLastRightPos, MENU_DEBUG_Y_USB, usbWraps, LEFT);
179 #endif
181 lcdDrawTextAlignedLeft(MENU_DEBUG_Y_RTOS, STR_FREESTACKMINB);
182 lcdDrawText(MENU_DEBUG_COL1_OFS, MENU_DEBUG_Y_RTOS+1, "[M]", SMLSIZE);
183 lcdDrawNumber(lcdLastRightPos, MENU_DEBUG_Y_RTOS, menusStack.available(), LEFT);
184 lcdDrawText(lcdLastRightPos+2, MENU_DEBUG_Y_RTOS+1, "[X]", SMLSIZE);
185 lcdDrawNumber(lcdLastRightPos, MENU_DEBUG_Y_RTOS, mixerStack.available(), LEFT);
186 lcdDrawText(lcdLastRightPos+2, MENU_DEBUG_Y_RTOS+1, "[A]", SMLSIZE);
187 lcdDrawNumber(lcdLastRightPos, MENU_DEBUG_Y_RTOS, audioStack.available(), LEFT);
188 lcdDrawText(lcdLastRightPos+2, MENU_DEBUG_Y_RTOS+1, "[I]", SMLSIZE);
189 lcdDrawNumber(lcdLastRightPos, MENU_DEBUG_Y_RTOS, stackAvailable(), LEFT);
191 lcdDrawText(3*FW, 7*FH+1, STR_MENUTORESET);
192 lcdInvertLastLine();
196 #if defined(DEBUG_TRACE_BUFFER)
197 void menuTraceBuffer(event_t event)
199 switch(event)
201 case EVT_KEY_LONG(KEY_ENTER):
202 dumpTraceBuffer();
203 killEvents(event);
204 break;
207 SIMPLE_SUBMENU("Trace Buffer", TRACE_BUFFER_LEN);
208 /* RTC time */
209 drawRtcTime(LCD_W+1, 0, LEFT|TIMEBLINK);
211 uint8_t y = 0;
212 uint8_t k = 0;
213 int8_t sub = menuVerticalPosition;
215 lcdDrawChar(0, FH, '#');
216 lcdDrawText(4*FW, FH, "Time");
217 lcdDrawText(14*FW, FH, "Event");
218 lcdDrawText(20*FW, FH, "Data");
220 for (uint8_t i=0; i<LCD_LINES-2; i++) {
221 y = 1 + (i+2)*FH;
222 k = i+menuVerticalOffset;
224 //item
225 lcdDrawNumber(0, y, k, LEFT | (sub==k ? INVERS : 0));
227 const struct TraceElement * te = getTraceElement(k);
228 if (te) {
229 //time
230 putstime_t tme = te->time % SECS_PER_DAY;
231 drawTimer(4*FW, y, tme, TIMEHOUR|LEFT, TIMEHOUR|LEFT);
232 //event
233 lcdDrawNumber(14*FW, y, te->event, LEADING0|LEFT, 3);
234 //data
235 lcdDrawSizedText (20*FW, y, "0x", 2);
236 lcdDrawHexNumber(22*FW-2, y, (uint16_t)(te->data >> 16));
237 lcdDrawHexNumber(25*FW, y, (uint16_t)(te->data & 0xFFFF));
244 #endif //#if defined(DEBUG_TRACE_BUFFER)