From 88b3abd743e9111e8ae6d1ef16679a64423d0629 Mon Sep 17 00:00:00 2001 From: emoose Date: Sun, 5 Jul 2020 18:30:37 +0100 Subject: [PATCH] Read/write deadzones to INI file, bump version to v1.4 --- Xb2XInput/Xb2XInput.rc | Bin 6452 -> 6452 bytes Xb2XInput/XboxController.cpp | 25 +++++++++++++++++++++++++ Xb2XInput/XboxController.hpp | 2 ++ dist/Xb2XInput.ini | 12 ++++++++++++ 4 files changed, 39 insertions(+) diff --git a/Xb2XInput/Xb2XInput.rc b/Xb2XInput/Xb2XInput.rc index 440a8aa6ac237fc84d82836720d511783102b1c6..e31e3c548d14ab3006e40f2d88051686e36209c2 100644 GIT binary patch delta 66 zcmdmDw8dz{JAPIZ1|0^2$)EXkA*{`+0_T}HO&IhT3_y6Yqmb@qE#Yg7C_>_!6+}f? E06FOn=l}o! delta 66 zcmdmDw8dz{JAPJU1|0^Y$)EXkA*{`+0_T}HjT!V9jDXl+vZIjhW-Z}sj3`3ln-xSw FSO7X|4(tE` diff --git a/Xb2XInput/XboxController.cpp b/Xb2XInput/XboxController.cpp index 80011be..70c2a06 100644 --- a/Xb2XInput/XboxController.cpp +++ b/Xb2XInput/XboxController.cpp @@ -291,6 +291,11 @@ XboxController::XboxController(libusb_device_handle* handle, uint8_t* usb_ports, if (vibration_enabled_) VibrationEnabled(vibration_enabled_); + deadzone_.sThumbL = min(max(GetSettingInt("DeadzoneLeftStick", 0), 0), SHRT_MAX); + deadzone_.sThumbR = min(max(GetSettingInt("DeadzoneRightStick", 0), 0), SHRT_MAX); + deadzone_.bLeftTrigger = min(max(GetSettingInt("DeadzoneLeftTrigger", 0), 0), 0xFF); + deadzone_.bRightTrigger = min(max(GetSettingInt("DeadzoneRightTrigger", 0), 0), 0xFF); + usb_product_ = usb_desc_.idProduct; usb_vendor_ = usb_desc_.idVendor; } @@ -479,6 +484,8 @@ bool XboxController::update() deadzone_.sThumbR = min(max(deadzone_.sThumbR+adjustment,0), SHRT_MAX); } + SaveDeadzones(); + // wait for button release deadzone_.hold = true; } @@ -498,6 +505,8 @@ bool XboxController::update() deadzone_.bRightTrigger = min(max(deadzone_.bRightTrigger+adjustment,0), 0xFF); } + SaveDeadzones(); + // wait for button release deadzone_.hold = true; } @@ -556,6 +565,22 @@ void XboxController::VibrationEnabled(bool value) SetSetting("EnableVibration", value ? "true" : "false"); } +void XboxController::SaveDeadzones() +{ + // WritePrivateProfile can only write strings, bleh + if (deadzone_.sThumbL) + SetSetting("DeadzoneLeftStick", std::to_string(deadzone_.sThumbL)); + + if (deadzone_.sThumbR) + SetSetting("DeadzoneRightStick", std::to_string(deadzone_.sThumbR)); + + if (deadzone_.bLeftTrigger) + SetSetting("DeadzoneLeftTrigger", std::to_string(deadzone_.bLeftTrigger)); + + if (deadzone_.bRightTrigger) + SetSetting("DeadzoneRightTrigger", std::to_string(deadzone_.bRightTrigger)); +} + int XboxController::GetSettingInt(const std::string& setting, int default_val) { return GetPrivateProfileIntA(ini_key_.c_str(), setting.c_str(), default_val, ini_path); diff --git a/Xb2XInput/XboxController.hpp b/Xb2XInput/XboxController.hpp index 217630b..21ce0f1 100644 --- a/Xb2XInput/XboxController.hpp +++ b/Xb2XInput/XboxController.hpp @@ -121,6 +121,8 @@ class XboxController void SetSetting(const std::string& setting, const std::string& value); + void SaveDeadzones(); + public: bool GuideEnabled() { return guide_enabled_; } void GuideEnabled(bool value); diff --git a/dist/Xb2XInput.ini b/dist/Xb2XInput.ini index e6ad9c7..22b8e9b 100644 --- a/dist/Xb2XInput.ini +++ b/dist/Xb2XInput.ini @@ -28,6 +28,18 @@ EnableGuide=true # Whether or not to enable vibration/rumble support EnableVibration=true +# Deadzone*Stick (default 0) +# Amount of deadzone to apply to each stick +# Range: 0 - 32767 +DeadzoneLeftStick=0 +DeadzoneRightStick=0 + +# Deadzone*Trigger (default 0) +# Amount of deadzone to apply to each trigger +# Range: 0 - 255 +DeadzoneLeftTrigger=0 +DeadzoneRightTrigger=0 + [0738:4526] # This section configures controllers that use the VID/PID of 0738:4526 (as not all controllers may have unique serial numbers) EnableGuide=true