Powermeter added

This commit is contained in:
Bertrand Songis
2019-03-20 08:46:47 +01:00
parent 1539bdb909
commit 775ac40aaa
13 changed files with 143 additions and 44 deletions
@@ -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()
@@ -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");
}
@@ -0,0 +1,62 @@
/*
* 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"
void menuRadioSpectrumAnalyser(event_t event)
{
SIMPLE_SUBMENU("SPECTRUM ANALYSER", 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.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.spectrumAnalyser.bars[i] >> 1, 128);
if (h > peak_y) {
peak_x = i;
peak_y = h;
}
lcdDrawSolidVerticalLine(i, LCD_H - h, h);
}
lcdDrawText(1, 10, "F:", 0);
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.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.spectrumAnalyser.freq - reusableBuffer.spectrumAnalyser.span / 2) + peak_x * (reusableBuffer.spectrumAnalyser.span / 128)) / 1000000, TINSIZE);
lcdDrawText(lcdLastRightPos, y, "M", TINSIZE);
}
@@ -0,0 +1,42 @@
/*
* 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"
void addRadioTool(uint8_t index, const char * label, void (* tool)(event_t event), event_t event)
{
int8_t sub = menuVerticalPosition - HEADER_LINE;
LcdFlags attr = (sub == index ? INVERS : 0);
coord_t y = MENU_HEADER_HEIGHT + 1 + index * FH;
lcdDrawNumber(3, y, index + 1, LEADING0|LEFT, 2);
lcdDrawText(3*FW, y, label, (sub == index ? INVERS : 0));
if (attr && s_editMode > 0) {
s_editMode = 0;
pushMenu(tool);
}
}
void menuRadioTools(event_t event)
{
SIMPLE_MENU("TOOLS", menuTabGeneral, MENU_RADIO_TOOLS, HEADER_LINE + 2);
addRadioTool(0, "Spectrum Analyser", menuRadioSpectrumAnalyser, event);
addRadioTool(1, "Power Meter", menuRadioPowerMeter, event);
}