Skip to content

Commit

Permalink
Disable scan timeout compile option, updated win_make.bat to help pat…
Browse files Browse the repository at this point in the history
…h problems
  • Loading branch information
OneOfEleven committed Sep 25, 2023
1 parent aa69a04 commit ed32177
Show file tree
Hide file tree
Showing 20 changed files with 247 additions and 289 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ ENABLE_BOOT_BEEPS := 0
ENABLE_COMPANDER := 1
ENABLE_SHOW_CHARGE_LEVEL := 0
ENABLE_REVERSE_BAT_SYMBOL := 1
ENABLE_NO_SCAN_TIMEOUT := 1
ENABLE_AM_FIX := 1
ENABLE_AM_FIX_SHOW_DATA := 1
ENABLE_SQUELCH1_LOWER := 0
Expand Down Expand Up @@ -204,6 +205,9 @@ endif
ifeq ($(ENABLE_REVERSE_BAT_SYMBOL),1)
CFLAGS += -DENABLE_REVERSE_BAT_SYMBOL
endif
ifeq ($(ENABLE_NO_SCAN_TIMEOUT),1)
CFLAGS += -DENABLE_NO_SCAN_TIMEOUT
endif
ifeq ($(ENABLE_AM_FIX),1)
CFLAGS += -DENABLE_AM_FIX
endif
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ To compile directly in windows without the need of a linux virtual machine:
```
1. Download and install "gcc-arm-none-eabi-10.3-2021.10-win32.exe" from https://developer.arm.com/downloads/-/gnu-rm
2. Download and install "gnu_make-3.81.exe" from https://gnuwin32.sourceforge.net/packages/make.htm
3. You may (or not) need to manualy add gcc path to you OS environment PATH, ie C:\Program Files (x86)\GNU Arm Embedded Toolchain\10 2021.10\bin
3. You may (or not) need to manualy add gcc path to you OS environment PATH.
ie add C:\Program Files (x86)\GNU Arm Embedded Toolchain\10 2021.10\bin
4. You may (or not) need to reboot your PC after installing the above
```

Expand Down
58 changes: 26 additions & 32 deletions am_fix.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,11 @@ const uint8_t orig_pga = 6; // -3dB
// used to simply detect we've changed our table index/register settings
unsigned int am_fix_gain_table_index_prev[2] = {0, 0};

// moving average RSSI buffer
// helps smooth out any spikey RSSI readings
struct {
unsigned int count; //
unsigned int index; // read/write buffer index
uint16_t samples[4]; // 40ms long buffer (10ms RSSI sample rate)
uint16_t sum; // sum of all samples in the buffer
} moving_avg_rssi[2] = {0};
struct
{
unsigned int count;
uint16_t level;
} rssi[2];

// to help reduce gain hunting, provides a peak hold time delay
unsigned int am_gain_hold_counter[2] = {0, 0};
Expand All @@ -315,8 +312,8 @@ const uint8_t orig_pga = 6; // -3dB
void AM_fix_reset(const int vfo)
{ // reset the AM fixer

// reset the moving average filter
memset(&moving_avg_rssi[vfo], 0, sizeof(moving_avg_rssi[vfo]));
rssi[vfo].count = 0;
rssi[vfo].level = 0;

am_gain_hold_counter[vfo] = 0;

Expand Down Expand Up @@ -352,6 +349,8 @@ const uint8_t orig_pga = 6; // -3dB
case FUNCTION_TRANSMIT:
case FUNCTION_BAND_SCOPE:
case FUNCTION_POWER_SAVE:
return;

case FUNCTION_FOREGROUND:
return;

Expand All @@ -362,21 +361,16 @@ const uint8_t orig_pga = 6; // -3dB
break;
}

// sample the current RSSI level
uint16_t rssi = BK4819_GetRSSI(); // supposed 9-bit value (0 .. 511) - never seen that though

#if 1
// compute moving average RSSI - helps smooth any sharp spikes/troughs
// but can cause gain hunting/oscillation if too long a buffer (.samples)
if (moving_avg_rssi[vfo].count < ARRAY_SIZE(moving_avg_rssi[vfo].samples))
moving_avg_rssi[vfo].count++;
moving_avg_rssi[vfo].sum -= moving_avg_rssi[vfo].samples[moving_avg_rssi[vfo].index]; // subtract the oldest sample
moving_avg_rssi[vfo].sum += rssi; // add the newest sample
moving_avg_rssi[vfo].samples[moving_avg_rssi[vfo].index] = rssi; // save the newest sample
if (++moving_avg_rssi[vfo].index >= ARRAY_SIZE(moving_avg_rssi[vfo].samples)) //
moving_avg_rssi[vfo].index = 0; //
rssi = moving_avg_rssi[vfo].sum / moving_avg_rssi[vfo].count; // compute the average of the past 'n' samples
#endif
// sample the current RSSI level, average it with the previous rssi
if (rssi[vfo].count < 1)
{
rssi[vfo].level = BK4819_GetRSSI();
rssi[vfo].count++;
}
else
{
rssi[vfo].level = (rssi[vfo].level + BK4819_GetRSSI()) >> 1;
}

#ifdef ENABLE_AM_FIX_TEST1

Expand All @@ -388,18 +382,18 @@ const uint8_t orig_pga = 6; // -3dB
{
if (--am_gain_hold_counter[vfo] > 0)
{
gCurrentRSSI[vfo] = rssi - (rssi_db_gain_diff[vfo] * 2);
gCurrentRSSI[vfo] = (int16_t)rssi[vfo].level - (rssi_db_gain_diff[vfo] * 2);
return;
}
}

am_gain_hold_counter[vfo] = 250; // 250ms hold

#else

// automatically choose a front end gain setting by monitoring the RSSI

if (rssi > desired_rssi)
if (rssi[vfo].level > desired_rssi)
{ // decrease gain

if (am_fix_gain_table_index[vfo] > 1)
Expand All @@ -413,14 +407,14 @@ const uint8_t orig_pga = 6; // -3dB

if (am_gain_hold_counter[vfo] == 0)
// hold has been released, we're free to increase gain
if (rssi < (desired_rssi - 10)) // 5dB hysterisis (helps reduce gain hunting)
if (rssi[vfo].level < (desired_rssi - 10)) // 5dB hysterisis (helps reduce gain hunting)
// increase gain
if (am_fix_gain_table_index[vfo] < (ARRAY_SIZE(am_fix_gain_table) - 1))
am_fix_gain_table_index[vfo]++;

if (am_fix_gain_table_index[vfo] == am_fix_gain_table_index_prev[vfo])
{ // no gain changes have been made
gCurrentRSSI[vfo] = rssi - (rssi_db_gain_diff[vfo] * 2);
gCurrentRSSI[vfo] = (int16_t)rssi[vfo].level - (rssi_db_gain_diff[vfo] * 2);
return;
}

Expand All @@ -442,7 +436,7 @@ const uint8_t orig_pga = 6; // -3dB
rssi_db_gain_diff[vfo] = am_dB_gain - orig_dB_gain;

// shall we or sharn't we ?
gCurrentRSSI[vfo] = rssi - (rssi_db_gain_diff[vfo] * 2);
gCurrentRSSI[vfo] = (int16_t)rssi[vfo].level - (rssi_db_gain_diff[vfo] * 2);
}

// remember the new table index
Expand Down Expand Up @@ -470,7 +464,7 @@ const uint8_t orig_pga = 6; // -3dB
// compute the current front end gain
const int16_t dB_gain = lna_short_dB[lna_short] + lna_dB[lna] + mixer_dB[mixer] + pga_dB[pga];

sprintf(s, "idx %2d %4ddB %3u", am_fix_gain_table_index[vfo], dB_gain, BK4819_GetRSSI());
sprintf(s, "idx %2d %4ddB %3u", am_fix_gain_table_index[vfo], dB_gain, rssi[vfo].level);
}

#endif
Expand Down
3 changes: 3 additions & 0 deletions app/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ void ACTION_Scan(bool bRestart)
AUDIO_PlaySingleVoice(true);
#endif

// clear the other vfo's rssi level (to hide the antenna symbol)
gVFO_RSSI_bar_level[gEeprom.RX_CHANNEL == 0] = 0;

// let the user see DW is not active
gDualWatchActive = false;
gUpdateStatus = true;
Expand Down
70 changes: 35 additions & 35 deletions app/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@

static void APP_ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld);

static void updateRSSI(const int vfo)
{
int16_t rssi = BK4819_GetRSSI();
#ifdef ENABLE_AM_FIX
// with compensation
if (gEeprom.VfoInfo[vfo].IsAM && gSetting_AM_fix)
rssi -= rssi_db_gain_diff[vfo] * 2;
#endif
gCurrentRSSI[vfo] = rssi;

UI_UpdateRSSI(rssi, vfo);
}

static void APP_CheckForIncoming(void)
{
if (!g_SquelchLost)
Expand Down Expand Up @@ -415,10 +428,11 @@ void APP_StartListening(FUNCTION_Type_t Function, const bool reset_am_fix)
#endif

#ifdef ENABLE_AM_FIX
if (reset_am_fix)
if (gEeprom.VfoInfo[gEeprom.RX_CHANNEL].IsAM && reset_am_fix)
AM_fix_reset(gEeprom.RX_CHANNEL); // TODO: only reset it when moving channel/frequency
#endif

// clear the other vfo's rssi level (to hide the antenna symbol)
gVFO_RSSI_bar_level[gEeprom.RX_CHANNEL == 0] = 0;

GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH);
Expand Down Expand Up @@ -1119,8 +1133,8 @@ void APP_Update(void)

if (gEeprom.DUAL_WATCH != DUAL_WATCH_OFF && gScanState == SCAN_OFF && gCssScanMode == CSS_SCAN_MODE_OFF)
{ // dual watch mode, toggle between the two VFO's

DUALWATCH_Alternate();

gUpdateRSSI = false;
}

Expand All @@ -1133,15 +1147,7 @@ void APP_Update(void)
if (gEeprom.DUAL_WATCH == DUAL_WATCH_OFF || gScanState != SCAN_OFF || gCssScanMode != CSS_SCAN_MODE_OFF || gUpdateRSSI)
{ // dual watch mode, go back to sleep

// sample the RSSI
gCurrentRSSI[gEeprom.RX_CHANNEL] = BK4819_GetRSSI();
#ifdef ENABLE_AM_FIX
// with compensation
if (gRxVfo->IsAM && gSetting_AM_fix)
gCurrentRSSI[gEeprom.RX_CHANNEL] -= rssi_db_gain_diff[gEeprom.RX_CHANNEL] * 2;
#endif

UI_UpdateRSSI(gCurrentRSSI[gEeprom.RX_CHANNEL], gEeprom.RX_CHANNEL);
updateRSSI(gEeprom.RX_CHANNEL);

// go back to sleep

Expand All @@ -1156,8 +1162,7 @@ void APP_Update(void)

}
else
{ // no yet in power save mode

{
// toggle between the two VFO's
DUALWATCH_Alternate();

Expand Down Expand Up @@ -1326,7 +1331,7 @@ void APP_TimeSlice10ms(void)
#endif

#ifdef ENABLE_AM_FIX
if (gRxVfo->IsAM && gSetting_AM_fix)
if (gEeprom.VfoInfo[gEeprom.RX_CHANNEL].IsAM && gSetting_AM_fix)
AM_fix_adjust_frontEnd_10ms(gEeprom.RX_CHANNEL);
#endif

Expand Down Expand Up @@ -1659,16 +1664,7 @@ void APP_TimeSlice500ms(void)
gUpdateStatus = true;

if (gCurrentFunction != FUNCTION_POWER_SAVE)
{
gCurrentRSSI[gEeprom.RX_CHANNEL] = (int16_t)BK4819_GetRSSI();
#ifdef ENABLE_AM_FIX
// with compensation
if (gRxVfo->IsAM && gSetting_AM_fix)
gCurrentRSSI[gEeprom.RX_CHANNEL] -= rssi_db_gain_diff[gEeprom.RX_CHANNEL] * 2;
#endif

UI_UpdateRSSI(gCurrentRSSI[gEeprom.RX_CHANNEL], gEeprom.RX_CHANNEL);
}
updateRSSI(gEeprom.RX_CHANNEL);

#ifdef ENABLE_FMRADIO
if ((gFM_ScanState == FM_SCAN_OFF || gAskToSave) && gCssScanMode == CSS_SCAN_MODE_OFF)
Expand Down Expand Up @@ -1759,7 +1755,7 @@ void APP_TimeSlice500ms(void)
{
gLowBatteryBlink = ++gLowBatteryCountdown & 1;

UI_DisplayBattery(gLowBatteryCountdown);
UI_DisplayBattery(0, gLowBatteryBlink);

if (gCurrentFunction != FUNCTION_TRANSMIT)
{ // not transmitting
Expand Down Expand Up @@ -1808,16 +1804,20 @@ void APP_TimeSlice500ms(void)

if (gScreenToDisplay == DISPLAY_SCANNER && gScannerEditState == 0 && gScanCssState < SCAN_CSS_STATE_FOUND)
{
if (++gScanProgressIndicator > 32)
{
if (gScanCssState == SCAN_CSS_STATE_SCANNING && !gScanSingleFrequency)
gScanCssState = SCAN_CSS_STATE_FOUND;
else
gScanCssState = SCAN_CSS_STATE_FAILED;

gUpdateStatus = true;
}

gScanProgressIndicator++;

#ifndef ENABLE_NO_SCAN_TIMEOUT
if (gScanProgressIndicator > 32)
{
if (gScanCssState == SCAN_CSS_STATE_SCANNING && !gScanSingleFrequency)
gScanCssState = SCAN_CSS_STATE_FOUND;
else
gScanCssState = SCAN_CSS_STATE_FAILED;

gUpdateStatus = true;
}
#endif

gUpdateDisplay = true;
}

Expand Down
Loading

0 comments on commit ed32177

Please sign in to comment.