Skip to content

Commit

Permalink
#34: Implemented SOCD cleaning and introduced third Guide button mode
Browse files Browse the repository at this point in the history
  • Loading branch information
OOPMan committed Jul 26, 2022
1 parent 94a0f8e commit 890285d
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 4 deletions.
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
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 890285d

Please sign in to comment.