From 0a410fe33672c017439961a0cb6799bd16d25124 Mon Sep 17 00:00:00 2001 From: vk7js <58905135+vk7js@users.noreply.github.com> Date: Fri, 13 May 2022 15:01:27 +1000 Subject: [PATCH] Speak only when values change Changed the function which determines if we should speak the new menu item to make it also check if a menu item's value changes. --- openrtx/src/ui/ui.c | 2 ++ openrtx/src/ui/ui_menu.c | 42 +++++++++++++++++++++++++++++----------- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/openrtx/src/ui/ui.c b/openrtx/src/ui/ui.c index 905ebcb2..76253bcf 100644 --- a/openrtx/src/ui/ui.c +++ b/openrtx/src/ui/ui.c @@ -1077,6 +1077,8 @@ void ui_updateFSM(bool *sync_rtx) ui_state.last_main_state = state.ui_screen; // Open Menu state.ui_screen = MENU_TOP; + // TODO: announce the menu name. + // The selected item will be announced when the item is first selected. } else if(msg.keys & KEY_ESC) { diff --git a/openrtx/src/ui/ui_menu.c b/openrtx/src/ui/ui_menu.c index c9cb84d4..d4407df5 100644 --- a/openrtx/src/ui/ui_menu.c +++ b/openrtx/src/ui/ui_menu.c @@ -33,7 +33,10 @@ /* UI main screen helper functions, their implementation is in "ui_main.c" */ extern void _ui_drawMainBottom(); -static int priorMenuIndex = -1; + +static char priorSelectedMenuName[21] = "\0"; +static char priorSelectedMenuValue[21] = "\0"; + const char *display_timer_values[] = { "Off", @@ -54,21 +57,38 @@ const char *display_timer_values[] = "1 hour" }; -bool DidSelectedMenuItemChange(uint8_t index) -{ - if (priorMenuIndex == -1) +bool DidSelectedMenuItemChange(char* menuName, char* menuValue) +{// menu name can't be empty. + if (!menuName || !*menuName) + return false; + // If value is supplied it can't be empty but it does not have to be supplied. + if (menuValue && !*menuValue) + return false; + + if (strcmp(menuName, priorSelectedMenuName) != 0) + { + strcpy(priorSelectedMenuName, menuName); + if (menuValue) + strcpy(priorSelectedMenuValue, menuValue); + return true; - bool result = index != priorMenuIndex; - priorMenuIndex = index; - return result; + } + + if (menuValue && strcmp(menuValue, priorSelectedMenuValue) != 0) + { + strcpy(priorSelectedMenuValue, menuValue); + return true; + } + + return false; } -static void announceMenuItemIfNeeded(uint8_t index, char* name, char* value) +static void announceMenuItemIfNeeded(char* name, char* value) { if (!name || !*name) return; - if (!DidSelectedMenuItemChange(index)) + if (!DidSelectedMenuItemChange(name, value)) return; announceText(name, vpqInit); @@ -103,7 +123,7 @@ void _ui_drawMenuList(uint8_t selected, int (*getCurrentEntry)(char *buf, uint8_ // Draw rectangle under selected item, compensating for text height point_t rect_pos = {0, pos.y - layout.menu_h + 3}; gfx_drawRect(rect_pos, SCREEN_WIDTH, layout.menu_h, color_white, true); - announceMenuItemIfNeeded(item+scroll, entry_buf, NULL); + announceMenuItemIfNeeded(entry_buf, NULL); } gfx_print(pos, layout.menu_font, TEXT_ALIGN_LEFT, text_color, entry_buf); pos.y += layout.menu_h; @@ -150,7 +170,7 @@ void _ui_drawMenuListValue(ui_state_t* ui_state, uint8_t selected, if (!ui_state->edit_mode) {// If in edit mode, only want to speak the char being entered,, //not repeat the entire display. - announceMenuItemIfNeeded(item+scroll, entry_buf, value_buf); + announceMenuItemIfNeeded(entry_buf, value_buf); } } gfx_print(pos, layout.menu_font, TEXT_ALIGN_LEFT, text_color, entry_buf);