Skip to content

Commit

Permalink
feat(X10/X12S) Int/Ext Antenna UI (#1765)
Browse files Browse the repository at this point in the history
* feature(colorlcd): antenna selection

* fix: let's assume all internal XJT modules used in horus targets are either X10 or X12S type

* fix NV14 compilation

Co-authored-by: Raphael Coeffic <[email protected]>
  • Loading branch information
pfeerick and raphaelcoeffic authored Oct 11, 2022
1 parent 324c8e9 commit e90cd0f
Show file tree
Hide file tree
Showing 11 changed files with 271 additions and 76 deletions.
4 changes: 4 additions & 0 deletions radio/src/gui/colorlcd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ if(MULTIMODULE)
add_gui_src(mpm_settings.cpp)
endif()

if(INTERNAL_MODULE_PXX1)
add_gui_src(pxx1_settings.cpp)
endif()

if(PXX2)
add_gui_src(access_settings.cpp)
endif()
Expand Down
48 changes: 46 additions & 2 deletions radio/src/gui/colorlcd/hw_intmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,44 @@ InternalModuleWindow::InternalModuleWindow(Window *parent) :
internalModule->setAvailableHandler(
[](int module) { return isInternalModuleSupported(module); });

#if defined(CROSSFIRE)
#if defined(INTERNAL_MODULE_PXX1) && defined(EXTERNAL_ANTENNA)
box = new FormGroup(box, rect_t{});
box->setFlexLayout(LV_FLEX_FLOW_ROW, lv_dpx(8));

ant_box = box->getLvObj();
lv_obj_set_width(ant_box, LV_SIZE_CONTENT);
lv_obj_set_style_flex_cross_place(ant_box, LV_FLEX_ALIGN_CENTER, 0);

new StaticText(box, rect_t{}, STR_ANTENNA, 0, COLOR_THEME_PRIMARY1);
new Choice(
box, rect_t{}, STR_ANTENNA_MODES, ANTENNA_MODE_INTERNAL,
ANTENNA_MODE_EXTERNAL, GET_DEFAULT(g_eeGeneral.antennaMode),
[](int antenna) {
if (!isExternalAntennaEnabled() &&
(antenna == ANTENNA_MODE_EXTERNAL ||
(antenna == ANTENNA_MODE_PER_MODEL &&
g_model.moduleData[INTERNAL_MODULE].pxx.antennaMode ==
ANTENNA_MODE_EXTERNAL))) {
if (confirmationDialog(STR_ANTENNACONFIRM1, STR_ANTENNACONFIRM2)) {
g_eeGeneral.antennaMode = antenna;
SET_DIRTY();
}
} else {
g_eeGeneral.antennaMode = antenna;
checkExternalAntenna();
SET_DIRTY();
}
});

updateAntennaLine();
#endif

#if defined(CROSSFIRE)
box = new FormGroup(box, rect_t{});
box->setFlexLayout(LV_FLEX_FLOW_ROW);

br_box = box->getLvObj();
lv_obj_set_width(br_box, LV_SIZE_CONTENT);
lv_obj_set_width(br_box, LV_SIZE_CONTENT);
lv_obj_set_style_flex_cross_place(br_box, LV_FLEX_ALIGN_CENTER, 0);

new StaticText(box, rect_t{}, STR_BAUDRATE, 0, COLOR_THEME_PRIMARY1);
Expand All @@ -78,6 +110,7 @@ void InternalModuleWindow::setModuleType(int moduleType)
}
g_eeGeneral.internalModule = moduleType;
updateBaudrateLine();
updateAntennaLine();
SET_DIRTY();
}

Expand Down Expand Up @@ -105,3 +138,14 @@ void InternalModuleWindow::updateBaudrateLine()
}
#endif
}

void InternalModuleWindow::updateAntennaLine()
{
#if defined(INTERNAL_MODULE_PXX1) && defined(EXTERNAL_ANTENNA)
if (isInternalModuleAvailable(MODULE_TYPE_XJT_PXX1)) {
lv_obj_clear_flag(ant_box, LV_OBJ_FLAG_HIDDEN);
} else {
lv_obj_add_flag(ant_box, LV_OBJ_FLAG_HIDDEN);
}
#endif
}
2 changes: 2 additions & 0 deletions radio/src/gui/colorlcd/hw_intmodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class InternalModuleWindow : public FormGroup::Line
protected:
uint8_t lastModule = 0;
lv_obj_t* br_box = nullptr;
lv_obj_t* ant_box = nullptr;

#if defined(CROSSFIRE)
static int getBaudrate();
Expand All @@ -39,4 +40,5 @@ class InternalModuleWindow : public FormGroup::Line

void setModuleType(int moduleType);
void updateBaudrateLine();
void updateAntennaLine();
};
21 changes: 10 additions & 11 deletions radio/src/gui/colorlcd/module_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
#include "channel_range.h"
#include "storage/modelslist.h"

#if defined(INTERNAL_MODULE_PXX1) && defined(EXTERNAL_ANTENNA)
#include "pxx1_settings.h"
#endif

#if defined(PXX2)
#include "access_settings.h"
#endif
Expand Down Expand Up @@ -219,6 +223,12 @@ void ModuleWindow::updateModule()
modOpts = new MultimoduleSettings(this, grid, moduleIdx);
}
#endif
#if defined(INTERNAL_MODULE_PXX1) && defined(EXTERNAL_ANTENNA)
else if (moduleIdx == INTERNAL_MODULE && isModuleXJT(moduleIdx) &&
g_eeGeneral.antennaMode == ANTENNA_MODE_PER_MODEL) {
modOpts = new PXX1AntennaSettings(this, grid, moduleIdx);
}
#endif

// Channel Range
auto line = newLine(&grid);
Expand Down Expand Up @@ -533,17 +543,6 @@ void ModuleWindow::startRSSIDialog(std::function<void()> closeHandler)
});
}

// void ModuleWindow::checkEvents()
// {
// if (isModuleFailsafeAvailable(moduleIdx) != hasFailsafe && rfChoice &&
// !rfChoice->isEditMode()) {
// hasFailsafe = isModuleFailsafeAvailable(moduleIdx);
// update();
// }

// FormGroup::checkEvents();
// }

class ModuleSubTypeChoice: public Choice
{
uint8_t moduleIdx;
Expand Down
63 changes: 63 additions & 0 deletions radio/src/gui/colorlcd/pxx1_settings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* 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 "pxx1_settings.h"
#include "choice.h"

#include "opentx.h"

#define SET_DIRTY() storageDirty(EE_MODEL)

PXX1AntennaSettings::PXX1AntennaSettings(Window* parent,
const FlexGridLayout& g,
uint8_t moduleIdx) :
FormGroup(parent, rect_t{}), md(&g_model.moduleData[moduleIdx])
{
FlexGridLayout grid(g);
setFlexLayout();

auto line = newLine(&grid);
new StaticText(line, rect_t{}, STR_ANTENNA, 0, COLOR_THEME_PRIMARY1);

if (md->pxx.antennaMode == ANTENNA_MODE_PER_MODEL) {
md->pxx.antennaMode = ANTENNA_MODE_INTERNAL;
SET_DIRTY();
}

auto antennaChoice = new Choice(
line, rect_t{}, STR_ANTENNA_MODES, ANTENNA_MODE_INTERNAL,
ANTENNA_MODE_EXTERNAL, GET_DEFAULT(md->pxx.antennaMode),
[=](int32_t antenna) -> void {
if (!isExternalAntennaEnabled() && (antenna == ANTENNA_MODE_EXTERNAL)) {
if (confirmationDialog(STR_ANTENNACONFIRM1, STR_ANTENNACONFIRM2)) {
md->pxx.antennaMode = antenna;
SET_DIRTY();
}
} else {
md->pxx.antennaMode = antenna;
SET_DIRTY();
checkExternalAntenna();
}
});

antennaChoice->setAvailableHandler(
[=](int8_t mode) { return mode != ANTENNA_MODE_PER_MODEL; });
}
37 changes: 37 additions & 0 deletions radio/src/gui/colorlcd/pxx1_settings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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 "form.h"
#include "module_setup.h"

struct ModuleData;

class PXX1AntennaSettings : public FormGroup, public ModuleOptions
{
ModuleData* md;

void update() override {}

public:
PXX1AntennaSettings(Window* parent, const FlexGridLayout& g, uint8_t moduleIdx);
};
98 changes: 98 additions & 0 deletions radio/src/gui/gui_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,104 @@ bool isSourceAvailableInResetSpecialFunction(int index)
}
}

#if defined(EXTERNAL_ANTENNA) && defined(INTERNAL_MODULE_PXX1)

#if defined(COLORLCD)

class AntennaSelectionMenu : public Menu
{
bool& done;

public:
AntennaSelectionMenu(bool& done) : Menu(MainWindow::instance()), done(done) {
setTitle(STR_ANTENNA);
addLine(STR_USE_INTERNAL_ANTENNA,
[] { globalData.externalAntennaEnabled = false; });
addLine(STR_USE_EXTERNAL_ANTENNA,
[] { globalData.externalAntennaEnabled = true; });
setCloseHandler([=]() { this->done = true; });
setCloseWhenClickOutside(false);
}
protected:
void onCancel() override {}
};

static void runAntennaSelectionMenu()
{
bool finished = false;
new AntennaSelectionMenu(finished);

while (!finished) {
WDG_RESET();
MainWindow::instance()->run();
LvglWrapper::runNested();
RTOS_WAIT_MS(20);
}
}
#else
void onAntennaSelection(const char* result)
{
if (result == STR_USE_INTERNAL_ANTENNA) {
globalData.externalAntennaEnabled = false;
} else if (result == STR_USE_EXTERNAL_ANTENNA) {
globalData.externalAntennaEnabled = true;
} else {
checkExternalAntenna();
}
}

void onAntennaSwitchConfirm(const char * result)
{
if (result == STR_OK) {
// Switch to external antenna confirmation
globalData.externalAntennaEnabled = true;
}
}
#endif

void checkExternalAntenna()
{
if (isModuleXJT(INTERNAL_MODULE)) {
if (g_eeGeneral.antennaMode == ANTENNA_MODE_EXTERNAL) {
// TRACE("checkExternalAntenna(): External");
globalData.externalAntennaEnabled = true;
} else if (g_eeGeneral.antennaMode == ANTENNA_MODE_PER_MODEL &&
g_model.moduleData[INTERNAL_MODULE].pxx.antennaMode ==
ANTENNA_MODE_EXTERNAL) {
// TRACE("checkExternalAntenna(): Per Model, External");
if (!globalData.externalAntennaEnabled) {
#if defined(COLORLCD)
if (confirmationDialog(STR_ANTENNACONFIRM1, STR_ANTENNACONFIRM2)) {
globalData.externalAntennaEnabled = true;
}
#else
POPUP_CONFIRMATION(STR_ANTENNACONFIRM1, onAntennaSwitchConfirm);
SET_WARNING_INFO(STR_ANTENNACONFIRM2, sizeof(TR_ANTENNACONFIRM2), 0);
#endif
}
} else if (g_eeGeneral.antennaMode == ANTENNA_MODE_ASK ||
(g_eeGeneral.antennaMode == ANTENNA_MODE_PER_MODEL &&
g_model.moduleData[INTERNAL_MODULE].pxx.antennaMode ==
ANTENNA_MODE_ASK)) {

// TRACE("checkExternalAntenna(): Ask");
globalData.externalAntennaEnabled = false;

#if defined(COLORLCD)
runAntennaSelectionMenu();
#else
POPUP_MENU_ADD_ITEM(STR_USE_INTERNAL_ANTENNA);
POPUP_MENU_ADD_ITEM(STR_USE_EXTERNAL_ANTENNA);
POPUP_MENU_START(onAntennaSelection);
#endif
} else {
globalData.externalAntennaEnabled = false;
}
} else {
globalData.externalAntennaEnabled = false;
}
}
#endif

#if defined(PXX2)
bool isPxx2IsrmChannelsCountAllowed(int channels)
Expand Down
6 changes: 6 additions & 0 deletions radio/src/gui/gui_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ inline uint8_t MODULE_CHANNELS_ROWS(int moduleIdx)
}
}

#if defined(EXTERNAL_ANTENNA) && defined(INTERNAL_MODULE_PXX1)
void onAntennaSwitchConfirm(const char * result);
void checkExternalAntenna();
void onAntennaSelection(const char* result);
#endif

#if defined(PXX2)
inline bool isRacingModeAllowed()
{
Expand Down
2 changes: 1 addition & 1 deletion radio/src/pulses/modules_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ enum R9MLBTPowerValues {
};

enum AntennaTypes {
XJT_INTERNAL_ANTENNA,
XJT_INTERNAL_ANTENNA = 0,
XJT_EXTERNAL_ANTENNA
};

Expand Down
Loading

0 comments on commit e90cd0f

Please sign in to comment.