refactor(cpn): Support JSON radio hardware definitions (#4406)

This commit is contained in:
Neil Horne
2024-02-04 15:59:04 +10:00
committed by GitHub
parent c6ae44f523
commit 83294613f6
63 changed files with 4166 additions and 2295 deletions
+12 -13
View File
@@ -25,38 +25,37 @@
CalibrationPanel::CalibrationPanel(QWidget * parent, GeneralSettings & generalSettings, Firmware * firmware):
GeneralPanel(parent, generalSettings, firmware)
{
Board::Type board = getCurrentBoard();
int rows = Boards::getCapability(board, Board::MaxAnalogs);
int maxrows = Boards::getInputsCalibrated();
int maxinputs = Boards::getCapability(getCurrentBoard(), Board::Inputs);
QStringList headerLabels;
headerLabels << "" << tr("Negative span") << tr("Mid value") << tr("Positive span");
TableLayout * tableLayout = new TableLayout(this, rows, headerLabels);
TableLayout * tableLayout = new TableLayout(this, maxrows, headerLabels);
for (int i = 0, row = 0; i < rows; i++) {
int col = 0;
if (firmware->getCapability(HasFlySkyGimbals) &&
i >= (Boards::getCapability(board, Board::Sticks) + 5) &&
i < (Boards::getCapability(board, Board::Sticks) + 7))
for (int i = 0, row = 0; i < maxinputs; i++) {
if (!Boards::isInputCalibrated(i))
continue;
GeneralSettings::InputCalib &calib = generalSettings.inputConfig[i].calib;
int col = 0;
row++;
QLabel * label = new QLabel(this);
label->setText(firmware->getAnalogInputName(i));
label->setText(Boards::getInputName(i));
tableLayout->addWidget(i, col++, label);
QLineEdit * leNeg = new QLineEdit(this);
leNeg->setText(QString("%1").arg(generalSettings.calibSpanNeg[i]));
leNeg->setText(QString("%1").arg(calib.spanNeg));
leNeg->setReadOnly(true);
tableLayout->addWidget(i, col++, leNeg);
QLineEdit * leMid = new QLineEdit(this);
leMid->setText(QString("%1").arg(generalSettings.calibMid[i]));
leMid->setText(QString("%1").arg(calib.mid));
leMid->setReadOnly(true);
tableLayout->addWidget(i, col++, leMid);
QLineEdit * lePos = new QLineEdit(this);
lePos->setText(QString("%1").arg(generalSettings.calibSpanPos[i]));
lePos->setText(QString("%1").arg(calib.spanPos));
lePos->setReadOnly(true);
tableLayout->addWidget(i, col++, lePos);
}
@@ -65,5 +64,5 @@ CalibrationPanel::CalibrationPanel(QWidget * parent, GeneralSettings & generalSe
tableLayout->resizeColumnsToContents();
tableLayout->setColumnWidth(0, QString(15, ' '));
tableLayout->pushColumnsLeft(headerLabels.count());
tableLayout->pushRowsUp(rows + 1);
tableLayout->pushRowsUp(maxrows + 1);
}
+91 -104
View File
@@ -114,17 +114,18 @@ void GeneralEdit::on_tabWidget_currentChanged(int index)
void GeneralEdit::on_calretrieve_PB_clicked()
{
Board::Type board = getCurrentBoard();
int profile_id=ui->profile_CB->itemData(ui->profile_CB->currentIndex()).toInt();
QString calib=g.profile[profile_id].stickPotCalib();
int potsnum=getBoardCapability(board, Board::Pots)+getBoardCapability(board, Board::Sliders);
int numSwPots=getBoardCapability(board, Board::Switches)+getBoardCapability(board, Board::Pots)+getBoardCapability(board, Board::Sliders);
int profile_id = ui->profile_CB->itemData(ui->profile_CB->currentIndex()).toInt();
QString calib = g.profile[profile_id].stickPotCalib();
int ttlSticks = getBoardCapability(board, Board::Sticks);
int ttlInputs = getBoardCapability(board, Board::Inputs);
int ttlSwitches = getBoardCapability(board, Board::Switches);
if (calib.isEmpty()) {
return;
}
else {
QString trainercalib = g.profile[profile_id].trainerCalib();
QString hwtypes = g.profile[profile_id].controlTypes();
QString controlNames=g.profile[profile_id].controlNames();
QString controlNames = g.profile[profile_id].controlNames();
int8_t txVoltageCalibration = (int8_t)g.profile[profile_id].txVoltageCalibration();
int8_t txCurrentCalibration = (int8_t)g.profile[profile_id].txCurrentCalibration();
int8_t PPM_Multiplier = (int8_t)g.profile[profile_id].ppmMultiplier();
@@ -136,74 +137,60 @@ void GeneralEdit::on_calretrieve_PB_clicked()
QString SpeakerSet = g.profile[profile_id].speaker();
QString CountrySet = g.profile[profile_id].countryCode();
if ((calib.length()==(CPN_MAX_STICKS+potsnum)*12) && (trainercalib.length()==16)) {
if ((calib.length() == (Boards::getInputsCalibrated() * 12)) && (trainercalib.length() == 16)) {
QString Byte;
int16_t byte16;
bool ok;
for (int i=0; i<(CPN_MAX_STICKS+potsnum); i++) {
Byte=calib.mid(i*12,4);
byte16=(int16_t)Byte.toInt(&ok,16);
if (ok) generalSettings.calibMid[i]=byte16;
Byte=calib.mid(4+i*12,4);
byte16=(int16_t)Byte.toInt(&ok,16);
if (ok) generalSettings.calibSpanNeg[i]=byte16;
Byte=calib.mid(8+i*12,4);
byte16=(int16_t)Byte.toInt(&ok,16);
if (ok) generalSettings.calibSpanPos[i]=byte16;
for (int i = 0; i < ttlInputs; i++) {
if (Boards::isInputCalibrated(i)) {
Byte = calib.mid(i * 12, 4);
byte16 = (int16_t)Byte.toInt(&ok, 16);
if (ok) generalSettings.inputConfig[i].calib.mid = byte16;
Byte = calib.mid(4 + i * 12, 4);
byte16 = (int16_t)Byte.toInt(&ok, 16);
if (ok) generalSettings.inputConfig[i].calib.spanNeg = byte16;
Byte = calib.mid(8 + i * 12, 4);
byte16 = (int16_t)Byte.toInt(&ok, 16);
if (ok) generalSettings.inputConfig[i].calib.spanPos = byte16;
}
}
for (int i=0; i<4; i++) {
Byte=trainercalib.mid(i*4,4);
byte16=(int16_t)Byte.toInt(&ok,16);
if (ok) generalSettings.trainer.calib[i]=byte16;
for (int i = 0; i < ttlSticks; i++) {
Byte = trainercalib.mid(i * 4, 4);
byte16 = (int16_t)Byte.toInt(&ok, 16);
if (ok) generalSettings.trainer.calib[i] = byte16;
}
generalSettings.txCurrentCalibration=txCurrentCalibration;
generalSettings.txVoltageCalibration=txVoltageCalibration;
generalSettings.txCurrentCalibration = txCurrentCalibration;
generalSettings.txVoltageCalibration = txVoltageCalibration;
generalSettings.vBatWarn=vBatWarn;
if (getCurrentFirmware()->getCapability(HasBatMeterRange)) {
generalSettings.vBatMin = (int8_t) g.profile[profile_id].vBatMin();
generalSettings.vBatMax = (int8_t) g.profile[profile_id].vBatMax();
}
generalSettings.PPM_Multiplier=PPM_Multiplier;
generalSettings.PPM_Multiplier = PPM_Multiplier;
} else {
QMessageBox::critical(this, CPN_STR_TTL_WARNING, tr("Wrong data in profile, radio calibration was not retrieved"));
}
if (hwtypes.length()==numSwPots) {
if (hwtypes.length() == ttlSwitches + ttlInputs) {
QString Byte;
int16_t byte16;
QByteArray qba;
int16_t offset;
bool ok;
for (int i=0; i<CPN_MAX_STICKS; i++) {
qba = controlNames.mid(3*i,3).toLatin1();
strcpy(generalSettings.stickName[i], qba.data());
}
for (int i=0; i<getBoardCapability(board, Board::Switches); i++) {
for (int i = 0; i < ttlSwitches; i++) {
Byte = hwtypes.mid(i, 1);
byte16=(int16_t)Byte.toInt(&ok,16);
qba=controlNames.mid(3*(i+CPN_MAX_STICKS),3).toLatin1();
byte16 = (int16_t)Byte.toInt(&ok, 16);
qba = controlNames.mid(3 * i, 3).toLatin1();
if (ok) {
generalSettings.switchConfig[i]=byte16;
strcpy(generalSettings.switchName[i], qba.data());
generalSettings.switchConfig[i].type = (Board::SwitchType)byte16;
strcpy(generalSettings.switchConfig[i].name, qba.data());
}
}
offset = getBoardCapability(board, Board::Switches);
for (int i=0; i<getBoardCapability(board, Board::Pots); i++) {
Byte=hwtypes.mid(i+offset,1);
byte16=(int16_t)Byte.toInt(&ok,16);
qba=controlNames.mid(3*(i+CPN_MAX_STICKS+offset),3).toLatin1();
for (int i = 0; i < getBoardCapability(board, Board::Inputs); i++) {
Byte = hwtypes.mid(i + ttlSwitches, 1);
byte16 = (int16_t)Byte.toInt(&ok, 16);
qba = controlNames.mid(3 * (i + ttlSwitches), 3).toLatin1();
if (ok) {
generalSettings.potConfig[i]=byte16;
strcpy(generalSettings.potName[i], qba.data());
}
}
offset += getBoardCapability(board, Board::Pots);
for (int i=0; i<getBoardCapability(board, Board::Sliders); i++) {
Byte=hwtypes.mid(i+offset,1);
byte16=(int16_t)Byte.toInt(&ok,16);
qba=controlNames.mid(3*(i+CPN_MAX_STICKS+offset),3).toLatin1();
if (ok) {
generalSettings.sliderConfig[i]=byte16;
strcpy(generalSettings.sliderName[i], qba.data());
generalSettings.inputConfig[i].flexType = (Board::FlexType)byte16;
strcpy(generalSettings.inputConfig[i].name, qba.data());
}
}
} else {
@@ -215,36 +202,36 @@ void GeneralEdit::on_calretrieve_PB_clicked()
int8_t byte8;
QString chars;
bool ok;
byte8=(int8_t)DisplaySet.mid(0,2).toInt(&ok,16);
if (ok) generalSettings.optrexDisplay=(byte8==1 ? true : false);
byte8u=(uint8_t)DisplaySet.mid(2,2).toUInt(&ok,16);
if (ok) generalSettings.contrast=byte8u;
byte8u=(uint8_t)DisplaySet.mid(4,2).toUInt(&ok,16);
if (ok) generalSettings.backlightBright=byte8u;
byte8=(int8_t)BeeperSet.mid(0,2).toUInt(&ok,16);
byte8 = (int8_t)DisplaySet.mid(0,2).toInt(&ok, 16);
if (ok) generalSettings.optrexDisplay = (byte8 == 1 ? true : false);
byte8u = (uint8_t)DisplaySet.mid(2,2).toUInt(&ok, 16);
if (ok) generalSettings.contrast = byte8u;
byte8u = (uint8_t)DisplaySet.mid(4,2).toUInt(&ok, 16);
if (ok) generalSettings.backlightBright = byte8u;
byte8 = (int8_t)BeeperSet.mid(0,2).toUInt(&ok, 16);
if (ok) generalSettings.beeperMode = (GeneralSettings::BeeperMode)byte8;
byte8=(int8_t)BeeperSet.mid(2,2).toInt(&ok,16);
if (ok) generalSettings.beeperLength=byte8;
byte8=(int8_t)HapticSet.mid(0,2).toUInt(&ok,16);
if (ok) generalSettings.hapticMode=(GeneralSettings::BeeperMode)byte8;
byte8=(int8_t)HapticSet.mid(2,2).toInt(&ok,16);
if (ok) generalSettings.hapticStrength=byte8;
byte8=(int8_t)HapticSet.mid(4,2).toInt(&ok,16);
if (ok) generalSettings.hapticLength=byte8;
byte8u=(uint8_t)SpeakerSet.mid(0,2).toUInt(&ok,16);
if (ok) generalSettings.speakerMode=byte8u;
byte8u=(uint8_t)SpeakerSet.mid(2,2).toUInt(&ok,16);
if (ok) generalSettings.speakerPitch=byte8u;
byte8u=(uint8_t)SpeakerSet.mid(4,2).toUInt(&ok,16);
if (ok) generalSettings.speakerVolume=byte8u;
if (CountrySet.length()==6) {
byte8u=(uint8_t)CountrySet.mid(0,2).toUInt(&ok,16);
if (ok) generalSettings.countryCode=byte8u;
byte8u=(uint8_t)CountrySet.mid(2,2).toUInt(&ok,16);
if (ok) generalSettings.imperial=byte8u;
chars=CountrySet.mid(4,2);
generalSettings.ttsLanguage[0]=chars[0].toLatin1();
generalSettings.ttsLanguage[1]=chars[1].toLatin1();
byte8 = (int8_t)BeeperSet.mid(2,2).toInt(&ok, 16);
if (ok) generalSettings.beeperLength = byte8;
byte8 = (int8_t)HapticSet.mid(0,2).toUInt(&ok, 16);
if (ok) generalSettings.hapticMode = (GeneralSettings::BeeperMode)byte8;
byte8 = (int8_t)HapticSet.mid(2,2).toInt(&ok, 16);
if (ok) generalSettings.hapticStrength = byte8;
byte8 = (int8_t)HapticSet.mid(4,2).toInt(&ok, 16);
if (ok) generalSettings.hapticLength = byte8;
byte8u = (uint8_t)SpeakerSet.mid(0,2).toUInt(&ok, 16);
if (ok) generalSettings.speakerMode = byte8u;
byte8u = (uint8_t)SpeakerSet.mid(2,2).toUInt(&ok, 16);
if (ok) generalSettings.speakerPitch = byte8u;
byte8u = (uint8_t)SpeakerSet.mid(4,2).toUInt(&ok, 16);
if (ok) generalSettings.speakerVolume = byte8u;
if (CountrySet.length() == 6) {
byte8u = (uint8_t)CountrySet.mid(0,2).toUInt(&ok, 16);
if (ok) generalSettings.countryCode = byte8u;
byte8u = (uint8_t)CountrySet.mid(2,2).toUInt(&ok, 16);
if (ok) generalSettings.imperial = byte8u;
chars = CountrySet.mid(4,2);
generalSettings.ttsLanguage[0] = chars[0].toLatin1();
generalSettings.ttsLanguage[1] = chars[1].toLatin1();
}
}
else {
@@ -257,18 +244,18 @@ void GeneralEdit::on_calretrieve_PB_clicked()
void GeneralEdit::on_calstore_PB_clicked()
{
int profile_id=ui->profile_CB->itemData(ui->profile_CB->currentIndex()).toInt();
Board::Type board = getCurrentBoard();
int profile_id = ui->profile_CB->itemData(ui->profile_CB->currentIndex()).toInt();
QString name=g.profile[profile_id].name();
int potsnum=getBoardCapability(getCurrentBoard(), Board::Pots)+getBoardCapability(getCurrentBoard(), Board::Sliders);
QString name = g.profile[profile_id].name();
if (name.isEmpty()) {
ui->calstore_PB->setDisabled(true);
return;
}
else {
QString calib=g.profile[profile_id].stickPotCalib();
QString hwtypes=g.profile[profile_id].controlTypes();
QString controlNames=g.profile[profile_id].controlNames();
QString calib = g.profile[profile_id].stickPotCalib();
QString hwtypes = g.profile[profile_id].controlTypes();
QString controlNames = g.profile[profile_id].controlNames();
if (!(calib.isEmpty())) {
int ret = QMessageBox::question(this, CPN_STR_APP_NAME,
tr("Do you want to store calibration in %1 profile<br>overwriting existing calibration?").arg(name) ,
@@ -277,34 +264,34 @@ void GeneralEdit::on_calstore_PB_clicked()
return;
}
}
int ttlSticks = getBoardCapability(board, Board::Sticks);
int ttlInputs = getBoardCapability(board, Board::Inputs);
int ttlSwitches = getBoardCapability(board, Board::Switches);
calib.clear();
for (int i=0; i< (CPN_MAX_STICKS+potsnum); i++) {
calib.append(QString("%1").arg((uint16_t)generalSettings.calibMid[i], 4, 16, QChar('0')));
calib.append(QString("%1").arg((uint16_t)generalSettings.calibSpanNeg[i], 4, 16, QChar('0')));
calib.append(QString("%1").arg((uint16_t)generalSettings.calibSpanPos[i], 4, 16, QChar('0')));
for (int i = 0; i < ttlInputs; i++) {
if (Boards::isInputCalibrated(i)) {
calib.append(QString("%1").arg((uint16_t)generalSettings.inputConfig[i].calib.mid, 4, 16, QChar('0')));
calib.append(QString("%1").arg((uint16_t)generalSettings.inputConfig[i].calib.spanNeg, 4, 16, QChar('0')));
calib.append(QString("%1").arg((uint16_t)generalSettings.inputConfig[i].calib.spanPos, 4, 16, QChar('0')));
}
}
g.profile[profile_id].stickPotCalib( calib );
calib.clear();
for (int i=0; i< 4; i++) {
for (int i = 0; i < ttlSticks; i++) {
calib.append(QString("%1").arg((uint16_t)generalSettings.trainer.calib[i], 4, 16, QChar('0')));
}
g.profile[profile_id].trainerCalib( calib );
hwtypes.clear();
controlNames.clear();
for (int i=0; i<CPN_MAX_STICKS; i++) {
controlNames.append(QString("%1").arg(generalSettings.stickName[i], -3));
for (int i = 0; i < ttlSwitches; i++) {
hwtypes.append(QString("%1").arg((uint16_t)generalSettings.switchConfig[i].type, 1));
controlNames.append(QString("%1").arg(generalSettings.switchConfig[i].name, -3));
}
for (int i=0; i<getBoardCapability(getCurrentBoard(), Board::Switches); i++) {
hwtypes.append(QString("%1").arg((uint16_t)generalSettings.switchConfig[i], 1));
controlNames.append(QString("%1").arg(generalSettings.switchName[i], -3));
}
for (int i=0; i<getBoardCapability(getCurrentBoard(), Board::Pots); i++) {
hwtypes.append(QString("%1").arg((uint16_t)generalSettings.potConfig[i], 1));
controlNames.append(QString("%1").arg(generalSettings.potName[i], -3));
}
for (int i=0; i<getBoardCapability(getCurrentBoard(), Board::Sliders); i++) {
hwtypes.append(QString("%1").arg((uint16_t)generalSettings.sliderConfig[i], 1));
controlNames.append(QString("%1").arg(generalSettings.sliderName[i], -3));
for (int i = 0; i < ttlInputs; i++) {
hwtypes.append(QString("%1").arg((uint16_t)generalSettings.inputConfig[i].flexType, 1));
controlNames.append(QString("%1").arg(generalSettings.inputConfig[i].name, -3));
}
g.profile[profile_id].controlTypes( hwtypes );
g.profile[profile_id].controlNames( controlNames );
+159 -86
View File
@@ -26,60 +26,75 @@
#include "autocheckbox.h"
#include "autospinbox.h"
#include "autodoublespinbox.h"
#include "autobitmappedcombobox.h"
#include "autobitmappedcheckbox.h"
#include <QLabel>
#include <QGridLayout>
#include <QFrame>
constexpr char FIM_SWITCHTYPE2POS[] {"Switch Type 2 Pos"};
constexpr char FIM_SWITCHTYPE3POS[] {"Switch Type 3 Pos"};
constexpr char FIM_INTERNALMODULES[] {"Internal Modules"};
constexpr char FIM_AUX1SERIALMODES[] {"AUX1 Modes"};
constexpr char FIM_AUX2SERIALMODES[] {"AUX2 Modes"};
constexpr char FIM_VCPSERIALMODES[] {"VCP Modes"};
constexpr char FIM_SWITCHTYPENONE[] {"Switch Type None"};
constexpr char FIM_SWITCHTYPE2POS[] {"Switch Type 2 Pos"};
constexpr char FIM_SWITCHTYPE3POS[] {"Switch Type 3 Pos"};
constexpr char FIM_INTERNALMODULES[] {"Internal Modules"};
constexpr char FIM_AUX1SERIALMODES[] {"AUX1 Modes"};
constexpr char FIM_AUX2SERIALMODES[] {"AUX2 Modes"};
constexpr char FIM_VCPSERIALMODES[] {"VCP Modes"};
constexpr char FIM_FLEXSWITCHES[] {"Flex Switches"};
constexpr char FIM_FLEXTYPE_SWITCH[] {"Flex Type Switch"};
constexpr char FIM_FLEXTYPE_NOSWITCH[] {"Flex Type No Switch"};
class ExclusiveComboGroup: public QObject
{
static constexpr auto _role = Qt::UserRole + 500;
public:
ExclusiveComboGroup(QObject *parent, std::function<bool(const QVariant&)> filter) :
QObject(parent), filter(std::move(filter))
{
}
QList<QComboBox*> combos;
std::function<bool(const QVariant&)> filter;
typedef QList<QComboBox*> ComboBoxes;
public:
ExclusiveComboGroup(QObject *parent, std::function<bool(const QVariant&)> filter) :
QObject(parent), filter(std::move(filter))
{
}
ComboBoxes* getComboBoxes()
{
return &combos;
}
void addCombo(QComboBox *comboBox)
{
connect(comboBox, QOverload<int>::of(&QComboBox::activated),
[=](int index) { this->handleActivated(comboBox, index); });
combos.append(comboBox);
}
void addCombo(QComboBox *comboBox)
{
connect(comboBox, QOverload<int>::of(&QComboBox::activated),
[=](int index) { this->handleActivated(comboBox, index); });
combos.append(comboBox);
}
void handleActivated(QComboBox* target, int index) {
auto data = target->itemData(index);
auto targetidx = combos.indexOf(target);
for (auto combo : combos) {
if (target == combo) continue;
auto view = dynamic_cast<QListView*>(combo->view());
Q_ASSERT(view);
void handleActivated(QComboBox* target, int index) {
auto data = target->itemData(index);
auto targetidx = combos.indexOf(target);
for (auto combo : combos) {
if (target == combo) continue;
auto view = dynamic_cast<QListView*>(combo->view());
Q_ASSERT(view);
auto previous = combo->findData(targetidx, _role);
if (previous >= 0) {
view->setRowHidden(previous, false);
combo->setItemData(previous, QVariant(), _role);
}
if (!filter(data)) {
auto idx = combo->findData(data);
if (idx >= 0) {
view->setRowHidden(idx, true);
combo->setItemData(idx, targetidx, _role);
auto previous = combo->findData(targetidx, _role);
if (previous >= 0) {
view->setRowHidden(previous, false);
combo->setItemData(previous, QVariant(), _role);
}
if (!filter(data)) {
auto idx = combo->findData(data);
if (idx >= 0) {
view->setRowHidden(idx, true);
combo->setItemData(idx, targetidx, _role);
}
}
}
}
}
private:
static constexpr auto _role = Qt::UserRole + 500;
ComboBoxes combos;
std::function<bool(const QVariant&)> filter;
};
HardwarePanel::HardwarePanel(QWidget * parent, GeneralSettings & generalSettings, Firmware * firmware, CompoundItemModelFactory * sharedItemModels):
@@ -88,13 +103,17 @@ HardwarePanel::HardwarePanel(QWidget * parent, GeneralSettings & generalSettings
editorItemModels(sharedItemModels),
serialPortUSBVCP(nullptr),
params(new QList<QWidget *>),
row(0)
row(0),
exclFlexSwitchesGroup(nullptr)
{
editorItemModels->registerItemModel(Boards::potTypeItemModel());
editorItemModels->registerItemModel(Boards::sliderTypeItemModel());
int id = editorItemModels->registerItemModel(Boards::switchTypeItemModel());
tabFilteredModels = new FilteredItemModelFactory();
int id = editorItemModels->registerItemModel(Boards::flexTypeItemModel());
tabFilteredModels->registerItemModel(new FilteredItemModel(editorItemModels->getItemModel(id), Board::FlexTypeContextSwitch), FIM_FLEXTYPE_SWITCH);
tabFilteredModels->registerItemModel(new FilteredItemModel(editorItemModels->getItemModel(id), Board::FlexTypeContextNoSwitch), FIM_FLEXTYPE_NOSWITCH);
id = editorItemModels->registerItemModel(Boards::switchTypeItemModel());
tabFilteredModels->registerItemModel(new FilteredItemModel(editorItemModels->getItemModel(id), Board::SwitchTypeContextNone), FIM_SWITCHTYPENONE);
tabFilteredModels->registerItemModel(new FilteredItemModel(editorItemModels->getItemModel(id), Board::SwitchTypeContext2Pos), FIM_SWITCHTYPE2POS);
tabFilteredModels->registerItemModel(new FilteredItemModel(editorItemModels->getItemModel(id), Board::SwitchTypeContext3Pos), FIM_SWITCHTYPE3POS);
@@ -110,13 +129,15 @@ HardwarePanel::HardwarePanel(QWidget * parent, GeneralSettings & generalSettings
id = editorItemModels->registerItemModel(ModuleData::internalModuleItemModel());
tabFilteredModels->registerItemModel(new FilteredItemModel(editorItemModels->getItemModel(id)), FIM_INTERNALMODULES);
editorItemModels->addItemModel(AbstractItemModel::IMID_FlexSwitches);
grid = new QGridLayout(this);
int count;
addSection(tr("Sticks"));
addSection(tr("Axis"));
count = Boards::getCapability(board, Board::Sticks);
if (count) {
if (count > 0) {
for (int i = 0; i < count; i++) {
addStick(i);
}
@@ -131,28 +152,33 @@ HardwarePanel::HardwarePanel(QWidget * parent, GeneralSettings & generalSettings
addParams();
}
count = Boards::getCapability(board, Board::Pots);
count -= firmware->getCapability(HasFlySkyGimbals) ? 2 : 0;
count = Boards::getCapability(board, Board::Inputs);
if (count > 0) {
addSection(tr("Pots"));
for (int i = 0; i < count; i++) {
addPot(i);
}
}
count = Boards::getCapability(board, Board::Sliders);
if (count) {
addSection(tr("Sliders"));
for (int i = 0; i < count; i++) {
addSlider(i);
for (int i = Boards::getCapability(board, Board::Sticks); i < count; i++) {
if (Boards::isInputConfigurable(i, board))
addFlex(i);
}
}
count = Boards::getCapability(board, Board::Switches);
if (count) {
// All values except -1 (None) are mutually exclusive
exclFlexSwitchesGroup = new ExclusiveComboGroup(
this, [=](const QVariant &value) { return value == -1; });
addSection(tr("Switches"));
for (int i = 0; i < count; i++) {
addSwitch(i);
for (int i = 0; i < count && i < CPN_MAX_SWITCHES; i++) {
if (Boards::isSwitchConfigurable(i, board))
addSwitch(i);
}
// if multiple combo boxes force update to lists
if (exclFlexSwitchesGroup->getComboBoxes()->count() > 1) {
QComboBox *cb = exclFlexSwitchesGroup->getComboBoxes()->at(0);
exclFlexSwitchesGroup->handleActivated(cb, cb->currentIndex());
}
}
@@ -383,62 +409,109 @@ void HardwarePanel::on_internalModuleChanged()
void HardwarePanel::addStick(int index)
{
addLabel(Boards::getAnalogInputName(board, index));
GeneralSettings::InputConfig &config = generalSettings.inputConfig[index];
addLabel(Boards::getInputName(index, board));
AutoLineEdit *name = new AutoLineEdit(this);
name->setField(generalSettings.stickName[index], HARDWARE_NAME_LEN, this);
name->setField(config.name, HARDWARE_NAME_LEN, this);
params->append(name);
addParams();
}
void HardwarePanel::addPot(int index)
void HardwarePanel::addFlex(int index)
{
addLabel(Boards::getAnalogInputName(board, Boards::getCapability(board, Board::Sticks) + index));
GeneralSettings::InputConfig &config = generalSettings.inputConfig[index];
addLabel(Boards::getInputName(index, board));
AutoLineEdit *name = new AutoLineEdit(this);
name->setField(generalSettings.potName[index], HARDWARE_NAME_LEN, this);
name->setField(config.name, HARDWARE_NAME_LEN, this);
params->append(name);
AutoComboBox *type = new AutoComboBox(this);
type->setModel(editorItemModels->getItemModel(AIM_BOARDS_POT_TYPE));
type->setField(generalSettings.potConfig[index], this);
setFlexTypeModel(type, index);
int & flexType = (int &)config.flexType;
type->setField(flexType, this);
connect(type, &AutoComboBox::currentDataChanged, [=] (int val) {
AbstractItemModel *mdl = editorItemModels->getItemModel(AbstractItemModel::IMID_FlexSwitches);
if (mdl)
mdl->update(AbstractItemModel::IMUE_FunctionSwitches);
emit InputFlexTypeChanged();
});
connect(this, &HardwarePanel::InputFlexTypeChanged, [=]() { setFlexTypeModel(type, index); });
params->append(type);
AutoCheckBox *inverted = new AutoCheckBox(this);
inverted->setField(config.inverted, this);
params->append(inverted);
addParams();
}
void HardwarePanel::addSlider(int index)
void HardwarePanel::setFlexTypeModel(AutoComboBox * cb, int index)
{
addLabel(Boards::getAnalogInputName(board, Boards::getCapability(board, Board::Sticks) +
Boards::getCapability(board, Board::Pots) + index));
AutoLineEdit *name = new AutoLineEdit(this);
name->setField(generalSettings.sliderName[index], HARDWARE_NAME_LEN, this);
params->append(name);
AutoComboBox *type = new AutoComboBox(this);
type->setModel(editorItemModels->getItemModel(AIM_BOARDS_SLIDER_TYPE));
type->setField(generalSettings.sliderConfig[index], this);
params->append(type);
addParams();
cb->setModel((generalSettings.inputConfig[index].flexType == Board::FLEX_SWITCH || generalSettings.unassignedInputFlexSwitches()) ?
tabFilteredModels->getItemModel(FIM_FLEXTYPE_SWITCH) :
tabFilteredModels->getItemModel(FIM_FLEXTYPE_NOSWITCH));
}
void HardwarePanel::addSwitch(int index)
{
addLabel(Boards::getSwitchInfo(board, index).name);
GeneralSettings::SwitchConfig &config = generalSettings.switchConfig[index];
Board::SwitchInfo info = Boards::getSwitchInfo(index);
addLabel(Boards::getSwitchName(index));
AutoLineEdit *name = new AutoLineEdit(this);
name->setField(generalSettings.switchName[index], HARDWARE_NAME_LEN, this);
name->setField(config.name, HARDWARE_NAME_LEN, this);
params->append(name);
AutoComboBox *input = nullptr;
if (generalSettings.isSwitchFlex(index)) {
int id = tabFilteredModels->registerItemModel(
new FilteredItemModel(editorItemModels->getItemModel(AbstractItemModel::IMID_FlexSwitches)),
QString("%1 %2").arg(FIM_FLEXSWITCHES).arg(index));
input = new AutoComboBox(this);
input->setModel(tabFilteredModels->getItemModel(id));
input->setField(config.inputIdx, this);
exclFlexSwitchesGroup->addCombo(input);
params->append(input);
}
AutoComboBox *type = new AutoComboBox(this);
Board::SwitchInfo switchInfo = Boards::getSwitchInfo(board, index);
type->setModel(switchInfo.config < Board::SWITCH_3POS ? tabFilteredModels->getItemModel(FIM_SWITCHTYPE2POS) :
tabFilteredModels->getItemModel(FIM_SWITCHTYPE3POS));
type->setField(generalSettings.switchConfig[index], this);
type->setSizeAdjustPolicy(QComboBox::AdjustToContents);
if (generalSettings.isSwitchFlex(index))
if (config.type == Board::SWITCH_NOT_AVAILABLE)
type->setModel(tabFilteredModels->getItemModel(FIM_SWITCHTYPENONE));
else
type->setModel(tabFilteredModels->getItemModel(FIM_SWITCHTYPE3POS));
else if (info.type < Board::SWITCH_3POS)
type->setModel(tabFilteredModels->getItemModel(FIM_SWITCHTYPE2POS));
else
type->setModel(tabFilteredModels->getItemModel(FIM_SWITCHTYPE3POS));
int & swtype = (int &)config.type;
type->setField(swtype, this);
params->append(type);
if (generalSettings.isSwitchFlex(index)) {
connect(input, &AutoComboBox::currentDataChanged, [=] (int val) {
if (val < 0) {
generalSettings.switchConfig[index].type = Board::SWITCH_NOT_AVAILABLE;
type->setModel(tabFilteredModels->getItemModel(FIM_SWITCHTYPENONE));
type->updateValue();
}
else
type->setModel(tabFilteredModels->getItemModel(FIM_SWITCHTYPE3POS));
});
}
addParams();
}
+5 -2
View File
@@ -26,6 +26,7 @@ class CompoundItemModelFactory;
class FilteredItemModelFactory;
class QGridLayout;
class AutoComboBox;
class ExclusiveComboGroup;
class HardwarePanel : public GeneralPanel
{
@@ -37,6 +38,7 @@ class HardwarePanel : public GeneralPanel
signals:
void internalModuleChanged();
void InputFlexTypeChanged();
private slots:
void on_internalModuleChanged();
@@ -55,15 +57,16 @@ class HardwarePanel : public GeneralPanel
AutoComboBox *antennaMode;
QList<QWidget *> *params;
int row;
ExclusiveComboGroup *exclFlexSwitchesGroup;
void addStick(int index);
void addPot(int index);
void addSlider(int index);
void addFlex(int index);
void addSwitch(int index);
void addLabel(QString text);
void addLine();
void addParams();
void addSection(QString text);
void setFlexTypeModel(AutoComboBox * cb, int index);
void updateSerialPortUSBVCP();
};
+3 -4
View File
@@ -35,8 +35,7 @@ TrainerPanel::TrainerPanel(QWidget * parent, GeneralSettings & generalSettings,
int modeid = editorItemModels->registerItemModel(TrainerMix::modeItemModel());
int srcid = editorItemModels->registerItemModel(TrainerMix::srcItemModel());
Board::Type board = getCurrentBoard();
const int stickcnt = Boards::getCapability(board, Board::Sticks);
const int stickcnt = Boards::getCapability(getCurrentBoard(), Board::Sticks);
const FieldRange weightrng = TrainerMix::getWeightRange();
@@ -50,9 +49,9 @@ TrainerPanel::TrainerPanel(QWidget * parent, GeneralSettings & generalSettings,
addLabel(tr("Weight"), row, 2);
addLabel(tr("Source"), row++, 3);
for (int i = 0; i < 4; i++, row++) { // TODO constant
for (int i = 0; i < CPN_MAX_STICKS; i++, row++) {
col = 0;
addLabel(Boards::getAnalogInputName(board, i), row, col++);
addLabel(Boards::getInputName(i), row, col++);
AutoComboBox *mode = new AutoComboBox(this);
mode->setModel(editorItemModels->getItemModel(modeid));