Skip to content

Commit

Permalink
feat: allow controller mapping to explicitely define data direction t…
Browse files Browse the repository at this point in the history
…o a device
  • Loading branch information
acolombier committed Jan 12, 2024
1 parent ed66026 commit c1660ba
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
20 changes: 18 additions & 2 deletions src/controllers/bulk/bulkcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ int BulkController::open() {

if (m_pReader != nullptr) {
qCWarning(m_logBase) << "BulkReader already present for" << getName();
} else if (m_pMapping &&
!(m_pMapping->getDeviceDirection() &
LegacyControllerMapping::DeviceDirection::IN)) {
qDebug() << "The mapping for the bulk device" << getName()
<< "doesn't require reading the data. Ignoring BulkReader "
"setup.";
} else {
m_pReader = new BulkReader(m_phandle, in_epaddr);
m_pReader->setObjectName(QString("BulkReader %1").arg(getName()));
Expand All @@ -195,10 +201,12 @@ int BulkController::close() {
qCInfo(m_logBase) << "Shutting down USB Bulk device" << getName();

// Stop the reading thread
if (m_pReader == nullptr) {
if (m_pReader == nullptr &&
m_pMapping->getDeviceDirection() &
LegacyControllerMapping::DeviceDirection::IN) {
qCWarning(m_logBase) << "BulkReader not present for" << getName()
<< "yet the device is open!";
} else {
} else if (m_pReader) {
disconnect(m_pReader, &BulkReader::incomingData, this, &BulkController::receive);
m_pReader->stop();
qCInfo(m_logBase) << " Waiting on reader to finish";
Expand Down Expand Up @@ -230,6 +238,14 @@ void BulkController::send(const QList<int>& data, unsigned int length) {
}

void BulkController::sendBytes(const QByteArray& data) {
VERIFY_OR_DEBUG_ASSERT(!m_pMapping ||
m_pMapping->getDeviceDirection() &
LegacyControllerMapping::DeviceDirection::OUT) {
qDebug() << "The mapping for the bulk device" << getName()
<< "doesn't require sending data. Ignoring sending request.";
return;
}

int ret;
int transferred;

Expand Down
17 changes: 16 additions & 1 deletion src/controllers/legacycontrollermapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class LegacyControllerMapping {
public:
LegacyControllerMapping()
: m_bDirty(false) {
: m_bDirty(false), m_deviceDirection(DeviceDirection::BIDIRECTIONNAL) {

Check failure on line 18 in src/controllers/legacycontrollermapping.h

View workflow job for this annotation

GitHub Actions / Windows 2019 (MSVC)

'LegacyControllerMapping': illegal member initialization: 'm_bDirty' is not a base or member

Check failure on line 18 in src/controllers/legacycontrollermapping.h

View workflow job for this annotation

GitHub Actions / Windows 2019 (MSVC)

'LegacyControllerMapping': illegal member initialization: 'm_deviceDirection' is not a base or member
}
virtual ~LegacyControllerMapping() = default;

Expand All @@ -32,6 +32,12 @@ class LegacyControllerMapping {
bool builtin;
};

enum DeviceDirection {
BIDIRECTIONNAL = 0b11,
IN = 0b10,

Check failure on line 37 in src/controllers/legacycontrollermapping.h

View workflow job for this annotation

GitHub Actions / Windows 2019 (MSVC)

syntax error: missing '}' before '='

Check failure on line 37 in src/controllers/legacycontrollermapping.h

View workflow job for this annotation

GitHub Actions / Windows 2019 (MSVC)

syntax error: '='
OUT = 0b01,
};

Check failure on line 39 in src/controllers/legacycontrollermapping.h

View workflow job for this annotation

GitHub Actions / Windows 2019 (MSVC)

syntax error: missing ';' before '}'

Check failure on line 39 in src/controllers/legacycontrollermapping.h

View workflow job for this annotation

GitHub Actions / Windows 2019 (MSVC)

unexpected token(s) preceding ';'

/// Adds a script file to the list of controller scripts for this mapping.
/// @param filename Name of the script file to add
/// @param functionprefix The script's function prefix (or empty string)
Expand All @@ -54,6 +60,14 @@ class LegacyControllerMapping {
return m_scripts;
}

inline void setDeviceDirection(DeviceDirection aDeviceDirection) {
m_deviceDirection = aDeviceDirection;
}

inline DeviceDirection getDeviceDirection() const {
return m_deviceDirection;
}

inline void setDirty(bool bDirty) {
m_bDirty = bDirty;
}
Expand Down Expand Up @@ -192,4 +206,5 @@ class LegacyControllerMapping {
QString m_mixxxVersion;

QList<ScriptFileInfo> m_scripts;
DeviceDirection m_deviceDirection;
};
9 changes: 9 additions & 0 deletions src/controllers/legacycontrollermappingfilehandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ void LegacyControllerMappingFileHandler::addScriptFilesToMapping(
QString deviceId = controller.attribute("id", "");
mapping->setDeviceId(deviceId);

QString deviceDirection = controller.attribute("direction", "").toLower();
if (deviceDirection == "in") {
mapping->setDeviceDirection(LegacyControllerMapping::DeviceDirection::IN);
} else if (deviceDirection == "out") {
mapping->setDeviceDirection(LegacyControllerMapping::DeviceDirection::OUT);
} else {
mapping->setDeviceDirection(LegacyControllerMapping::DeviceDirection::BIDIRECTIONNAL);
}

// Build a list of script files to load
QDomElement scriptFile = controller.firstChildElement("scriptfiles")
.firstChildElement("file");
Expand Down

0 comments on commit c1660ba

Please sign in to comment.