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.
This commit is contained in:
vk7js 2022-05-13 15:01:27 +10:00 committed by Silvano Seva
parent 39cbfbe66f
commit 0a410fe336
2 changed files with 33 additions and 11 deletions

View File

@ -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)
{

View File

@ -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);