This commit is contained in:
Krzysiek Egzmont
2024-01-12 21:55:04 +01:00
parent 4efabfc2b6
commit 04b0bd8c93
6 changed files with 156 additions and 277 deletions

View File

@@ -156,7 +156,7 @@ void ACTION_Monitor(void)
} }
else else
#endif #endif
gRequestDisplayScreen = gScreenToDisplay; gRequestDisplayScreen = gScreenToDisplay;
} }
void ACTION_Scan(bool bRestart) void ACTION_Scan(bool bRestart)

179
app/app.c
View File

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

View File

@@ -75,27 +75,17 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep)
{ {
uint8_t Vfo = gEeprom.TX_VFO; uint8_t Vfo = gEeprom.TX_VFO;
if (gScreenToDisplay == DISPLAY_MENU) if (gScreenToDisplay == DISPLAY_MENU) {
{ gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
// if (beep)
gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
return; return;
} }
// if (beep) gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL;
gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL;
switch (Key) switch (Key) {
{
case KEY_0: case KEY_0:
#ifdef ENABLE_FMRADIO #ifdef ENABLE_FMRADIO
ACTION_FM(); ACTION_FM();
#else
// TODO: make use of this function key
#endif #endif
break; break;
@@ -106,14 +96,12 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep)
gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL;
#ifdef ENABLE_COPY_CHAN_TO_VFO #ifdef ENABLE_COPY_CHAN_TO_VFO
if (!gEeprom.VFO_OPEN || gCssBackgroundScan) if (!gEeprom.VFO_OPEN || gCssBackgroundScan) {
{
gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
return; return;
} }
if (gScanStateDir != SCAN_OFF) if (gScanStateDir != SCAN_OFF) {
{
if (gCurrentFunction != FUNCTION_INCOMING || if (gCurrentFunction != FUNCTION_INCOMING ||
gRxReceptionMode == RX_MODE_NONE || gRxReceptionMode == RX_MODE_NONE ||
gScanPauseDelayIn_10ms == 0) gScanPauseDelayIn_10ms == 0)
@@ -149,7 +137,6 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep)
return; return;
} }
#endif #endif
gTxVfo->Band += 1; gTxVfo->Band += 1;
if (gTxVfo->Band == BAND5_350MHz && !gSetting_350EN) { if (gTxVfo->Band == BAND5_350MHz && !gSetting_350EN) {
@@ -204,13 +191,10 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep)
case KEY_5: case KEY_5:
if(beep) { if(beep) {
#ifdef ENABLE_NOAA #ifdef ENABLE_NOAA
if (!IS_NOAA_CHANNEL(gTxVfo->CHANNEL_SAVE)) {
if (!IS_NOAA_CHANNEL(gTxVfo->CHANNEL_SAVE))
{
gEeprom.ScreenChannel[Vfo] = gEeprom.NoaaChannel[gEeprom.TX_VFO]; gEeprom.ScreenChannel[Vfo] = gEeprom.NoaaChannel[gEeprom.TX_VFO];
} }
else else {
{
gEeprom.ScreenChannel[Vfo] = gEeprom.FreqChannel[gEeprom.TX_VFO]; gEeprom.ScreenChannel[Vfo] = gEeprom.FreqChannel[gEeprom.TX_VFO];
#ifdef ENABLE_VOICE #ifdef ENABLE_VOICE
gAnotherVoiceID = VOICE_ID_FREQUENCY_MODE; gAnotherVoiceID = VOICE_ID_FREQUENCY_MODE;
@@ -249,8 +233,7 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep)
break; break;
case KEY_9: case KEY_9:
if (RADIO_CheckValidChannel(gEeprom.CHAN_1_CALL, false, 0)) if (RADIO_CheckValidChannel(gEeprom.CHAN_1_CALL, false, 0)) {
{
gEeprom.MrChannel[Vfo] = gEeprom.CHAN_1_CALL; gEeprom.MrChannel[Vfo] = gEeprom.CHAN_1_CALL;
gEeprom.ScreenChannel[Vfo] = gEeprom.CHAN_1_CALL; gEeprom.ScreenChannel[Vfo] = gEeprom.CHAN_1_CALL;
#ifdef ENABLE_VOICE #ifdef ENABLE_VOICE
@@ -279,15 +262,10 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep)
static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
{ {
if (bKeyHeld) if (bKeyHeld) { // key held down
{ // key held down if (bKeyPressed) {
if (gScreenToDisplay == DISPLAY_MAIN) {
if (bKeyPressed) if (gInputBoxIndex > 0) { // delete any inputted chars
{
if (gScreenToDisplay == DISPLAY_MAIN)
{
if (gInputBoxIndex > 0)
{ // delete any inputted chars
gInputBoxIndex = 0; gInputBoxIndex = 0;
gRequestDisplayScreen = DISPLAY_MAIN; gRequestDisplayScreen = DISPLAY_MAIN;
} }
@@ -298,7 +276,6 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
processFKeyFunction(Key, false); processFKeyFunction(Key, false);
} }
} }
return; return;
} }
@@ -308,22 +285,15 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
return; // don't use the key till it's released return; // don't use the key till it's released
} }
if (!gWasFKeyPressed) if (!gWasFKeyPressed) { // F-key wasn't pressed
{ // F-key wasn't pressed
const uint8_t Vfo = gEeprom.TX_VFO; const uint8_t Vfo = gEeprom.TX_VFO;
gKeyInputCountdown = key_input_timeout_500ms; gKeyInputCountdown = key_input_timeout_500ms;
INPUTBOX_Append(Key); INPUTBOX_Append(Key);
gRequestDisplayScreen = DISPLAY_MAIN; gRequestDisplayScreen = DISPLAY_MAIN;
if (IS_MR_CHANNEL(gTxVfo->CHANNEL_SAVE)) if (IS_MR_CHANNEL(gTxVfo->CHANNEL_SAVE)) { // user is entering channel number
{ // user is entering channel number
if (gInputBoxIndex != 3) if (gInputBoxIndex != 3) {
{
#ifdef ENABLE_VOICE #ifdef ENABLE_VOICE
gAnotherVoiceID = (VOICE_ID_t)Key; gAnotherVoiceID = (VOICE_ID_t)Key;
#endif #endif
@@ -335,8 +305,7 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
const uint16_t Channel = ((gInputBox[0] * 100) + (gInputBox[1] * 10) + gInputBox[2]) - 1; const uint16_t Channel = ((gInputBox[0] * 100) + (gInputBox[1] * 10) + gInputBox[2]) - 1;
if (!RADIO_CheckValidChannel(Channel, false, 0)) if (!RADIO_CheckValidChannel(Channel, false, 0)) {
{
gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
return; return;
} }
@@ -363,8 +332,7 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
gAnotherVoiceID = (VOICE_ID_t)Key; gAnotherVoiceID = (VOICE_ID_t)Key;
#endif #endif
bool isGigaF = gTxVfo->pRX->Frequency >= _1GHz_in_KHz; bool isGigaF = gTxVfo->pRX->Frequency >= _1GHz_in_KHz;
if (gInputBoxIndex < 6 + isGigaF) if (gInputBoxIndex < 6 + isGigaF) {
{
return; return;
} }
@@ -372,26 +340,20 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
uint32_t Frequency = StrToUL(INPUTBOX_GetAscii()) * 100; uint32_t Frequency = StrToUL(INPUTBOX_GetAscii()) * 100;
// clamp the frequency entered to some valid value // clamp the frequency entered to some valid value
if (Frequency < frequencyBandTable[0].lower) if (Frequency < frequencyBandTable[0].lower) {
{
Frequency = frequencyBandTable[0].lower; Frequency = frequencyBandTable[0].lower;
} }
else else if (Frequency >= BX4819_band1.upper && Frequency < BX4819_band2.lower) {
if (Frequency >= BX4819_band1.upper && Frequency < BX4819_band2.lower)
{
const uint32_t center = (BX4819_band1.upper + BX4819_band2.lower) / 2; const uint32_t center = (BX4819_band1.upper + BX4819_band2.lower) / 2;
Frequency = (Frequency < center) ? BX4819_band1.upper : BX4819_band2.lower; Frequency = (Frequency < center) ? BX4819_band1.upper : BX4819_band2.lower;
} }
else else if (Frequency > frequencyBandTable[BAND_N_ELEM - 1].upper) {
if (Frequency > frequencyBandTable[BAND_N_ELEM - 1].upper)
{
Frequency = frequencyBandTable[BAND_N_ELEM - 1].upper; Frequency = frequencyBandTable[BAND_N_ELEM - 1].upper;
} }
const FREQUENCY_Band_t band = FREQUENCY_GetBand(Frequency); const FREQUENCY_Band_t band = FREQUENCY_GetBand(Frequency);
if (gTxVfo->Band != band) if (gTxVfo->Band != band) {
{
gTxVfo->Band = band; gTxVfo->Band = band;
gEeprom.ScreenChannel[Vfo] = band + FREQ_CHANNEL_FIRST; gEeprom.ScreenChannel[Vfo] = band + FREQ_CHANNEL_FIRST;
gEeprom.FreqChannel[Vfo] = band + FREQ_CHANNEL_FIRST; gEeprom.FreqChannel[Vfo] = band + FREQ_CHANNEL_FIRST;
@@ -419,8 +381,7 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
else else
if (IS_NOAA_CHANNEL(gTxVfo->CHANNEL_SAVE)) if (IS_NOAA_CHANNEL(gTxVfo->CHANNEL_SAVE))
{ // user is entering NOAA channel { // user is entering NOAA channel
if (gInputBoxIndex != 2) if (gInputBoxIndex != 2) {
{
#ifdef ENABLE_VOICE #ifdef ENABLE_VOICE
gAnotherVoiceID = (VOICE_ID_t)Key; gAnotherVoiceID = (VOICE_ID_t)Key;
#endif #endif
@@ -431,8 +392,7 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
gInputBoxIndex = 0; gInputBoxIndex = 0;
uint8_t Channel = (gInputBox[0] * 10) + gInputBox[1]; uint8_t Channel = (gInputBox[0] * 10) + gInputBox[1];
if (Channel >= 1 && Channel <= ARRAY_SIZE(NoaaFrequencyTable)) if (Channel >= 1 && Channel <= ARRAY_SIZE(NoaaFrequencyTable)) {
{
Channel += NOAA_CHANNEL_FIRST; Channel += NOAA_CHANNEL_FIRST;
#ifdef ENABLE_VOICE #ifdef ENABLE_VOICE
gAnotherVoiceID = (VOICE_ID_t)Key; gAnotherVoiceID = (VOICE_ID_t)Key;
@@ -521,22 +481,16 @@ static void MAIN_Key_EXIT(bool bKeyPressed, bool bKeyHeld)
static void MAIN_Key_MENU(const bool bKeyPressed, const bool bKeyHeld) static void MAIN_Key_MENU(const bool bKeyPressed, const bool bKeyHeld)
{ {
if (bKeyPressed && !bKeyHeld) if (bKeyPressed && !bKeyHeld) // menu key pressed
// menu key pressed
gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL;
if (bKeyHeld) if (bKeyHeld) { // menu key held down (long press)
{ // menu key held down (long press) if (bKeyPressed) { // long press MENU key
if (bKeyPressed)
{ // long press MENU key
gWasFKeyPressed = false; gWasFKeyPressed = false;
if (gScreenToDisplay == DISPLAY_MAIN) if (gScreenToDisplay == DISPLAY_MAIN) {
{ if (gInputBoxIndex > 0) { // delete any inputted chars
if (gInputBoxIndex > 0)
{ // delete any inputted chars
gInputBoxIndex = 0; gInputBoxIndex = 0;
gRequestDisplayScreen = DISPLAY_MAIN; gRequestDisplayScreen = DISPLAY_MAIN;
} }
@@ -551,13 +505,11 @@ static void MAIN_Key_MENU(const bool bKeyPressed, const bool bKeyHeld)
return; return;
} }
if (!bKeyPressed && !gDTMF_InputMode) if (!bKeyPressed && !gDTMF_InputMode) { // menu key released
{ // menu key released
const bool bFlag = !gInputBoxIndex; const bool bFlag = !gInputBoxIndex;
gInputBoxIndex = 0; gInputBoxIndex = 0;
if (bFlag) if (bFlag) {
{
if (gScanStateDir != SCAN_OFF) { if (gScanStateDir != SCAN_OFF) {
CHFRSCANNER_Stop(); CHFRSCANNER_Stop();
return; return;
@@ -569,8 +521,7 @@ static void MAIN_Key_MENU(const bool bKeyPressed, const bool bKeyHeld)
gAnotherVoiceID = VOICE_ID_MENU; gAnotherVoiceID = VOICE_ID_MENU;
#endif #endif
} }
else else {
{
gRequestDisplayScreen = DISPLAY_MAIN; gRequestDisplayScreen = DISPLAY_MAIN;
} }
} }
@@ -581,15 +532,13 @@ static void MAIN_Key_STAR(bool bKeyPressed, bool bKeyHeld)
if (gCurrentFunction == FUNCTION_TRANSMIT) if (gCurrentFunction == FUNCTION_TRANSMIT)
return; return;
if (gInputBoxIndex) if (gInputBoxIndex) {
{
if (!bKeyHeld && bKeyPressed) if (!bKeyHeld && bKeyPressed)
gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
return; return;
} }
if (bKeyHeld && !gWasFKeyPressed) // long press if (bKeyHeld && !gWasFKeyPressed){ // long press
{
if (!bKeyPressed) // released if (!bKeyPressed) // released
return; return;
@@ -599,8 +548,7 @@ static void MAIN_Key_STAR(bool bKeyPressed, bool bKeyHeld)
return; return;
} }
if (bKeyPressed) // just pressed if (bKeyPressed) { // just pressed
{
return; return;
} }
@@ -639,7 +587,6 @@ static void MAIN_Key_STAR(bool bKeyPressed, bool bKeyHeld)
return; return;
} }
#endif #endif
// scan the CTCSS/DCS code // scan the CTCSS/DCS code
gBackup_CROSS_BAND_RX_TX = gEeprom.CROSS_BAND_RX_TX; gBackup_CROSS_BAND_RX_TX = gEeprom.CROSS_BAND_RX_TX;
gEeprom.CROSS_BAND_RX_TX = CROSS_BAND_OFF; gEeprom.CROSS_BAND_RX_TX = CROSS_BAND_OFF;
@@ -655,58 +602,43 @@ static void MAIN_Key_UP_DOWN(bool bKeyPressed, bool bKeyHeld, int8_t Direction)
{ {
uint8_t Channel = gEeprom.ScreenChannel[gEeprom.TX_VFO]; uint8_t Channel = gEeprom.ScreenChannel[gEeprom.TX_VFO];
if (bKeyHeld || !bKeyPressed) if (bKeyHeld || !bKeyPressed) { // key held or released
{
if (gInputBoxIndex > 0) if (gInputBoxIndex > 0)
return; return; // leave if input box active
if (!bKeyPressed) if (!bKeyPressed) {
{ if (!bKeyHeld || IS_FREQ_CHANNEL(Channel))
if (!bKeyHeld)
return; return;
// if released long button press and not in freq mode
if (IS_FREQ_CHANNEL(Channel)) #ifdef ENABLE_VOICE
return; AUDIO_SetDigitVoice(0, gTxVfo->CHANNEL_SAVE + 1); // say channel number
gAnotherVoiceID = (VOICE_ID_t)0xFE;
#ifdef ENABLE_VOICE #endif
AUDIO_SetDigitVoice(0, gTxVfo->CHANNEL_SAVE + 1);
gAnotherVoiceID = (VOICE_ID_t)0xFE;
#endif
return; return;
} }
} }
else else { // short pressed
{ if (gInputBoxIndex > 0) {
if (gInputBoxIndex > 0)
{
gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
return; return;
} }
gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL;
} }
if (gScanStateDir == SCAN_OFF) if (gScanStateDir == SCAN_OFF) {
{ #ifdef ENABLE_NOAA
#ifdef ENABLE_NOAA if (!IS_NOAA_CHANNEL(Channel))
if (!IS_NOAA_CHANNEL(Channel)) #endif
#endif
{ {
uint8_t Next; uint8_t Next;
if (IS_FREQ_CHANNEL(Channel)) { // step/down in frequency
if (IS_FREQ_CHANNEL(Channel))
{ // step/down in frequency
const uint32_t frequency = APP_SetFrequencyByStep(gTxVfo, Direction); const uint32_t frequency = APP_SetFrequencyByStep(gTxVfo, Direction);
if (RX_freq_check(frequency) < 0) if (RX_freq_check(frequency) < 0) { // frequency not allowed
{ // frequency not allowed
gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
return; return;
} }
gTxVfo->freq_config_RX.Frequency = frequency; gTxVfo->freq_config_RX.Frequency = frequency;
gRequestSaveChannel = 1; gRequestSaveChannel = 1;
return; return;
} }
@@ -714,29 +646,25 @@ static void MAIN_Key_UP_DOWN(bool bKeyPressed, bool bKeyHeld, int8_t Direction)
Next = RADIO_FindNextChannel(Channel + Direction, Direction, false, 0); Next = RADIO_FindNextChannel(Channel + Direction, Direction, false, 0);
if (Next == 0xFF) if (Next == 0xFF)
return; return;
if (Channel == Next) if (Channel == Next)
return; return;
gEeprom.MrChannel[gEeprom.TX_VFO] = Next;
gEeprom.MrChannel[gEeprom.TX_VFO] = Next;
gEeprom.ScreenChannel[gEeprom.TX_VFO] = Next; gEeprom.ScreenChannel[gEeprom.TX_VFO] = Next;
if (!bKeyHeld) if (!bKeyHeld) {
{ #ifdef ENABLE_VOICE
#ifdef ENABLE_VOICE AUDIO_SetDigitVoice(0, Next + 1);
AUDIO_SetDigitVoice(0, Next + 1); gAnotherVoiceID = (VOICE_ID_t)0xFE;
gAnotherVoiceID = (VOICE_ID_t)0xFE; #endif
#endif
} }
} }
#ifdef ENABLE_NOAA #ifdef ENABLE_NOAA
else else {
{ Channel = NOAA_CHANNEL_FIRST + NUMBER_AddWithWraparound(gEeprom.ScreenChannel[gEeprom.TX_VFO] - NOAA_CHANNEL_FIRST, Direction, 0, 9);
Channel = NOAA_CHANNEL_FIRST + NUMBER_AddWithWraparound(gEeprom.ScreenChannel[gEeprom.TX_VFO] - NOAA_CHANNEL_FIRST, Direction, 0, 9); gEeprom.NoaaChannel[gEeprom.TX_VFO] = Channel;
gEeprom.NoaaChannel[gEeprom.TX_VFO] = Channel; gEeprom.ScreenChannel[gEeprom.TX_VFO] = Channel;
gEeprom.ScreenChannel[gEeprom.TX_VFO] = Channel; }
} #endif
#endif
gRequestSaveVFO = true; gRequestSaveVFO = true;
gVfoConfigureMode = VFO_CONFIGURE_RELOAD; gVfoConfigureMode = VFO_CONFIGURE_RELOAD;
@@ -746,24 +674,22 @@ static void MAIN_Key_UP_DOWN(bool bKeyPressed, bool bKeyHeld, int8_t Direction)
// jump to the next channel // jump to the next channel
CHFRSCANNER_Start(false, Direction); CHFRSCANNER_Start(false, Direction);
gScanPauseDelayIn_10ms = 1; gScanPauseDelayIn_10ms = 1;
gScheduleScanListen = false; gScheduleScanListen = false;
gPttWasReleased = true; gPttWasReleased = true;
} }
void MAIN_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) void MAIN_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
{ {
#ifdef ENABLE_FMRADIO #ifdef ENABLE_FMRADIO
if (gFmRadioMode && Key != KEY_PTT && Key != KEY_EXIT) if (gFmRadioMode && Key != KEY_PTT && Key != KEY_EXIT) {
{ if (!bKeyHeld && bKeyPressed)
if (!bKeyHeld && bKeyPressed) gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; return;
return; }
} #endif
#endif
if (gDTMF_InputMode && bKeyPressed && !bKeyHeld) if (gDTMF_InputMode && bKeyPressed && !bKeyHeld) {
{
const char Character = DTMF_GetCharacter(Key); const char Character = DTMF_GetCharacter(Key);
if (Character != 0xFF) if (Character != 0xFF)
{ // add key to DTMF string { // add key to DTMF string
@@ -782,18 +708,8 @@ void MAIN_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
// Key = KEY_SIDE2; // what's this doing ??? // Key = KEY_SIDE2; // what's this doing ???
// } // }
switch (Key) switch (Key) {
{ case KEY_0...KEY_9:
case KEY_0:
case KEY_1:
case KEY_2:
case KEY_3:
case KEY_4:
case KEY_5:
case KEY_6:
case KEY_7:
case KEY_8:
case KEY_9:
MAIN_Key_DIGITS(Key, bKeyPressed, bKeyHeld); MAIN_Key_DIGITS(Key, bKeyPressed, bKeyHeld);
break; break;
case KEY_MENU: case KEY_MENU:

View File

@@ -14,6 +14,16 @@ static inline void LogUart(const char *const str)
UART_Send(str, strlen(str)); UART_Send(str, strlen(str));
} }
static inline void LogUartf(const char* format, ...)
{
char buffer[128];
va_list va;
va_start(va, format);
vsnprintf(buffer, (size_t)-1, format, va);
va_end(va);
UART_Send(buffer, strlen(buffer));
}
static inline void LogRegUart(uint16_t reg) static inline void LogRegUart(uint16_t reg)
{ {
uint16_t regVal = BK4819_ReadRegister(reg); uint16_t regVal = BK4819_ReadRegister(reg);

3
misc.c
View File

@@ -181,9 +181,6 @@ bool gFlagPrepareTX;
bool gFlagAcceptSetting; bool gFlagAcceptSetting;
bool gFlagRefreshSetting; bool gFlagRefreshSetting;
bool gFlagSaveVfo;
bool gFlagSaveSettings;
bool gFlagSaveChannel;
#ifdef ENABLE_FMRADIO #ifdef ENABLE_FMRADIO
bool gFlagSaveFM; bool gFlagSaveFM;
#endif #endif

3
misc.h
View File

@@ -260,9 +260,6 @@ extern bool gFlagPrepareTX;
extern bool gFlagAcceptSetting; // accept menu setting extern bool gFlagAcceptSetting; // accept menu setting
extern bool gFlagRefreshSetting; // refresh menu display extern bool gFlagRefreshSetting; // refresh menu display
extern bool gFlagSaveVfo;
extern bool gFlagSaveSettings;
extern bool gFlagSaveChannel;
#ifdef ENABLE_FMRADIO #ifdef ENABLE_FMRADIO
extern bool gFlagSaveFM; extern bool gFlagSaveFM;
#endif #endif