Skip to content

Commit

Permalink
Merge pull request #53 from fpoussin/feature-hid-report
Browse files Browse the repository at this point in the history
[HID] Adding feature report methods
  • Loading branch information
fpoussin authored May 13, 2020
2 parents 661f1e8 + e506dcf commit 0895ddb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/usb/qhiddevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,36 @@ qint32 QHidDevice::read(QByteArray *data, int len, int timeout)
return res;
}

/*!
\brief Send a Feature report.
*/
qint32 QHidDevice::sendFeatureReport(const QByteArray *data, int len)
{
Q_CHECK_PTR(data);
Q_D(QHidDevice);
// Default is buffer size
if (len == -1)
len = data->size();

return hid_send_feature_report(d->m_devHandle, reinterpret_cast<const unsigned char *>(data->constData()), static_cast<size_t>(len));
}

/*!
\brief Get a feature report.
*/
qint32 QHidDevice::getFeatureReport(QByteArray *data, int len)
{
Q_CHECK_PTR(data);
Q_D(QHidDevice);
// Default is buffer size
if (len == -1)
len = data->size();
// Allocate max read size
data->fill(0, len);

return hid_get_feature_report(d->m_devHandle, reinterpret_cast<unsigned char *>(data->data()), static_cast<size_t>(len));
}

/*!
\brief Returns the serial number string.
*/
Expand Down
3 changes: 3 additions & 0 deletions src/usb/qhiddevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class Q_USB_EXPORT QHidDevice : public QObject
qint32 write(const QByteArray *data, int len = -1);
qint32 read(QByteArray *data, int len = -1, int timeout = -1);

qint32 sendFeatureReport(const QByteArray *data, int len = -1);
qint32 getFeatureReport(QByteArray *data, int len = -1);

QString serialNumber();
QString manufacturer();
QString product();
Expand Down

0 comments on commit 0895ddb

Please sign in to comment.