feat(color): GPS QR code locator tool (#6431)
This commit is contained in:
@@ -97,6 +97,7 @@ set(GUI_SRC
|
||||
radio/radio_tools.cpp
|
||||
radio/radio_trainer.cpp
|
||||
radio/radio_version.cpp
|
||||
radio/radio_gps_tool.cpp
|
||||
)
|
||||
|
||||
macro(add_gui_src src)
|
||||
|
||||
@@ -371,7 +371,13 @@ QRCode::QRCode(Window *parent, coord_t x, coord_t y, coord_t sz, std::string dat
|
||||
LcdFlags color, LcdFlags bgColor) :
|
||||
Window(parent, {x, y, sz, sz})
|
||||
{
|
||||
auto qr = lv_qrcode_create(lvobj, sz, makeLvColor(color), makeLvColor(bgColor));
|
||||
lv_qrcode_update(qr, data.c_str(), data.length());
|
||||
qr = lv_qrcode_create(lvobj, sz, makeLvColor(color), makeLvColor(bgColor));
|
||||
lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_CLICKABLE);
|
||||
setData(data);
|
||||
}
|
||||
|
||||
void QRCode::setData(std::string data)
|
||||
{
|
||||
if (qr)
|
||||
lv_qrcode_update(qr, data.c_str(), data.length());
|
||||
}
|
||||
|
||||
@@ -216,5 +216,8 @@ class QRCode : public Window
|
||||
std::string getName() const override { return "QRCode"; }
|
||||
#endif
|
||||
|
||||
void setData(std::string data);
|
||||
|
||||
protected:
|
||||
lv_obj_t* qr = nullptr;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* 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 "radio_gps_tool.h"
|
||||
|
||||
#include "edgetx.h"
|
||||
|
||||
RadioGpsTool::RadioGpsTool() :
|
||||
Page(ICON_RADIO_TOOLS)
|
||||
{
|
||||
init();
|
||||
buildHeader(header);
|
||||
buildBody(body);
|
||||
}
|
||||
|
||||
void RadioGpsTool::buildHeader(Window* window)
|
||||
{
|
||||
header->setTitle(STR_MENUTOOLS);
|
||||
header->setTitle2(STR_GPS_MODEL_LOCATOR);
|
||||
}
|
||||
|
||||
void RadioGpsTool::buildBody(Window* window)
|
||||
{
|
||||
window->padAll(PAD_ZERO);
|
||||
gpsLabel = new StaticText(window, {PAD_LARGE, PAD_LARGE, LV_SIZE_CONTENT, 0}, "", COLOR_THEME_PRIMARY1_INDEX, FONT(L));
|
||||
gpsQR = new QRCode(window, (window->width() - QR_SZ) / 2, (window->height() - QR_SZ) / 2, QR_SZ, "");
|
||||
new TextButton(window,
|
||||
{window->width() - BTN_SZ - PAD_LARGE * 2, window->height() - EdgeTxStyles::UI_ELEMENT_HEIGHT - PAD_LARGE * 2, BTN_SZ, 0},
|
||||
STR_REFRESH, [=]() {
|
||||
refresh();
|
||||
return 0;
|
||||
});
|
||||
refresh();
|
||||
}
|
||||
|
||||
void RadioGpsTool::init()
|
||||
{
|
||||
gpsSensorID = -1;
|
||||
for (int i = 0; i < MAX_TELEMETRY_SENSORS; i++) {
|
||||
if (isGPSSensor(i+1)) {
|
||||
gpsSensorID = i;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RadioGpsTool::refresh()
|
||||
{
|
||||
if (gpsSensorID >= 0) {
|
||||
static TelemetryItem& gpsItem = telemetryItems[gpsSensorID];
|
||||
char gps_uri[64];
|
||||
snprintf(gps_uri, sizeof(gps_uri), "geo:%f,%f", (float)gpsItem.gps.latitude / 1000000, (float)gpsItem.gps.longitude / 1000000);
|
||||
gpsQR->setData(gps_uri);
|
||||
gpsQR->show();
|
||||
gpsLabel->setText(getGPSSensorValue(gpsItem, 0));
|
||||
} else {
|
||||
gpsQR->hide();
|
||||
gpsLabel->setText(STR_NODATA);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "page.h"
|
||||
|
||||
class RadioGpsTool: public Page
|
||||
{
|
||||
public:
|
||||
explicit RadioGpsTool();
|
||||
|
||||
protected:
|
||||
int8_t gpsSensorID;
|
||||
StaticText* gpsLabel = nullptr;
|
||||
QRCode* gpsQR = nullptr;
|
||||
|
||||
static LAYOUT_VAL_SCALED(QR_SZ, 150)
|
||||
static LAYOUT_VAL_SCALED(BTN_SZ, 80)
|
||||
|
||||
void buildHeader(Window * window);
|
||||
void buildBody(Window * window);
|
||||
void init();
|
||||
void refresh();
|
||||
};
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "edgetx.h"
|
||||
#include "radio_ghost_module_config.h"
|
||||
#include "radio_spectrum_analyser.h"
|
||||
#include "radio_gps_tool.h"
|
||||
#include "standalone_lua.h"
|
||||
#include "etx_lv_theme.h"
|
||||
|
||||
@@ -140,6 +141,19 @@ static void scanLuaTools(std::list<ToolEntry>& scripts)
|
||||
}
|
||||
#endif
|
||||
|
||||
static bool isModelGPSSensorPresent()
|
||||
{
|
||||
for (int i = 0; i < MAX_TELEMETRY_SENSORS; i++) {
|
||||
if (isGPSSensor(i+1)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void run_gpstool(Window* parent, const std::string&)
|
||||
{
|
||||
new RadioGpsTool();
|
||||
}
|
||||
|
||||
#if defined(PXX2) || defined(MULTIMODULE)
|
||||
|
||||
#if defined(HARDWARE_INTERNAL_MODULE)
|
||||
@@ -242,19 +256,22 @@ void RadioToolsPage::rebuild(Window* window)
|
||||
}
|
||||
#endif
|
||||
|
||||
if (isModelGPSSensorPresent())
|
||||
tools.emplace_back(ToolEntry{STR_GPS_MODEL_LOCATOR, "", run_gpstool});
|
||||
|
||||
#if defined(HARDWARE_INTERNAL_MODULE)
|
||||
if (intSpecAnalyser)
|
||||
tools.emplace_back(ToolEntry{STR_SPECTRUM_ANALYSER_INT, {}, run_spektrum_int});
|
||||
tools.emplace_back(ToolEntry{STR_SPECTRUM_ANALYSER_INT, "", run_spektrum_int});
|
||||
#endif
|
||||
|
||||
#if defined(HARDWARE_EXTERNAL_MODULE)
|
||||
if (extSpecAnalyser)
|
||||
tools.emplace_back(ToolEntry{STR_SPECTRUM_ANALYSER_EXT, {}, run_spektrum_ext});
|
||||
tools.emplace_back(ToolEntry{STR_SPECTRUM_ANALYSER_EXT, "", run_spektrum_ext});
|
||||
#endif
|
||||
|
||||
#if defined(GHOST)
|
||||
if (isModuleGhost(EXTERNAL_MODULE)) {
|
||||
tools.emplace_back(ToolEntry{"Ghost module config", {}, run_ghost_config});
|
||||
tools.emplace_back(ToolEntry{STR_GHOST_MODULE_CONFIG, "", run_ghost_config});
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user