Fixed Pro Controller timing out on USB mode due to new rumble implementation.

Fixed Pro Controller sticks. (broken due to single joycon mode)

Finally made program close correctly every time / start correctly every time.
This commit is contained in:
David Khachaturov 2018-08-14 10:42:00 +03:00
parent c296b5cf2e
commit 9509e44ae3
3 changed files with 23 additions and 19 deletions

View file

@ -291,11 +291,6 @@ namespace BetterJoyForCemu {
a[0] = 0x1; a[0] = 0x1;
dump_calibration_data(); dump_calibration_data();
a = Enumerable.Repeat((byte)0xFF, 25).ToArray();
a[0] = 0x18;
a[1] = 0x01;
Subcommand(0x38, a, 25, false);
} else { } else {
Subcommand(0x03, new byte[] { 0x3f }, 1, false); Subcommand(0x03, new byte[] { 0x3f }, 1, false);
@ -328,7 +323,12 @@ namespace BetterJoyForCemu {
dump_calibration_data(); dump_calibration_data();
} }
a[0] = leds_; a = Enumerable.Repeat((byte)0xFF, 25).ToArray(); // LED ring
a[0] = 0x18;
a[1] = 0x01;
Subcommand(0x38, a, 25, false);
a[0] = leds_;
Subcommand(0x30, a, 1); Subcommand(0x30, a, 1);
Subcommand(0x40, new byte[] { (imu_enabled ? (byte)0x1 : (byte)0x0) }, 1, true); Subcommand(0x40, new byte[] { (imu_enabled ? (byte)0x1 : (byte)0x0) }, 1, true);
Subcommand(0x3, new byte[] { 0x30 }, 1, true); Subcommand(0x3, new byte[] { 0x30 }, 1, true);
@ -377,7 +377,9 @@ namespace BetterJoyForCemu {
byte[] raw_buf = new byte[report_len]; byte[] raw_buf = new byte[report_len];
int ret = HIDapi.hid_read(handle, raw_buf, new UIntPtr(report_len)); int ret = HIDapi.hid_read(handle, raw_buf, new UIntPtr(report_len));
if (ret > 0) { if (ret > 0) {
SendRumble(rumble_obj.GetData()); // Needed for USB to not time out if (!isPro)
SendRumble(rumble_obj.GetData()); // make rumble better when on bluetooth
// Process packets as soon as they come // Process packets as soon as they come
for (int n = 0; n < 3; n++) { for (int n = 0; n < 3; n++) {
ExtractIMUValues(raw_buf, n); ExtractIMUValues(raw_buf, n);
@ -411,6 +413,8 @@ namespace BetterJoyForCemu {
private void Poll() { private void Poll() {
int attempts = 0; int attempts = 0;
while (!stop_polling & state > state_.NO_JOYCONS) { while (!stop_polling & state > state_.NO_JOYCONS) {
if (isPro)
SendRumble(rumble_obj.GetData()); // Needed for USB to not time out
int a = ReceiveRaw(); int a = ReceiveRaw();
if (a > 0) { if (a > 0) {
@ -593,7 +597,7 @@ namespace BetterJoyForCemu {
} }
if (xin != null) { if (xin != null) {
if (other != null) { if (other != null | isPro) {
report.SetAxis(Xbox360Axes.LeftThumbX, (short)Math.Max(Int16.MinValue, Math.Min(Int16.MaxValue, stick[0] * (stick[0] > 0 ? Int16.MaxValue : -Int16.MinValue)))); report.SetAxis(Xbox360Axes.LeftThumbX, (short)Math.Max(Int16.MinValue, Math.Min(Int16.MaxValue, stick[0] * (stick[0] > 0 ? Int16.MaxValue : -Int16.MinValue))));
report.SetAxis(Xbox360Axes.LeftThumbY, (short)Math.Max(Int16.MinValue, Math.Min(Int16.MaxValue, stick[1] * (stick[1] > 0 ? Int16.MaxValue : -Int16.MinValue)))); report.SetAxis(Xbox360Axes.LeftThumbY, (short)Math.Max(Int16.MinValue, Math.Min(Int16.MaxValue, stick[1] * (stick[1] > 0 ? Int16.MaxValue : -Int16.MinValue))));
report.SetAxis(Xbox360Axes.RightThumbX, (short)Math.Max(Int16.MinValue, Math.Min(Int16.MaxValue, stick2[0] * (stick2[0] > 0 ? Int16.MaxValue : -Int16.MinValue)))); report.SetAxis(Xbox360Axes.RightThumbX, (short)Math.Max(Int16.MinValue, Math.Min(Int16.MaxValue, stick2[0] * (stick2[0] > 0 ? Int16.MaxValue : -Int16.MinValue))));
@ -648,6 +652,7 @@ namespace BetterJoyForCemu {
public void Begin() { public void Begin() {
if (PollThreadObj == null) { if (PollThreadObj == null) {
PollThreadObj = new Thread(new ThreadStart(Poll)); PollThreadObj = new Thread(new ThreadStart(Poll));
PollThreadObj.IsBackground = true;
PollThreadObj.Start(); PollThreadObj.Start();
form.console.Text += "Starting poll thread.\r\n"; form.console.Text += "Starting poll thread.\r\n";

View file

@ -31,23 +31,21 @@ namespace BetterJoyForCemu {
private void MainForm_Load(object sender, EventArgs e) { private void MainForm_Load(object sender, EventArgs e) {
this.ShowInTaskbar = true; this.ShowInTaskbar = true;
notifyIcon.Visible = false; notifyIcon.Visible = false;
this.Show();
Program.Start(); Program.Start();
} }
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { private void MainForm_FormClosing(object sender, FormClosingEventArgs e) {
try { try {
Program.Stop(); Program.Stop();
System.Threading.Thread.Sleep(1000); Close();
Application.Exit();
} catch { } } catch { }
} }
private void exitToolStripMenuItem_Click(object sender, EventArgs e) { private void exitToolStripMenuItem_Click(object sender, EventArgs e) {
try { try {
Program.Stop(); Program.Stop();
System.Threading.Thread.Sleep(1000); Close();
Application.Exit();
} catch { } } catch { }
} }

View file

@ -181,12 +181,12 @@ namespace BetterJoyForCemu {
} }
public void OnApplicationQuit() { public void OnApplicationQuit() {
for (int i = 0; i < j.Count; ++i) { foreach (Joycon v in j) {
j[i].Detach(); v.Detach();
if (j[i].xin != null) { if (v.xin != null) {
j[i].xin.Disconnect(); v.xin.Disconnect();
j[i].xin.Dispose(); v.xin.Dispose();
} }
} }
} }
@ -214,6 +214,7 @@ namespace BetterJoyForCemu {
public void Start() { public void Start() {
run = true; run = true;
thread = new Thread(new ThreadStart(Run)); thread = new Thread(new ThreadStart(Run));
thread.IsBackground = true;
thread.Start(); thread.Start();
} }