Skip to content

Commit

Permalink
Read/write deadzones to INI file, bump version to v1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
emoose committed Jul 5, 2020
1 parent e337551 commit 88b3abd
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
Binary file modified Xb2XInput/Xb2XInput.rc
Binary file not shown.
25 changes: 25 additions & 0 deletions Xb2XInput/XboxController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -498,6 +505,8 @@ bool XboxController::update()
deadzone_.bRightTrigger = min(max(deadzone_.bRightTrigger+adjustment,0), 0xFF);
}

SaveDeadzones();

// wait for button release
deadzone_.hold = true;
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions Xb2XInput/XboxController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions dist/Xb2XInput.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 88b3abd

Please sign in to comment.