Skip to content

Commit

Permalink
FM radio button actions changed to be the same as in VFO mode
Browse files Browse the repository at this point in the history
  • Loading branch information
egzumer committed Nov 27, 2023
1 parent 3c64320 commit fe49f25
Showing 1 changed file with 55 additions and 49 deletions.
104 changes: 55 additions & 49 deletions app/fm.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ bool gFM_FoundFrequency;
bool gFM_AutoScan;
uint16_t gFM_RestoreCountdown_10ms;



const uint8_t BUTTON_STATE_PRESSED = 1 << 0;
const uint8_t BUTTON_STATE_HELD = 1 << 1;

const uint8_t BUTTON_EVENT_PRESSED = BUTTON_STATE_PRESSED;
const uint8_t BUTTON_EVENT_HELD = BUTTON_STATE_PRESSED | BUTTON_STATE_HELD;
const uint8_t BUTTON_EVENT_SHORT = 0;
const uint8_t BUTTON_EVENT_LONG = BUTTON_STATE_HELD;


static void Key_FUNC(KEY_Code_t Key, uint8_t state);

bool FM_CheckValidChannel(uint8_t Channel)
{
return (Channel < ARRAY_SIZE(gFM_Channels) && (gFM_Channels[Channel] >= 760 && gFM_Channels[Channel] < 1080)) ? true : false;
Expand Down Expand Up @@ -223,12 +236,11 @@ int FM_CheckFrequencyLock(uint16_t Frequency, uint16_t LowerLimit)
return ret;
}

static void FM_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
static void Key_DIGITS(KEY_Code_t Key, uint8_t state)
{
enum { STATE_FREQ_MODE, STATE_MR_MODE, STATE_SAVE };

if (!bKeyHeld && !bKeyPressed) {
if (!gWasFKeyPressed) {
if (state == BUTTON_EVENT_SHORT && !gWasFKeyPressed) {
uint8_t State;

if (gAskToDelete) {
Expand Down Expand Up @@ -317,9 +329,16 @@ static void FM_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
#ifdef ENABLE_VOICE
gAnotherVoiceID = (VOICE_ID_t)Key;
#endif
}
else
Key_FUNC(Key, state);
}

return;
}
static void Key_FUNC(KEY_Code_t Key, uint8_t state)
{
if (state == BUTTON_EVENT_SHORT || state == BUTTON_EVENT_HELD)
{
bool autoScan = gWasFKeyPressed || (state == BUTTON_EVENT_HELD);

gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL;
gWasFKeyPressed = false;
Expand All @@ -331,7 +350,7 @@ static void FM_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
ACTION_FM();
break;

case KEY_1:
case KEY_3:
gEeprom.FM_IsMrMode = !gEeprom.FM_IsMrMode;

if (!FM_ConfigureChannelState())
Expand All @@ -343,12 +362,8 @@ static void FM_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
break;

case KEY_2:
ACTION_Scan(true);
break;

case KEY_3:
ACTION_Scan(false);
case KEY_STAR:
ACTION_Scan(autoScan);
break;

default:
Expand All @@ -358,12 +373,9 @@ static void FM_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
}
}

static void FM_Key_EXIT(bool bKeyPressed, bool bKeyHeld)
static void Key_EXIT(uint8_t state)
{
if (bKeyHeld)
return;

if (!bKeyPressed)
if (state != BUTTON_EVENT_SHORT)
return;

gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL;
Expand Down Expand Up @@ -418,13 +430,11 @@ static void FM_Key_EXIT(bool bKeyPressed, bool bKeyHeld)
gRequestDisplayScreen = DISPLAY_FM;
}

static void FM_Key_MENU(bool bKeyPressed, bool bKeyHeld)
static void Key_MENU(uint8_t state)
{
if (bKeyHeld)
if (state != BUTTON_EVENT_SHORT)
return;

if (!bKeyPressed)
return;

gRequestDisplayScreen = DISPLAY_FM;
gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL;
Expand Down Expand Up @@ -478,38 +488,29 @@ static void FM_Key_MENU(bool bKeyPressed, bool bKeyHeld)
}
}

static void FM_Key_UP_DOWN(bool bKeyPressed, bool bKeyHeld, int8_t Step)
static void Key_UP_DOWN(uint8_t state, int8_t Step)
{
if (bKeyHeld || !bKeyPressed)
{
if (gInputBoxIndex)
return;

if (!bKeyPressed)
return;
}
else
{
if (gInputBoxIndex)
{
if (state == BUTTON_EVENT_PRESSED) {
if (gInputBoxIndex) {
gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
return;
}

gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL;
}
else {
if (gInputBoxIndex || state!=BUTTON_EVENT_HELD)
return;
}

if (gAskToSave)
{
if (gAskToSave) {
gRequestDisplayScreen = DISPLAY_FM;
gFM_ChannelPosition = NUMBER_AddWithWraparound(gFM_ChannelPosition, Step, 0, 19);
return;
}

if (gFM_ScanState != FM_SCAN_OFF)
{
if (gFM_AutoScan)
{
if (gFM_ScanState != FM_SCAN_OFF) {
if (gFM_AutoScan) {
gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
return;
}
Expand All @@ -519,17 +520,15 @@ static void FM_Key_UP_DOWN(bool bKeyPressed, bool bKeyHeld, int8_t Step)
return;
}

if (gEeprom.FM_IsMrMode)
{
if (gEeprom.FM_IsMrMode) {
const uint8_t Channel = FM_FindNextChannel(gEeprom.FM_SelectedChannel + Step, Step);
if (Channel == 0xFF || gEeprom.FM_SelectedChannel == Channel)
goto Bail;

gEeprom.FM_SelectedChannel = Channel;
gEeprom.FM_FrequencyPlaying = gFM_Channels[Channel];
}
else
{
else {
uint16_t Frequency = gEeprom.FM_SelectedFrequency + Step;
if (Frequency < gEeprom.FM_LowerLimit)
Frequency = gEeprom.FM_UpperLimit;
Expand All @@ -551,6 +550,10 @@ static void FM_Key_UP_DOWN(bool bKeyPressed, bool bKeyHeld, int8_t Step)

void FM_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
{
uint8_t state = bKeyPressed + 2 * bKeyHeld;



switch (Key)
{
case KEY_0:
Expand All @@ -563,19 +566,22 @@ void FM_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
case KEY_7:
case KEY_8:
case KEY_9:
FM_Key_DIGITS(Key, bKeyPressed, bKeyHeld);
Key_DIGITS(Key, state);
break;
case KEY_STAR:
Key_FUNC(Key, state);
break;
case KEY_MENU:
FM_Key_MENU(bKeyPressed, bKeyHeld);
Key_MENU(state);
return;
case KEY_UP:
FM_Key_UP_DOWN(bKeyPressed, bKeyHeld, 1);
Key_UP_DOWN(state, 1);
break;
case KEY_DOWN:
FM_Key_UP_DOWN(bKeyPressed, bKeyHeld, -1);
Key_UP_DOWN(state, -1);
break;;
case KEY_EXIT:
FM_Key_EXIT(bKeyPressed, bKeyHeld);
Key_EXIT(state);
break;
case KEY_F:
GENERIC_Key_F(bKeyPressed, bKeyHeld);
Expand Down

0 comments on commit fe49f25

Please sign in to comment.