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
|
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
|
* Struct containing a set of positions and sizes that get
|
||||||
* calculated for the selected display size.
|
* calculated for the selected display size.
|
||||||
|
|
|
@ -120,10 +120,10 @@ const char *menu_items[] =
|
||||||
|
|
||||||
const char *settings_items[] =
|
const char *settings_items[] =
|
||||||
{
|
{
|
||||||
|
"Display",
|
||||||
#ifdef HAS_RTC
|
#ifdef HAS_RTC
|
||||||
"Time & Date",
|
"Time & Date",
|
||||||
#endif
|
#endif
|
||||||
"Display",
|
|
||||||
#ifdef HAS_GPS
|
#ifdef HAS_GPS
|
||||||
"GPS"
|
"GPS"
|
||||||
#endif
|
#endif
|
||||||
|
@ -830,25 +830,32 @@ void ui_updateFSM(event_t event, bool *sync_rtx)
|
||||||
_ui_menuDown(menu_num);
|
_ui_menuDown(menu_num);
|
||||||
else if(msg.keys & KEY_ENTER)
|
else if(msg.keys & KEY_ENTER)
|
||||||
{
|
{
|
||||||
// Open selected menu item
|
switch(ui_state.menu_selected)
|
||||||
if(strcmp(menu_items[ui_state.menu_selected], "Zone") == 0)
|
{
|
||||||
state.ui_screen = MENU_ZONE;
|
case M_ZONE:
|
||||||
else if(strcmp(menu_items[ui_state.menu_selected], "Channels") == 0)
|
state.ui_screen = MENU_ZONE;
|
||||||
state.ui_screen = MENU_CHANNEL;
|
break;
|
||||||
else if(strcmp(menu_items[ui_state.menu_selected], "Contacts") == 0)
|
case M_CHANNEL:
|
||||||
state.ui_screen = MENU_CONTACTS;
|
state.ui_screen = MENU_CHANNEL;
|
||||||
else if(strcmp(menu_items[ui_state.menu_selected], "Messages") == 0)
|
break;
|
||||||
state.ui_screen = MENU_TOP;
|
case M_CONTACTS:
|
||||||
else if(strcmp(menu_items[ui_state.menu_selected], "GPS") == 0)
|
state.ui_screen = MENU_CONTACTS;
|
||||||
state.ui_screen = MENU_GPS;
|
break;
|
||||||
else if(strcmp(menu_items[ui_state.menu_selected], "Settings") == 0)
|
#ifdef HAS_GPS
|
||||||
state.ui_screen = MENU_SETTINGS;
|
case M_GPS:
|
||||||
else if(strcmp(menu_items[ui_state.menu_selected], "Info") == 0)
|
state.ui_screen = MENU_GPS;
|
||||||
state.ui_screen = MENU_INFO;
|
break;
|
||||||
else if(strcmp(menu_items[ui_state.menu_selected], "About") == 0)
|
#endif
|
||||||
state.ui_screen = MENU_ABOUT;
|
case M_SETTINGS:
|
||||||
else
|
state.ui_screen = MENU_SETTINGS;
|
||||||
state.ui_screen = MENU_TOP;
|
break;
|
||||||
|
case M_INFO:
|
||||||
|
state.ui_screen = MENU_INFO;
|
||||||
|
break;
|
||||||
|
case M_ABOUT:
|
||||||
|
state.ui_screen = MENU_ABOUT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
// Reset menu selection
|
// Reset menu selection
|
||||||
ui_state.menu_selected = 0;
|
ui_state.menu_selected = 0;
|
||||||
}
|
}
|
||||||
|
@ -943,16 +950,23 @@ void ui_updateFSM(event_t event, bool *sync_rtx)
|
||||||
_ui_menuDown(settings_num);
|
_ui_menuDown(settings_num);
|
||||||
else if(msg.keys & KEY_ENTER)
|
else if(msg.keys & KEY_ENTER)
|
||||||
{
|
{
|
||||||
if(strcmp(settings_items[ui_state.menu_selected], "Time & Date") == 0)
|
|
||||||
state.ui_screen = SETTINGS_TIMEDATE;
|
switch(ui_state.menu_selected)
|
||||||
else if(strcmp(settings_items[ui_state.menu_selected], "Display") == 0)
|
{
|
||||||
state.ui_screen = SETTINGS_DISPLAY;
|
case S_DISPLAY:
|
||||||
#ifdef HAS_GPS
|
state.ui_screen = SETTINGS_DISPLAY;
|
||||||
else if(strcmp(settings_items[ui_state.menu_selected], "GPS") == 0)
|
break;
|
||||||
state.ui_screen = SETTINGS_GPS;
|
#ifdef HAS_RTC
|
||||||
|
case S_TIMEDATE:
|
||||||
|
state.ui_screen = SETTINGS_TIMEDATE;
|
||||||
|
break;
|
||||||
#endif
|
#endif
|
||||||
else
|
#ifdef HAS_GPS
|
||||||
state.ui_screen = MENU_TOP;
|
case S_GPS:
|
||||||
|
state.ui_screen = SETTINGS_GPS;
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
// Reset menu selection
|
// Reset menu selection
|
||||||
ui_state.menu_selected = 0;
|
ui_state.menu_selected = 0;
|
||||||
}
|
}
|
||||||
|
@ -1024,24 +1038,30 @@ void ui_updateFSM(event_t event, bool *sync_rtx)
|
||||||
case SETTINGS_DISPLAY:
|
case SETTINGS_DISPLAY:
|
||||||
if(msg.keys & KEY_LEFT || (msg.keys & KEY_UP && ui_state.edit_mode))
|
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);
|
case D_BRIGHTNESS:
|
||||||
}
|
_ui_changeBrightness(-25);
|
||||||
else if(strcmp(display_items[ui_state.menu_selected], "Contrast") == 0)
|
break;
|
||||||
{
|
#ifdef SCREEN_CONTRAST
|
||||||
_ui_changeContrast(-25);
|
case D_CONTRAST:
|
||||||
|
_ui_changeContrast(-25);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(msg.keys & KEY_RIGHT || (msg.keys & KEY_DOWN && ui_state.edit_mode))
|
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);
|
case D_BRIGHTNESS:
|
||||||
}
|
_ui_changeBrightness(+25);
|
||||||
else if(strcmp(display_items[ui_state.menu_selected], "Contrast") == 0)
|
break;
|
||||||
{
|
#ifdef SCREEN_CONTRAST
|
||||||
_ui_changeContrast(+25);
|
case D_CONTRAST:
|
||||||
|
_ui_changeContrast(+25);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(msg.keys & KEY_UP)
|
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 ||
|
if(msg.keys & KEY_LEFT || msg.keys & KEY_RIGHT ||
|
||||||
((msg.keys & KEY_UP || msg.keys & KEY_DOWN) && ui_state.edit_mode))
|
((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
|
case G_ENABLED:
|
||||||
if(state.settings.gps_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();
|
state.settings.gps_enabled = !state.settings.gps_enabled;
|
||||||
}
|
gps_disable();
|
||||||
else
|
}
|
||||||
{
|
else
|
||||||
state.settings.gps_enabled = !state.settings.gps_enabled;
|
{
|
||||||
gps_enable();
|
state.settings.gps_enabled = !state.settings.gps_enabled;
|
||||||
}
|
gps_enable();
|
||||||
}
|
}
|
||||||
else if(strcmp(settings_gps_items[ui_state.menu_selected], "GPS Set Time") == 0)
|
break;
|
||||||
state.settings.gps_set_time = !state.settings.gps_set_time;
|
case G_SET_TIME:
|
||||||
else if(strcmp(settings_gps_items[ui_state.menu_selected], "UTC Timezone") == 0)
|
state.settings.gps_set_time = !state.settings.gps_set_time;
|
||||||
{
|
break;
|
||||||
if(msg.keys & KEY_LEFT || msg.keys & KEY_UP)
|
case G_TIMEZONE:
|
||||||
state.settings.utc_timezone -= 1;
|
if(msg.keys & KEY_LEFT || msg.keys & KEY_UP)
|
||||||
else if(msg.keys & KEY_RIGHT || msg.keys & KEY_DOWN)
|
state.settings.utc_timezone -= 1;
|
||||||
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)
|
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;
|
if(index >= display_num) return -1;
|
||||||
uint8_t value = 0;
|
uint8_t value = 0;
|
||||||
if(strcmp(display_items[index], "Brightness") == 0)
|
switch(index)
|
||||||
value = last_state.settings.brightness;
|
{
|
||||||
else if(strcmp(display_items[index], "Contrast") == 0)
|
case D_BRIGHTNESS:
|
||||||
value = last_state.settings.contrast;
|
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);
|
snprintf(buf, max_len, "%d", value);
|
||||||
return 0;
|
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)
|
int _ui_getSettingsGPSValueName(char *buf, uint8_t max_len, uint8_t index)
|
||||||
{
|
{
|
||||||
if(index >= settings_gps_num) return -1;
|
if(index >= settings_gps_num) return -1;
|
||||||
if(strcmp(settings_gps_items[index], "GPS Enabled") == 0)
|
switch(index)
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
// Add + prefix to positive numbers
|
case G_ENABLED:
|
||||||
if(last_state.settings.utc_timezone > 0)
|
snprintf(buf, max_len, "%s", (last_state.settings.gps_enabled) ? "ON" : "OFF");
|
||||||
snprintf(buf, max_len, "+%d", last_state.settings.utc_timezone);
|
break;
|
||||||
else
|
case G_SET_TIME:
|
||||||
snprintf(buf, max_len, "%d", last_state.settings.utc_timezone);
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -167,22 +178,33 @@ int _ui_getInfoValueName(char *buf, uint8_t max_len, uint8_t index)
|
||||||
{
|
{
|
||||||
const hwInfo_t* hwinfo = platform_getHwInfo();
|
const hwInfo_t* hwinfo = platform_getHwInfo();
|
||||||
if(index >= info_num) return -1;
|
if(index >= info_num) return -1;
|
||||||
else if(strcmp(info_items[index], "Bat. Voltage") == 0)
|
switch(index)
|
||||||
snprintf(buf, max_len, "%.1fV", last_state.v_bat);
|
{
|
||||||
else if(strcmp(info_items[index], "Bat. Charge") == 0)
|
case 0: // Battery voltage
|
||||||
snprintf(buf, max_len, "%.1f%%", last_state.charge * 100);
|
snprintf(buf, max_len, "%.1fV", last_state.v_bat);
|
||||||
else if(strcmp(info_items[index], "RSSI") == 0)
|
break;
|
||||||
snprintf(buf, max_len, "%.1fdBm", last_state.rssi);
|
case 1: // Battery charge
|
||||||
if(strcmp(info_items[index], "Model") == 0)
|
snprintf(buf, max_len, "%.1f%%", last_state.charge * 100);
|
||||||
snprintf(buf, max_len, "%s", hwinfo->name);
|
break;
|
||||||
if(strcmp(info_items[index], "Band") == 0)
|
case 2: // RSSI
|
||||||
snprintf(buf, max_len, "%s %s", hwinfo->vhf_band ? "VHF" : "", hwinfo->uhf_band ? "UHF" : "");
|
snprintf(buf, max_len, "%.1fdBm", last_state.rssi);
|
||||||
else if(strcmp(info_items[index], "VHF") == 0)
|
break;
|
||||||
snprintf(buf, max_len, "%d - %d", hwinfo->vhf_minFreq, hwinfo->vhf_maxFreq);
|
case 3: // Model
|
||||||
else if(strcmp(info_items[index], "UHF") == 0)
|
snprintf(buf, max_len, "%s", hwinfo->name);
|
||||||
snprintf(buf, max_len, "%d - %d", hwinfo->uhf_minFreq, hwinfo->uhf_maxFreq);
|
break;
|
||||||
else if(strcmp(info_items[index], "LCD Type") == 0)
|
case 4: // Band
|
||||||
snprintf(buf, max_len, "%d", hwinfo->lcd_type);
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue