- fix Hori controllers (thank you bitamind!)

- add default calibration settings (acc/gyro and sticks) that are used for third party controllers automatically
This commit is contained in:
David Khachaturov 2021-04-17 11:15:38 +01:00
parent e451b95536
commit 7444c01adc
4 changed files with 37 additions and 53 deletions

View file

@ -41,18 +41,25 @@
<!--On is "true"; off is "false". Default: false -->
<add key="SwapXY" value="false" />
<!--Allows for calibration of the controller's gyro. Adds a "Calibrate" button.-->
<!--When "true", click the "Calibrate" button once to get gyro calibrate data.-->
<!--When enabled, can only calibrate one controller at a time.-->
<!--Default: false -->
<!-- Allows for calibration of the controller's gyro. Adds a "Calibrate" button.-->
<!-- When "true", click the "Calibrate" button once to get gyro calibrate data.-->
<!-- When enabled, can only calibrate one controller at a time.-->
<!-- Default: false -->
<add key="AllowCalibration" value="false" />
<!-- Default calibration; used for third party controller -->
<add key="acc_sensiti" value="16384,16384,16384"/>
<add key="gyr_sensiti" value="18642,18642,18642"/>
<add key="stick_cal" value="0x780,0x780,0x780,0x830,0x780,0x780"/>
<add key="deadzone" value="200"/>
<add key="stick2_cal" value="0x780,0x780,0x780,0x830,0x780,0x780"/>
<add key="deadzone2" value="200"/>
<!--Allows use of gyroscope tilting to get full control of the slider values (big triggers)-->
<!--Works on pro controller and joined joycons (pro controller case - triggers combined, joycons case - separate tilt)-->
<!--Default: false -->
<!-- Allows use of gyroscope tilting to get full control of the slider values (big triggers)-->
<!-- Works on pro controller and joined joycons (pro controller case - triggers combined, joycons case - separate tilt)-->
<!-- Default: false -->
<add key="GyroAnalogSliders" value="false" />
<!--Change to -400 to change direction of tilt needed. Positive is ramp up if pointing up-->
<!--Default: 400 -->
<!-- Change to -400 to change direction of tilt needed. Positive is ramp up if pointing up-->
<!-- Default: 400 -->
<add key="GyroAnalogSensitivity" value="400" />
<!-- Determines whether or not the program should purge the affected devices list upon exit -->
@ -68,15 +75,6 @@
<!-- Default: false -->
<add key="UseHIDG" value="false" />
<!-- Determines whether or not to enable (experimental - currently default controller to pro) support for 3rd-party controllers. -->
<!-- Can be set to: False, DefaultCalibration, ControllerCalibration -->
<!-- Disabled => Disables support for 3rd-party controllers. Uses joystick calibration data from the controller. -->
<!-- DefaultCalibration => Enables support for 3rd-party controllers. Uses hard coded joystick calibration data. -->
<!-- ControllerCalibration => Enables support for 3rd-party controllers. Uses joystick calibration data from the controller. -->
<!-- Not case sensitive. -->
<!-- Default: Disabled -->
<add key="NonOriginalController" value="Disabled" />
<!-- The program will keep the HOME button LED ring light on at all times. -->
<!-- Default: true -->
<add key="HomeLEDOn" value="true"/>

View file

@ -440,6 +440,8 @@ namespace BetterJoyForCemu {
}
public void BlinkHomeLight() { // do not call after initial setup
if (thirdParty)
return;
byte[] a = Enumerable.Repeat((byte)0xFF, 25).ToArray();
a[0] = 0x18;
a[1] = 0x01;
@ -447,6 +449,8 @@ namespace BetterJoyForCemu {
}
public void SetHomeLight(bool on) {
if (thirdParty)
return;
byte[] a = Enumerable.Repeat((byte)0xFF, 25).ToArray();
if (on) {
a[0] = 0x1F;
@ -853,15 +857,12 @@ namespace BetterJoyForCemu {
stick_precal[0] = (UInt16)(stick_raw[0] | ((stick_raw[1] & 0xf) << 8));
stick_precal[1] = (UInt16)((stick_raw[1] >> 4) | (stick_raw[2] << 4));
ushort[] cal = form.useControllerStickCalibration ? stick_cal : new ushort[6] { 2048, 2048, 2048, 2048, 2048, 2048 };
ushort dz = form.useControllerStickCalibration ? deadzone : (ushort)200;
stick = CenterSticks(stick_precal, cal, dz);
stick = CenterSticks(stick_precal, stick_cal, deadzone);
if (isPro) {
stick2_precal[0] = (UInt16)(stick2_raw[0] | ((stick2_raw[1] & 0xf) << 8));
stick2_precal[1] = (UInt16)((stick2_raw[1] >> 4) | (stick2_raw[2] << 4));
ushort dz2 = form.useControllerStickCalibration ? deadzone2 : (ushort)200;
stick2 = CenterSticks(stick2_precal, form.useControllerStickCalibration ? stick2_cal : cal, dz2);
stick2 = CenterSticks(stick2_precal, stick2_cal, deadzone2);
}
// Read other Joycon's sticks
@ -1119,8 +1120,22 @@ namespace BetterJoyForCemu {
}
private void dump_calibration_data() {
if (isSnes || thirdParty)
if (isSnes || thirdParty) {
short[] temp = (short[])ConfigurationManager.AppSettings["acc_sensiti"].Split(',').Select(s => short.Parse(s)).ToArray();
acc_sensiti[0] = temp[0]; acc_sensiti[1] = temp[1]; acc_sensiti[2] = temp[2];
temp = (short[])ConfigurationManager.AppSettings["gyr_sensiti"].Split(',').Select(s => short.Parse(s)).ToArray();
gyr_sensiti[0] = temp[0]; gyr_sensiti[1] = temp[1]; gyr_sensiti[2] = temp[2];
ushort[] temp2 = (ushort[])ConfigurationManager.AppSettings["stick_cal"].Split(',').Select(s => ushort.Parse(s.Substring(2), System.Globalization.NumberStyles.HexNumber)).ToArray();
stick_cal[0] = temp2[0]; stick_cal[1] = temp2[1]; stick_cal[2] = temp2[2];
stick_cal[3] = temp2[3]; stick_cal[4] = temp2[4]; stick_cal[5] = temp2[5];
deadzone = ushort.Parse(ConfigurationManager.AppSettings["deadzone"]);
temp2 = (ushort[])ConfigurationManager.AppSettings["stick2_cal"].Split(',').Select(s => ushort.Parse(s.Substring(2), System.Globalization.NumberStyles.HexNumber)).ToArray();
stick2_cal[0] = temp2[0]; stick2_cal[1] = temp2[1]; stick2_cal[2] = temp2[2];
stick2_cal[3] = temp2[3]; stick2_cal[4] = temp2[4]; stick2_cal[5] = temp2[5];
deadzone2 = ushort.Parse(ConfigurationManager.AppSettings["deadzone2"]);
return;
}
HIDapi.hid_set_nonblocking(handle, 0);
byte[] buf_ = ReadSPI(0x80, (isLeft ? (byte)0x12 : (byte)0x1d), 9); // get user calibration data if possible
bool found = false;

View file

@ -15,8 +15,6 @@ using System.Xml.Linq;
namespace BetterJoyForCemu {
public partial class MainForm : Form {
public bool useControllerStickCalibration;
public bool nonOriginal;
public bool allowCalibration = Boolean.Parse(ConfigurationManager.AppSettings["AllowCalibration"]);
public List<Button> con, loc;
public bool calibrate;
@ -40,7 +38,6 @@ namespace BetterJoyForCemu {
caliData = new List<KeyValuePair<string, float[]>> {
new KeyValuePair<string, float[]>("0", new float[6] {0,0,0,-710,0,0})
};
SetNonOriginalControllerSettings();
InitializeComponent();
@ -70,28 +67,6 @@ namespace BetterJoyForCemu {
}
}
private void SetNonOriginalControllerSettings() {
Enum.TryParse(ConfigurationManager.AppSettings["NonOriginalController"], true, out NonOriginalController nonOriginalController);
switch ((int)nonOriginalController) {
case 0:
nonOriginal = false;
break;
case 1:
case 2:
nonOriginal = true;
break;
}
switch ((int)nonOriginalController) {
case 0:
case 2:
useControllerStickCalibration = true;
break;
case 1:
useControllerStickCalibration = false;
break;
}
}
private void HideToTray() {
this.WindowState = FormWindowState.Minimized;
notifyIcon.Visible = true;

View file

@ -126,10 +126,6 @@ namespace BetterJoyForCemu {
continue;
}
if (form.nonOriginal) {
enumerate.product_id = product_pro;
}
bool validController = (enumerate.product_id == product_l || enumerate.product_id == product_r ||
enumerate.product_id == product_pro || enumerate.product_id == product_snes) && enumerate.vendor_id == vendor_id;
// check list of custom controllers specified