0
mirror of https://github.com/OneOfEleven/uv-k5-firmware-custom.git synced 2025-06-20 15:08:37 +03:00

Can now interrupt RF scanning with any other function

This commit is contained in:
OneOfEleven
2023-10-17 11:05:41 +01:00
parent 73572f24b1
commit d47cd80fd4
24 changed files with 529 additions and 459 deletions

241
app/app.c
View File

@ -103,7 +103,7 @@ static void APP_check_for_incoming_rx(void)
if (g_css_scan_mode != CSS_SCAN_MODE_OFF && g_rx_reception_mode == RX_MODE_NONE)
{ // CTCSS/DTS scanning
g_scan_pause_10ms = scan_pause_5_10ms;
g_scan_pause_10ms = scan_pause_code_10ms;
g_rx_reception_mode = RX_MODE_DETECTED;
}
@ -118,62 +118,32 @@ static void APP_check_for_incoming_rx(void)
}
#endif
if (g_current_function != FUNCTION_INCOMING)
{
FUNCTION_Select(FUNCTION_INCOMING);
//g_update_display = true;
APP_update_rssi(g_eeprom.rx_vfo);
g_update_rssi = true;
}
return;
goto done;
}
// dual watch is enabled and we're RX'ing a signal
if (g_rx_reception_mode != RX_MODE_NONE)
{
if (g_current_function != FUNCTION_INCOMING)
{
FUNCTION_Select(FUNCTION_INCOMING);
//g_update_display = true;
goto done;
APP_update_rssi(g_eeprom.rx_vfo);
g_update_rssi = true;
}
return;
}
g_dual_watch_count_down_10ms = dual_watch_count_after_rx_10ms;
g_schedule_dual_watch = false;
g_dual_watch_delay_10ms = g_eeprom.scan_hold_time_500ms * 50;
g_update_status = true;
}
else
{ // RF scanning
if (g_rx_reception_mode != RX_MODE_NONE)
{
if (g_current_function != FUNCTION_INCOMING)
{
FUNCTION_Select(FUNCTION_INCOMING);
//g_update_display = true;
goto done;
APP_update_rssi(g_eeprom.rx_vfo);
g_update_rssi = true;
}
return;
}
g_scan_pause_10ms = scan_pause_3_10ms;
g_scan_pause_10ms = scan_pause_chan_10ms;
}
g_rx_reception_mode = RX_MODE_DETECTED;
done:
if (g_current_function != FUNCTION_INCOMING)
{
FUNCTION_Select(FUNCTION_INCOMING);
//g_update_display = true;
APP_update_rssi(g_eeprom.rx_vfo);
g_update_rssi = true;
@ -223,7 +193,7 @@ static void APP_process_incoming_rx(void)
return;
if (g_scan_state_dir == SCAN_STATE_DIR_OFF && g_css_scan_mode == CSS_SCAN_MODE_OFF)
{ // not scanning
{ // not code scanning
#ifdef ENABLE_KILL_REVIVE
if (g_rx_vfo->dtmf_decoding_enable || g_setting_radio_disabled)
@ -238,10 +208,8 @@ static void APP_process_incoming_rx(void)
{
if (g_rx_reception_mode == RX_MODE_DETECTED)
{
g_dual_watch_count_down_10ms = dual_watch_count_after_1_10ms;
g_schedule_dual_watch = false;
g_rx_reception_mode = RX_MODE_LISTENING;
g_dual_watch_delay_10ms = g_eeprom.scan_hold_time_500ms * 50;
g_rx_reception_mode = RX_MODE_LISTENING;
g_update_status = true;
g_update_display = true;
@ -411,7 +379,7 @@ Skip:
break;
case SCAN_RESUME_CO:
g_scan_pause_10ms = scan_pause_7_10ms;
g_scan_pause_10ms = g_eeprom.scan_hold_time_500ms * 50;
break;
case SCAN_RESUME_SE:
@ -456,13 +424,9 @@ static void APP_process_function(void)
APP_process_incoming_rx();
case FUNCTION_MONITOR:
if (g_setting_backlight_on_tx_rx >= 2)
backlight_turn_on(backlight_tx_rx_time_500ms);
break;
case FUNCTION_RECEIVE:
if (g_setting_backlight_on_tx_rx >= 2)
backlight_turn_on(backlight_tx_rx_time_500ms);
APP_process_rx();
break;
@ -488,6 +452,9 @@ void APP_start_listening(function_type_t Function, const bool reset_am_fix)
return;
#endif
if (g_setting_backlight_on_tx_rx >= 2)
backlight_turn_on(backlight_tx_rx_time_500ms);
#ifdef ENABLE_FMRADIO
if (g_fm_radio_mode)
BK1080_Init(0, false);
@ -501,15 +468,15 @@ void APP_start_listening(function_type_t Function, const bool reset_am_fix)
g_enable_speaker = true;
if (g_scan_state_dir != SCAN_STATE_DIR_OFF)
{ // we're scanning
{ // we're RF scanning
switch (g_eeprom.scan_resume_mode)
{
case SCAN_RESUME_TO:
if (!g_scan_pause_mode)
{
g_scan_pause_10ms = scan_pause_1_10ms;
g_scan_pause_mode = true;
g_scan_pause_10ms = g_eeprom.scan_hold_time_500ms * 50;
g_scan_pause_mode = true;
}
break;
@ -519,7 +486,9 @@ void APP_start_listening(function_type_t Function, const bool reset_am_fix)
break;
}
g_scan_keep_frequency = true;
g_scan_restore_channel = 0xff;
g_scan_restore_frequency = 0;
// g_scan_keep_frequency = true;
}
#ifdef ENABLE_NOAA
@ -542,10 +511,8 @@ void APP_start_listening(function_type_t Function, const bool reset_am_fix)
g_eeprom.dual_watch != DUAL_WATCH_OFF)
{ // not scanning, but dual watch is enabled
g_dual_watch_count_down_10ms = dual_watch_count_after_2_10ms;
g_schedule_dual_watch = false;
g_rx_vfo_is_active = true;
g_dual_watch_delay_10ms = g_eeprom.scan_hold_time_500ms * 50;
g_rx_vfo_is_active = true;
g_update_status = true;
}
@ -562,16 +529,12 @@ void APP_start_listening(function_type_t Function, const bool reset_am_fix)
if (g_rx_vfo->am_mode && g_setting_am_fix)
{ // AM RX mode
if (reset_am_fix)
AM_fix_reset(chan); // TODO: only reset it when moving channel/frequency .. or do we ???
AM_fix_reset(chan); // TODO: only reset it when moving channel/frequency .. or do we ???
AM_fix_10ms(chan);
}
else
{ // FM RX mode
BK4819_WriteRegister(BK4819_REG_13, (lna_short << 8) | (lna << 5) | (mixer << 3) | (pga << 0));
}
#else
BK4819_WriteRegister(BK4819_REG_13, (lna_short << 8) | (lna << 5) | (mixer << 3) | (pga << 0));
#endif
BK4819_WriteRegister(BK4819_REG_13, (lna_short << 8) | (lna << 5) | (mixer << 3) | (pga << 0));
}
// AF gain - original QS values
@ -599,7 +562,7 @@ void APP_start_listening(function_type_t Function, const bool reset_am_fix)
#else
if (Function == FUNCTION_MONITOR)
#endif
{ // squelch is disabled
{ // monitor mode (open squelch)
if (g_screen_to_display != DISPLAY_MENU) // 1of11 .. don't close the menu
GUI_SelectNextDisplay(DISPLAY_MAIN);
}
@ -637,46 +600,53 @@ uint32_t APP_set_frequency_by_step(vfo_info_t *pInfo, int8_t Step)
void APP_stop_scan(void)
{
const uint8_t Previous = g_scan_restore_channel;
if (g_scan_state_dir == SCAN_STATE_DIR_OFF)
return; // but, but, we weren't doing anything !
// yes we were ;)
g_scan_state_dir = SCAN_STATE_DIR_OFF;
if (!g_scan_keep_frequency)
{
if (g_scan_next_channel <= USER_CHANNEL_LAST)
{
g_eeprom.user_channel[g_eeprom.rx_vfo] = g_scan_restore_channel;
g_eeprom.screen_channel[g_eeprom.rx_vfo] = Previous;
if (g_scan_restore_channel != 0xff || (g_scan_restore_frequency > 0 && g_scan_restore_frequency != 0xffffffff))
{ // revert to where we were before starting the scan
RADIO_ConfigureChannel(g_eeprom.rx_vfo, VFO_CONFIGURE_RELOAD);
if (g_scan_next_channel <= USER_CHANNEL_LAST)
{ // we were channel scanning
if (g_scan_restore_channel != 0xff)
{
g_eeprom.user_channel[g_eeprom.rx_vfo] = g_scan_restore_channel;
g_eeprom.screen_channel[g_eeprom.rx_vfo] = g_scan_restore_channel;
RADIO_configure_channel(g_eeprom.rx_vfo, VFO_CONFIGURE_RELOAD);
RADIO_setup_registers(true);
}
}
else
if (g_scan_restore_frequency > 0 && g_scan_restore_frequency != 0xffffffff)
{
g_rx_vfo->freq_config_rx.frequency = g_scan_restore_frequency;
RADIO_ApplyOffset(g_rx_vfo);
RADIO_ConfigureSquelchAndOutputPower(g_rx_vfo);
RADIO_setup_registers(true);
}
RADIO_setup_registers(true);
g_update_display = true;
return;
}
if (g_rx_vfo->channel_save > USER_CHANNEL_LAST)
else
{
RADIO_ApplyOffset(g_rx_vfo);
RADIO_ConfigureSquelchAndOutputPower(g_rx_vfo);
SETTINGS_SaveChannel(g_rx_vfo->channel_save, g_eeprom.rx_vfo, g_rx_vfo, 1);
return;
if (g_rx_vfo->channel_save > USER_CHANNEL_LAST)
{
RADIO_ApplyOffset(g_rx_vfo);
RADIO_ConfigureSquelchAndOutputPower(g_rx_vfo);
SETTINGS_SaveChannel(g_rx_vfo->channel_save, g_eeprom.rx_vfo, g_rx_vfo, 1);
return;
}
SETTINGS_SaveVfoIndices();
}
SETTINGS_SaveVfoIndices();
g_update_status = true;
}
@ -700,7 +670,7 @@ static void APP_next_freq(void)
#ifdef ENABLE_FASTER_CHANNEL_SCAN
g_scan_pause_10ms = 8; // 80ms
#else
g_scan_pause_10ms = scan_pause_6_10ms;
g_scan_pause_10ms = scan_pause_freq_10ms;
#endif
}
else
@ -711,11 +681,11 @@ static void APP_next_freq(void)
#ifdef ENABLE_FASTER_CHANNEL_SCAN
g_scan_pause_10ms = 10; // 100ms
#else
g_scan_pause_10ms = scan_pause_6_10ms;
g_scan_pause_10ms = scan_pause_freq_10ms;
#endif
}
g_scan_keep_frequency = false;
// g_scan_keep_frequency = false;
g_update_display = true;
}
@ -803,7 +773,7 @@ static void APP_next_channel(void)
g_eeprom.user_channel[g_eeprom.rx_vfo] = g_scan_next_channel;
g_eeprom.screen_channel[g_eeprom.rx_vfo] = g_scan_next_channel;
RADIO_ConfigureChannel(g_eeprom.rx_vfo, VFO_CONFIGURE_RELOAD);
RADIO_configure_channel(g_eeprom.rx_vfo, VFO_CONFIGURE_RELOAD);
RADIO_setup_registers(true);
g_update_display = true;
@ -812,10 +782,10 @@ static void APP_next_channel(void)
#ifdef ENABLE_FASTER_CHANNEL_SCAN
g_scan_pause_10ms = 9; // 90ms .. <= ~60ms it misses signals (squelch response and/or PLL lock time) ?
#else
g_scan_pause_10ms = scan_pause_3_10ms;
g_scan_pause_10ms = scan_pause_chan_10ms;
#endif
g_scan_keep_frequency = false;
// g_scan_keep_frequency = false;
if (enabled)
if (++g_scan_current_scan_list >= SCAN_NEXT_NUM)
@ -832,6 +802,10 @@ static void APP_next_channel(void)
static void APP_toggle_dual_watch_vfo(void)
{
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
UART_SendText("dual watch\r\n");
#endif
#ifdef ENABLE_NOAA
if (g_is_noaa_mode)
{
@ -856,9 +830,9 @@ static void APP_toggle_dual_watch_vfo(void)
RADIO_setup_registers(false);
#ifdef ENABLE_NOAA
g_dual_watch_count_down_10ms = g_is_noaa_mode ? dual_watch_count_noaa_10ms : dual_watch_count_toggle_10ms;
g_dual_watch_delay_10ms = g_is_noaa_mode ? dual_watch_delay_noaa_10ms : dual_watch_delay_toggle_10ms;
#else
g_dual_watch_count_down_10ms = dual_watch_count_toggle_10ms;
g_dual_watch_delay_10ms = dual_watch_delay_toggle_10ms;
#endif
}
@ -944,16 +918,14 @@ void APP_process_radio_interrupts(void)
{
if (g_current_function == FUNCTION_POWER_SAVE && !g_rx_idle_mode)
{
g_power_save_10ms = power_save2_10ms;
g_power_save_10ms = power_save2_10ms;
g_power_save_expired = false;
}
if (g_eeprom.dual_watch != DUAL_WATCH_OFF &&
(g_schedule_dual_watch || g_dual_watch_count_down_10ms < dual_watch_count_after_vox_10ms))
(g_dual_watch_delay_10ms == 0 || g_dual_watch_delay_10ms < dual_watch_delay_after_vox_10ms))
{
g_dual_watch_count_down_10ms = dual_watch_count_after_vox_10ms;
g_schedule_dual_watch = false;
g_dual_watch_delay_10ms = dual_watch_delay_after_vox_10ms;
g_update_status = true;
}
}
@ -1180,42 +1152,30 @@ void APP_process(void)
#endif
// toggle between the VFO's if dual watch is enabled
if (g_screen_to_display != DISPLAY_SEARCH && g_eeprom.dual_watch != DUAL_WATCH_OFF)
{
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
UART_SendText("dual watch\r\n");
if (g_eeprom.dual_watch != DUAL_WATCH_OFF &&
g_dual_watch_delay_10ms == 0 &&
!g_ptt_is_pressed &&
#ifdef ENABLE_VOICE
g_voice_write_index == 0 &&
#endif
#ifdef ENABLE_FMRADIO
!g_fm_radio_mode &&
#endif
g_dtmf_call_state == DTMF_CALL_STATE_NONE &&
g_screen_to_display != DISPLAY_SEARCH &&
g_scan_state_dir == SCAN_STATE_DIR_OFF &&
g_css_scan_mode == CSS_SCAN_MODE_OFF &&
g_current_function != FUNCTION_POWER_SAVE &&
(g_current_function == FUNCTION_FOREGROUND || g_current_function == FUNCTION_POWER_SAVE))
{
APP_toggle_dual_watch_vfo(); // toggle between the two VFO's
#ifdef ENABLE_VOICE
if (g_voice_write_index == 0)
#endif
{
if (g_schedule_dual_watch)
{
if (g_scan_state_dir == SCAN_STATE_DIR_OFF && g_css_scan_mode == CSS_SCAN_MODE_OFF)
{
#ifdef ENABLE_FMRADIO
if (!g_fm_radio_mode)
#endif
{
if (!g_ptt_is_pressed &&
g_dtmf_call_state == DTMF_CALL_STATE_NONE &&
g_current_function != FUNCTION_POWER_SAVE)
{
APP_toggle_dual_watch_vfo(); // toggle between the two VFO's
if (g_rx_vfo_is_active && g_screen_to_display == DISPLAY_MAIN)
GUI_SelectNextDisplay(DISPLAY_MAIN);
if (g_rx_vfo_is_active && g_screen_to_display == DISPLAY_MAIN)
GUI_SelectNextDisplay(DISPLAY_MAIN);
g_rx_vfo_is_active = false;
g_scan_pause_mode = false;
g_rx_reception_mode = RX_MODE_NONE;
g_schedule_dual_watch = false;
}
}
}
}
}
g_rx_vfo_is_active = false;
g_scan_pause_mode = false;
g_rx_reception_mode = RX_MODE_NONE;
}
#ifdef ENABLE_FMRADIO
@ -1311,7 +1271,6 @@ void APP_process(void)
g_css_scan_mode == CSS_SCAN_MODE_OFF)
{ // dual watch mode, toggle between the two VFO's
APP_toggle_dual_watch_vfo();
g_update_rssi = false;
}
@ -1599,7 +1558,7 @@ void APP_time_slice_10ms(void)
SETTINGS_SaveChannel(g_tx_vfo->channel_save, g_eeprom.tx_vfo, g_tx_vfo, g_flag_save_channel ? 1 : 0);
g_flag_save_channel = false;
RADIO_ConfigureChannel(g_eeprom.tx_vfo, VFO_CONFIGURE);
RADIO_configure_channel(g_eeprom.tx_vfo, VFO_CONFIGURE);
RADIO_setup_registers(true);
GUI_SelectNextDisplay(DISPLAY_MAIN);
@ -2179,8 +2138,8 @@ void APP_time_slice_500ms(void)
{
BK4819_StopScan();
RADIO_ConfigureChannel(0, VFO_CONFIGURE_RELOAD);
RADIO_ConfigureChannel(1, VFO_CONFIGURE_RELOAD);
RADIO_configure_channel(0, VFO_CONFIGURE_RELOAD);
RADIO_configure_channel(1, VFO_CONFIGURE_RELOAD);
RADIO_setup_registers(true);
}
@ -2395,9 +2354,10 @@ void APP_channel_next(const bool flag, const scan_state_dir_t scan_direction)
APP_next_freq();
}
g_scan_pause_10ms = scan_pause_2_10ms;
g_scan_pause_mode = false;
g_scan_keep_frequency = false;
g_scan_pause_10ms = scan_pause_css_10ms;
g_scan_pause_mode = false;
// g_scan_keep_frequency = false;
g_rx_reception_mode = RX_MODE_NONE;
}
@ -2522,7 +2482,8 @@ static void APP_process_key(const key_code_t Key, const bool key_pressed, const
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wtype-limits"
if (g_scan_state_dir != SCAN_STATE_DIR_OFF || g_css_scan_mode != CSS_SCAN_MODE_OFF)
// if (g_scan_state_dir != SCAN_STATE_DIR_OFF || g_css_scan_mode != CSS_SCAN_MODE_OFF)
if (g_css_scan_mode != CSS_SCAN_MODE_OFF)
{ // FREQ/CTCSS/CDCSS scanning
if ((Key >= KEY_0 && Key <= KEY_9) || Key == KEY_F)
@ -2800,12 +2761,12 @@ Skip:
if (g_flag_reset_vfos)
{
RADIO_ConfigureChannel(0, g_vfo_configure_mode);
RADIO_ConfigureChannel(1, g_vfo_configure_mode);
RADIO_configure_channel(0, g_vfo_configure_mode);
RADIO_configure_channel(1, g_vfo_configure_mode);
}
else
{
RADIO_ConfigureChannel(g_eeprom.tx_vfo, g_vfo_configure_mode);
RADIO_configure_channel(g_eeprom.tx_vfo, g_vfo_configure_mode);
}
if (g_request_display_screen == DISPLAY_INVALID)