From ccb4db4c701e91b58ec87cfcef1e41104f83859f Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Mon, 14 Mar 2016 18:56:55 +0100 Subject: [PATCH] [Horus] Draft for stats menu --- radio/src/gui/horus/bitmaps.cpp | 41 +++++ radio/src/gui/horus/bitmaps.h | 1 + radio/src/gui/horus/menus.h | 37 +++- radio/src/gui/horus/view_main.cpp | 6 +- radio/src/gui/horus/view_statistics.cpp | 216 ++++++++++++------------ 5 files changed, 188 insertions(+), 113 deletions(-) diff --git a/radio/src/gui/horus/bitmaps.cpp b/radio/src/gui/horus/bitmaps.cpp index b7b1ed918..cce2f0dfb 100644 --- a/radio/src/gui/horus/bitmaps.cpp +++ b/radio/src/gui/horus/bitmaps.cpp @@ -76,6 +76,47 @@ const uint8_t LBM_RSCALE[] = { #include "mask_rscale.lbm" }; +/* + * Stats / Debug menu bitmaps + */ + +const uint8_t LBM_STATS_ICON[] = { +#include "mask_stats.lbm" +}; + +const uint8_t LBM_STATS_GRAPH_ICON[] = { +#include "mask_stats_graph.lbm" +}; + +const uint8_t LBM_STATS_VALUE_ICON[] = { +#include "mask_stats_value.lbm" +}; + +const uint8_t LBM_STATS_TIME_ICON[] = { +#include "mask_stats_time.lbm" +}; + +const uint8_t LBM_STATS_LUA_ICON[] = { +#include "mask_stats_lua.lbm" +}; + +const uint8_t LBM_STATS_DEBUG_ICON[] = { +#include "mask_stats_debug.lbm" +}; + +const uint8_t * const LBM_STATS_ICONS[] = { + LBM_STATS_ICON, + LBM_STATS_GRAPH_ICON, + LBM_STATS_VALUE_ICON, + LBM_STATS_TIME_ICON, +#if defined(LUA) + LBM_STATS_LUA_ICON, +#endif +#if defined(DEBUG_TRACE_BUFFER) + LBM_STATS_DEBUG_ICON +#endif +}; + /* * Radio menu bitmaps */ diff --git a/radio/src/gui/horus/bitmaps.h b/radio/src/gui/horus/bitmaps.h index 96880401a..a520571a3 100644 --- a/radio/src/gui/horus/bitmaps.h +++ b/radio/src/gui/horus/bitmaps.h @@ -42,6 +42,7 @@ extern const uint8_t LBM_RSCALE[]; // Menu icons extern const uint8_t * const LBM_RADIO_ICONS[]; extern const uint8_t * const LBM_MODEL_ICONS[]; +extern const uint8_t * const LBM_STATS_ICONS[]; extern const uint8_t LBM_RADIO_ICON[]; extern const uint8_t LBM_SD_BROWSER_ICON[]; extern const uint8_t LBM_CALIBRATION_ICON[]; diff --git a/radio/src/gui/horus/menus.h b/radio/src/gui/horus/menus.h index 3cf440a82..c72d6f82f 100644 --- a/radio/src/gui/horus/menus.h +++ b/radio/src/gui/horus/menus.h @@ -144,14 +144,43 @@ static const MenuHandlerFunc menuTabGeneral[] PROGMEM = { menuGeneralVersion, }; +enum EnumTabDiag +{ + e_StatsGraph, + e_StatsValue, + e_StatsTime, +#if defined(LUA) + e_StatsLua, +#endif +#if defined(DEBUG_TRACE_BUFFER) + s_StatsDebug, +#endif +}; + +bool menuStatsGraph(evt_t event); +bool menuStatsValue(evt_t event); +bool menuStatsTime(evt_t event); +bool menuStatsLua(evt_t event); +bool menuStatsDebug(evt_t event); + +static const MenuHandlerFunc menuTabStats[] PROGMEM = { + menuStatsGraph, + menuStatsValue, + menuStatsTime, +#if defined(LUA) + menuStatsLua, +#endif +#if defined(DEBUG_TRACE_BUFFER) + menuStatsDebug, +#endif +}; + extern const MenuHandlerFunc menuTabScreensSetup[1+MAX_CUSTOM_SCREENS] PROGMEM; bool menuFirstCalib(evt_t event); bool menuMainView(evt_t event); bool menuCustomFunctions(evt_t event, CustomFunctionData * functions, CustomFunctionsContext & functionsContext); bool menuModelSelect(evt_t event); -bool menuStatisticsView(evt_t event); -bool menuStatisticsDebug(evt_t event); bool menuAboutView(evt_t event); bool menuMainViewChannelsMonitor(evt_t event); bool menuChannelsView(evt_t event); @@ -159,10 +188,6 @@ bool menuChannelsView(evt_t event); bool menuTextView(evt_t event); bool menuScreensTheme(evt_t event); -#if defined(DEBUG_TRACE_BUFFER) -void menuTraceBuffer(evt_t event); -#endif - typedef uint16_t FlightModesType; extern int8_t checkIncDec_Ret; // global helper vars diff --git a/radio/src/gui/horus/view_main.cpp b/radio/src/gui/horus/view_main.cpp index 7263b54ab..a7d6b8b02 100644 --- a/radio/src/gui/horus/view_main.cpp +++ b/radio/src/gui/horus/view_main.cpp @@ -108,7 +108,7 @@ void onMainViewMenu(const char *result) flightReset(); } else if (result == STR_STATISTICS) { - chainMenu(menuStatisticsView); + pushMenu(menuTabStats[0]); } else if (result == STR_SETUP_SCREENS) { pushMenu(menuTabScreensSetup[1]); @@ -155,12 +155,12 @@ bool menuMainView(evt_t event) break; case EVT_KEY_BREAK(KEY_MENU): - pushMenu(menuModelSetup); + pushMenu(menuTabModel[0]); break; case EVT_KEY_LONG(KEY_MENU): killEvents(event); - pushMenu(menuGeneralSetup); + pushMenu(menuTabGeneral[0]); break; case EVT_KEY_BREAK(KEY_DOWN): diff --git a/radio/src/gui/horus/view_statistics.cpp b/radio/src/gui/horus/view_statistics.cpp index d0e63dc52..475a2f1d6 100644 --- a/radio/src/gui/horus/view_statistics.cpp +++ b/radio/src/gui/horus/view_statistics.cpp @@ -18,40 +18,15 @@ * GNU General Public License for more details. */ -#include "../../opentx.h" +#include "opentx.h" +#include "stamp.h" -bool menuStatisticsView(evt_t event) +#define MENU_STATS_COLUMN1 (MENUS_MARGIN_LEFT + 120) + +bool menuStatsGraph(evt_t event) { - switch(event) { - case EVT_KEY_FIRST(KEY_UP): - chainMenu(menuStatisticsDebug); - return false; + MENU("Throttle graph", LBM_STATS_ICONS, menuTabStats, e_StatsGraph, 0, { 0 }); - case EVT_KEY_LONG(KEY_MENU): - g_eeGeneral.globalTimer = 0; - storageDirty(EE_GENERAL); - sessionTimer = 0; - break; - - case EVT_KEY_FIRST(KEY_EXIT): - chainMenu(menuMainView); - return false; - } - - drawScreenTemplate("Statistics", LBM_RADIO_ICON, OPTION_MENU_NO_SCROLLBAR); - - lcdDrawText( 10, MENU_CONTENT_TOP + FH*0, "\037\145TOT:\037\317BATT:", HEADER_COLOR); - lcdDrawText( 10, MENU_CONTENT_TOP + FH*1, "TM1:\037\145TM2:", HEADER_COLOR); - lcdDrawText( 10, MENU_CONTENT_TOP + FH*2, "THR:\037\145TH%:", HEADER_COLOR); - - putsTimer( 45, MENU_CONTENT_TOP + FH*1, timersStates[0].val); - putsTimer( 140, MENU_CONTENT_TOP + FH*1, timersStates[1].val); - putsTimer( 45, MENU_CONTENT_TOP + FH*2, s_timeCumThr); - putsTimer( 140, MENU_CONTENT_TOP + FH*2, s_timeCum16ThrP/16); - putsTimer( 140, MENU_CONTENT_TOP + FH*0, sessionTimer); - putsTimer( 250, MENU_CONTENT_TOP + 0*FH, g_eeGeneral.globalTimer+sessionTimer, TIMEHOUR); - -#if defined(THRTRACE) coord_t traceRd = (s_traceCnt < 0 ? s_traceWr : 0); const coord_t x = 4; const coord_t y = 200; @@ -67,19 +42,11 @@ bool menuStatisticsView(evt_t event) if (traceRd>=MAXTRACE) traceRd = 0; if (traceRd==s_traceWr) break; } -#endif return true; } -#define MENU_DEBUG_COL1_OFS (11*10-2) -#define MENU_DEBUG_Y_MIXMAX (MENU_CONTENT_TOP + 2*FH) -#define MENU_DEBUG_Y_LUA (MENU_CONTENT_TOP + 3*FH) -#define MENU_DEBUG_Y_FREE_RAM (MENU_CONTENT_TOP + 4*FH) -#define MENU_DEBUG_Y_STACK (MENU_CONTENT_TOP + 5*FH) -#define MENU_DEBUG_Y_RTOS (MENU_CONTENT_TOP + 6*FH) - -bool menuStatisticsDebug(evt_t event) +bool menuStatsValue(evt_t event) { switch(event) { @@ -92,63 +59,110 @@ bool menuStatisticsDebug(evt_t event) break; case EVT_KEY_FIRST(KEY_ENTER): -#if defined(LUA) - maxLuaInterval = 0; - maxLuaDuration = 0; -#endif maxMixerDuration = 0; AUDIO_KEYPAD_UP(); break; - -#if defined(DEBUG_TRACE_BUFFER) - case EVT_KEY_FIRST(KEY_UP): - pushMenu(menuTraceBuffer); - return false; -#endif - - case EVT_KEY_FIRST(KEY_DOWN): - chainMenu(menuStatisticsView); - return false; - - case EVT_KEY_FIRST(KEY_EXIT): - chainMenu(menuMainView); - return false; } - drawScreenTemplate(STR_MENUDEBUG, LBM_RADIO_ICON, OPTION_MENU_NO_SCROLLBAR); + MENU("Values", LBM_STATS_ICONS, menuTabStats, e_StatsValue, 0, { 0 }); - lcdDrawText(MENUS_MARGIN_LEFT, MENU_DEBUG_Y_FREE_RAM, "Free Mem"); - lcdDrawNumber(MENU_DEBUG_COL1_OFS, MENU_DEBUG_Y_FREE_RAM, availableMemory(), LEFT, 0, NULL, "b"); + lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP, "Free Mem"); + lcdDrawNumber(MENU_STATS_COLUMN1, MENU_CONTENT_TOP, availableMemory(), LEFT, 0, NULL, "b"); -#if defined(LUA) - lcdDrawText(MENUS_MARGIN_LEFT, MENU_DEBUG_Y_LUA, "Lua scripts"); - lcdDrawText(MENU_DEBUG_COL1_OFS, MENU_DEBUG_Y_LUA+1, "[Duration]", HEADER_COLOR|SMLSIZE); - lcdDrawNumber(MENU_DEBUG_COL1_OFS+30, MENU_DEBUG_Y_LUA, 10*maxLuaDuration, LEFT); - lcdDrawText(MENU_DEBUG_COL1_OFS+60, MENU_DEBUG_Y_LUA+1, "[Interval]", HEADER_COLOR|SMLSIZE); - lcdDrawNumber(MENU_DEBUG_COL1_OFS+90, MENU_DEBUG_Y_LUA, 10*maxLuaInterval, LEFT); -#endif + lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP+FH, STR_TMIXMAXMS); + lcdDrawNumber(MENU_STATS_COLUMN1, MENU_CONTENT_TOP+FH, DURATION_MS_PREC2(maxMixerDuration), PREC2|LEFT, 0, NULL, "ms"); - lcdDrawText(MENUS_MARGIN_LEFT, MENU_DEBUG_Y_MIXMAX, STR_TMIXMAXMS); - lcdDrawNumber(MENU_DEBUG_COL1_OFS, MENU_DEBUG_Y_MIXMAX, DURATION_MS_PREC2(maxMixerDuration), PREC2|LEFT, 0, NULL, "ms"); + lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP+2*FH, STR_FREESTACKMINB); + lcdDrawText(MENU_STATS_COLUMN1, MENU_CONTENT_TOP+2*FH+1, "[Menus]", HEADER_COLOR|SMLSIZE); + lcdDrawNumber(lcdNextPos+5, MENU_CONTENT_TOP+2*FH, menusStack.available(), LEFT); + lcdDrawText(lcdNextPos+20, MENU_CONTENT_TOP+2*FH+1, "[Mix]", HEADER_COLOR|SMLSIZE); + lcdDrawNumber(lcdNextPos+5, MENU_CONTENT_TOP+2*FH, mixerStack.available(), LEFT); + lcdDrawText(lcdNextPos+20, MENU_CONTENT_TOP+2*FH+1, "[Audio]", HEADER_COLOR|SMLSIZE); + lcdDrawNumber(lcdNextPos+5, MENU_CONTENT_TOP+2*FH, audioStack.available(), LEFT); - lcdDrawText(MENUS_MARGIN_LEFT, MENU_DEBUG_Y_RTOS, STR_FREESTACKMINB); - lcdDrawText(MENU_DEBUG_COL1_OFS, MENU_DEBUG_Y_RTOS+1, "[Menus]", HEADER_COLOR|SMLSIZE); - lcdDrawNumber(MENU_DEBUG_COL1_OFS+30, MENU_DEBUG_Y_RTOS, menusStack.available(), LEFT); - lcdDrawText(MENU_DEBUG_COL1_OFS+60, MENU_DEBUG_Y_RTOS+1, "[Mix]", HEADER_COLOR|SMLSIZE); - lcdDrawNumber(MENU_DEBUG_COL1_OFS+90, MENU_DEBUG_Y_RTOS, mixerStack.available(), LEFT); - lcdDrawText(MENU_DEBUG_COL1_OFS+120, MENU_DEBUG_Y_RTOS+1, "[Audio]", HEADER_COLOR|SMLSIZE); - lcdDrawNumber(MENU_DEBUG_COL1_OFS+150, MENU_DEBUG_Y_RTOS, audioStack.available(), LEFT); - - // TODO lcd_putsCenter(7*FH+1, STR_MENUTORESET); - // lcdInvertLastLine(); + lcdDrawText(LCD_W/2, MENU_FOOTER_TOP+2, STR_MENUTORESET, CENTERED); return true; } -#if defined(DEBUG_TRACE_BUFFER) -#include "stamp-opentx.h" +bool menuStatsTime(evt_t event) +{ + switch(event) { + case EVT_KEY_LONG(KEY_MENU): + g_eeGeneral.globalTimer = 0; + storageDirty(EE_GENERAL); + sessionTimer = 0; + break; + } -bool menuTraceBuffer(evt_t event) + MENU("Time Stats", LBM_STATS_ICONS, menuTabStats, e_StatsTime, 0, { 0 }); + + lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP, "Session", HEADER_COLOR); + putsTimer(MENU_STATS_COLUMN1, MENU_CONTENT_TOP, sessionTimer, TIMEHOUR); + + lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP+FH, "Battery", HEADER_COLOR); + putsTimer(MENU_STATS_COLUMN1, MENU_CONTENT_TOP+FH, g_eeGeneral.globalTimer+sessionTimer, TIMEHOUR); + + lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP+2*FH, "Timer1", HEADER_COLOR); + putsTimer(MENU_STATS_COLUMN1, MENU_CONTENT_TOP+2*FH, timersStates[0].val); + + lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP+3*FH, "Timer2", HEADER_COLOR); + putsTimer(MENU_STATS_COLUMN1, MENU_CONTENT_TOP+3*FH, timersStates[2].val); + + lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP+4*FH, "Timer3", HEADER_COLOR); + putsTimer(MENU_STATS_COLUMN1, MENU_CONTENT_TOP+4*FH, timersStates[3].val); + + lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP+5*FH, "Throttle", HEADER_COLOR); + putsTimer(MENU_STATS_COLUMN1, MENU_CONTENT_TOP+5*FH, s_timeCumThr); + + lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP+6*FH, "Throttle %", HEADER_COLOR); + putsTimer(MENU_STATS_COLUMN1, MENU_CONTENT_TOP+6*FH, s_timeCum16ThrP/16); + + return true; +} + +#if defined(LUA) +bool menuStatsLua(evt_t event) +{ + switch(event) + { + case EVT_KEY_LONG(KEY_ENTER): + g_eeGeneral.globalTimer = 0; + storageDirty(EE_GENERAL); + sessionTimer = 0; + killEvents(event); + AUDIO_KEYPAD_UP(); + break; + + case EVT_KEY_FIRST(KEY_ENTER): + maxLuaInterval = 0; + maxLuaDuration = 0; + AUDIO_KEYPAD_UP(); + break; + } + + MENU("LUA", LBM_STATS_ICONS, menuTabStats, e_StatsLua, 0, { 0 }); + + lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP, "Free Mem"); + lcdDrawNumber(MENU_STATS_COLUMN1, MENU_CONTENT_TOP, availableMemory(), LEFT, 0, NULL, "b"); + + lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP+FH, "Duration"); + lcdDrawNumber(MENU_STATS_COLUMN1, MENU_CONTENT_TOP+FH, 10*maxLuaDuration, LEFT, 0, NULL, "ms"); + + lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP+2*FH, "Interval"); + lcdDrawNumber(MENU_STATS_COLUMN1, MENU_CONTENT_TOP+2*FH, 10*maxLuaInterval, LEFT, 0, NULL, "ms"); + + return true; +} +#endif + +#if defined(DEBUG_TRACE_BUFFER) +#define STATS_TRACES_INDEX_POS MENUS_MARGIN_LEFT +#define STATS_TRACES_TIME_POS MENUS_MARGIN_LEFT + 4*10 +#define STATS_TRACES_EVENT_POS MENUS_MARGIN_LEFT + 14*10 +#define STATS_TRACES_DATA_POS MENUS_MARGIN_LEFT + 20*10 + +bool menuStatsDebug(evt_t event) { switch(event) { @@ -158,40 +172,34 @@ bool menuTraceBuffer(evt_t event) break; } - SIMPLE_SUBMENU("Trace Buffer " VERSION, TRACE_BUFFER_LEN); + SIMPLE_MENU("", LBM_STATS_ICONS, menuTabStats, s_StatsDebug, TRACE_BUFFER_LEN); - /* RTC time */ - struct gtm t; - gettime(&t); - putsTime(LCD_W+1, 0, t, TIMEBLINK); - - uint8_t y = 0; uint8_t k = 0; int8_t sub = menuVerticalPosition; - lcdDrawChar(0, FH, '#', TEXT_COLOR); - lcdDrawText(4*10, FH, "Time"); - lcdDrawText(14*10, FH, "Event"); - lcdDrawText(20*10, FH, "Data"); + lcdDrawChar(STATS_TRACES_INDEX_POS, MENU_TITLE_TOP+2, '#', MENU_TITLE_COLOR); + lcdDrawText(STATS_TRACES_TIME_POS, MENU_TITLE_TOP+2, "Time", MENU_TITLE_COLOR); + lcdDrawText(STATS_TRACES_EVENT_POS, MENU_TITLE_TOP+2, "Event", MENU_TITLE_COLOR); + lcdDrawText(STATS_TRACES_DATA_POS, MENU_TITLE_TOP+2, "Data", MENU_TITLE_COLOR); for (uint8_t i=0; itime % SECS_PER_DAY; - putsTimer(4*10, y, tme, TIMEHOUR|LEFT); - //event - lcdDrawNumber(14*10, y, te->event, LEADING0|LEFT, 3); - //data - lcdDrawSizedText (20*10, y, "0x", 2); - lcdDrawHexNumber(22*10-2, y, (uint16_t)(te->data >> 16)); - lcdDrawHexNumber(25*10, y, (uint16_t)(te->data & 0xFFFF)); + putsTimer(STATS_TRACES_TIME_POS, y, tme, TIMEHOUR|LEFT); + // event + lcdDrawNumber(STATS_TRACES_EVENT_POS, y, te->event, LEADING0|LEFT, 3); + // data + lcdDrawSizedText(STATS_TRACES_DATA_POS, y, "0x", 2); + lcdDrawHexNumber(STATS_TRACES_DATA_POS + 20, y, (uint16_t)(te->data >> 16)); + lcdDrawHexNumber(STATS_TRACES_DATA_POS+ 60, y, (uint16_t)(te->data & 0xFFFF)); } }