feat: New advanced joystick mode on radio, improvements to Companion and Simulator joystick support (#3111)
* Allow switches on the connected radio to control switches in the simulator via the joystick interface. * Merge configurable radio joystick interface from banyaszg. * Add two more 'axis' channels to companion. * Fix 6POS from USB joystick to simulator. * Reduce data size. * Fix build error on B&W radios. * Add 'Companion' button mode to work with the button logic in the Companion app. * Build Companion joystick setup layout at runtime. Change #define names for simulator joystick. Allow 15 axes and 32 buttons. Initial support for trim sliders. * Remove custom joystick button type for companion - use 3 buttons per switch in companion to control simulator switch state. * Fix joystick constructor calls parameters. Connect some radio joystick trims to simulator widgets. * Restore 'companion' button type to reduce number of buttons needed. Make trims work via buttons in USB joystick. * Connect joystick trim buttons to simulator widgets. * Use companion source names for trims. * Add encode / decode of usb joystick custom settings to Companion. * Convert to lvgl layouts. Update language files. * Fix generated YAML storage files. * Fix initialisation error when editing button channel. Cleanup code. * Fix rebase. * Fix refresh of joystick channel list view after editing an entry. Companion joystick config window uses two columns. * Fix vertical joystick inversion bug. Change stick axis labels. --------- Co-authored-by: Phil Mitchell <phil.a.mitchell@gmail.com>
This commit is contained in:
@@ -273,7 +273,7 @@ void AppPreferencesDialog::initSettings()
|
||||
if (ui->joystickChkB->isChecked()) {
|
||||
QStringList joystickNames;
|
||||
joystickNames << tr("No joysticks found");
|
||||
joystick = new Joystick(0,false,0,0);
|
||||
joystick = new Joystick(0,0,false,0);
|
||||
ui->joystickcalButton->setDisabled(true);
|
||||
ui->joystickCB->setDisabled(true);
|
||||
|
||||
@@ -591,7 +591,7 @@ void AppPreferencesDialog::on_joystickChkB_clicked() {
|
||||
if (ui->joystickChkB->isChecked()) {
|
||||
QStringList joystickNames;
|
||||
joystickNames << tr("No joysticks found");
|
||||
joystick = new Joystick(0,false,0,0);
|
||||
joystick = new Joystick(0,0,false,0);
|
||||
ui->joystickcalButton->setDisabled(true);
|
||||
ui->joystickCB->setDisabled(true);
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ set(firmwares_SRCS
|
||||
edgetx/yaml_customfunctiondata.cpp
|
||||
edgetx/yaml_sensordata.cpp
|
||||
edgetx/yaml_screendata.cpp
|
||||
edgetx/yaml_usbjoystickdata.cpp
|
||||
datahelpers.cpp
|
||||
customisation_data.cpp
|
||||
)
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "yaml_customfunctiondata.h"
|
||||
#include "yaml_sensordata.h"
|
||||
#include "yaml_screendata.h"
|
||||
#include "yaml_usbjoystickdata.h"
|
||||
|
||||
#include "modeldata.h"
|
||||
#include "output_data.h"
|
||||
@@ -79,6 +80,12 @@ static const YamlLookupTable jitterFilterLut = {
|
||||
{ 2, "ON" },
|
||||
};
|
||||
|
||||
static const YamlLookupTable usbJoystickIfModeLut = {
|
||||
{ 0, "JOYSTICK" },
|
||||
{ 1, "GAMEPAD" },
|
||||
{ 2, "MULTIAXIS" },
|
||||
};
|
||||
|
||||
struct YamlTrim {
|
||||
int mode = 0;
|
||||
int ref = 0;
|
||||
@@ -1008,6 +1015,16 @@ Node convert<ModelData>::encode(const ModelData& rhs)
|
||||
}
|
||||
}
|
||||
|
||||
// Custom USB joytsick mapping
|
||||
node["usbJoystickExtMode"] = rhs.usbJoystickExtMode;
|
||||
node["usbJoystickIfMode"] = usbJoystickIfModeLut << rhs.usbJoystickIfMode;
|
||||
node["usbJoystickCircularCut"] = rhs.usbJoystickCircularCut;
|
||||
for (int i = 0; i < CPN_USBJ_MAX_JOYSTICK_CHANNELS; i++) {
|
||||
if (rhs.usbJoystickCh[i].mode > 0) {
|
||||
node["usbJoystickCh"][std::to_string(i)] = rhs.usbJoystickCh[i];
|
||||
}
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
@@ -1194,6 +1211,12 @@ bool convert<ModelData>::decode(const Node& node, ModelData& rhs)
|
||||
node["functionSwitchLogicalState"] >> rhs.functionSwitchLogicalState;
|
||||
node["switchNames"] >> rhs.functionSwitchNames;
|
||||
|
||||
// Custom USB joytsick mapping
|
||||
node["usbJoystickExtMode"] >> rhs.usbJoystickExtMode;
|
||||
node["usbJoystickIfMode"] >> usbJoystickIfModeLut >> rhs.usbJoystickIfMode;
|
||||
node["usbJoystickCircularCut"] >> rhs.usbJoystickCircularCut;
|
||||
node["usbJoystickCh"] >> rhs.usbJoystickCh;
|
||||
|
||||
// preferably perform conversions here to avoid cluttering the field decodes
|
||||
|
||||
if (SemanticVersion(QString(rhs.semver)) < SemanticVersion("2.8.0")) {
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "yaml_usbjoystickdata.h"
|
||||
#include "generalsettings.h"
|
||||
#include "modeldata.h"
|
||||
|
||||
const YamlLookupTable usbJoystickChMode = {
|
||||
{0, "CH_NONE"},
|
||||
{1, "CH_BUTTON"},
|
||||
{2, "CH_AXIS"},
|
||||
{3, "CH_SIM"},
|
||||
};
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
|
||||
Node convert<USBJoystickChData>::encode(const USBJoystickChData& rhs)
|
||||
{
|
||||
Node node;
|
||||
node["mode"] = usbJoystickChMode << rhs.mode;
|
||||
node["inversion"] = rhs.inversion;
|
||||
node["param"] = rhs.param;
|
||||
node["btn_num"] = rhs.btn_num;
|
||||
node["switch_npos"] = rhs.switch_npos;
|
||||
return node;
|
||||
}
|
||||
|
||||
bool convert<USBJoystickChData>::decode(const Node& node, USBJoystickChData& rhs)
|
||||
{
|
||||
node["mode"] >> usbJoystickChMode >> rhs.mode;
|
||||
node["inversion"] >> rhs.inversion;
|
||||
node["param"] >> rhs.param;
|
||||
node["btn_num"] >> rhs.btn_num;
|
||||
node["switch_npos"] >> rhs.switch_npos;
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace YAML
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "yaml_ops.h"
|
||||
#include "generalsettings.h"
|
||||
|
||||
extern const YamlLookupTable usbJoystickChMode;
|
||||
|
||||
class USBJoystickChData;
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
template <>
|
||||
struct convert<USBJoystickChData> {
|
||||
static Node encode(const USBJoystickChData& rhs);
|
||||
static bool decode(const Node& node, USBJoystickChData& rhs);
|
||||
};
|
||||
} // namespace YAML
|
||||
@@ -90,6 +90,19 @@ enum TrainerMode {
|
||||
#define INPUT_NAME_LEN 4
|
||||
#define CPN_MAX_BITMAP_LEN 14
|
||||
|
||||
#define CPN_USBJ_MAX_JOYSTICK_CHANNELS 26
|
||||
|
||||
class USBJoystickChData {
|
||||
public:
|
||||
USBJoystickChData() { clear(); }
|
||||
unsigned int mode;
|
||||
unsigned int inversion;
|
||||
unsigned int param;
|
||||
unsigned int btn_num;
|
||||
unsigned int switch_npos;
|
||||
void clear() { memset(reinterpret_cast<void *>(this), 0, sizeof(USBJoystickChData)); }
|
||||
};
|
||||
|
||||
class ModelData {
|
||||
Q_DECLARE_TR_FUNCTIONS(ModelData)
|
||||
|
||||
@@ -201,6 +214,12 @@ class ModelData {
|
||||
unsigned int functionSwitchLogicalState;
|
||||
char functionSwitchNames[CPN_MAX_FUNCTION_SWITCHES][HARDWARE_NAME_LEN + 1];
|
||||
|
||||
// Custom USB joytsick mapping
|
||||
unsigned int usbJoystickExtMode;
|
||||
unsigned int usbJoystickIfMode;
|
||||
unsigned int usbJoystickCircularCut;
|
||||
USBJoystickChData usbJoystickCh[CPN_USBJ_MAX_JOYSTICK_CHANNELS];
|
||||
|
||||
void clear();
|
||||
bool isEmpty() const;
|
||||
void setDefaultInputs(const GeneralSettings & settings);
|
||||
|
||||
@@ -116,7 +116,7 @@ qreal Node::getY()
|
||||
if(scene())
|
||||
{
|
||||
QRectF rect = scene()->sceneRect();
|
||||
return 1+((y()-rect.bottom())*2/rect.height());
|
||||
return ((rect.bottom()-y())*2/rect.height())-1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -126,7 +126,7 @@ void Node::setY(qreal newY)
|
||||
if(scene())
|
||||
{
|
||||
QRectF rect = scene()->sceneRect();
|
||||
QGraphicsObject::setY(rect.top() + (newY+1) * rect.height()/2);
|
||||
QGraphicsObject::setY(rect.top() + (1-newY) * rect.height()/2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -63,6 +63,9 @@ bool Joystick::open(int stick)
|
||||
numHats = SDL_JoystickNumHats(joystick);
|
||||
numTrackballs = SDL_JoystickNumBalls(joystick);
|
||||
joystickTimer.start(eventTimeout);
|
||||
for (int i = 0; i < numButtons; i += 1) {
|
||||
buttons[i] = -1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
@@ -109,9 +112,9 @@ void Joystick::processEvents()
|
||||
axisRepeatTimers[i].restart();
|
||||
}
|
||||
}
|
||||
else {
|
||||
emit axisValueChanged(i, 0);
|
||||
}
|
||||
// else {
|
||||
// emit axisValueChanged(i, 0);
|
||||
// }
|
||||
}
|
||||
for (i = 0; i < numButtons; i++) {
|
||||
Uint8 changed = SDL_JoystickGetButton(joystick, i);
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
#include "joystickdialog.h"
|
||||
#include "ui_joystickdialog.h"
|
||||
#include "eeprominterface.h"
|
||||
|
||||
#include "boards.h"
|
||||
#include "constants.h"
|
||||
@@ -33,40 +34,71 @@ joystickDialog::joystickDialog(QWidget *parent, int stick) :
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
int jscaltmp[8][3] = {
|
||||
{32767, 0, -32767},
|
||||
{32767, 0, -32767},
|
||||
{32767, 0, -32767},
|
||||
{32767, 0, -32767},
|
||||
{32767, 0, -32767},
|
||||
{32767, 0, -32767},
|
||||
{32767, 0, -32767},
|
||||
{32767, 0, -32767}
|
||||
};
|
||||
memcpy(jscal, jscaltmp, sizeof (jscal));
|
||||
int i;
|
||||
char s[20];
|
||||
|
||||
foreach(QComboBox *cb, findChildren<QComboBox *>(QRegularExpression("jsmapCB_[0-9]+"))) {
|
||||
populateSourceCombo(cb);
|
||||
sticks[cb->property("channel").toUInt()] = cb;
|
||||
}
|
||||
foreach(QCheckBox *ib, findChildren<QCheckBox *>(QRegularExpression("ChInv_[0-9]+"))) {
|
||||
invert[ib->property("channel").toUInt()] = ib;
|
||||
}
|
||||
foreach(QSlider *sl, findChildren<QSlider *>(QRegularExpression("Ch_[0-9]+"))) {
|
||||
sliders[sl->property("channel").toUInt()] = sl;
|
||||
for (i = 0; i < MAX_JS_AXES; i += 1) {
|
||||
jscal[i][0] = 32767;
|
||||
jscal[i][1] = 0;
|
||||
jscal[i][2] = -32767;
|
||||
}
|
||||
|
||||
for (int i = 0; i < MAX_JOYSTICKS; ++i) {
|
||||
if (!g.joystick[i].existsOnDisk())
|
||||
continue;
|
||||
QGridLayout *grid = findChild<QGridLayout*>("gridLayout");
|
||||
int row = 0;
|
||||
int col = 0;
|
||||
if (grid) {
|
||||
for (i = 0; i < MAX_JS_AXES; i += 1, row += 1) {
|
||||
col = (i & 1) * 4;
|
||||
sprintf(s, "Ch%d", i + 1);
|
||||
QLabel *l = new QLabel(s);
|
||||
grid->addWidget(l, row/2, col+0, 1, 1);
|
||||
QSlider *s = new QSlider(Qt::Horizontal);
|
||||
s->setMinimum(-32767);
|
||||
s->setMaximum(32767);
|
||||
sliders[row] = s;
|
||||
grid->addWidget(s, row/2, col+1, 1, 1);
|
||||
QCheckBox *c = new QCheckBox("");
|
||||
invert[row] = c;
|
||||
grid->addWidget(c, row/2, col+2, 1, 1);
|
||||
QComboBox *d = new QComboBox();
|
||||
populateSourceCombo(d);
|
||||
sticks[row] = d;
|
||||
grid->addWidget(d, row/2, col+3, 1, 1);
|
||||
}
|
||||
if (row & 1) row += 1;
|
||||
for (i = 0; i < MAX_JS_BUTTONS; i += 1, row += 1) {
|
||||
col = (i & 1) * 4;
|
||||
sprintf(s, "Btn%d", i + 1);
|
||||
QLabel *l = new QLabel(s);
|
||||
grid->addWidget(l, row/2, col+0, 1, 1);
|
||||
QSlider *s = new QSlider(Qt::Horizontal);
|
||||
s->setMinimum(0);
|
||||
s->setMaximum(1);
|
||||
sliders[row] = s;
|
||||
grid->addWidget(s, row/2, col+1, 1, 1);
|
||||
QComboBox *d = new QComboBox();
|
||||
populateButtonCombo(d);
|
||||
sticks[row] = d;
|
||||
grid->addWidget(d, row/2, col+3, 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
jscal[i][0] = g.joystick[i].stick_min();
|
||||
jscal[i][1] = g.joystick[i].stick_med();
|
||||
jscal[i][2] = g.joystick[i].stick_max();
|
||||
sliders[i]->setMinimum(jscal[i][0]);
|
||||
sliders[i]->setMaximum(jscal[i][2]);
|
||||
invert[i]->setChecked(g.joystick[i].stick_inv());
|
||||
sticks[i]->setCurrentIndex(sticks[i]->findData(g.joystick[i].stick_axe()));
|
||||
for (int i = 0; i < MAX_JS_AXES; ++i) {
|
||||
if (g.joystick[i].existsOnDisk()) {
|
||||
jscal[i][0] = g.joystick[i].stick_min();
|
||||
jscal[i][1] = g.joystick[i].stick_med();
|
||||
jscal[i][2] = g.joystick[i].stick_max();
|
||||
sliders[i]->setMinimum(jscal[i][0]);
|
||||
sliders[i]->setMaximum(jscal[i][2]);
|
||||
invert[i]->setChecked(g.joystick[i].stick_inv());
|
||||
sticks[i]->setCurrentIndex(sticks[i]->findData(g.joystick[i].stick_axe()));
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < MAX_JS_BUTTONS; ++i) {
|
||||
if (g.jsButton[i].existsOnDisk()) {
|
||||
sticks[i+MAX_JS_AXES]->setCurrentIndex(sticks[i+MAX_JS_AXES]->findData(g.jsButton[i].button_idx()));
|
||||
}
|
||||
}
|
||||
|
||||
ui->backButton->setEnabled(false);
|
||||
@@ -86,6 +118,7 @@ joystickDialog::joystickDialog(QWidget *parent, int stick) :
|
||||
loadStep();
|
||||
|
||||
connect(joystick, SIGNAL(axisValueChanged(int, int)), this, SLOT(onjoystickAxisValueChanged(int, int)));
|
||||
connect(joystick, SIGNAL(buttonValueChanged(int, bool)), this, SLOT(onjoystickButtonValueChanged(int, bool)));
|
||||
connect(ui->joystickCB, SIGNAL(currentIndexChanged(int)), this, SLOT(joystickOpen(int)));
|
||||
connect(ui->joystickChkB, SIGNAL(toggled(bool)), this, SLOT(joystickSetEnabled(bool)));
|
||||
}
|
||||
@@ -98,13 +131,75 @@ joystickDialog::~joystickDialog()
|
||||
void joystickDialog::populateSourceCombo(QComboBox * cb)
|
||||
{
|
||||
int i;
|
||||
QString wname;
|
||||
|
||||
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);
|
||||
|
||||
cb->clear();
|
||||
cb->addItem(tr("Not Assigned"), -1);
|
||||
for (i=0; i < Board::STICK_AXIS_COUNT; ++i) {
|
||||
cb->addItem(Boards::getAxisName(i) % tr(" Stick"), i);
|
||||
|
||||
for (i=0; i < ttlSticks; ++i) {
|
||||
wname = Boards::getAxisName(i);
|
||||
cb->addItem(wname, i);
|
||||
}
|
||||
for (; i < Board::STICK_AXIS_COUNT + CPN_MAX_POTS + CPN_MAX_SLIDERS; ++i) {
|
||||
cb->addItem(tr("Knob/Slider %1").arg(i - Board::STICK_AXIS_COUNT + 1), 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void joystickDialog::populateButtonCombo(QComboBox * cb)
|
||||
{
|
||||
int i;
|
||||
QString wname;
|
||||
|
||||
Board::Type m_board = getCurrentBoard();
|
||||
GeneralSettings radioSettings = GeneralSettings();
|
||||
|
||||
int ttlSwitches = Boards::getCapability(m_board, Board::Switches);
|
||||
int ttlTrims = Boards::getCapability(m_board, Board::NumTrims);
|
||||
|
||||
cb->clear();
|
||||
cb->addItem(tr("Not Assigned"), -1);
|
||||
|
||||
Board::SwitchType swcfg;
|
||||
for (i = 0; i < ttlSwitches; ++i) {
|
||||
if (radioSettings.switchConfig[i] != Board::SWITCH_NOT_AVAILABLE) {
|
||||
swcfg = Board::SwitchType(radioSettings.switchConfig[i]);
|
||||
wname = RawSource(RawSourceType::SOURCE_TYPE_SWITCH, i).toString(nullptr, &radioSettings);
|
||||
if (swcfg == 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 {
|
||||
cb->addItem(wname, i | JS_BUTTON_TOGGLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < ttlTrims; i += 1) {
|
||||
wname = RawSource(RawSourceType::SOURCE_TYPE_TRIM, i).toString(nullptr, &radioSettings);
|
||||
if ((i == 0) || (i == 3)) {
|
||||
cb->addItem(wname + " Left", i + ttlSwitches | JS_BUTTON_3POS_DN);
|
||||
cb->addItem(wname + " Right", i + ttlSwitches | JS_BUTTON_3POS_UP);
|
||||
} else {
|
||||
cb->addItem(wname + " Down", i + ttlSwitches | JS_BUTTON_3POS_DN);
|
||||
cb->addItem(wname + " Up", i + ttlSwitches | JS_BUTTON_3POS_UP);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +210,7 @@ bool joystickDialog::loadJoysticks(int stick)
|
||||
|
||||
ui->joystickCB->clear();
|
||||
joystickNames << tr("No joysticks found");
|
||||
joystick = new Joystick(0, false, 0, 0);
|
||||
joystick = new Joystick(0, 0, false, 0);
|
||||
if ( joystick ) {
|
||||
if ( joystick->joystickNames.count() > 0 ) {
|
||||
joystickNames = joystick->joystickNames;
|
||||
@@ -140,10 +235,10 @@ void joystickDialog::joystickOpen(int stick)
|
||||
|
||||
joystick = new Joystick(this, 1, false, 0);
|
||||
if (joystick && joystick->open(stick)) {
|
||||
numAxes = std::min(joystick->numAxes, MAX_JOYSTICKS);
|
||||
numAxes = std::min(joystick->numAxes, MAX_JS_AXES);
|
||||
for (int j=0; j<numAxes; j++) {
|
||||
joystick->sensitivities[j] = 0;
|
||||
joystick->deadzones[j]=20;
|
||||
joystick->deadzones[j] = 20;
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -161,7 +256,7 @@ void joystickDialog::joystickSetEnabled(bool enable)
|
||||
|
||||
void joystickDialog::onjoystickAxisValueChanged(int axis, int value)
|
||||
{
|
||||
if (axis >= MAX_JOYSTICKS)
|
||||
if (axis >= MAX_JS_AXES)
|
||||
return;
|
||||
|
||||
if (started) {
|
||||
@@ -177,6 +272,14 @@ void joystickDialog::onjoystickAxisValueChanged(int axis, int value)
|
||||
sliders[axis]->setValue(value);
|
||||
}
|
||||
|
||||
void joystickDialog::onjoystickButtonValueChanged(int button, bool state)
|
||||
{
|
||||
if (button >= MAX_JS_BUTTONS)
|
||||
return;
|
||||
|
||||
sliders[button + MAX_JS_AXES]->setValue(state);
|
||||
}
|
||||
|
||||
void joystickDialog::loadStep()
|
||||
{
|
||||
switch (step) {
|
||||
@@ -241,8 +344,6 @@ void joystickDialog::on_cancelButton_clicked()
|
||||
|
||||
void joystickDialog::on_okButton_clicked()
|
||||
{
|
||||
int stick;
|
||||
|
||||
g.jsSupport(ui->joystickChkB->isChecked());
|
||||
g.jsCtrl(ui->joystickCB->currentIndex());
|
||||
|
||||
@@ -261,8 +362,8 @@ void joystickDialog::on_okButton_clicked()
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < MAX_JOYSTICKS; ++i) {
|
||||
stick = sticks[i]->currentData().toInt();
|
||||
for (int i = 0; i < MAX_JS_AXES; ++i) {
|
||||
auto stick = sticks[i]->currentData().toInt();
|
||||
if (stick < 0) {
|
||||
g.joystick[i].stick_axe(-1);
|
||||
}
|
||||
@@ -276,5 +377,16 @@ void joystickDialog::on_okButton_clicked()
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < MAX_JS_BUTTONS; ++i) {
|
||||
auto btn = sticks[i+MAX_JS_AXES]->currentData().toInt();
|
||||
if (btn < 0) {
|
||||
g.jsButton[i].button_idx(-1);
|
||||
}
|
||||
else {
|
||||
g.jsButton[i].button_idx(btn);
|
||||
qDebug() << "joystick button mapping " << sticks[i+MAX_JS_AXES]->objectName() << "stick:" << i << "idx:" << btn;
|
||||
}
|
||||
}
|
||||
|
||||
this->accept();
|
||||
}
|
||||
|
||||
@@ -29,6 +29,14 @@ class QCheckBox;
|
||||
class QComboBox;
|
||||
class QSlider;
|
||||
|
||||
enum JSButtonFlag {
|
||||
JS_BUTTON_TOGGLE = 0x1000,
|
||||
JS_BUTTON_3POS_UP = 0x2000,
|
||||
JS_BUTTON_3POS_DN = 0x4000,
|
||||
JS_BUTTON_TYPE_MASK = 0xF000,
|
||||
JS_BUTTON_SWITCH_MASK = 0x1F
|
||||
};
|
||||
|
||||
namespace Ui {
|
||||
class joystickDialog;
|
||||
}
|
||||
@@ -44,20 +52,22 @@ class joystickDialog : public QDialog
|
||||
|
||||
private:
|
||||
Ui::joystickDialog *ui;
|
||||
int jscal[MAX_JOYSTICKS][3];
|
||||
QCheckBox * invert[MAX_JOYSTICKS];
|
||||
QComboBox * sticks[MAX_JOYSTICKS];
|
||||
QSlider * sliders[MAX_JOYSTICKS];
|
||||
int jscal[MAX_JS_AXES][3];
|
||||
QCheckBox * invert[MAX_JS_AXES];
|
||||
QComboBox * sticks[MAX_JS_AXES + MAX_JS_BUTTONS];
|
||||
QSlider * sliders[MAX_JS_AXES + MAX_JS_BUTTONS];
|
||||
int step;
|
||||
int numAxes;
|
||||
bool started;
|
||||
|
||||
private slots:
|
||||
void populateSourceCombo(QComboBox * cb);
|
||||
void populateButtonCombo(QComboBox * cb);
|
||||
bool loadJoysticks(int stick = -1);
|
||||
void joystickOpen(int stick);
|
||||
void joystickSetEnabled(bool enable);
|
||||
void onjoystickAxisValueChanged(int axis, int value);
|
||||
void onjoystickButtonValueChanged(int button, bool state);
|
||||
void loadStep();
|
||||
void on_backButton_clicked();
|
||||
void on_nextButton_clicked();
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>554</width>
|
||||
<height>351</height>
|
||||
<width>709</width>
|
||||
<height>195</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
@@ -20,495 +20,23 @@
|
||||
<string>Configure Joystick</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="0" column="2" rowspan="4">
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QWidget" name="calibrationWidget" native="true">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>640</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Ch2</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QSlider" name="Ch_3">
|
||||
<property name="minimum">
|
||||
<number>-32767</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>32676</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="invertedAppearance">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="invertedControls">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="tickPosition">
|
||||
<enum>QSlider::NoTicks</enum>
|
||||
</property>
|
||||
<property name="tickInterval">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="channel" stdset="0">
|
||||
<number>2</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="3">
|
||||
<widget class="QComboBox" name="jsmapCB_2">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="channel" stdset="0">
|
||||
<number>1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Ch1</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="3">
|
||||
<widget class="QComboBox" name="jsmapCB_3">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="channel" stdset="0">
|
||||
<number>2</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QSlider" name="Ch_2">
|
||||
<property name="minimum">
|
||||
<number>-32767</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>32676</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="invertedAppearance">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="invertedControls">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="tickPosition">
|
||||
<enum>QSlider::NoTicks</enum>
|
||||
</property>
|
||||
<property name="tickInterval">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="channel" stdset="0">
|
||||
<number>1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="QComboBox" name="jsmapCB_1">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="channel" stdset="0">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Ch4</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QSlider" name="Ch_5">
|
||||
<property name="minimum">
|
||||
<number>-32767</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>32676</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="invertedAppearance">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="invertedControls">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="tickPosition">
|
||||
<enum>QSlider::NoTicks</enum>
|
||||
</property>
|
||||
<property name="tickInterval">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="channel" stdset="0">
|
||||
<number>4</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string>Ch6</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Ch3</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="3">
|
||||
<widget class="QComboBox" name="jsmapCB_5">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="channel" stdset="0">
|
||||
<number>4</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QSlider" name="Ch_4">
|
||||
<property name="minimum">
|
||||
<number>-32767</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>32676</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="invertedAppearance">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="invertedControls">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="tickPosition">
|
||||
<enum>QSlider::NoTicks</enum>
|
||||
</property>
|
||||
<property name="tickInterval">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="channel" stdset="0">
|
||||
<number>3</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="3">
|
||||
<widget class="QComboBox" name="jsmapCB_4">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="channel" stdset="0">
|
||||
<number>3</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QSlider" name="Ch_6">
|
||||
<property name="minimum">
|
||||
<number>-32767</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>32676</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="invertedAppearance">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="invertedControls">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="tickPosition">
|
||||
<enum>QSlider::NoTicks</enum>
|
||||
</property>
|
||||
<property name="tickInterval">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="channel" stdset="0">
|
||||
<number>5</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="3">
|
||||
<widget class="QComboBox" name="jsmapCB_6">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="channel" stdset="0">
|
||||
<number>5</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Ch5</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="text">
|
||||
<string>Ch7</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<widget class="QSlider" name="Ch_7">
|
||||
<property name="minimum">
|
||||
<number>-32767</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>32676</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="invertedAppearance">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="invertedControls">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="tickPosition">
|
||||
<enum>QSlider::NoTicks</enum>
|
||||
</property>
|
||||
<property name="tickInterval">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="channel" stdset="0">
|
||||
<number>6</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="3">
|
||||
<widget class="QComboBox" name="jsmapCB_7">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="channel" stdset="0">
|
||||
<number>6</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<widget class="QLabel" name="label_8">
|
||||
<property name="text">
|
||||
<string>Ch8</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="1">
|
||||
<widget class="QSlider" name="Ch_8">
|
||||
<property name="minimum">
|
||||
<number>-32767</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>32676</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="invertedAppearance">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="invertedControls">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="tickPosition">
|
||||
<enum>QSlider::NoTicks</enum>
|
||||
</property>
|
||||
<property name="tickInterval">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="channel" stdset="0">
|
||||
<number>7</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="3">
|
||||
<widget class="QComboBox" name="jsmapCB_8">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="channel" stdset="0">
|
||||
<number>7</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QSlider" name="Ch_1">
|
||||
<property name="minimum">
|
||||
<number>-32767</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>32676</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="invertedAppearance">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="invertedControls">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="tickPosition">
|
||||
<enum>QSlider::NoTicks</enum>
|
||||
</property>
|
||||
<property name="tickInterval">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="channel" stdset="0">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QCheckBox" name="ChInv_1">
|
||||
<property name="text">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<property name="channel" stdset="0">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QCheckBox" name="ChInv_2">
|
||||
<property name="text">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<property name="channel" stdset="0">
|
||||
<number>1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QCheckBox" name="ChInv_3">
|
||||
<property name="text">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<property name="channel" stdset="0">
|
||||
<number>2</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="2">
|
||||
<widget class="QCheckBox" name="ChInv_4">
|
||||
<property name="text">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<property name="channel" stdset="0">
|
||||
<number>3</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="2">
|
||||
<widget class="QCheckBox" name="ChInv_5">
|
||||
<property name="text">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<property name="channel" stdset="0">
|
||||
<number>4</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="2">
|
||||
<widget class="QCheckBox" name="ChInv_6">
|
||||
<property name="text">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<property name="channel" stdset="0">
|
||||
<number>5</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="2">
|
||||
<widget class="QCheckBox" name="ChInv_7">
|
||||
<property name="text">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<property name="channel" stdset="0">
|
||||
<number>6</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="2">
|
||||
<widget class="QCheckBox" name="ChInv_8">
|
||||
<property name="text">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<property name="channel" stdset="0">
|
||||
<number>7</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
<layout class="QGridLayout" name="gridLayout"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="howtoLabel">
|
||||
@@ -544,6 +72,19 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2" rowspan="4">
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>1</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
@@ -587,7 +128,7 @@
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>198</width>
|
||||
<width>360</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
@@ -647,7 +188,7 @@
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<width>1</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
@@ -661,7 +202,7 @@
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>20</height>
|
||||
<height>1</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
#include "simulatorwidget.h"
|
||||
#include "ui_simulatorwidget.h"
|
||||
|
||||
#include "appdata.h"
|
||||
#include "appdebugmessagehandler.h"
|
||||
#include "radiofaderwidget.h"
|
||||
#include "radiokeywidget.h"
|
||||
@@ -619,7 +618,6 @@ void SimulatorWidget::setupRadioWidgets()
|
||||
RadioKnobWidget * pot = new RadioKnobWidget(Board::PotType(radioSettings.potConfig[i]), wname, 0, ui->radioWidgetsHT);
|
||||
pot->setIndex(i);
|
||||
ui->radioWidgetsHTLayout->insertWidget(midpos++, pot);
|
||||
|
||||
m_radioWidgets.append(pot);
|
||||
}
|
||||
|
||||
@@ -661,6 +659,7 @@ void SimulatorWidget::setupRadioWidgets()
|
||||
foreach (RadioWidget * rw, m_radioWidgets) {
|
||||
connect(rw, &RadioWidget::valueChange, this, &SimulatorWidget::onRadioWidgetValueChange);
|
||||
connect(this, &SimulatorWidget::widgetValueChange, rw, &RadioWidget::setValueQual);
|
||||
connect(this, &SimulatorWidget::widgetValueAdjust, rw, &RadioWidget::chgValueQual);
|
||||
connect(this, &SimulatorWidget::widgetStateChange, rw, &RadioWidget::setStateData);
|
||||
}
|
||||
|
||||
@@ -673,21 +672,28 @@ void SimulatorWidget::setupJoysticks()
|
||||
|
||||
if (g.jsSupport() && g.jsCtrl() > -1) {
|
||||
if (!joystick)
|
||||
joystick = new Joystick(this);
|
||||
joystick = new Joystick(this, SDL_JOYSTICK_DEFAULT_EVENT_TIMEOUT, false, SDL_JOYSTICK_DEFAULT_AUTOREPEAT_DELAY);
|
||||
else
|
||||
joystick->close();
|
||||
|
||||
if (joystick && joystick->open(g.jsCtrl())) {
|
||||
int numAxes = std::min(joystick->numAxes, MAX_JOYSTICKS);
|
||||
int numAxes = std::min(joystick->numAxes, MAX_JS_AXES);
|
||||
for (int j=0; j<numAxes; j++) {
|
||||
joystick->sensitivities[j] = 0;
|
||||
joystick->deadzones[j] = 0;
|
||||
}
|
||||
connect(joystick, &Joystick::axisValueChanged, this, &SimulatorWidget::onjoystickAxisValueChanged);
|
||||
if (vJoyLeft)
|
||||
connect(joystick, &Joystick::buttonValueChanged, this, &SimulatorWidget::onjoystickButtonValueChanged);
|
||||
if (vJoyLeft) {
|
||||
connect(this, &SimulatorWidget::stickValueChange, vJoyLeft, &VirtualJoystickWidget::setStickAxisValue);
|
||||
if (vJoyRight)
|
||||
connect(this, &SimulatorWidget::widgetValueAdjust, vJoyLeft->horizontalTrim(), &RadioWidget::chgValueQual);
|
||||
connect(this, &SimulatorWidget::widgetValueAdjust, vJoyLeft->verticalTrim(), &RadioWidget::chgValueQual);
|
||||
}
|
||||
if (vJoyRight) {
|
||||
connect(this, &SimulatorWidget::stickValueChange, vJoyRight, &VirtualJoystickWidget::setStickAxisValue);
|
||||
connect(this, &SimulatorWidget::widgetValueAdjust, vJoyRight->horizontalTrim(), &RadioWidget::chgValueQual);
|
||||
connect(this, &SimulatorWidget::widgetValueAdjust, vJoyRight->verticalTrim(), &RadioWidget::chgValueQual);
|
||||
}
|
||||
joysticksEnabled = true;
|
||||
}
|
||||
else {
|
||||
@@ -858,7 +864,7 @@ void SimulatorWidget::onjoystickAxisValueChanged(int axis, int value)
|
||||
static const int ttlFaders = Boards::getCapability(m_board, Board::Sliders);
|
||||
static const int valueRange = 1024;
|
||||
|
||||
if (!joystick || axis >= MAX_JOYSTICKS)
|
||||
if (!joystick || axis >= MAX_JS_AXES)
|
||||
return;
|
||||
|
||||
int dlta;
|
||||
@@ -885,11 +891,58 @@ void SimulatorWidget::onjoystickAxisValueChanged(int axis, int value)
|
||||
}
|
||||
else {
|
||||
stick -= ttlSticks;
|
||||
if (stick < ttlKnobs)
|
||||
if (stick < ttlKnobs) {
|
||||
GeneralSettings radioSettings = GeneralSettings();
|
||||
if (Board::PotType(radioSettings.potConfig[stick]) == Board::POT_MULTIPOS_SWITCH)
|
||||
stickval += 1024;
|
||||
emit widgetValueChange(RadioWidget::RADIO_WIDGET_KNOB, stick, stickval);
|
||||
else
|
||||
emit widgetValueChange(RadioWidget::RADIO_WIDGET_FADER, stick - ttlKnobs, stickval);
|
||||
} else {
|
||||
stick -= ttlKnobs;
|
||||
emit widgetValueChange(RadioWidget::RADIO_WIDGET_FADER, stick, stickval);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void SimulatorWidget::onjoystickButtonValueChanged(int button, bool state)
|
||||
{
|
||||
#ifdef JOYSTICKS
|
||||
|
||||
if (!joystick || button >= MAX_JS_BUTTONS)
|
||||
return;
|
||||
|
||||
int ttlSwitches = Boards::getCapability(m_board, Board::Switches);
|
||||
|
||||
int btn = g.jsButton[button].button_idx();
|
||||
|
||||
if (g.jsButton[button].button_inv())
|
||||
state = !state;
|
||||
|
||||
int swtch = btn & JS_BUTTON_SWITCH_MASK;
|
||||
|
||||
if (swtch < ttlSwitches) {
|
||||
if (btn & JS_BUTTON_3POS_DN) {
|
||||
// 3POS Down
|
||||
if (state || (switchDirection[swtch] == 0) || (switchDirection[swtch] == (btn & JS_BUTTON_TYPE_MASK))) {
|
||||
emit widgetValueChange(RadioWidget::RADIO_WIDGET_SWITCH, swtch, state ? 1 : 0);
|
||||
switchDirection[swtch] = (btn & JS_BUTTON_TYPE_MASK);
|
||||
}
|
||||
} else if (btn & JS_BUTTON_3POS_UP) {
|
||||
// 3POS Up
|
||||
if (state || (switchDirection[swtch] == 0) || (switchDirection[swtch] == (btn & JS_BUTTON_TYPE_MASK))) {
|
||||
emit widgetValueChange(RadioWidget::RADIO_WIDGET_SWITCH, swtch, state ? -1 : 0);
|
||||
switchDirection[swtch] = (btn & JS_BUTTON_TYPE_MASK);
|
||||
}
|
||||
} else if (btn & JS_BUTTON_TOGGLE) {
|
||||
// Toggle or momentary
|
||||
emit widgetValueChange(RadioWidget::RADIO_WIDGET_SWITCH, swtch, state ? 1 : - 1);
|
||||
}
|
||||
} else {
|
||||
// Trim
|
||||
swtch -= ttlSwitches;
|
||||
int offset = (btn & JS_BUTTON_3POS_DN) ? -1 : 1;
|
||||
emit widgetValueAdjust(RadioWidget::RADIO_WIDGET_TRIM, swtch, offset, state);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#ifndef _SIMULATORWIDGET_H_
|
||||
#define _SIMULATORWIDGET_H_
|
||||
|
||||
#include "appdata.h"
|
||||
#include "constants.h"
|
||||
#include "helpers.h"
|
||||
#include "radiodata.h"
|
||||
@@ -88,6 +89,7 @@ class SimulatorWidget : public QWidget
|
||||
void stickValueChange(int axis, int value);
|
||||
void stickModeChange(const unsigned mode);
|
||||
void widgetValueChange(const RadioWidget::RadioWidgetType type, const int index, const int value);
|
||||
void widgetValueAdjust(const RadioWidget::RadioWidgetType type, const int index, const int offset, const bool state);
|
||||
void widgetStateChange(const RadioWidget::RadioWidgetState & state);
|
||||
void inputValueChange(int type, quint8 index, qint16 value);
|
||||
void simulatorSetData(const QByteArray & data);
|
||||
@@ -110,6 +112,7 @@ class SimulatorWidget : public QWidget
|
||||
void onSimulatorError(const QString & error);
|
||||
void onRadioWidgetValueChange(const RadioWidget::RadioWidgetType type, const int index, int value);
|
||||
void onjoystickAxisValueChanged(int axis, int value);
|
||||
void onjoystickButtonValueChanged(int button, bool state);
|
||||
|
||||
void setRadioProfileId(int value);
|
||||
void setupRadioWidgets();
|
||||
@@ -145,6 +148,7 @@ class SimulatorWidget : public QWidget
|
||||
|
||||
#ifdef JOYSTICKS
|
||||
Joystick * joystick = nullptr;
|
||||
int switchDirection[MAX_JS_BUTTONS];
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ class RadioTrimWidget : public RadioWidget
|
||||
setValue(value);
|
||||
}
|
||||
|
||||
void setValue(const int & value)
|
||||
void setValue(const int & value) override
|
||||
{
|
||||
if (sender() && qobject_cast<SliderWidget *>(sender())) {
|
||||
RadioWidget::setValue(value);
|
||||
@@ -75,6 +75,12 @@ class RadioTrimWidget : public RadioWidget
|
||||
}
|
||||
}
|
||||
|
||||
void chgValueQual(const RadioWidgetType & type, const int & index, const int offset, const bool state) override {
|
||||
if (type == m_type && index == m_index) {
|
||||
emit valueChange(m_type, (offset < 0) ? m_btnDecIndex : m_btnIncIndex, state ? RADIO_TRIM_BTN_ON : RADIO_TRIM_BTN_OFF);
|
||||
}
|
||||
}
|
||||
|
||||
protected slots:
|
||||
|
||||
void init(Qt::Orientation orientation)
|
||||
|
||||
@@ -88,6 +88,7 @@ class RadioWidget : public QWidget
|
||||
virtual void setType(const RadioWidgetType & type);
|
||||
virtual void setValue(const int & value);
|
||||
virtual void setValueQual(const RadioWidgetType & type, const int & index, const int & value);
|
||||
virtual void chgValueQual(const RadioWidgetType & type, const int & index, const int offset, const bool state) {}
|
||||
virtual void setFlags(const quint16 & flags);
|
||||
virtual void setShowLabel(const bool show);
|
||||
virtual void setLabelText(const QString & labelText, bool showLabel = true);
|
||||
|
||||
@@ -323,7 +323,7 @@ void VirtualJoystickWidget::onNodeXChanged()
|
||||
|
||||
void VirtualJoystickWidget::onNodeYChanged()
|
||||
{
|
||||
emit valueChange(RadioWidget::RADIO_WIDGET_STICK, m_yIndex, int(-m_stickScale * getStickY()));
|
||||
emit valueChange(RadioWidget::RADIO_WIDGET_STICK, m_yIndex, int(m_stickScale * getStickY()));
|
||||
updateNodeValueLabels();
|
||||
}
|
||||
|
||||
@@ -564,9 +564,9 @@ void VirtualJoystickWidget::onButtonChange(bool checked)
|
||||
void VirtualJoystickWidget::updateNodeValueLabels()
|
||||
{
|
||||
if (nodeLabelX)
|
||||
nodeLabelX->setText(QString("%1").arg(node->getX() * 100.0f, 2, 'f', 0));
|
||||
nodeLabelX->setText(QString("%1").arg(getStickX() * 100.0f, 2, 'f', 0));
|
||||
if (nodeLabelY)
|
||||
nodeLabelY->setText(QString("%1").arg(node->getY() * -100.0f, 2, 'f', 0));
|
||||
nodeLabelY->setText(QString("%1").arg(getStickY() * 100.0f, 2, 'f', 0));
|
||||
}
|
||||
|
||||
void VirtualJoystickWidget::onGsMouseEvent(QGraphicsSceneMouseEvent * event)
|
||||
|
||||
@@ -61,6 +61,9 @@ class VirtualJoystickWidget : public QWidget
|
||||
int getStickScale() const;
|
||||
void setStickScale(int stickScale);
|
||||
|
||||
const RadioTrimWidget *horizontalTrim() { return hTrimWidget; }
|
||||
const RadioTrimWidget *verticalTrim() { return vTrimWidget; }
|
||||
|
||||
public slots:
|
||||
void setStickX(qreal x);
|
||||
void setStickY(qreal y);
|
||||
|
||||
@@ -256,6 +256,16 @@ bool JStickData::existsOnDisk()
|
||||
return (m_settings.value(settingsPath() % stick_axe_key(), -1).toInt() > -1);
|
||||
}
|
||||
|
||||
JButtonData::JButtonData() : CompStoreObj(), index(-1)
|
||||
{
|
||||
CompStoreObj::addObjectMapping(propertyGroup(), this);
|
||||
}
|
||||
|
||||
bool JButtonData::existsOnDisk()
|
||||
{
|
||||
return (m_settings.value(settingsPath() % button_idx_key(), -1).toInt() > -1);
|
||||
}
|
||||
|
||||
|
||||
// ** Profile class********************
|
||||
|
||||
@@ -397,8 +407,10 @@ AppData::AppData() :
|
||||
profile[i].setIndex(i);
|
||||
|
||||
// Configure the joysticks
|
||||
for (int i = 0; i < MAX_JOYSTICKS; i++)
|
||||
for (int i = 0; i < MAX_JS_AXES; i++)
|
||||
joystick[i].setIndex(i);
|
||||
for (int i = 0; i < MAX_JS_BUTTONS; i++)
|
||||
jsButton[i].setIndex(i);
|
||||
|
||||
// Configure the updates
|
||||
for (int i = 0; i < MAX_COMPONENTS; i++) {
|
||||
@@ -436,8 +448,10 @@ void AppData::initAll()
|
||||
for (int i = 0; i < MAX_PROFILES; i++)
|
||||
profile[i].init();
|
||||
// Initialize the joysticks
|
||||
for (int i = 0; i < MAX_JOYSTICKS; i++)
|
||||
for (int i = 0; i < MAX_JS_AXES; i++)
|
||||
joystick[i].init();
|
||||
for (int i = 0; i < MAX_JS_BUTTONS; i++)
|
||||
jsButton[i].init();
|
||||
// Initialize the updatess
|
||||
for (int i = 0; i < MAX_COMPONENTS; i++) {
|
||||
component[i].init();
|
||||
@@ -453,8 +467,10 @@ void AppData::resetAllSettings()
|
||||
fwRev.resetAll();
|
||||
for (int i = 0; i < MAX_PROFILES; i++)
|
||||
profile[i].resetAll();
|
||||
for (int i = 0; i < MAX_JOYSTICKS; i++)
|
||||
for (int i = 0; i < MAX_JS_AXES; i++)
|
||||
joystick[i].resetAll();
|
||||
for (int i = 0; i < MAX_JS_BUTTONS; i++)
|
||||
jsButton[i].resetAll();
|
||||
for (int i = 0; i < MAX_COMPONENTS; i++) {
|
||||
component[i].resetAll();
|
||||
for (int j = 0; j < MAX_COMPONENT_ASSETS; j++) {
|
||||
@@ -469,8 +485,10 @@ void AppData::storeAllSettings()
|
||||
storeAll();
|
||||
for (int i = 0; i < MAX_PROFILES; i++)
|
||||
profile[i].storeAll();
|
||||
for (int i = 0; i < MAX_JOYSTICKS; i++)
|
||||
for (int i = 0; i < MAX_JS_AXES; i++)
|
||||
joystick[i].storeAll();
|
||||
for (int i = 0; i < MAX_JS_BUTTONS; i++)
|
||||
jsButton[i].storeAll();
|
||||
for (int i = 0; i < MAX_COMPONENTS; i++) {
|
||||
component[i].storeAll();
|
||||
for (int j = 0; j < MAX_COMPONENT_ASSETS; j++)
|
||||
|
||||
@@ -59,7 +59,8 @@
|
||||
#define CPN_SETTINGS_INI_PATH QString(CPN_SETTINGS_BACKUP_DIR % "/" % CPN_SETTINGS_INI_FILE)
|
||||
|
||||
#define MAX_PROFILES 20
|
||||
#define MAX_JOYSTICKS 8
|
||||
#define MAX_JS_AXES 10
|
||||
#define MAX_JS_BUTTONS 32
|
||||
#define MAX_COMPONENTS 10
|
||||
#define MAX_COMPONENT_ASSETS 5
|
||||
|
||||
@@ -347,6 +348,26 @@ class JStickData: public CompStoreObj
|
||||
int index;
|
||||
};
|
||||
|
||||
class JButtonData: public CompStoreObj
|
||||
{
|
||||
Q_OBJECT
|
||||
public slots:
|
||||
bool existsOnDisk();
|
||||
|
||||
protected:
|
||||
explicit JButtonData();
|
||||
void setIndex(int idx) { index = idx; }
|
||||
inline QString propertyGroup() const override { return QStringLiteral("JsButton"); }
|
||||
inline QString settingsPath() const override { return QString("%1/%2/").arg(propertyGroup()).arg(index); }
|
||||
friend class AppData;
|
||||
|
||||
private:
|
||||
PROPERTY(int, button_idx, -1)
|
||||
PROPERTY(int, button_inv, 0)
|
||||
|
||||
int index;
|
||||
};
|
||||
|
||||
|
||||
//! \brief Profile class stores properties related to each Radio Profile.
|
||||
//! \todo TODO: Remove or refactor stored radio settings system (#4583)
|
||||
@@ -592,7 +613,8 @@ class AppData: public CompStoreObj
|
||||
bool exportSettingsToFile(const QString & expFile, QString & resultMsg);
|
||||
|
||||
Profile profile[MAX_PROFILES];
|
||||
JStickData joystick[MAX_JOYSTICKS];
|
||||
JStickData joystick[MAX_JS_AXES];
|
||||
JButtonData jsButton[MAX_JS_BUTTONS];
|
||||
FwRevision fwRev;
|
||||
ComponentData component[MAX_COMPONENTS];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user