Refactor
This commit is contained in:
179
app/app.c
179
app/app.c
@@ -72,6 +72,10 @@
|
||||
#include "ui/status.h"
|
||||
#include "ui/ui.h"
|
||||
|
||||
static bool flagSaveVfo;
|
||||
static bool flagSaveSettings;
|
||||
static bool flagSaveChannel;
|
||||
|
||||
static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld);
|
||||
|
||||
|
||||
@@ -1564,32 +1568,27 @@ static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
|
||||
if (gEeprom.AUTO_KEYPAD_LOCK)
|
||||
gKeyLockCountdown = 30; // 15 seconds
|
||||
|
||||
if (!bKeyPressed) // key released
|
||||
{
|
||||
if (gFlagSaveVfo)
|
||||
{
|
||||
if (!bKeyPressed) { // key released
|
||||
if (flagSaveVfo) {
|
||||
SETTINGS_SaveVfoIndices();
|
||||
gFlagSaveVfo = false;
|
||||
flagSaveVfo = false;
|
||||
}
|
||||
|
||||
if (gFlagSaveSettings)
|
||||
{
|
||||
if (flagSaveSettings) {
|
||||
SETTINGS_SaveSettings();
|
||||
gFlagSaveSettings = false;
|
||||
flagSaveSettings = false;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_FMRADIO
|
||||
if (gFlagSaveFM)
|
||||
{
|
||||
SETTINGS_SaveFM();
|
||||
gFlagSaveFM = false;
|
||||
}
|
||||
#endif
|
||||
#ifdef ENABLE_FMRADIO
|
||||
if (gFlagSaveFM) {
|
||||
SETTINGS_SaveFM();
|
||||
gFlagSaveFM = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (gFlagSaveChannel)
|
||||
{
|
||||
SETTINGS_SaveChannel(gTxVfo->CHANNEL_SAVE, gEeprom.TX_VFO, gTxVfo, gFlagSaveChannel);
|
||||
gFlagSaveChannel = false;
|
||||
if (flagSaveChannel) {
|
||||
SETTINGS_SaveChannel(gTxVfo->CHANNEL_SAVE, gEeprom.TX_VFO, gTxVfo, flagSaveChannel);
|
||||
flagSaveChannel = false;
|
||||
|
||||
RADIO_ConfigureChannel(gEeprom.TX_VFO, VFO_CONFIGURE);
|
||||
RADIO_SetupRegisters(true);
|
||||
@@ -1597,8 +1596,7 @@ static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
|
||||
GUI_SelectNextDisplay(DISPLAY_MAIN);
|
||||
}
|
||||
}
|
||||
else // key pressed or held
|
||||
{
|
||||
else { // key pressed or held
|
||||
const int m = UI_MENU_GetCurrentMenuId();
|
||||
if ( //not when PTT and the backlight shouldn't turn on on TX
|
||||
!(Key == KEY_PTT && !(gSetting_backlight_on_tx_rx & BACKLIGHT_ON_TR_TX))
|
||||
@@ -1609,12 +1607,9 @@ static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
|
||||
BACKLIGHT_TurnOn();
|
||||
}
|
||||
|
||||
if (Key == KEY_EXIT && bKeyHeld)
|
||||
{ // exit key held pressed
|
||||
|
||||
if (Key == KEY_EXIT && bKeyHeld) { // exit key held pressed
|
||||
// clear the live DTMF decoder
|
||||
if (gDTMF_RX_live[0] != 0)
|
||||
{
|
||||
if (gDTMF_RX_live[0] != 0) {
|
||||
memset(gDTMF_RX_live, 0, sizeof(gDTMF_RX_live));
|
||||
gDTMF_RX_live_timeout = 0;
|
||||
gUpdateDisplay = true;
|
||||
@@ -1634,14 +1629,12 @@ static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
|
||||
gMenuCountdown = menu_timeout_500ms;
|
||||
|
||||
#ifdef ENABLE_DTMF_CALLING
|
||||
if (gDTMF_DecodeRingCountdown_500ms > 0)
|
||||
{ // cancel the ringing
|
||||
if (gDTMF_DecodeRingCountdown_500ms > 0) { // cancel the ringing
|
||||
gDTMF_DecodeRingCountdown_500ms = 0;
|
||||
|
||||
AUDIO_PlayBeep(BEEP_1KHZ_60MS_OPTIONAL);
|
||||
|
||||
if (Key != KEY_PTT)
|
||||
{
|
||||
if (Key != KEY_PTT) {
|
||||
gPttWasReleased = true;
|
||||
return;
|
||||
}
|
||||
@@ -1662,14 +1655,11 @@ static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
|
||||
return;
|
||||
}
|
||||
|
||||
if (Key == KEY_F)
|
||||
{ // function/key-lock key
|
||||
|
||||
if (Key == KEY_F) { // function/key-lock key
|
||||
if (!bKeyPressed)
|
||||
return;
|
||||
|
||||
if (!bKeyHeld)
|
||||
{ // keypad is locked, tell the user
|
||||
if (!bKeyHeld) { // keypad is locked, tell the user
|
||||
AUDIO_PlayBeep(BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL);
|
||||
gKeypadLocked = 4; // 2 seconds
|
||||
gUpdateDisplay = true;
|
||||
@@ -1694,10 +1684,8 @@ static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
|
||||
}
|
||||
}
|
||||
|
||||
if (Key <= KEY_9 || Key == KEY_F)
|
||||
{
|
||||
if (gScanStateDir != SCAN_OFF || gCssBackgroundScan)
|
||||
{ // FREQ/CTCSS/DCS scanning
|
||||
if (Key <= KEY_9 || Key == KEY_F) {
|
||||
if (gScanStateDir != SCAN_OFF || gCssBackgroundScan) { // FREQ/CTCSS/DCS scanning
|
||||
if (bKeyPressed && !bKeyHeld)
|
||||
AUDIO_PlayBeep(BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL);
|
||||
return;
|
||||
@@ -1705,31 +1693,26 @@ static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
|
||||
}
|
||||
|
||||
bool bFlag = false;
|
||||
if (Key == KEY_PTT)
|
||||
{
|
||||
if (gPttWasPressed)
|
||||
{
|
||||
if (Key == KEY_PTT) {
|
||||
if (gPttWasPressed) {
|
||||
bFlag = bKeyHeld;
|
||||
if (!bKeyPressed)
|
||||
{
|
||||
if (!bKeyPressed) {
|
||||
bFlag = true;
|
||||
gPttWasPressed = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (gPttWasReleased)
|
||||
{
|
||||
else if (gPttWasReleased) {
|
||||
if (bKeyHeld)
|
||||
bFlag = true;
|
||||
if (!bKeyPressed)
|
||||
{
|
||||
if (!bKeyPressed) {
|
||||
bFlag = true;
|
||||
gPttWasReleased = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (gWasFKeyPressed && (Key == KEY_PTT || Key == KEY_EXIT || Key == KEY_SIDE1 || Key == KEY_SIDE2))
|
||||
{ // cancel the F-key
|
||||
if (gWasFKeyPressed && (Key == KEY_PTT || Key == KEY_EXIT || Key == KEY_SIDE1 || Key == KEY_SIDE2)) {
|
||||
// cancel the F-key
|
||||
gWasFKeyPressed = false;
|
||||
gUpdateStatus = true;
|
||||
}
|
||||
@@ -1745,30 +1728,23 @@ static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
|
||||
{
|
||||
char Code;
|
||||
|
||||
if (Key == KEY_PTT)
|
||||
{
|
||||
if (Key == KEY_PTT) {
|
||||
GENERIC_Key_PTT(bKeyPressed);
|
||||
goto Skip;
|
||||
}
|
||||
|
||||
if (Key == KEY_SIDE2)
|
||||
{ // transmit 1750Hz tone
|
||||
if (Key == KEY_SIDE2) { // transmit 1750Hz tone
|
||||
Code = 0xFE;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
else {
|
||||
Code = DTMF_GetCharacter(Key - KEY_0);
|
||||
if (Code == 0xFF)
|
||||
goto Skip;
|
||||
|
||||
// transmit DTMF keys
|
||||
}
|
||||
|
||||
if (!bKeyPressed || bKeyHeld)
|
||||
{
|
||||
if (!bKeyPressed)
|
||||
{
|
||||
if (!bKeyPressed || bKeyHeld) {
|
||||
if (!bKeyPressed) {
|
||||
AUDIO_AudioPathOff();
|
||||
|
||||
gEnableSpeaker = false;
|
||||
@@ -1781,10 +1757,8 @@ static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
|
||||
BK4819_EnableScramble(gCurrentVfo->SCRAMBLING_TYPE - 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (gEeprom.DTMF_SIDE_TONE)
|
||||
{ // user will here the DTMF tones in speaker
|
||||
else {
|
||||
if (gEeprom.DTMF_SIDE_TONE) { // user will here the DTMF tones in speaker
|
||||
AUDIO_AudioPathOn();
|
||||
gEnableSpeaker = true;
|
||||
}
|
||||
@@ -1808,8 +1782,7 @@ static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
|
||||
|
||||
if (Key == KEY_PTT)
|
||||
gPttWasPressed = true;
|
||||
else
|
||||
if (!bKeyHeld)
|
||||
else if (!bKeyHeld)
|
||||
gPttWasReleased = true;
|
||||
}
|
||||
#endif
|
||||
@@ -1829,14 +1802,12 @@ static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
|
||||
}
|
||||
|
||||
Skip:
|
||||
if (gBeepToPlay != BEEP_NONE)
|
||||
{
|
||||
if (gBeepToPlay != BEEP_NONE) {
|
||||
AUDIO_PlayBeep(gBeepToPlay);
|
||||
gBeepToPlay = BEEP_NONE;
|
||||
}
|
||||
|
||||
if (gFlagAcceptSetting)
|
||||
{
|
||||
if (gFlagAcceptSetting) {
|
||||
gMenuCountdown = menu_timeout_500ms;
|
||||
|
||||
MENU_AcceptSetting();
|
||||
@@ -1845,19 +1816,17 @@ Skip:
|
||||
gFlagAcceptSetting = false;
|
||||
}
|
||||
|
||||
if (gRequestSaveSettings)
|
||||
{
|
||||
if (gRequestSaveSettings) {
|
||||
if (!bKeyHeld)
|
||||
SETTINGS_SaveSettings();
|
||||
else
|
||||
gFlagSaveSettings = 1;
|
||||
flagSaveSettings = 1;
|
||||
gRequestSaveSettings = false;
|
||||
gUpdateStatus = true;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_FMRADIO
|
||||
if (gRequestSaveFM)
|
||||
{
|
||||
if (gRequestSaveFM) {
|
||||
gRequestSaveFM = false;
|
||||
if (!bKeyHeld)
|
||||
SETTINGS_SaveFM();
|
||||
@@ -1866,28 +1835,24 @@ Skip:
|
||||
}
|
||||
#endif
|
||||
|
||||
if (gRequestSaveVFO)
|
||||
{
|
||||
if (gRequestSaveVFO) {
|
||||
gRequestSaveVFO = false;
|
||||
if (!bKeyHeld)
|
||||
SETTINGS_SaveVfoIndices();
|
||||
else
|
||||
gFlagSaveVfo = true;
|
||||
flagSaveVfo = true;
|
||||
}
|
||||
|
||||
if (gRequestSaveChannel > 0) // TODO: remove the gRequestSaveChannel, why use global variable for that??
|
||||
{
|
||||
if (!bKeyHeld)
|
||||
{
|
||||
if (gRequestSaveChannel > 0) { // TODO: remove the gRequestSaveChannel, why use global variable for that??
|
||||
if (!bKeyHeld) {
|
||||
SETTINGS_SaveChannel(gTxVfo->CHANNEL_SAVE, gEeprom.TX_VFO, gTxVfo, gRequestSaveChannel);
|
||||
|
||||
if (!SCANNER_IsScanning())
|
||||
if (gVfoConfigureMode == VFO_CONFIGURE_NONE) // 'if' is so as we don't wipe out previously setting this variable elsewhere
|
||||
gVfoConfigureMode = VFO_CONFIGURE;
|
||||
if (!SCANNER_IsScanning() && gVfoConfigureMode == VFO_CONFIGURE_NONE)
|
||||
// gVfoConfigureMode is so as we don't wipe out previously setting this variable elsewhere
|
||||
gVfoConfigureMode = VFO_CONFIGURE;
|
||||
}
|
||||
else
|
||||
{
|
||||
gFlagSaveChannel = gRequestSaveChannel;
|
||||
else { // this is probably so settings are not saved when up/down button is held and save is postponed to btn release
|
||||
flagSaveChannel = gRequestSaveChannel;
|
||||
|
||||
if (gRequestDisplayScreen == DISPLAY_INVALID)
|
||||
gRequestDisplayScreen = DISPLAY_MAIN;
|
||||
@@ -1896,10 +1861,8 @@ Skip:
|
||||
gRequestSaveChannel = 0;
|
||||
}
|
||||
|
||||
if (gVfoConfigureMode != VFO_CONFIGURE_NONE)
|
||||
{
|
||||
if (gFlagResetVfos)
|
||||
{
|
||||
if (gVfoConfigureMode != VFO_CONFIGURE_NONE) {
|
||||
if (gFlagResetVfos) {
|
||||
RADIO_ConfigureChannel(0, gVfoConfigureMode);
|
||||
RADIO_ConfigureChannel(1, gVfoConfigureMode);
|
||||
}
|
||||
@@ -1914,8 +1877,7 @@ Skip:
|
||||
gFlagResetVfos = false;
|
||||
}
|
||||
|
||||
if (gFlagReconfigureVfos)
|
||||
{
|
||||
if (gFlagReconfigureVfos) {
|
||||
RADIO_SelectVfos();
|
||||
|
||||
#ifdef ENABLE_NOAA
|
||||
@@ -1940,29 +1902,26 @@ Skip:
|
||||
ACTION_Monitor(); // 1of11
|
||||
}
|
||||
|
||||
if (gFlagRefreshSetting)
|
||||
{
|
||||
if (gFlagRefreshSetting) {
|
||||
gFlagRefreshSetting = false;
|
||||
gMenuCountdown = menu_timeout_500ms;
|
||||
|
||||
MENU_ShowCurrentSetting();
|
||||
}
|
||||
|
||||
if (gFlagPrepareTX)
|
||||
{
|
||||
if (gFlagPrepareTX) {
|
||||
RADIO_PrepareTX();
|
||||
gFlagPrepareTX = false;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_VOICE
|
||||
if (gAnotherVoiceID != VOICE_ID_INVALID)
|
||||
{
|
||||
if (gAnotherVoiceID < 76)
|
||||
AUDIO_SetVoiceID(0, gAnotherVoiceID);
|
||||
AUDIO_PlaySingleVoice(false);
|
||||
gAnotherVoiceID = VOICE_ID_INVALID;
|
||||
}
|
||||
#endif
|
||||
#ifdef ENABLE_VOICE
|
||||
if (gAnotherVoiceID != VOICE_ID_INVALID) {
|
||||
if (gAnotherVoiceID < 76)
|
||||
AUDIO_SetVoiceID(0, gAnotherVoiceID);
|
||||
AUDIO_PlaySingleVoice(false);
|
||||
gAnotherVoiceID = VOICE_ID_INVALID;
|
||||
}
|
||||
#endif
|
||||
|
||||
GUI_SelectNextDisplay(gRequestDisplayScreen);
|
||||
gRequestDisplayScreen = DISPLAY_INVALID;
|
||||
|
Reference in New Issue
Block a user