kopia lustrzana https://github.com/OpenRTX/OpenRTX
UI: Replaced strcmp with switch case to fix GPS/menu bug
rodzic
d8951e9eb2
commit
75c1f13882
|
@ -62,6 +62,50 @@ enum SetRxTx
|
|||
SET_TX
|
||||
};
|
||||
|
||||
// This enum is needed to have item numbers that match
|
||||
// menu elements even if some elements may be missing (GPS)
|
||||
enum menuItems
|
||||
{
|
||||
M_ZONE = 0,
|
||||
M_CHANNEL,
|
||||
M_CONTACTS,
|
||||
M_MESSAGES,
|
||||
#ifdef HAS_GPS
|
||||
M_GPS,
|
||||
#endif
|
||||
M_SETTINGS,
|
||||
M_INFO,
|
||||
M_ABOUT
|
||||
};
|
||||
|
||||
enum settingsItems
|
||||
{
|
||||
S_DISPLAY = 0,
|
||||
#ifdef HAS_RTC
|
||||
S_TIMEDATE
|
||||
#endif
|
||||
#ifdef HAS_GPS
|
||||
,S_GPS
|
||||
#endif
|
||||
};
|
||||
|
||||
enum displayItems
|
||||
{
|
||||
D_BRIGHTNESS = 0
|
||||
#ifdef SCREEN_CONTRAST
|
||||
,D_CONTRAST
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef HAS_GPS
|
||||
enum settingsGPSItems
|
||||
{
|
||||
G_ENABLED = 0,
|
||||
G_SET_TIME,
|
||||
G_TIMEZONE
|
||||
};
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Struct containing a set of positions and sizes that get
|
||||
* calculated for the selected display size.
|
||||
|
|
|
@ -120,10 +120,10 @@ const char *menu_items[] =
|
|||
|
||||
const char *settings_items[] =
|
||||
{
|
||||
"Display",
|
||||
#ifdef HAS_RTC
|
||||
"Time & Date",
|
||||
#endif
|
||||
"Display",
|
||||
#ifdef HAS_GPS
|
||||
"GPS"
|
||||
#endif
|
||||
|
@ -830,25 +830,32 @@ void ui_updateFSM(event_t event, bool *sync_rtx)
|
|||
_ui_menuDown(menu_num);
|
||||
else if(msg.keys & KEY_ENTER)
|
||||
{
|
||||
// Open selected menu item
|
||||
if(strcmp(menu_items[ui_state.menu_selected], "Zone") == 0)
|
||||
state.ui_screen = MENU_ZONE;
|
||||
else if(strcmp(menu_items[ui_state.menu_selected], "Channels") == 0)
|
||||
state.ui_screen = MENU_CHANNEL;
|
||||
else if(strcmp(menu_items[ui_state.menu_selected], "Contacts") == 0)
|
||||
state.ui_screen = MENU_CONTACTS;
|
||||
else if(strcmp(menu_items[ui_state.menu_selected], "Messages") == 0)
|
||||
state.ui_screen = MENU_TOP;
|
||||
else if(strcmp(menu_items[ui_state.menu_selected], "GPS") == 0)
|
||||
state.ui_screen = MENU_GPS;
|
||||
else if(strcmp(menu_items[ui_state.menu_selected], "Settings") == 0)
|
||||
state.ui_screen = MENU_SETTINGS;
|
||||
else if(strcmp(menu_items[ui_state.menu_selected], "Info") == 0)
|
||||
state.ui_screen = MENU_INFO;
|
||||
else if(strcmp(menu_items[ui_state.menu_selected], "About") == 0)
|
||||
state.ui_screen = MENU_ABOUT;
|
||||
else
|
||||
state.ui_screen = MENU_TOP;
|
||||
switch(ui_state.menu_selected)
|
||||
{
|
||||
case M_ZONE:
|
||||
state.ui_screen = MENU_ZONE;
|
||||
break;
|
||||
case M_CHANNEL:
|
||||
state.ui_screen = MENU_CHANNEL;
|
||||
break;
|
||||
case M_CONTACTS:
|
||||
state.ui_screen = MENU_CONTACTS;
|
||||
break;
|
||||
#ifdef HAS_GPS
|
||||
case M_GPS:
|
||||
state.ui_screen = MENU_GPS;
|
||||
break;
|
||||
#endif
|
||||
case M_SETTINGS:
|
||||
state.ui_screen = MENU_SETTINGS;
|
||||
break;
|
||||
case M_INFO:
|
||||
state.ui_screen = MENU_INFO;
|
||||
break;
|
||||
case M_ABOUT:
|
||||
state.ui_screen = MENU_ABOUT;
|
||||
break;
|
||||
}
|
||||
// Reset menu selection
|
||||
ui_state.menu_selected = 0;
|
||||
}
|
||||
|
@ -943,16 +950,23 @@ void ui_updateFSM(event_t event, bool *sync_rtx)
|
|||
_ui_menuDown(settings_num);
|
||||
else if(msg.keys & KEY_ENTER)
|
||||
{
|
||||
if(strcmp(settings_items[ui_state.menu_selected], "Time & Date") == 0)
|
||||
state.ui_screen = SETTINGS_TIMEDATE;
|
||||
else if(strcmp(settings_items[ui_state.menu_selected], "Display") == 0)
|
||||
state.ui_screen = SETTINGS_DISPLAY;
|
||||
#ifdef HAS_GPS
|
||||
else if(strcmp(settings_items[ui_state.menu_selected], "GPS") == 0)
|
||||
state.ui_screen = SETTINGS_GPS;
|
||||
|
||||
switch(ui_state.menu_selected)
|
||||
{
|
||||
case S_DISPLAY:
|
||||
state.ui_screen = SETTINGS_DISPLAY;
|
||||
break;
|
||||
#ifdef HAS_RTC
|
||||
case S_TIMEDATE:
|
||||
state.ui_screen = SETTINGS_TIMEDATE;
|
||||
break;
|
||||
#endif
|
||||
else
|
||||
state.ui_screen = MENU_TOP;
|
||||
#ifdef HAS_GPS
|
||||
case S_GPS:
|
||||
state.ui_screen = SETTINGS_GPS;
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
// Reset menu selection
|
||||
ui_state.menu_selected = 0;
|
||||
}
|
||||
|
@ -1024,24 +1038,30 @@ void ui_updateFSM(event_t event, bool *sync_rtx)
|
|||
case SETTINGS_DISPLAY:
|
||||
if(msg.keys & KEY_LEFT || (msg.keys & KEY_UP && ui_state.edit_mode))
|
||||
{
|
||||
if(strcmp(display_items[ui_state.menu_selected], "Brightness") == 0)
|
||||
switch(ui_state.menu_selected)
|
||||
{
|
||||
_ui_changeBrightness(-25);
|
||||
}
|
||||
else if(strcmp(display_items[ui_state.menu_selected], "Contrast") == 0)
|
||||
{
|
||||
_ui_changeContrast(-25);
|
||||
case D_BRIGHTNESS:
|
||||
_ui_changeBrightness(-25);
|
||||
break;
|
||||
#ifdef SCREEN_CONTRAST
|
||||
case D_CONTRAST:
|
||||
_ui_changeContrast(-25);
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else if(msg.keys & KEY_RIGHT || (msg.keys & KEY_DOWN && ui_state.edit_mode))
|
||||
{
|
||||
if(strcmp(display_items[ui_state.menu_selected], "Brightness") == 0)
|
||||
switch(ui_state.menu_selected)
|
||||
{
|
||||
_ui_changeBrightness(+25);
|
||||
}
|
||||
else if(strcmp(display_items[ui_state.menu_selected], "Contrast") == 0)
|
||||
{
|
||||
_ui_changeContrast(+25);
|
||||
case D_BRIGHTNESS:
|
||||
_ui_changeBrightness(+25);
|
||||
break;
|
||||
#ifdef SCREEN_CONTRAST
|
||||
case D_CONTRAST:
|
||||
_ui_changeContrast(+25);
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else if(msg.keys & KEY_UP)
|
||||
|
@ -1058,28 +1078,31 @@ void ui_updateFSM(event_t event, bool *sync_rtx)
|
|||
if(msg.keys & KEY_LEFT || msg.keys & KEY_RIGHT ||
|
||||
((msg.keys & KEY_UP || msg.keys & KEY_DOWN) && ui_state.edit_mode))
|
||||
{
|
||||
if(strcmp(settings_gps_items[ui_state.menu_selected], "GPS Enabled") == 0)
|
||||
switch(ui_state.menu_selected)
|
||||
{
|
||||
// Disable or Enable GPS to stop or start GPS thread
|
||||
if(state.settings.gps_enabled)
|
||||
{
|
||||
state.settings.gps_enabled = !state.settings.gps_enabled;
|
||||
gps_disable();
|
||||
}
|
||||
else
|
||||
{
|
||||
state.settings.gps_enabled = !state.settings.gps_enabled;
|
||||
gps_enable();
|
||||
}
|
||||
}
|
||||
else if(strcmp(settings_gps_items[ui_state.menu_selected], "GPS Set Time") == 0)
|
||||
state.settings.gps_set_time = !state.settings.gps_set_time;
|
||||
else if(strcmp(settings_gps_items[ui_state.menu_selected], "UTC Timezone") == 0)
|
||||
{
|
||||
if(msg.keys & KEY_LEFT || msg.keys & KEY_UP)
|
||||
state.settings.utc_timezone -= 1;
|
||||
else if(msg.keys & KEY_RIGHT || msg.keys & KEY_DOWN)
|
||||
state.settings.utc_timezone += 1;
|
||||
case G_ENABLED:
|
||||
// Disable or Enable GPS to stop or start GPS thread
|
||||
if(state.settings.gps_enabled)
|
||||
{
|
||||
state.settings.gps_enabled = !state.settings.gps_enabled;
|
||||
gps_disable();
|
||||
}
|
||||
else
|
||||
{
|
||||
state.settings.gps_enabled = !state.settings.gps_enabled;
|
||||
gps_enable();
|
||||
}
|
||||
break;
|
||||
case G_SET_TIME:
|
||||
state.settings.gps_set_time = !state.settings.gps_set_time;
|
||||
break;
|
||||
case G_TIMEZONE:
|
||||
if(msg.keys & KEY_LEFT || msg.keys & KEY_UP)
|
||||
state.settings.utc_timezone -= 1;
|
||||
else if(msg.keys & KEY_RIGHT || msg.keys & KEY_DOWN)
|
||||
state.settings.utc_timezone += 1;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
else if(msg.keys & KEY_UP)
|
||||
|
|
|
@ -123,10 +123,17 @@ int _ui_getDisplayValueName(char *buf, uint8_t max_len, uint8_t index)
|
|||
{
|
||||
if(index >= display_num) return -1;
|
||||
uint8_t value = 0;
|
||||
if(strcmp(display_items[index], "Brightness") == 0)
|
||||
value = last_state.settings.brightness;
|
||||
else if(strcmp(display_items[index], "Contrast") == 0)
|
||||
value = last_state.settings.contrast;
|
||||
switch(index)
|
||||
{
|
||||
case D_BRIGHTNESS:
|
||||
value = last_state.settings.brightness;
|
||||
break;
|
||||
#ifdef SCREEN_CONTRAST
|
||||
case D_CONTRAST:
|
||||
value = last_state.settings.contrast;
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
snprintf(buf, max_len, "%d", value);
|
||||
return 0;
|
||||
}
|
||||
|
@ -141,17 +148,21 @@ int _ui_getSettingsGPSEntryName(char *buf, uint8_t max_len, uint8_t index)
|
|||
int _ui_getSettingsGPSValueName(char *buf, uint8_t max_len, uint8_t index)
|
||||
{
|
||||
if(index >= settings_gps_num) return -1;
|
||||
if(strcmp(settings_gps_items[index], "GPS Enabled") == 0)
|
||||
snprintf(buf, max_len, "%s", (last_state.settings.gps_enabled) ? "ON" : "OFF");
|
||||
else if(strcmp(settings_gps_items[index], "GPS Set Time") == 0)
|
||||
snprintf(buf, max_len, "%s", (last_state.settings.gps_set_time) ? "ON" : "OFF");
|
||||
else if(strcmp(settings_gps_items[index], "UTC Timezone") == 0)
|
||||
switch(index)
|
||||
{
|
||||
// Add + prefix to positive numbers
|
||||
if(last_state.settings.utc_timezone > 0)
|
||||
snprintf(buf, max_len, "+%d", last_state.settings.utc_timezone);
|
||||
else
|
||||
snprintf(buf, max_len, "%d", last_state.settings.utc_timezone);
|
||||
case G_ENABLED:
|
||||
snprintf(buf, max_len, "%s", (last_state.settings.gps_enabled) ? "ON" : "OFF");
|
||||
break;
|
||||
case G_SET_TIME:
|
||||
snprintf(buf, max_len, "%s", (last_state.settings.gps_set_time) ? "ON" : "OFF");
|
||||
break;
|
||||
case G_TIMEZONE:
|
||||
// Add + prefix to positive numbers
|
||||
if(last_state.settings.utc_timezone > 0)
|
||||
snprintf(buf, max_len, "+%d", last_state.settings.utc_timezone);
|
||||
else
|
||||
snprintf(buf, max_len, "%d", last_state.settings.utc_timezone);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -167,22 +178,33 @@ int _ui_getInfoValueName(char *buf, uint8_t max_len, uint8_t index)
|
|||
{
|
||||
const hwInfo_t* hwinfo = platform_getHwInfo();
|
||||
if(index >= info_num) return -1;
|
||||
else if(strcmp(info_items[index], "Bat. Voltage") == 0)
|
||||
snprintf(buf, max_len, "%.1fV", last_state.v_bat);
|
||||
else if(strcmp(info_items[index], "Bat. Charge") == 0)
|
||||
snprintf(buf, max_len, "%.1f%%", last_state.charge * 100);
|
||||
else if(strcmp(info_items[index], "RSSI") == 0)
|
||||
snprintf(buf, max_len, "%.1fdBm", last_state.rssi);
|
||||
if(strcmp(info_items[index], "Model") == 0)
|
||||
snprintf(buf, max_len, "%s", hwinfo->name);
|
||||
if(strcmp(info_items[index], "Band") == 0)
|
||||
snprintf(buf, max_len, "%s %s", hwinfo->vhf_band ? "VHF" : "", hwinfo->uhf_band ? "UHF" : "");
|
||||
else if(strcmp(info_items[index], "VHF") == 0)
|
||||
snprintf(buf, max_len, "%d - %d", hwinfo->vhf_minFreq, hwinfo->vhf_maxFreq);
|
||||
else if(strcmp(info_items[index], "UHF") == 0)
|
||||
snprintf(buf, max_len, "%d - %d", hwinfo->uhf_minFreq, hwinfo->uhf_maxFreq);
|
||||
else if(strcmp(info_items[index], "LCD Type") == 0)
|
||||
snprintf(buf, max_len, "%d", hwinfo->lcd_type);
|
||||
switch(index)
|
||||
{
|
||||
case 0: // Battery voltage
|
||||
snprintf(buf, max_len, "%.1fV", last_state.v_bat);
|
||||
break;
|
||||
case 1: // Battery charge
|
||||
snprintf(buf, max_len, "%.1f%%", last_state.charge * 100);
|
||||
break;
|
||||
case 2: // RSSI
|
||||
snprintf(buf, max_len, "%.1fdBm", last_state.rssi);
|
||||
break;
|
||||
case 3: // Model
|
||||
snprintf(buf, max_len, "%s", hwinfo->name);
|
||||
break;
|
||||
case 4: // Band
|
||||
snprintf(buf, max_len, "%s %s", hwinfo->vhf_band ? "VHF" : "", hwinfo->uhf_band ? "UHF" : "");
|
||||
break;
|
||||
case 5: // VHF
|
||||
snprintf(buf, max_len, "%d - %d", hwinfo->vhf_minFreq, hwinfo->vhf_maxFreq);
|
||||
break;
|
||||
case 6: // UHF
|
||||
snprintf(buf, max_len, "%d - %d", hwinfo->uhf_minFreq, hwinfo->uhf_maxFreq);
|
||||
break;
|
||||
case 7: // LCD Type
|
||||
snprintf(buf, max_len, "%d", hwinfo->lcd_type);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue