diff --git a/BetterJoyForCemu/App.config b/BetterJoyForCemu/App.config index d347221b..6ae34cc1 100644 --- a/BetterJoyForCemu/App.config +++ b/BetterJoyForCemu/App.config @@ -44,7 +44,7 @@ - + diff --git a/BetterJoyForCemu/Joycon.cs b/BetterJoyForCemu/Joycon.cs index df50bc81..2ed44b45 100644 --- a/BetterJoyForCemu/Joycon.cs +++ b/BetterJoyForCemu/Joycon.cs @@ -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) @@ -531,7 +531,6 @@ private int ReceiveRaw() { } } - if (ret > 0) { // Process packets as soon as they come for (int n = 0; n < 3; n++) { diff --git a/BetterJoyForCemu/MainForm.cs b/BetterJoyForCemu/MainForm.cs index 6a57f879..894378d3 100644 --- a/BetterJoyForCemu/MainForm.cs +++ b/BetterJoyForCemu/MainForm.cs @@ -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; @@ -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) @@ -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; @@ -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(); } }