Skip to content

Commit

Permalink
enh(cpn): more support for afhds2a and 3
Browse files Browse the repository at this point in the history
  • Loading branch information
elecpower committed Jul 16, 2023
1 parent b091c27 commit 854af38
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 46 deletions.
1 change: 0 additions & 1 deletion companion/src/firmwares/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ set(firmwares_SRCS
sensordata.cpp
telem_data.cpp
timerdata.cpp
afhds3.cpp
ersky9x/ersky9xeeprom.cpp
ersky9x/ersky9xinterface.cpp
opentx/opentxeeprom.cpp
Expand Down
12 changes: 0 additions & 12 deletions companion/src/firmwares/afhds3.cpp

This file was deleted.

12 changes: 0 additions & 12 deletions companion/src/firmwares/afhds3.h

This file was deleted.

74 changes: 73 additions & 1 deletion companion/src/firmwares/moduledata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
#include "moduledata.h"
#include "eeprominterface.h"
#include "multiprotocols.h"
#include "afhds3.h"
#include "radiodataconversionstate.h"
#include "compounditemmodels.h"
#include "generalsettings.h"
#include "helpers.h"

#include <QPair>
#include <QVector>
Expand Down Expand Up @@ -665,3 +665,75 @@ AbstractStaticItemModel * ModuleData::telemetryBaudrateItemModel(unsigned int p
mdl->loadItemList();
return mdl;
}

QString ModuleData::afhds2aMode1ToString() const
{
return afhds2aMode1List.at(Helpers::getBitmappedValue(flysky.mode, 1));
}

QString ModuleData::afhds2aMode2ToString() const
{
return afhds2aMode2List.at(Helpers::getBitmappedValue(flysky.mode, 2));
}

QString ModuleData::afhds3PhyModeToString() const
{
return afhds3PhyModeList.at(afhds3.phyMode);
}

QString ModuleData::afhds3EmiToString() const
{
return afhds3EmiList.at(afhds3.emi);
}

AbstractStaticItemModel * ModuleData::afhds2aMode1ItemModel()
{
AbstractStaticItemModel * mdl = new AbstractStaticItemModel();
mdl->setName("moduledata.afhds2aMode1");

for (int i = 0; i < afhds2aMode1List.size(); i++) {
mdl->appendToItemList(afhds2aMode1List.at(i), i);
}

mdl->loadItemList();
return mdl;
}

AbstractStaticItemModel * ModuleData::afhds2aMode2ItemModel()
{
AbstractStaticItemModel * mdl = new AbstractStaticItemModel();
mdl->setName("moduledata.afhds2aMode2");

for (int i = 0; i < afhds2aMode2List.size(); i++) {
mdl->appendToItemList(afhds2aMode2List.at(i), i);
}

mdl->loadItemList();
return mdl;
}

AbstractStaticItemModel * ModuleData::afhds3PhyModeItemModel()
{
AbstractStaticItemModel * mdl = new AbstractStaticItemModel();
mdl->setName("moduledata.afhds3PhyMode");

for (int i = 0; i < afhds3PhyModeList.size(); i++) {
mdl->appendToItemList(afhds3PhyModeList.at(i), i);
}

mdl->loadItemList();
return mdl;
}

AbstractStaticItemModel * ModuleData::afhds3EmiItemModel()
{
AbstractStaticItemModel * mdl = new AbstractStaticItemModel();
mdl->setName("moduledata.afhds3Emi");

for (int i = 0; i < afhds3EmiList.size(); i++) {
mdl->appendToItemList(afhds3EmiList.at(i), i + 1); // Note: 1 based
}

mdl->loadItemList();
return mdl;
}
25 changes: 24 additions & 1 deletion companion/src/firmwares/moduledata.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ enum ModuleSubtypeR9M {
constexpr int PXX2_MAX_RECEIVERS_PER_MODULE = 3;
constexpr int PXX2_LEN_RX_NAME = 8;

static const QStringList afhds2aMode1List({"PWM", "PPM"});
static const QStringList afhds2aMode2List({"IBUS", "SBUS"});
static const QStringList afhds3PhyModeList({"Classic 18ch", "C-Fast 10ch", "Routine 18ch", "Fast 8ch", "Lora 12ch"});
static const QStringList afhds3EmiList({"CE", "FCC"});

class ModuleData {
Q_DECLARE_TR_FUNCTIONS(ModuleData)

Expand Down Expand Up @@ -161,6 +166,14 @@ class ModuleData {
unsigned int phyMode;
unsigned int reserved;
unsigned int rfPower;

void setDefault() {
emi = 1;
telemetry = 0;
phyMode = 0;
reserved = 0;
rfPower = 0;
}
} afhds3;

struct PXX {
Expand Down Expand Up @@ -208,6 +221,16 @@ class ModuleData {
static AbstractStaticItemModel * internalModuleItemModel(int board = -1);
static bool isProtocolAvailable(int moduleidx, unsigned int protocol, GeneralSettings & generalSettings);
static AbstractStaticItemModel * protocolItemModel(GeneralSettings & settings);
static AbstractStaticItemModel * telemetryBaudrateItemModel(unsigned int protocol);
static AbstractStaticItemModel * telemetryBaudrateItemModel(unsigned int protocol);
static bool isAvailable(PulsesProtocol proto, int port = 0); // moved from OpenTxFirmware EdgeTX v2.9 - TODO remove and use isProtocolAvailable

QString afhds2aMode1ToString() const;
QString afhds2aMode2ToString() const;
QString afhds3PhyModeToString() const;
QString afhds3EmiToString() const;

static AbstractStaticItemModel * afhds2aMode1ItemModel();
static AbstractStaticItemModel * afhds2aMode2ItemModel();
static AbstractStaticItemModel * afhds3PhyModeItemModel();
static AbstractStaticItemModel * afhds3EmiItemModel();
};
64 changes: 55 additions & 9 deletions companion/src/modeledit/setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ void TimerPanel::onModeChanged(int index)
#define MASK_MULTI_DSM_OPT (1<<19)
#define MASK_CHANNELMAP (1<<20)
#define MASK_MULTI_BAYANG_OPT (1<<21)
#define MASK_AFHDS (1<<22)

quint8 ModulePanel::failsafesValueDisplayType = ModulePanel::FAILSAFE_DISPLAY_PERCENT;

Expand Down Expand Up @@ -314,9 +315,32 @@ ModulePanel::ModulePanel(QWidget * parent, ModelData & model, ModuleData & modul
connect(ui->clearRx1, SIGNAL(clicked()), this, SLOT(onClearAccessRxClicked()));
connect(ui->clearRx2, SIGNAL(clicked()), this, SLOT(onClearAccessRxClicked()));
connect(ui->clearRx3, SIGNAL(clicked()), this, SLOT(onClearAccessRxClicked()));
connect(ui->cboAfhdsOpt1, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [=] (int index)
{
if (lock)
return;

lock = false;
if (this->module.protocol == PULSES_FLYSKY_AFHDS2A)
Helpers::setBitmappedValue(this->module.flysky.mode, ui->cboAfhdsOpt1->currentData().toInt(), 1);
else
this->module.afhds3.phyMode = ui->cboAfhdsOpt1->currentData().toInt();

emit modified();
});
connect(ui->cboAfhdsOpt2, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [=] (int index)
{
if (lock)
return;

if (this->module.protocol == PULSES_FLYSKY_AFHDS2A)
Helpers::setBitmappedValue(this->module.flysky.mode, ui->cboAfhdsOpt2->currentData().toInt(), 0);
else
this->module.afhds3.emi = ui->cboAfhdsOpt2->currentData().toInt();

emit modified();
});

lock = false;
}

ModulePanel::~ModulePanel()
Expand Down Expand Up @@ -523,13 +547,10 @@ void ModulePanel::update()
if (pdef.disableChannelMap)
mask |= MASK_CHANNELMAP;
break;
case PULSES_FLYSKY_AFHDS2A:
mask |= MASK_CHANNELS_RANGE| MASK_CHANNELS_COUNT | MASK_FAILSAFES;
mask |= MASK_RX_FREQ | MASK_RF_POWER;
break;
case PULSES_FLYSKY_AFHDS3:
mask |= MASK_CHANNELS_RANGE| MASK_CHANNELS_COUNT | MASK_FAILSAFES;
mask |= MASK_RF_POWER;
mask |= MASK_RX_NUMBER;
case PULSES_FLYSKY_AFHDS2A:
mask |= MASK_CHANNELS_RANGE| MASK_CHANNELS_COUNT | MASK_FAILSAFES | MASK_AFHDS;
break;
case PULSES_LEMON_DSMP:
mask |= MASK_CHANNELS_RANGE;
Expand Down Expand Up @@ -749,11 +770,33 @@ void ModulePanel::update()
ui->clearRx3->setVisible((mask & MASK_ACCESS) && (module.access.receivers & (1 << 2)));
ui->rx3->setVisible((mask & MASK_ACCESS) && (module.access.receivers & (1 << 2)));

// AFHFS
if (mask & MASK_AFHDS) {
if (protocol == PULSES_FLYSKY_AFHDS2A) {
ui->label_afhds->setText(tr("Options"));
ui->cboAfhdsOpt1->setModel(ModuleData::afhds2aMode1ItemModel());
ui->cboAfhdsOpt1->setCurrentIndex(Helpers::getBitmappedValue(module.flysky.mode, 1));

ui->cboAfhdsOpt2->setModel(ModuleData::afhds2aMode2ItemModel());
ui->cboAfhdsOpt2->setCurrentIndex(Helpers::getBitmappedValue(module.flysky.mode, 0));
}
else {
ui->label_afhds->setText(tr("Type"));
ui->cboAfhdsOpt1->setModel(ModuleData::afhds3PhyModeItemModel());
ui->cboAfhdsOpt1->setCurrentIndex(ui->cboAfhdsOpt1->findData(module.afhds3.phyMode));

ui->cboAfhdsOpt2->setModel(ModuleData::afhds3EmiItemModel());
ui->cboAfhdsOpt2->setCurrentIndex(ui->cboAfhdsOpt2->findData(module.afhds3.emi));
}
}

ui->label_afhds->setVisible(mask & MASK_AFHDS);
ui->cboAfhdsOpt1->setVisible(mask & MASK_AFHDS);
ui->cboAfhdsOpt2->setVisible(mask & MASK_AFHDS);

// Failsafes
ui->label_failsafeMode->setVisible(mask & MASK_FAILSAFES);
ui->failsafeMode->setVisible(mask & MASK_FAILSAFES);
//hide receiver mode for afhds2a or afhds3
qobject_cast<QListView *>(ui->failsafeMode->view())->setRowHidden(FAILSAFE_RECEIVER, (protocol == PULSES_FLYSKY_AFHDS2A || protocol == PULSES_FLYSKY_AFHDS3));

if ((mask & MASK_FAILSAFES) && module.failsafeMode == FAILSAFE_CUSTOM) {
if (ui->failsafesGroupBox->isHidden()) {
Expand Down Expand Up @@ -810,6 +853,9 @@ void ModulePanel::onProtocolChanged(int index)
else if (module.protocol == PULSES_FLYSKY_AFHDS2A) {
module.flysky.setDefault();
}
else if (module.protocol == PULSES_FLYSKY_AFHDS3) {
module.afhds3.setDefault();
}

emit updateItemModels();
emit modified();
Expand Down
37 changes: 27 additions & 10 deletions companion/src/modeledit/setup_module.ui
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<item row="6" column="0" colspan="2">
<widget class="QLabel" name="warning_r9mFlex">
<property name="palette">
<palette>
Expand Down Expand Up @@ -276,7 +276,7 @@
</property>
</widget>
</item>
<item row="6" column="0">
<item row="7" column="0">
<widget class="QLabel" name="label_failsafeMode">
<property name="maximumSize">
<size>
Expand All @@ -292,7 +292,7 @@
</property>
</widget>
</item>
<item row="6" column="1">
<item row="7" column="1">
<widget class="QComboBox" name="failsafeMode">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
Expand Down Expand Up @@ -336,7 +336,7 @@
</item>
</widget>
</item>
<item row="7" column="0">
<item row="8" column="0">
<widget class="QLabel" name="label_trainerMode">
<property name="maximumSize">
<size>
Expand All @@ -352,7 +352,7 @@
</property>
</widget>
</item>
<item row="7" column="1">
<item row="8" column="1">
<widget class="AutoComboBox" name="trainerMode">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
Expand All @@ -371,35 +371,35 @@
</property>
</widget>
</item>
<item row="8" column="1">
<item row="9" column="1">
<widget class="QCheckBox" name="disableTelem">
<property name="text">
<string>Disable Telemetry</string>
</property>
</widget>
</item>
<item row="11" column="1">
<item row="12" column="1">
<widget class="QCheckBox" name="disableChMap">
<property name="text">
<string>Disable Ch. Map</string>
</property>
</widget>
</item>
<item row="12" column="1">
<item row="13" column="1">
<widget class="QCheckBox" name="racingMode">
<property name="text">
<string>Racing Mode</string>
</property>
</widget>
</item>
<item row="13" column="1">
<item row="14" column="1">
<widget class="QCheckBox" name="raw12bits">
<property name="text">
<string>Raw 12 bits</string>
</property>
</widget>
</item>
<item row="15" column="0" colspan="2">
<item row="16" column="0" colspan="2">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
Expand All @@ -412,6 +412,23 @@
</property>
</spacer>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_afhds">
<property name="text">
<string>Options</string>
</property>
</widget>
</item>
<item row="5" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QComboBox" name="cboAfhdsOpt1"/>
</item>
<item>
<widget class="QComboBox" name="cboAfhdsOpt2"/>
</item>
</layout>
</item>
</layout>
</item>
<item row="0" column="1">
Expand Down

0 comments on commit 854af38

Please sign in to comment.