diff --git a/App/app/spectrum.c b/App/app/spectrum.c index 653e9a5f..a8577e4e 100644 --- a/App/app/spectrum.c +++ b/App/app/spectrum.c @@ -148,7 +148,6 @@ static void LoadSettings() static void SaveSettings() { uint8_t Data[8] = {0}; - // 1FF0..0x1FF7 PY25Q16_ReadBuffer(0x00c000, Data, sizeof(Data)); Data[3] = (settings.scanStepIndex << 4) | (settings.stepsCount << 2) | settings.listenBw; @@ -368,6 +367,36 @@ static void ResetPeak() peak.rssi = 0; } +#ifdef ENABLE_FEAT_F4HWN_SPECTRUM + static void setTailFoundInterrupt() + { + BK4819_WriteRegister(BK4819_REG_3F, BK4819_REG_02_CxCSS_TAIL | BK4819_REG_02_SQUELCH_FOUND); + } + + static bool checkIfTailFound() + { + uint16_t interrupt_status_bits; + // if interrupt waiting to be handled + if(BK4819_ReadRegister(BK4819_REG_0C) & 1u) { + // reset the interrupt + BK4819_WriteRegister(BK4819_REG_02, 0); + // fetch the interrupt status bits + interrupt_status_bits = BK4819_ReadRegister(BK4819_REG_02); + // if tail found interrupt + if (interrupt_status_bits & BK4819_REG_02_CxCSS_TAIL) + { + listenT = 0; + // disable interrupts + BK4819_WriteRegister(BK4819_REG_3F, 0); + // reset the interrupt + BK4819_WriteRegister(BK4819_REG_02, 0); + return true; + } + } + return false; + } +#endif + bool IsCenterMode() { return settings.scanStepIndex < S_STEP_2_5kHz; } // scan step in 0.01khz uint16_t GetScanStep() { return scanStepValues[settings.scanStepIndex]; } @@ -446,9 +475,14 @@ static void ToggleAudio(bool on) static void ToggleRX(bool on) { + #ifdef ENABLE_FEAT_F4HWN_SPECTRUM + if (isListening == on) { + return; + } + #endif isListening = on; - RADIO_SetupAGC(on, lockAGC); + RADIO_SetupAGC(settings.modulationType == MODULATION_AM, lockAGC); BK4819_ToggleGpioOut(BK4819_GPIO6_PIN2_GREEN, on); ToggleAudio(on); @@ -457,8 +491,14 @@ static void ToggleRX(bool on) if (on) { + #ifdef ENABLE_FEAT_F4HWN_SPECTRUM + listenT = 100; + BK4819_WriteRegister(0x43, listenBWRegValues[settings.listenBw]); + setTailFoundInterrupt(); + #else listenT = 1000; BK4819_WriteRegister(0x43, listenBWRegValues[settings.listenBw]); + #endif } else { @@ -879,19 +919,20 @@ uint8_t Rssi2Y(uint16_t rssi) uint8_t shift_graph = 64 / steps + 1; uint8_t ox = 0; - for (uint8_t i = 0; i < 128; ++i) + for (uint8_t i = 0; i < bars; ++i) { - uint16_t rssi = rssiHistory[i >> settings.stepsCount]; + uint16_t rssi = rssiHistory[(bars>128) ? i >> settings.stepsCount : i]; + // stretch bars to fill the screen width + uint8_t x = i * 128 / bars + shift_graph; + if (rssi != RSSI_MAX_VALUE) { - // stretch bars to fill the screen width - uint8_t x = i * 128 / bars + shift_graph; for (uint8_t xx = ox; xx < x; xx++) { DrawVLine(Rssi2Y(rssi), DrawingEndY, xx, true); } - ox = x; } + ox = x; } } #else @@ -949,36 +990,33 @@ static void DrawStatus() #ifdef ENABLE_FEAT_F4HWN_SPECTRUM static void ShowChannelName(uint32_t f) { - unsigned int i; - char String[12]; - memset(String, 0, sizeof(String)); + static uint32_t channelF = 0; + static char channelName[12]; if (isListening) { - for (i = 0; IS_MR_CHANNEL(i); i++) - { - if (RADIO_CheckValidChannel(i, false, 0)) + if (f != channelF) { + channelF = f; + unsigned int i; + memset(channelName, 0, sizeof(channelName)); + for (i = 0; IS_MR_CHANNEL(i); i++) { - if (SETTINGS_FetchChannelFrequency(i) == f) + if (RADIO_CheckValidChannel(i, false, 0)) { - SETTINGS_FetchChannelName(String, i); - if (String[0] != 0) { - UI_PrintStringSmallBufferNormal(String, gStatusLine + 36); - //GUI_DisplaySmallest(String, 127, 1, true, true); + if (SETTINGS_FetchChannelFrequency(i) == channelF) + { + SETTINGS_FetchChannelName(channelName, i); + break; } - break; } } } + if (channelName[0] != 0) { + UI_PrintStringSmallBufferNormal(channelName, gStatusLine + 36); + } } else { - /* - for (int i = 36; i < 100; i++) - { - gStatusLine[i] = 0b00000000; - } - */ memset(&gStatusLine[36], 0, 100 - 28); } ST7565_BlitStatusLine(); @@ -1309,9 +1347,6 @@ static void RenderStatus() { memset(gStatusLine, 0, sizeof(gStatusLine)); DrawStatus(); -#ifdef ENABLE_FEAT_F4HWN_SPECTRUM - ShowChannelName(peak.f); -#endif ST7565_BlitStatusLine(); } @@ -1503,7 +1538,7 @@ static void UpdateScan() return; } - if (scanInfo.measurementsCount < 128) + if (! (scanInfo.measurementsCount >> 7)) // if (scanInfo.measurementsCount < 128) memset(&rssiHistory[scanInfo.measurementsCount], 0, sizeof(rssiHistory) - scanInfo.measurementsCount * sizeof(rssiHistory[0])); @@ -1530,13 +1565,20 @@ static void UpdateStill() peak.rssi = scanInfo.rssi; AutoTriggerLevel(); - ToggleRX(IsPeakOverLevel() || monitorMode); + if (IsPeakOverLevel() || monitorMode) { + ToggleRX(true); + } } static void UpdateListening() { preventKeypress = false; + #ifdef ENABLE_FEAT_F4HWN_SPECTRUM + bool tailFound = checkIfTailFound(); + if (tailFound) + #else if (currentState == STILL) + #endif { listenT = 0; } @@ -1561,11 +1603,19 @@ static void UpdateListening() peak.rssi = scanInfo.rssi; redrawScreen = true; - if (IsPeakOverLevel() || monitorMode) - { - listenT = 1000; - return; - } + #ifdef ENABLE_FEAT_F4HWN_SPECTRUM + if ((IsPeakOverLevel() && !tailFound) || monitorMode) + { + listenT = 100; + return; + } + #else + if (IsPeakOverLevel() || monitorMode) + { + listenT = 1000; + return; + } + #endif ToggleRX(false); ResetScanStats();