Skip to content

Commit

Permalink
feat: add support for ExpressLRS optional arming method (#5641)
Browse files Browse the repository at this point in the history
Co-authored-by: elecpower <[email protected]>
  • Loading branch information
mha1 and elecpower authored Nov 22, 2024
1 parent ebb5d39 commit 8fd3d50
Show file tree
Hide file tree
Showing 69 changed files with 654 additions and 38 deletions.
5 changes: 5 additions & 0 deletions companion/src/firmwares/edgetx/yaml_moduledata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "yaml_generalsettings.h"
#include "eeprominterface.h"
#include "rawsource.h"
#include "yaml_rawswitch.h"
#include "multiprotocols.h"

// type: TYPE_MULTIMODULE
Expand Down Expand Up @@ -242,6 +243,8 @@ Node convert<ModuleData>::encode(const ModuleData& rhs)
Node crsf;
YamlTelemetryBaudrate br(&rhs.crsf.telemetryBaudrate);
crsf["telemetryBaudrate"] = br.value;
crsf["crsfArmingMode"] = rhs.crsf.crsfArmingMode;
crsf["crsfArmingTrigger"] = rhs.crsf.crsfArmingTrigger;
mod["crsf"] = crsf;
} break;
case PULSES_LEMON_DSMP: {
Expand Down Expand Up @@ -399,6 +402,8 @@ bool convert<ModuleData>::decode(const Node& node, ModuleData& rhs)
YamlTelemetryBaudrate telemetryBaudrate;
crsf["telemetryBaudrate"] >> telemetryBaudrate.value;
telemetryBaudrate.toCpn(&rhs.crsf.telemetryBaudrate, getCurrentFirmware()->getBoard());
crsf["crsfArmingMode"] >> rhs.crsf.crsfArmingMode;
crsf["crsfArmingTrigger"] >> rhs.crsf.crsfArmingTrigger;
} else if (mod["dsmp"]) {
Node dsmp = mod["dsmp"];
dsmp["flags"] >> rhs.dsmp.flags;
Expand Down
32 changes: 32 additions & 0 deletions companion/src/firmwares/moduledata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -770,3 +770,35 @@ AbstractStaticItemModel * ModuleData::afhds3EmiItemModel()
mdl->loadItemList();
return mdl;
}

QString ModuleData::crsfArmingModeToString() const
{
return crsfArmingModeToString(crsf.crsfArmingMode);
}

// static
QString ModuleData::crsfArmingModeToString(int mode)
{
switch (mode) {
case CRSF_ARMING_MODE_CH5:
return tr("CH5");
case CRSF_ARMING_MODE_SWITCH:
return tr("Switch");
default:
return CPN_STR_UNKNOWN_ITEM;
}
}

// static
AbstractStaticItemModel * ModuleData::crsfArmingModeItemModel()
{
AbstractStaticItemModel * mdl = new AbstractStaticItemModel();
mdl->setName(AIM_MODULE_CRSFARMINGMODE);

for (int i = 0; i < CRSF_ARMING_MODE_COUNT; i++) {
mdl->appendToItemList(crsfArmingModeToString(i), i);
}

mdl->loadItemList();
return mdl;
}
17 changes: 16 additions & 1 deletion companion/src/firmwares/moduledata.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@

#include "constants.h"
#include "radio/src/MultiProtoDefs.h"
#include "rawswitch.h"

#include <QtCore>

constexpr char AIM_MODULE_CRSFARMINGMODE[] {"moduledata.crsfArmingMode"};

class Firmware;
class RadioDataConversionState;
class AbstractStaticItemModel;
Expand Down Expand Up @@ -114,6 +117,12 @@ class ModuleData {
Q_DECLARE_TR_FUNCTIONS(ModuleData)

public:
enum CrsfArmingMode {
CRSF_ARMING_MODE_CH5,
CRSF_ARMING_MODE_SWITCH,
CRSF_ARMING_MODE_COUNT
};

ModuleData()
{
clear();
Expand Down Expand Up @@ -191,6 +200,8 @@ class ModuleData {

struct CRSF {
unsigned int telemetryBaudrate;
unsigned int crsfArmingMode;
RawSwitch crsfArmingTrigger;
} crsf;

struct Access {
Expand All @@ -203,7 +214,7 @@ class ModuleData {
unsigned int flags;
} dsmp;

void clear() { memset(this, 0, sizeof(ModuleData)); }
void clear() { memset(reinterpret_cast<void *>(this), 0, sizeof(ModuleData)); }
void convert(RadioDataConversionState & cstate);
bool isPxx2Module() const;
bool supportRxNum() const;
Expand Down Expand Up @@ -234,4 +245,8 @@ class ModuleData {
static AbstractStaticItemModel * afhds2aMode2ItemModel();
static AbstractStaticItemModel * afhds3PhyModeItemModel();
static AbstractStaticItemModel * afhds3EmiItemModel();

QString crsfArmingModeToString() const;
static QString crsfArmingModeToString(int mode);
static AbstractStaticItemModel * crsfArmingModeItemModel();
};
57 changes: 48 additions & 9 deletions companion/src/modeledit/setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@

#include <QDir>

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"};
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"};
constexpr char FIM_CRSFARMSWITCH[] {"CRSF Arming Switch"};


TimerPanel::TimerPanel(QWidget * parent, ModelData & model, TimerData & timer, GeneralSettings & generalSettings, Firmware * firmware,
QWidget * prevFocus, FilteredItemModelFactory * panelFilteredModels, CompoundItemModelFactory * panelItemModels):
Expand Down Expand Up @@ -230,11 +232,13 @@ void TimerPanel::onModeChanged(int index)
#define MASK_CHANNELMAP (1<<20)
#define MASK_MULTI_BAYANG_OPT (1<<21)
#define MASK_AFHDS (1<<22)
#define MASK_CSRF_ARMING_MODE (1<<23)
#define MASK_CSRF_ARMING_TRIGGER (1<<24)

quint8 ModulePanel::failsafesValueDisplayType = ModulePanel::FAILSAFE_DISPLAY_PERCENT;

ModulePanel::ModulePanel(QWidget * parent, ModelData & model, ModuleData & module, GeneralSettings & generalSettings, Firmware * firmware, int moduleIdx,
FilteredItemModelFactory * panelFilteredItemModels):
FilteredItemModelFactory * panelFilteredItemModels, CompoundItemModelFactory * panelItemModels):
ModelPanel(parent, model, generalSettings, firmware),
module(module),
moduleIdx(moduleIdx),
Expand Down Expand Up @@ -310,6 +314,11 @@ ModulePanel::ModulePanel(QWidget * parent, ModelData & model, ModuleData & modul

ui->registrationId->setText(model.registrationId);

if (panelItemModels) {
ui->crsfArmingMode->setModel(panelItemModels->getItemModel(AIM_MODULE_CRSFARMINGMODE));
ui->crsfArmingTrigger->setModel(panelFilteredItemModels->getItemModel(FIM_CRSFARMSWITCH));
}

setupFailsafes();

disableMouseScrolling();
Expand Down Expand Up @@ -350,6 +359,21 @@ ModulePanel::ModulePanel(QWidget * parent, ModelData & model, ModuleData & modul
emit modified();
});

connect(ui->crsfArmingMode, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [=] (int index)
{
this->module.crsf.crsfArmingMode = ui->crsfArmingMode->currentData().toInt();
if (this->module.crsf.crsfArmingMode != ModuleData::CRSF_ARMING_MODE_SWITCH)
this->module.crsf.crsfArmingTrigger = RawSwitch(SWITCH_TYPE_NONE);
update();
emit modified();
});

connect(ui->crsfArmingTrigger, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [=] (int index)
{
this->module.crsf.crsfArmingTrigger = RawSwitch(ui->crsfArmingTrigger->currentData().toInt());
emit modified();
});

lock = false;
}

Expand Down Expand Up @@ -505,10 +529,15 @@ void ModulePanel::update()
max_rx_num = 20;
break;
case PULSES_CROSSFIRE:
mask |= MASK_CHANNELS_RANGE | MASK_RX_NUMBER | MASK_BAUDRATE;
mask |= MASK_CHANNELS_RANGE | MASK_RX_NUMBER | MASK_BAUDRATE | MASK_CSRF_ARMING_MODE;
module.channelsCount = 16;
ui->telemetryBaudrate->setModel(ModuleData::telemetryBaudrateItemModel(protocol));
ui->telemetryBaudrate->setField(module.crsf.telemetryBaudrate);
ui->crsfArmingMode->setCurrentIndex(module.crsf.crsfArmingMode);
if (module.crsf.crsfArmingMode == ModuleData::CRSF_ARMING_MODE_SWITCH) {
mask |= MASK_CSRF_ARMING_TRIGGER;
ui->crsfArmingTrigger->setCurrentIndex(ui->crsfArmingTrigger->findData(RawSwitch(module.crsf.crsfArmingTrigger).toValue()));
}
break;
case PULSES_GHOST:
mask |= MASK_CHANNELS_RANGE | MASK_GHOST | MASK_BAUDRATE;
Expand Down Expand Up @@ -602,6 +631,9 @@ void ModulePanel::update()
ui->channelsCount->setMaximum(module.getMaxChannelCount());
ui->channelsCount->setValue(module.channelsCount);
ui->channelsCount->setSingleStep(firmware->getCapability(HasPPMStart) ? 1 : 2);
ui->label_crsfArmingMode->setVisible(mask & MASK_CSRF_ARMING_MODE);
ui->crsfArmingMode->setVisible(mask & MASK_CSRF_ARMING_MODE);
ui->crsfArmingTrigger->setVisible(mask & MASK_CSRF_ARMING_TRIGGER);

// PPM settings fields
ui->label_ppmPolarity->setVisible(mask & MASK_SBUSPPM_FIELDS);
Expand Down Expand Up @@ -1563,17 +1595,24 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge
FIM_TIMERSWITCH);
connectItemModelEvents(panelFilteredModels->getItemModel(FIM_TIMERSWITCH));

panelFilteredModels->registerItemModel(new FilteredItemModel(sharedItemModels->getItemModel(AbstractItemModel::IMID_RawSwitch),
RawSwitch::SpecialFunctionsContext),
FIM_CRSFARMSWITCH);
connectItemModelEvents(panelFilteredModels->getItemModel(FIM_CRSFARMSWITCH));

panelFilteredModels->registerItemModel(new FilteredItemModel(sharedItemModels->getItemModel(AbstractItemModel::IMID_ThrSource)),
FIM_THRSOURCE);
connectItemModelEvents(panelFilteredModels->getItemModel(FIM_THRSOURCE));

panelFilteredModels->registerItemModel(new FilteredItemModel(GeneralSettings::hatsModeItemModel(false)), FIM_HATSMODE);

panelItemModels = new CompoundItemModelFactory(&generalSettings, &model);
panelItemModels->registerItemModel(TimerData::countdownBeepItemModel());
panelItemModels->registerItemModel(TimerData::countdownStartItemModel());
panelItemModels->registerItemModel(TimerData::persistentItemModel());
panelItemModels->registerItemModel(TimerData::modeItemModel());
panelItemModels->registerItemModel(TimerData::showElapsedItemModel());
panelFilteredModels->registerItemModel(new FilteredItemModel(GeneralSettings::hatsModeItemModel(false)), FIM_HATSMODE);
panelItemModels->registerItemModel(ModuleData::crsfArmingModeItemModel());

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

Expand Down Expand Up @@ -1807,7 +1846,7 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge
}

for (int i = firmware->getCapability(NumFirstUsableModule); i < firmware->getCapability(NumModules); i++) {
modules[i] = new ModulePanel(this, model, model.moduleData[i], generalSettings, firmware, i, panelFilteredModels);
modules[i] = new ModulePanel(this, model, model.moduleData[i], generalSettings, firmware, i, panelFilteredModels, panelItemModels);
ui->modulesLayout->addWidget(modules[i]);
connect(modules[i], &ModulePanel::modified, this, &SetupPanel::modified);
connect(modules[i], &ModulePanel::updateItemModels, this, &SetupPanel::onModuleUpdateItemModels);
Expand Down
2 changes: 1 addition & 1 deletion companion/src/modeledit/setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class ModulePanel : public ModelPanel

public:
ModulePanel(QWidget * parent, ModelData & model, ModuleData & module, GeneralSettings & generalSettings, Firmware * firmware, int moduleIdx,
FilteredItemModelFactory * panelFilteredItemModels = nullptr);
FilteredItemModelFactory * panelFilteredItemModels = nullptr, CompoundItemModelFactory * panelItemModels = nullptr);
virtual ~ModulePanel();
virtual void update();

Expand Down
19 changes: 18 additions & 1 deletion companion/src/modeledit/setup_module.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>1075</width>
<height>527</height>
<height>543</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -429,6 +429,23 @@
</item>
</layout>
</item>
<item row="15" column="0">
<widget class="QLabel" name="label_crsfArmingMode">
<property name="text">
<string>Arm using</string>
</property>
</widget>
</item>
<item row="15" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_crsfarm">
<item>
<widget class="QComboBox" name="crsfArmingMode"/>
</item>
<item>
<widget class="QComboBox" name="crsfArmingTrigger"/>
</item>
</layout>
</item>
</layout>
</item>
<item row="0" column="1">
Expand Down
6 changes: 6 additions & 0 deletions companion/src/modelprinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,12 @@ QString ModelPrinter::printModule(int idx)
if (module.protocol == PULSES_GHOST) {
str << printLabelValue(tr("Raw 12 bits"), printBoolean(module.ghost.raw12bits, BOOLEAN_YN));
}
if (module.protocol == PULSES_CROSSFIRE) {
str << printLabelValue(tr("Arming mode"), module.crsfArmingModeToString());
if (module.crsf.crsfArmingMode == ModuleData::CRSF_ARMING_MODE_SWITCH) {
str << printLabelValue(tr("Switch"), RawSwitch(module.crsf.crsfArmingTrigger).toString());
}
}
}
}
result = str.join(" ");
Expand Down
15 changes: 15 additions & 0 deletions companion/src/translations/companion_cs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10252,6 +10252,21 @@ p, li { white-space: pre-wrap; }
<source>Receiver No.</source>
<translation type="unfinished">Číslo přijímače</translation>
</message>
<message>
<location filename="../modeledit/setup_module.ui" line="507"/>
<source>Arm using</source>
<translation>Arm mód</translation>
</message>
<message>
<location filename="../modeledit/setup_module.ui" line="507"/>
<source>CH5</source>
<translation type="unfinished">CH5</translation>
</message>
<message>
<location filename="../modeledit/setup_module.ui" line="507"/>
<source>Switch</source>
<translation type="unfinished">Switch</translation>
</message>
<message>
<location filename="../modeledit/setup_module.ui" line="1050"/>
<source>Output type</source>
Expand Down
15 changes: 15 additions & 0 deletions companion/src/translations/companion_da.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10111,6 +10111,21 @@ p, li { white-space: pre-wrap; }
<source>Receiver No.</source>
<translation>Modtager nummer.</translation>
</message>
<message>
<location filename="../modeledit/setup_module.ui" line="507"/>
<source>Arm using</source>
<translation>Aktiver m.</translation>
</message>
<message>
<location filename="../modeledit/setup_module.ui" line="507"/>
<source>CH5</source>
<translation>KA5</translation>
</message>
<message>
<location filename="../modeledit/setup_module.ui" line="507"/>
<source>Switch</source>
<translation type="unfinished">Switch</translation>
</message>
<message>
<location filename="../modeledit/setup_module.ui" line="482"/>
<source>CH </source>
Expand Down
15 changes: 15 additions & 0 deletions companion/src/translations/companion_de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10233,6 +10233,21 @@ p, li { white-space: pre-wrap; }
<source>Receiver No.</source>
<translation>Empfänger Nr.</translation>
</message>
<message>
<location filename="../modeledit/setup_module.ui" line="507"/>
<source>Arm using</source>
<translation>Armen via</translation>
</message>
<message>
<location filename="../modeledit/setup_module.ui" line="507"/>
<source>CH5</source>
<translation type="unfinished">CH5</translation>
</message>
<message>
<location filename="../modeledit/setup_module.ui" line="507"/>
<source>Switch</source>
<translation type="unfinished">Switch</translation>
</message>
<message>
<location filename="../modeledit/setup_module.ui" line="1050"/>
<source>Output type</source>
Expand Down
15 changes: 15 additions & 0 deletions companion/src/translations/companion_en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10031,6 +10031,21 @@ p, li { white-space: pre-wrap; }
<source>Receiver No.</source>
<translation></translation>
</message>
<message>
<location filename="../modeledit/setup_module.ui" line="507"/>
<source>Arm using</source>
<translation type="unfinished">Arm using</translation>
</message>
<message>
<location filename="../modeledit/setup_module.ui" line="507"/>
<source>CH5</source>
<translation type="unfinished">CH5</translation>
</message>
<message>
<location filename="../modeledit/setup_module.ui" line="507"/>
<source>Switch</source>
<translation type="unfinished">Switch</translation>
</message>
<message>
<location filename="../modeledit/setup_module.ui" line="596"/>
<source>RF Output Power</source>
Expand Down
Loading

0 comments on commit 8fd3d50

Please sign in to comment.