diff --git a/app/aircopy.c b/app/aircopy.c index 32e4619..a4c3b13 100644 --- a/app/aircopy.c +++ b/app/aircopy.c @@ -621,7 +621,7 @@ static void AIRCOPY_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held) uint32_t Frequency; unsigned int i; - INPUTBOX_Append(Key); + INPUTBOX_append(Key); g_request_display_screen = DISPLAY_AIRCOPY; diff --git a/app/fm.c b/app/fm.c index 8023e8b..01dd410 100644 --- a/app/fm.c +++ b/app/fm.c @@ -261,7 +261,7 @@ static void FM_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held) State = g_eeprom.fm_is_channel_mode ? STATE_USER_MODE : STATE_FREQ_MODE; } - INPUTBOX_Append(Key); + INPUTBOX_append(Key); g_request_display_screen = DISPLAY_FM; diff --git a/app/main.c b/app/main.c index 57fc74b..5757191 100644 --- a/app/main.c +++ b/app/main.c @@ -145,7 +145,7 @@ void toggle_chan_scanlist(void) g_screen_to_display = DISPLAY_INVALID; GUI_SelectNextDisplay(DISPLAY_MENU); g_menu_cursor = MENU_MEM_SAVE; - g_is_in_sub_menu = true; + g_in_sub_menu = true; if (chan <= USER_CHANNEL_LAST) { #if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG) @@ -452,7 +452,7 @@ void MAIN_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held) // add the digit to the channel/frequency input box - INPUTBOX_Append(Key); + INPUTBOX_append(Key); g_request_display_screen = DISPLAY_MAIN; diff --git a/app/menu.c b/app/menu.c index 092ad4f..224627c 100644 --- a/app/menu.c +++ b/app/menu.c @@ -1320,11 +1320,11 @@ void MENU_ShowCurrentSetting(void) static void MENU_Key_0_to_9(key_code_t Key, bool key_pressed, bool key_held) { - uint8_t Offset; - int32_t Min; - int32_t Max; - uint16_t Value = 0; - + unsigned int index; + int32_t min; + int32_t max; + uint32_t value = 0; + if (key_held || !key_pressed) return; @@ -1357,11 +1357,11 @@ static void MENU_Key_0_to_9(key_code_t Key, bool key_pressed, bool key_held) return; } - INPUTBOX_Append(Key); + INPUTBOX_append(Key); g_request_display_screen = DISPLAY_MENU; - if (!g_is_in_sub_menu) + if (!g_in_sub_menu) { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wimplicit-fallthrough=" @@ -1371,26 +1371,26 @@ static void MENU_Key_0_to_9(key_code_t Key, bool key_pressed, bool key_held) case 2: g_input_box_index = 0; - Value = (g_input_box[0] * 10) + g_input_box[1]; + value = (g_input_box[0] * 10) + g_input_box[1]; - if (Value > 0 && Value <= g_menu_list_count) + if (value > 0 && value <= g_menu_list_count) { - g_menu_cursor = Value - 1; + g_menu_cursor = value - 1; g_flag_refresh_menu = true; return; } - if (Value <= g_menu_list_count) + if (value <= g_menu_list_count) break; g_input_box[0] = g_input_box[1]; g_input_box_index = 1; case 1: - Value = g_input_box[0]; - if (Value > 0 && Value <= g_menu_list_count) + value = g_input_box[0]; + if (value > 0 && value <= g_menu_list_count) { - g_menu_cursor = Value - 1; + g_menu_cursor = value - 1; g_flag_refresh_menu = true; return; } @@ -1410,19 +1410,39 @@ static void MENU_Key_0_to_9(key_code_t Key, bool key_pressed, bool key_held) uint32_t Frequency; if (g_input_box_index < 6) - { // invalid frequency -#ifdef ENABLE_VOICE + { // not yet enough characters + #ifdef ENABLE_VOICE g_another_voice_id = (voice_id_t)Key; -#endif + #endif return; } -#ifdef ENABLE_VOICE + #ifdef ENABLE_VOICE g_another_voice_id = (voice_id_t)Key; -#endif + #endif NUMBER_Get(g_input_box, &Frequency); - g_sub_menu_selection = FREQUENCY_FloorToStep(Frequency + 75, g_tx_vfo->step_freq, 0); + g_input_box_index = 0; + + g_sub_menu_selection = FREQUENCY_FloorToStep(Frequency + (g_tx_vfo->step_freq / 2), g_tx_vfo->step_freq, 0); + return; + } + + if (g_menu_cursor == MENU_BAT_CAL) + { + g_sub_menu_selection = INPUTBOX_value(); // get the current value from the input box + + if (g_input_box_index < 4) + { // not yet enough characters + #ifdef ENABLE_VOICE + g_another_voice_id = (voice_id_t)Key; + #endif + return; + } + + #ifdef ENABLE_VOICE + g_another_voice_id = (voice_id_t)Key; + #endif g_input_box_index = 0; return; @@ -1436,23 +1456,23 @@ static void MENU_Key_0_to_9(key_code_t Key, bool key_pressed, bool key_held) if (g_input_box_index < 3) { -#ifdef ENABLE_VOICE + #ifdef ENABLE_VOICE g_another_voice_id = (voice_id_t)Key; -#endif + #endif g_request_display_screen = DISPLAY_MENU; return; } g_input_box_index = 0; - Value = ((g_input_box[0] * 100) + (g_input_box[1] * 10) + g_input_box[2]) - 1; + value = ((g_input_box[0] * 100) + (g_input_box[1] * 10) + g_input_box[2]) - 1; - if (Value <= USER_CHANNEL_LAST) + if (value <= USER_CHANNEL_LAST) { // user channel -#ifdef ENABLE_VOICE + #ifdef ENABLE_VOICE g_another_voice_id = (voice_id_t)Key; -#endif - g_sub_menu_selection = Value; + #endif + g_sub_menu_selection = value; return; } @@ -1460,34 +1480,37 @@ static void MENU_Key_0_to_9(key_code_t Key, bool key_pressed, bool key_held) return; } - if (MENU_GetLimits(g_menu_cursor, &Min, &Max)) + if (MENU_GetLimits(g_menu_cursor, &min, &max)) { g_input_box_index = 0; g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; return; } - Offset = (Max >= 100) ? 3 : (Max >= 10) ? 2 : 1; - + index = (max >= 100000) ? 6 : (max >= 10000) ? 5 : (max >= 1000) ? 4 : (max >= 100) ? 3 : (max >= 10) ? 2 : 1; +// NUMBER_Get(g_input_box, &value); switch (g_input_box_index) { case 1: - Value = g_input_box[0]; + value = g_input_box[0]; break; case 2: - Value = (g_input_box[0] * 10) + g_input_box[1]; + value = (g_input_box[0] * 10) + g_input_box[1]; break; case 3: - Value = (g_input_box[0] * 100) + (g_input_box[1] * 10) + g_input_box[2]; + value = (g_input_box[0] * 100) + (g_input_box[1] * 10) + g_input_box[2]; + break; + case 4: + value = (g_input_box[0] * 1000) + (g_input_box[1] * 100) + (g_input_box[2] * 10) + g_input_box[3]; break; } - if (Offset == g_input_box_index) + if (index == g_input_box_index) g_input_box_index = 0; - if (Value <= Max) + if ((int32_t)value <= max) { - g_sub_menu_selection = Value; + g_sub_menu_selection = value; return; } @@ -1503,12 +1526,12 @@ static void MENU_Key_EXIT(bool key_pressed, bool key_held) if (g_css_scan_mode == CSS_SCAN_MODE_OFF) { - if (g_is_in_sub_menu) + if (g_in_sub_menu) { if (g_input_box_index == 0 || g_menu_cursor != MENU_OFFSET) { g_ask_for_confirmation = 0; - g_is_in_sub_menu = false; + g_in_sub_menu = false; g_input_box_index = 0; g_flag_refresh_menu = true; @@ -1559,7 +1582,7 @@ static void MENU_Key_MENU(const bool key_pressed, const bool key_held) g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL; g_request_display_screen = DISPLAY_MENU; - if (!g_is_in_sub_menu) + if (!g_in_sub_menu) { #ifdef ENABLE_VOICE if (g_menu_cursor != MENU_SCRAMBLER) @@ -1573,7 +1596,7 @@ static void MENU_Key_MENU(const bool key_pressed, const bool key_held) #endif g_ask_for_confirmation = 0; - g_is_in_sub_menu = true; + g_in_sub_menu = true; // if (g_menu_cursor != MENU_DTMF_LIST) { @@ -1616,7 +1639,7 @@ static void MENU_Key_MENU(const bool key_pressed, const bool key_held) if (memcmp(g_edit_original, g_edit, sizeof(g_edit_original)) == 0) { // no change - drop it g_flag_accept_setting = false; - g_is_in_sub_menu = false; + g_in_sub_menu = false; g_ask_for_confirmation = 0; } else @@ -1629,7 +1652,7 @@ static void MENU_Key_MENU(const bool key_pressed, const bool key_held) // exiting the sub menu - if (g_is_in_sub_menu) + if (g_in_sub_menu) { if (g_menu_cursor == MENU_RESET || g_menu_cursor == MENU_MEM_SAVE || @@ -1664,14 +1687,14 @@ static void MENU_Key_MENU(const bool key_pressed, const bool key_held) } g_flag_accept_setting = true; - g_is_in_sub_menu = false; + g_in_sub_menu = false; g_ask_for_confirmation = 0; } } else { g_flag_accept_setting = true; - g_is_in_sub_menu = false; + g_in_sub_menu = false; } } @@ -1757,7 +1780,7 @@ static void MENU_Key_UP_DOWN(bool key_pressed, bool key_held, int8_t Direction) uint8_t Channel; bool bCheckScanList; - if (g_menu_cursor == MENU_MEM_NAME && g_is_in_sub_menu && g_edit_index >= 0) + if (g_menu_cursor == MENU_MEM_NAME && g_in_sub_menu && g_edit_index >= 0) { // change the character if (key_pressed && g_edit_index < 10 && Direction != 0) { @@ -1801,7 +1824,7 @@ static void MENU_Key_UP_DOWN(bool key_pressed, bool key_held, int8_t Direction) return; } - if (!g_is_in_sub_menu) + if (!g_in_sub_menu) { g_menu_cursor = NUMBER_AddWithWraparound(g_menu_cursor, -Direction, 0, g_menu_list_count - 1); diff --git a/app/search.c b/app/search.c index d107790..bf4a5e9 100644 --- a/app/search.c +++ b/app/search.c @@ -60,7 +60,7 @@ static void SEARCH_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held) g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL; - INPUTBOX_Append(Key); + INPUTBOX_append(Key); g_request_display_screen = DISPLAY_SEARCH; diff --git a/firmware.bin b/firmware.bin index 3a676c4..d4be00f 100644 Binary files a/firmware.bin and b/firmware.bin differ diff --git a/firmware.packed.bin b/firmware.packed.bin index 77ca60d..65515b6 100644 Binary files a/firmware.packed.bin and b/firmware.packed.bin differ diff --git a/misc.c b/misc.c index 6945693..17ec1cc 100644 --- a/misc.c +++ b/misc.c @@ -305,16 +305,16 @@ unsigned int get_TX_VFO(void) void NUMBER_Get(char *pDigits, uint32_t *pInteger) { unsigned int i; - uint32_t Multiplier = 10000000; - uint32_t Value = 0; + uint32_t mul = 10000000; + uint32_t val = 0; for (i = 0; i < 8; i++) { if (pDigits[i] > 9) break; - Value += pDigits[i] * Multiplier; - Multiplier /= 10U; + val += pDigits[i] * mul; + mul /= 10u; } - *pInteger = Value; + *pInteger = val; } void NUMBER_ToDigits(uint32_t Value, char *pDigits) diff --git a/ui/inputbox.c b/ui/inputbox.c index f504268..6513902 100644 --- a/ui/inputbox.c +++ b/ui/inputbox.c @@ -21,7 +21,23 @@ char g_input_box[8]; uint8_t g_input_box_index; -void INPUTBOX_Append(const key_code_t Digit) +uint32_t INPUTBOX_value(void) +{ + int i = g_input_box_index; + uint32_t val = 0; + uint32_t mul = 1; + while (--i >= 0) + { + if (g_input_box[i] < 10) + { + val += (uint32_t)g_input_box[i] * mul; + mul *= 10; + } + } + return val; +} + +void INPUTBOX_append(const key_code_t Digit) { if (g_input_box_index >= sizeof(g_input_box)) return; diff --git a/ui/inputbox.h b/ui/inputbox.h index 5ca93d7..014121b 100644 --- a/ui/inputbox.h +++ b/ui/inputbox.h @@ -24,7 +24,8 @@ extern char g_input_box[8]; extern uint8_t g_input_box_index; -void INPUTBOX_Append(const key_code_t Digit); +uint32_t INPUTBOX_value(void); +void INPUTBOX_append(const key_code_t Digit); #endif diff --git a/ui/menu.c b/ui/menu.c index 187f1ea..2af5c38 100644 --- a/ui/menu.c +++ b/ui/menu.c @@ -381,7 +381,7 @@ const char g_sub_menu_SIDE_BUTT[9][16] = uint8_t g_menu_list_sorted[ARRAY_SIZE(g_menu_list)]; -bool g_is_in_sub_menu; +bool g_in_sub_menu; uint8_t g_menu_cursor; int8_t g_menu_scroll_direction; int32_t g_sub_menu_selection; @@ -478,7 +478,7 @@ void UI_DisplayMenu(void) g_frame_buffer[i][(8 * menu_list_width) + 1] = 0xAA; // draw the little sub-menu triangle marker - if (g_is_in_sub_menu) + if (g_in_sub_menu) memmove(g_frame_buffer[0] + (8 * menu_list_width) + 1, BITMAP_CurrentIndicator, sizeof(BITMAP_CurrentIndicator)); // draw the menu index number/count @@ -491,7 +491,7 @@ void UI_DisplayMenu(void) const int menu_index = g_menu_cursor; // current selected menu item i = 1; - if (!g_is_in_sub_menu) + if (!g_in_sub_menu) { while (i < 2) { // leading menu items - small text @@ -647,7 +647,7 @@ void UI_DisplayMenu(void) break; case MENU_OFFSET: - if (!g_is_in_sub_menu || g_input_box_index == 0) + if (!g_in_sub_menu || g_input_box_index == 0) { sprintf(String, "%d.%05u", g_sub_menu_selection / 100000, abs(g_sub_menu_selection) % 100000); UI_PrintString(String, menu_item_x1, menu_item_x2, 1, 8); @@ -655,7 +655,7 @@ void UI_DisplayMenu(void) else { for (i = 0; i < 3; i++) - String[i ] = (g_input_box[i] == 10) ? '-' : g_input_box[i] + '0'; + String[i + 0] = (g_input_box[i] == 10) ? '-' : g_input_box[i] + '0'; String[3] = '.'; for (i = 3; i < 6; i++) String[i + 1] = (g_input_box[i] == 10) ? '-' : g_input_box[i] + '0'; @@ -844,7 +844,7 @@ void UI_DisplayMenu(void) case MENU_MEM_NAME: { const bool valid = RADIO_CheckValidChannel(g_sub_menu_selection, false, 0); - const unsigned int y = (!g_is_in_sub_menu || g_edit_index < 0) ? 1 : 0; + const unsigned int y = (!g_in_sub_menu || g_edit_index < 0) ? 1 : 0; UI_GenerateChannelStringEx(String, valid ? "CH-" : "", g_sub_menu_selection); UI_PrintString(String, menu_item_x1, menu_item_x2, y, 8); @@ -853,7 +853,7 @@ void UI_DisplayMenu(void) { const uint32_t frequency = BOARD_fetchChannelFrequency(g_sub_menu_selection); - if (!g_is_in_sub_menu || g_edit_index < 0) + if (!g_in_sub_menu || g_edit_index < 0) { // show the channel name BOARD_fetchChannelName(String, g_sub_menu_selection); if (String[0] == 0) @@ -870,7 +870,7 @@ void UI_DisplayMenu(void) if (!g_ask_for_confirmation) { // show the frequency so that the user knows the channels frequency sprintf(String, "%u.%05u", frequency / 100000, frequency % 100000); - if (!g_is_in_sub_menu || g_edit_index < 0) + if (!g_in_sub_menu || g_edit_index < 0) UI_PrintString(String, menu_item_x1, menu_item_x2, y + 4, 8); else UI_PrintString(String, menu_item_x1, menu_item_x2, y + 5, 8); @@ -1116,7 +1116,7 @@ void UI_DisplayMenu(void) } break; -#ifdef ENABLE_F_CAL_MENU + #ifdef ENABLE_F_CAL_MENU case MENU_F_CALI: { const uint32_t value = 22656 + g_sub_menu_selection; @@ -1129,12 +1129,15 @@ void UI_DisplayMenu(void) xtal_Hz / 1000000, xtal_Hz % 1000000); } break; -#endif + #endif case MENU_BAT_CAL: { const uint16_t vol = (uint32_t)g_battery_voltage_average * g_battery_calibration[3] / g_sub_menu_selection; - sprintf(String, "%u.%02uV\n%u", vol / 100, vol % 100, g_sub_menu_selection); + if (!g_in_sub_menu || g_input_box_index == 0) + sprintf(String, "%u.%02uV\n%d", vol / 100, vol % 100, g_sub_menu_selection); + else + sprintf(String, "%u.%02uV\n%d\n%04d", vol / 100, vol % 100, g_battery_calibration[3], g_sub_menu_selection); break; } } @@ -1259,7 +1262,7 @@ void UI_DisplayMenu(void) g_menu_cursor == MENU_TX_CDCSS || g_menu_cursor == MENU_DTMF_LIST) { - if (g_is_in_sub_menu) + if (g_in_sub_menu) { unsigned int Offset; NUMBER_ToDigits(g_sub_menu_selection, String); diff --git a/ui/menu.h b/ui/menu.h index f7a077f..7821256 100644 --- a/ui/menu.h +++ b/ui/menu.h @@ -191,7 +191,7 @@ extern const char g_sub_MENU_SCRAMBLERAMBLER[11][7]; extern const char g_sub_menu_SIDE_BUTT[9][16]; #endif -extern bool g_is_in_sub_menu; +extern bool g_in_sub_menu; extern uint8_t g_menu_cursor; extern int8_t g_menu_scroll_direction; diff --git a/ui/ui.c b/ui/ui.c index 2b66d90..cf08385 100644 --- a/ui/ui.c +++ b/ui/ui.c @@ -86,7 +86,7 @@ void GUI_SelectNextDisplay(gui_display_type_t Display) DTMF_clear_input_box(); g_input_box_index = 0; - g_is_in_sub_menu = false; + g_in_sub_menu = false; g_css_scan_mode = CSS_SCAN_MODE_OFF; g_scan_state_dir = SCAN_STATE_DIR_OFF; #ifdef ENABLE_FMRADIO