Skip to content

Commit

Permalink
No double/buffer compare logic as in poll needed for explicit read op…
Browse files Browse the repository at this point in the history
…eration
  • Loading branch information
JoergAtGithub committed Jan 2, 2021
1 parent 77fa9b0 commit aeaffe2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ if(MSVC)

# http://msdn.microsoft.com/en-us/library/59a3b321.aspx
# In general, you should pick /O2 over /Ox
add_compile_options($<$<NOT:$<CONFIG:Debug>>:/O2>)
add_compile_options($<$<NOT:$<CONFIG:Debug>>:/Od>)

# Remove /RTC1 flag (conflicts with /O2)
string(REGEX REPLACE "/RTC[^ ]*" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
Expand Down Expand Up @@ -1140,6 +1140,11 @@ add_executable(mixxx WIN32 src/main.cpp)
set_target_properties(mixxx-lib PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY}")
target_link_libraries(mixxx PUBLIC mixxx-lib)

# Visual Studio Debugger startup options
set_target_properties(mixxx PROPERTIES LINK_FLAGS_RELWITHDEBINFO "/SUBSYSTEM:CONSOLE")
set_target_properties(mixxx PROPERTIES COMPILE_DEFINITIONS_RELWITHDEBINFO "_CONSOLE")
#set_target_properties(mixxx PROPERTIES VS_DEBUGGER_COMMAND_ARGUMENTS "--developer")

#
# Installation and Packaging
#
Expand Down
32 changes: 18 additions & 14 deletions src/controllers/hid/hidcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,30 +139,32 @@ int HidController::close() {

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];
unsigned char CurrentBuffer[kBufferSize];
int bytesRead;
pCurrentBuffer[0] = reportID;
bytesRead = hid_get_input_report(m_pHidDevice, pCurrentBuffer, kBufferSize);
CurrentBuffer[0] = reportID;
bytesRead = hid_get_input_report(m_pHidDevice, CurrentBuffer, 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());
if (bytesRead < 0) {
// -1 is the only error value according to hidapi documentation. Otherwise minimum possible value is 1, because 1 byte is for the reportID.
DEBUG_ASSERT(bytesRead < 0);
return QList<int>();
}

// Execute callback function in JavaScript mapping
// and print to stdout in case of --controllerDebug
auto incomingData = QByteArray::fromRawData(
reinterpret_cast<char*>(CurrentBuffer), bytesRead);
receive(incomingData, mixxx::Time::elapsed());

// Convert array of bytes read in a JavaScript compatible return type
QList<int> dataList;
dataList.reserve(bytesRead);
for (int i = 0; i < bytesRead; i++) {
dataList.append(pCurrentBuffer[i]);
dataList.append(CurrentBuffer[i]);
}
return dataList;
}
Expand Down Expand Up @@ -306,6 +308,8 @@ QList<int> HidController::getFeatureReport(
<< "serial #" << m_deviceInfo.serialNumber()
<< "(including report ID of" << reportID << ")");
}

// Convert array of bytes read in a JavaScript compatible return type
QList<int> dataList;
dataList.reserve(bytesRead);
for (int i = 0; i < bytesRead; i++) {
Expand Down

0 comments on commit aeaffe2

Please sign in to comment.