FM Radio: Simplify logic
This commit is contained in:
committed by
Krzysiek Egzmont
parent
82ddbcd375
commit
b6a49db31d
65
app/fm.c
65
app/fm.c
@@ -62,7 +62,7 @@ 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;
|
||||
return (Channel < ARRAY_SIZE(gFM_Channels) && (gFM_Channels[Channel] >= 760 && gFM_Channels[Channel] < 1080));
|
||||
}
|
||||
|
||||
uint8_t FM_FindNextChannel(uint8_t Channel, uint8_t Direction)
|
||||
@@ -193,41 +193,36 @@ int FM_CheckFrequencyLock(uint16_t Frequency, uint16_t LowerLimit)
|
||||
// This is supposed to be a signed value, but above function is unsigned
|
||||
const uint16_t Deviation = BK1080_REG_07_GET_FREQD(Test2);
|
||||
|
||||
if (BK1080_REG_07_GET_SNR(Test2) >= 2)
|
||||
{
|
||||
const uint16_t Status = BK1080_ReadRegister(BK1080_REG_10);
|
||||
if ((Status & BK1080_REG_10_MASK_AFCRL) == BK1080_REG_10_AFCRL_NOT_RAILED && BK1080_REG_10_GET_RSSI(Status) >= 10)
|
||||
{
|
||||
//if (Deviation > -281 && Deviation < 280)
|
||||
if (Deviation < 280 || Deviation > 3815)
|
||||
{
|
||||
// not BLE(less than or equal)
|
||||
|
||||
if (Frequency > LowerLimit && (Frequency - BK1080_BaseFrequency) == 1)
|
||||
{
|
||||
if (BK1080_FrequencyDeviation & 0x800)
|
||||
if (BK1080_REG_07_GET_SNR(Test2) <= 2){
|
||||
goto Bail;
|
||||
}
|
||||
|
||||
if (BK1080_FrequencyDeviation < 20)
|
||||
const uint16_t Status = BK1080_ReadRegister(BK1080_REG_10);
|
||||
|
||||
if ((Status & BK1080_REG_10_MASK_AFCRL) != BK1080_REG_10_AFCRL_NOT_RAILED || BK1080_REG_10_GET_RSSI(Status) < 10) {
|
||||
goto Bail;
|
||||
}
|
||||
|
||||
//if (Deviation > -281 && Deviation < 280)
|
||||
if (Deviation >= 280 && Deviation <= 3815) {
|
||||
goto Bail;
|
||||
}
|
||||
|
||||
// not BLE(less than or equal)
|
||||
if (Frequency > LowerLimit && (Frequency - BK1080_BaseFrequency) == 1) {
|
||||
if (BK1080_FrequencyDeviation & 0x800 || (BK1080_FrequencyDeviation < 20))
|
||||
goto Bail;
|
||||
}
|
||||
|
||||
// not BLT(less than)
|
||||
|
||||
if (Frequency >= LowerLimit && (BK1080_BaseFrequency - Frequency) == 1)
|
||||
{
|
||||
if ((BK1080_FrequencyDeviation & 0x800) == 0)
|
||||
if (Frequency >= LowerLimit && (BK1080_BaseFrequency - Frequency) == 1) {
|
||||
if ((BK1080_FrequencyDeviation & 0x800) == 0 || (BK1080_FrequencyDeviation > 4075))
|
||||
goto Bail;
|
||||
|
||||
// if (BK1080_FrequencyDeviation > -21)
|
||||
if (BK1080_FrequencyDeviation > 4075)
|
||||
goto Bail;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Bail:
|
||||
BK1080_FrequencyDeviation = Deviation;
|
||||
@@ -446,11 +441,9 @@ static void Key_MENU(uint8_t state)
|
||||
if (gAskToSave)
|
||||
{
|
||||
gFM_Channels[gFM_ChannelPosition] = gEeprom.FM_FrequencyPlaying;
|
||||
gAskToSave = false;
|
||||
gRequestSaveFM = true;
|
||||
}
|
||||
else
|
||||
gAskToSave = true;
|
||||
gAskToSave = !gAskToSave;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -462,10 +455,9 @@ static void Key_MENU(uint8_t state)
|
||||
BK1080_SetFrequency(gEeprom.FM_FrequencyPlaying);
|
||||
|
||||
gRequestSaveFM = true;
|
||||
gAskToDelete = false;
|
||||
}
|
||||
else
|
||||
gAskToDelete = true;
|
||||
|
||||
gAskToDelete = !gAskToDelete;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -480,11 +472,9 @@ static void Key_MENU(uint8_t state)
|
||||
if (gAskToSave)
|
||||
{
|
||||
gFM_Channels[gFM_ChannelPosition] = gEeprom.FM_FrequencyPlaying;
|
||||
gAskToSave = false;
|
||||
gRequestSaveFM = true;
|
||||
}
|
||||
else
|
||||
gAskToSave = true;
|
||||
gAskToSave = !gAskToSave;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -497,9 +487,7 @@ static void Key_UP_DOWN(uint8_t state, int8_t Step)
|
||||
}
|
||||
|
||||
gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL;
|
||||
}
|
||||
else {
|
||||
if (gInputBoxIndex || state!=BUTTON_EVENT_HELD)
|
||||
} else if (gInputBoxIndex || state!=BUTTON_EVENT_HELD) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -530,6 +518,7 @@ static void Key_UP_DOWN(uint8_t state, int8_t Step)
|
||||
}
|
||||
else {
|
||||
uint16_t Frequency = gEeprom.FM_SelectedFrequency + Step;
|
||||
|
||||
if (Frequency < gEeprom.FM_LowerLimit)
|
||||
Frequency = gEeprom.FM_UpperLimit;
|
||||
else
|
||||
@@ -552,8 +541,6 @@ void FM_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
|
||||
{
|
||||
uint8_t state = bKeyPressed + 2 * bKeyHeld;
|
||||
|
||||
|
||||
|
||||
switch (Key)
|
||||
{
|
||||
case KEY_0:
|
||||
@@ -573,7 +560,7 @@ void FM_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
|
||||
break;
|
||||
case KEY_MENU:
|
||||
Key_MENU(state);
|
||||
return;
|
||||
break;
|
||||
case KEY_UP:
|
||||
Key_UP_DOWN(state, 1);
|
||||
break;
|
||||
|
2
app/fm.h
2
app/fm.h
@@ -38,7 +38,6 @@ extern uint8_t gFM_ChannelPosition;
|
||||
// Doubts about whether this should be signed or not
|
||||
extern uint16_t gFM_FrequencyDeviation;
|
||||
extern bool gFM_FoundFrequency;
|
||||
extern bool gFM_AutoScan;
|
||||
extern uint16_t gFM_RestoreCountdown_10ms;
|
||||
|
||||
bool FM_CheckValidChannel(uint8_t Channel);
|
||||
@@ -59,4 +58,3 @@ void FM_Start(void);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
Reference in New Issue
Block a user