diff --git a/radio/src/gui/common/stdlcd/radio_power_meter.cpp b/radio/src/gui/common/stdlcd/radio_power_meter.cpp index 6f010e7d8a..79a587e58c 100644 --- a/radio/src/gui/common/stdlcd/radio_power_meter.cpp +++ b/radio/src/gui/common/stdlcd/radio_power_meter.cpp @@ -22,14 +22,10 @@ #include "opentx.h" void pxx2ModuleRequiredScreen(event_t event); +extern uint8_t g_moduleIdx; void menuRadioPowerMeter(event_t event) { - if (!isModulePXX2(INTERNAL_MODULE)) { - pxx2ModuleRequiredScreen(event); - return; - } - if (TELEMETRY_STREAMING()) { lcdDrawCenteredText(LCD_H/2, "Turn off receiver"); return; @@ -39,18 +35,21 @@ void menuRadioPowerMeter(event_t event) if (menuEvent) { pausePulses(); - moduleSettings[INTERNAL_MODULE].mode = MODULE_MODE_NORMAL; + moduleSettings[g_moduleIdx].mode = MODULE_MODE_NORMAL; /* wait 500ms off */ watchdogSuspend(500); RTOS_WAIT_MS(500); resumePulses(); + /* wait 500ms to resume normal operation before leaving */ + watchdogSuspend(500); + RTOS_WAIT_MS(500); return; } - if (moduleSettings[INTERNAL_MODULE].mode != MODULE_MODE_POWER_METER) { + if (moduleSettings[g_moduleIdx].mode != MODULE_MODE_POWER_METER) { memclear(&reusableBuffer.powerMeter, sizeof(reusableBuffer.powerMeter)); reusableBuffer.powerMeter.freq = 2400; - moduleSettings[INTERNAL_MODULE].mode = MODULE_MODE_POWER_METER; + moduleSettings[g_moduleIdx].mode = MODULE_MODE_POWER_METER; } coord_t y = MENU_HEADER_HEIGHT + 1 + FH; diff --git a/radio/src/gui/common/stdlcd/radio_spectrum_analyser.cpp b/radio/src/gui/common/stdlcd/radio_spectrum_analyser.cpp index 64d6668e6e..e32b9ddfd6 100644 --- a/radio/src/gui/common/stdlcd/radio_spectrum_analyser.cpp +++ b/radio/src/gui/common/stdlcd/radio_spectrum_analyser.cpp @@ -21,14 +21,10 @@ #include "opentx.h" extern void pxx2ModuleRequiredScreen(event_t event); +extern uint8_t g_moduleIdx; void menuRadioSpectrumAnalyser(event_t event) { - if (!isModulePXX2(INTERNAL_MODULE)) { - pxx2ModuleRequiredScreen(event); - return; - } - if (TELEMETRY_STREAMING()) { lcdDrawCenteredText(15, "Turn off receiver"); return; @@ -38,17 +34,23 @@ void menuRadioSpectrumAnalyser(event_t event) if (menuEvent) { pausePulses(); - moduleSettings[INTERNAL_MODULE].mode = MODULE_MODE_NORMAL; + moduleSettings[g_moduleIdx].mode = MODULE_MODE_NORMAL; /* wait 500ms off */ watchdogSuspend(500); RTOS_WAIT_MS(500); resumePulses(); + /* wait 500ms to resume normal operation before leaving */ + watchdogSuspend(500); + RTOS_WAIT_MS(500); return; } - if (moduleSettings[INTERNAL_MODULE].mode != MODULE_MODE_SPECTRUM_ANALYSER) { + if (moduleSettings[g_moduleIdx].mode != MODULE_MODE_SPECTRUM_ANALYSER) { memclear(reusableBuffer.spectrumAnalyser.bars, sizeof(reusableBuffer.spectrumAnalyser.bars)); - moduleSettings[INTERNAL_MODULE].mode = MODULE_MODE_SPECTRUM_ANALYSER; + reusableBuffer.spectrumAnalyser.span = 40000000; // 40MHz + reusableBuffer.spectrumAnalyser.freq = 2440000000; // 2440MHz + reusableBuffer.spectrumAnalyser.step = reusableBuffer.spectrumAnalyser.span / LCD_W; + moduleSettings[g_moduleIdx].mode = MODULE_MODE_SPECTRUM_ANALYSER; } uint8_t peak_y = 1; diff --git a/radio/src/gui/common/stdlcd/radio_tools.cpp b/radio/src/gui/common/stdlcd/radio_tools.cpp index 74b58ba050..d9f88aad75 100644 --- a/radio/src/gui/common/stdlcd/radio_tools.cpp +++ b/radio/src/gui/common/stdlcd/radio_tools.cpp @@ -20,6 +20,8 @@ #include "opentx.h" +extern uint8_t g_moduleIdx; + void pxx2ModuleRequiredScreen(event_t event) { lcdClear(); @@ -33,7 +35,7 @@ void pxx2ModuleRequiredScreen(event_t event) } } -void addRadioTool(uint8_t index, const char * label, void (* tool)(event_t event), event_t event) +void addRadioTool(uint8_t index, const char * label, void (* tool)(event_t event), uint8_t module, event_t event) { int8_t sub = menuVerticalPosition - HEADER_LINE; LcdFlags attr = (sub == index ? INVERS : 0); @@ -42,16 +44,65 @@ void addRadioTool(uint8_t index, const char * label, void (* tool)(event_t event lcdDrawText(3*FW, y, label, (sub == index ? INVERS : 0)); if (attr && s_editMode > 0) { s_editMode = 0; + g_moduleIdx = module; pushMenu(tool); } } +bool hasSpektrumAnalyserCapability(uint8_t module) +{ +#if defined(SIMU) + return true; +#else + return (reusableBuffer.hardwareAndSettings.modules[module].information.modelID == PXX2_MODULE_IXJT_S || + reusableBuffer.hardwareAndSettings.modules[module].information.modelID == PXX2_MODULE_IXJT_PRO || + reusableBuffer.hardwareAndSettings.modules[module].information.modelID >= PXX2_MODULE_R9M_LITE_PRO); +#endif +} + +bool hasPowerMeterCapablity(uint8_t module) +{ +#if defined(SIMU) + return true; +#else + return (reusableBuffer.hardwareAndSettings.modules[module].information.modelID == PXX2_MODULE_IXJT_PRO || + reusableBuffer.hardwareAndSettings.modules[module].information.modelID == PXX2_MODULE_R9M_LITE_PRO); +#endif +} + void menuRadioTools(event_t event) { - SIMPLE_MENU("TOOLS", menuTabGeneral, MENU_RADIO_TOOLS, HEADER_LINE + 2); + uint8_t spektrum_modules = 0, power_modules = 0; -#if defined(PXX2) && (defined(PCBXLITES) || defined(PCBX3)) - addRadioTool(0, "Spectrum Analyser", menuRadioSpectrumAnalyser, event); - addRadioTool(1, "Power Meter", menuRadioPowerMeter, event); -#endif + if(event == EVT_ENTRY || event == EVT_ENTRY_UP) { + memclear(&reusableBuffer.hardwareAndSettings, sizeof(reusableBuffer.hardwareAndSettings)); + for (uint8_t idx=0; idx < NUM_MODULES; idx++) { + if (isModulePXX2(idx) && (idx == INTERNAL_MODULE ? IS_INTERNAL_MODULE_ON() : IS_EXTERNAL_MODULE_ON())) { + reusableBuffer.hardwareAndSettings.modules[idx].current = PXX2_HW_INFO_TX_ID; + reusableBuffer.hardwareAndSettings.modules[idx].maximum = PXX2_HW_INFO_TX_ID; + moduleSettings[idx].mode = MODULE_MODE_GET_HARDWARE_INFO; + } + } + } + + for (uint8_t idx=0; idx < NUM_MODULES; idx++) { + if(hasSpektrumAnalyserCapability(idx)) { + spektrum_modules++; + } + if(hasPowerMeterCapablity(idx)) { + power_modules++; + } + } + + SIMPLE_MENU("TOOLS", menuTabGeneral, MENU_RADIO_TOOLS, HEADER_LINE + spektrum_modules + power_modules); + + uint8_t menu_index=0; + if(hasSpektrumAnalyserCapability(INTERNAL_MODULE)) + addRadioTool(menu_index++, "Spectrum (INT)", menuRadioSpectrumAnalyser, INTERNAL_MODULE, event); + if(hasPowerMeterCapablity(INTERNAL_MODULE)) + addRadioTool(menu_index++, "Power Meter (INT)", menuRadioPowerMeter, INTERNAL_MODULE, event); + if(hasSpektrumAnalyserCapability(EXTERNAL_MODULE)) + addRadioTool(menu_index++, "Spectrum (EXT)", menuRadioSpectrumAnalyser, EXTERNAL_MODULE, event); + if(hasPowerMeterCapablity(EXTERNAL_MODULE)) + addRadioTool(menu_index++, "Power Meter (EXT)", menuRadioPowerMeter, EXTERNAL_MODULE, event); } \ No newline at end of file diff --git a/radio/src/pulses/pxx2.cpp b/radio/src/pulses/pxx2.cpp index 978cfe29a9..cd2fe5c2bd 100644 --- a/radio/src/pulses/pxx2.cpp +++ b/radio/src/pulses/pxx2.cpp @@ -256,14 +256,8 @@ void Pxx2Pulses::setupSpectrumAnalyser(uint8_t module) addFrameType(PXX2_TYPE_C_POWER_METER, PXX2_TYPE_ID_SPECTRUM); Pxx2Transport::addByte(0x00); - - reusableBuffer.spectrumAnalyser.freq = 2440000000; // 2440MHz Pxx2Transport::addWord(reusableBuffer.spectrumAnalyser.freq); - - reusableBuffer.spectrumAnalyser.span = 40000000; // 40MHz Pxx2Transport::addWord(reusableBuffer.spectrumAnalyser.span); - - reusableBuffer.spectrumAnalyser.step = 100000; // 100KHz Pxx2Transport::addWord(reusableBuffer.spectrumAnalyser.step); }