1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-17 13:25:20 +03:00

Add external modules handling for power and spektrum

This commit is contained in:
3djc 2019-04-02 13:55:07 +02:00
parent c5793c93d5
commit 5fd70d7c8c
4 changed files with 74 additions and 28 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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);
}
}
void menuRadioTools(event_t event)
bool hasSpektrumAnalyserCapability(uint8_t module)
{
SIMPLE_MENU("TOOLS", menuTabGeneral, MENU_RADIO_TOOLS, HEADER_LINE + 2);
#if defined(PXX2) && (defined(PCBXLITES) || defined(PCBX3))
addRadioTool(0, "Spectrum Analyser", menuRadioSpectrumAnalyser, event);
addRadioTool(1, "Power Meter", menuRadioPowerMeter, event);
#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)
{
uint8_t spektrum_modules = 0, power_modules = 0;
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);
}

View file

@ -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);
}