Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
egzumer committed Jan 13, 2024
1 parent 4efabfc commit 04b0bd8
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 277 deletions.
2 changes: 1 addition & 1 deletion app/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void ACTION_Monitor(void)
}
else
#endif
gRequestDisplayScreen = gScreenToDisplay;
gRequestDisplayScreen = gScreenToDisplay;
}

void ACTION_Scan(bool bRestart)
Expand Down
179 changes: 69 additions & 110 deletions app/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);


Expand Down Expand Up @@ -1564,41 +1568,35 @@ 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);

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))
Expand All @@ -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;
Expand All @@ -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;
}
Expand All @@ -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;
Expand All @@ -1694,42 +1684,35 @@ 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;
}
}

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;
}
Expand All @@ -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;
Expand All @@ -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;
}
Expand All @@ -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
Expand All @@ -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();
Expand All @@ -1845,19 +1816,17 @@ static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
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();
Expand All @@ -1866,28 +1835,24 @@ static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
}
#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;
Expand All @@ -1896,10 +1861,8 @@ static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
gRequestSaveChannel = 0;
}

if (gVfoConfigureMode != VFO_CONFIGURE_NONE)
{
if (gFlagResetVfos)
{
if (gVfoConfigureMode != VFO_CONFIGURE_NONE) {
if (gFlagResetVfos) {
RADIO_ConfigureChannel(0, gVfoConfigureMode);
RADIO_ConfigureChannel(1, gVfoConfigureMode);
}
Expand All @@ -1914,8 +1877,7 @@ static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
gFlagResetVfos = false;
}

if (gFlagReconfigureVfos)
{
if (gFlagReconfigureVfos) {
RADIO_SelectVfos();

#ifdef ENABLE_NOAA
Expand All @@ -1940,29 +1902,26 @@ static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
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;
Expand Down
Loading

0 comments on commit 04b0bd8

Please sign in to comment.