Skip to content

Commit 51c883d

Browse files
OneOfElevenOneOfEleven
authored andcommitted
.
1 parent f201915 commit 51c883d

File tree

7 files changed

+66
-30
lines changed

7 files changed

+66
-30
lines changed

app/fm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ int FM_check_frequency_lock(const uint16_t frequency, const uint16_t lower_limit
190190
if (afc_railed || snr < 2 || rssi < 10 || abs(freq_offset) > 250)
191191
goto Bail;
192192

193-
if (frequency >= lower_limit && abs(((int)BK1080_freq_base - frequency)) == 1)
193+
if (frequency >= lower_limit && abs(((int)BK1080_freq_base - (int)frequency)) == 1)
194194
if (abs(BK1080_freq_offset) < 20)
195195
goto Bail;
196196

app/main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,8 @@ void MAIN_Key_STAR(bool key_pressed, bool key_held)
873873
#ifdef ENABLE_SCAN_IGNORE_LIST
874874
if (scanning_paused())
875875
{
876-
FI_add_freq_ignored(g_rx_vfo->freq_config_rx.frequency);
876+
if (!FI_add_freq_ignored(g_rx_vfo->freq_config_rx.frequency))
877+
g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; // not added for some reason
877878

878879
// immediately continue the scan
879880
g_scan_tick_10ms = 0;

firmware.bin

-12 Bytes
Binary file not shown.

firmware.packed.bin

-12 Bytes
Binary file not shown.

freq_ignore.c

Lines changed: 59 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11

2+
#include <stdlib.h> // abs()
3+
24
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
35
#include "driver/uart.h"
46
#endif
57
#include "freq_ignore.h"
68
#include "misc.h"
79

10+
//#define FI_CLOSE_ENOUGH_HZ 300
11+
812
// a list of frequencies to ignore/skip when scanning
913
uint32_t ignore_frequencies[64];
1014
int ignore_frequencies_count = 0;
@@ -21,53 +25,70 @@ void FI_clear_freq_ignored(void)
2125
int FI_freq_ignored(const uint32_t frequency)
2226
{ // return index of the ignored frequency
2327

24-
if (frequency == 0 || frequency == 0xffffffff || ignore_frequencies_count <= 0)
25-
return -1;
28+
#ifdef FI_CLOSE_ENOUGH_HZ
29+
if (frequency <= FI_CLOSE_ENOUGH_HZ || frequency >= (0xffffffff - FI_CLOSE_ENOUGH_HZ) || ignore_frequencies_count <= 0)
30+
return -1; // invalid frequency
31+
#else
32+
if (frequency == 0 || frequency == 0xffffffff || ignore_frequencies_count <= 0)
33+
return -1; // invalid frequency
34+
#endif
2635

27-
if (ignore_frequencies_count >= 8)
28-
{ // binary search .. becomes much faster than sequencial search when the list is bigger
36+
if (ignore_frequencies_count >= 20)
37+
{ // binary search becomes faster than sequencial as the list grows beyound a certain size
2938
int low = 0;
3039
int high = ignore_frequencies_count;
40+
3141
while (low < high)
3242
{
3343
register int mid = (low + high) / 2;
3444
register uint32_t freq = ignore_frequencies[mid];
35-
if (freq > frequency)
36-
high = mid;
37-
else
38-
if (freq < frequency)
39-
low = mid + 1;
40-
else
41-
{
45+
46+
#ifdef FI_CLOSE_ENOUGH_HZ
47+
if (abs((int32_t)frequency - (int32_t)freq) <= FI_CLOSE_ENOUGH_HZ)
48+
#else
49+
if (frequency == freq)
50+
#endif
51+
{ // found it
4252
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
4353
UART_printf("ignored bin %u %u\r\n", frequency, mid);
4454
#endif
4555
return mid;
4656
}
57+
58+
if (freq > frequency)
59+
high = mid;
60+
else
61+
low = mid + 1;
4762
}
4863
}
4964
else
5065
{ // sequencial search
51-
int i;
66+
register int i;
5267
for (i = 0; i < ignore_frequencies_count; i++)
5368
{
5469
register uint32_t freq = ignore_frequencies[i];
55-
if (frequency == freq)
70+
71+
#ifdef FI_CLOSE_ENOUGH_HZ
72+
if (abs((int32_t)frequency - (int32_t)freq) <= FI_CLOSE_ENOUGH_HZ)
73+
#else
74+
if (frequency == freq)
75+
#endif
5676
{ // found it
5777
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
5878
UART_printf("ignored seq %u %u\r\n", frequency, i);
5979
#endif
6080
return i;
6181
}
82+
6283
if (frequency < freq)
63-
return -1; // can exit loop early as the list is sorted by frequency
84+
return -1; // exit loop early as the list is sorted by frequency
6485
}
6586
}
6687

6788
return -1; // not found
6889
}
6990

70-
void FI_add_freq_ignored(const uint32_t frequency)
91+
bool FI_add_freq_ignored(const uint32_t frequency)
7192
{ // add a new frequency to the ignore list
7293

7394
int i;
@@ -76,31 +97,45 @@ void FI_add_freq_ignored(const uint32_t frequency)
7697
UART_printf("ignore add %u\r\n", frequency);
7798
#endif
7899

79-
if (frequency == 0 || frequency == 0xffffffff)
80-
return;
100+
#ifdef FI_CLOSE_ENOUGH_HZ
101+
if (frequency <= FI_CLOSE_ENOUGH_HZ || frequency >= (0xffffffff - FI_CLOSE_ENOUGH_HZ))
102+
return false; // invalid frequency
103+
#else
104+
if (frequency == 0 || frequency == 0xffffffff)
105+
return false; // invalid frequency
106+
#endif
81107

82108
if (ignore_frequencies_count >= (int)ARRAY_SIZE(ignore_frequencies))
83109
{ // the list is full
84110
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
85111
UART_SendText("ignore add full\r\n");
86112
#endif
87-
return;
113+
return false; // failed
88114
}
89115

90116
for (i = 0; i < ignore_frequencies_count; i++)
91117
{
92118
register uint32_t freq = ignore_frequencies[i];
93119

94-
if (frequency == freq)
120+
#ifdef FI_CLOSE_ENOUGH_HZ
121+
if (abs((int32_t)frequency - (int32_t)freq) <= FI_CLOSE_ENOUGH_HZ)
122+
#else
123+
if (frequency == freq)
124+
#endif
95125
{ // already in the list
96126
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
97127
UART_SendText("ignore add already\r\n");
98128
#endif
99-
return;
129+
return true;
100130
}
101131

102-
if (frequency < freq)
103-
break;
132+
#ifdef FI_CLOSE_ENOUGH_HZ
133+
if (frequency < (freq + FI_CLOSE_ENOUGH_HZ))
134+
break; // exit loop early as the list is sorted by frequency
135+
#else
136+
if (frequency < freq)
137+
break; // exit loop early as the list is sorted by frequency
138+
#endif
104139
}
105140

106141
// found the location to store the new frequency - the list is kept sorted by frequency
@@ -117,6 +152,8 @@ void FI_add_freq_ignored(const uint32_t frequency)
117152
for (i = 0; i < ignore_frequencies_count; i++)
118153
UART_printf("%2u %10u\r\n", i, ignore_frequencies[i]);
119154
#endif
155+
156+
return true;
120157
}
121158

122159
void FI_sub_freq_ignored(const uint32_t frequency)
@@ -126,9 +163,6 @@ void FI_sub_freq_ignored(const uint32_t frequency)
126163
UART_printf("ignore sub %u\r\n", frequency);
127164
#endif
128165

129-
if (frequency == 0 || frequency == 0xffffffff)
130-
return;
131-
132166
int index = FI_freq_ignored(frequency);
133167
if (index < 0)
134168
return;

freq_ignore.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@
1818
#define FREQ_IGNORE_H
1919

2020
#include <stdint.h>
21+
#include <stdbool.h>
2122

2223
#ifdef ENABLE_SCAN_IGNORE_LIST
2324
void FI_clear_freq_ignored(void);
2425
int FI_freq_ignored(const uint32_t frequency);
25-
void FI_add_freq_ignored(const uint32_t frequency);
26+
bool FI_add_freq_ignored(const uint32_t frequency);
2627
void FI_sub_freq_ignored(const uint32_t frequency);
2728
#endif
2829

settings.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,8 @@ unsigned int SETTINGS_find_channel(const uint32_t frequency)
562562
continue;
563563
if (freq == frequency)
564564
return chan; // found it
565-
// if (abs((int32_t)freq - frequency) < 5)
566-
// return chan; // found a very close match
565+
// if (abs((int32_t)freq - (int32_t)frequency) < 300)
566+
// return chan; // found a close match
567567
}
568568

569569
return 0xffffffff;

0 commit comments

Comments
 (0)