Skip to content

Commit

Permalink
Merged in upstream/Main
Browse files Browse the repository at this point in the history
  • Loading branch information
JoergAtGithub committed Dec 27, 2020
1 parent a9203e3 commit 2b74b98
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 2 deletions.
57 changes: 57 additions & 0 deletions src/controllers/hid/hidcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,35 @@ int HidController::close() {
return 0;
}

QList<int> HidController::getInputReport(unsigned int reportID) {
Trace hidRead("HidController getInputReport");
unsigned char* pPreviousBuffer = m_pPollData[m_iPollingBufferIndex];
const int currentBufferIndex = (m_iPollingBufferIndex + 1) % kNumBuffers;
unsigned char* pCurrentBuffer = m_pPollData[currentBufferIndex];
int bytesRead;
pCurrentBuffer[0] = reportID;
bytesRead = hid_get_input_report(m_pHidDevice, pCurrentBuffer, kBufferSize);
controllerDebug(bytesRead << "bytes received by hid_get_input_report" << getName()
<< "serial #" << m_deviceInfo.serialNumber()
<< "(including report ID of" << reportID << ")");
bytesRead -= kReportIdSize;

if (bytesRead == m_iLastPollSize &&
memcmp(pCurrentBuffer, pPreviousBuffer, bytesRead) == 0) {
} else {
m_iLastPollSize = bytesRead;
m_iPollingBufferIndex = currentBufferIndex;
auto incomingData = QByteArray::fromRawData(
reinterpret_cast<char*>(pCurrentBuffer), bytesRead);
receive(incomingData, mixxx::Time::elapsed());
}
QList<int> dataList;
for (int i = 0; i < bytesRead; i++) {
dataList.append(pCurrentBuffer[i]);
}
return dataList;
}

bool HidController::poll() {
Trace hidRead("HidController poll");

Expand Down Expand Up @@ -255,3 +284,31 @@ void HidController::sendFeatureReport(
ControllerJSProxy* HidController::jsProxy() {
return new HidControllerJSProxy(this);
}

QList<int> HidController::getFeatureReport(
unsigned int reportID) {
unsigned char dataRead[kReportIdSize + kBufferSize];
dataRead[0] = reportID;

int bytesRead;
bytesRead = hid_get_feature_report(m_pHidDevice,
dataRead,
kReportIdSize + kBufferSize);
if (bytesRead == -1) {
qWarning() << "getFeatureReport is unable to get data from" << getName()
<< "serial #" << m_deviceInfo.serialNumber() << ":"
<< mixxx::convertWCStringToQString(
hid_error(m_pHidDevice),
kMaxHidErrorMessageSize);
} else {
controllerDebug(bytesRead << "bytes received by getFeatureReport from" << getName()
<< "serial #" << m_deviceInfo.serialNumber()
<< "(including report ID of" << reportID << ")");
}
QList<int> dataList;
for (int i = 0; i < bytesRead; i++) {
dataList.append(dataRead[i]);
}
return dataList;
}

16 changes: 14 additions & 2 deletions src/controllers/hid/hidcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ class HidController final : public Controller {
void sendBytesReport(QByteArray data, unsigned int reportID);
void sendFeatureReport(const QList<int>& dataList, unsigned int reportID);

// Returns a pointer to the currently loaded controller mapping. For internal
// use only.
QList<int> getInputReport(unsigned int reportID);
QList<int> getFeatureReport(unsigned int reportID);

// Returns a pointer to the currently loaded controller mapping. For internal // use only.
LegacyControllerMapping* mapping() override {
return &m_mapping;
}
Expand Down Expand Up @@ -91,11 +93,21 @@ class HidControllerJSProxy : public ControllerJSProxy {
m_pHidController->sendReport(data, length, reportID);
}

Q_INVOKABLE QList<int> getInputReport(
unsigned int reportID) {
return m_pHidController->getInputReport(reportID);
}

Q_INVOKABLE void sendFeatureReport(
const QList<int>& dataList, unsigned int reportID) {
m_pHidController->sendFeatureReport(dataList, reportID);
}

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

private:
HidController* m_pHidController;
};

0 comments on commit 2b74b98

Please sign in to comment.