kopia lustrzana https://gitlab.com/eliggett/wfview
Add mutex to ensure thread safety
rodzic
fa47bfb4bc
commit
c8a29bb400
|
@ -70,6 +70,9 @@ void controllerSetup::mousePressed(QPoint p)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
QMutexLocker locker(mutex);
|
||||||
|
|
||||||
|
|
||||||
for (BUTTON& b : *buttons)
|
for (BUTTON& b : *buttons)
|
||||||
{
|
{
|
||||||
if (b.dev == currentDevice && b.pos.contains(p))
|
if (b.dev == currentDevice && b.pos.contains(p))
|
||||||
|
@ -119,20 +122,25 @@ void controllerSetup::mousePressed(QPoint p)
|
||||||
offEvent->hide();
|
offEvent->hide();
|
||||||
knobEvent->hide();
|
knobEvent->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void controllerSetup::onEventIndexChanged(int index) {
|
void controllerSetup::onEventIndexChanged(int index) {
|
||||||
Q_UNUSED(index);
|
Q_UNUSED(index);
|
||||||
|
|
||||||
if (currentButton != Q_NULLPTR && onEvent->currentData().toInt() < commands->size()) {
|
if (currentButton != Q_NULLPTR && onEvent->currentData().toInt() < commands->size()) {
|
||||||
|
QMutexLocker locker(mutex);
|
||||||
currentButton->onCommand = &commands->at(onEvent->currentData().toInt());
|
currentButton->onCommand = &commands->at(onEvent->currentData().toInt());
|
||||||
currentButton->onText->setPlainText(currentButton->onCommand->text);
|
currentButton->onText->setPlainText(currentButton->onCommand->text);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void controllerSetup::offEventIndexChanged(int index) {
|
void controllerSetup::offEventIndexChanged(int index) {
|
||||||
Q_UNUSED(index);
|
Q_UNUSED(index);
|
||||||
if (currentButton != Q_NULLPTR && offEvent->currentData().toInt() < commands->size()) {
|
if (currentButton != Q_NULLPTR && offEvent->currentData().toInt() < commands->size()) {
|
||||||
|
QMutexLocker locker(mutex);
|
||||||
currentButton->offCommand = &commands->at(offEvent->currentData().toInt());
|
currentButton->offCommand = &commands->at(offEvent->currentData().toInt());
|
||||||
currentButton->offText->setPlainText(currentButton->offCommand->text);
|
currentButton->offText->setPlainText(currentButton->offCommand->text);
|
||||||
}
|
}
|
||||||
|
@ -141,17 +149,21 @@ void controllerSetup::offEventIndexChanged(int index) {
|
||||||
void controllerSetup::knobEventIndexChanged(int index) {
|
void controllerSetup::knobEventIndexChanged(int index) {
|
||||||
Q_UNUSED(index);
|
Q_UNUSED(index);
|
||||||
if (currentKnob != Q_NULLPTR && knobEvent->currentData().toInt() < commands->size()) {
|
if (currentKnob != Q_NULLPTR && knobEvent->currentData().toInt() < commands->size()) {
|
||||||
|
QMutexLocker locker(mutex);
|
||||||
currentKnob->command = &commands->at(knobEvent->currentData().toInt());
|
currentKnob->command = &commands->at(knobEvent->currentData().toInt());
|
||||||
currentKnob->text->setPlainText(currentKnob->command->text);
|
currentKnob->text->setPlainText(currentKnob->command->text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void controllerSetup::newDevice(unsigned char devType, QVector<BUTTON>* but, QVector<KNOB>* kb, QVector<COMMAND>* cmd)
|
void controllerSetup::newDevice(unsigned char devType, QVector<BUTTON>* but, QVector<KNOB>* kb, QVector<COMMAND>* cmd, QMutex* mut)
|
||||||
{
|
{
|
||||||
buttons = but;
|
buttons = but;
|
||||||
knobs = kb;
|
knobs = kb;
|
||||||
commands = cmd;
|
commands = cmd;
|
||||||
|
mutex = mut;
|
||||||
|
|
||||||
|
QMutexLocker locker(mutex);
|
||||||
|
|
||||||
// Remove any existing button text:
|
// Remove any existing button text:
|
||||||
for (QGraphicsItem* item : scene->items())
|
for (QGraphicsItem* item : scene->items())
|
||||||
|
|
|
@ -38,7 +38,7 @@ signals:
|
||||||
void sendSensitivity(int val);
|
void sendSensitivity(int val);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void newDevice(unsigned char devType, QVector<BUTTON>* but, QVector<KNOB>* kb, QVector<COMMAND>* cmd);
|
void newDevice(unsigned char devType, QVector<BUTTON>* but, QVector<KNOB>* kb, QVector<COMMAND>* cmd, QMutex* mut);
|
||||||
void mousePressed(QPoint p);
|
void mousePressed(QPoint p);
|
||||||
void onEventIndexChanged(int index);
|
void onEventIndexChanged(int index);
|
||||||
void offEventIndexChanged(int index);
|
void offEventIndexChanged(int index);
|
||||||
|
@ -67,7 +67,7 @@ private:
|
||||||
QGraphicsProxyWidget* offEventProxy = Q_NULLPTR;
|
QGraphicsProxyWidget* offEventProxy = Q_NULLPTR;
|
||||||
QGraphicsProxyWidget* knobEventProxy = Q_NULLPTR;
|
QGraphicsProxyWidget* knobEventProxy = Q_NULLPTR;
|
||||||
QString deviceName;
|
QString deviceName;
|
||||||
|
QMutex* mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -38,9 +38,10 @@ usbController::~usbController()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void usbController::init(int sens)
|
void usbController::init(int sens, QMutex* mut)
|
||||||
{
|
{
|
||||||
sensitivity = sens;
|
this->mutex = mut;
|
||||||
|
this->sensitivity = sens;
|
||||||
emit sendSensitivity(sensitivity);
|
emit sendSensitivity(sensitivity);
|
||||||
|
|
||||||
if (HID_API_VERSION == HID_API_MAKE_VERSION(hid_version()->major, hid_version()->minor, hid_version()->patch)) {
|
if (HID_API_VERSION == HID_API_MAKE_VERSION(hid_version()->major, hid_version()->minor, hid_version()->patch)) {
|
||||||
|
@ -207,7 +208,7 @@ void usbController::run()
|
||||||
qInfo(logUsbControl()) << "Button Guide" << pressed;
|
qInfo(logUsbControl()) << "Button Guide" << pressed;
|
||||||
});
|
});
|
||||||
|
|
||||||
emit newDevice(usbDevice, buttonList, knobList, commands); // Let the UI know we have a new controller
|
emit newDevice(usbDevice, buttonList, knobList, commands, &usbMutex); // Let the UI know we have a new controller
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -267,7 +268,7 @@ void usbController::run()
|
||||||
|
|
||||||
|
|
||||||
// Let the UI know we have a new controller
|
// Let the UI know we have a new controller
|
||||||
emit newDevice(usbDevice, buttonList, knobList, commands);
|
emit newDevice(usbDevice, buttonList, knobList, commands, mutex);
|
||||||
// Run the periodic timer to get data
|
// Run the periodic timer to get data
|
||||||
QTimer::singleShot(25, this, SLOT(runTimer()));
|
QTimer::singleShot(25, this, SLOT(runTimer()));
|
||||||
}
|
}
|
||||||
|
@ -297,13 +298,16 @@ void usbController::runTimer()
|
||||||
res = 0;
|
res = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QMutexLocker locker(mutex);
|
||||||
|
|
||||||
|
|
||||||
while (res > 0) {
|
while (res > 0) {
|
||||||
QByteArray data(HIDDATALENGTH, 0x0);
|
QByteArray data(HIDDATALENGTH, 0x0);
|
||||||
res = hid_read(this->handle, (unsigned char*)data.data(), HIDDATALENGTH);
|
res = hid_read(this->handle, (unsigned char*)data.data(), HIDDATALENGTH);
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
{
|
{
|
||||||
qInfo(logUsbControl()) << "USB Device disconnected" << this->product;
|
qInfo(logUsbControl()) << "USB Device disconnected" << this->product;
|
||||||
emit newDevice(0, buttonList, knobList, commands);
|
emit newDevice(0, buttonList, knobList, commands, mutex);
|
||||||
this->product = "";
|
this->product = "";
|
||||||
this->manufacturer = "";
|
this->manufacturer = "";
|
||||||
this->serial = "<none>";
|
this->serial = "<none>";
|
||||||
|
@ -602,6 +606,7 @@ void usbController::runTimer()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run every 25ms
|
// Run every 25ms
|
||||||
QTimer::singleShot(25, this, SLOT(runTimer()));
|
QTimer::singleShot(25, this, SLOT(runTimer()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
#include <QMutex>
|
||||||
|
|
||||||
#if defined(USB_CONTROLLER) && QT_VERSION < QT_VERSION_CHECK(6,0,0)
|
#if defined(USB_CONTROLLER) && QT_VERSION < QT_VERSION_CHECK(6,0,0)
|
||||||
#include <QGamepad>
|
#include <QGamepad>
|
||||||
|
@ -120,7 +121,7 @@ public:
|
||||||
~usbController();
|
~usbController();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void init(int sens);
|
void init(int sens, QMutex *mut);
|
||||||
void run();
|
void run();
|
||||||
void runTimer();
|
void runTimer();
|
||||||
void ledControl(bool on, unsigned char num);
|
void ledControl(bool on, unsigned char num);
|
||||||
|
@ -137,7 +138,7 @@ signals:
|
||||||
void doShuttle(bool plus, quint8 level);
|
void doShuttle(bool plus, quint8 level);
|
||||||
void setBand(int band);
|
void setBand(int band);
|
||||||
void button(const COMMAND* cmd);
|
void button(const COMMAND* cmd);
|
||||||
void newDevice(unsigned char devType, QVector<BUTTON>* but, QVector<KNOB>* kb, QVector<COMMAND>* cmd);
|
void newDevice(unsigned char devType, QVector<BUTTON>* but, QVector<KNOB>* kb, QVector<COMMAND>* cmd, QMutex* mut);
|
||||||
void sendSensitivity(int val);
|
void sendSensitivity(int val);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -162,6 +163,7 @@ private:
|
||||||
QString path = "";
|
QString path = "";
|
||||||
int sensitivity = 1;
|
int sensitivity = 1;
|
||||||
QList<int> knobValues;
|
QList<int> knobValues;
|
||||||
|
QMutex* mutex=Q_NULLPTR;
|
||||||
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
||||||
QGamepad* gamepad=Q_NULLPTR;
|
QGamepad* gamepad=Q_NULLPTR;
|
||||||
#endif
|
#endif
|
||||||
|
|
16
wfmain.cpp
16
wfmain.cpp
|
@ -1671,7 +1671,7 @@ void wfmain::setupUsbControllerDevice()
|
||||||
connect(usbControllerDev, SIGNAL(doShuttle(bool, unsigned char)), this, SLOT(doShuttle(bool, unsigned char)));
|
connect(usbControllerDev, SIGNAL(doShuttle(bool, unsigned char)), this, SLOT(doShuttle(bool, unsigned char)));
|
||||||
connect(usbControllerDev, SIGNAL(button(const COMMAND*)), this, SLOT(buttonControl(const COMMAND*)));
|
connect(usbControllerDev, SIGNAL(button(const COMMAND*)), this, SLOT(buttonControl(const COMMAND*)));
|
||||||
connect(usbControllerDev, SIGNAL(setBand(int)), this, SLOT(setBand(int)));
|
connect(usbControllerDev, SIGNAL(setBand(int)), this, SLOT(setBand(int)));
|
||||||
connect(usbControllerDev, SIGNAL(newDevice(unsigned char, QVector<BUTTON>*, QVector<KNOB>*, QVector<COMMAND>*)), shut, SLOT(newDevice(unsigned char, QVector<BUTTON>*, QVector<KNOB>*, QVector<COMMAND>*)));
|
connect(usbControllerDev, SIGNAL(newDevice(unsigned char, QVector<BUTTON>*, QVector<KNOB>*, QVector<COMMAND>*, QMutex*)), shut, SLOT(newDevice(unsigned char, QVector<BUTTON>*, QVector<KNOB>*, QVector<COMMAND>*,QMutex*)));
|
||||||
usbControllerThread->start(QThread::LowestPriority);
|
usbControllerThread->start(QThread::LowestPriority);
|
||||||
|
|
||||||
connect(this, SIGNAL(sendUsbControllerCommands(QVector<COMMAND>*)), usbControllerDev, SLOT(receiveCommands(QVector<COMMAND>*)));
|
connect(this, SIGNAL(sendUsbControllerCommands(QVector<COMMAND>*)), usbControllerDev, SLOT(receiveCommands(QVector<COMMAND>*)));
|
||||||
|
@ -1680,7 +1680,7 @@ void wfmain::setupUsbControllerDevice()
|
||||||
connect(shut, SIGNAL(sendSensitivity(int)), usbControllerDev, SLOT(receiveSensitivity(int)));
|
connect(shut, SIGNAL(sendSensitivity(int)), usbControllerDev, SLOT(receiveSensitivity(int)));
|
||||||
connect(shut, SIGNAL(sendSensitivity(int)), this, SLOT(receiveUsbSensitivity(int)));
|
connect(shut, SIGNAL(sendSensitivity(int)), this, SLOT(receiveUsbSensitivity(int)));
|
||||||
connect(usbControllerDev, SIGNAL(sendSensitivity(int)), shut, SLOT(receiveSensitivity(int)));
|
connect(usbControllerDev, SIGNAL(sendSensitivity(int)), shut, SLOT(receiveSensitivity(int)));
|
||||||
connect(this, SIGNAL(initUsbController(int)), usbControllerDev, SLOT(init(int)));
|
connect(this, SIGNAL(initUsbController(int,QMutex*)), usbControllerDev, SLOT(init(int,QMutex*)));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2440,11 +2440,14 @@ void wfmain::loadSettings()
|
||||||
ui->usbButtonsResetBtn->setEnabled(prefs.enableUSBControllers);
|
ui->usbButtonsResetBtn->setEnabled(prefs.enableUSBControllers);
|
||||||
ui->usbCommandsResetBtn->setEnabled(prefs.enableUSBControllers);
|
ui->usbCommandsResetBtn->setEnabled(prefs.enableUSBControllers);
|
||||||
ui->usbResetLbl->setVisible(prefs.enableUSBControllers);
|
ui->usbResetLbl->setVisible(prefs.enableUSBControllers);
|
||||||
|
|
||||||
|
/*Ensure that no operations on the usb commands/buttons/knobs take place*/
|
||||||
|
QMutexLocker locker(&usbMutex);
|
||||||
|
|
||||||
if (prefs.enableUSBControllers) {
|
if (prefs.enableUSBControllers) {
|
||||||
// Setup USB Controller
|
// Setup USB Controller
|
||||||
setupUsbControllerDevice();
|
setupUsbControllerDevice();
|
||||||
emit initUsbController(prefs.usbSensitivity);
|
emit initUsbController(prefs.usbSensitivity, &usbMutex);
|
||||||
emit sendUsbControllerCommands(&usbCommands);
|
emit sendUsbControllerCommands(&usbCommands);
|
||||||
emit sendUsbControllerButtons(&usbButtons);
|
emit sendUsbControllerButtons(&usbButtons);
|
||||||
emit sendUsbControllerKnobs(&usbKnobs);
|
emit sendUsbControllerKnobs(&usbKnobs);
|
||||||
|
@ -2515,7 +2518,6 @@ void wfmain::loadSettings()
|
||||||
settings->endArray();
|
settings->endArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int numKnobs = settings->beginReadArray("Knobs");
|
int numKnobs = settings->beginReadArray("Knobs");
|
||||||
// This is the last time the knobs were changed, (v1.58)
|
// This is the last time the knobs were changed, (v1.58)
|
||||||
if (numKnobs == 0 || priorVersionFloat < 1.58) {
|
if (numKnobs == 0 || priorVersionFloat < 1.58) {
|
||||||
|
@ -2954,6 +2956,7 @@ void wfmain::saveSettings()
|
||||||
settings->setValue("EnableUSBControllers", prefs.enableUSBControllers);
|
settings->setValue("EnableUSBControllers", prefs.enableUSBControllers);
|
||||||
settings->setValue("USBSensitivity", prefs.usbSensitivity);
|
settings->setValue("USBSensitivity", prefs.usbSensitivity);
|
||||||
|
|
||||||
|
QMutexLocker locker(&usbMutex);
|
||||||
settings->beginWriteArray("Buttons");
|
settings->beginWriteArray("Buttons");
|
||||||
for (int nb = 0; nb < usbButtons.count(); nb++)
|
for (int nb = 0; nb < usbButtons.count(); nb++)
|
||||||
{
|
{
|
||||||
|
@ -9117,7 +9120,7 @@ void wfmain::on_enableUsbChk_clicked(bool checked)
|
||||||
if (checked) {
|
if (checked) {
|
||||||
// Setup USB Controller
|
// Setup USB Controller
|
||||||
setupUsbControllerDevice();
|
setupUsbControllerDevice();
|
||||||
emit initUsbController(prefs.usbSensitivity);
|
emit initUsbController(prefs.usbSensitivity, &usbMutex);
|
||||||
emit sendUsbControllerCommands(&usbCommands);
|
emit sendUsbControllerCommands(&usbCommands);
|
||||||
emit sendUsbControllerButtons(&usbButtons);
|
emit sendUsbControllerButtons(&usbButtons);
|
||||||
emit sendUsbControllerKnobs(&usbKnobs);
|
emit sendUsbControllerKnobs(&usbKnobs);
|
||||||
|
@ -9263,6 +9266,7 @@ void wfmain::on_cwButton_clicked()
|
||||||
void wfmain::resetUsbButtons()
|
void wfmain::resetUsbButtons()
|
||||||
{
|
{
|
||||||
#ifdef USB_CONTROLLER
|
#ifdef USB_CONTROLLER
|
||||||
|
qInfo(logUsbControl) << "Resetting USB Buttons to defaults";
|
||||||
usbButtons.clear();
|
usbButtons.clear();
|
||||||
|
|
||||||
// ShuttleXpress
|
// ShuttleXpress
|
||||||
|
@ -9342,6 +9346,7 @@ void wfmain::resetUsbButtons()
|
||||||
void wfmain::resetUsbKnobs()
|
void wfmain::resetUsbKnobs()
|
||||||
{
|
{
|
||||||
#ifdef USB_CONTROLLER
|
#ifdef USB_CONTROLLER
|
||||||
|
qInfo(logUsbControl) << "Resetting USB Knobs to defaults";
|
||||||
usbKnobs.clear();
|
usbKnobs.clear();
|
||||||
// eCoder
|
// eCoder
|
||||||
usbKnobs.append(KNOB(eCoderPlus, 1, QRect(120, 153, 72, 27), Qt::green, &usbCommands[0]));
|
usbKnobs.append(KNOB(eCoderPlus, 1, QRect(120, 153, 72, 27), Qt::green, &usbCommands[0]));
|
||||||
|
@ -9355,6 +9360,7 @@ void wfmain::resetUsbKnobs()
|
||||||
void wfmain::resetUsbCommands()
|
void wfmain::resetUsbCommands()
|
||||||
{
|
{
|
||||||
#ifdef USB_CONTROLLER
|
#ifdef USB_CONTROLLER
|
||||||
|
qInfo(logUsbControl) << "Resetting USB Commands to defaults";
|
||||||
usbCommands.clear();
|
usbCommands.clear();
|
||||||
int num = 0;
|
int num = 0;
|
||||||
usbCommands.append(COMMAND(num++, "None", commandButton, cmdNone, 0x0));
|
usbCommands.append(COMMAND(num++, "None", commandButton, cmdNone, 0x0));
|
||||||
|
|
3
wfmain.h
3
wfmain.h
|
@ -223,7 +223,7 @@ signals:
|
||||||
void openShuttle();
|
void openShuttle();
|
||||||
void requestRigState();
|
void requestRigState();
|
||||||
void stateUpdated();
|
void stateUpdated();
|
||||||
void initUsbController(int sens);
|
void initUsbController(int sens, QMutex* mutex);
|
||||||
void sendUsbControllerCommands(QVector<COMMAND>* cmds);
|
void sendUsbControllerCommands(QVector<COMMAND>* cmds);
|
||||||
void sendUsbControllerButtons(QVector<BUTTON>* buts);
|
void sendUsbControllerButtons(QVector<BUTTON>* buts);
|
||||||
void sendUsbControllerKnobs(QVector<KNOB>* kbs);
|
void sendUsbControllerKnobs(QVector<KNOB>* kbs);
|
||||||
|
@ -1150,6 +1150,7 @@ private:
|
||||||
QVector<COMMAND> usbCommands;
|
QVector<COMMAND> usbCommands;
|
||||||
QVector<BUTTON> usbButtons;
|
QVector<BUTTON> usbButtons;
|
||||||
QVector<KNOB> usbKnobs;
|
QVector<KNOB> usbKnobs;
|
||||||
|
QMutex usbMutex;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
dxClusterClient* cluster = Q_NULLPTR;
|
dxClusterClient* cluster = Q_NULLPTR;
|
||||||
|
|
Ładowanie…
Reference in New Issue