0
mirror of https://github.com/OneOfEleven/uv-k5-firmware-custom.git synced 2025-04-28 14:21:25 +03:00

428 lines
8.9 KiB
C
Raw Normal View History

2023-09-09 08:03:56 +01:00
/* Copyright 2023 Dual Tachyon
* https://github.com/DualTachyon
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
2023-09-30 11:22:19 +01:00
#include <string.h>
2023-09-09 08:03:56 +01:00
#include "app/action.h"
#include "app/app.h"
#include "app/dtmf.h"
2023-09-14 09:56:30 +01:00
#ifdef ENABLE_FMRADIO
#include "app/fm.h"
#endif
2023-09-09 08:03:56 +01:00
#include "app/scanner.h"
#include "audio.h"
#include "bsp/dp32g030/gpio.h"
2023-09-14 09:56:30 +01:00
#ifdef ENABLE_FMRADIO
#include "driver/bk1080.h"
#endif
2023-09-09 08:03:56 +01:00
#include "driver/bk4819.h"
#include "driver/gpio.h"
#include "functions.h"
#include "misc.h"
#include "settings.h"
#include "ui/inputbox.h"
#include "ui/ui.h"
static void ACTION_FlashLight(void)
{
2023-10-08 20:23:37 +01:00
switch (g_flash_light_state)
2023-09-09 08:03:56 +01:00
{
case 0:
2023-10-08 20:23:37 +01:00
g_flash_light_state++;
2023-09-09 08:03:56 +01:00
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_FLASHLIGHT);
break;
case 1:
2023-10-08 20:23:37 +01:00
g_flash_light_state++;
2023-09-09 08:03:56 +01:00
break;
default:
2023-10-08 20:23:37 +01:00
g_flash_light_state = 0;
2023-09-09 08:03:56 +01:00
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_FLASHLIGHT);
}
}
void ACTION_Power(void)
{
2023-10-08 20:23:37 +01:00
if (++g_tx_vfo->output_power > OUTPUT_POWER_HIGH)
g_tx_vfo->output_power = OUTPUT_POWER_LOW;
2023-09-09 08:03:56 +01:00
2023-10-08 20:23:37 +01:00
g_request_save_channel = 1;
//g_request_save_channel = 2; // auto save the channel
2023-09-09 08:03:56 +01:00
2023-09-14 09:56:30 +01:00
#ifdef ENABLE_VOICE
2023-10-08 17:14:13 +01:00
g_another_voice_id = VOICE_ID_POWER;
2023-09-09 08:03:56 +01:00
#endif
2023-10-08 20:23:37 +01:00
g_request_display_screen = g_screen_to_display;
2023-09-09 08:03:56 +01:00
}
void ACTION_Monitor(void)
2023-09-09 08:03:56 +01:00
{
2023-10-08 20:23:37 +01:00
if (g_current_function != FUNCTION_MONITOR)
{ // enable the monitor
2023-09-09 08:03:56 +01:00
RADIO_SelectVfos();
2023-09-14 09:56:30 +01:00
#ifdef ENABLE_NOAA
2023-10-08 20:23:37 +01:00
if (g_rx_vfo->channel_save >= NOAA_CHANNEL_FIRST && g_is_noaa_mode)
g_noaa_channel = g_rx_vfo->channel_save - NOAA_CHANNEL_FIRST;
2023-09-09 08:03:56 +01:00
#endif
RADIO_SetupRegisters(true);
2023-09-22 13:52:17 +01:00
APP_StartListening(FUNCTION_MONITOR, false);
2023-09-09 08:03:56 +01:00
return;
}
2023-10-08 20:23:37 +01:00
g_monitor_enabled = false;
2023-10-08 20:23:37 +01:00
if (g_scan_state_dir != SCAN_OFF)
2023-09-09 08:03:56 +01:00
{
2023-10-08 20:23:37 +01:00
g_scan_pause_delay_in_10ms = scan_pause_delay_in_1_10ms;
g_schedule_scan_listen = false;
2023-10-05 23:58:55 +01:00
gScanPauseMode = true;
2023-09-09 08:03:56 +01:00
}
2023-09-14 09:56:30 +01:00
#ifdef ENABLE_NOAA
2023-10-08 20:23:37 +01:00
if (g_eeprom.dual_watch == DUAL_WATCH_OFF && g_is_noaa_mode)
2023-09-09 08:03:56 +01:00
{
2023-10-08 20:23:37 +01:00
g_noaa_count_down_10ms = noaa_count_down_10ms;
g_schedule_noaa = false;
2023-09-09 08:03:56 +01:00
}
#endif
2023-09-09 08:03:56 +01:00
RADIO_SetupRegisters(true);
2023-09-14 09:56:30 +01:00
#ifdef ENABLE_FMRADIO
2023-10-08 20:23:37 +01:00
if (g_fm_radio_mode)
2023-09-14 09:56:30 +01:00
{
FM_Start();
2023-10-08 20:23:37 +01:00
g_request_display_screen = DISPLAY_FM;
2023-09-14 09:56:30 +01:00
}
else
#endif
2023-10-08 20:23:37 +01:00
g_request_display_screen = g_screen_to_display;
2023-09-09 08:03:56 +01:00
}
void ACTION_Scan(bool bRestart)
{
2023-09-14 09:56:30 +01:00
#ifdef ENABLE_FMRADIO
2023-10-08 20:23:37 +01:00
if (g_fm_radio_mode)
2023-09-09 08:03:56 +01:00
{
2023-10-08 20:23:37 +01:00
if (g_current_function != FUNCTION_RECEIVE &&
g_current_function != FUNCTION_MONITOR &&
g_current_function != FUNCTION_TRANSMIT)
2023-09-09 08:03:56 +01:00
{
2023-09-14 09:56:30 +01:00
GUI_SelectNextDisplay(DISPLAY_FM);
2023-10-08 20:23:37 +01:00
g_monitor_enabled = false;
2023-10-08 20:23:37 +01:00
if (g_fm_scan_state != FM_SCAN_OFF)
2023-09-09 08:03:56 +01:00
{
2023-09-14 09:56:30 +01:00
FM_PlayAndUpdate();
2023-09-14 09:56:30 +01:00
#ifdef ENABLE_VOICE
2023-10-08 17:14:13 +01:00
g_another_voice_id = VOICE_ID_SCANNING_STOP;
2023-09-14 09:56:30 +01:00
#endif
2023-09-09 08:03:56 +01:00
}
else
{
2023-09-14 09:56:30 +01:00
uint16_t Frequency;
2023-09-14 09:56:30 +01:00
if (bRestart)
{
2023-10-08 20:23:37 +01:00
g_fm_auto_scan = true;
g_fm_channel_position = 0;
2023-09-14 09:56:30 +01:00
FM_EraseChannels();
2023-10-08 17:14:13 +01:00
Frequency = g_eeprom.fm_lower_limit;
2023-09-14 09:56:30 +01:00
}
else
{
2023-10-08 20:23:37 +01:00
g_fm_auto_scan = false;
g_fm_channel_position = 0;
2023-10-08 17:14:13 +01:00
Frequency = g_eeprom.fm_frequency_playing;
2023-09-14 09:56:30 +01:00
}
2023-09-14 09:56:30 +01:00
BK1080_GetFrequencyDeviation(Frequency);
FM_Tune(Frequency, 1, bRestart);
2023-09-14 09:56:30 +01:00
#ifdef ENABLE_VOICE
2023-10-08 17:14:13 +01:00
g_another_voice_id = VOICE_ID_SCANNING_BEGIN;
2023-09-14 09:56:30 +01:00
#endif
2023-09-09 08:03:56 +01:00
}
}
2023-09-14 09:56:30 +01:00
return;
2023-09-09 08:03:56 +01:00
}
2023-09-14 09:56:30 +01:00
#endif
2023-10-08 20:23:37 +01:00
if (g_screen_to_display != DISPLAY_SCANNER)
2023-09-20 11:23:45 +01:00
{ // not scanning
2023-10-08 20:23:37 +01:00
g_monitor_enabled = false;
2023-09-30 11:22:19 +01:00
DTMF_clear_RX();
2023-10-08 20:23:37 +01:00
g_dtmf_rx_live_timeout = 0;
memset(g_dtmf_rx_live, 0, sizeof(g_dtmf_rx_live));
2023-09-30 11:22:19 +01:00
2023-09-09 08:03:56 +01:00
RADIO_SelectVfos();
2023-09-14 09:56:30 +01:00
#ifdef ENABLE_NOAA
2023-10-08 20:23:37 +01:00
if (IS_NOT_NOAA_CHANNEL(g_rx_vfo->channel_save))
2023-09-09 08:03:56 +01:00
#endif
{
GUI_SelectNextDisplay(DISPLAY_MAIN);
2023-09-11 00:02:57 +01:00
2023-10-08 20:23:37 +01:00
if (g_scan_state_dir != SCAN_OFF)
2023-10-05 23:58:55 +01:00
{ // already scanning
2023-10-08 20:23:37 +01:00
if (g_next_channel <= USER_CHANNEL_LAST)
2023-10-05 23:58:55 +01:00
{ // channel mode
// keep scanning but toggle between scan lists
2023-10-08 17:14:13 +01:00
g_eeprom.scan_list_default = (g_eeprom.scan_list_default + 1) % 3;
2023-10-05 23:58:55 +01:00
// jump to the next channel
2023-10-08 20:23:37 +01:00
CHANNEL_Next(true, g_scan_state_dir);
g_scan_pause_delay_in_10ms = 1;
g_schedule_scan_listen = false;
2023-10-05 23:58:55 +01:00
2023-10-08 20:23:37 +01:00
g_update_status = true;
2023-10-05 23:58:55 +01:00
}
else
{ // stop scanning
2023-10-04 19:01:00 +01:00
SCANNER_Stop();
2023-09-11 00:02:57 +01:00
2023-10-04 19:01:00 +01:00
#ifdef ENABLE_VOICE
2023-10-08 17:14:13 +01:00
g_another_voice_id = VOICE_ID_SCANNING_STOP;
2023-10-04 19:01:00 +01:00
#endif
2023-10-05 23:58:55 +01:00
}
2023-09-09 08:03:56 +01:00
}
else
2023-10-05 23:58:55 +01:00
{ // start scanning
CHANNEL_Next(true, SCAN_FWD);
2023-09-11 00:02:57 +01:00
2023-09-14 09:56:30 +01:00
#ifdef ENABLE_VOICE
2023-09-09 08:03:56 +01:00
AUDIO_SetVoiceID(0, VOICE_ID_SCANNING_BEGIN);
AUDIO_PlaySingleVoice(true);
#endif
// clear the other vfo's rssi level (to hide the antenna symbol)
2023-10-08 20:23:37 +01:00
g_vfo_rssi_bar_level[(g_eeprom.rx_vfo + 1) & 1u] = 0;
// let the user see DW is not active
2023-10-08 20:23:37 +01:00
g_dual_watch_active = false;
g_update_status = true;
2023-09-09 08:03:56 +01:00
}
}
}
2023-09-20 11:23:45 +01:00
else
2023-10-05 23:58:55 +01:00
// if (!bRestart)
2023-10-08 20:23:37 +01:00
if (!bRestart && g_next_channel <= USER_CHANNEL_LAST)
2023-10-05 23:58:55 +01:00
{ // channel mode, keep scanning but toggle between scan lists
2023-10-08 17:14:13 +01:00
g_eeprom.scan_list_default = (g_eeprom.scan_list_default + 1) % 3;
2023-10-05 23:58:55 +01:00
// jump to the next channel
2023-10-08 20:23:37 +01:00
CHANNEL_Next(true, g_scan_state_dir);
g_scan_pause_delay_in_10ms = 1;
g_schedule_scan_listen = false;
2023-10-05 23:58:55 +01:00
2023-10-08 20:23:37 +01:00
g_update_status = true;
2023-10-04 18:54:26 +01:00
}
else
{ // stop scanning
2023-10-08 20:23:37 +01:00
g_monitor_enabled = false;
2023-10-04 18:54:26 +01:00
2023-09-20 11:23:45 +01:00
SCANNER_Stop();
2023-10-04 18:54:26 +01:00
2023-09-20 11:23:45 +01:00
#ifdef ENABLE_VOICE
2023-10-08 17:14:13 +01:00
g_another_voice_id = VOICE_ID_SCANNING_STOP;
2023-09-20 11:23:45 +01:00
#endif
2023-10-04 18:54:26 +01:00
2023-10-08 20:23:37 +01:00
g_request_display_screen = DISPLAY_MAIN;
2023-09-20 11:23:45 +01:00
}
2023-09-09 08:03:56 +01:00
}
#ifdef ENABLE_VOX
void ACTION_Vox(void)
{
2023-10-08 17:14:13 +01:00
g_eeprom.vox_switch = !g_eeprom.vox_switch;
2023-10-08 20:23:37 +01:00
g_request_save_settings = true;
g_flag_reconfigure_vfos = true;
#ifdef ENABLE_VOICE
2023-10-08 17:14:13 +01:00
g_another_voice_id = VOICE_ID_VOX;
#endif
2023-10-08 20:23:37 +01:00
g_update_status = true;
}
#endif
2023-09-09 08:03:56 +01:00
#if defined(ENABLE_ALARM) || defined(ENABLE_TX1750)
static void ACTION_AlarmOr1750(const bool b1750)
2023-09-09 09:01:52 +01:00
{
2023-10-08 20:23:37 +01:00
g_input_box_index = 0;
#if defined(ENABLE_ALARM) && defined(ENABLE_TX1750)
2023-10-08 20:23:37 +01:00
g_alarm_state = b1750 ? ALARM_STATE_TX1750 : ALARM_STATE_TXALARM;
g_alarm_running_counter = 0;
#elif defined(ENABLE_ALARM)
2023-10-08 20:23:37 +01:00
g_alarm_state = ALARM_STATE_TXALARM;
g_alarm_running_counter = 0;
#else
2023-10-08 20:23:37 +01:00
g_alarm_state = ALARM_STATE_TX1750;
#endif
2023-10-08 20:23:37 +01:00
g_flag_prepare_tx = true;
2023-10-03 00:14:36 +01:00
2023-10-08 20:23:37 +01:00
if (g_screen_to_display != DISPLAY_MENU) // 1of11 .. don't close the menu
g_request_display_screen = DISPLAY_MAIN;
2023-09-09 09:01:52 +01:00
}
#endif
2023-09-09 08:03:56 +01:00
2023-09-14 09:56:30 +01:00
#ifdef ENABLE_FMRADIO
void ACTION_FM(void)
2023-09-09 08:03:56 +01:00
{
2023-10-08 20:23:37 +01:00
if (g_current_function != FUNCTION_TRANSMIT && g_current_function != FUNCTION_MONITOR)
2023-09-09 08:03:56 +01:00
{
2023-10-08 20:23:37 +01:00
if (g_fm_radio_mode)
2023-09-14 09:56:30 +01:00
{
FM_TurnOff();
2023-10-08 20:23:37 +01:00
g_input_box_index = 0;
#ifdef ENABLE_VOX
2023-10-08 20:23:37 +01:00
g_vox_resume_count_down = 80;
#endif
2023-10-08 20:23:37 +01:00
g_flag_reconfigure_vfos = true;
2023-10-03 00:14:36 +01:00
2023-10-08 20:23:37 +01:00
g_request_display_screen = DISPLAY_MAIN;
2023-09-14 09:56:30 +01:00
return;
}
2023-10-08 20:23:37 +01:00
g_monitor_enabled = false;
2023-09-14 09:56:30 +01:00
RADIO_SelectVfos();
RADIO_SetupRegisters(true);
2023-09-14 09:56:30 +01:00
FM_Start();
2023-10-08 20:23:37 +01:00
g_input_box_index = 0;
2023-10-03 00:14:36 +01:00
2023-10-08 20:23:37 +01:00
g_request_display_screen = DISPLAY_FM;
2023-09-09 08:03:56 +01:00
}
}
2023-09-14 09:56:30 +01:00
#endif
2023-09-09 08:03:56 +01:00
2023-10-08 20:23:37 +01:00
void ACTION_Handle(key_code_t Key, bool key_pressed, bool key_held)
2023-09-09 08:03:56 +01:00
{
2023-09-12 11:01:34 +01:00
uint8_t Short = ACTION_OPT_NONE;
uint8_t Long = ACTION_OPT_NONE;
2023-09-09 08:03:56 +01:00
2023-10-08 20:23:37 +01:00
if (g_screen_to_display == DISPLAY_MAIN && g_dtmf_input_mode)
2023-09-09 08:03:56 +01:00
{
2023-10-08 20:23:37 +01:00
if (Key == KEY_SIDE1 && !key_held && key_pressed)
2023-09-09 08:03:56 +01:00
{
2023-10-08 20:23:37 +01:00
g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL;
2023-10-08 20:23:37 +01:00
if (g_dtmf_input_box_index > 0)
2023-09-09 08:03:56 +01:00
{
2023-10-08 20:23:37 +01:00
g_dtmf_input_box[--g_dtmf_input_box_index] = '-';
if (g_dtmf_input_box_index > 0)
2023-09-09 08:03:56 +01:00
{
2023-10-08 20:23:37 +01:00
g_ptt_was_released = true;
g_request_display_screen = DISPLAY_MAIN;
2023-09-09 08:03:56 +01:00
return;
}
}
2023-09-14 09:56:30 +01:00
#ifdef ENABLE_VOICE
2023-10-08 17:14:13 +01:00
g_another_voice_id = VOICE_ID_CANCEL;
2023-09-09 08:03:56 +01:00
#endif
2023-10-08 20:23:37 +01:00
g_request_display_screen = DISPLAY_MAIN;
g_dtmf_input_mode = false;
2023-09-09 08:03:56 +01:00
}
2023-10-08 20:23:37 +01:00
g_ptt_was_released = true;
2023-09-09 08:03:56 +01:00
return;
}
if (Key == KEY_SIDE1)
{
2023-10-08 17:14:13 +01:00
Short = g_eeprom.key1_short_press_action;
Long = g_eeprom.key1_long_press_action;
2023-09-09 08:03:56 +01:00
}
else
2023-09-12 11:01:34 +01:00
if (Key == KEY_SIDE2)
2023-09-09 08:03:56 +01:00
{
2023-10-08 17:14:13 +01:00
Short = g_eeprom.key2_short_press_action;
Long = g_eeprom.key2_long_press_action;
2023-09-09 08:03:56 +01:00
}
2023-10-08 20:23:37 +01:00
if (!key_held && key_pressed)
2023-09-09 08:03:56 +01:00
{
2023-10-08 20:23:37 +01:00
g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL;
2023-09-09 08:03:56 +01:00
return;
}
2023-10-08 20:23:37 +01:00
if (key_held || key_pressed)
2023-09-09 08:03:56 +01:00
{
2023-10-08 20:23:37 +01:00
if (!key_held)
2023-09-09 08:03:56 +01:00
return;
Short = Long;
2023-09-12 11:01:34 +01:00
2023-10-08 20:23:37 +01:00
if (!key_pressed)
2023-09-09 08:03:56 +01:00
return;
}
switch (Short)
{
2023-09-12 11:01:34 +01:00
default:
case ACTION_OPT_NONE:
2023-09-12 11:01:34 +01:00
break;
case ACTION_OPT_FLASHLIGHT:
2023-09-09 08:03:56 +01:00
ACTION_FlashLight();
break;
2023-09-12 11:01:34 +01:00
case ACTION_OPT_POWER:
2023-09-09 08:03:56 +01:00
ACTION_Power();
break;
2023-09-12 11:01:34 +01:00
case ACTION_OPT_MONITOR:
2023-09-09 08:03:56 +01:00
ACTION_Monitor();
break;
2023-09-12 11:01:34 +01:00
case ACTION_OPT_SCAN:
2023-09-09 08:03:56 +01:00
ACTION_Scan(true);
break;
2023-09-12 11:01:34 +01:00
case ACTION_OPT_VOX:
#ifdef ENABLE_VOX
ACTION_Vox();
#endif
2023-09-09 08:03:56 +01:00
break;
2023-09-12 11:01:34 +01:00
case ACTION_OPT_ALARM:
2023-09-14 09:56:30 +01:00
#ifdef ENABLE_ALARM
2023-09-09 09:01:52 +01:00
ACTION_AlarmOr1750(false);
#endif
2023-09-09 08:03:56 +01:00
break;
2023-09-14 09:56:30 +01:00
#ifdef ENABLE_FMRADIO
case ACTION_OPT_FM:
ACTION_FM();
break;
#endif
2023-09-12 11:01:34 +01:00
case ACTION_OPT_1750:
#ifdef ENABLE_TX1750
2023-09-09 09:01:52 +01:00
ACTION_AlarmOr1750(true);
#endif
2023-09-09 08:03:56 +01:00
break;
}
}