wfview/shuttle.cpp

89 wiersze
1.7 KiB
C++
Czysty Zwykły widok Historia

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)
{
/* 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) {
qDebug() << "unable to open device";
return;
2021-05-27 07:49:35 +00:00
}
2021-06-04 10:14:01 +00:00
qDebug() << "*************** open device success";
hid_set_nonblocking(handle, 1);
qDebug() << "************ Starting HID";
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)
{
qDebug() << "Unable to read()";
return;
}
else if (res == 5)
{
data.resize(res);
qDebug() << "Shuttle Data received: " << hex << (quint8)data[0] << ":"
<< hex << (quint8)data[1] << ":"
<< hex << (quint8)data[2] << ":"
<< hex << (quint8)data[3] << ":"
<< hex << (quint8)data[4];
emit hidDataArrived(data);
2021-06-01 16:48:19 +00:00
}
2021-06-04 10:14:01 +00:00
// Run every 50ms
QTimer::singleShot(50, this, SLOT(runTimer()));
2021-06-01 16:48:19 +00:00
}
2021-06-04 10:14:01 +00:00