Skip to content

Commit

Permalink
Merge pull request #40 from OOPMan/issue_34_implement_support_for_soc…
Browse files Browse the repository at this point in the history
…d_cleaning

Issue 34 implement support for socd cleaning
  • Loading branch information
OOPMan authored Jul 26, 2022
2 parents 33b3eff + c4f4d63 commit 747888f
Show file tree
Hide file tree
Showing 11 changed files with 215 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ libusbK
# Ignore installer artifacts
xbofs.win.7z
XBOFS.win.1.0.0.exe
*.installer.exe
VC_redist.*

# Ignore vcpkg dependencies
vcpkg_installed
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ Head over to the [main website](https://xbofs.win) to view the installation inst

In order to compile this project you will need:
* [Microsoft Visual Studio Community 2019](https://visualstudio.microsoft.com)
* [Qt 5.x](https://www.qt.io/download-qt-installer)
* [Qt 6.1.x](https://www.qt.io/download-qt-installer)
* [Windows SDK 10.0.19041.0](https://download.microsoft.com/download/1/c/3/1c3d5161-d9e9-4e4b-9b43-b70fe8be268c/windowssdk/winsdksetup.exe)
* [WDK for Windows 10, version 2004](https://docs.microsoft.com/en-ca/windows-hardware/drivers/download-the-wdk)
* [WDK 8 Redistributable components](https://docs.microsoft.com/en-us/windows-hardware/drivers/other-wdk-downloads)
* [vcpkg](https://github.com/microsoft/vcpkg)
* [spdlog](https://github.com/gabime/spdlog) installed using vcpkg: `vcpkg install spdlog:x64-windows`
* [VigEmClient](https://github.com/ViGEm/ViGEmClient)
* VigEmClient exists as a Git sub-module within this repository. A full checkout including sub-modules will automatically pull it in
* [libwdi](https://github.com/pbatard/libwdi/)
Expand Down
21 changes: 20 additions & 1 deletion XBOFS.win.qt/ConfigureBindingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,21 @@ ConfigureBindingsDialog::ConfigureBindingsDialog(QWidget *parent)
connect(ui.ltButtonPushButton, &QPushButton::clicked, this, &ConfigureBindingsDialog::handleLTButtonPushButtonClicked);
connect(ui.viewButtonPushButton, &QPushButton::clicked, this, &ConfigureBindingsDialog::handleViewButtonPushButtonClicked);
connect(ui.startButtonPushButton, &QPushButton::clicked, this, &ConfigureBindingsDialog::handleStartButtonPushButtonClicked);
connect(ui.enableSOCDCleaningCheckBox, &QCheckBox::stateChanged, this, &ConfigureBindingsDialog::handleEnableSOCDCleaningCheckBoxStateChanged);
}

ConfigureBindingsDialog::~ConfigureBindingsDialog()
{
delete controlBindingDialog;
}

void ConfigureBindingsDialog::accept() {
settings.setValue(SOCD_CLEANING_ENABLED, ui.enableSOCDCleaningCheckBox->isChecked());
settings.setValue(SOCD_CLEAN_UP_DOWN_TO, ui.cleanUpDownToComboBox->currentIndex());
settings.setValue(SOCD_CLEAN_LEFT_RIGHT_TO, ui.cleanLeftRightToComboBox->currentIndex());
QDialog::accept();
}

void ConfigureBindingsDialog::open(QString vendorId, QString productId, QString product, QString serialNumber, QString profile, bool alternativeBindings) {
this->vendorId = vendorId;
this->productId = productId;
Expand All @@ -35,7 +43,13 @@ void ConfigureBindingsDialog::open(QString vendorId, QString productId, QString
this->profile = profile;
this->alternativeBindings = alternativeBindings;
auto prefix = QString(alternativeBindings ? "Alternative Bindings": "Bindings");
setWindowTitle(QString("%1: Configuring %2 for %3 (S/N: %4)").arg(APPLICATION, prefix, product, serialNumber));
setWindowTitle(QString("%1: Configuring %2 for %3 (S/N: %4)").arg(APPLICATION, prefix, product, serialNumber));
while (settings.group() != "") settings.endGroup();
auto group = QString("%1/%2/%3/%4/%5").arg(vendorId, productId, serialNumber, profile, QString::number(alternativeBindings));
settings.beginGroup(group);
ui.enableSOCDCleaningCheckBox->setChecked(settings.value(SOCD_CLEANING_ENABLED, false).toBool());
ui.cleanUpDownToComboBox->setCurrentIndex(settings.value(SOCD_CLEAN_UP_DOWN_TO, ui.cleanUpDownToComboBox->currentIndex()).toInt());
ui.cleanLeftRightToComboBox->setCurrentIndex(settings.value(SOCD_CLEAN_LEFT_RIGHT_TO, ui.cleanLeftRightToComboBox->currentIndex()).toInt());
QDialog::open();
}

Expand Down Expand Up @@ -94,3 +108,8 @@ void ConfigureBindingsDialog::handleViewButtonPushButtonClicked(bool checked) {
void ConfigureBindingsDialog::handleStartButtonPushButtonClicked(bool checked) {
controlBindingDialog->open(vendorId, productId, product, serialNumber, profile, alternativeBindings, XBOFSWin::XBO_ARCADE_STICK_BUTTONS::START);
}

void ConfigureBindingsDialog::handleEnableSOCDCleaningCheckBoxStateChanged(int state) {
ui.SOCDCleaningFrame->setEnabled((bool)state);
}

5 changes: 4 additions & 1 deletion XBOFS.win.qt/ConfigureBindingsDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ConfigureBindingsDialog : public QDialog
~ConfigureBindingsDialog();

public slots:
void accept();
void open(QString vendorId, QString productId, QString product, QString serialNumber, QString profile, bool alternativeBindings);
void handleStickUpPushButtonClicked(bool checked = false);
void handleStickDownPushButtonClicked(bool checked = false);
Expand All @@ -32,7 +33,8 @@ public slots:
void handleLBButtonPushButtonClicked(bool checked = false);
void handleLTButtonPushButtonClicked(bool checked = false);
void handleViewButtonPushButtonClicked(bool checked = false);
void handleStartButtonPushButtonClicked(bool checked = false);
void handleStartButtonPushButtonClicked(bool checked = false);
void handleEnableSOCDCleaningCheckBoxStateChanged(int state);

protected:
QString vendorId;
Expand All @@ -43,4 +45,5 @@ public slots:
bool alternativeBindings;
Ui::ConfigureBindingsDialog ui;
ControlBindingDialog* controlBindingDialog;
QSettings settings = QSettings(ORGANIZATION, APPLICATION);
};
94 changes: 87 additions & 7 deletions XBOFS.win.qt/ConfigureBindingsDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,17 @@
<x>0</x>
<y>0</y>
<width>883</width>
<height>297</height>
<height>306</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Buttons</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="6">
Expand Down Expand Up @@ -124,6 +121,89 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>SOCD Cleaning</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QCheckBox" name="enableSOCDCleaningCheckBox">
<property name="text">
<string>Enabled</string>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="SOCDCleaningFrame">
<property name="enabled">
<bool>false</bool>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Clean Up + Down to</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="cleanUpDownToComboBox">
<item>
<property name="text">
<string>Neutral</string>
</property>
</item>
<item>
<property name="text">
<string>Up</string>
</property>
</item>
<item>
<property name="text">
<string>Down</string>
</property>
</item>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Clean Left + Right to</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="cleanLeftRightToComboBox">
<item>
<property name="text">
<string>Neutral</string>
</property>
</item>
<item>
<property name="text">
<string>Left</string>
</property>
</item>
<item>
<property name="text">
<string>Right</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
Expand Down
1 change: 0 additions & 1 deletion XBOFS.win.qt/ControlBindingDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,3 @@ void ControlBindingDialog::open(QString vendorId, QString productId, QString pro
void ControlBindingDialog::handleBindCheckBoxStateChanged(int state) {
ui.controlPanelWidget->setEnabled((bool)state);
}

5 changes: 5 additions & 0 deletions XBOFS.win.qt/WinUsbDeviceWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,11 @@
<string>Press Guide button to Switch between Bindings and Alternate Bindings</string>
</property>
</item>
<item>
<property name="text">
<string>Normal (Disables access to Alternate Bindings)</string>
</property>
</item>
</widget>
</item>
</layout>
Expand Down
13 changes: 11 additions & 2 deletions XBOFS.win.qt/XBOFS.win.qt.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup>
<XBOFS_WIN_VERSION>v1.1.0</XBOFS_WIN_VERSION>
</PropertyGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{B12702AD-ABFB-343A-A199-8E24837244A3}</ProjectGuid>
<Keyword>QtVS_v304</Keyword>
Expand Down Expand Up @@ -106,7 +109,10 @@
<QtRccFileName>qrc_%(Filename).cpp</QtRccFileName>
</QtRcc>
<PostBuildEvent>
<Command>set VCINSTALLDIR=$(VCInstallDir)&amp;&amp; cd $(OutputPath) &amp;&amp; $(QTDIR)\$(QtPathBinaries)\windeployqt --debug $(TargetFileName)</Command>
<Command>set VCINSTALLDIR=$(VCInstallDir) &amp;&amp; cd $(OutputPath) &amp;&amp; $(QTDIR)\$(QtPathBinaries)\windeployqt --debug $(TargetFileName)
del $(SolutionDir)\installer\packages\win.xbofs\data\xbofs.win.7z
cd $(OutputPath) &amp;&amp; $(QTDIR)\..\..\Tools\QtInstallerFramework\4.1\bin\archivegen $(SolutionDir)\installer\packages\win.xbofs\data\xbofs.win.7z .
cd $(OutputPath) &amp;&amp; $(QTDIR)\..\..\Tools\QtInstallerFramework\4.1\bin\binarycreator -c $(SolutionDir)\installer\config\config.xml -p $(SolutionDir)\installer\packages $(SolutionDir)\installer\$(SolutionName).$(XBOFS_WIN_VERSION).debug.installer.exe </Command>
</PostBuildEvent>
<CopyFileToFolders>
<DestinationFolders>$(OutDir)Resources</DestinationFolders>
Expand Down Expand Up @@ -149,7 +155,10 @@
<QtRccFileName>qrc_%(Filename).cpp</QtRccFileName>
</QtRcc>
<PostBuildEvent>
<Command>set VCINSTALLDIR=$(VCInstallDir)&amp;&amp; cd $(OutputPath) &amp;&amp; $(QTDIR)\$(QtPathBinaries)\windeployqt --release $(TargetFileName)</Command>
<Command>set VCINSTALLDIR=$(VCInstallDir) &amp;&amp; cd $(OutputPath) &amp;&amp; $(QTDIR)\$(QtPathBinaries)\windeployqt --release $(TargetFileName)
del $(SolutionDir)\installer\packages\win.xbofs\data\xbofs.win.7z
cd $(OutputPath) &amp;&amp; $(QTDIR)\..\..\Tools\QtInstallerFramework\4.1\bin\archivegen $(SolutionDir)\installer\packages\win.xbofs\data\xbofs.win.7z .
cd $(OutputPath) &amp;&amp; $(QTDIR)\..\..\Tools\QtInstallerFramework\4.1\bin\binarycreator -c $(SolutionDir)\installer\config\config.xml -p $(SolutionDir)\installer\packages $(SolutionDir)\installer\$(SolutionName).$(XBOFS_WIN_VERSION).installer.exe</Command>
</PostBuildEvent>
<CopyFileToFolders>
<DestinationFolders>$(OutDir)Resources</DestinationFolders>
Expand Down
1 change: 1 addition & 0 deletions XBOFS.win/include/XBOFS.win/WinUsbDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ namespace XBOFSWin {
int bindings[2][15][2][7] = {};
bool buttons[15] = {false, false, false, false, false, false, false, false, false, false, false, false, false, false, false};
GUIDE_BUTTON_MODE guideButtonMode;
SOCD_CLEANING_CONFIGURATION socdCleaningConfiguration[2];

bool deviceHandlesOpen = false;
UCHAR XBO_ARCADE_STICK_INIT[5] = { 0x05, 0x20, 0x00, 0x01, 0x00 };
Expand Down
59 changes: 58 additions & 1 deletion XBOFS.win/include/XBOFS.win/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ namespace XBOFSWin {
const QString THUMB_LY = QString::number(4);
const QString THUMB_RX = QString::number(5);
const QString THUMB_RY = QString::number(6);
const QString SOCD_CLEANING_ENABLED = "socdCleaningEnabled";
const QString SOCD_CLEAN_UP_DOWN_TO = "socdCleanUpDownTo";
const QString SOCD_CLEAN_LEFT_RIGHT_TO = "socdCleanLeftRightTo";
}

enum class XBO_ARCADE_STICK_BUTTONS {
Expand All @@ -42,7 +45,8 @@ namespace XBOFSWin {

enum class GUIDE_BUTTON_MODE {
HOLD,
TOGGLE
TOGGLE,
NORMAL
};

/*
Expand Down Expand Up @@ -267,4 +271,57 @@ namespace XBOFSWin {
WCHAR bString[126];
};

/*
* SOCD constants
*/
enum class SOCD_CLEANING_UP_DOWN_OPTIONS {
NEUTRAL,
UP,
DOWN
};

enum class SOCD_CLEANING_LEFT_RIGHT_OPTIONS {
NEUTRAL,
LEFT,
RIGHT
};

const int SOCD_UP_DOWN_MASK = XUSB_GAMEPAD_DPAD_UP | XUSB_GAMEPAD_DPAD_DOWN;
const int SOCD_LEFT_RIGHT_MASK = XUSB_GAMEPAD_DPAD_LEFT | XUSB_GAMEPAD_DPAD_RIGHT;
const int SOCD_ALL_BUTTONS_MASK =
XUSB_GAMEPAD_DPAD_UP | XUSB_GAMEPAD_DPAD_DOWN | XUSB_GAMEPAD_DPAD_LEFT | XUSB_GAMEPAD_DPAD_RIGHT |
XUSB_GAMEPAD_START | XUSB_GAMEPAD_BACK | XUSB_GAMEPAD_LEFT_THUMB | XUSB_GAMEPAD_RIGHT_THUMB |
XUSB_GAMEPAD_LEFT_SHOULDER | XUSB_GAMEPAD_RIGHT_SHOULDER | XUSB_GAMEPAD_GUIDE |
XUSB_GAMEPAD_A | XUSB_GAMEPAD_B | XUSB_GAMEPAD_X | XUSB_GAMEPAD_Y;
const int SOCD_NEGATE_UP_DOWN = SOCD_ALL_BUTTONS_MASK ^ (XUSB_GAMEPAD_DPAD_UP | XUSB_GAMEPAD_DPAD_DOWN);
const int SOCD_NEGATE_UP = SOCD_ALL_BUTTONS_MASK ^ XUSB_GAMEPAD_DPAD_UP;
const int SOCD_NEGATE_DOWN = SOCD_ALL_BUTTONS_MASK ^ XUSB_GAMEPAD_DPAD_DOWN;
const int SOCD_NEGATE_LEFT_RIGHT = SOCD_ALL_BUTTONS_MASK ^ (XUSB_GAMEPAD_DPAD_LEFT | XUSB_GAMEPAD_DPAD_RIGHT);
const int SOCD_NEGATE_LEFT = SOCD_ALL_BUTTONS_MASK ^ XUSB_GAMEPAD_DPAD_LEFT;
const int SOCD_NEGATE_RIGHT = SOCD_ALL_BUTTONS_MASK ^ XUSB_GAMEPAD_DPAD_RIGHT;

const std::map<SOCD_CLEANING_UP_DOWN_OPTIONS, int> socdCleaningUpDownOptionsMapping {
{SOCD_CLEANING_UP_DOWN_OPTIONS::NEUTRAL, SOCD_NEGATE_UP_DOWN},
{SOCD_CLEANING_UP_DOWN_OPTIONS::UP, SOCD_NEGATE_DOWN},
{SOCD_CLEANING_UP_DOWN_OPTIONS::DOWN, SOCD_NEGATE_UP}
};

const std::map<SOCD_CLEANING_LEFT_RIGHT_OPTIONS, int> socdCleaningLeftRightOptionsMapping{
{SOCD_CLEANING_LEFT_RIGHT_OPTIONS::NEUTRAL, SOCD_NEGATE_LEFT_RIGHT},
{SOCD_CLEANING_LEFT_RIGHT_OPTIONS::LEFT, SOCD_NEGATE_RIGHT},
{SOCD_CLEANING_LEFT_RIGHT_OPTIONS::RIGHT, SOCD_NEGATE_LEFT}
};

struct SOCD_CLEANING_CONFIGURATION {
std::map<int, int> upDownMasks {
{0, SOCD_ALL_BUTTONS_MASK},
{XUSB_GAMEPAD_DPAD_UP, SOCD_ALL_BUTTONS_MASK},
{XUSB_GAMEPAD_DPAD_DOWN, SOCD_ALL_BUTTONS_MASK}
};
std::map<int, int> leftRightMasks {
{0, SOCD_ALL_BUTTONS_MASK},
{XUSB_GAMEPAD_DPAD_LEFT, SOCD_ALL_BUTTONS_MASK},
{XUSB_GAMEPAD_DPAD_RIGHT, SOCD_ALL_BUTTONS_MASK}
};
};
}
28 changes: 25 additions & 3 deletions XBOFS.win/src/WinUsbDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,27 @@ void WinUsbDevice::refreshSettings() {
bindingSelector = 0;
debugEnabled = settings.value(settings::DEBUG_ENABLED, false).toBool();
activeProfile = settings.value(settings::ACTIVE_PROFILE, "").toString();
guideButtonMode = (GUIDE_BUTTON_MODE)settings.value(QString("%1/%2").arg(activeProfile, settings::GUIDE_BUTTON_MODE), 0).toInt();
guideButtonMode = static_cast<GUIDE_BUTTON_MODE>(settings.value(QString("%1/%2").arg(activeProfile, settings::GUIDE_BUTTON_MODE), 0).toInt());
// Configure control bindings
logger->info(bindingEnabled ? "Binding Enabled" : "Binding Disabled");
for (int bindingsSelector = 0; bindingsSelector < 2; bindingsSelector++) {
// Configure SOCD cleaning
auto bindingsSelectorQString = QString::number(bindingsSelector);
auto key = QString("%1/%2").arg(activeProfile, bindingsSelectorQString);
auto socdCleaningEnabled = settings.value(QString("%1/%2").arg(key, settings::SOCD_CLEANING_ENABLED), false).toBool();
auto socdCleanUpDownTo = settings.value(QString("%1/%2").arg(key, settings::SOCD_CLEAN_UP_DOWN_TO), static_cast<int>(SOCD_CLEANING_UP_DOWN_OPTIONS::NEUTRAL)).toInt();
auto socdCleanLeftRightTo = settings.value(QString("%1/%2").arg(key, settings::SOCD_CLEAN_LEFT_RIGHT_TO), static_cast<int>(SOCD_CLEANING_LEFT_RIGHT_OPTIONS::NEUTRAL)).toInt();
socdCleaningConfiguration[bindingsSelector].upDownMasks.insert_or_assign(
XUSB_GAMEPAD_DPAD_UP | XUSB_GAMEPAD_DPAD_DOWN,
socdCleaningEnabled ? socdCleaningUpDownOptionsMapping.at(static_cast<SOCD_CLEANING_UP_DOWN_OPTIONS>(socdCleanUpDownTo)) : SOCD_ALL_BUTTONS_MASK
);
socdCleaningConfiguration[bindingsSelector].leftRightMasks.insert_or_assign(
XUSB_GAMEPAD_DPAD_LEFT | XUSB_GAMEPAD_DPAD_RIGHT,
socdCleaningEnabled ? socdCleaningLeftRightOptionsMapping.at(static_cast<SOCD_CLEANING_LEFT_RIGHT_OPTIONS>(socdCleanLeftRightTo)) : SOCD_ALL_BUTTONS_MASK
);
// Configure Bindings
for (int xboArcadeStickButtonSelector = 0; xboArcadeStickButtonSelector < 15; xboArcadeStickButtonSelector++) {
auto key = QString("%1/%2/%3").arg(activeProfile, QString::number(bindingsSelector), QString::number(xboArcadeStickButtonSelector));
auto key = QString("%1/%2/%3").arg(activeProfile, bindingsSelectorQString, QString::number(xboArcadeStickButtonSelector));
auto bindEnabled = settings.value(QString("%1/%2").arg(key, settings::BIND_ENABLED), false).toBool();
for (int outputValueSelector = 0; outputValueSelector < 7; outputValueSelector++) {
auto value = bindingEnabled && bindEnabled
Expand Down Expand Up @@ -242,7 +257,7 @@ PACKET_TYPES WinUsbDevice::processInputFromXBOArcadeStick() {
return PACKET_TYPES::HEARTBEAT;
case 0x07: // Guide button
guideButtonState = dataPacket.data[4] & 0x01;
if (!bindingEnabled) {
if (!bindingEnabled || guideButtonMode == GUIDE_BUTTON_MODE::NORMAL) {
buttons[(int)XBO_ARCADE_STICK_BUTTONS::GUIDE] = guideButtonState;
}
else {
Expand Down Expand Up @@ -310,6 +325,13 @@ XUSB_REPORT WinUsbDevice::prepareInputForVigEmController() {
controllerData.sThumbRX |= rxValue;
controllerData.sThumbRY |= ryValue;
}
// SOCD cleaning
auto upDownCheck = SOCD_UP_DOWN_MASK & controllerData.wButtons;
auto upDownMask = socdCleaningConfiguration[bindingSelector].upDownMasks.at(upDownCheck);
controllerData.wButtons &= upDownMask;
auto leftRightCheck = SOCD_LEFT_RIGHT_MASK & controllerData.wButtons;
auto leftRightMask = socdCleaningConfiguration[bindingSelector].leftRightMasks.at(leftRightCheck);
controllerData.wButtons &= leftRightMask;
return controllerData;
}

Expand Down

0 comments on commit 747888f

Please sign in to comment.