diff --git a/meson.build b/meson.build index 1a8bb698..fc82c1f6 100644 --- a/meson.build +++ b/meson.build @@ -31,6 +31,7 @@ openrtx_src = ['openrtx/src/state.c', 'openrtx/src/calibUtils.c', 'openrtx/src/queue.c', 'openrtx/src/chan.c', + 'openrtx/src/cps.c', 'openrtx/src/rtx/rtx.cpp', 'openrtx/src/rtx/OpMode_FM.cpp', 'openrtx/src/rtx/OpMode_M17.cpp', diff --git a/openrtx/include/cps.h b/openrtx/include/cps.h index fb75472e..30b08c6e 100644 --- a/openrtx/include/cps.h +++ b/openrtx/include/cps.h @@ -121,6 +121,7 @@ typedef struct } __attribute__((packed)) channel_t; + /** * Data structure containing all the information of a zone. */ @@ -143,4 +144,11 @@ typedef struct } __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 diff --git a/openrtx/include/state.h b/openrtx/include/state.h index 8bb796c6..a57568be 100644 --- a/openrtx/include/state.h +++ b/openrtx/include/state.h @@ -130,6 +130,13 @@ extern state_t state; */ 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, * 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); + #endif /* STATE_H */ diff --git a/openrtx/include/ui.h b/openrtx/include/ui.h index 030f786b..7f1a0aa1 100644 --- a/openrtx/include/ui.h +++ b/openrtx/include/ui.h @@ -55,6 +55,7 @@ enum uiScreen SETTINGS_DISPLAY, SETTINGS_GPS, SETTINGS_M17, + SETTINGS_RESET2DEFAULTS, LOW_BAT }; @@ -89,6 +90,7 @@ enum settingsItems ,S_GPS #endif ,S_M17 + ,S_RESET2DEFAULTS }; enum displayItems diff --git a/openrtx/src/cps.c b/openrtx/src/cps.c new file mode 100644 index 00000000..cd628436 --- /dev/null +++ b/openrtx/src/cps.c @@ -0,0 +1,30 @@ +#include +#include + + +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; +} diff --git a/openrtx/src/state.c b/openrtx/src/state.c index 5522c56d..cc6a472d 100644 --- a/openrtx/src/state.c +++ b/openrtx/src/state.c @@ -26,8 +26,21 @@ #include #include +#include + 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() { /* @@ -46,27 +59,7 @@ void state_init() */ if(nvm_readVFOChannelData(&state.channel) < 0) { - state.channel.mode = FM; - 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 + state.channel = get_default_channel(); } /* diff --git a/openrtx/src/ui/ui.c b/openrtx/src/ui/ui.c index 1e89b828..9e0492fe 100644 --- a/openrtx/src/ui/ui.c +++ b/openrtx/src/ui/ui.c @@ -106,6 +106,7 @@ extern void _ui_drawSettingsTimeDateSet(ui_state_t* ui_state); #endif extern void _ui_drawSettingsDisplay(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(); const char *menu_items[] = @@ -130,7 +131,8 @@ const char *settings_items[] = #ifdef HAS_GPS "GPS", #endif - "M17" + "M17", + "Default Settings" }; const char *display_items[] = @@ -1382,6 +1384,9 @@ void ui_updateFSM(event_t event, bool *sync_rtx) case S_M17: state.ui_screen = SETTINGS_M17; break; + case S_RESET2DEFAULTS: + state.ui_screen = SETTINGS_RESET2DEFAULTS; + break; default: state.ui_screen = MENU_SETTINGS; } @@ -1578,6 +1583,32 @@ void ui_updateFSM(event_t event, bool *sync_rtx) _ui_menuBack(MENU_SETTINGS); } 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) @@ -1683,6 +1714,10 @@ void ui_updateGUI() case SETTINGS_M17: _ui_drawSettingsM17(&ui_state); break; + // Screen to support resetting Settings and VFO to defaults + case SETTINGS_RESET2DEFAULTS: + _ui_drawSettingsReset2Defaults(&ui_state); + break; // Low battery screen case LOW_BAT: _ui_drawLowBatteryScreen(); diff --git a/openrtx/src/ui/ui_menu.c b/openrtx/src/ui/ui_menu.c index eb4c72b2..30dc4bc2 100644 --- a/openrtx/src/ui/ui_menu.c +++ b/openrtx/src/ui/ui_menu.c @@ -566,6 +566,23 @@ void _ui_drawSettingsM17(ui_state_t* ui_state) 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() { // Header