Skip to content

Commit

Permalink
feat(el18): Use trim hats as keys for navigation (#3894)
Browse files Browse the repository at this point in the history
Co-authored-by: elecpower <[email protected]>
Co-authored-by: Peter Feerick <[email protected]>
  • Loading branch information
3 people authored Sep 29, 2023
1 parent b733ec4 commit f40fa1a
Show file tree
Hide file tree
Showing 81 changed files with 1,021 additions and 91 deletions.
8 changes: 8 additions & 0 deletions companion/src/firmwares/edgetx/yaml_generalsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ const YamlLookupTable internalModuleLut = {
{ MODULE_TYPE_LEMON_DSMP, "TYPE_LEMON_DSMP" },
};

static const YamlLookupTable hatsModeLut = {
{ GeneralSettings::HATSMODE_TRIMS_ONLY, "TRIMS_ONLY" },
{ GeneralSettings::HATSMODE_KEYS_ONLY, "KEYS_ONLY" },
{ GeneralSettings::HATSMODE_SWITCHABLE, "SWITCHABLE" },
};

YamlTelemetryBaudrate::YamlTelemetryBaudrate(
const unsigned int* moduleBaudrate)
{
Expand Down Expand Up @@ -181,6 +187,7 @@ Node convert<GeneralSettings>::encode(const GeneralSettings& rhs)
node["disableAlarmWarning"] = (int)rhs.disableAlarmWarning;
node["disableRssiPoweroffAlarm"] = (int)rhs.disableRssiPoweroffAlarm;
node["USBMode"] = rhs.usbMode;
node["hatsMode"] = hatsModeLut << rhs.hatsMode;
node["stickDeadZone"] = rhs.stickDeadZone;
node["jackMode"] = rhs.jackMode;
node["hapticMode"] = rhs.hapticMode;
Expand Down Expand Up @@ -431,6 +438,7 @@ bool convert<GeneralSettings>::decode(const Node& node, GeneralSettings& rhs)
node["disableAlarmWarning"] >> rhs.disableAlarmWarning;
node["disableRssiPoweroffAlarm"] >> rhs.disableRssiPoweroffAlarm;
node["USBMode"] >> rhs.usbMode;
node["hatsMode"] >> hatsModeLut >> rhs.hatsMode;
node["stickDeadZone"] >> rhs.stickDeadZone;
node["jackMode"] >> rhs.jackMode;
node["hapticMode"] >> rhs.hapticMode;
Expand Down
9 changes: 9 additions & 0 deletions companion/src/firmwares/edgetx/yaml_modeldata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ static const YamlLookupTable usbJoystickIfModeLut = {
{ 2, "MULTIAXIS" },
};

static const YamlLookupTable hatsModeLut = {
{ GeneralSettings::HATSMODE_TRIMS_ONLY, "TRIMS_ONLY" },
{ GeneralSettings::HATSMODE_KEYS_ONLY, "KEYS_ONLY" },
{ GeneralSettings::HATSMODE_SWITCHABLE, "SWITCHABLE" },
{ GeneralSettings::HATSMODE_GLOBAL, "GLOBAL" },
};

struct YamlTrim {
int mode = 0;
int ref = 0;
Expand Down Expand Up @@ -1104,6 +1111,7 @@ Node convert<ModelData>::encode(const ModelData& rhs)
}

node["modelRegistrationID"] = rhs.registrationId;
node["hatsMode"] = hatsModeLut << rhs.hatsMode;

if (Boards::getCapability(board, Board::FunctionSwitches)) {
node["functionSwitchConfig"] = rhs.functionSwitchConfig;
Expand Down Expand Up @@ -1342,6 +1350,7 @@ bool convert<ModelData>::decode(const Node& node, ModelData& rhs)

node["view"] >> rhs.view;
node["modelRegistrationID"] >> rhs.registrationId;
node["hatsMode"] >> hatsModeLut >> rhs.hatsMode;

node["functionSwitchConfig"] >> rhs.functionSwitchConfig;
node["functionSwitchGroup"] >> rhs.functionSwitchGroup;
Expand Down
38 changes: 38 additions & 0 deletions companion/src/firmwares/generalsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ void GeneralSettings::init()
backlightDelay = 2; // 2 * 5 = 10 secs
inactivityTimer = 10;

hatsMode = HATSMODE_SWITCHABLE;

// backlightBright = 0; // 0 = 100%

if (IS_FAMILY_HORUS_OR_T16(board)) {
Expand Down Expand Up @@ -675,6 +677,42 @@ AbstractStaticItemModel * GeneralSettings::uartSampleModeItemModel()
return mdl;
}

QString GeneralSettings::hatsModeToString() const
{
return hatsModeToString(hatsMode);
}

// static
QString GeneralSettings::hatsModeToString(int value)
{
switch(value) {
case HATSMODE_TRIMS_ONLY:
return tr("Trims only");
case HATSMODE_KEYS_ONLY:
return tr("Keys only");
case HATSMODE_SWITCHABLE:
return tr("Switchable");
case HATSMODE_GLOBAL:
return tr("Global");
default:
return CPN_STR_UNKNOWN_ITEM;
}
}

// static
AbstractStaticItemModel * GeneralSettings::hatsModeItemModel(bool radio_setup)
{
AbstractStaticItemModel * mdl = new AbstractStaticItemModel();
mdl->setName(AIM_GS_HATSMODE);

for (int i = 0; i < HATSMODE_COUNT; i++) {
mdl->appendToItemList(hatsModeToString(i), i, i == HATSMODE_GLOBAL && radio_setup ? false : true);
}

mdl->loadItemList();
return mdl;
}

/*
TrainerMix
*/
Expand Down
13 changes: 13 additions & 0 deletions companion/src/firmwares/generalsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ constexpr char AIM_GS_SERIALMODE[] {"gs.serialmode"};
constexpr char AIM_GS_INTMODULEBAUDRATE[] {"gs.intmodulebaudrate"};
constexpr char AIM_GS_STICKDEADZONE[] {"gs.stickdeadzone"};
constexpr char AIM_GS_UARTSAMPLEMODE[] {"gs.uartsamplemode"};
constexpr char AIM_GS_HATSMODE[] {"gs.hatsmode"};
constexpr char AIM_TRAINERMIX_MODE[] {"trainermix.mode"};
constexpr char AIM_TRAINERMIX_SRC[] {"trainermix.src"};

Expand Down Expand Up @@ -171,6 +172,14 @@ class GeneralSettings {
UART_SAMPLE_MODE_COUNT
};

enum HatsMode {
HATSMODE_TRIMS_ONLY,
HATSMODE_KEYS_ONLY,
HATSMODE_SWITCHABLE,
HATSMODE_GLOBAL,
HATSMODE_COUNT
};

GeneralSettings() { clear(); }
void clear();
void init();
Expand Down Expand Up @@ -206,6 +215,7 @@ class GeneralSettings {
bool disableAlarmWarning;
bool disableRssiPoweroffAlarm;
unsigned int usbMode;
unsigned int hatsMode;
unsigned int stickDeadZone;
unsigned int jackMode;
bool sportPower;
Expand Down Expand Up @@ -311,6 +321,7 @@ class GeneralSettings {
QString serialPortModeToString(int port_nr) const;
QString internalModuleBaudrateToString() const;
QString uartSampleModeToString() const;
QString hatsModeToString() const;

static QString antennaModeToString(int value);
static QString bluetoothModeToString(int value);
Expand All @@ -319,11 +330,13 @@ class GeneralSettings {
static FieldRange getPPM_MultiplierRange();
static FieldRange getTxCurrentCalibration();
static QString uartSampleModeToString(int value);
static QString hatsModeToString(int value);

static AbstractStaticItemModel * antennaModeItemModel(bool model_setup = false);
static AbstractStaticItemModel * bluetoothModeItemModel();
static AbstractStaticItemModel * serialModeItemModel();
static AbstractStaticItemModel * internalModuleBaudrateItemModel();
static AbstractStaticItemModel * stickDeadZoneItemModel();
static AbstractStaticItemModel * uartSampleModeItemModel();
static AbstractStaticItemModel * hatsModeItemModel(bool radio_setup = true);
};
2 changes: 2 additions & 0 deletions companion/src/firmwares/modeldata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ void ModelData::clear()

const char * layoutId = "Layout2P1"; // currently all using same default though might change for NV14
RadioLayout::init(layoutId, customScreens);

hatsMode = GeneralSettings::HATSMODE_GLOBAL;
}

bool ModelData::isEmpty() const
Expand Down
1 change: 1 addition & 0 deletions companion/src/firmwares/modeldata.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ class ModelData {
unsigned int view;

char registrationId[8+1];
unsigned int hatsMode;

// Radio level tabs control (global settings)
unsigned int radioThemesDisabled;
Expand Down
31 changes: 22 additions & 9 deletions companion/src/generaledit/generalsetup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,22 @@

#include "generalsetup.h"
#include "ui_generalsetup.h"
#include "compounditemmodels.h"
#include "filtereditemmodels.h"
#include "autocombobox.h"

GeneralSetupPanel::GeneralSetupPanel(QWidget * parent, GeneralSettings & generalSettings, Firmware * firmware):
GeneralPanel(parent, generalSettings, firmware),
ui(new Ui::GeneralSetup)
{
ui->setupUi(this);

Board::Type board = firmware->getBoard();

QLabel *pmsl[] = {ui->ro_label, ui->ro1_label, ui->ro2_label, ui->ro3_label, ui->ro4_label, ui->ro5_label, ui->ro6_label, ui->ro7_label, ui->ro8_label, NULL};
QSlider *tpmsld[] = {ui->chkSA, ui->chkSB, ui->chkSC, ui->chkSD, ui->chkSE, ui->chkSF, ui->chkSG, ui->chkSH, NULL};

if (IS_TARANIS(firmware->getBoard())) {
if (IS_TARANIS(board)) {
if (firmware->getId().contains("readonly")) {
uint16_t switchstate = generalSettings.switchUnlockStates;
ui->chkSA->setValue(switchstate & 0x3);
Expand Down Expand Up @@ -153,21 +158,30 @@ ui(new Ui::GeneralSetup)

ui->timezoneLE->setTime((generalSettings.timezone * 3600) + (generalSettings.timezoneMinutes/*quarter hours*/ * 15 * 60));

if (IS_HORUS_OR_TARANIS(firmware->getBoard())) {
if (IS_HORUS_OR_TARANIS(board)) {
ui->adjustRTC->setChecked(generalSettings.adjustRTC);
}
else {
ui->adjustRTC->hide();
}

if (IS_STM32(firmware->getBoard())) {
if (IS_STM32(board)) {
ui->usbModeCB->setCurrentIndex(generalSettings.usbMode);
}
else {
ui->usbModeLabel->hide();
ui->usbModeCB->hide();
}

if (IS_FLYSKY_EL18(board) || IS_FLYSKY_NV14(board)) {
ui->hatsModeCB->setModel(new FilteredItemModel(GeneralSettings::hatsModeItemModel()));
ui->hatsModeCB->setField(generalSettings.hatsMode, this);
}
else {
ui->hatsModeLabel->hide();
ui->hatsModeCB->hide();
}

if (firmware->getCapability(HasSwitchableJack)) {
ui->jackModeCB->setCurrentIndex(generalSettings.jackMode);
}
Expand Down Expand Up @@ -200,13 +214,13 @@ ui(new Ui::GeneralSetup)
ui->label_BLBright->hide();
}

if (!IS_FAMILY_HORUS_OR_T16(firmware->getBoard())) {
if (!IS_FAMILY_HORUS_OR_T16(board)) {
ui->OFFBright_SB->hide();
ui->OFFBright_SB->setDisabled(true);
ui->label_OFFBright->hide();
}

if (!IS_JUMPER_T18(firmware->getBoard())) {
if (!IS_JUMPER_T18(board)) {
ui->keysBl_ChkB->hide();
ui->keysBl_ChkB->setDisabled(true);
ui->label_KeysBl->hide();
Expand Down Expand Up @@ -262,7 +276,7 @@ ui(new Ui::GeneralSetup)
ui->pwrOffDelayLabel->hide();
ui->pwrOffDelay->hide();
}
else if (!IS_TARANIS(firmware->getBoard())) {
else if (!IS_TARANIS(board)) {
ui->pwrOnDelayLabel->hide();
ui->pwrOnDelay->hide();
}
Expand All @@ -279,7 +293,7 @@ ui(new Ui::GeneralSetup)
connect(tpmsld[i], SIGNAL(valueChanged(int)),this,SLOT(unlockSwitchEdited()));
}

if (!IS_HORUS_OR_TARANIS(firmware->getBoard())) {
if (!IS_HORUS_OR_TARANIS(board)) {
ui->stickReverse1->setChecked(generalSettings.stickReverse & (1 << 0));
ui->stickReverse2->setChecked(generalSettings.stickReverse & (1 << 1));
ui->stickReverse3->setChecked(generalSettings.stickReverse & (1 << 2));
Expand All @@ -297,7 +311,7 @@ ui(new Ui::GeneralSetup)
ui->stickReverse4->hide();
}

if (IS_TARANIS_PLUS(firmware->getBoard())) {
if (IS_TARANIS_PLUS(board)) {
ui->backlightColor_SL->setValue(generalSettings.backlightColor);
}
else {
Expand Down Expand Up @@ -396,7 +410,6 @@ void GeneralSetupPanel::on_jackModeCB_currentIndexChanged(int index)
}
}


void GeneralSetupPanel::on_backlightColor_SL_valueChanged()
{
if (!lock) {
Expand Down
10 changes: 10 additions & 0 deletions companion/src/generaledit/generalsetup.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1682,6 +1682,16 @@ p, li { white-space: pre-wrap; }
</item>
</widget>
</item>
<item row="25" column="0">
<widget class="QLabel" name="hatsModeLabel">
<property name="text">
<string>Hats Mode</string>
</property>
</widget>
</item>
<item row="25" column="1">
<widget class="AutoComboBox" name="hatsModeCB"/>
</item>
<item row="20" column="0">
<widget class="QLabel" name="units_label">
<property name="text">
Expand Down
12 changes: 12 additions & 0 deletions companion/src/modeledit/setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ constexpr char FIM_TIMERSWITCH[] {"Timer Switch"};
constexpr char FIM_THRSOURCE[] {"Throttle Source"};
constexpr char FIM_TRAINERMODE[] {"Trainer Mode"};
constexpr char FIM_ANTENNAMODE[] {"Antenna Mode"};
constexpr char FIM_HATSMODE[] {"Hats Mode"};

TimerPanel::TimerPanel(QWidget * parent, ModelData & model, TimerData & timer, GeneralSettings & generalSettings, Firmware * firmware,
QWidget * prevFocus, FilteredItemModelFactory * panelFilteredModels, CompoundItemModelFactory * panelItemModels):
Expand Down Expand Up @@ -1474,6 +1475,8 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge
panelItemModels->registerItemModel(TimerData::persistentItemModel());
panelItemModels->registerItemModel(TimerData::modeItemModel());
panelItemModels->registerItemModel(TimerData::showElapsedItemModel());
panelFilteredModels->registerItemModel(new FilteredItemModel(GeneralSettings::hatsModeItemModel(false)), FIM_HATSMODE);

Board::Type board = firmware->getBoard();

memset(modules, 0, sizeof(modules));
Expand Down Expand Up @@ -1693,6 +1696,15 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge

ui->trimsDisplay->setField(model.trimsDisplay, this);

if (IS_FLYSKY_EL18(board) || IS_FLYSKY_NV14(board)) {
ui->cboHatsMode->setModel(panelFilteredModels->getItemModel(FIM_HATSMODE));
ui->cboHatsMode->setField(model.hatsMode, this);
}
else {
ui->lblHatsMode->hide();
ui->cboHatsMode->hide();
}

if (Boards::getCapability(firmware->getBoard(), Board::FunctionSwitches) > 0) {
funcswitches = new FunctionSwitchesPanel(this, model, generalSettings, firmware);
ui->functionSwitchesLayout->addWidget(funcswitches);
Expand Down
7 changes: 5 additions & 2 deletions companion/src/modeledit/setup.ui
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,15 @@
</widget>
</item>
<item alignment="Qt::AlignRight">
<widget class="QLabel" name="label_spacer">
<widget class="QLabel" name="lblHatsMode">
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="text">
<string/>
<string>Hats Mode</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
Expand Down Expand Up @@ -627,6 +627,9 @@
</item>
</widget>
</item>
<item row="1" column="0">
<widget class="AutoComboBox" name="cboHatsMode"/>
</item>
<item row="2" column="4">
<widget class="QPushButton" name="editText">
<property name="sizePolicy">
Expand Down
Loading

0 comments on commit f40fa1a

Please sign in to comment.