36 #include <QMutexLocker>
41 static const int READ_TIMEOUT = 200;
42 static const int READ_SIZE = 64;
44 static const int WRITE_SIZE = 64;
46 static const int WRITE_RETRIES = 10;
60 if (wait(10000) ==
false)
61 qWarning() <<
"Cannot terminate RawHIDReadThread";
74 unsigned char buffer[READ_SIZE] = { 0 };
76 int ret = hid_read_timeout(
m_handle, buffer, READ_SIZE, READ_TIMEOUT);
86 m_readBuffer.append(reinterpret_cast<char *>(&buffer[2]), buffer[1]);
131 connect(
this, &QThread::finished,
this, &QObject::deleteLater);
135 unsigned char buffer[WRITE_SIZE] = { 0 };
159 int ret = hid_write(
m_handle, buffer, WRITE_SIZE);
165 }
else if (ret == -110)
168 RAW_HID_QXTLOG_DEBUG(
"Send Timeout: No data written to device.");
172 if (retry > WRITE_RETRIES) {
174 qWarning() <<
"[RawHID] Error writing to device";
180 RAW_HID_QXTLOG_DEBUG(
"No data written to device ??");
224 , m_deviceInfo(deviceStructure)
226 , m_writeThread(NULL)
257 qWarning() <<
"[RawHID] Failed to open USB device";
261 return QIODevice::open(mode);
264 void RawHID::sendReadyRead()
274 RAW_HID_QXTLOG_DEBUG(
"RawHID: close()");
324 emit bytesWritten(ret);
virtual qint64 bytesToWrite() const
RawHIDReadThread * m_readThread
RawHIDReadThread(hid_device *device)
virtual ~RawHIDReadThread()
void stop()
Tell the thread to stop and make sure it wakes up immediately.
virtual bool open(OpenMode mode)
virtual bool isSequential() const
RawHIDWriteThread(hid_device *device)
virtual qint64 bytesAvailable() const
int pushDataToWrite(const char *data, int size)
qint64 getBytesAvailable()
virtual ~RawHIDWriteThread()
RawHIDWriteThread * m_writeThread
virtual qint64 writeData(const char *data, qint64 maxSize)
int getReadData(char *data, int size)
virtual qint64 readData(char *data, qint64 maxSize)
QWaitCondition m_newDataToWrite