-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathForm1.cs
More file actions
493 lines (447 loc) · 26.5 KB
/
Form1.cs
File metadata and controls
493 lines (447 loc) · 26.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
using System;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using DirectInputManager;
namespace DirectInputExplorer
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//////////////////////////////////////////////////////////////
// .NET Events/Actions
//////////////////////////////////////////////////////////////
private void Form1_Load(object sender, EventArgs e)
{
DIManager.Initialize();
DIManager.OnDeviceAdded += DIDeviceAdded; // Register handler for when a device is attached
DIManager.OnDeviceRemoved += DIDeviceRemoved; // Register handler for when a device is removed
ButtonEnumerateDevices.PerformClick();
if (DIManager.devices.Length != 0) { ComboBoxDevices.SelectedIndex = 0; } // Select first device by default
// Disable tabs until device is attached
foreach (TabPage tab in TabController.TabPages)
{
tab.Enabled = false;
}
(TabController.TabPages[0] as TabPage).Enabled = true;
(TabController.TabPages["TabMisc"] as TabPage).Enabled = true;
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
DIManager.StopDirectInput();
}
private void ButtonEnumerateDevices_Click(object sender, EventArgs e)
{
string ExistingGUID = ComboBoxDevices.SelectedIndex != -1 ? DIManager.devices[ComboBoxDevices.SelectedIndex].guidInstance : ""; // GUID of device selected, empty if not
DIManager.EnumerateDevices(); // Fetch currently plugged in devices
ComboBoxDevices.Items.Clear();
foreach (DeviceInfo device in DIManager.devices)
{
ComboBoxDevices.Items.Add(device.productName);
}
if (!String.IsNullOrEmpty(ExistingGUID)) { ComboBoxDevices.SelectedIndex = Array.FindIndex(DIManager.devices, d => d.guidInstance == ExistingGUID); } // Reselect that device
}
private void ComboBoxDevices_SelectedIndexChanged(object sender, EventArgs e)
{
UpdateReadoutsWithDeviceData(DIManager.devices[ComboBoxDevices.SelectedIndex]);
}
private void ButtonAttach_Click(object sender, EventArgs e)
{
DeviceInfo targetDevice = DIManager.devices[ComboBoxDevices.SelectedIndex];
DIManager.Attach(targetDevice); // Connect to device
UpdateReadoutsWithDeviceData(DIManager.devices[ComboBoxDevices.SelectedIndex]);
// Attach Events
ActiveDeviceInfo ADI;
if (DIManager.GetADI(targetDevice, out ADI))
{ // Check if device active
ADI.OnDeviceRemoved += DIDeviceRemoved; // Register a handler for when the device is removed
ADI.OnDeviceStateChange += DeviceStateChanged; // Register a handler for when the device state changes
if (DIManager.FFBCapable(targetDevice))
{
(TabController.TabPages["tabPage1"] as TabPage).Enabled = true;
}
else
{
(TabController.TabPages["tabPage1"] as TabPage).Enabled = false;
}
}
}
private void ButtonRemove_Click(object sender, EventArgs e)
{
DIManager.StopAllFFBEffects(DIManager.devices[ComboBoxDevices.SelectedIndex]);
DIManager.Destroy(DIManager.devices[ComboBoxDevices.SelectedIndex]); // Destroy device
UpdateReadoutsWithDeviceData(DIManager.devices[ComboBoxDevices.SelectedIndex]);
(TabController.TabPages["tabPage1"] as TabPage).Enabled = false;
}
private void TimerPoll_Tick_1(object sender, EventArgs e)
{
// If device connected get data
/*if (DIManager.devices.Length != 0 && DIManager.isDeviceActive(DIManager.devices[ComboBoxDevices.SelectedIndex])) { // Currently selected device is attached
FlatJoyState2 DeviceState = DIManager.GetDeviceState(DIManager.devices[ComboBoxDevices.SelectedIndex]);
LabelInput.Text = $"buttonsA: {Convert.ToString((long)DeviceState.buttonsA, 2).PadLeft(64, '0')}\nbuttonsB: {Convert.ToString((long)DeviceState.buttonsB, 2).PadLeft(64, '0')}\nlX: {DeviceState.lX}\nlY: {DeviceState.lY}\nlZ: {DeviceState.lZ}\nlU: {DeviceState.lU}\nlV: {DeviceState.lV}\nlRx: {DeviceState.lRx}\nlRy: {DeviceState.lRy}\nlRz: {DeviceState.lRz}\nlVX: {DeviceState.lVX}\nlVY: {DeviceState.lVY}\nlVZ: {DeviceState.lVZ}\nlVU: {DeviceState.lVU}\nlVV: {DeviceState.lVV}\nlVRx: {DeviceState.lVRx}\nlVRy: {DeviceState.lVRy}\nlVRz: {DeviceState.lVRz}\nlAX: {DeviceState.lAX}\nlAY: {DeviceState.lAY}\nlAZ: {DeviceState.lAZ}\nlAU: {DeviceState.lAU}\nlAV: {DeviceState.lAV}\nlARx: {DeviceState.lARx}\nlARy: {DeviceState.lARy}\nlARz: {DeviceState.lARz}\nlFX: {DeviceState.lFX}\nlFY: {DeviceState.lFY}\nlFZ: {DeviceState.lFZ}\nlFU: {DeviceState.lFU}\nlFV: {DeviceState.lFV}\nlFRx: {DeviceState.lFRx}\nlFRy: {DeviceState.lFRy}\nlFRz: {DeviceState.lFRz}\nrgdwPOV: {Convert.ToString((long)DeviceState.rgdwPOV, 2).PadLeft(16, '0')}\n";
}*/
DIManager.PollAll(); // Fetch data from all active devices
if (DIManager.devices.Length != 0 && DIManager.isDeviceActive(DIManager.devices[ComboBoxDevices.SelectedIndex]))
{ // Currently selected device is attached
UpdateReadoutsWithDeviceData(DIManager.devices[ComboBoxDevices.SelectedIndex]); // Update readouts with active device data
}
}
//////////////////////////////////////////////////////////////
// FFB Tab Functions
//////////////////////////////////////////////////////////////
private void FFB_CheckBox_CheckedChanged(object sender, EventArgs e)
{
CheckBox TriggeringCheckBox = (CheckBox)sender;
FFBEffects TriggeringEffectType = (FFBEffects)Enum.Parse(typeof(FFBEffects), TriggeringCheckBox.Tag.ToString());
if (TriggeringCheckBox.Checked)
{
// Special handling for the periodic effects
if (TriggeringCheckBox.Tag.ToString() == "Sine" ||
TriggeringCheckBox.Tag.ToString() == "SawtoothDown" ||
TriggeringCheckBox.Tag.ToString() == "SawtoothUp" ||
TriggeringCheckBox.Tag.ToString() == "RampForce" ||
TriggeringCheckBox.Tag.ToString() == "Triangle" ||
TriggeringCheckBox.Tag.ToString() == "Square")
{
// Create and initialize periodic effect
if (!DIManager.EnableFFBEffect(DIManager.devices[ComboBoxDevices.SelectedIndex], TriggeringEffectType))
{
Debug.WriteLine($"Failed to enable periodic effect");
TriggeringCheckBox.Checked = false;
return;
}
// Initialize with current magnitude
if (TriggeringCheckBox.Parent.Controls.Find("UD" + TriggeringEffectType.ToString() + "Magnitude", false).FirstOrDefault() as NumericUpDown != null)
{
UpdatePeriodicSimple(
DIManager.devices[ComboBoxDevices.SelectedIndex],
TriggeringEffectType,
(int)(TriggeringCheckBox.Parent.Controls.Find("UD" + TriggeringEffectType.ToString() + "Magnitude", false).FirstOrDefault() as NumericUpDown).Value,
TriggeringCheckBox.Parent.Controls.Find("UD" + TriggeringEffectType.ToString() + "Magnitude", false).FirstOrDefault() as NumericUpDown
);
}
}
else
{
// Handle other effects normally
TriggeringCheckBox.Checked = DIManager.EnableFFBEffect(
DIManager.devices[ComboBoxDevices.SelectedIndex],
TriggeringEffectType
);
}
}
else
{
// Special handling for periodic effects
if (TriggeringCheckBox.Tag.ToString() == "Sine" ||
TriggeringCheckBox.Tag.ToString() == "SawtoothDown" ||
TriggeringCheckBox.Tag.ToString() == "SawtoothUp" ||
TriggeringCheckBox.Tag.ToString() == "RampForce" ||
TriggeringCheckBox.Tag.ToString() == "Triangle" ||
TriggeringCheckBox.Tag.ToString() == "Square")
{
// First stop the effect by setting magnitude to 0
UpdatePeriodicSimple(
DIManager.devices[ComboBoxDevices.SelectedIndex],
(FFBEffects)Enum.Parse(typeof(FFBEffects), TriggeringCheckBox.Tag.ToString()),
0,
TriggeringCheckBox.Parent.Controls.Find("UD" + TriggeringEffectType.ToString() + "Magnitude", false).FirstOrDefault() as NumericUpDown
);
// Then destroy the effect
TriggeringCheckBox.Checked = !DIManager.DestroyFFBEffect(DIManager.devices[ComboBoxDevices.SelectedIndex], (FFBEffects)Enum.Parse(typeof(FFBEffects), TriggeringCheckBox.Tag.ToString()));
}
else
{
// Handle other effects normally
TriggeringCheckBox.Checked = !DIManager.DestroyFFBEffect(DIManager.devices[ComboBoxDevices.SelectedIndex], TriggeringEffectType);
}
}
// Update control states
foreach (Control element in TriggeringCheckBox.Parent.Controls)
{
if (element is CheckBox) continue;
element.Enabled = TriggeringCheckBox.Checked;
}
}
private void FFB_GroupBox_Click(object sender, EventArgs e)
{
CheckBox CB = ((GroupBox)sender).Controls.Find("CB" + ((GroupBox)sender).Tag, false).FirstOrDefault() as CheckBox;
CB.Checked = !CB.Checked;
}
private void FFB_Label_Click(object sender, EventArgs e)
{
Label TrigElement = (Label)sender;
TrackBar TB = TrigElement.Parent.Controls.Find("Slider" + TrigElement.Tag, false).FirstOrDefault() as TrackBar;
NumericUpDown UD = TrigElement.Parent.Controls.Find("UD" + TrigElement.Tag, false).FirstOrDefault() as NumericUpDown;
switch (TB.Tag)
{
case string a when a.Contains("Saturation"): // Center Saturation to 5000
TB.Value = 5000;
UD.Value = 5000;
break;
default:
TB.Value = 0;
UD.Value = 0;
break;
}
}
private void FFB_Slider_Scroll(object sender, EventArgs e)
{
TrackBar TrigElement = (TrackBar)sender;
// Update UpDown
NumericUpDown UD = TrigElement.Parent.Controls.Find("UD" + TrigElement.Tag, false).FirstOrDefault() as NumericUpDown;
UD.Value = TrigElement.Value;
// FFB Effect has changed
}
private void FFB_UpDown_ValueChanged(object sender, EventArgs e)
{
DeviceInfo ActiveDevice = DIManager.devices[ComboBoxDevices.SelectedIndex];
NumericUpDown TrigElement = (NumericUpDown)sender;
// Update slider(TrackBar)
TrackBar TB = TrigElement.Parent.Controls.Find("Slider" + TrigElement.Tag, false).FirstOrDefault() as TrackBar;
TB.Value = (int)TrigElement.Value;
// Update Effect
switch (TrigElement.Parent.Tag)
{
case "ConstantForce":
DIManager.UpdateConstantForceSimple(ActiveDevice, (int)((TrigElement.Parent.Controls.Find("UDConstantForceMagnitude", false).FirstOrDefault() as NumericUpDown).Value));
break;
case "Spring":
DIManager.UpdateSpringSimple(ActiveDevice,
(uint)((TrigElement.Parent.Controls.Find("UDSpringDeadband", false).FirstOrDefault() as NumericUpDown).Value),
(int)((TrigElement.Parent.Controls.Find("UDSpringOffset", false).FirstOrDefault() as NumericUpDown).Value),
(int)((TrigElement.Parent.Controls.Find("UDSpringCoefficient", false).FirstOrDefault() as NumericUpDown).Value),
(int)((TrigElement.Parent.Controls.Find("UDSpringCoefficient", false).FirstOrDefault() as NumericUpDown).Value),
(uint)((TrigElement.Parent.Controls.Find("UDSpringSaturation", false).FirstOrDefault() as NumericUpDown).Value),
(uint)((TrigElement.Parent.Controls.Find("UDSpringSaturation", false).FirstOrDefault() as NumericUpDown).Value)
);
break;
case "Damper":
DIManager.UpdateDamperSimple(ActiveDevice, (int)((TrigElement.Parent.Controls.Find("UDDamperMagnitude", false).FirstOrDefault() as NumericUpDown).Value));
break;
case "Friction":
DIManager.UpdateFrictionSimple(ActiveDevice, (int)((TrigElement.Parent.Controls.Find("UDFrictionMagnitude", false).FirstOrDefault() as NumericUpDown).Value));
break;
case "Inertia":
DIManager.UpdateInertiaSimple(ActiveDevice, (int)((TrigElement.Parent.Controls.Find("UDInertiaMagnitude", false).FirstOrDefault() as NumericUpDown).Value));
break;
case "Sine":
UpdatePeriodicSimple(
ActiveDevice,
FFBEffects.Sine,
(int)((TrigElement.Parent.Controls.Find("UDSineMagnitude", false).FirstOrDefault() as NumericUpDown).Value),
TrigElement
);
break;
case "RampForce":
UpdatePeriodicSimple(
ActiveDevice,
FFBEffects.RampForce,
(int)((TrigElement.Parent.Controls.Find("UDRampForceMagnitude", false).FirstOrDefault() as NumericUpDown).Value),
TrigElement
);
break;
case "SawtoothDown":
UpdatePeriodicSimple(
ActiveDevice,
FFBEffects.SawtoothDown,
(int)((TrigElement.Parent.Controls.Find("UDSawtoothDownMagnitude", false).FirstOrDefault() as NumericUpDown).Value),
TrigElement
);
break;
case "SawtoothUp":
UpdatePeriodicSimple(
ActiveDevice,
FFBEffects.SawtoothUp,
(int)((TrigElement.Parent.Controls.Find("UDSawtoothUpMagnitude", false).FirstOrDefault() as NumericUpDown).Value),
TrigElement
);
break;
case "Square":
UpdatePeriodicSimple(
ActiveDevice,
FFBEffects.Square,
(int)((TrigElement.Parent.Controls.Find("UDSquareMagnitude", false).FirstOrDefault() as NumericUpDown).Value),
TrigElement
);
break;
case "Triangle":
UpdatePeriodicSimple(
ActiveDevice,
FFBEffects.Triangle,
(int)((TrigElement.Parent.Controls.Find("UDTriangleMagnitude", false).FirstOrDefault() as NumericUpDown).Value),
TrigElement
);
break;
case "CustomForce":
uint samplePeriod = (uint)((TrigElement.Parent.Controls.Find("UDCustomForceSamplePeriod", false).FirstOrDefault() as NumericUpDown).Value);
int magnitude0 = (int)((TrigElement.Parent.Controls.Find("UDCustomForceMagnitude0", false).FirstOrDefault() as NumericUpDown).Value);
int magnitude1 = (int)((TrigElement.Parent.Controls.Find("UDCustomForceMagnitude1", false).FirstOrDefault() as NumericUpDown).Value);
int magnitude2 = (int)((TrigElement.Parent.Controls.Find("UDCustomForceMagnitude2", false).FirstOrDefault() as NumericUpDown).Value);
int magnitude3 = (int)((TrigElement.Parent.Controls.Find("UDCustomForceMagnitude3", false).FirstOrDefault() as NumericUpDown).Value);
int magnitude4 = (int)((TrigElement.Parent.Controls.Find("UDCustomForceMagnitude4", false).FirstOrDefault() as NumericUpDown).Value);
int magnitude5 = (int)((TrigElement.Parent.Controls.Find("UDCustomForceMagnitude5", false).FirstOrDefault() as NumericUpDown).Value);
int magnitude6 = (int)((TrigElement.Parent.Controls.Find("UDCustomForceMagnitude6", false).FirstOrDefault() as NumericUpDown).Value);
int magnitude7 = (int)((TrigElement.Parent.Controls.Find("UDCustomForceMagnitude7", false).FirstOrDefault() as NumericUpDown).Value);
int magnitude8 = (int)((TrigElement.Parent.Controls.Find("UDCustomForceMagnitude8", false).FirstOrDefault() as NumericUpDown).Value);
int magnitude9 = (int)((TrigElement.Parent.Controls.Find("UDCustomForceMagnitude9", false).FirstOrDefault() as NumericUpDown).Value);
int[] forceData = new int[] { magnitude0,
magnitude1,
magnitude2,
magnitude3,
magnitude4,
magnitude5,
magnitude6,
magnitude7,
magnitude8,
magnitude9,
};
UpdateCustomForceSimple(
ActiveDevice,
forceData,
samplePeriod,
TrigElement
);
break;
default:
break;
}
//System.Diagnostics.Debug.WriteLine("Changed: " + TrigElement.Parent.Tag);
}
private void UpdatePeriodicSimple(DeviceInfo activeDevice, FFBEffects effectType, int magnitude, NumericUpDown trigElement)
{
try
{
if (activeDevice.guidInstance == null || trigElement == null)
{
Debug.WriteLine("UpdatePeriodicSimple: Invalid input parameters");
return;
}
// Get the effect checkbox
CheckBox effectCheckBox = trigElement.Parent.Controls.Find("CB" + effectType.ToString(), false).FirstOrDefault() as CheckBox;
// First destroy any existing periodic effect
foreach (FFBEffects effects in new FFBEffects[] { FFBEffects.SawtoothUp, FFBEffects.SawtoothDown, FFBEffects.Square,
FFBEffects.Triangle, FFBEffects.RampForce, FFBEffects.Sine})
{
DIManager.DestroyFFBEffect(activeDevice, effectType);
}
// Then create new effect
if (!DIManager.EnableFFBEffect(activeDevice, effectType))
{
Debug.WriteLine($"UpdatePeriodicSimple: Failed to create effect {effectType}");
if (effectCheckBox != null)
{
effectCheckBox.Checked = false;
}
return;
}
// Update the effect
DIManager.UpdatePeriodicSimple(
activeDevice,
effectType,
magnitude
);
}
catch (Exception ex)
{
Debug.WriteLine($"UpdatePeriodicSimple: Exception occurred: {ex.Message}");
Debug.WriteLine(ex.StackTrace);
}
}
private void UpdateCustomForceSimple(DeviceInfo activeDevice, int[] forceData, uint samplePeriod, NumericUpDown trigElement)
{
try
{
if (activeDevice.guidInstance == null || trigElement == null)
{
Debug.WriteLine("UpdatePeriodicSimple: Invalid input parameters");
return;
}
// Get the effect checkbox
CheckBox effectCheckBox = trigElement.Parent.Controls.Find("CBCustomForce", false).FirstOrDefault() as CheckBox;
DIManager.DestroyFFBEffect(activeDevice, FFBEffects.CustomForce);
// Then create new effect
if (!DIManager.EnableFFBEffect(activeDevice, FFBEffects.CustomForce))
{
Debug.WriteLine($"UpdatePeriodicSimple: Failed to create effect \"CustomForce\"");
if (effectCheckBox != null)
{
effectCheckBox.Checked = false;
}
return;
}
DIManager.UpdateCustomForceEffect(activeDevice, forceData, samplePeriod);
}
catch (Exception ex)
{
Debug.WriteLine($"UpdateCustomForceSimple error: {ex.Message}");
}
}
//////////////////////////////////////////////////////////////
// Device Events
//////////////////////////////////////////////////////////////
public void DIDeviceAdded(DeviceInfo device)
{
string deviceName = $"{device.productName}:{device.guidInstance}";
System.Diagnostics.Debug.WriteLine($"{deviceName} Added!");
ButtonEnumerateDevices.PerformClick(); // Refresh device dropdown
}
public void DIDeviceRemoved(DeviceInfo device)
{
string deviceName = $"{device.productName}:{device.guidInstance}";
System.Diagnostics.Debug.WriteLine($"{deviceName} Removed!");
ButtonEnumerateDevices.PerformClick(); // Refresh device dropdown
}
public void DeviceStateChanged(DeviceInfo device, FlatJoyState2 state)
{
System.Diagnostics.Debug.WriteLine($"{device.productName} Event {state.lX}");
if (device.guidInstance == DIManager.devices[ComboBoxDevices.SelectedIndex].guidInstance)
{ // If this device is selected show the state
LabelInput.Text = $"buttonsA: {Convert.ToString((long)state.buttonsA, 2).PadLeft(64, '0')}\nbuttonsB: {Convert.ToString((long)state.buttonsB, 2).PadLeft(64, '0')}\nlX: {state.lX}\nlY: {state.lY}\nlZ: {state.lZ}\nlU: {state.lU}\nlV: {state.lV}\nlRx: {state.lRx}\nlRy: {state.lRy}\nlRz: {state.lRz}\nlVX: {state.lVX}\nlVY: {state.lVY}\nlVZ: {state.lVZ}\nlVU: {state.lVU}\nlVV: {state.lVV}\nlVRx: {state.lVRx}\nlVRy: {state.lVRy}\nlVRz: {state.lVRz}\nlAX: {state.lAX}\nlAY: {state.lAY}\nlAZ: {state.lAZ}\nlAU: {state.lAU}\nlAV: {state.lAV}\nlARx: {state.lARx}\nlARy: {state.lARy}\nlARz: {state.lARz}\nlFX: {state.lFX}\nlFY: {state.lFY}\nlFZ: {state.lFZ}\nlFU: {state.lFU}\nlFV: {state.lFV}\nlFRx: {state.lFRx}\nlFRy: {state.lFRy}\nlFRz: {state.lFRz}\nrgdwPOV: {Convert.ToString((long)state.rgdwPOV, 2).PadLeft(16, '0')}\n";
}
}
//////////////////////////////////////////////////////////////
// Utility Functions
//////////////////////////////////////////////////////////////
private void UpdateReadoutsWithDeviceData(DeviceInfo Device)
{
LabelDeviceInfo.Text = $"deviceType: {Device.deviceType}\nguidInstance: {Device.guidInstance}\nguidProduct: {Device.guidProduct}\ninstanceName: {Device.instanceName}\nFFBCapable: {Device.FFBCapable}";
if (DIManager.isDeviceActive(DIManager.devices[ComboBoxDevices.SelectedIndex]))
{ // Currently selected device is attached
(TabController.TabPages["TabInput"] as TabPage).Enabled = true; // Enable the Input Tab as we're connected
DIDEVCAPS DeviceCaps = DIManager.GetDeviceCapabilities(Device);
LabelCapabilities.Text = $"dwSize: {DeviceCaps.dwSize}\ndwFlags: {DeviceCaps.dwFlags}\ndwDevType: {Convert.ToString(DeviceCaps.dwDevType, 2).PadLeft(32, '0')}\ndwAxes: {DeviceCaps.dwAxes}\ndwButtons: {DeviceCaps.dwButtons}\ndwPOVs: {DeviceCaps.dwPOVs}\ndwFFSamplePeriod: {DeviceCaps.dwFFSamplePeriod}\ndwFFMinTimeResolution: {DeviceCaps.dwFFMinTimeResolution}\ndwFirmwareRevision: {DeviceCaps.dwFirmwareRevision}\ndwHardwareRevision: {DeviceCaps.dwHardwareRevision}\ndwFFDriverVersion: {DeviceCaps.dwFFDriverVersion}";
if (DIManager.FFBCapable(Device))
{
(TabController.TabPages["TabFFB"] as TabPage).Enabled = true; // If Device is FFB capable, enable the tab
LabelFFBCapabilities.Text = string.Join("\n", DIManager.GetDeviceFFBCapabilities(Device));
}
else
{
(TabController.TabPages["TabFFB"] as TabPage).Enabled = false;
LabelFFBCapabilities.Text = "FFBCapabilities: FFB Unsupported";
}
}
else
{ // Device isn't attached, default readouts
LabelInput.Text = "Input: Attach First";
LabelCapabilities.Text = "Capabilities: Attach First";
LabelFFBCapabilities.Text = "FFBCapabilities: Attach First";
(TabController.TabPages["TabInput"] as TabPage).Enabled = false;
(TabController.TabPages["TabFFB"] as TabPage).Enabled = false;
}
}
//////////////////////////////////////////////////////////////
// Debug Functions
//////////////////////////////////////////////////////////////
private void ButtonDebug_Click(object sender, EventArgs e)
{
DirectInputManager.Native.DEBUG1(DIManager.devices[ComboBoxDevices.SelectedIndex].guidInstance, out string[] DEBUGDATA);
LabelDebug.Text = string.Join("\n", DEBUGDATA);
}
}
}