Skip to content

Commit

Permalink
- Fixed DS4 joycon joining bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Davidobot committed May 17, 2020
1 parent cd65936 commit 7b722dd
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 21 deletions.
2 changes: 1 addition & 1 deletion BetterJoyForCemu/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<!-- Determines whether or not to use HidGuardian (improves compatibility with other programs, like Steam, when set to "false") -->
<!-- When "true", BetterJoyForCemu will hide the Pro/Joycons from other programs to prevent glitching out on exit and to prevent DI/XI clashes in certain programs -->
<!-- Default: false -->
<add key="UseHIDG" value="false" />
<add key="UseHIDG" value="true" />


<!-- Determines whether or not to enable (experimental - currently default controller to pro) support for 3rd-party controllers. Adds a "Calibrate" button. -->
Expand Down
13 changes: 6 additions & 7 deletions BetterJoyForCemu/Joycon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,18 +283,18 @@ public Joycon(IntPtr handle_, bool imu, bool localize, float alpha, bool left, s
}
}

private void Ds4_FeedbackReceived(object sender, DualShock4FeedbackReceivedEventArgs e) {
public void getActiveData() {
this.activeData = form.activeCaliData(serial_number);
}

public void ReceiveRumble(object sender, Nefarius.ViGEm.Client.Targets.Xbox360.Xbox360FeedbackReceivedEventArgs e) {
SetRumble(lowFreq, highFreq, (float)(e.LargeMotor + e.SmallMotor) / (float)255, rumblePeriod);

if (other != null && other != this)
other.SetRumble(lowFreq, highFreq, (float)(e.LargeMotor + e.SmallMotor) / (float)255, rumblePeriod);
}

public void getActiveData() {
this.activeData = form.activeCaliData(serial_number);
}

public void ReceiveRumble(object sender, Nefarius.ViGEm.Client.Targets.Xbox360.Xbox360FeedbackReceivedEventArgs e) {
public void Ds4_FeedbackReceived(object sender, DualShock4FeedbackReceivedEventArgs e) {
SetRumble(lowFreq, highFreq, (float)(e.LargeMotor + e.SmallMotor) / (float)255, rumblePeriod);

if (other != null && other != this)
Expand Down Expand Up @@ -531,7 +531,6 @@ private int ReceiveRaw() {
}
}


if (ret > 0) {
// Process packets as soon as they come
for (int n = 0; n < 3; n++) {
Expand Down
37 changes: 24 additions & 13 deletions BetterJoyForCemu/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public void AppendTextBox(string value) { // https://stackoverflow.com/questions

bool toRumble = Boolean.Parse(ConfigurationManager.AppSettings["EnableRumble"]);
bool showAsXInput = Boolean.Parse(ConfigurationManager.AppSettings["ShowAsXInput"]);
bool showAsDS4 = Boolean.Parse(ConfigurationManager.AppSettings["ShowAsDS4"]);

public void locBtnClick(object sender, EventArgs e) {
Button bb = sender as Button;
Expand Down Expand Up @@ -177,8 +178,15 @@ public void conBtnClick(object sender, EventArgs e) {
jc.SetPlayerLED(led);
v.SetPlayerLED(led);

v.xin.Disconnect();
v.xin = null;
if (v.xin != null) {
v.xin.Disconnect();
v.xin = null;
}

if (v.ds4 != null) {
v.ds4.Disconnect();
v.ds4 = null;
}

// setting the other joycon's button image
foreach (Button b in con)
Expand All @@ -196,15 +204,8 @@ public void conBtnClick(object sender, EventArgs e) {
if (b.Tag == v)
b.BackgroundImage = v.isLeft ? Properties.Resources.jc_left : Properties.Resources.jc_right;
} else if (v.other != null && !v.isPro) { // needs disconnecting from other joycon
if (v.xin == null) {
ReenableXinput(v);
v.xin.Connect();
}

if (v.other.xin == null) {
ReenableXinput(v.other);
v.other.xin.Connect();
}
ReenableViGEm(v);
ReenableViGEm(v.other);

button.BackgroundImage = v.isLeft ? Properties.Resources.jc_left_s : Properties.Resources.jc_right_s;

Expand Down Expand Up @@ -260,12 +261,22 @@ private void settingsApply_Click(object sender, EventArgs e) {
Environment.Exit(0);
}

void ReenableXinput(Joycon v) {
if (showAsXInput) {
void ReenableViGEm(Joycon v) {
if (showAsXInput && v.xin == null) {
v.xin = Program.emClient.CreateXbox360Controller();

if (toRumble)
v.xin.FeedbackReceived += v.ReceiveRumble;
v.xin.Connect();
}

if (showAsDS4 && v.ds4 == null) {
v.ds4 = Program.emClient.CreateDualShock4Controller();
v.ds4.AutoSubmitReport = false;

if (toRumble)
v.ds4.FeedbackReceived += v.Ds4_FeedbackReceived;
v.ds4.Connect();
}
}

Expand Down

0 comments on commit 7b722dd

Please sign in to comment.