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.
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
)
34 case EVT_KEY_FIRST(KEY_UP
):
35 case EVT_KEY_BREAK(KEY_PAGE
):
36 chainMenu(menuStatisticsDebug
);
39 case EVT_KEY_FIRST(KEY_DOWN
):
40 case EVT_KEY_LONG(KEY_PAGE
):
42 #if defined(DEBUG_TRACE_BUFFER)
43 chainMenu(menuTraceBuffer
);
45 chainMenu(menuStatisticsDebug2
);
49 case EVT_KEY_LONG(KEY_MENU
): // historical
50 case EVT_KEY_LONG(KEY_ENTER
):
51 g_eeGeneral
.globalTimer
= 0;
52 storageDirty(EE_GENERAL
);
56 case EVT_KEY_FIRST(KEY_EXIT
):
57 chainMenu(menuMainView
);
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);
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);
79 drawTimer(STATS_3RD_COLUMN
+ STATS_LABEL_WIDTH
, FH
*i
+1, timersStates
[i
].val
, 0, 0);
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
);
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)
113 // do a user requested watchdog test
114 TRACE("Performing watchdog test");
121 case EVT_KEY_LONG(KEY_ENTER
):
122 g_eeGeneral
.globalTimer
= 0;
123 storageDirty(EE_GENERAL
);
127 case EVT_KEY_FIRST(KEY_ENTER
):
132 maxMixerDuration
= 0;
135 case EVT_KEY_FIRST(KEY_DOWN
):
136 case EVT_KEY_LONG(KEY_PAGE
):
138 chainMenu(menuStatisticsView
);
141 case EVT_KEY_FIRST(KEY_UP
):
142 case EVT_KEY_BREAK(KEY_PAGE
):
143 chainMenu(menuStatisticsDebug2
);
146 case EVT_KEY_FIRST(KEY_EXIT
):
147 chainMenu(menuMainView
);
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);
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");
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
);
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
);
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
);
201 void menuStatisticsDebug2(event_t event
)
203 TITLE(STR_MENUDEBUG
);
210 case EVT_KEY_FIRST(KEY_UP
):
211 case EVT_KEY_BREAK(KEY_PAGE
):
212 #if defined(DEBUG_TRACE_BUFFER)
213 chainMenu(menuTraceBuffer
);
215 chainMenu(menuStatisticsView
);
219 case EVT_KEY_FIRST(KEY_DOWN
):
220 case EVT_KEY_LONG(KEY_PAGE
):
222 chainMenu(menuStatisticsDebug
);
226 case EVT_KEY_FIRST(KEY_EXIT
):
227 chainMenu(menuMainView
);
230 case EVT_KEY_LONG(KEY_ENTER
):
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
);
244 #if defined(DEBUG_TRACE_BUFFER)
245 void menuTraceBuffer(event_t event
)
249 case EVT_KEY_LONG(KEY_ENTER
):
254 case EVT_KEY_FIRST(KEY_DOWN
):
255 case EVT_KEY_LONG(KEY_PAGE
):
257 chainMenu(menuStatisticsDebug2
);
260 case EVT_KEY_FIRST(KEY_UP
):
261 case EVT_KEY_BREAK(KEY_PAGE
):
262 chainMenu(menuStatisticsView
);
266 SIMPLE_SUBMENU("Trace Buffer", TRACE_BUFFER_LEN
);
268 drawRtcTime(LCD_W
+1, 0, LEFT
|TIMEBLINK
);
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
++) {
281 k
= i
+menuVerticalOffset
;
284 lcdDrawNumber(0, y
, k
, LEFT
| (sub
==k
? INVERS
: 0));
286 const struct TraceElement
* te
= getTraceElement(k
);
289 putstime_t tme
= te
->time
% SECS_PER_DAY
;
290 drawTimer(4*FW
, y
, tme
, TIMEHOUR
|LEFT
, TIMEHOUR
|LEFT
);
292 lcdDrawNumber(14*FW
, y
, te
->event
, LEADING0
|LEFT
, 3);
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)