refactor(cpn): Support JSON radio hardware definitions (#4406)
This commit is contained in:
@@ -82,8 +82,8 @@ void joystickDialog::loadGrid()
|
||||
}
|
||||
|
||||
memset(sliders, 0, sizeof(sliders));
|
||||
memset(sticks, 0, sizeof(sliders));
|
||||
memset(invert, 0, sizeof(sliders));
|
||||
memset(sticks, 0, sizeof(sticks));
|
||||
memset(invert, 0, sizeof(invert));
|
||||
|
||||
int row = 0;
|
||||
int col = 0;
|
||||
@@ -151,29 +151,19 @@ void joystickDialog::populateSourceCombo(QComboBox * cb)
|
||||
Board::Type m_board = getCurrentBoard();
|
||||
GeneralSettings radioSettings = GeneralSettings();
|
||||
|
||||
int ttlSticks = Boards::getCapability(m_board, Board::Sticks);
|
||||
int ttlKnobs = Boards::getCapability(m_board, Board::Pots);
|
||||
int ttlFaders = Boards::getCapability(m_board, Board::Sliders);
|
||||
int ttlInputs = Boards::getCapability(m_board, Board::Inputs);
|
||||
|
||||
cb->clear();
|
||||
cb->addItem(tr("Not Assigned"), -1);
|
||||
|
||||
for (i=0; i < ttlSticks; ++i) {
|
||||
wname = Boards::getAxisName(i);
|
||||
cb->addItem(wname, i);
|
||||
}
|
||||
|
||||
for (i = 0; i < ttlKnobs; ++i) {
|
||||
if (radioSettings.isPotAvailable(i)) {
|
||||
wname = RawSource(RawSourceType::SOURCE_TYPE_STICK, ttlSticks + i).toString(nullptr, &radioSettings);
|
||||
cb->addItem(wname, i + ttlSticks);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < ttlFaders; ++i) {
|
||||
if (radioSettings.isSliderAvailable(i)) {
|
||||
wname = RawSource(RawSourceType::SOURCE_TYPE_STICK, ttlSticks + ttlKnobs + i).toString(nullptr, &radioSettings);
|
||||
cb->addItem(wname, i + ttlSticks + ttlKnobs);
|
||||
for (i = 0; i < ttlInputs; ++i) {
|
||||
if (radioSettings.isInputAvailable(i) &&
|
||||
(radioSettings.isInputStick(i) || radioSettings.isInputPot(i) || radioSettings.isInputSlider(i))) {
|
||||
if (radioSettings.isInputStick(i))
|
||||
wname = Boards::getAxisName(i);
|
||||
else
|
||||
wname = RawSource(RawSourceType::SOURCE_TYPE_STICK, i).toString(nullptr, &radioSettings);
|
||||
cb->addItem(wname, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -192,12 +182,12 @@ void joystickDialog::populateButtonCombo(QComboBox * cb)
|
||||
cb->clear();
|
||||
cb->addItem(tr("Not Assigned"), -1);
|
||||
|
||||
Board::SwitchType swcfg;
|
||||
Board::SwitchType swtype;
|
||||
for (i = 0; i < ttlSwitches; ++i) {
|
||||
if (radioSettings.switchConfig[i] != Board::SWITCH_NOT_AVAILABLE) {
|
||||
swcfg = Board::SwitchType(radioSettings.switchConfig[i]);
|
||||
if (radioSettings.switchConfig[i].type != Board::SWITCH_NOT_AVAILABLE) {
|
||||
swtype = Board::SwitchType(radioSettings.switchConfig[i].type);
|
||||
wname = RawSource(RawSourceType::SOURCE_TYPE_SWITCH, i).toString(nullptr, &radioSettings);
|
||||
if (swcfg == Board::SWITCH_3POS) {
|
||||
if (swtype == Board::SWITCH_3POS) {
|
||||
cb->addItem(wname + CPN_STR_SW_INDICATOR_UP, i | JS_BUTTON_3POS_UP);
|
||||
cb->addItem(wname + CPN_STR_SW_INDICATOR_DN, i | JS_BUTTON_3POS_DN);
|
||||
} else {
|
||||
|
||||
@@ -575,8 +575,7 @@ void SimulatorWidget::setupRadioWidgets()
|
||||
int i, midpos;
|
||||
const int ttlSticks = Boards::getCapability(m_board, Board::Sticks);
|
||||
const int ttlSwitches = Boards::getCapability(m_board, Board::Switches);
|
||||
const int ttlKnobs = Boards::getCapability(m_board, Board::Pots);
|
||||
const int ttlFaders = Boards::getCapability(m_board, Board::Sliders);
|
||||
const int ttlInputs = Boards::getCapability(m_board, Board::Inputs);
|
||||
const int extraTrims = Boards::getCapability(m_board, Board::NumTrims) - ttlSticks;
|
||||
|
||||
// First clear out any existing widgets.
|
||||
@@ -604,11 +603,11 @@ void SimulatorWidget::setupRadioWidgets()
|
||||
// switches
|
||||
Board::SwitchType swcfg;
|
||||
for (i = 0; i < ttlSwitches; ++i) {
|
||||
if (radioSettings.switchConfig[i] == Board::SWITCH_NOT_AVAILABLE)
|
||||
if (!radioSettings.isSwitchAvailable(i) || Boards::isSwitchFunc(i))
|
||||
continue;
|
||||
|
||||
swcfg = Board::SwitchType(radioSettings.switchConfig[i]);
|
||||
wname = RawSource(RawSourceType::SOURCE_TYPE_SWITCH, i).toString(nullptr, &radioSettings);
|
||||
swcfg = Board::SwitchType(radioSettings.switchConfig[i].type);
|
||||
wname = RawSource(RawSourceType::SOURCE_TYPE_SWITCH, i).toString(nullptr, &radioSettings, Board::BOARD_UNKNOWN, false);
|
||||
RadioSwitchWidget * sw = new RadioSwitchWidget(swcfg, wname, -1, ui->radioWidgetsHT);
|
||||
sw->setIndex(i);
|
||||
ui->radioWidgetsHTLayout->addWidget(sw);
|
||||
@@ -619,12 +618,12 @@ void SimulatorWidget::setupRadioWidgets()
|
||||
midpos = (int)floorf(m_radioWidgets.size() / 2.0f);
|
||||
|
||||
// pots in middle of switches
|
||||
for (i = 0; i < ttlKnobs; ++i) {
|
||||
if (!radioSettings.isPotAvailable(i))
|
||||
for (i = 0; i < ttlInputs; ++i) {
|
||||
if (!(radioSettings.isInputAvailable(i) && radioSettings.isInputPot(i)))
|
||||
continue;
|
||||
|
||||
wname = RawSource(RawSourceType::SOURCE_TYPE_STICK, ttlSticks + i).toString(nullptr, &radioSettings);
|
||||
RadioKnobWidget * pot = new RadioKnobWidget(Board::PotType(radioSettings.potConfig[i]), wname, 0, ui->radioWidgetsHT);
|
||||
wname = RawSource(RawSourceType::SOURCE_TYPE_STICK, i).toString(nullptr, &radioSettings, Board::BOARD_UNKNOWN, false);
|
||||
RadioKnobWidget * pot = new RadioKnobWidget(radioSettings.inputConfig[i].flexType, wname, 0, ui->radioWidgetsHT);
|
||||
pot->setIndex(i);
|
||||
ui->radioWidgetsHTLayout->insertWidget(midpos++, pot);
|
||||
m_radioWidgets.append(pot);
|
||||
@@ -632,15 +631,15 @@ void SimulatorWidget::setupRadioWidgets()
|
||||
|
||||
// faders between sticks
|
||||
int fc = extraTrims / 2; // leave space for any extra trims
|
||||
for (i = 0; i < ttlFaders; ++i) {
|
||||
if (!radioSettings.isSliderAvailable(i))
|
||||
|
||||
for (i = 0; i < ttlInputs; ++i) {
|
||||
if (!(radioSettings.isInputAvailable(i) && radioSettings.isInputSlider(i)))
|
||||
continue;
|
||||
|
||||
wname = RawSource(RawSourceType::SOURCE_TYPE_STICK, ttlSticks + ttlKnobs + i).toString(nullptr, &radioSettings);
|
||||
wname = RawSource(RawSourceType::SOURCE_TYPE_STICK, i).toString(nullptr, &radioSettings, Board::BOARD_UNKNOWN, false);
|
||||
RadioFaderWidget * sl = new RadioFaderWidget(wname, 0, ui->radioWidgetsVC);
|
||||
sl->setIndex(i);
|
||||
ui->VCGridLayout->addWidget(sl, 0, fc++, 1, 1);
|
||||
|
||||
m_radioWidgets.append(sl);
|
||||
}
|
||||
|
||||
@@ -648,7 +647,7 @@ void SimulatorWidget::setupRadioWidgets()
|
||||
int tc = 0;
|
||||
int tridx = ttlSticks;
|
||||
for (i = 0; i < extraTrims; i += 1, tridx += 1) {
|
||||
wname = RawSource(RawSourceType::SOURCE_TYPE_TRIM, tridx).toString(nullptr, &radioSettings);
|
||||
wname = RawSource(RawSourceType::SOURCE_TYPE_TRIM, tridx).toString(nullptr, &radioSettings, Board::BOARD_UNKNOWN, false);
|
||||
wname = wname.left(1) % wname.right(1);
|
||||
RadioTrimWidget * tw = new RadioTrimWidget(Qt::Vertical, ui->radioWidgetsVC);
|
||||
tw->setIndices(tridx, tridx * 2, tridx * 2 + 1);
|
||||
@@ -814,17 +813,25 @@ void SimulatorWidget::onPhaseChanged(qint32 phase, const QString & name)
|
||||
setWindowTitle(windowName + tr(" - Flight Mode %1 (#%2)").arg(name).arg(phase));
|
||||
}
|
||||
|
||||
void SimulatorWidget::onRadioWidgetValueChange(const RadioWidget::RadioWidgetType type, const int index, int value)
|
||||
void SimulatorWidget::onRadioWidgetValueChange(const RadioWidget::RadioWidgetType type, int index, int value)
|
||||
{
|
||||
//qDebug() << type << index << value;
|
||||
if (!simulator || index < 0)
|
||||
return;
|
||||
|
||||
SimulatorInterface::InputSourceType inpType = SimulatorInterface::INPUT_SRC_NONE;
|
||||
GeneralSettings::SwitchConfig *cfg = nullptr;
|
||||
|
||||
switch (type) {
|
||||
case RadioWidget::RADIO_WIDGET_SWITCH :
|
||||
inpType = SimulatorInterface::INPUT_SRC_SWITCH;
|
||||
cfg = &radioSettings.switchConfig[index];
|
||||
if (cfg->inputIdx != SWITCH_INPUTINDEX_NONE) {
|
||||
inpType = SimulatorInterface::INPUT_SRC_STICK;
|
||||
index = cfg->inputIdx;
|
||||
value = value * 1024;
|
||||
}
|
||||
else
|
||||
inpType = SimulatorInterface::INPUT_SRC_SWITCH;
|
||||
break;
|
||||
|
||||
case RadioWidget::RADIO_WIDGET_KNOB :
|
||||
|
||||
@@ -110,7 +110,7 @@ class SimulatorWidget : public QWidget
|
||||
void onSimulatorHeartbeat(qint32 loops, qint64 timestamp);
|
||||
void onPhaseChanged(qint32 phase, const QString & name);
|
||||
void onSimulatorError(const QString & error);
|
||||
void onRadioWidgetValueChange(const RadioWidget::RadioWidgetType type, const int index, int value);
|
||||
void onRadioWidgetValueChange(const RadioWidget::RadioWidgetType type, int index, int value);
|
||||
void onjoystickAxisValueChanged(int axis, int value);
|
||||
void onjoystickButtonValueChanged(int button, bool state);
|
||||
|
||||
|
||||
@@ -18,8 +18,7 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef _RADIOKNOBWIDGET_H_
|
||||
#define _RADIOKNOBWIDGET_H_
|
||||
#pragma once
|
||||
|
||||
#include "radiowidget.h"
|
||||
#include "boards.h"
|
||||
@@ -38,23 +37,23 @@ class RadioKnobWidget : public RadioWidget
|
||||
|
||||
public:
|
||||
|
||||
explicit RadioKnobWidget(Board::PotType type = Board::POT_WITH_DETENT, QWidget * parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags()) :
|
||||
explicit RadioKnobWidget(Board::FlexType type = Board::FLEX_POT_CENTER, QWidget * parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags()) :
|
||||
RadioWidget(parent, f)
|
||||
{
|
||||
init(type);
|
||||
}
|
||||
|
||||
explicit RadioKnobWidget(Board::PotType type, const QString & labelText, int value = 0, QWidget * parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags()) :
|
||||
explicit RadioKnobWidget(Board::FlexType type, const QString & labelText, int value = 0, QWidget * parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags()) :
|
||||
RadioWidget(labelText, value, parent, f)
|
||||
{
|
||||
init(type);
|
||||
}
|
||||
|
||||
void init(Board::PotType potType)
|
||||
void init(Board::FlexType potType)
|
||||
{
|
||||
m_type = RADIO_WIDGET_KNOB;
|
||||
|
||||
m_stepSize = (potType == Board::POT_MULTIPOS_SWITCH) ? 2048 / 5 : 1;
|
||||
m_stepSize = (potType == Board::FLEX_MULTIPOS) ? 2048 / 5 : 1;
|
||||
|
||||
m_toolTip = tr("<p>Value (input): <b>%1</b></p>");
|
||||
if (m_stepSize == 1)
|
||||
@@ -88,7 +87,7 @@ class RadioKnobWidget : public RadioWidget
|
||||
}
|
||||
|
||||
m_dial->setValue(m_value);
|
||||
|
||||
|
||||
connect(m_dial, &QDial::valueChanged, this, &RadioKnobWidget::setValueFromDial);
|
||||
connect(this, &RadioWidget::valueChanged, m_dial, &QDial::setValue);
|
||||
|
||||
@@ -157,6 +156,3 @@ class RadioKnobWidget : public RadioWidget
|
||||
QString m_toolTip;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // _RADIOKNOBWIDGET_H_
|
||||
|
||||
Reference in New Issue
Block a user