Add a menu for clearing settings and vfo to sane defaults (#67)

This commit is contained in:
tarxvf 2022-02-26 06:42:28 -05:00 committed by GitHub
parent 9e588216f9
commit 9297c08b05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 116 additions and 22 deletions

View File

@ -31,6 +31,7 @@ openrtx_src = ['openrtx/src/state.c',
'openrtx/src/calibUtils.c', 'openrtx/src/calibUtils.c',
'openrtx/src/queue.c', 'openrtx/src/queue.c',
'openrtx/src/chan.c', 'openrtx/src/chan.c',
'openrtx/src/cps.c',
'openrtx/src/rtx/rtx.cpp', 'openrtx/src/rtx/rtx.cpp',
'openrtx/src/rtx/OpMode_FM.cpp', 'openrtx/src/rtx/OpMode_FM.cpp',
'openrtx/src/rtx/OpMode_M17.cpp', 'openrtx/src/rtx/OpMode_M17.cpp',

View File

@ -121,6 +121,7 @@ typedef struct
} }
__attribute__((packed)) channel_t; __attribute__((packed)) channel_t;
/** /**
* Data structure containing all the information of a zone. * Data structure containing all the information of a zone.
*/ */
@ -143,4 +144,11 @@ typedef struct
} }
__attribute__((packed)) contact_t; __attribute__((packed)) contact_t;
/*
* Create and return a viable channel for this radio.
* Suitable for default VFO settings or the creation of a new channel.
* Needs to be generated by a function frequency settings require details from the running hardware on limitations
*/
channel_t get_default_channel();
#endif #endif

View File

@ -130,6 +130,13 @@ extern state_t state;
*/ */
void state_init(); void state_init();
/**
* Write default values to OpenRTX settings and VFO Channel configuration
* Writes out to flash and calls state_init again to reload it immediately
*
*/
void defaultSettingsAndVfo();
/** /**
* This function terminates the Radio state, * This function terminates the Radio state,
* Saving persistent settings to flash. * Saving persistent settings to flash.
@ -148,4 +155,5 @@ curTime_t state_getLocalTime(curTime_t utc_time);
*/ */
curTime_t state_getUTCTime(curTime_t local_time); curTime_t state_getUTCTime(curTime_t local_time);
#endif /* STATE_H */ #endif /* STATE_H */

View File

@ -55,6 +55,7 @@ enum uiScreen
SETTINGS_DISPLAY, SETTINGS_DISPLAY,
SETTINGS_GPS, SETTINGS_GPS,
SETTINGS_M17, SETTINGS_M17,
SETTINGS_RESET2DEFAULTS,
LOW_BAT LOW_BAT
}; };
@ -89,6 +90,7 @@ enum settingsItems
,S_GPS ,S_GPS
#endif #endif
,S_M17 ,S_M17
,S_RESET2DEFAULTS
}; };
enum displayItems enum displayItems

30
openrtx/src/cps.c Normal file
View File

@ -0,0 +1,30 @@
#include <interfaces/platform.h>
#include <cps.h>
channel_t get_default_channel()
{
channel_t channel;
channel.mode = FM;
channel.bandwidth = BW_25;
channel.power = 1.0;
// Set initial frequency based on supported bands
const hwInfo_t* hwinfo = platform_getHwInfo();
if(hwinfo->uhf_band)
{
channel.rx_frequency = 430000000;
channel.tx_frequency = 430000000;
}
else if(hwinfo->vhf_band)
{
channel.rx_frequency = 144000000;
channel.tx_frequency = 144000000;
}
channel.fm.rxToneEn = 0; //disabled
channel.fm.rxTone = 0; //and no ctcss/dcs selected
channel.fm.txToneEn = 0;
channel.fm.txTone = 0;
return channel;
}

View File

@ -26,8 +26,21 @@
#include <interfaces/platform.h> #include <interfaces/platform.h>
#include <interfaces/nvmem.h> #include <interfaces/nvmem.h>
#include <cps.h>
state_t state; state_t state;
void defaultSettingsAndVfo()
{
//don't need to lock state mutex because this is called from a section
//that already does that - ui_updatefsm runs in a critical section in
//the ui thread
channel_t default_vfo = get_default_channel();
nvm_writeSettingsAndVfo( &default_settings, &default_vfo );
state_init();
}
void state_init() void state_init()
{ {
/* /*
@ -46,27 +59,7 @@ void state_init()
*/ */
if(nvm_readVFOChannelData(&state.channel) < 0) if(nvm_readVFOChannelData(&state.channel) < 0)
{ {
state.channel.mode = FM; state.channel = get_default_channel();
state.channel.bandwidth = BW_25;
state.channel.power = 1.0;
// Set initial frequency based on supported bands
const hwInfo_t* hwinfo = platform_getHwInfo();
if(hwinfo->uhf_band)
{
state.channel.rx_frequency = 430000000;
state.channel.tx_frequency = 430000000;
}
else if(hwinfo->vhf_band)
{
state.channel.rx_frequency = 144000000;
state.channel.tx_frequency = 144000000;
}
state.channel.fm.rxToneEn = 0;
state.channel.fm.rxTone = 2; // 71.9Hz
state.channel.fm.txToneEn = 1;
state.channel.fm.txTone = 2; // 71.9Hz
} }
/* /*

View File

@ -106,6 +106,7 @@ extern void _ui_drawSettingsTimeDateSet(ui_state_t* ui_state);
#endif #endif
extern void _ui_drawSettingsDisplay(ui_state_t* ui_state); extern void _ui_drawSettingsDisplay(ui_state_t* ui_state);
extern void _ui_drawSettingsM17(ui_state_t* ui_state); extern void _ui_drawSettingsM17(ui_state_t* ui_state);
extern void _ui_drawSettingsReset2Defaults(ui_state_t* ui_state);
extern bool _ui_drawMacroMenu(); extern bool _ui_drawMacroMenu();
const char *menu_items[] = const char *menu_items[] =
@ -130,7 +131,8 @@ const char *settings_items[] =
#ifdef HAS_GPS #ifdef HAS_GPS
"GPS", "GPS",
#endif #endif
"M17" "M17",
"Default Settings"
}; };
const char *display_items[] = const char *display_items[] =
@ -1382,6 +1384,9 @@ void ui_updateFSM(event_t event, bool *sync_rtx)
case S_M17: case S_M17:
state.ui_screen = SETTINGS_M17; state.ui_screen = SETTINGS_M17;
break; break;
case S_RESET2DEFAULTS:
state.ui_screen = SETTINGS_RESET2DEFAULTS;
break;
default: default:
state.ui_screen = MENU_SETTINGS; state.ui_screen = MENU_SETTINGS;
} }
@ -1578,6 +1583,32 @@ void ui_updateFSM(event_t event, bool *sync_rtx)
_ui_menuBack(MENU_SETTINGS); _ui_menuBack(MENU_SETTINGS);
} }
break; break;
case SETTINGS_RESET2DEFAULTS:
if(! ui_state.edit_mode){
//require a confirmation ENTER, then another
//edit_mode is slightly misused to allow for this
if(msg.keys & KEY_ENTER)
{
ui_state.edit_mode = true;
}
else if(msg.keys & KEY_ESC)
{
_ui_menuBack(MENU_SETTINGS);
}
} else {
if(msg.keys & KEY_ENTER)
{
ui_state.edit_mode = false;
defaultSettingsAndVfo();
_ui_menuBack(MENU_SETTINGS);
}
else if(msg.keys & KEY_ESC)
{
ui_state.edit_mode = false;
_ui_menuBack(MENU_SETTINGS);
}
}
break;
} }
} }
else if(event.type == EVENT_STATUS) else if(event.type == EVENT_STATUS)
@ -1683,6 +1714,10 @@ void ui_updateGUI()
case SETTINGS_M17: case SETTINGS_M17:
_ui_drawSettingsM17(&ui_state); _ui_drawSettingsM17(&ui_state);
break; break;
// Screen to support resetting Settings and VFO to defaults
case SETTINGS_RESET2DEFAULTS:
_ui_drawSettingsReset2Defaults(&ui_state);
break;
// Low battery screen // Low battery screen
case LOW_BAT: case LOW_BAT:
_ui_drawLowBatteryScreen(); _ui_drawLowBatteryScreen();

View File

@ -566,6 +566,23 @@ void _ui_drawSettingsM17(ui_state_t* ui_state)
TEXT_ALIGN_CENTER, color_white, last_state.settings.callsign); TEXT_ALIGN_CENTER, color_white, last_state.settings.callsign);
} }
} }
void _ui_drawSettingsReset2Defaults(ui_state_t* ui_state)
{
static int drawcnt = 0;
gfx_clearScreen();
gfx_print(layout.top_pos, layout.top_font, TEXT_ALIGN_CENTER,
color_white, "Reset to Defaults");
//text will flash yellow and white based on update rate of screen
color_t textcolor = drawcnt % 2 == 0 ? color_white : yellow_fab413;
gfx_printLine(1, 4, layout.top_h, SCREEN_HEIGHT - layout.bottom_h,
layout.horizontal_pad, layout.top_font,
TEXT_ALIGN_CENTER, textcolor, "To reset:");
gfx_printLine(2, 4, layout.top_h, SCREEN_HEIGHT - layout.bottom_h,
layout.horizontal_pad, layout.top_font,
TEXT_ALIGN_CENTER, textcolor, "Press Enter 2x");
drawcnt++;
}
bool _ui_drawMacroMenu() { bool _ui_drawMacroMenu() {
// Header // Header