Skip to content

Commit 88b3abd

Browse files
committed
Read/write deadzones to INI file, bump version to v1.4
1 parent e337551 commit 88b3abd

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

Xb2XInput/Xb2XInput.rc

0 Bytes
Binary file not shown.

Xb2XInput/XboxController.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,11 @@ XboxController::XboxController(libusb_device_handle* handle, uint8_t* usb_ports,
291291
if (vibration_enabled_)
292292
VibrationEnabled(vibration_enabled_);
293293

294+
deadzone_.sThumbL = min(max(GetSettingInt("DeadzoneLeftStick", 0), 0), SHRT_MAX);
295+
deadzone_.sThumbR = min(max(GetSettingInt("DeadzoneRightStick", 0), 0), SHRT_MAX);
296+
deadzone_.bLeftTrigger = min(max(GetSettingInt("DeadzoneLeftTrigger", 0), 0), 0xFF);
297+
deadzone_.bRightTrigger = min(max(GetSettingInt("DeadzoneRightTrigger", 0), 0), 0xFF);
298+
294299
usb_product_ = usb_desc_.idProduct;
295300
usb_vendor_ = usb_desc_.idVendor;
296301
}
@@ -479,6 +484,8 @@ bool XboxController::update()
479484
deadzone_.sThumbR = min(max(deadzone_.sThumbR+adjustment,0), SHRT_MAX);
480485
}
481486

487+
SaveDeadzones();
488+
482489
// wait for button release
483490
deadzone_.hold = true;
484491
}
@@ -498,6 +505,8 @@ bool XboxController::update()
498505
deadzone_.bRightTrigger = min(max(deadzone_.bRightTrigger+adjustment,0), 0xFF);
499506
}
500507

508+
SaveDeadzones();
509+
501510
// wait for button release
502511
deadzone_.hold = true;
503512
}
@@ -556,6 +565,22 @@ void XboxController::VibrationEnabled(bool value)
556565
SetSetting("EnableVibration", value ? "true" : "false");
557566
}
558567

568+
void XboxController::SaveDeadzones()
569+
{
570+
// WritePrivateProfile can only write strings, bleh
571+
if (deadzone_.sThumbL)
572+
SetSetting("DeadzoneLeftStick", std::to_string(deadzone_.sThumbL));
573+
574+
if (deadzone_.sThumbR)
575+
SetSetting("DeadzoneRightStick", std::to_string(deadzone_.sThumbR));
576+
577+
if (deadzone_.bLeftTrigger)
578+
SetSetting("DeadzoneLeftTrigger", std::to_string(deadzone_.bLeftTrigger));
579+
580+
if (deadzone_.bRightTrigger)
581+
SetSetting("DeadzoneRightTrigger", std::to_string(deadzone_.bRightTrigger));
582+
}
583+
559584
int XboxController::GetSettingInt(const std::string& setting, int default_val)
560585
{
561586
return GetPrivateProfileIntA(ini_key_.c_str(), setting.c_str(), default_val, ini_path);

Xb2XInput/XboxController.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ class XboxController
121121

122122
void SetSetting(const std::string& setting, const std::string& value);
123123

124+
void SaveDeadzones();
125+
124126
public:
125127
bool GuideEnabled() { return guide_enabled_; }
126128
void GuideEnabled(bool value);

dist/Xb2XInput.ini

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@ EnableGuide=true
2828
# Whether or not to enable vibration/rumble support
2929
EnableVibration=true
3030

31+
# Deadzone*Stick (default 0)
32+
# Amount of deadzone to apply to each stick
33+
# Range: 0 - 32767
34+
DeadzoneLeftStick=0
35+
DeadzoneRightStick=0
36+
37+
# Deadzone*Trigger (default 0)
38+
# Amount of deadzone to apply to each trigger
39+
# Range: 0 - 255
40+
DeadzoneLeftTrigger=0
41+
DeadzoneRightTrigger=0
42+
3143
[0738:4526]
3244
# This section configures controllers that use the VID/PID of 0738:4526 (as not all controllers may have unique serial numbers)
3345
EnableGuide=true

0 commit comments

Comments
 (0)