mirror of
https://github.com/opentx/opentx.git
synced 2025-07-17 21:35:27 +03:00
Powermeter added
This commit is contained in:
parent
1539bdb909
commit
775ac40aaa
13 changed files with 143 additions and 44 deletions
|
@ -99,7 +99,8 @@ void menuRadioDiagKeys(event_t event);
|
|||
void menuRadioDiagAnalogs(event_t event);
|
||||
void menuRadioHardware(event_t event);
|
||||
void menuRadioTools(event_t event);
|
||||
void menuRadioSpectrum(event_t event);
|
||||
void menuRadioSpectrumAnalyser(event_t event);
|
||||
void menuRadioPowerMeter(event_t event);
|
||||
void menuRadioCalibration(event_t event);
|
||||
|
||||
static const MenuHandlerFunc menuTabGeneral[] = {
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
const MenuHandlerFunc menuTabGeneral[] = {
|
||||
menuRadioSetup,
|
||||
menuRadioSdManager,
|
||||
menuRadioTools,
|
||||
menuRadioSpecialFunctions,
|
||||
menuRadioTrainer,
|
||||
menuRadioVersion,
|
||||
|
|
|
@ -73,6 +73,7 @@ void menuTraceBuffer(event_t event);
|
|||
enum MenuRadioIndexes {
|
||||
MENU_RADIO_SETUP,
|
||||
MENU_RADIO_SD_MANAGER,
|
||||
MENU_RADIO_TOOLS,
|
||||
MENU_RADIO_SPECIAL_FUNCTIONS,
|
||||
MENU_RADIO_TRAINER,
|
||||
MENU_RADIO_VERSION,
|
||||
|
@ -88,7 +89,10 @@ void menuRadioVersion(event_t event);
|
|||
void menuRadioDiagKeys(event_t event);
|
||||
void menuRadioDiagAnalogs(event_t event);
|
||||
void menuRadioHardware(event_t event);
|
||||
void menuRadioTools(event_t event);
|
||||
void menuRadioCalibration(event_t event);
|
||||
void menuRadioSpectrumAnalyser(event_t event);
|
||||
void menuRadioPowerMeter(event_t event);
|
||||
|
||||
extern const MenuHandlerFunc menuTabGeneral[MENU_RADIO_PAGES_COUNT];
|
||||
|
||||
|
|
|
@ -28,5 +28,8 @@ if(SDCARD)
|
|||
set(GUI_SRC
|
||||
${GUI_SRC}
|
||||
../common/stdlcd/radio_sdmanager.cpp
|
||||
../common/stdlcd/radio_tools.cpp
|
||||
../common/stdlcd/radio_spectrum_analyser.cpp
|
||||
../common/stdlcd/radio_power_meter.cpp
|
||||
)
|
||||
endif()
|
||||
|
|
64
radio/src/gui/common/stdlcd/radio_power_meter.cpp
Normal file
64
radio/src/gui/common/stdlcd/radio_power_meter.cpp
Normal file
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <opentx.h>
|
||||
#include "opentx.h"
|
||||
|
||||
void menuRadioPowerMeter(event_t event)
|
||||
{
|
||||
SIMPLE_SUBMENU("POWER METER", 1);
|
||||
|
||||
if (menuEvent) {
|
||||
INTERNAL_MODULE_OFF();
|
||||
moduleSettings[INTERNAL_MODULE].mode = MODULE_MODE_NORMAL;
|
||||
/* wait 500ms off */
|
||||
watchdogSuspend(500);
|
||||
RTOS_WAIT_MS(500);
|
||||
INTERNAL_MODULE_ON();
|
||||
}
|
||||
else if (event == EVT_ENTRY) {
|
||||
memclear(&reusableBuffer.powerMeter, sizeof(reusableBuffer.powerMeter));
|
||||
reusableBuffer.powerMeter.freq = 2400;
|
||||
moduleSettings[INTERNAL_MODULE].mode = MODULE_MODE_POWER_METER;
|
||||
}
|
||||
|
||||
coord_t y = MENU_HEADER_HEIGHT + 1 + FH;
|
||||
LcdFlags attr = (menuVerticalPosition - HEADER_LINE == 0 ? INVERS : 0);
|
||||
lcdDrawText(0, y, "Freq.");
|
||||
lcdDrawNumber(8*FW, y, reusableBuffer.powerMeter.freq, LEFT|attr|(s_editMode > 0 ? BLINK : 0));
|
||||
lcdDrawText(lcdNextPos, y, "MHz");
|
||||
if (attr) {
|
||||
CHECK_INCDEC_MODELVAR(event, reusableBuffer.powerMeter.freq, 2300, 2500);
|
||||
if (checkIncDec_Ret) {
|
||||
reusableBuffer.powerMeter.power = 0;
|
||||
reusableBuffer.powerMeter.peak = 0;
|
||||
}
|
||||
}
|
||||
|
||||
y += FH + 1;
|
||||
lcdDrawText(0, y, "Power");
|
||||
lcdDrawNumber(8*FW, y, reusableBuffer.powerMeter.power, LEFT);
|
||||
lcdDrawText(lcdNextPos, y, "dBm");
|
||||
|
||||
y += FH + 1;
|
||||
lcdDrawText(0, y, "Peak");
|
||||
lcdDrawNumber(8*FW, y, reusableBuffer.powerMeter.peak, LEFT);
|
||||
lcdDrawText(lcdNextPos, y, "dBm");
|
||||
}
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
#include "opentx.h"
|
||||
|
||||
void menuRadioSpectrum(event_t event)
|
||||
void menuRadioSpectrumAnalyser(event_t event)
|
||||
{
|
||||
SIMPLE_SUBMENU("SPECTRUM ANALYSER", 1);
|
||||
|
||||
|
@ -33,14 +33,14 @@ void menuRadioSpectrum(event_t event)
|
|||
INTERNAL_MODULE_ON();
|
||||
}
|
||||
else if (event == EVT_ENTRY) {
|
||||
memclear(reusableBuffer.spectrum.bars, sizeof(reusableBuffer.spectrum.bars));
|
||||
memclear(reusableBuffer.spectrumAnalyser.bars, sizeof(reusableBuffer.spectrumAnalyser.bars));
|
||||
moduleSettings[INTERNAL_MODULE].mode = MODULE_MODE_SPECTRUM_ANALYSER;
|
||||
}
|
||||
|
||||
uint8_t peak_y = 1;
|
||||
uint8_t peak_x = 0;
|
||||
for (uint8_t i=0; i<LCD_W; i++) {
|
||||
uint8_t h = min<uint8_t >(reusableBuffer.spectrum.bars[i] >> 1, 128);
|
||||
uint8_t h = min<uint8_t >(reusableBuffer.spectrumAnalyser.bars[i] >> 1, 128);
|
||||
if (h > peak_y) {
|
||||
peak_x = i;
|
||||
peak_y = h;
|
||||
|
@ -49,14 +49,14 @@ void menuRadioSpectrum(event_t event)
|
|||
}
|
||||
|
||||
lcdDrawText(1, 10, "F:", 0);
|
||||
lcdDrawNumber(lcdLastRightPos + 2, 10, reusableBuffer.spectrum.fq/10000000,PREC2);
|
||||
lcdDrawNumber(lcdLastRightPos + 2, 10, reusableBuffer.spectrumAnalyser.freq / 10000000, PREC2);
|
||||
lcdDrawText(lcdLastRightPos + 2, 10, "GHz", 0);
|
||||
|
||||
lcdDrawText(lcdLastRightPos + 5, 10, "S:", 0);
|
||||
lcdDrawNumber(lcdLastRightPos + 2, 10, reusableBuffer.spectrum.span/1000000, 0);
|
||||
lcdDrawNumber(lcdLastRightPos + 2, 10, reusableBuffer.spectrumAnalyser.span/1000000, 0);
|
||||
lcdDrawText(lcdLastRightPos + 2, 10, "MHz", 0);
|
||||
|
||||
int8_t y = max<int8_t>(FH, LCD_H - peak_y - FH);
|
||||
lcdDrawNumber(min<uint8_t>(100, peak_x), y, ((reusableBuffer.spectrum.fq - reusableBuffer.spectrum.span / 2) + peak_x * (reusableBuffer.spectrum.span / 128)) / 1000000, TINSIZE);
|
||||
lcdDrawNumber(min<uint8_t>(100, peak_x), y, ((reusableBuffer.spectrumAnalyser.freq - reusableBuffer.spectrumAnalyser.span / 2) + peak_x * (reusableBuffer.spectrumAnalyser.span / 128)) / 1000000, TINSIZE);
|
||||
lcdDrawText(lcdLastRightPos, y, "M", TINSIZE);
|
||||
}
|
|
@ -35,8 +35,8 @@ void addRadioTool(uint8_t index, const char * label, void (* tool)(event_t event
|
|||
|
||||
void menuRadioTools(event_t event)
|
||||
{
|
||||
SIMPLE_MENU("TOOLS", menuTabGeneral, MENU_RADIO_TOOLS, HEADER_LINE + 1);
|
||||
|
||||
addRadioTool(0, "Spectrum Analyser", menuRadioSpectrum, event);
|
||||
SIMPLE_MENU("TOOLS", menuTabGeneral, MENU_RADIO_TOOLS, HEADER_LINE + 2);
|
||||
|
||||
addRadioTool(0, "Spectrum Analyser", menuRadioSpectrumAnalyser, event);
|
||||
addRadioTool(1, "Power Meter", menuRadioPowerMeter, event);
|
||||
}
|
|
@ -1200,11 +1200,18 @@ union ReusableBuffer
|
|||
|
||||
struct
|
||||
{
|
||||
uint8_t bars[128];
|
||||
uint32_t fq;
|
||||
uint8_t bars[LCD_W];
|
||||
uint32_t freq;
|
||||
uint32_t span;
|
||||
uint32_t step;
|
||||
} spectrum;
|
||||
} spectrumAnalyser;
|
||||
|
||||
struct
|
||||
{
|
||||
uint32_t freq;
|
||||
uint32_t power;
|
||||
uint32_t peak;
|
||||
} powerMeter;
|
||||
|
||||
struct
|
||||
{
|
||||
|
|
|
@ -38,12 +38,6 @@
|
|||
extern uint8_t dsm2BindTimer;
|
||||
#endif
|
||||
|
||||
#if defined(PXX)
|
||||
#define IS_PXX_PROTOCOL(protocol) (protocol==PROTO_PXX)
|
||||
#else
|
||||
#define IS_PXX_PROTOCOL(protocol) (0)
|
||||
#endif
|
||||
|
||||
#if defined(DSM2)
|
||||
#define IS_DSM2_PROTOCOL(protocol) (protocol>=PROTOCOL_CHANNELS_DSM2_LP45 && protocol<=PROTOCOL_CHANNELS_DSM2_DSMX)
|
||||
#else
|
||||
|
@ -73,6 +67,7 @@ enum ModuleSettingsMode
|
|||
{
|
||||
MODULE_MODE_NORMAL,
|
||||
MODULE_MODE_SPECTRUM_ANALYSER,
|
||||
MODULE_MODE_POWER_METER,
|
||||
MODULE_MODE_GET_HARDWARE_INFO,
|
||||
MODULE_MODE_RECEIVER_SETTINGS,
|
||||
MODULE_MODE_BEEP_FIRST,
|
||||
|
@ -84,8 +79,9 @@ enum ModuleSettingsMode
|
|||
|
||||
PACK(struct ModuleSettings {
|
||||
uint8_t protocol:4;
|
||||
uint8_t mode:4;
|
||||
uint8_t paused:1;
|
||||
uint8_t mode:3;
|
||||
uint8_t spare:7;
|
||||
uint16_t counter;
|
||||
});
|
||||
|
||||
|
|
|
@ -212,14 +212,30 @@ void Pxx2Pulses::setupSpectrumAnalyser(uint8_t module)
|
|||
addFrameType(PXX2_TYPE_C_POWER_METER, PXX2_TYPE_ID_SPECTRUM);
|
||||
Pxx2Transport::addByte(0x00);
|
||||
|
||||
reusableBuffer.spectrum.fq = 2440000000; // 2440MHz
|
||||
Pxx2Transport::addWord(reusableBuffer.spectrum.fq);
|
||||
reusableBuffer.spectrumAnalyser.freq = 2440000000; // 2440MHz
|
||||
Pxx2Transport::addWord(reusableBuffer.spectrumAnalyser.freq);
|
||||
|
||||
reusableBuffer.spectrum.span = 40000000; // 40MHz
|
||||
Pxx2Transport::addWord(reusableBuffer.spectrum.span);
|
||||
reusableBuffer.spectrumAnalyser.span = 40000000; // 40MHz
|
||||
Pxx2Transport::addWord(reusableBuffer.spectrumAnalyser.span);
|
||||
|
||||
reusableBuffer.spectrum.step = 100000; // 100KHz
|
||||
Pxx2Transport::addWord(reusableBuffer.spectrum.step);
|
||||
reusableBuffer.spectrumAnalyser.step = 100000; // 100KHz
|
||||
Pxx2Transport::addWord(reusableBuffer.spectrumAnalyser.step);
|
||||
}
|
||||
|
||||
|
||||
void Pxx2Pulses::setupPowerMeter(uint8_t module)
|
||||
{
|
||||
if (moduleSettings[module].counter > 1000) {
|
||||
moduleSettings[module].counter = 1002;
|
||||
return;
|
||||
}
|
||||
|
||||
moduleSettings[module].counter = 1002;
|
||||
|
||||
addFrameType(PXX2_TYPE_C_POWER_METER, PXX2_TYPE_ID_POWER_METER);
|
||||
Pxx2Transport::addByte(0x00);
|
||||
|
||||
Pxx2Transport::addWord(reusableBuffer.powerMeter.freq);
|
||||
}
|
||||
|
||||
void Pxx2Pulses::setupShareMode(uint8_t module)
|
||||
|
@ -248,6 +264,9 @@ void Pxx2Pulses::setupFrame(uint8_t module)
|
|||
case MODULE_MODE_SPECTRUM_ANALYSER:
|
||||
setupSpectrumAnalyser(module);
|
||||
break;
|
||||
case MODULE_MODE_POWER_METER:
|
||||
setupPowerMeter(module);
|
||||
break;
|
||||
case MODULE_MODE_SHARE:
|
||||
setupShareMode(module);
|
||||
break;
|
||||
|
|
|
@ -129,6 +129,8 @@ class Pxx2Pulses: public PxxPulses<Pxx2Transport> {
|
|||
|
||||
void setupSpectrumAnalyser(uint8_t module);
|
||||
|
||||
void setupPowerMeter(uint8_t module);
|
||||
|
||||
void addHead()
|
||||
{
|
||||
// send 7E, do not CRC
|
||||
|
|
|
@ -140,7 +140,6 @@ elseif(PCB STREQUAL XLITES)
|
|||
set(FONTS_TARGET 9x_fonts_1bit)
|
||||
set(LCD_DRIVER lcd_driver_spi.cpp)
|
||||
set(GVAR_SCREEN model_gvars.cpp)
|
||||
set(RADIO_SPECTRUM YES)
|
||||
set(STATUS_LEDS YES)
|
||||
endif()
|
||||
|
||||
|
@ -211,7 +210,6 @@ set(GUI_SRC
|
|||
radio_diagkeys.cpp
|
||||
radio_diaganas.cpp
|
||||
radio_hardware.cpp
|
||||
radio_tools.cpp
|
||||
view_channels.cpp
|
||||
view_telemetry.cpp
|
||||
view_about.cpp
|
||||
|
@ -219,14 +217,6 @@ set(GUI_SRC
|
|||
../screenshot.cpp
|
||||
)
|
||||
|
||||
if(RADIO_SPECTRUM)
|
||||
add_definitions(-DRADIO_SPECTRUM)
|
||||
set(GUI_SRC
|
||||
${GUI_SRC}
|
||||
radio_spectrum.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
if(STATUS_LEDS)
|
||||
set(LED_DRIVER led_driver.cpp)
|
||||
endif()
|
||||
|
|
|
@ -151,7 +151,7 @@ void processTelemetryFrame(uint8_t module, uint8_t * frame)
|
|||
sportProcessTelemetryPacketWithoutCrc(&frame[3]);
|
||||
}
|
||||
|
||||
void processSpectrumFrame(uint8_t module, uint8_t * frame)
|
||||
void processSpectrumAnalyserFrame(uint8_t module, uint8_t * frame)
|
||||
{
|
||||
if (moduleSettings[module].mode != MODULE_MODE_SPECTRUM_ANALYSER) {
|
||||
return;
|
||||
|
@ -170,10 +170,22 @@ void processSpectrumFrame(uint8_t module, uint8_t * frame)
|
|||
// TRACE("Fq=%u, Pw=%d, X=%d, Y=%d", *frequency, int32_t(*power), D * 128 / 40000000, int32_t(127 + *power));
|
||||
uint8_t x = D * 128 / 40000000;
|
||||
|
||||
reusableBuffer.spectrum.bars[x] = 127 + *power;
|
||||
reusableBuffer.spectrumAnalyser.bars[x] = 127 + *power;
|
||||
}
|
||||
|
||||
void processRadioFrame(uint8_t module, uint8_t * frame)
|
||||
void processPowerMeterFrame(uint8_t module, uint8_t * frame)
|
||||
{
|
||||
if (moduleSettings[module].mode != MODULE_MODE_POWER_METER) {
|
||||
return;
|
||||
}
|
||||
|
||||
reusableBuffer.powerMeter.power = *((uint16_t *)&frame[8]);
|
||||
if (reusableBuffer.powerMeter.power > reusableBuffer.powerMeter.peak) {
|
||||
reusableBuffer.powerMeter.peak = reusableBuffer.powerMeter.power;
|
||||
}
|
||||
}
|
||||
|
||||
void processModuleFrame(uint8_t module, uint8_t *frame)
|
||||
{
|
||||
switch (frame[2]) {
|
||||
case PXX2_TYPE_ID_HW_INFO:
|
||||
|
@ -198,15 +210,15 @@ void processRadioFrame(uint8_t module, uint8_t * frame)
|
|||
}
|
||||
}
|
||||
|
||||
void processPowerMeterFrame(uint8_t module, uint8_t * frame)
|
||||
void processToolsFrame(uint8_t module, uint8_t * frame)
|
||||
{
|
||||
switch (frame[2]) {
|
||||
case PXX2_TYPE_ID_POWER_METER:
|
||||
// TODO
|
||||
processPowerMeterFrame(module, frame);
|
||||
break;
|
||||
|
||||
case PXX2_TYPE_ID_SPECTRUM:
|
||||
processSpectrumFrame(module, frame);
|
||||
processSpectrumAnalyserFrame(module, frame);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -215,11 +227,11 @@ void processPXX2TelemetryFrame(uint8_t module, uint8_t * frame)
|
|||
{
|
||||
switch (frame[1]) {
|
||||
case PXX2_TYPE_C_MODULE:
|
||||
processRadioFrame(module, frame);
|
||||
processModuleFrame(module, frame);
|
||||
break;
|
||||
|
||||
case PXX2_TYPE_C_POWER_METER:
|
||||
processPowerMeterFrame(module, frame);
|
||||
processToolsFrame(module, frame);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue