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 053a938 commit 666b4c2
Show file tree
Hide file tree
Showing 3 changed files with 50 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
22 changes: 21 additions & 1 deletion src/controllers/legacycontrollermapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@
class LegacyControllerMapping {
public:
LegacyControllerMapping()
: m_bDirty(false) {
: m_bDirty(false)
#ifdef MIXXX_USE_QML
,
m_deviceDirection(DeviceDirection::BIDIRECTIONNAL)
#endif
{
}
virtual ~LegacyControllerMapping() = default;

Expand All @@ -46,6 +51,11 @@ class LegacyControllerMapping {
};

#ifdef MIXXX_USE_QML
enum DeviceDirection {
BIDIRECTIONNAL = 0b11,
IN = 0b10,
OUT = 0b01,
};
struct QMLModuleInfo {
QMLModuleInfo(const QFileInfo& aDirinfo,
bool isBuiltin)
Expand Down Expand Up @@ -160,6 +170,14 @@ class LegacyControllerMapping {
const QList<ScreenInfo>& getInfoScreens() const {
return m_screens;
}

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

inline DeviceDirection getDeviceDirection() const {
return m_deviceDirection;
}
#endif

inline void setDirty(bool bDirty) {
Expand Down Expand Up @@ -303,5 +321,7 @@ class LegacyControllerMapping {
#ifdef MIXXX_USE_QML
QList<QMLModuleInfo> m_modules;
QList<ScreenInfo> m_screens;

DeviceDirection m_deviceDirection;
#endif
};
11 changes: 11 additions & 0 deletions src/controllers/legacycontrollermappingfilehandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,17 @@ void LegacyControllerMappingFileHandler::addScriptFilesToMapping(
QString deviceId = controller.attribute("id", "");
mapping->setDeviceId(deviceId);

#ifdef MIXXX_USE_QML
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);
}
#endif

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

0 comments on commit 666b4c2

Please sign in to comment.