2021-05-27 07:49:35 +00:00
|
|
|
#include "shuttle.h"
|
|
|
|
#include <QDebug>
|
|
|
|
|
2021-06-04 10:14:01 +00:00
|
|
|
shuttle::shuttle()
|
2021-05-27 07:49:35 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
shuttle::~shuttle()
|
|
|
|
{
|
2021-06-04 10:14:01 +00:00
|
|
|
qDebug() << "************ Ending HID";
|
|
|
|
hid_close(handle);
|
|
|
|
hid_exit();
|
2021-05-27 07:49:35 +00:00
|
|
|
}
|
|
|
|
|
2021-06-01 16:48:19 +00:00
|
|
|
void shuttle::init()
|
2021-05-27 07:49:35 +00:00
|
|
|
{
|
2021-06-01 16:48:19 +00:00
|
|
|
|
2021-05-27 07:49:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-04 10:14:01 +00:00
|
|
|
int shuttle::hidApiWrite(unsigned char* data, unsigned char length)
|
|
|
|
{
|
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
|
|
|
|
|
|
|
void shuttle::run()
|
2021-05-27 07:49:35 +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) {
|
|
|
|
QTimer::singleShot(1000, this, SLOT(run()));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
usbDevice = RC28;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
usbDevice = shuttlePro2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
usbDevice = shuttleXpress;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (handle)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
wchar_t manufacturer[MAX_STR];
|
|
|
|
wchar_t product[MAX_STR];
|
|
|
|
res = hid_get_manufacturer_string(handle, manufacturer, MAX_STR);
|
|
|
|
res = hid_get_product_string(handle, product, MAX_STR);
|
|
|
|
qDebug() << QString("Found Device: %0 from %1").arg(QString::fromWCharArray(product)).arg(QString::fromWCharArray(manufacturer));
|
|
|
|
hid_set_nonblocking(handle, 1);
|
|
|
|
QTimer::singleShot(0, this, SLOT(runTimer()));
|
2021-05-27 07:49:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-04 10:14:01 +00:00
|
|
|
void shuttle::runTimer()
|
2021-06-01 16:48:19 +00:00
|
|
|
{
|
2021-06-04 10:14:01 +00:00
|
|
|
int res;
|
|
|
|
QByteArray data(HIDDATALENGTH,0x0);
|
|
|
|
res = hid_read(handle, (unsigned char *)data.data(), HIDDATALENGTH);
|
|
|
|
if (res == 0)
|
|
|
|
;//printf("waiting...\n");
|
|
|
|
else if (res < 0)
|
|
|
|
{
|
2021-06-04 23:23:16 +00:00
|
|
|
qDebug() << "USB Device disconnected?";
|
|
|
|
hid_close(handle);
|
|
|
|
QTimer::singleShot(1000, this, SLOT(run()));
|
2021-06-04 10:14:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (res == 5)
|
|
|
|
{
|
|
|
|
data.resize(res);
|
2021-06-04 12:08:14 +00:00
|
|
|
qDebug() << "Shuttle Data received: " << hex << (unsigned char)data[0] << ":"
|
|
|
|
<< hex << (unsigned char)data[1] << ":"
|
|
|
|
<< hex << (unsigned char)data[2] << ":"
|
|
|
|
<< hex << (unsigned char)data[3] << ":"
|
|
|
|
<< hex << (unsigned char)data[4];
|
|
|
|
|
2021-06-04 23:23:16 +00:00
|
|
|
unsigned int tempButtons = unsigned int((unsigned char)data[3] | (unsigned char)data[4] << 8);
|
2021-06-04 12:08:14 +00:00
|
|
|
unsigned char tempJogpos = (unsigned char)data[1];
|
|
|
|
unsigned char tempShutpos = (unsigned char)data[0];
|
|
|
|
|
2021-06-04 23:23:16 +00:00
|
|
|
if (tempJogpos == jogpos +1 || (tempJogpos == 0 && jogpos == 0xff))
|
|
|
|
{
|
|
|
|
qDebug() << "JOG PLUS";
|
|
|
|
emit jogPlus();
|
|
|
|
}
|
|
|
|
else if (tempJogpos != jogpos) {
|
|
|
|
qDebug() << "JOG MINUS";
|
|
|
|
emit jogMinus();
|
2021-06-04 12:08:14 +00:00
|
|
|
}
|
2021-06-04 23:23:16 +00:00
|
|
|
|
|
|
|
|
2021-06-04 12:08:14 +00:00
|
|
|
if (tempShutpos == shutpos + 1)
|
|
|
|
{
|
2021-06-04 23:23:16 +00:00
|
|
|
qDebug() << "SHUTTLE PLUS";
|
2021-06-04 12:08:14 +00:00
|
|
|
}
|
|
|
|
else if (tempShutpos == shutpos-1) {
|
2021-06-04 23:23:16 +00:00
|
|
|
qDebug() << "SHUTTLE MINUS";
|
2021-06-04 12:08:14 +00:00
|
|
|
}
|
2021-06-04 23:23:16 +00:00
|
|
|
/* Button matrix:
|
|
|
|
1000000000000000 = button15
|
|
|
|
0100000000000000 = button14
|
|
|
|
0010000000000000 = button13
|
|
|
|
0001000000000000 = button12
|
|
|
|
0000100000000000 = button11
|
|
|
|
0000010000000000 = button10
|
|
|
|
0000001000000000 = button9
|
|
|
|
0000000100000000 = button8 - xpress1
|
|
|
|
0000000010000000 = button7 - xpress2
|
|
|
|
0000000001000000 = button6 - xpress3
|
|
|
|
0000000000100000 = button5 - xpress4
|
|
|
|
0000000000010000 = button4 - xpress5
|
|
|
|
0000000000001000 = button3
|
|
|
|
0000000000000100 = button2
|
|
|
|
0000000000000010 = button1
|
|
|
|
0000000000000001 = button0
|
|
|
|
*/
|
|
|
|
if (buttons != tempButtons)
|
|
|
|
{
|
|
|
|
qDebug() << "BUTTON: " << qSetFieldWidth(16) << bin << tempButtons;
|
|
|
|
|
|
|
|
// Step size down
|
|
|
|
if ((tempButtons >> 5 & 1) && !(buttons >> 5 & 1))
|
|
|
|
emit button5(true);
|
|
|
|
// PTT on and off
|
|
|
|
if ((tempButtons >> 6 & 1) && !(buttons >> 6 & 1))
|
|
|
|
emit button6(true);
|
|
|
|
else if ((buttons >> 6 & 1) && !(tempButtons >> 6 & 1))
|
|
|
|
emit button6(false);
|
|
|
|
// Step size up
|
|
|
|
if ((tempButtons >> 7 & 1) && !(buttons >> 7 & 1))
|
|
|
|
emit button7(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
buttons = unsigned int((unsigned char)data[3] | (unsigned char)data[4] << 8);
|
2021-06-04 12:08:14 +00:00
|
|
|
jogpos = (unsigned char)data[1];
|
|
|
|
shutpos = (unsigned char)data[0];
|
2021-06-04 10:14:01 +00:00
|
|
|
|
2021-06-01 16:48:19 +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
|
|
|
|