From 1d65b2e7987b4041adb2bb943046f2749d6aacc4 Mon Sep 17 00:00:00 2001 From: Mikhail Yudin Date: Sat, 12 Aug 2023 22:30:43 +0700 Subject: [PATCH 1/7] refactor, feat: 100KHz to track satellite doppler shift, better smaller steps, better defaults --- README.md | 9 +- libs/lcd/lcd.hpp | 5 +- src/spectrum_fagci/keys.hpp | 26 ++++++ src/spectrum_fagci/spectrum.hpp | 149 +++++++++++++++----------------- 4 files changed, 102 insertions(+), 87 deletions(-) create mode 100644 src/spectrum_fagci/keys.hpp diff --git a/README.md b/README.md index cf23dd5..e2ddf5c 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Features: * no scan sound * squelch by user input level -* 0.2 .. 3.2MHz frequency ranges +* 0.1 .. 3.2MHz frequency ranges * ticks by frequency (100,500,1000KHz) * catch signal peak frequency * automatic frequency change step @@ -41,8 +41,11 @@ How to start: How to operate: -* press **8** / **2** for zoom in / zoom out -* press and hold **3** / **9** to set squelch level +* press **UP** / **DOWN** key to change frequency +* press **1** / **7** to control measurement time (increasing "sensitivity") +* press **2** / **8** to to set frequency change step +* press **9** / **3** for zoom in / zoom out +* press and hold **\*** / **F** to set squelch level * press **5** to toggle backlight * press **0** to remove frequency from sspectrum to scan * press **EXIT** to disable spectrum view diff --git a/libs/lcd/lcd.hpp b/libs/lcd/lcd.hpp index 22ef78f..31c4d19 100644 --- a/libs/lcd/lcd.hpp +++ b/libs/lcd/lcd.hpp @@ -270,10 +270,9 @@ template class CDisplay { const char dot[1] = {64}; for (unsigned char i = 0; i < len; i++) { if (pointAt == len - i) { - u16CoursorPosition++; - auto *pCoursorPosition = Bitmap.GetCoursorData(u16CoursorPosition); + auto *pCoursorPosition = Bitmap.GetCoursorData(u16CoursorPosition + 1); memcpy(pCoursorPosition, dot, 1); - u16CoursorPosition++; + u16CoursorPosition += 2; } PrintCharacter(str[i]); } diff --git a/src/spectrum_fagci/keys.hpp b/src/spectrum_fagci/keys.hpp new file mode 100644 index 0000000..82396bf --- /dev/null +++ b/src/spectrum_fagci/keys.hpp @@ -0,0 +1,26 @@ +enum Keys { + NUM0, + NUM1, + NUM2, + NUM3, + NUM4, + NUM5, + NUM6, + NUM7, + NUM8, + NUM9, + MENU, // 10 + UP, // 11 + DOWN, // 12 + EXIT, // 13 + ASTERISK, // 14 + FUNCTION, // 15 + _NA16, + _NA17, + _NA18, + _NA19, + _NA20, + _NA21, + FN2, // 22 + FN1, // 23 +}; diff --git a/src/spectrum_fagci/spectrum.hpp b/src/spectrum_fagci/spectrum.hpp index 508e35b..a58f092 100644 --- a/src/spectrum_fagci/spectrum.hpp +++ b/src/spectrum_fagci/spectrum.hpp @@ -1,4 +1,5 @@ #pragma once +#include "keys.hpp" #include "radio.hpp" #include "system.hpp" #include "types.hpp" @@ -6,10 +7,15 @@ template class CSpectrum { public: - static constexpr auto ExitKey = 13; static constexpr auto DrawingEndY = 42; static constexpr auto BarPos = 5 * 128; + static constexpr u32 modeHalfSpectrumBW[6] = {50_KHz, 100_KHz, 200_KHz, + 400_KHz, 800_KHz, 1600_KHz}; + static constexpr u16 modeScanStep[6] = {1562_Hz, 6250_Hz, 12500_Hz, + 25_KHz, 25_KHz, 25_KHz}; + static constexpr u8 modeXdiv[6] = {1, 2, 2, 2, 1, 0}; + u8 rssiHistory[128] = {}; u32 fMeasure; @@ -18,16 +24,16 @@ template class CSpectrum { u8 peakI = 0; u32 peakF = 0; u8 rssiMin = 255; - - u16 scanDelay = 1200; + u8 btnCounter = 0; bool resetBlacklist = false; CSpectrum() : DisplayBuff(gDisplayBuffer), Display(DisplayBuff), - FontSmallNr(gSmallDigs), frequencyChangeStep(400_KHz), bwMul(2), + FontSmallNr(gSmallDigs), scanDelay(1600), mode(4), rssiTriggerLevel(60) { Display.SetFont(&FontSmallNr); + frequencyChangeStep = modeHalfSpectrumBW[mode]; }; void Scan() { @@ -73,7 +79,7 @@ template class CSpectrum { void DrawSpectrum() { for (u8 x = 0; x < 128; ++x) { - auto v = rssiHistory[x >> BWMul2XDiv()]; + auto v = rssiHistory[x >> modeXdiv[mode]]; if (v != 255) { Display.DrawHLine(Rssi2Y(v), DrawingEndY, x); } @@ -87,9 +93,6 @@ template class CSpectrum { Display.SetCoursorXY(112, 0); Display.PrintFixedDigitsNumber3(GetBW(), 4, 2, 1); - /* Display.SetCoursorXY(0, 0); - Display.PrintFixedDigitsNumber2(rssiMinV, 0); */ - Display.SetCoursorXY(44, 0); Display.PrintFixedDigitsNumber3(peakF, 2, 6, 3); @@ -101,9 +104,6 @@ template class CSpectrum { Display.SetCoursorXY(57, 48); Display.PrintFixedDigitsNumber3(frequencyChangeStep, 4, 2, 1); - - /* Display.SetCoursorXY(0, 8); - Display.PrintFixedDigitsNumber2(rssiMaxV, 0); */ } void DrawRssiTriggerLevel() { @@ -127,61 +127,56 @@ template class CSpectrum { } } - void OnKey(u8 key) { - switch (key) { - case 14: - UpdateRssiTriggerLevel(1); - DelayMs(90); - break; - case 15: - UpdateRssiTriggerLevel(-1); - DelayMs(90); - break; - } - } - void OnKeyDown(u8 key) { switch (key) { - case 1: + case Keys::NUM1: if (scanDelay < 8000) { scanDelay += 200; rssiMin = 255; } break; - case 7: + case Keys::NUM7: if (scanDelay > 800) { scanDelay -= 200; rssiMin = 255; } break; - case 3: + case Keys::NUM3: UpdateBWMul(1); resetBlacklist = true; break; - case 9: + case Keys::NUM9: UpdateBWMul(-1); resetBlacklist = true; break; - case 2: + case Keys::NUM2: UpdateFreqChangeStep(100_KHz); break; - case 8: + case Keys::NUM8: UpdateFreqChangeStep(-100_KHz); break; - case 11: // up + case Keys::UP: UpdateCurrentFreq(frequencyChangeStep); resetBlacklist = true; break; - case 12: // down + case Keys::DOWN: UpdateCurrentFreq(-frequencyChangeStep); resetBlacklist = true; break; - case 5: + case Keys::NUM5: ToggleBacklight(); break; - case 0: + case Keys::NUM0: Blacklist(); break; + case Keys::ASTERISK: + UpdateRssiTriggerLevel(1); + DelayMs(90); + break; + case Keys::FUNCTION: + UpdateRssiTriggerLevel(-1); + DelayMs(90); + break; } ResetPeak(); } @@ -189,12 +184,16 @@ template class CSpectrum { bool HandleUserInput() { btnPrev = btn; btn = PollKeyboard(); - if (btn == ExitKey) { + if (btn == Keys::EXIT) { DeInit(); return false; } - OnKey(btn); - if (btn != 255 && btnPrev == 255) { + if (btn != 255 && btn == btnPrev) { + btnCounter = clamp(btnCounter + 1, 0, 255); + } else { + btnCounter = 0; + } + if ((btn != 255 && btnPrev == 255) || btnCounter > 16) { OnKeyDown(btn); } return true; @@ -203,7 +202,7 @@ template class CSpectrum { void Render() { DisplayBuff.ClearAll(); DrawTicks(); - DrawArrow(peakI << BWMul2XDiv()); + DrawArrow(peakI << modeXdiv[mode]); DrawSpectrum(); DrawRssiTriggerLevel(); DrawNums(); @@ -212,24 +211,22 @@ template class CSpectrum { void Update() { if (peakRssi >= rssiTriggerLevel) { - Listen(1600); - return; + Listen(); } - Scan(); - } - - void UpdateRssiTriggerLevel(i32 diff) { - if ((diff > 0 && rssiTriggerLevel < 255) || - (diff < 0 && rssiTriggerLevel > 0)) { - rssiTriggerLevel += diff; + if (peakRssi < rssiTriggerLevel) { + Scan(); } } + void UpdateRssiTriggerLevel(i32 diff) { rssiTriggerLevel += diff; } + void UpdateBWMul(i32 diff) { - if ((diff > 0 && bwMul < 4) || (diff < 0 && bwMul > 0)) { - bwMul += diff; + if ((diff > 0 && mode < 5) || (diff < 0 && mode > 0)) { + mode += diff; + SetBW(); + rssiMin = 255; + frequencyChangeStep = modeHalfSpectrumBW[mode]; } - frequencyChangeStep = 100_KHz << bwMul; } void UpdateCurrentFreq(i64 diff) { @@ -267,7 +264,9 @@ template class CSpectrum { oldAFSettings = BK4819Read(0x47); oldBWSettings = BK4819Read(0x43); MuteAF(); - SetWideBW(); + SetBW(); + ResetPeak(); + resetBlacklist = true; isInitialized = true; } @@ -282,19 +281,21 @@ template class CSpectrum { void ResetPeak() { peakRssi = 0; - peakF = currentFreq; + // peakF = currentFreq; peakT = 0; } - void SetWideBW() { + void SetBW() { auto Reg = BK4819Read(0x43); Reg &= ~(0b11 << 4); - BK4819Write(0x43, Reg | (0b11 << 4)); + if (mode >= 3) + Reg |= 0b11 << 4; + BK4819Write(0x43, Reg); } void MuteAF() { BK4819Write(0x47, 0); } void RestoreOldAFSettings() { BK4819Write(0x47, oldAFSettings); } - void Listen(u16 durationMs) { + void Listen() { if (fMeasure != peakF) { fMeasure = peakF; RadioDriver.SetFrequency(fMeasure); @@ -302,26 +303,17 @@ template class CSpectrum { RadioDriver.ToggleAFDAC(true); } for (u8 i = 0; i < 16 && PollKeyboard() == 255; ++i) { - DelayMs(durationMs >> 4); + DelayMs(64); } peakRssi = rssiHistory[peakI] = GetRssi(); } - u16 GetScanStep() { return 25_KHz >> (2 >> bwMul); } - u32 GetBW() { return 200_KHz << bwMul; } - u32 GetFStart() { return currentFreq - (100_KHz << bwMul); } - u32 GetFEnd() { return currentFreq + (100_KHz << bwMul); } + u16 GetScanStep() { return modeScanStep[mode]; } + u32 GetBW() { return modeHalfSpectrumBW[mode] << 1; } + u32 GetFStart() { return currentFreq - modeHalfSpectrumBW[mode]; } + u32 GetFEnd() { return currentFreq + modeHalfSpectrumBW[mode]; } - u8 BWMul2XDiv() { return clamp(4 - bwMul, 0, 2); } - u8 GetMeasurementsCount() { - if (bwMul == 3) { - return 64; - } - if (bwMul > 3) { - return 128; - } - return 32; - } + u8 GetMeasurementsCount() { return 128 >> modeXdiv[mode]; } void ResetRSSI() { RadioDriver.ToggleRXDSP(false); @@ -331,7 +323,7 @@ template class CSpectrum { u8 GetRssi() { ResetRSSI(); - DelayUs(scanDelay); + DelayUs(scanDelay << (mode < 3)); return (BK4819Read(0x67) & 0x1FF) >> 1; } @@ -355,25 +347,20 @@ template class CSpectrum { return v; } - u32 modulo(u32 num, u32 div) { - while (num >= div) - num -= div; - return num; - } - TUV_K5Display DisplayBuff; CDisplay Display; const TUV_K5SmallNumbers FontSmallNr; - u32 frequencyChangeStep; - u8 bwMul; + u16 scanDelay; + u8 mode; u8 rssiTriggerLevel; - u8 btn = 255; - u8 btnPrev = 255; + u8 btn; + u8 btnPrev; u32 currentFreq; u16 oldAFSettings; u16 oldBWSettings; + u32 frequencyChangeStep; bool isInitialized = false; }; From 3b0508bee838408e7157d6858c94037fb48c239c Mon Sep 17 00:00:00 2001 From: Mikhail Yudin Date: Sun, 13 Aug 2023 11:51:45 +0700 Subject: [PATCH 2/7] feat: better sensitivity, refactor --- libs/lcd/lcd.hpp | 8 +------- src/spectrum_fagci/spectrum.hpp | 32 ++++++++++++++++---------------- 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/libs/lcd/lcd.hpp b/libs/lcd/lcd.hpp index 31c4d19..e13c26b 100644 --- a/libs/lcd/lcd.hpp +++ b/libs/lcd/lcd.hpp @@ -256,14 +256,8 @@ template class CDisplay { startIdx = 8 - i; } - // If the number was 0, we write a single 0. - /* if (startIdx == 0) - U8NumBuff[0] = '0'; */ - // Print the string from the start index - if (u8FixedDigtsCnt) { - startIdx = 9 - u8DigsToCut - u8FixedDigtsCnt; - } + startIdx = 9 - u8DigsToCut - u8FixedDigtsCnt; const char *str = U8NumBuff + startIdx; const char len = strlen(str); diff --git a/src/spectrum_fagci/spectrum.hpp b/src/spectrum_fagci/spectrum.hpp index a58f092..ee49b1d 100644 --- a/src/spectrum_fagci/spectrum.hpp +++ b/src/spectrum_fagci/spectrum.hpp @@ -30,8 +30,7 @@ template class CSpectrum { CSpectrum() : DisplayBuff(gDisplayBuffer), Display(DisplayBuff), - FontSmallNr(gSmallDigs), scanDelay(1600), mode(4), - rssiTriggerLevel(60) { + FontSmallNr(gSmallDigs), scanDelay(800), mode(4), rssiTriggerLevel(60) { Display.SetFont(&FontSmallNr); frequencyChangeStep = modeHalfSpectrumBW[mode]; }; @@ -188,14 +187,18 @@ template class CSpectrum { DeInit(); return false; } - if (btn != 255 && btn == btnPrev) { - btnCounter = clamp(btnCounter + 1, 0, 255); - } else { - btnCounter = 0; - } - if ((btn != 255 && btnPrev == 255) || btnCounter > 16) { - OnKeyDown(btn); + + if (btn != 255) { + if (btn == btnPrev && btnCounter < 255) { + btnCounter++; + } + if (btnPrev == 255 || btnCounter > 16) { + OnKeyDown(btn); + } + return true; } + + btnCounter = 0; return true; } @@ -279,11 +282,7 @@ template class CSpectrum { isInitialized = false; } - void ResetPeak() { - peakRssi = 0; - // peakF = currentFreq; - peakT = 0; - } + void ResetPeak() { peakRssi = 0; } void SetBW() { auto Reg = BK4819Read(0x43); @@ -324,7 +323,8 @@ template class CSpectrum { ResetRSSI(); DelayUs(scanDelay << (mode < 3)); - return (BK4819Read(0x67) & 0x1FF) >> 1; + auto v = BK4819Read(0x67) & 0x1FF; + return v < 255 ? v : 255; } bool IsFlashLightOn() { return GPIOC->DATA & GPIO_PIN_3; } @@ -362,5 +362,5 @@ template class CSpectrum { u16 oldBWSettings; u32 frequencyChangeStep; - bool isInitialized = false; + bool isInitialized; }; From a8bb4df50797d8cf1297877bbc866f2f6135212d Mon Sep 17 00:00:00 2001 From: Mikhail Yudin Date: Sun, 13 Aug 2023 12:52:13 +0700 Subject: [PATCH 3/7] feat: turn green led off --- src/spectrum_fagci/spectrum.hpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/spectrum_fagci/spectrum.hpp b/src/spectrum_fagci/spectrum.hpp index ee49b1d..ec07a1c 100644 --- a/src/spectrum_fagci/spectrum.hpp +++ b/src/spectrum_fagci/spectrum.hpp @@ -214,9 +214,11 @@ template class CSpectrum { void Update() { if (peakRssi >= rssiTriggerLevel) { + // ToggleGreen(true); Listen(); } if (peakRssi < rssiTriggerLevel) { + // ToggleGreen(false); Scan(); } } @@ -270,6 +272,7 @@ template class CSpectrum { SetBW(); ResetPeak(); resetBlacklist = true; + ToggleGreen(false); isInitialized = true; } @@ -279,6 +282,7 @@ template class CSpectrum { RadioDriver.SetFrequency(currentFreq); RestoreOldAFSettings(); BK4819Write(0x43, oldBWSettings); + ToggleGreen(true); isInitialized = false; } @@ -335,16 +339,15 @@ template class CSpectrum { void ToggleBacklight() { GPIOB->DATA ^= GPIO_PIN_6; } + void ToggleRed(bool flag) { BK4819SetGpio(5, flag); } + void ToggleGreen(bool flag) { BK4819SetGpio(6, flag); } + u8 Rssi2Y(u8 rssi) { return DrawingEndY - clamp(rssi - rssiMin, 0, DrawingEndY); } i32 clamp(i32 v, i32 min, i32 max) { - if (v <= min) - return min; - if (v >= max) - return max; - return v; + return v <= min ? min : (v >= max ? max : v); } TUV_K5Display DisplayBuff; From b56c2eb68a53e6f81c11d3f68dc25c2196891873 Mon Sep 17 00:00:00 2001 From: Mikhail Yudin Date: Sun, 13 Aug 2023 13:36:18 +0700 Subject: [PATCH 4/7] feat: 32kHz to track satellite doppler, set BK bandwidth by api --- libs/k5_uv_system/api.s | 3 +++ libs/k5_uv_system/system.hpp | 1 + src/spectrum_fagci/spectrum.hpp | 15 ++++++++------- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/libs/k5_uv_system/api.s b/libs/k5_uv_system/api.s index bf2b86c..5f09def 100644 --- a/libs/k5_uv_system/api.s +++ b/libs/k5_uv_system/api.s @@ -43,6 +43,9 @@ BK4819Reset = 0xa7cc + 1; .globl IntDivide IntDivide = 0x128 + 1; +.globl BK4819SetChannelBandwidth +BK4819SetChannelBandwidth = 0xaa48 + 1; + .globl BK4819WriteFrequency BK4819WriteFrequency = 0xaabc + 1; diff --git a/libs/k5_uv_system/system.hpp b/libs/k5_uv_system/system.hpp index 672b8bf..ed02fb6 100644 --- a/libs/k5_uv_system/system.hpp +++ b/libs/k5_uv_system/system.hpp @@ -23,6 +23,7 @@ extern "C" { void AirCopyFskSetup(); void BK4819Reset(); int IntDivide(int s32Divident, int s32Divisor); + void BK4819SetChannelBandwidth(bool narrow); void BK4819WriteFrequency(unsigned int u32Frequency); void BK4819SetPaGain(unsigned short u16PaBias, unsigned int u32Frequency); void BK4819ConfigureAndStartTxFsk(); diff --git a/src/spectrum_fagci/spectrum.hpp b/src/spectrum_fagci/spectrum.hpp index ec07a1c..2ff7bee 100644 --- a/src/spectrum_fagci/spectrum.hpp +++ b/src/spectrum_fagci/spectrum.hpp @@ -10,11 +10,11 @@ template class CSpectrum { static constexpr auto DrawingEndY = 42; static constexpr auto BarPos = 5 * 128; - static constexpr u32 modeHalfSpectrumBW[6] = {50_KHz, 100_KHz, 200_KHz, + static constexpr u32 modeHalfSpectrumBW[6] = {16_KHz, 100_KHz, 200_KHz, 400_KHz, 800_KHz, 1600_KHz}; - static constexpr u16 modeScanStep[6] = {1562_Hz, 6250_Hz, 12500_Hz, - 25_KHz, 25_KHz, 25_KHz}; - static constexpr u8 modeXdiv[6] = {1, 2, 2, 2, 1, 0}; + static constexpr u16 modeScanStep[6] = {1_KHz, 6250_Hz, 12500_Hz, + 25_KHz, 25_KHz, 25_KHz}; + static constexpr u8 modeXdiv[6] = {2, 2, 2, 2, 1, 0}; u8 rssiHistory[128] = {}; u32 fMeasure; @@ -289,11 +289,12 @@ template class CSpectrum { void ResetPeak() { peakRssi = 0; } void SetBW() { - auto Reg = BK4819Read(0x43); + /* auto Reg = BK4819Read(0x43); Reg &= ~(0b11 << 4); if (mode >= 3) - Reg |= 0b11 << 4; - BK4819Write(0x43, Reg); + Reg |= 0b10 << 4; + BK4819Write(0x43, Reg); */ + BK4819SetChannelBandwidth(mode < 3); } void MuteAF() { BK4819Write(0x47, 0); } void RestoreOldAFSettings() { BK4819Write(0x47, oldAFSettings); } From 487b28177941496ec292b91882ec7749194ff835 Mon Sep 17 00:00:00 2001 From: Mikhail Yudin Date: Sun, 13 Aug 2023 14:46:53 +0700 Subject: [PATCH 5/7] feat: Strlen from fw, turn on green led on squelch open --- libs/k5_uv_system/api.s | 3 +++ libs/k5_uv_system/system.hpp | 1 + libs/lcd/lcd.hpp | 5 +++-- src/spectrum_fagci/spectrum.hpp | 13 +++---------- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/libs/k5_uv_system/api.s b/libs/k5_uv_system/api.s index 5f09def..d8c3f50 100644 --- a/libs/k5_uv_system/api.s +++ b/libs/k5_uv_system/api.s @@ -43,6 +43,9 @@ BK4819Reset = 0xa7cc + 1; .globl IntDivide IntDivide = 0x128 + 1; +.globl Strlen +Strlen = 0x1c0 + 1; + .globl BK4819SetChannelBandwidth BK4819SetChannelBandwidth = 0xaa48 + 1; diff --git a/libs/k5_uv_system/system.hpp b/libs/k5_uv_system/system.hpp index ed02fb6..c0ac537 100644 --- a/libs/k5_uv_system/system.hpp +++ b/libs/k5_uv_system/system.hpp @@ -23,6 +23,7 @@ extern "C" { void AirCopyFskSetup(); void BK4819Reset(); int IntDivide(int s32Divident, int s32Divisor); + int Strlen(const char *string); void BK4819SetChannelBandwidth(bool narrow); void BK4819WriteFrequency(unsigned int u32Frequency); void BK4819SetPaGain(unsigned short u16PaBias, unsigned int u32Frequency); diff --git a/libs/lcd/lcd.hpp b/libs/lcd/lcd.hpp index e13c26b..c649f1b 100644 --- a/libs/lcd/lcd.hpp +++ b/libs/lcd/lcd.hpp @@ -1,6 +1,7 @@ #pragma once #include #include +#include "system.hpp" struct ILcd { virtual void UpdateScreen() = 0; @@ -161,7 +162,7 @@ template class CDisplay { } void Print(const char *C8String) const { - for (unsigned char i = 0; i < strlen(C8String); i++) { + for (unsigned char i = 0; i < Strlen(C8String); i++) { PrintCharacter(C8String[i]); } } @@ -260,7 +261,7 @@ template class CDisplay { startIdx = 9 - u8DigsToCut - u8FixedDigtsCnt; const char *str = U8NumBuff + startIdx; - const char len = strlen(str); + const char len = Strlen(str); const char dot[1] = {64}; for (unsigned char i = 0; i < len; i++) { if (pointAt == len - i) { diff --git a/src/spectrum_fagci/spectrum.hpp b/src/spectrum_fagci/spectrum.hpp index 2ff7bee..6fdef6d 100644 --- a/src/spectrum_fagci/spectrum.hpp +++ b/src/spectrum_fagci/spectrum.hpp @@ -214,11 +214,11 @@ template class CSpectrum { void Update() { if (peakRssi >= rssiTriggerLevel) { - // ToggleGreen(true); + ToggleGreen(true); Listen(); } if (peakRssi < rssiTriggerLevel) { - // ToggleGreen(false); + ToggleGreen(false); Scan(); } } @@ -288,14 +288,7 @@ template class CSpectrum { void ResetPeak() { peakRssi = 0; } - void SetBW() { - /* auto Reg = BK4819Read(0x43); - Reg &= ~(0b11 << 4); - if (mode >= 3) - Reg |= 0b10 << 4; - BK4819Write(0x43, Reg); */ - BK4819SetChannelBandwidth(mode < 3); - } + void SetBW() { BK4819SetChannelBandwidth(mode < 3); } void MuteAF() { BK4819Write(0x47, 0); } void RestoreOldAFSettings() { BK4819Write(0x47, oldAFSettings); } From 28817c7d3b0d0f1a094d1b91c287853e7e5f51ed Mon Sep 17 00:00:00 2001 From: Mikhail Yudin Date: Sun, 13 Aug 2023 16:02:55 +0700 Subject: [PATCH 6/7] feat: reverted 100KHz mode, smaller scan delay step, more precise numbers --- src/spectrum_fagci/spectrum.hpp | 36 +++++++++++++++++---------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/spectrum_fagci/spectrum.hpp b/src/spectrum_fagci/spectrum.hpp index 6fdef6d..7a7ed73 100644 --- a/src/spectrum_fagci/spectrum.hpp +++ b/src/spectrum_fagci/spectrum.hpp @@ -10,11 +10,13 @@ template class CSpectrum { static constexpr auto DrawingEndY = 42; static constexpr auto BarPos = 5 * 128; - static constexpr u32 modeHalfSpectrumBW[6] = {16_KHz, 100_KHz, 200_KHz, - 400_KHz, 800_KHz, 1600_KHz}; - static constexpr u16 modeScanStep[6] = {1_KHz, 6250_Hz, 12500_Hz, - 25_KHz, 25_KHz, 25_KHz}; - static constexpr u8 modeXdiv[6] = {2, 2, 2, 2, 1, 0}; + static constexpr auto ModesCount = 7; + + static constexpr u32 modeHalfSpectrumBW[ModesCount] = { + 16_KHz, 50_KHz, 100_KHz, 200_KHz, 400_KHz, 800_KHz, 1600_KHz}; + static constexpr u16 modeScanStep[ModesCount] = { + 1_KHz, 3125_Hz, 6250_Hz, 12500_Hz, 25_KHz, 25_KHz, 25_KHz}; + static constexpr u8 modeXdiv[ModesCount] = {2, 2, 2, 2, 2, 1, 0}; u8 rssiHistory[128] = {}; u32 fMeasure; @@ -30,7 +32,7 @@ template class CSpectrum { CSpectrum() : DisplayBuff(gDisplayBuffer), Display(DisplayBuff), - FontSmallNr(gSmallDigs), scanDelay(800), mode(4), rssiTriggerLevel(60) { + FontSmallNr(gSmallDigs), scanDelay(800), mode(5), rssiTriggerLevel(50) { Display.SetFont(&FontSmallNr); frequencyChangeStep = modeHalfSpectrumBW[mode]; }; @@ -89,10 +91,10 @@ template class CSpectrum { Display.SetCoursorXY(0, 0); Display.PrintFixedDigitsNumber3(scanDelay, 2, 2, 1); - Display.SetCoursorXY(112, 0); - Display.PrintFixedDigitsNumber3(GetBW(), 4, 2, 1); + Display.SetCoursorXY(105, 0); + Display.PrintFixedDigitsNumber3(GetBW(), 3, 3, 2); - Display.SetCoursorXY(44, 0); + Display.SetCoursorXY(42, 0); Display.PrintFixedDigitsNumber3(peakF, 2, 6, 3); Display.SetCoursorXY(0, 48); @@ -101,8 +103,8 @@ template class CSpectrum { Display.SetCoursorXY(98, 48); Display.PrintFixedDigitsNumber3(GetFEnd(), 4, 4, 1); - Display.SetCoursorXY(57, 48); - Display.PrintFixedDigitsNumber3(frequencyChangeStep, 4, 2, 1); + Display.SetCoursorXY(52, 48); + Display.PrintFixedDigitsNumber3(frequencyChangeStep, 3, 3, 2); } void DrawRssiTriggerLevel() { @@ -130,13 +132,13 @@ template class CSpectrum { switch (key) { case Keys::NUM1: if (scanDelay < 8000) { - scanDelay += 200; + scanDelay += 100; rssiMin = 255; } break; case Keys::NUM7: - if (scanDelay > 800) { - scanDelay -= 200; + if (scanDelay > 400) { + scanDelay -= 100; rssiMin = 255; } break; @@ -226,7 +228,7 @@ template class CSpectrum { void UpdateRssiTriggerLevel(i32 diff) { rssiTriggerLevel += diff; } void UpdateBWMul(i32 diff) { - if ((diff > 0 && mode < 5) || (diff < 0 && mode > 0)) { + if ((diff > 0 && mode < (ModesCount - 1)) || (diff < 0 && mode > 0)) { mode += diff; SetBW(); rssiMin = 255; @@ -288,7 +290,7 @@ template class CSpectrum { void ResetPeak() { peakRssi = 0; } - void SetBW() { BK4819SetChannelBandwidth(mode < 3); } + void SetBW() { BK4819SetChannelBandwidth(mode < 4); } void MuteAF() { BK4819Write(0x47, 0); } void RestoreOldAFSettings() { BK4819Write(0x47, oldAFSettings); } @@ -320,7 +322,7 @@ template class CSpectrum { u8 GetRssi() { ResetRSSI(); - DelayUs(scanDelay << (mode < 3)); + DelayUs(scanDelay << (mode < 4)); auto v = BK4819Read(0x67) & 0x1FF; return v < 255 ? v : 255; } From d050bdcf1929d9278d5ea56f21ac2f2c4d6c478e Mon Sep 17 00:00:00 2001 From: Mikhail Yudin Date: Mon, 14 Aug 2023 02:01:18 +0700 Subject: [PATCH 7/7] feat: disable sound completely when "squelch" closed --- src/spectrum_fagci/spectrum.hpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/spectrum_fagci/spectrum.hpp b/src/spectrum_fagci/spectrum.hpp index 7a7ed73..db54775 100644 --- a/src/spectrum_fagci/spectrum.hpp +++ b/src/spectrum_fagci/spectrum.hpp @@ -11,6 +11,7 @@ template class CSpectrum { static constexpr auto BarPos = 5 * 128; static constexpr auto ModesCount = 7; + static constexpr auto LastLowBWModeIndex = 3; static constexpr u32 modeHalfSpectrumBW[ModesCount] = { 16_KHz, 50_KHz, 100_KHz, 200_KHz, 400_KHz, 800_KHz, 1600_KHz}; @@ -28,8 +29,6 @@ template class CSpectrum { u8 rssiMin = 255; u8 btnCounter = 0; - bool resetBlacklist = false; - CSpectrum() : DisplayBuff(gDisplayBuffer), Display(DisplayBuff), FontSmallNr(gSmallDigs), scanDelay(800), mode(5), rssiTriggerLevel(50) { @@ -44,7 +43,7 @@ template class CSpectrum { fMeasure = GetFStart(); - RadioDriver.ToggleAFDAC(false); + // RadioDriver.ToggleAFDAC(false); MuteAF(); u16 scanStep = GetScanStep(); @@ -217,10 +216,12 @@ template class CSpectrum { void Update() { if (peakRssi >= rssiTriggerLevel) { ToggleGreen(true); + GPIOC->DATA |= GPIO_PIN_4; Listen(); } if (peakRssi < rssiTriggerLevel) { ToggleGreen(false); + GPIOC->DATA &= ~GPIO_PIN_4; Scan(); } } @@ -290,7 +291,7 @@ template class CSpectrum { void ResetPeak() { peakRssi = 0; } - void SetBW() { BK4819SetChannelBandwidth(mode < 4); } + void SetBW() { BK4819SetChannelBandwidth(mode <= LastLowBWModeIndex); } void MuteAF() { BK4819Write(0x47, 0); } void RestoreOldAFSettings() { BK4819Write(0x47, oldAFSettings); } @@ -299,7 +300,7 @@ template class CSpectrum { fMeasure = peakF; RadioDriver.SetFrequency(fMeasure); RestoreOldAFSettings(); - RadioDriver.ToggleAFDAC(true); + // RadioDriver.ToggleAFDAC(true); } for (u8 i = 0; i < 16 && PollKeyboard() == 255; ++i) { DelayMs(64); @@ -322,7 +323,7 @@ template class CSpectrum { u8 GetRssi() { ResetRSSI(); - DelayUs(scanDelay << (mode < 4)); + DelayUs(scanDelay << (mode <= LastLowBWModeIndex)); auto v = BK4819Read(0x67) & 0x1FF; return v < 255 ? v : 255; } @@ -362,4 +363,5 @@ template class CSpectrum { u32 frequencyChangeStep; bool isInitialized; + bool resetBlacklist; };