mirror of
https://github.com/armel/uv-k1-k5v3-firmware-custom.git
synced 2026-10-02 11:08:20 +00:00
Fix large-range spectrum stability and manual dB floor behavior
This commit is contained in:
1 parent
35e5d8df90
commit
0004074ffe
1 file changed
+46
-15
+46
-15
@@ -645,10 +645,10 @@ static void UpdateScanInfo()
|
||||
if (scanInfo.rssi < scanInfo.rssiMin)
|
||||
{
|
||||
scanInfo.rssiMin = scanInfo.rssi;
|
||||
if (!manualSetFlag) {
|
||||
settings.dbMin = Rssi2DBm(scanInfo.rssiMin);
|
||||
redrawStatus = true;
|
||||
}
|
||||
settings.dbMin = Rssi2DBm(scanInfo.rssiMin);
|
||||
if (settings.dbMin > settings.dbMax - 10)
|
||||
settings.dbMin = settings.dbMax - 10;
|
||||
redrawStatus = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -707,24 +707,50 @@ static void UpdatePeakInfo()
|
||||
UpdatePeakInfoForce();
|
||||
}
|
||||
|
||||
static void SetRssiHistory(uint16_t idx, uint16_t rssi)
|
||||
static uint8_t GetHistorySlot(uint16_t idx)
|
||||
{
|
||||
#ifdef ENABLE_SCAN_RANGES
|
||||
if (scanInfo.measurementsCount > 128)
|
||||
if (scanInfo.measurementsCount > ARRAY_SIZE(rssiHistory))
|
||||
{
|
||||
uint8_t i = (uint32_t)ARRAY_SIZE(rssiHistory) * 1000 / scanInfo.measurementsCount * idx / 1000;
|
||||
if (rssiHistory[i] < rssi || isListening)
|
||||
rssiHistory[i] = rssi;
|
||||
rssiHistory[(i + 1) % 128] = 0;
|
||||
uint32_t slot = (uint32_t)idx * ARRAY_SIZE(rssiHistory) / scanInfo.measurementsCount;
|
||||
if (slot >= ARRAY_SIZE(rssiHistory))
|
||||
slot = ARRAY_SIZE(rssiHistory) - 1;
|
||||
return (uint8_t)slot;
|
||||
}
|
||||
#endif
|
||||
return (uint8_t)idx;
|
||||
}
|
||||
|
||||
static void SetRssiHistory(uint16_t idx, uint16_t rssi)
|
||||
{
|
||||
uint8_t slot = GetHistorySlot(idx);
|
||||
|
||||
if (rssi == RSSI_MAX_VALUE)
|
||||
{
|
||||
rssiHistory[slot] = RSSI_MAX_VALUE;
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_SCAN_RANGES
|
||||
if (scanInfo.measurementsCount > ARRAY_SIZE(rssiHistory))
|
||||
{
|
||||
uint16_t prev = rssiHistory[slot];
|
||||
if (prev == RSSI_MAX_VALUE)
|
||||
return;
|
||||
// For large ranges: keep fast attack, soften decay to reduce flicker.
|
||||
if (rssi >= prev)
|
||||
rssiHistory[slot] = rssi;
|
||||
else
|
||||
rssiHistory[slot] = (uint16_t)((3u * prev + rssi) >> 2);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
// Attack/decay: instant rise, fast fall for stable display
|
||||
uint16_t prev = rssiHistory[idx];
|
||||
uint16_t prev = rssiHistory[slot];
|
||||
if (rssi >= prev) {
|
||||
rssiHistory[idx] = rssi; // Attack: instant
|
||||
rssiHistory[slot] = rssi; // Attack: instant
|
||||
} else {
|
||||
rssiHistory[idx] = (prev + rssi) >> 1; // Decay: halve the gap each sweep
|
||||
rssiHistory[slot] = (prev + rssi) >> 1; // Decay: halve the gap each sweep
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1646,8 +1672,11 @@ static void RenderStatus()
|
||||
|
||||
static void RenderSpectrum()
|
||||
{
|
||||
uint16_t steps = GetStepsCount();
|
||||
uint8_t arrowX = (steps > 1) ? (uint8_t)(128u * peak.i / (steps - 1)) : 0;
|
||||
|
||||
DrawTicks();
|
||||
DrawArrow(128u * peak.i / (GetStepsCount() - 1));
|
||||
DrawArrow(arrowX);
|
||||
DrawSpectrum();
|
||||
DrawRssiTriggerLevel();
|
||||
DrawF(peak.f);
|
||||
@@ -1804,7 +1833,9 @@ static bool HandleUserInput()
|
||||
|
||||
static void Scan()
|
||||
{
|
||||
if (rssiHistory[scanInfo.i] != RSSI_MAX_VALUE
|
||||
uint8_t slot = GetHistorySlot(scanInfo.i);
|
||||
|
||||
if (rssiHistory[slot] != RSSI_MAX_VALUE
|
||||
#ifdef ENABLE_SCAN_RANGES
|
||||
&& !IsBlacklisted(scanInfo.i)
|
||||
#endif
|
||||
|
||||
Reference in new issue
Block a user