mirror of
https://github.com/opentx/opentx.git
synced 2025-07-23 16:25:16 +03:00
Spectrum analyser reworked (#6836)
* Spectrum analyser reworked * Fix typo * Cosmetics * Cosmetics * yet another overall look update * T16 compilations fixes * Various Taranis compile fixes * Cosmetics * Cosmetics * Cosmetics * Cosmetics fixes
This commit is contained in:
parent
7094a744d6
commit
891c13e98d
16 changed files with 284 additions and 131 deletions
|
@ -21,10 +21,12 @@
|
|||
#include "telemetry.h"
|
||||
#include "multi.h"
|
||||
|
||||
extern uint8_t g_moduleIdx;
|
||||
|
||||
enum MultiPacketTypes : uint8_t
|
||||
{
|
||||
MultiStatus = 1,
|
||||
FrSkySportTelemtry,
|
||||
FrSkySmoduleIdxTelemtry,
|
||||
FrSkyHubTelemetry,
|
||||
SpektrumTelemetry,
|
||||
DSMBindPacket,
|
||||
|
@ -138,7 +140,14 @@ void setMultiTelemetryBufferState(uint8_t, MultiBufferState state)
|
|||
|
||||
static MultiBufferState guessProtocol(uint8_t module)
|
||||
{
|
||||
if (g_model.moduleData[module].getMultiProtocol(false) == MODULE_SUBTYPE_MULTI_DSM2)
|
||||
uint32_t moduleIdx = EXTERNAL_MODULE;
|
||||
#if defined(INTERNAL_MODULE_MULTI)
|
||||
if (isModuleMultimodule(INTERNAL_MODULE)) {
|
||||
moduleIdx = INTERNAL_MODULE;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (g_model.moduleData[moduleIdx].getMultiProtocol(false) == MODULE_SUBTYPE_MULTI_DSM2)
|
||||
return SpektrumTelemetryFallback;
|
||||
else if (g_model.moduleData[module].getMultiProtocol(false) == MODULE_SUBTYPE_MULTI_FS_AFHDS2A)
|
||||
return FlyskyTelemetryFallback;
|
||||
|
@ -146,6 +155,44 @@ static MultiBufferState guessProtocol(uint8_t module)
|
|||
return FrskyTelemetryFallback;
|
||||
}
|
||||
|
||||
static void processMultiScannerPacket(const uint8_t *data)
|
||||
{
|
||||
uint8_t cur_channel = data[0];
|
||||
if (moduleState[g_moduleIdx].mode == MODULE_MODE_SPECTRUM_ANALYSER) {
|
||||
for (uint8_t channel = 0; channel <5; channel++) {
|
||||
uint8_t power = max<int>(0,(data[channel+1] - 34) >> 1); // remove everything below -120dB
|
||||
|
||||
#if LCD_W == 480
|
||||
coord_t x = cur_channel*2;
|
||||
if (x < LCD_W) {
|
||||
reusableBuffer.spectrumAnalyser.bars[x] = power;
|
||||
reusableBuffer.spectrumAnalyser.bars[x+1] = power;
|
||||
if (power > reusableBuffer.spectrumAnalyser.max[x]) {
|
||||
reusableBuffer.spectrumAnalyser.max[x] = power;
|
||||
reusableBuffer.spectrumAnalyser.max[x+1] = power;
|
||||
}
|
||||
#elif LCD_W == 212
|
||||
coord_t x = cur_channel;
|
||||
if (x <= LCD_W) {
|
||||
reusableBuffer.spectrumAnalyser.bars[x] = power;
|
||||
if (power > reusableBuffer.spectrumAnalyser.max[x]) {
|
||||
reusableBuffer.spectrumAnalyser.max[x] = power;
|
||||
}
|
||||
#else
|
||||
coord_t x = cur_channel/2 + 1;
|
||||
if (x <= LCD_W) {
|
||||
reusableBuffer.spectrumAnalyser.bars[x] = power;
|
||||
if (power > reusableBuffer.spectrumAnalyser.max[x]) {
|
||||
reusableBuffer.spectrumAnalyser.max[x] = power;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (++cur_channel > MULTI_SCANNER_MAX_CHANNEL)
|
||||
cur_channel = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void processMultiStatusPacket(const uint8_t * data, uint8_t module)
|
||||
{
|
||||
MultiModuleStatus &status = getMultiModuleStatus(module);
|
||||
|
@ -248,11 +295,11 @@ static void processMultiTelemetryPaket(const uint8_t * packet, uint8_t module)
|
|||
TRACE("[MP] Received Frsky HUB telemetry len %d < 4", len);
|
||||
break;
|
||||
|
||||
case FrSkySportTelemtry:
|
||||
case FrSkySmoduleIdxTelemtry:
|
||||
if (len >= 4)
|
||||
sportProcessTelemetryPacket(data);
|
||||
else
|
||||
TRACE("[MP] Received sport telemetry len %d < 4", len);
|
||||
TRACE("[MP] Received smoduleIdx telemetry len %d < 4", len);
|
||||
break;
|
||||
|
||||
case InputSync:
|
||||
|
@ -269,11 +316,17 @@ static void processMultiTelemetryPaket(const uint8_t * packet, uint8_t module)
|
|||
#if defined(LUA)
|
||||
case FrskySportPolling:
|
||||
if (len >= 1 && outputTelemetryBuffer.destination == TELEMETRY_ENDPOINT_SPORT && data[0] == outputTelemetryBuffer.sport.physicalId) {
|
||||
TRACE("MP Sending sport data out.");
|
||||
TRACE("MP Sending smoduleIdx data out.");
|
||||
sportSendBuffer(outputTelemetryBuffer.data, outputTelemetryBuffer.size);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
case SpectrumScannerPacket:
|
||||
if (len == 6)
|
||||
processMultiScannerPacket(data);
|
||||
else
|
||||
TRACE("[MP] Received spectrum scanner len %d != 6", len);
|
||||
break;
|
||||
|
||||
default:
|
||||
TRACE("[MP] Unkown multi packet type 0x%02X, len %d", type, len);
|
||||
|
@ -319,7 +372,7 @@ void MultiModuleSyncStatus::calcAdjustedRefreshRate(uint16_t newRefreshRate, uin
|
|||
return;
|
||||
}
|
||||
|
||||
// Caluclate how many samples went into the reported input Lag (*10)
|
||||
// Caluclate how many samples went into the remoduleIdxed input Lag (*10)
|
||||
int numsamples = interval * 10000 / targetRefreshRate;
|
||||
|
||||
// Convert lagDifference to ps
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue