Skip to content

Commit

Permalink
add spectrum analyser for multiprtocol modul
Browse files Browse the repository at this point in the history
  • Loading branch information
multigcs committed Sep 8, 2019
1 parent 298d394 commit 9afce1e
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 4 deletions.
3 changes: 3 additions & 0 deletions radio/src/gui/480x272/menus.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ bool menuRadioHardware(event_t event);
bool menuRadioCalibration(event_t event);
bool menuRadioSpectrumAnalyser(event_t event);
bool menuRadioPowerMeter(event_t event);
#if defined(MULTIMODUL_ANALYSER)
bool menuMultiModuleAnalyser(event_t event);
#endif

extern const MenuHandlerFunc menuTabGeneral[MENU_RADIO_PAGES_COUNT];

Expand Down
5 changes: 4 additions & 1 deletion radio/src/gui/480x272/radio_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ bool menuRadioTools(event_t event)
if (isPXX2ModuleOptionAvailable(reusableBuffer.radioTools.modules[EXTERNAL_MODULE].information.modelID, MODULE_OPTION_POWER_METER))
addRadioModuleTool(index++, STR_POWER_METER_EXT, menuRadioPowerMeter, EXTERNAL_MODULE);
#endif
#if defined(MULTIMODUL_ANALYSER)
addRadioModuleTool(index++, STR_SPECTRUM_ANALYSER_EXT, menuMultiModuleAnalyser, EXTERNAL_MODULE);
#endif

#if defined(LUA)
FILINFO fno;
Expand Down Expand Up @@ -132,4 +135,4 @@ bool menuRadioTools(event_t event)
reusableBuffer.radioTools.linesCount = index;

return true;
}
}
1 change: 1 addition & 0 deletions radio/src/gui/gui_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,7 @@ const mm_protocol_definition multi_protocols[] = {
{MODULE_SUBTYPE_MULTI_POTENSIC, 0, false, STR_SUBTYPE_POTENSIC, nullptr},
{MODULE_SUBTYPE_MULTI_ZSX, 0, false, STR_SUBTYPE_ZSX, nullptr},
{MODULE_SUBTYPE_MULTI_FLYZONE, 0, false, STR_SUBTYPE_FLYZONE, nullptr},
{MODULE_SUBTYPE_MULTI_SCANNER, 0, false, NO_SUBTYPE, nullptr},
{MM_RF_CUSTOM_SELECTED, 7, true, NO_SUBTYPE, STR_MULTI_OPTION},

// Sentinel and default for protocols not listed above (MM_RF_CUSTOM is 0xff)
Expand Down
3 changes: 2 additions & 1 deletion radio/src/pulses/modules_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ enum ModuleSubtypeMulti {
MODULE_SUBTYPE_MULTI_POTENSIC,
MODULE_SUBTYPE_MULTI_ZSX,
MODULE_SUBTYPE_MULTI_FLYZONE,
MODULE_SUBTYPE_MULTI_LAST = MODULE_SUBTYPE_MULTI_FLYZONE
MODULE_SUBTYPE_MULTI_SCANNER,
MODULE_SUBTYPE_MULTI_LAST = MODULE_SUBTYPE_MULTI_SCANNER
};

enum MMDSM2Subtypes {
Expand Down
14 changes: 14 additions & 0 deletions radio/src/pulses/multi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
#define MULTI_CHANS 16
#define MULTI_CHAN_BITS 11

#if defined(MULTIMODUL_ANALYSER)
extern uint8_t MultiModuleAnalyserActive;
#endif

static void sendFrameProtocolHeader(uint8_t port, bool failsafe);

void sendChannels(uint8_t port);
Expand Down Expand Up @@ -148,6 +152,16 @@ void sendChannels(uint8_t port)
void sendFrameProtocolHeader(uint8_t port, bool failsafe)
{// byte 1+2, protocol information

#if defined(MULTIMODUL_ANALYSER)
if (MultiModuleAnalyserActive == 1) {
sendByteSbus(0x54);
sendByteSbus(22);
sendByteSbus(0);
sendByteSbus(0);
return;
}
#endif

// Our enumeration starts at 0
int type = g_model.moduleData[port].getMultiProtocol(false) + 1;
int subtype = g_model.moduleData[port].subType;
Expand Down
5 changes: 5 additions & 0 deletions radio/src/targets/horus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ if (PCB STREQUAL X10)
set(FLAVOUR t16)
option(INTERNAL_MODULE_PXX1 "Support for PXX1 internal module" ON)
option(INTERNAL_MODULE_PXX2 "Support for PXX2 internal module" OFF)
option(MULTIMODUL_ANALYSER "Support for Multimodul Spectrum-Analyser" ON)
else()
set(FLAVOUR x10)
option(INTERNAL_MODULE_PXX1 "Support for PXX1 internal module" ON)
Expand Down Expand Up @@ -104,6 +105,10 @@ if(INTERNAL_MODULE_PXX2)
add_definitions(-DINTERNAL_MODULE_PXX2)
endif()

if(MULTIMODUL_ANALYSER)
add_definitions(-DMULTIMODUL_ANALYSER)
endif()

include_directories(${RADIO_SRC_DIRECTORY}/fonts/480x272 gui/${GUI_DIR} gui/${GUI_DIR}/layouts)

file(GLOB THEMES_SRC RELATIVE ${RADIO_SRC_DIRECTORY}/gui/480x272 ${RADIO_SRC_DIRECTORY}/gui/480x272/themes/*.cpp)
Expand Down
95 changes: 94 additions & 1 deletion radio/src/telemetry/multi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

MultiModuleStatus multiModuleStatus;
MultiModuleSyncStatus multiSyncStatus;
#if defined(MULTIMODUL_ANALYSER)
MultiModuleAnalyser multiModuleAnalyser;
#endif
uint8_t multiBindStatus = MULTI_NORMAL_OPERATION;


Expand All @@ -35,7 +38,9 @@ enum MultiPacketTypes : uint8_t {
FlyskyIBusTelemetry,
ConfigCommand,
InputSync,
FrskySportPolling
FrskySportPolling,
HitecTelemetry,
SpectrumScannerPacket
};

enum MultiBufferState : uint8_t {
Expand Down Expand Up @@ -96,6 +101,14 @@ static void processMultiSyncPacket(const uint8_t *data)
#endif
}

#if defined(MULTIMODUL_ANALYSER)
static void processMultiScannerPacket(const uint8_t *data)
{
if (data[0] < MULTIMODUL_ANALYSER_CHANNELS) {
multiModuleAnalyser.data[data[0]] = data[1] * MULTIMODUL_ANALYSER_SCALE;
}
}
#endif

static void processMultiTelemetryPaket(const uint8_t *packet)
{
Expand Down Expand Up @@ -165,6 +178,15 @@ static void processMultiTelemetryPaket(const uint8_t *packet)
break;
#endif

#if defined(MULTIMODUL_ANALYSER)
case SpectrumScannerPacket:
if (len == 2)
processMultiScannerPacket(data);
else
TRACE("[MP] Received spectrum scanner len %d != 2", len);
break;
#endif

default:
TRACE("[MP] Unkown multi packet type 0x%02X, len %d", type, len);
break;
Expand Down Expand Up @@ -472,3 +494,74 @@ void processMultiTelemetryData(const uint8_t data)

}

#if defined(MULTIMODUL_ANALYSER)
#define DRAW_Y (LCD_H - MENU_FOOTER_HEIGHT - 12)
#define DRAW_H (LCD_H - MENU_HEADER_HEIGHT - MENU_FOOTER_HEIGHT - 12)
#define DRAW_XS ((LCD_W - 4) / MULTIMODUL_ANALYSER_CHANNELS)
#define DRAW_MAXVAL 160

uint8_t MultiModuleAnalyserActive = 0;

bool menuMultiModuleAnalyser(event_t event)
{
SUBMENU(STR_MENU_SPECTRUM_ANALYSER, ICON_RADIO_SPECTRUM_ANALYSER, 1, {1});

if (menuEvent) {
MultiModuleAnalyserActive = 0;
lcdDrawCenteredText(LCD_H/2, STR_STOPPING);
lcdRefresh();
watchdogSuspend(300);
RTOS_WAIT_MS(300);
return false;
}

MultiModuleAnalyserActive = 1;

lcdDrawFilledRect(0, MENU_HEADER_HEIGHT, LCD_W, DRAW_H, SOLID, OVERLAY_COLOR);
int maxv = 0;
int maxvch = 0;
for (int ch=0; ch<MULTIMODUL_ANALYSER_CHANNELS; ch++) {
if (multiModuleAnalyser.max[ch] < multiModuleAnalyser.data[ch]) {
multiModuleAnalyser.max[ch] = multiModuleAnalyser.data[ch];
}
if (maxv < multiModuleAnalyser.data[ch]) {
maxv = multiModuleAnalyser.data[ch];
maxvch = ch;
}
for (int y=0; y<=multiModuleAnalyser.data[ch] * DRAW_H / DRAW_MAXVAL; y+=1) {
lcdDrawPointColor(2 + ch * DRAW_XS - 1, DRAW_Y - y, RGB(200 + y * 55 / DRAW_H, 255 - (y * 255 / DRAW_H), 0));
lcdDrawPointColor(2 + ch * DRAW_XS, DRAW_Y - y, RGB(200 + y * 55 / DRAW_H, 255 - (y * 255 / DRAW_H), 0));
lcdDrawPointColor(2 + ch * DRAW_XS + 1, DRAW_Y - y, RGB(200 + y * 55 / DRAW_H, 255 - (y * 255 / DRAW_H), 0));

}
lcdDrawPointColor(2 + ch * DRAW_XS - 1, DRAW_Y - (multiModuleAnalyser.max[ch] * DRAW_H / DRAW_MAXVAL), YELLOW);
lcdDrawPointColor(2 + ch * DRAW_XS, DRAW_Y - (multiModuleAnalyser.max[ch] * DRAW_H / DRAW_MAXVAL), YELLOW);
lcdDrawPointColor(2 + ch * DRAW_XS + 1, DRAW_Y - (multiModuleAnalyser.max[ch] * DRAW_H / DRAW_MAXVAL), YELLOW);

if (ch > 0 && ch % 10 == 0) {
lcdDrawPointColor(2 + ch * DRAW_XS, DRAW_Y + 1, TEXT_COLOR);
lcdDrawPointColor(2 + ch * DRAW_XS, DRAW_Y + 2, TEXT_COLOR);
lcdDrawNumber(2 + ch * DRAW_XS - 12, DRAW_Y + 1, 2400 + ch, TINSIZE | TEXT_COLOR);
}
}

lcdDrawText(2 + (MULTIMODUL_ANALYSER_CHANNELS + 1) * DRAW_XS, DRAW_Y + 1, "Mhz", TINSIZE | TEXT_COLOR);

for (int ch=0; ch<MULTIMODUL_ANALYSER_CHANNELS; ch++) {
if (multiModuleAnalyser.max[ch] > 0) {
multiModuleAnalyser.max[ch]--;
}
}

int ty = 5;
lcdDrawText(LCD_W - 80, MENU_HEADER_HEIGHT + ty, "MaxRSSI:", TINSIZE | TEXT_INVERTED_COLOR);
lcdDrawNumber(LCD_W - 80 + 50, MENU_HEADER_HEIGHT + ty, maxv / MULTIMODUL_ANALYSER_SCALE, TINSIZE | TEXT_INVERTED_COLOR);
ty += 10;
lcdDrawText(LCD_W - 80, MENU_HEADER_HEIGHT + ty, "MaxCH:", TINSIZE | TEXT_INVERTED_COLOR);
lcdDrawNumber(LCD_W - 80 + 50, MENU_HEADER_HEIGHT + ty, 2400 + maxvch, TINSIZE | TEXT_INVERTED_COLOR);
ty += 10;

return true;
}
#endif

12 changes: 12 additions & 0 deletions radio/src/telemetry/multi.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,16 @@ enum MultiBindStatus : uint8_t {

extern uint8_t multiBindStatus;

#if defined(MULTIMODUL_ANALYSER)
#define MULTIMODUL_ANALYSER_CHANNELS 98
#define MULTIMODUL_ANALYSER_SCALE 12

struct MultiModuleAnalyser {
uint8_t data[MULTIMODUL_ANALYSER_CHANNELS];
uint8_t max[MULTIMODUL_ANALYSER_CHANNELS];
};

extern MultiModuleAnalyser multiModuleAnalyser;
#endif

#endif //OPENTX_MULTI_H
2 changes: 1 addition & 1 deletion radio/src/translations/untranslated.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,4 @@
#define TR_DSM_PROTOCOLS "LP45""DSM2""DSMX"

#define LEN_MULTI_PROTOCOLS "\007"
#define TR_MULTI_PROTOCOLS "FlySky\0""Hubsan\0""FrSky\0 ""Hisky\0 ""V2x2\0 ""DSM\0 ""Devo\0 ""YD717\0 ""KN\0 ""SymaX\0 ""SLT\0 ""CX10\0 ""CG023\0 ""Bayang\0""ESky\0 ""MT99XX\0""MJXq\0 ""Shenqi\0""FY326\0 ""SFHSS\0 ""J6 Pro\0""FQ777\0 ""Assan\0 ""Hontai\0""OpenLrs""FSky 2A""Q2x2\0 ""Walkera""Q303\0 ""GW008\0 ""DM002\0 ""Cabell\0""Esky150""H8 3D\0 ""Corona\0""CFlie\0 ""Hitec\0 ""WFly\0 ""Bugs\0 ""BugMini""Traxxas""NCC1701""E01X\0 ""V911S\0 ""GD00X\0 ""V761\0 ""KF606\0 ""Redpine""Potensi""ZSX\0 ""FlyZone"
#define TR_MULTI_PROTOCOLS "FlySky\0""Hubsan\0""FrSky\0 ""Hisky\0 ""V2x2\0 ""DSM\0 ""Devo\0 ""YD717\0 ""KN\0 ""SymaX\0 ""SLT\0 ""CX10\0 ""CG023\0 ""Bayang\0""ESky\0 ""MT99XX\0""MJXq\0 ""Shenqi\0""FY326\0 ""SFHSS\0 ""J6 Pro\0""FQ777\0 ""Assan\0 ""Hontai\0""OpenLrs""FSky 2A""Q2x2\0 ""Walkera""Q303\0 ""GW008\0 ""DM002\0 ""Cabell\0""Esky150""H8 3D\0 ""Corona\0""CFlie\0 ""Hitec\0 ""WFly\0 ""Bugs\0 ""BugMini""Traxxas""NCC1701""E01X\0 ""V911S\0 ""GD00X\0 ""V761\0 ""KF606\0 ""Redpine""Potensi""ZSX\0 ""FlyZone""Scanner"

0 comments on commit 9afce1e

Please sign in to comment.