From 8ee8d23fb90a2c70a8883d5cbe8bae2fd67ed8ff Mon Sep 17 00:00:00 2001 From: Phil Taylor Date: Fri, 22 Apr 2022 11:11:21 +0100 Subject: [PATCH] 'Almost' working shuttle support --- rigidentities.h | 1 + shuttle.h | 68 --------------- shuttlesetup.cpp | 99 ++++++++++++++++++++- shuttlesetup.h | 71 ++++++++++++++- shuttle.cpp => usbcontroller.cpp | 143 +++++++++++++++++++++---------- usbcontroller.h | 122 ++++++++++++++++++++++++++ wfmain.cpp | 82 +++++++++++------- wfmain.h | 25 ++++-- wfview.pro | 10 +-- wfview.vcxproj | 54 ++++++++++-- wfview.vcxproj.filters | 32 +++++++ wfview.vcxproj.user | 4 +- 12 files changed, 537 insertions(+), 174 deletions(-) delete mode 100644 shuttle.h rename shuttle.cpp => usbcontroller.cpp (56%) create mode 100644 usbcontroller.h diff --git a/rigidentities.h b/rigidentities.h index 7df3e19..cad0fc2 100644 --- a/rigidentities.h +++ b/rigidentities.h @@ -14,6 +14,7 @@ // 7850 and 7851 have the same commands and are essentially identical + enum model_kind { model7100 = 0x88, model7200 = 0x76, diff --git a/shuttle.h b/shuttle.h deleted file mode 100644 index 2ced3f5..0000000 --- a/shuttle.h +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef SHUTTLE_H -#define SHUTTLE_H - -#include -#include -#include -#include -#include - -#ifndef Q_OS_WIN -#include "hidapi/hidapi.h" -#else -#include "hidapi.h" -#endif - -#ifndef Q_OS_WIN -//Headers needed for sleeping. -#include -#endif - -using namespace std; - - -#define HIDDATALENGTH 64 -#define MAX_STR 255 - - -class shuttle : public QObject -{ - Q_OBJECT - -public: - shuttle(); - ~shuttle(); - int hidApiWrite(unsigned char* data, unsigned char length); - -public slots: - void init(); - void run(); - void runTimer(); - void ledControl(bool on, unsigned char num); - -signals: - void jogPlus(); - void jogMinus(); - - void doShuttle(bool plus, quint8 level); - - void button(bool,unsigned char num); - void newDevice(unsigned char devType); - -private: - hid_device* handle; - enum { NONE, shuttleXpress, shuttlePro2, RC28 }usbDevice; - bool isOpen=false; - unsigned int buttons=0; - unsigned char jogpos=0; - unsigned char shutpos=0; - unsigned char shutMult = 0; - QTime lastShuttle = QTime::currentTime(); - QByteArray lastData=""; - unsigned char lastDialPos=0; - -protected: -}; - - -#endif diff --git a/shuttlesetup.cpp b/shuttlesetup.cpp index 4d5df6e..0a22ed4 100644 --- a/shuttlesetup.cpp +++ b/shuttlesetup.cpp @@ -7,10 +7,21 @@ shuttleSetup::shuttleSetup(QWidget* parent) : ui(new Ui::shuttleSetup) { ui->setupUi(this); - scene = new QGraphicsScene(); + scene = new shuttleScene(); + connect(scene, SIGNAL(mousePressed(QPoint)), this, SLOT(mousePressed(QPoint))); ui->graphicsView->setScene(scene); textItem = scene->addText("No USB controller found"); textItem->setDefaultTextColor(Qt::gray); + + for (QString cmd : onEventCommands) { + onEvent.addItem(cmd); + } + for (QString cmd : offEventCommands) { + offEvent.addItem(cmd); + } + + connect(&onEvent, SIGNAL(currentIndexChanged(int)), this, SLOT(onEventIndexChanged(int))); + connect(&offEvent, SIGNAL(currentIndexChanged(int)), this, SLOT(offEventIndexChanged(int))); } shuttleSetup::~shuttleSetup() @@ -24,12 +35,79 @@ shuttleSetup::~shuttleSetup() } } -void shuttleSetup::newDevice(unsigned char devType) +void shuttleSetup::mousePressed(QPoint p) { + // Receive mouse event from the scene + qDebug() << "Looking for button Point x=" << p.x() << " y=" << p.y(); + bool found = false; + for (BUTTON& b : *buttons) + { + if (b.pos.contains(p)) + { + found = true; + currentButton = &b; + // Add off event first so it doesn't obscure on event. + if (offEventProxy == Q_NULLPTR) { + offEventProxy = scene->addWidget(&offEvent); + } + if (onEventProxy == Q_NULLPTR) { + onEventProxy = scene->addWidget(&onEvent); + } + onEvent.blockSignals(true); + onEvent.move(p); + onEvent.setCurrentIndex(currentButton->onEvent); + onEvent.show(); + onEvent.blockSignals(false); + + p.setY(p.y() + 40); + offEvent.blockSignals(true); + offEvent.move(p); + offEvent.setCurrentIndex(currentButton->offEvent); + offEvent.show(); + offEvent.blockSignals(false); + + } + } + + if (!found) { + onEvent.hide(); + offEvent.hide(); + } + +} + +void shuttleSetup::onEventIndexChanged(int index) { + qDebug() << "On Event for button" << currentButton->num << "Event" << index; + if (currentButton != Q_NULLPTR) { + currentButton->onEvent = index; + currentButton->onCommand.text->setPlainText(onEventCommands[index]); + currentButton->onCommand.index = index; + } +} + + +void shuttleSetup::offEventIndexChanged(int index) { + qDebug() << "Off Event for button" << currentButton->num << "Event" << index; + if (currentButton != Q_NULLPTR) { + currentButton->offEvent = index; + currentButton->offCommand.text->setPlainText(offEventCommands[index]); + currentButton->offCommand.index = index; + } +} + + +void shuttleSetup::newDevice(unsigned char devType, QVector