Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(el18): Use trim hats as keys for navigation #3894

Merged
merged 35 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
48a59e7
initial commit
mha1 Jul 29, 2023
ca2baee
Radio: cleanup
mha1 Jul 29, 2023
4f1f33d
left hat left as spare key for future use
mha1 Jul 30, 2023
ed50357
code cleanup
mha1 Jul 30, 2023
0f3828e
change direction for rotary events and trims used as keys
mha1 Jul 31, 2023
897b4e7
update key event definitions
mha1 Jul 31, 2023
8b8927d
enable forwarding trims as key events to LUA
mha1 Aug 1, 2023
dbd480e
fix rebase
mha1 Aug 1, 2023
ff209bd
add data funcs
Aug 3, 2023
580bd6b
convert ui QComboBox to AutoComboBox
Aug 3, 2023
aeb2750
model level selection of hats mode in model settings / model setup / …
mha1 Aug 3, 2023
c5c1fbc
add global to hats mode and hide from list of available modes if radi…
Aug 3, 2023
fa28daa
add hats mode to model setup
Aug 3, 2023
a5dbe76
add hats mode to models
Aug 4, 2023
f341a75
hats mode value as text in yaml files
Aug 4, 2023
013818b
harmonized radio and companion yaml tags and id's
mha1 Aug 4, 2023
6b57eba
updated logic for allowing hats mode switching
mha1 Aug 4, 2023
c89beaa
changed hats mode enum names to have prefix HATS_
mha1 Aug 5, 2023
300ab30
code cleanup
mha1 Aug 5, 2023
8af7e86
code cleanup with harmonizing variable and define names
mha1 Aug 5, 2023
d42e924
hats mode default settings:
mha1 Aug 6, 2023
3fa5cae
default hatsMode on radio.yml/modelxx.yml creation:
mha1 Aug 7, 2023
1ac2bbd
radio and cpn: update translations PL, SE, JP, IT, HE, FR, DE, DA , …
mha1 Aug 13, 2023
cdb9ca3
updated FR language translations
mha1 Aug 15, 2023
7d88b33
fix rebase
mha1 Aug 29, 2023
5d168f5
fix rebase
mha1 Aug 31, 2023
afd59a7
fix rebase
mha1 Aug 31, 2023
60534a4
fixed overlaying label and cb - courtesy @pfeerick
mha1 Sep 21, 2023
2a00c97
Merge remote-tracking branch 'origin/main' into PR_NV14_trims_as_keys
mha1 Sep 21, 2023
b65edbc
empty commit
mha1 Sep 21, 2023
0f2904e
fix merge error
mha1 Sep 21, 2023
a813da7
weird stuff after merge
mha1 Sep 21, 2023
b8c956a
chore: Remove unnecessary edits, formatting
pfeerick Sep 24, 2023
cb10543
chore: Run generate-yaml as someone clearly hasn't
pfeerick Sep 24, 2023
6493e3f
chore: Also show hats status in model printer
pfeerick Sep 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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