Skip to content

Commit 7b1400b

Browse files
committedJan 8, 2015
Fixed swapping buttons swapping the wrong controllers
1 parent 6c33dd7 commit 7b1400b

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed
 

‎XOutput.v12.suo

8.5 KB
Binary file not shown.

‎XOutput/ControllerManager.cs

+18-1
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,10 @@ public ControllerDevice[] detectControllers()
154154
if (devices[i] != null && !directInput.IsDeviceAttached(devices[i].joystick.Information.InstanceGuid))
155155
{
156156
Console.WriteLine(devices[i].joystick.Properties.InstanceName + " Removed");
157+
devices[i] = null;
158+
workers[i].Abort();
157159
workers[i] = null;
158160
Unplug(i + 1);
159-
devices[i] = null;
160161
}
161162
}
162163

@@ -204,6 +205,16 @@ public ControllerDevice[] detectControllers()
204205
joystick.Acquire();
205206

206207
devices[spot] = new ControllerDevice(joystick, spot + 1);
208+
if (IsActive)
209+
{
210+
processingData[spot] = new ContData();
211+
Console.WriteLine("Plug " + spot);
212+
Plugin(spot + 1);
213+
int t = spot;
214+
workers[spot] = new Thread(() =>
215+
{ ProcessData(t); });
216+
workers[spot].Start();
217+
}
207218
}
208219
return devices;
209220
}
@@ -217,6 +228,7 @@ public override bool Stop()
217228
{
218229
if (devices[i] != null && devices[i].enabled)
219230
{
231+
Console.WriteLine(i);
220232
workers[i].Abort();
221233
workers[i] = null;
222234
Unplug(i + 1);
@@ -279,6 +291,11 @@ private void ProcessData(int n)
279291
{
280292
lock (ds4locks[n])
281293
{
294+
if (devices[n] == null)
295+
{
296+
//Console.WriteLine("die" + n.ToString());
297+
//continue;
298+
}
282299
byte[] data = devices[n].getoutput();
283300
if (data != null && devices[n].enabled)
284301
{

‎XOutput/XOut.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ private void UpdateInfo(ControllerDevice[] dev)
110110

111111
private void Swap(int i, int p)
112112
{
113-
bool s = checks[i].Checked;
114-
checks[i].Checked = checks[p].Checked;
115-
checks[p].Checked = s;
113+
bool s = checks[i - 1].Checked;
114+
checks[i- 1].Checked = checks[p - 1].Checked;
115+
checks[p - 1].Checked = s;
116116
controllerManager.Swap(i, p);
117117

118118
UpdateInfo(controllerManager.detectControllers());

0 commit comments

Comments
 (0)
Please sign in to comment.