From a437bcf8b5a1c7d819702cbe02a3b5ff6b143bb7 Mon Sep 17 00:00:00 2001 From: Brent Perteet Date: Thu, 29 May 2025 13:12:29 -0500 Subject: [PATCH] Refactored menu working --- .settings/language.settings.xml | 4 ++-- source/keys.h | 1 + source/main.c | 5 ++++- source/menu.c | 31 ++++++++++++++++++++++++++++--- source/timer.c | 18 +++++++++--------- source/timer.h | 2 +- 6 files changed, 45 insertions(+), 16 deletions(-) diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml index 00fcf06..f068d2b 100644 --- a/.settings/language.settings.xml +++ b/.settings/language.settings.xml @@ -4,7 +4,7 @@ - + @@ -15,7 +15,7 @@ - + diff --git a/source/keys.h b/source/keys.h index 9646062..ad1e4d6 100644 --- a/source/keys.h +++ b/source/keys.h @@ -55,6 +55,7 @@ #endif //Menu Press Functions +#define KEY_HOME KEY0 #define KEY_BACK KEY1 //Cancel / Back in menu #define KEY_UP KEY2 //Up in menu #define KEY_DOWN KEY3 //Down in menu diff --git a/source/main.c b/source/main.c index a258725..694fd00 100644 --- a/source/main.c +++ b/source/main.c @@ -255,7 +255,7 @@ uint32_t tmp; KEY_Update(); - + Tx_TimeOut(); // Check main transmitter timer #if !BYPASS_USB_SAFETY @@ -398,6 +398,9 @@ uint32_t tmp; } + + + } diff --git a/source/menu.c b/source/menu.c index 3acac0a..3031839 100644 --- a/source/menu.c +++ b/source/menu.c @@ -81,14 +81,18 @@ extern uint8_t Port_State[]; extern HARDWARE_FIX_t hwf; extern uint32_t systemTime; +MenuItem_t _menuItems[50]; + /******************************************************************************* * Static Function Declarations ******************************************************************************/ - static Menu_t* getNewMenu(MenuHandler_t handler); +static Menu_t* getNewMenu(MenuHandler_t handler); +static Menu_t* getCurrentMenu(void); static int handleSystemInfoMenu(Menu_t *menu); +static int handleAutoShutdown(Menu_t *menu); static void ClearMenuItems(MenuItem_t items[], uint32_t num); @@ -137,6 +141,7 @@ static void createMenuItem(MenuItemId_t id, MenuItem_t *item) { item->pMonoIcon = 0; strcpy(item->text, "Auto Shutdown"); + item->handler = handleAutoShutdown; break; } @@ -191,6 +196,11 @@ static void handleUpDown(uint32_t pressed, Menu_t *menu) switch(pressed) { + case KEY_HOME: + { + menu->exitCode = MENU_HOME; + break; + } case KEY_UP: { menu->selected--; @@ -244,6 +254,10 @@ static void drawScrollBar(Menu_t *menu) } +static Menu_t* getCurrentMenu(void) +{ + return &_menuData.menuStack[_menuData.stackCount-1]; +} static Menu_t* getNewMenu(MenuHandler_t handler) { @@ -268,6 +282,17 @@ static Menu_t* getNewMenu(MenuHandler_t handler) return menu; } +static int handleAutoShutdown(Menu_t *menu) +{ + // cycle through selections + tmr_ChangeAutoSDTimer(); + + menu = getCurrentMenu(); + + menu->draw = true; + +} + static int handleSystemInfoMenu(Menu_t *menu) { if (menu == NULL) @@ -397,7 +422,7 @@ static int handleMainMenu(Menu_t *menu) if (menu->items[menu->selected].handler != NULL) { menu->items[menu->selected].handler(NULL); - return MENU_OK; + //return MENU_OK; } } @@ -1501,7 +1526,7 @@ void Menu_service(void) if (_menuData.stackCount > 0) { - _menuData.currentMenu = &_menuData.menuStack[_menuData.stackCount-1]; + _menuData.currentMenu = getCurrentMenu(); _menuData.currentMenu->draw = true; } break; diff --git a/source/timer.c b/source/timer.c index d6cd005..36decef 100644 --- a/source/timer.c +++ b/source/timer.c @@ -70,9 +70,10 @@ uint32_t systemTime = 0; // 10mS ticks ******************************************************************************/ - +#define TIMER_SCALE 10 void ctimer_match0_callback(uint32_t flags) // ISR every 10mS { + int timerScaler = 0; static bool Test_Flg = false; if(Test_Flg) GPIO_PinWrite(GPIO, 0, 4, 1); //TODO remove @@ -81,12 +82,14 @@ void ctimer_match0_callback(uint32_t flags) // ISR every 10mS Test_Flg ^=1; - // Sys_Timer = 1000000; -// it goes here + systemTime++; // increment system time by 10mS Check_Live_Voltage(); - systemTime += 10; // increment system time by 10mS + if ((systemTime % TIMER_SCALE != 0)) + { + return; + } if (Sys_Timer > 0) Sys_Timer--; @@ -111,9 +114,6 @@ void ctimer_match0_callback(uint32_t flags) // ISR every 10mS if(Key_Lock_Out_tmr > 0) Key_Lock_Out_tmr--; - KEY_Update(); - - Tx_TimeOut(); // Check main transmitter timer if( Port_timer > 0) Port_timer--; // Port checking timer @@ -159,7 +159,7 @@ uint8_t i; /* Configuration 0 */ matchConfig0.enableCounterReset = true; matchConfig0.enableCounterStop = false; - matchConfig0.matchValue = 1500000;//150MHz clock 10mS period + matchConfig0.matchValue = 150000;//150MHz clock 10mS period matchConfig0.enableInterrupt = true; CTIMER_RegisterCallBack(CTIMER, &ctimer_callback_table[0], kCTIMER_MultipleCallback); @@ -210,7 +210,7 @@ void tmr_ChangeAutoSDTimer(void) tmr.autoShutdown = (AUTO_SHUTDOWN_t)0; } - Tx_timer = TX_TIME[i]; // reload the timer + Tx_timer = TX_TIME[tmr.autoShutdown]; // reload the timer } diff --git a/source/timer.h b/source/timer.h index 452ecfe..385b0de 100644 --- a/source/timer.h +++ b/source/timer.h @@ -16,7 +16,7 @@ #define TIME_7HR 7*TIME_1HR #define TIME_8HR 8*TIME_1HR #define TIME_9HR 9*TIME_1HR -#define TIME_0HR 10 +#define TIME_0HR 100 #define DELAY_5S 500 #define DELAY_1S 100 #define DELAY_2S 200