Skip to content

Commit

Permalink
HidController: return QByteArrays for get[Input/Feature]Report
Browse files Browse the repository at this point in the history
for compatibility with HidController::poll
  • Loading branch information
Be-ing committed Nov 14, 2021
1 parent dea9f71 commit 297113b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
24 changes: 9 additions & 15 deletions src/controllers/hid/hidcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ void HidController::processInputReport(int bytesRead) {
receive(incomingData, mixxx::Time::elapsed());
}

QList<int> HidController::getInputReport(unsigned int reportID) {
QByteArray HidController::getInputReport(unsigned int reportID) {
Trace hidRead("HidController getInputReport");
int bytesRead;

Expand All @@ -186,17 +186,11 @@ QList<int> HidController::getInputReport(unsigned int reportID) {
// Otherwise minimum possible value is 1, because 1 byte is for the reportID,
// the smallest report with data is therefore 2 bytes.
DEBUG_ASSERT(bytesRead <= kReportIdSize);
return QList<int>();
return QByteArray();
}

// Convert array of bytes read in a JavaScript compatible return type
// For compatibility with the array provided by HidController::poll the reportID is contained as prefix
QList<int> dataList;
dataList.reserve(bytesRead);
for (int i = 0; i < bytesRead; i++) {
dataList.append(m_pPollData[m_pollingBufferIndex][i]);
}
return dataList;
return QByteArray(
reinterpret_cast<char*>(m_pPollData[m_pollingBufferIndex]), bytesRead);
}

bool HidController::poll() {
Expand Down Expand Up @@ -296,7 +290,7 @@ ControllerJSProxy* HidController::jsProxy() {
return new HidControllerJSProxy(this);
}

QList<int> HidController::getFeatureReport(
QByteArray HidController::getFeatureReport(
unsigned int reportID) {
unsigned char dataRead[kReportIdSize + kBufferSize];
dataRead[0] = reportID;
Expand Down Expand Up @@ -327,10 +321,10 @@ QList<int> HidController::getFeatureReport(

// Convert array of bytes read in a JavaScript compatible return type
// For compatibility with input array HidController::sendFeatureReport, a reportID prefix is not added here
QList<int> dataList;
dataList.reserve(bytesRead - kReportIdSize);
QByteArray byteArray;
byteArray.reserve(bytesRead - kReportIdSize);
for (int i = kReportIdSize; i < bytesRead; i++) {
dataList.append(dataRead[i]);
byteArray[i - 1] = dataRead[i];
}
return dataList;
return byteArray;
}
8 changes: 4 additions & 4 deletions src/controllers/hid/hidcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class HidController final : public Controller {
// as in the polling functionality (including ReportID in first byte).
// The returned list can be used to call the incomingData
// function of the common-hid-packet-parser.
QList<int> getInputReport(unsigned int reportID);
QByteArray getInputReport(unsigned int reportID);

// getFeatureReport receives a feature reports on request.
// HID doesn't support polling feature reports, therefore this is the
Expand All @@ -64,7 +64,7 @@ class HidController final : public Controller {
// changing the other bits. The returned list matches the input
// format of sendFeatureReport, allowing it to be read, modified
// and sent it back to the controller.
QList<int> getFeatureReport(unsigned int reportID);
QByteArray getFeatureReport(unsigned int reportID);

const mixxx::hid::DeviceInfo m_deviceInfo;

Expand Down Expand Up @@ -96,7 +96,7 @@ class HidControllerJSProxy : public ControllerJSProxy {
m_pHidController->sendReport(data, length, reportID);
}

Q_INVOKABLE QList<int> getInputReport(
Q_INVOKABLE QByteArray getInputReport(
unsigned int reportID) {
return m_pHidController->getInputReport(reportID);
}
Expand All @@ -106,7 +106,7 @@ class HidControllerJSProxy : public ControllerJSProxy {
m_pHidController->sendFeatureReport(dataList, reportID);
}

Q_INVOKABLE QList<int> getFeatureReport(
Q_INVOKABLE QByteArray getFeatureReport(
unsigned int reportID) {
return m_pHidController->getFeatureReport(reportID);
}
Expand Down

0 comments on commit 297113b

Please sign in to comment.