2022-10-22 22:19:52 +00:00
|
|
|
|
|
|
|
#include "usbcontroller.h"
|
|
|
|
|
2022-10-22 22:18:45 +00:00
|
|
|
#ifdef Q_OS_WIN
|
2021-08-19 09:21:09 +00:00
|
|
|
#pragma comment (lib, "Setupapi.lib")
|
2022-10-22 22:18:45 +00:00
|
|
|
#endif
|
|
|
|
|
2021-05-27 07:49:35 +00:00
|
|
|
#include <QDebug>
|
|
|
|
|
2022-04-27 11:56:54 +00:00
|
|
|
#include "logcategories.h"
|
|
|
|
|
2022-04-22 10:11:21 +00:00
|
|
|
usbController::usbController()
|
2021-05-27 07:49:35 +00:00
|
|
|
{
|
2022-04-27 11:56:54 +00:00
|
|
|
qInfo(logUsbControl()) << "Starting usbController()";
|
2021-05-27 07:49:35 +00:00
|
|
|
}
|
|
|
|
|
2022-04-22 10:11:21 +00:00
|
|
|
usbController::~usbController()
|
2021-05-27 07:49:35 +00:00
|
|
|
{
|
2022-04-27 11:56:54 +00:00
|
|
|
qInfo(logUsbControl) << "Ending usbController()";
|
2021-06-04 10:14:01 +00:00
|
|
|
hid_close(handle);
|
|
|
|
hid_exit();
|
2022-10-22 19:55:08 +00:00
|
|
|
if (gamepad != Q_NULLPTR)
|
|
|
|
{
|
|
|
|
delete gamepad;
|
|
|
|
gamepad = Q_NULLPTR;
|
|
|
|
}
|
2021-05-27 07:49:35 +00:00
|
|
|
}
|
|
|
|
|
2022-04-22 10:11:21 +00:00
|
|
|
void usbController::init()
|
2021-05-27 07:49:35 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-09-18 16:42:41 +00:00
|
|
|
void usbController::receiveCommands(QVector<COMMAND>* cmds)
|
|
|
|
{
|
|
|
|
qDebug(logUsbControl()) << "Receiving commands";
|
|
|
|
commands = cmds;
|
|
|
|
}
|
2021-05-27 07:49:35 +00:00
|
|
|
|
2022-09-18 20:00:44 +00:00
|
|
|
void usbController::receiveButtons(QVector<BUTTON>* buts)
|
|
|
|
{
|
|
|
|
qDebug(logUsbControl()) << "Receiving buttons";
|
|
|
|
buttonList = buts;
|
|
|
|
}
|
|
|
|
|
2022-04-22 10:11:21 +00:00
|
|
|
int usbController::hidApiWrite(unsigned char* data, unsigned char length)
|
2021-06-04 10:14:01 +00:00
|
|
|
{
|
2021-06-04 23:23:16 +00:00
|
|
|
Q_UNUSED(data);
|
|
|
|
Q_UNUSED(length);
|
2021-06-04 10:14:01 +00:00
|
|
|
/* int res;
|
|
|
|
unsigned char realData[length + 1];
|
|
|
|
|
|
|
|
realData[0] = length;
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < length; i++)
|
|
|
|
{
|
|
|
|
realData[i + 1] = data[i];
|
2021-05-27 07:49:35 +00:00
|
|
|
}
|
|
|
|
|
2021-06-04 10:14:01 +00:00
|
|
|
res = hid_write(handle, realData, length + 1);
|
|
|
|
if (res < 0) {
|
|
|
|
printf("Unable to write()\n");
|
|
|
|
printf("Error: %ls\n", hid_error(handle));
|
|
|
|
return -1;
|
|
|
|
}
|
2021-05-27 07:49:35 +00:00
|
|
|
|
2021-06-04 10:14:01 +00:00
|
|
|
printf("write success\n");
|
|
|
|
*/
|
|
|
|
return 0;
|
2021-05-27 07:49:35 +00:00
|
|
|
}
|
|
|
|
|
2021-06-04 10:14:01 +00:00
|
|
|
|
2022-04-22 10:11:21 +00:00
|
|
|
void usbController::run()
|
2021-05-27 07:49:35 +00:00
|
|
|
{
|
2022-09-18 16:42:41 +00:00
|
|
|
|
|
|
|
if (commands == Q_NULLPTR) {
|
|
|
|
// We are not ready yet, commands haven't been loaded!
|
|
|
|
QTimer::singleShot(1000, this, SLOT(run()));
|
|
|
|
return;
|
|
|
|
}
|
2022-04-25 16:40:41 +00:00
|
|
|
|
2022-10-22 19:55:08 +00:00
|
|
|
if (gamepad == Q_NULLPTR) {
|
|
|
|
auto gamepads = QGamepadManager::instance()->connectedGamepads();
|
|
|
|
if (!gamepads.isEmpty()) {
|
2022-10-22 22:36:19 +00:00
|
|
|
qInfo(logUsbControl()) << "Found" << gamepads.size() << "Gamepad controllers";
|
2022-10-22 19:55:08 +00:00
|
|
|
// If we got here, we have detected a gamepad of some description!
|
|
|
|
gamepad = new QGamepad(*gamepads.begin(), this);
|
2022-10-22 22:30:15 +00:00
|
|
|
qInfo(logUsbControl()) << "Gamepad 0 is " << gamepad->name();
|
2022-10-22 19:55:08 +00:00
|
|
|
|
|
|
|
if (gamepad->name() == "Microsoft X-Box 360 pad 0")
|
|
|
|
{
|
|
|
|
usbDevice = xBoxGamepad;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
usbDevice = unknownGamepad;
|
|
|
|
}
|
2022-10-23 18:13:11 +00:00
|
|
|
connect(gamepad, &QGamepad::buttonDownChanged, this, [this](bool pressed) {
|
|
|
|
qInfo(logUsbControl()) << "Button Down" << pressed;
|
|
|
|
this->buttonState("DOWN", pressed);
|
2022-10-23 18:06:48 +00:00
|
|
|
});
|
2022-10-23 18:13:11 +00:00
|
|
|
connect(gamepad, &QGamepad::buttonUpChanged, this, [this](bool pressed) {
|
|
|
|
qInfo(logUsbControl()) << "Button Up" << pressed;
|
|
|
|
this->buttonState("UP", pressed);
|
2022-10-23 18:06:48 +00:00
|
|
|
});
|
2022-10-23 18:13:11 +00:00
|
|
|
connect(gamepad, &QGamepad::buttonLeftChanged, this, [this](bool pressed) {
|
|
|
|
qInfo(logUsbControl()) << "Button Left" << pressed;
|
|
|
|
this->buttonState("LEFT", pressed);
|
2022-10-23 18:06:48 +00:00
|
|
|
});
|
2022-10-23 18:13:11 +00:00
|
|
|
connect(gamepad, &QGamepad::buttonRightChanged, this, [this](bool pressed) {
|
|
|
|
qInfo(logUsbControl()) << "Button Right" << pressed;
|
|
|
|
this->buttonState("RIGHT", pressed);
|
2022-10-23 18:06:48 +00:00
|
|
|
});
|
2022-10-23 18:13:11 +00:00
|
|
|
connect(gamepad, &QGamepad::buttonCenterChanged, this, [this](bool pressed) {
|
|
|
|
qInfo(logUsbControl()) << "Button Center" << pressed;
|
|
|
|
this->buttonState("CENTER", pressed);
|
2022-10-23 18:06:48 +00:00
|
|
|
});
|
2022-10-22 19:55:08 +00:00
|
|
|
connect(gamepad, &QGamepad::axisLeftXChanged, this, [](double value) {
|
2022-10-22 22:30:15 +00:00
|
|
|
qInfo(logUsbControl()) << "Left X" << value;
|
2022-10-22 19:55:08 +00:00
|
|
|
});
|
|
|
|
connect(gamepad, &QGamepad::axisLeftYChanged, this, [](double value) {
|
2022-10-22 22:30:15 +00:00
|
|
|
qInfo(logUsbControl()) << "Left Y" << value;
|
2022-10-22 19:55:08 +00:00
|
|
|
});
|
|
|
|
connect(gamepad, &QGamepad::axisRightXChanged, this, [](double value) {
|
2022-10-22 22:30:15 +00:00
|
|
|
qInfo(logUsbControl()) << "Right X" << value;
|
2022-10-22 19:55:08 +00:00
|
|
|
});
|
|
|
|
connect(gamepad, &QGamepad::axisRightYChanged, this, [](double value) {
|
2022-10-22 22:30:15 +00:00
|
|
|
qInfo(logUsbControl()) << "Right Y" << value;
|
2022-10-22 19:55:08 +00:00
|
|
|
});
|
2022-10-22 23:17:50 +00:00
|
|
|
connect(gamepad, &QGamepad::buttonAChanged, this, [this](bool pressed) {
|
2022-10-22 22:30:15 +00:00
|
|
|
qInfo(logUsbControl()) << "Button A" << pressed;
|
2022-10-23 17:54:18 +00:00
|
|
|
this->buttonState("A", pressed);
|
2022-10-22 19:55:08 +00:00
|
|
|
});
|
2022-10-22 23:17:50 +00:00
|
|
|
connect(gamepad, &QGamepad::buttonBChanged, this, [this](bool pressed) {
|
2022-10-22 22:30:15 +00:00
|
|
|
qInfo(logUsbControl()) << "Button B" << pressed;
|
2022-10-23 17:54:18 +00:00
|
|
|
this->buttonState("B", pressed);
|
2022-10-22 19:55:08 +00:00
|
|
|
});
|
2022-10-22 23:17:50 +00:00
|
|
|
connect(gamepad, &QGamepad::buttonXChanged, this, [this](bool pressed) {
|
2022-10-22 22:30:15 +00:00
|
|
|
qInfo(logUsbControl()) << "Button X" << pressed;
|
2022-10-23 17:54:18 +00:00
|
|
|
this->buttonState("X", pressed);
|
2022-10-22 19:55:08 +00:00
|
|
|
});
|
2022-10-22 23:17:50 +00:00
|
|
|
connect(gamepad, &QGamepad::buttonYChanged, this, [this](bool pressed) {
|
2022-10-22 22:30:15 +00:00
|
|
|
qInfo(logUsbControl()) << "Button Y" << pressed;
|
2022-10-23 17:54:18 +00:00
|
|
|
this->buttonState("Y", pressed);
|
2022-10-22 19:55:08 +00:00
|
|
|
});
|
2022-10-22 23:17:50 +00:00
|
|
|
connect(gamepad, &QGamepad::buttonL1Changed, this, [this](bool pressed) {
|
2022-10-22 22:30:15 +00:00
|
|
|
qInfo(logUsbControl()) << "Button L1" << pressed;
|
2022-10-23 17:54:18 +00:00
|
|
|
this->buttonState("L1", pressed);
|
2022-10-22 19:55:08 +00:00
|
|
|
});
|
2022-10-22 23:17:50 +00:00
|
|
|
connect(gamepad, &QGamepad::buttonR1Changed, this, [this](bool pressed) {
|
2022-10-22 22:30:15 +00:00
|
|
|
qInfo(logUsbControl()) << "Button R1" << pressed;
|
2022-10-23 17:54:18 +00:00
|
|
|
this->buttonState("R1", pressed);
|
2022-10-22 19:55:08 +00:00
|
|
|
});
|
|
|
|
connect(gamepad, &QGamepad::buttonL2Changed, this, [](double value) {
|
2022-10-22 22:30:15 +00:00
|
|
|
qInfo(logUsbControl()) << "Button L2: " << value;
|
2022-10-22 19:55:08 +00:00
|
|
|
});
|
|
|
|
connect(gamepad, &QGamepad::buttonR2Changed, this, [](double value) {
|
2022-10-22 22:30:15 +00:00
|
|
|
qInfo(logUsbControl()) << "Button R2: " << value;
|
2022-10-22 19:55:08 +00:00
|
|
|
});
|
2022-10-22 23:17:50 +00:00
|
|
|
connect(gamepad, &QGamepad::buttonSelectChanged, this, [this](bool pressed) {
|
2022-10-22 22:30:15 +00:00
|
|
|
qInfo(logUsbControl()) << "Button Select" << pressed;
|
2022-10-23 17:54:18 +00:00
|
|
|
this->buttonState("SELECT", pressed);
|
2022-10-22 19:55:08 +00:00
|
|
|
});
|
2022-10-22 23:17:50 +00:00
|
|
|
connect(gamepad, &QGamepad::buttonStartChanged, this, [this](bool pressed) {
|
2022-10-22 22:30:15 +00:00
|
|
|
qInfo(logUsbControl()) << "Button Start" << pressed;
|
2022-10-23 17:54:18 +00:00
|
|
|
this->buttonState("START", pressed);
|
2022-10-22 19:55:08 +00:00
|
|
|
});
|
2022-10-22 23:17:50 +00:00
|
|
|
connect(gamepad, &QGamepad::buttonGuideChanged, this, [this](bool pressed) {
|
2022-10-22 22:30:15 +00:00
|
|
|
qInfo(logUsbControl()) << "Button Guide" << pressed;
|
2022-10-22 19:55:08 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
emit newDevice(usbDevice, buttonList, commands); // Let the UI know we have a new controller
|
2022-10-22 22:17:34 +00:00
|
|
|
return;
|
2022-10-22 19:55:08 +00:00
|
|
|
}
|
|
|
|
}
|
2022-10-22 22:17:34 +00:00
|
|
|
else if (!gamepad->isConnected()) {
|
|
|
|
delete gamepad;
|
|
|
|
gamepad = Q_NULLPTR;
|
2022-10-22 19:55:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-04 10:14:01 +00:00
|
|
|
handle = hid_open(0x0b33, 0x0020, NULL);
|
|
|
|
if (!handle) {
|
2021-06-04 23:23:16 +00:00
|
|
|
handle = hid_open(0x0b33, 0x0030, NULL);
|
|
|
|
if (!handle) {
|
|
|
|
handle = hid_open(0x0C26, 0x001E, NULL);
|
|
|
|
if (!handle) {
|
2021-08-28 22:27:18 +00:00
|
|
|
usbDevice = NONE;
|
2021-06-04 23:23:16 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
usbDevice = RC28;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
usbDevice = shuttlePro2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
usbDevice = shuttleXpress;
|
|
|
|
}
|
2021-08-28 22:27:18 +00:00
|
|
|
|
2021-06-04 23:23:16 +00:00
|
|
|
if (handle)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
wchar_t manufacturer[MAX_STR];
|
|
|
|
wchar_t product[MAX_STR];
|
2022-04-27 11:56:54 +00:00
|
|
|
wchar_t serial[MAX_STR];
|
|
|
|
|
2021-06-04 23:23:16 +00:00
|
|
|
res = hid_get_manufacturer_string(handle, manufacturer, MAX_STR);
|
2022-04-27 11:56:54 +00:00
|
|
|
if (res > -1)
|
|
|
|
{
|
|
|
|
this->manufacturer = QString::fromWCharArray(manufacturer);
|
|
|
|
}
|
|
|
|
|
2021-06-04 23:23:16 +00:00
|
|
|
res = hid_get_product_string(handle, product, MAX_STR);
|
2022-04-27 11:56:54 +00:00
|
|
|
if (res > -1)
|
|
|
|
{
|
|
|
|
this->product = QString::fromWCharArray(product);
|
|
|
|
}
|
|
|
|
|
|
|
|
res = hid_get_serial_number_string(handle, serial, MAX_STR);
|
|
|
|
if (res > -1)
|
|
|
|
{
|
|
|
|
this->serial = QString::fromWCharArray(serial);
|
|
|
|
}
|
|
|
|
|
|
|
|
qInfo(logUsbControl()) << QString("Found Device: %0 from %1 S/N %2").arg(this->product).arg(this->manufacturer).arg(this->serial);
|
2021-06-04 23:23:16 +00:00
|
|
|
hid_set_nonblocking(handle, 1);
|
2022-09-18 20:00:44 +00:00
|
|
|
emit newDevice(usbDevice, buttonList, commands); // Let the UI know we have a new controller
|
2021-06-04 23:23:16 +00:00
|
|
|
QTimer::singleShot(0, this, SLOT(runTimer()));
|
2022-10-22 22:17:34 +00:00
|
|
|
return;
|
2021-05-27 07:49:35 +00:00
|
|
|
}
|
2022-10-22 19:55:08 +00:00
|
|
|
|
2022-10-22 22:17:34 +00:00
|
|
|
// No devices found, schedule another check in 1000ms
|
|
|
|
QTimer::singleShot(1000, this, SLOT(run()));
|
|
|
|
|
2021-05-27 07:49:35 +00:00
|
|
|
}
|
|
|
|
|
2022-04-22 10:11:21 +00:00
|
|
|
void usbController::runTimer()
|
2021-06-01 16:48:19 +00:00
|
|
|
{
|
2021-08-22 08:34:00 +00:00
|
|
|
int res=1;
|
|
|
|
while (res > 0) {
|
|
|
|
QByteArray data(HIDDATALENGTH, 0x0);
|
|
|
|
res = hid_read(handle, (unsigned char*)data.data(), HIDDATALENGTH);
|
|
|
|
if (res < 0)
|
2021-06-04 23:23:16 +00:00
|
|
|
{
|
2022-04-27 11:56:54 +00:00
|
|
|
qInfo(logUsbControl()) << "USB Device disconnected" << this->product;
|
2022-10-22 22:17:34 +00:00
|
|
|
emit newDevice(0, buttonList, commands);
|
2022-04-27 11:56:54 +00:00
|
|
|
this->product = "";
|
|
|
|
this->manufacturer = "";
|
|
|
|
this->serial = "<none>";
|
2021-08-22 08:34:00 +00:00
|
|
|
hid_close(handle);
|
|
|
|
QTimer::singleShot(1000, this, SLOT(run()));
|
|
|
|
return;
|
2021-06-04 23:23:16 +00:00
|
|
|
}
|
2021-08-22 08:34:00 +00:00
|
|
|
else if (res == 5 && (usbDevice == shuttleXpress || usbDevice == shuttlePro2))
|
2021-06-04 23:23:16 +00:00
|
|
|
{
|
2021-08-22 08:34:00 +00:00
|
|
|
data.resize(res);
|
2022-10-22 22:17:34 +00:00
|
|
|
|
2022-04-27 11:56:54 +00:00
|
|
|
/*qDebug(logUsbControl()) << "usbController Data received " << hex << (unsigned char)data[0] << ":"
|
2021-08-22 08:34:00 +00:00
|
|
|
<< hex << (unsigned char)data[1] << ":"
|
|
|
|
<< hex << (unsigned char)data[2] << ":"
|
|
|
|
<< hex << (unsigned char)data[3] << ":"
|
|
|
|
<< hex << (unsigned char)data[4];
|
2022-04-22 10:11:21 +00:00
|
|
|
*/
|
2021-08-22 08:34:00 +00:00
|
|
|
unsigned int tempButtons = (unsigned int)((unsigned char)data[3] | (unsigned char)data[4] << 8);
|
|
|
|
unsigned char tempJogpos = (unsigned char)data[1];
|
|
|
|
unsigned char tempShutpos = (unsigned char)data[0];
|
|
|
|
|
|
|
|
if (tempJogpos == jogpos + 1 || (tempJogpos == 0 && jogpos == 0xff))
|
2021-08-19 09:21:09 +00:00
|
|
|
{
|
2022-04-26 07:52:08 +00:00
|
|
|
jogCounter++;
|
2022-04-27 11:56:54 +00:00
|
|
|
//qDebug(logUsbControl()) << "JOG PLUS" << jogCounter;
|
2021-08-22 08:34:00 +00:00
|
|
|
}
|
|
|
|
else if (tempJogpos != jogpos) {
|
2022-04-26 07:52:08 +00:00
|
|
|
jogCounter--;
|
2022-04-27 11:56:54 +00:00
|
|
|
//qDebug(logUsbControl()) << "JOG MINUS" << jogCounter;
|
2021-08-22 08:34:00 +00:00
|
|
|
}
|
2021-06-04 10:14:01 +00:00
|
|
|
|
2021-08-22 08:34:00 +00:00
|
|
|
/* Button matrix:
|
|
|
|
1000000000000000 = button15
|
|
|
|
0100000000000000 = button14
|
|
|
|
0010000000000000 = button13
|
|
|
|
0001000000000000 = button12
|
|
|
|
0000100000000000 = button11
|
|
|
|
0000010000000000 = button10
|
|
|
|
0000001000000000 = button9
|
|
|
|
0000000100000000 = button8 - xpress0
|
|
|
|
0000000010000000 = button7 - xpress1
|
|
|
|
0000000001000000 = button6 - xpress2
|
|
|
|
0000000000100000 = button5 - xpress3
|
|
|
|
0000000000010000 = button4 - xpress4
|
|
|
|
0000000000001000 = button3
|
|
|
|
0000000000000100 = button2
|
|
|
|
0000000000000010 = button1
|
|
|
|
0000000000000001 = button0
|
|
|
|
*/
|
|
|
|
if (buttons != tempButtons)
|
|
|
|
{
|
2022-09-18 20:00:44 +00:00
|
|
|
|
|
|
|
|
2021-08-22 08:34:00 +00:00
|
|
|
|
|
|
|
// Step through all buttons and emit ones that have been pressed.
|
|
|
|
for (unsigned char i = 0; i < 16; i++)
|
|
|
|
{
|
2022-09-18 20:00:44 +00:00
|
|
|
|
|
|
|
for (BUTTON* but = buttonList->begin(); but != buttonList->end(); but++) {
|
|
|
|
if (but->dev == usbDevice && but->num == i) {
|
|
|
|
|
|
|
|
if ((tempButtons >> i & 1) && !(buttons >> i & 1) && but->onCommand->index > 0)
|
|
|
|
{
|
2022-10-22 22:30:15 +00:00
|
|
|
qInfo(logUsbControl()) << "On Button event:" << but->onCommand->text;
|
2022-09-18 20:00:44 +00:00
|
|
|
emit button(but->onCommand);
|
|
|
|
}
|
|
|
|
else if ((buttons >> i & 1) && !(tempButtons >> i & 1) && but->offCommand->index > 0)
|
|
|
|
{
|
2022-10-22 22:30:15 +00:00
|
|
|
qInfo(logUsbControl()) << "Off Button event:" << but->offCommand->text;
|
2022-09-18 20:00:44 +00:00
|
|
|
emit button(but->offCommand);
|
|
|
|
}
|
2022-04-22 10:11:21 +00:00
|
|
|
}
|
|
|
|
}
|
2021-08-22 08:34:00 +00:00
|
|
|
}
|
|
|
|
}
|
2021-06-07 13:05:57 +00:00
|
|
|
|
2021-08-22 08:34:00 +00:00
|
|
|
buttons = tempButtons;
|
|
|
|
jogpos = tempJogpos;
|
|
|
|
shutpos = tempShutpos;
|
2021-06-07 13:05:57 +00:00
|
|
|
|
|
|
|
}
|
2021-08-22 08:34:00 +00:00
|
|
|
else if (res == 64 && usbDevice == RC28)
|
|
|
|
{
|
|
|
|
// This is a response from the Icom RC28
|
|
|
|
data.resize(8); // Might as well get rid of the unused data.
|
2021-08-28 22:27:18 +00:00
|
|
|
|
|
|
|
if (lastData.size() != 8) {
|
|
|
|
lastData = data;
|
|
|
|
}
|
|
|
|
|
2021-08-22 08:34:00 +00:00
|
|
|
if (((unsigned char)data[5] == 0x06) && ((unsigned char)lastData[5] != 0x06))
|
|
|
|
{
|
2022-04-26 13:50:16 +00:00
|
|
|
//emit button(true, 6);
|
2021-08-22 08:34:00 +00:00
|
|
|
}
|
|
|
|
else if (((unsigned char)data[5] != 0x06) && ((unsigned char)lastData[5] == 0x06))
|
|
|
|
{
|
2022-04-26 13:50:16 +00:00
|
|
|
//emit button(false, 6);
|
2021-08-22 08:34:00 +00:00
|
|
|
}
|
|
|
|
else if (((unsigned char)data[5] == 0x03) && ((unsigned char)lastData[5] != 0x03))
|
|
|
|
{
|
2022-04-26 13:50:16 +00:00
|
|
|
//emit button(true, 7);
|
2021-08-22 08:34:00 +00:00
|
|
|
}
|
|
|
|
else if (((unsigned char)data[5] != 0x03) && ((unsigned char)lastData[5] == 0x03))
|
|
|
|
{
|
2022-04-26 13:50:16 +00:00
|
|
|
//emit button(false, 7);
|
2021-08-22 08:34:00 +00:00
|
|
|
}
|
|
|
|
else if (((unsigned char)data[5] == 0x7d) && ((unsigned char)lastData[5] != 0x7d))
|
|
|
|
{
|
2022-04-26 13:50:16 +00:00
|
|
|
//emit button(true, 5);
|
2021-08-22 08:34:00 +00:00
|
|
|
}
|
|
|
|
else if (((unsigned char)data[5] != 0x7d) && ((unsigned char)lastData[5] == 0x7d))
|
|
|
|
{
|
2022-04-26 13:50:16 +00:00
|
|
|
//emit button(false, 5);
|
2021-08-22 08:34:00 +00:00
|
|
|
}
|
2021-06-08 07:04:41 +00:00
|
|
|
|
2021-08-22 08:34:00 +00:00
|
|
|
if ((unsigned char)data[5] == 0x07)
|
|
|
|
{
|
2022-04-22 10:11:21 +00:00
|
|
|
if ((unsigned char)data[3] == 0x01)
|
2021-08-22 08:34:00 +00:00
|
|
|
{
|
2022-04-27 11:56:54 +00:00
|
|
|
//qDebug(logUsbControl()) << "Frequency UP";
|
2022-04-26 07:52:08 +00:00
|
|
|
jogCounter++;
|
2022-04-22 10:11:21 +00:00
|
|
|
//emit jogPlus();
|
2021-08-22 08:34:00 +00:00
|
|
|
}
|
|
|
|
else if ((unsigned char)data[3] == 0x02)
|
|
|
|
{
|
2022-04-27 11:56:54 +00:00
|
|
|
//qDebug(logUsbControl()) << "Frequency DOWN";
|
2022-04-22 10:11:21 +00:00
|
|
|
emit jogMinus();
|
2022-04-26 07:52:08 +00:00
|
|
|
jogCounter--;
|
2021-08-22 08:34:00 +00:00
|
|
|
}
|
|
|
|
}
|
2021-08-28 22:27:18 +00:00
|
|
|
|
2021-08-22 08:34:00 +00:00
|
|
|
lastData = data;
|
|
|
|
}
|
2021-06-08 07:04:41 +00:00
|
|
|
|
2022-04-22 10:11:21 +00:00
|
|
|
if (lastusbController.msecsTo(QTime::currentTime()) >= 500 || lastusbController > QTime::currentTime())
|
2021-08-19 09:21:09 +00:00
|
|
|
{
|
2022-04-26 07:52:08 +00:00
|
|
|
if (shutpos < 0x08)
|
2021-08-22 08:34:00 +00:00
|
|
|
{
|
|
|
|
shutMult = shutpos;
|
|
|
|
emit doShuttle(true, shutMult);
|
2022-04-27 11:56:54 +00:00
|
|
|
//qDebug(logUsbControl()) << "Shuttle PLUS" << shutMult;
|
2021-06-08 07:04:41 +00:00
|
|
|
|
2021-08-22 08:34:00 +00:00
|
|
|
}
|
2022-04-26 07:52:08 +00:00
|
|
|
else if (shutpos > 0xEF) {
|
2021-08-22 08:34:00 +00:00
|
|
|
shutMult = abs(shutpos - 0xff) + 1;
|
|
|
|
emit doShuttle(false, shutMult);
|
2022-04-27 11:56:54 +00:00
|
|
|
//qDebug(logUsbControl()) << "Shuttle MINUS" << shutMult;
|
2022-04-22 10:11:21 +00:00
|
|
|
}
|
2022-04-26 07:52:08 +00:00
|
|
|
if (jogCounter != 0) {
|
2022-10-22 22:17:34 +00:00
|
|
|
emit sendJog(jogCounter);
|
2022-04-27 11:58:42 +00:00
|
|
|
//qDebug(logUsbControl()) << "Change Frequency by" << jogCounter << "hz";
|
2022-04-26 07:52:08 +00:00
|
|
|
jogCounter = 0;
|
2021-08-22 08:34:00 +00:00
|
|
|
}
|
2022-04-22 10:11:21 +00:00
|
|
|
|
|
|
|
lastusbController = QTime::currentTime();
|
2021-08-19 09:21:09 +00:00
|
|
|
}
|
2021-06-08 07:04:41 +00:00
|
|
|
|
2021-08-22 08:34:00 +00:00
|
|
|
}
|
2021-06-04 23:23:16 +00:00
|
|
|
// Run every 25ms
|
|
|
|
QTimer::singleShot(25, this, SLOT(runTimer()));
|
2021-06-01 16:48:19 +00:00
|
|
|
}
|
2021-06-04 10:14:01 +00:00
|
|
|
|
2022-04-22 10:11:21 +00:00
|
|
|
void usbController::ledControl(bool on, unsigned char num)
|
2021-08-22 08:34:00 +00:00
|
|
|
{
|
2022-04-22 10:11:21 +00:00
|
|
|
if (usbDevice == RC28) {
|
|
|
|
QByteArray data(9, 0x0);
|
|
|
|
data[0] = 8;
|
|
|
|
data[1] = 0x01;
|
|
|
|
unsigned char ledNum = 0x07;
|
|
|
|
if (on)
|
|
|
|
ledNum &= ~(1ULL << (num - 1));
|
2021-08-23 09:02:16 +00:00
|
|
|
|
2022-04-22 10:11:21 +00:00
|
|
|
data[2] = ledNum;
|
2021-08-22 08:34:00 +00:00
|
|
|
|
2022-04-22 10:11:21 +00:00
|
|
|
int res = hid_write(handle, (const unsigned char*)data.constData(), 8);
|
2021-08-22 08:34:00 +00:00
|
|
|
|
2022-04-22 10:11:21 +00:00
|
|
|
if (res < 0) {
|
2022-04-27 11:56:54 +00:00
|
|
|
qDebug(logUsbControl()) << "Unable to write(), Error:" << hid_error(handle);
|
2022-04-22 10:11:21 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-08-22 08:34:00 +00:00
|
|
|
|
2022-04-27 11:56:54 +00:00
|
|
|
qDebug(logUsbControl()) << "write() success";
|
2021-08-22 08:34:00 +00:00
|
|
|
}
|
2022-10-22 23:02:44 +00:00
|
|
|
}
|
|
|
|
|
2022-10-23 17:54:18 +00:00
|
|
|
void usbController::buttonState(QString name, bool val)
|
2022-10-22 23:02:44 +00:00
|
|
|
{
|
|
|
|
for (BUTTON* but = buttonList->begin(); but != buttonList->end(); but++) {
|
2022-10-23 17:54:18 +00:00
|
|
|
if (but->dev == usbDevice && but->name == name) {
|
2022-10-22 23:02:44 +00:00
|
|
|
|
|
|
|
if (val && but->onCommand->index > 0) {
|
2022-10-23 18:06:48 +00:00
|
|
|
qInfo(logUsbControl()) << "On Button" << but->name << "event:" << but->onCommand->text;
|
2022-10-22 23:02:44 +00:00
|
|
|
emit button(but->onCommand);
|
|
|
|
}
|
|
|
|
if (!val && but->offCommand->index > 0) {
|
2022-10-23 18:06:48 +00:00
|
|
|
qInfo(logUsbControl()) << "Off Button" << but->name << "event:" << but->offCommand->text;
|
2022-10-22 23:02:44 +00:00
|
|
|
emit button(but->offCommand);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-10-23 18:06:48 +00:00
|
|
|
}
|
|
|
|
void usbController::buttonState(QString name, double val)
|
|
|
|
{
|
|
|
|
for (BUTTON* but = buttonList->begin(); but != buttonList->end(); but++) {
|
|
|
|
if (but->dev == usbDevice && but->name == name) {
|
2022-10-22 23:02:44 +00:00
|
|
|
|
2022-10-23 18:06:48 +00:00
|
|
|
if (val && but->onCommand->index > 0) {
|
|
|
|
qInfo(logUsbControl()) << "On Button" << but->name << "event:" << but->onCommand->text;
|
|
|
|
emit button(but->onCommand);
|
|
|
|
}
|
|
|
|
if (!val && but->offCommand->index > 0) {
|
|
|
|
qInfo(logUsbControl()) << "Off Button" << but->name << "event:" << but->offCommand->text;
|
|
|
|
emit button(but->offCommand);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-08-22 08:34:00 +00:00
|
|
|
}
|