Correct usbMutex

smart-pointers
Phil Taylor 2023-02-10 18:10:32 +00:00
rodzic 3429786e10
commit 3461a0e5e5
6 zmienionych plików z 38 dodań i 10 usunięć

Wyświetl plik

@ -122,7 +122,6 @@ void controllerSetup::mousePressed(QPoint p)
offEvent->hide();
knobEvent->hide();
}
}
void controllerSetup::onEventIndexChanged(int index) {
@ -133,7 +132,7 @@ void controllerSetup::onEventIndexChanged(int index) {
currentButton->onCommand = &commands->at(onEvent->currentData().toInt());
currentButton->onText->setPlainText(currentButton->onCommand->text);
}
emit programButtons(); // Signal that any button programming on the device should be completed.
}
@ -144,6 +143,7 @@ void controllerSetup::offEventIndexChanged(int index) {
currentButton->offCommand = &commands->at(offEvent->currentData().toInt());
currentButton->offText->setPlainText(currentButton->offCommand->text);
}
emit programButtons(); // Signal that any button programming on the device should be completed.
}
void controllerSetup::knobEventIndexChanged(int index) {
@ -153,6 +153,7 @@ void controllerSetup::knobEventIndexChanged(int index) {
currentKnob->command = &commands->at(knobEvent->currentData().toInt());
currentKnob->text->setPlainText(currentKnob->command->text);
}
emit programButtons(); // Signal that any button programming on the device should be completed.
}
@ -163,7 +164,7 @@ void controllerSetup::newDevice(unsigned char devType, QVector<BUTTON>* but, QVe
commands = cmd;
mutex = mut;
QMutexLocker locker(mutex);
mutex->lock();
// Remove any existing button text:
for (QGraphicsItem* item : scene->items())
@ -321,6 +322,8 @@ void controllerSetup::newDevice(unsigned char devType, QVector<BUTTON>* but, QVe
knobEventProxy = scene->addWidget(knobEvent);
connect(knobEvent, SIGNAL(currentIndexChanged(int)), this, SLOT(knobEventIndexChanged(int)));
mutex->unlock();
emit programButtons(); // Needs to take the mutex
}
void controllerSetup::receiveSensitivity(int val)

Wyświetl plik

@ -36,6 +36,7 @@ public:
signals:
void sendSensitivity(int val);
void programButtons();
public slots:
void newDevice(unsigned char devType, QVector<BUTTON>* but, QVector<KNOB>* kb, QVector<COMMAND>* cmd, QMutex* mut);

Wyświetl plik

@ -74,10 +74,11 @@ void usbController::init(int sens, QMutex* mut)
struct hid_device_info* devs;
devs = hid_enumerate(0x0, 0x0);
while (devs) {
qInfo(logUsbControl()) << QString("Manufacturer: %0 Product: %1 Path: %2")
.arg(QString::fromWCharArray(devs->manufacturer_string))
qInfo(logUsbControl()) << QString("Device found: %0 manufacturer: %1 usage: 0x%3 usage_page 0x%4")
.arg(QString::fromWCharArray(devs->product_string))
.arg(QString::fromLocal8Bit(devs->path));
.arg(QString::fromWCharArray(devs->manufacturer_string))
.arg(devs->usage, 4, 16, QChar('0'))
.arg(devs->usage_page, 4, 16, QChar('0'));
devs = devs->next;
}
hid_free_enumeration(devs);
@ -103,6 +104,26 @@ void usbController::receiveKnobs(QVector<KNOB>* kbs)
knobList = kbs;
}
void usbController::programButtons() {
QMutexLocker locker(mutex);
if (usbDevice == QuickKeys) {
for (BUTTON* but = buttonList->begin(); but != buttonList->end(); but++) {
QByteArray data(16, 0x0);
data[0] = (qint8)0x02;
data[1] = (qint8)0xb1;
data[2] = but->num;
data.replace(3,but->name.mid(0,8).length(), but->name.mid(0,8).toLocal8Bit());
int res = hid_write(this->handle, (const unsigned char*)data.constData(), data.size());
if (res < 0) {
qDebug(logUsbControl()) << "Unable to write(), Error:" << hid_error(this->handle);
return;
}
}
}
}
void usbController::run()
{
@ -208,7 +229,7 @@ void usbController::run()
qInfo(logUsbControl()) << "Button Guide" << pressed;
});
emit newDevice(usbDevice, buttonList, knobList, commands, &usbMutex); // Let the UI know we have a new controller
emit newDevice(usbDevice, buttonList, knobList, commands, &mutex); // Let the UI know we have a new controller
return;
}
}

Wyświetl plik

@ -130,6 +130,7 @@ public slots:
void receiveKnobs(QVector<KNOB>*);
void getVersion();
void receiveSensitivity(int val);
void programButtons();
signals:
void jogPlus();
@ -171,12 +172,13 @@ private:
void buttonState(QString but, double val);
usbDeviceType usbDevice = usbNone;
unsigned short knownUsbDevices[4][3] = {
unsigned short knownUsbDevices[5][3] = {
{shuttleXpress,0x0b33,0x0020},
{shuttlePro2,0x0b33,0x0030},
//{eCoderPlus,0x0c26,0x001e}, // Only enable for testing!
{RC28,0x0c26,0x001e},
{eCoderPlus, 0x1fc9, 0x0003}
{eCoderPlus, 0x1fc9, 0x0003},
{QuickKeys, 0x28bd, 0x5202}
};
protected:

Wyświetl plik

@ -1680,6 +1680,7 @@ void wfmain::setupUsbControllerDevice()
connect(shut, SIGNAL(sendSensitivity(int)), usbControllerDev, SLOT(receiveSensitivity(int)));
connect(shut, SIGNAL(sendSensitivity(int)), this, SLOT(receiveUsbSensitivity(int)));
connect(usbControllerDev, SIGNAL(sendSensitivity(int)), shut, SLOT(receiveSensitivity(int)));
connect(usbControllerDev, SIGNAL(programButtons()), shut, SLOT(programButtons()));
connect(this, SIGNAL(initUsbController(int,QMutex*)), usbControllerDev, SLOT(init(int,QMutex*)));
#endif
}

Wyświetl plik

@ -194,7 +194,7 @@ enum codecType { LPCM, PCMU, OPUS };
enum passbandActions {passbandStatic, pbtInnerMove, pbtOuterMove, pbtMoving, passbandResizing};
enum usbDeviceType { usbNone = 0, shuttleXpress, shuttlePro2, RC28, xBoxGamepad, unknownGamepad, eCoderPlus};
enum usbDeviceType { usbNone = 0, shuttleXpress, shuttlePro2, RC28, xBoxGamepad, unknownGamepad, eCoderPlus, QuickKeys};
enum usbCommandType{ commandButton, commandKnob };
#endif // WFVIEWTYPES_H