From 792fac11d67328d1443e591b25d4d70f96db12ef Mon Sep 17 00:00:00 2001 From: Phil Taylor Date: Fri, 17 Mar 2023 23:35:40 +0000 Subject: [PATCH 01/36] Support multiple USB controllers --- controllersetup.cpp | 379 +++++------ controllersetup.h | 110 ++-- controllersetup.ui | 209 +----- prefs.h | 10 +- rigcommander.cpp | 52 +- rigcommander.h | 1 + usbcontroller.cpp | 1493 ++++++++++++++++++++++++++----------------- usbcontroller.h | 126 ++-- wfmain.cpp | 437 ++++--------- wfmain.h | 18 +- wfviewtypes.h | 2 +- 11 files changed, 1440 insertions(+), 1397 deletions(-) diff --git a/controllersetup.cpp b/controllersetup.cpp index dcc1a9f..68e8f5d 100644 --- a/controllersetup.cpp +++ b/controllersetup.cpp @@ -7,65 +7,36 @@ controllerSetup::controllerSetup(QWidget* parent) : ui(new Ui::controllerSetup) { ui->setupUi(this); - scene = new controllerScene(); - connect(scene, SIGNAL(mousePressed(QPoint)), this, SLOT(mousePressed(QPoint))); - ui->graphicsView->setScene(scene); - ui->qkBrightCombo->setVisible(false); - ui->qkOrientCombo->setVisible(false); - ui->qkSpeedCombo->setVisible(false); - ui->qkColorButton->setVisible(false); - ui->qkTimeoutSpin->setVisible(false); - ui->qkTimeoutLabel->setVisible(false); - textItem = scene->addText("No USB controller found"); - textItem->setDefaultTextColor(Qt::gray); + ui->tabWidget->clear(); + ui->tabWidget->hide(); + noControllersText = new QLabel("No USB controller found"); + noControllersText->setStyleSheet("QLabel { color : gray; }"); + ui->hboxLayout->addWidget(noControllersText); this->resize(this->sizeHint()); } controllerSetup::~controllerSetup() { - /* - // Remove any existing button text: - for (QGraphicsItem* item : scene->items()) - { - QGraphicsTextItem* txt = qgraphicsitem_cast(item); - if (!txt || txt == textItem) - continue; - scene->removeItem(txt); - delete txt; - } if (onEventProxy != Q_NULLPTR) { - scene->removeItem(onEventProxy); - onEventProxy = Q_NULLPTR; + delete onEventProxy; delete onEvent; - onEvent = Q_NULLPTR; } + if (offEventProxy != Q_NULLPTR) { - scene->removeItem(offEventProxy); - offEventProxy = Q_NULLPTR; + delete offEventProxy; delete offEvent; - offEvent = Q_NULLPTR; } + if (knobEventProxy != Q_NULLPTR) { - scene->removeItem(knobEventProxy); - knobEventProxy = Q_NULLPTR; + delete knobEventProxy; delete knobEvent; - knobEvent = Q_NULLPTR; - } - */ - - if (bgImage != Q_NULLPTR) { - scene->removeItem(bgImage); - delete bgImage; - bgImage = Q_NULLPTR; } - delete textItem; - delete scene; delete ui; } -void controllerSetup::mousePressed(QPoint p) +void controllerSetup::mousePressed(controllerScene* scene, QPoint p) { // Receive mouse event from the scene qDebug() << "Looking for button Point x=" << p.x() << " y=" << p.y(); @@ -79,9 +50,11 @@ void controllerSetup::mousePressed(QPoint p) QMutexLocker locker(mutex); + for (BUTTON& b : *buttons) { - if (b.dev == currentDevice && b.pos.contains(p)) + + if (ui->tabWidget->currentWidget()->objectName() == b.devicePath && b.pos.contains(p)) { found = true; currentButton = &b; @@ -106,7 +79,7 @@ void controllerSetup::mousePressed(QPoint p) if (!found) { for (KNOB& k : *knobs) { - if (k.dev == currentDevice && k.pos.contains(p)) + if (ui->tabWidget->currentWidget()->objectName() == k.devicePath && k.pos.contains(p)) { found = true; currentKnob = &k; @@ -123,7 +96,25 @@ void controllerSetup::mousePressed(QPoint p) } } - if (!found) { + if(found) + { + found=false; + foreach (QGraphicsItem *item, scene->items()) + { + QGraphicsProxyWidget *node = dynamic_cast(item); + if (node) { + found=true; + break; + } + } + if (!found) { + scene->addItem(offEvent->graphicsProxyWidget()); + scene->addItem(onEvent->graphicsProxyWidget()); + scene->addItem(knobEvent->graphicsProxyWidget()); + } + } + else + { onEvent->hide(); offEvent->hide(); knobEvent->hide(); @@ -140,7 +131,7 @@ void controllerSetup::onEventIndexChanged(int index) { currentButton->onText->setPos(currentButton->pos.center().x() - currentButton->onText->boundingRect().width() / 2, (currentButton->pos.center().y() - currentButton->onText->boundingRect().height() / 2)-6); // Signal that any button programming on the device should be completed. - emit programButton(currentButton->num, currentButton->onCommand->text); + emit programButton(currentButton->devicePath,currentButton->num, currentButton->onCommand->text); } } @@ -168,8 +159,33 @@ void controllerSetup::knobEventIndexChanged(int index) { } } +void controllerSetup::removeDevice(USBDEVICE* dev) +{ + QMutexLocker locker(mutex); -void controllerSetup::newDevice(unsigned char devType, QVector