0
mirror of https://github.com/OneOfEleven/uv-k5-firmware-custom.git synced 2025-06-19 06:39:49 +03:00

fix unable to enter freq/chan

This commit is contained in:
OneOfEleven
2023-11-05 10:48:37 +00:00
parent 359fa3bf47
commit 4bc506a0f7
9 changed files with 111 additions and 91 deletions

View File

@ -1233,6 +1233,11 @@ void APP_check_keys(void)
// *****************
// PTT is treated completely separately from all the other buttons
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
// if (g_input_box_index > 0)
// UART_printf("1 index %u %u\r\n", g_input_box_index, g_flash_light_blink_tick_10ms);
#endif
if (ptt_pressed)
{ // PTT pressed
@ -1262,24 +1267,28 @@ void APP_check_keys(void)
else
{ // PTT released
#ifdef ENABLE_KILL_REVIVE
if (g_ptt_is_pressed || g_serial_config_tick_500ms > 0 || !g_eeprom.config.setting.tx_enable || g_eeprom.config.setting.radio_disabled)
#else
if (g_ptt_is_pressed || g_serial_config_tick_500ms > 0 || !g_eeprom.config.setting.tx_enable)
#endif
if (g_ptt_is_pressed || g_serial_config_tick_500ms > 0)
{
if (--g_ptt_debounce <= 0)
{ // stop TX'ing
g_ptt_is_pressed = false;
g_ptt_was_released = true;
g_ptt_debounce = 0;
APP_process_key(KEY_PTT, false, false);
// if (g_ptt_debounce > 0)
{
if (--g_ptt_debounce <= 0)
{ // stop TX'ing
g_ptt_is_pressed = false;
g_ptt_was_released = true;
g_ptt_debounce = 0;
APP_process_key(KEY_PTT, false, false);
}
}
}
}
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
// if (g_input_box_index > 0)
// UART_printf("2 index %u %u\r\n", g_input_box_index, g_flash_light_blink_tick_10ms);
#endif
// *****************
// button processing (non-PTT)
@ -1326,6 +1335,7 @@ void APP_check_keys(void)
// g_update_display = true;
}
}
if (g_key_debounce_repeat > 0)
g_key_debounce_repeat--;
}
@ -2503,9 +2513,9 @@ static void APP_process_key(const key_code_t Key, const bool key_pressed, const
g_schedule_power_save_tick_10ms = battery_save_count_10ms;
#ifdef ENABLE_KEYLOCK
// keep the auto keylock at bay
if (g_eeprom.config.setting.auto_key_lock != 0)
g_key_lock_tick_500ms = key_lock_timeout_500ms;
// keep the auto keylock at bay
if (g_eeprom.config.setting.auto_key_lock != 0)
g_key_lock_tick_500ms = key_lock_timeout_500ms;
#endif
if (g_fkey_pressed && (Key == KEY_PTT || Key == KEY_EXIT || Key == KEY_SIDE1 || Key == KEY_SIDE2))
@ -2561,10 +2571,6 @@ static void APP_process_key(const key_code_t Key, const bool key_pressed, const
}
#endif
// key beep
// if (Key != KEY_PTT && !key_held && key_pressed)
// g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL;
// ********************
if (Key == KEY_EXIT && key_held && key_pressed)

View File

@ -444,6 +444,10 @@ void MAIN_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held)
g_key_input_count_down = key_input_timeout_500ms;
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
UART_printf("key0 %u\r\n", Key);
#endif
if (key_held)
{ // key held down
@ -483,7 +487,10 @@ void MAIN_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held)
return;
}
if (g_scan_state_dir != SCAN_STATE_DIR_OFF || g_current_function == FUNCTION_TRANSMIT)
if (g_current_function == FUNCTION_TRANSMIT)
return;
if (g_scan_state_dir != SCAN_STATE_DIR_OFF)
{
g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
return;
@ -493,16 +500,20 @@ void MAIN_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held)
INPUTBOX_append(Key);
UI_DisplayMain();
// UI_DisplayMain();
// g_request_display_screen = DISPLAY_MAIN;
g_request_display_screen = DISPLAY_MAIN;
if (IS_USER_CHANNEL(g_tx_vfo->channel_save))
{ // user is entering channel number
uint16_t Channel;
const unsigned int chan = ((g_input_box[0] * 100) + (g_input_box[1] * 10) + g_input_box[2]) - 1;
if (g_input_box_index != 3)
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
UART_printf("key2 %u %u\r\n", chan, g_input_box_index);
#endif
if (g_input_box_index < 3)
{
#ifdef ENABLE_VOICE
g_another_voice_id = (voice_id_t)Key;
@ -512,9 +523,7 @@ void MAIN_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held)
g_input_box_index = 0;
Channel = ((g_input_box[0] * 100) + (g_input_box[1] * 10) + g_input_box[2]) - 1;
if (!RADIO_CheckValidChannel(Channel, false, 0))
if (!RADIO_CheckValidChannel(chan, false, 0))
{
g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
return;
@ -524,8 +533,8 @@ void MAIN_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held)
g_another_voice_id = (voice_id_t)Key;
#endif
g_eeprom.config.setting.indices.vfo[vfo].user = (uint8_t)Channel;
g_eeprom.config.setting.indices.vfo[vfo].screen = (uint8_t)Channel;
g_eeprom.config.setting.indices.vfo[vfo].user = chan;
g_eeprom.config.setting.indices.vfo[vfo].screen = chan;
g_request_save_vfo = true;
g_vfo_configure_mode = VFO_CONFIGURE_RELOAD;
@ -536,7 +545,13 @@ void MAIN_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held)
if (IS_FREQ_CHANNEL(g_tx_vfo->channel_save))
{ // user is entering a frequency
uint32_t Frequency;
uint32_t freq;
NUMBER_Get(g_input_box, &freq);
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
UART_printf("key2 %u %u\r\n", freq, g_input_box_index);
#endif
if (g_input_box_index < 6)
{
@ -548,23 +563,21 @@ void MAIN_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held)
g_input_box_index = 0;
NUMBER_Get(g_input_box, &Frequency);
// clamp the frequency entered to some valid value
if (Frequency < FREQ_BAND_TABLE[0].lower)
Frequency = FREQ_BAND_TABLE[0].lower;
if (freq < FREQ_BAND_TABLE[0].lower)
freq = FREQ_BAND_TABLE[0].lower;
else
if (Frequency >= BX4819_BAND1.upper && Frequency < BX4819_BAND2.lower)
if (freq >= BX4819_BAND1.upper && freq < BX4819_BAND2.lower)
{
const uint32_t center = (BX4819_BAND1.upper + BX4819_BAND2.lower) / 2;
Frequency = (Frequency < center) ? BX4819_BAND1.upper : BX4819_BAND2.lower;
freq = (freq < center) ? BX4819_BAND1.upper : BX4819_BAND2.lower;
}
else
if (Frequency > FREQ_BAND_TABLE[ARRAY_SIZE(FREQ_BAND_TABLE) - 1].upper)
Frequency = FREQ_BAND_TABLE[ARRAY_SIZE(FREQ_BAND_TABLE) - 1].upper;
if (freq > FREQ_BAND_TABLE[ARRAY_SIZE(FREQ_BAND_TABLE) - 1].upper)
freq = FREQ_BAND_TABLE[ARRAY_SIZE(FREQ_BAND_TABLE) - 1].upper;
{
const frequency_band_t band = FREQUENCY_GetBand(Frequency);
const frequency_band_t band = FREQUENCY_GetBand(freq);
#ifdef ENABLE_VOICE
g_another_voice_id = (voice_id_t)Key;
@ -582,21 +595,21 @@ void MAIN_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held)
}
#if 0
Frequency += g_tx_vfo->step_freq / 2; // for rounding to nearest step size
Frequency = FREQUENCY_floor_to_step(Frequency, g_tx_vfo->step_freq, FREQ_BAND_TABLE[g_tx_vfo->channel_attributes.band].lower, FREQ_BAND_TABLE[g_tx_vfo->channel_attributes.band].upper);
freq += g_tx_vfo->step_freq / 2; // for rounding to nearest step size
freq = FREQUENCY_floor_to_step(freq, g_tx_vfo->step_freq, FREQ_BAND_TABLE[g_tx_vfo->channel_attributes.band].lower, FREQ_BAND_TABLE[g_tx_vfo->channel_attributes.band].upper);
#endif
if (Frequency >= BX4819_BAND1.upper && Frequency < BX4819_BAND2.lower)
if (freq >= BX4819_BAND1.upper && freq < BX4819_BAND2.lower)
{ // clamp the frequency to the limit
const uint32_t center = (BX4819_BAND1.upper + BX4819_BAND2.lower) / 2;
Frequency = (Frequency < center) ? BX4819_BAND1.upper - g_tx_vfo->step_freq : BX4819_BAND2.lower;
freq = (freq < center) ? BX4819_BAND1.upper - g_tx_vfo->step_freq : BX4819_BAND2.lower;
}
g_tx_vfo->freq_config_rx.frequency = Frequency;
g_tx_vfo->freq_config_tx.frequency = Frequency;
g_tx_vfo->freq_config_rx.frequency = freq;
g_tx_vfo->freq_config_tx.frequency = freq;
// find the first channel that contains this frequency
g_tx_vfo->freq_in_channel = SETTINGS_find_channel(Frequency);
g_tx_vfo->freq_in_channel = SETTINGS_find_channel(freq);
g_request_save_channel = 1;
g_vfo_configure_mode = VFO_CONFIGURE;