Permalink
Browse files

[Input] Added JoystickCapabilities.HatCount

  • Loading branch information...
1 parent 168c45f commit a7228274aa32a70772355963d690a2b39a1189a9 @thefiddler thefiddler committed Jan 31, 2014
@@ -40,21 +40,23 @@ public struct JoystickCapabilities : IEquatable<JoystickCapabilities>
{
byte axis_count;
byte button_count;
- byte dpad_count;
+ byte hat_count;
bool is_connected;
#region Constructors
- internal JoystickCapabilities(int axis_count, int button_count, bool is_connected)
+ internal JoystickCapabilities(int axis_count, int button_count, int hat_count, bool is_connected)
{
- if (axis_count < 0 || axis_count >= JoystickState.MaxAxes)
+ if (axis_count < 0 || axis_count > JoystickState.MaxAxes)
throw new ArgumentOutOfRangeException("axis_count");
- if (button_count < 0 || button_count >= JoystickState.MaxButtons)
+ if (button_count < 0 || button_count > JoystickState.MaxButtons)
throw new ArgumentOutOfRangeException("axis_count");
+ if (hat_count < 0 || hat_count > JoystickState.MaxHats)
+ throw new ArgumentOutOfRangeException("hat_count");
this.axis_count = (byte)axis_count;
this.button_count = (byte)button_count;
- this.dpad_count = 0; // Todo: either remove dpad_count or add it as a parameter
+ this.hat_count = (byte)hat_count;
this.is_connected = is_connected;
}
@@ -78,6 +80,14 @@ public int ButtonCount
get { return button_count; }
}
+ /// <summary>
+ /// Gets the number of hats supported by this <see cref="JoystickDevice"/>.
+ /// </summary>
+ public int HatCount
+ {
+ get { return hat_count; }
+ }
+
/// <summary>
/// Gets a value indicating whether this <see cref="JoystickDevice"/> is connected.
/// </summary>
@@ -94,8 +104,8 @@ public bool IsConnected
public override string ToString()
{
return String.Format(
- "{{Axes: {0}; Buttons: {1}; IsConnected: {2}}}",
- AxisCount, ButtonCount, IsConnected);
+ "{{Axes: {0}; Buttons: {1}; Hats: {2}; IsConnected: {2}}}",
+ AxisCount, ButtonCount, HatCount, IsConnected);
}
/// <summary>
@@ -108,6 +118,7 @@ public override int GetHashCode()
return
AxisCount.GetHashCode() ^
ButtonCount.GetHashCode() ^
+ HatCount.GetHashCode() ^
IsConnected.GetHashCode();
}
@@ -126,15 +137,6 @@ public override bool Equals(object obj)
#endregion
- #region Private Members
-
- int DPadCount
- {
- get { return dpad_count; }
- }
-
- #endregion
-
#region IEquatable<JoystickCapabilities> Members
/// <summary>
@@ -148,6 +150,7 @@ public bool Equals(JoystickCapabilities other)
return
AxisCount == other.AxisCount &&
ButtonCount == other.ButtonCount &&
+ HatCount == other.HatCount &&
IsConnected == other.IsConnected;
}
@@ -441,7 +441,7 @@ JoystickData CreateJoystick(IntPtr sender, IntPtr device)
joy = new JoystickData();
int axes = 0;
int buttons = 0;
- int dpads = 0;
+ int hats = 0;
CFStringRef name_ref = NativeMethods.IOHIDDeviceGetProperty(device, NativeMethods.IOHIDProductKey);
string name = CF.CFStringGetCString(name_ref);
@@ -475,7 +475,7 @@ JoystickData CreateJoystick(IntPtr sender, IntPtr device)
break;
case HIDUsageGD.Hatswitch:
- dpads++;
+ hats++;
break;
}
break;
@@ -499,7 +499,7 @@ JoystickData CreateJoystick(IntPtr sender, IntPtr device)
joy.Name = name;
joy.Guid = guid;
joy.State.SetIsConnected(true);
- joy.Capabilities = new JoystickCapabilities(axes, buttons, true);
+ joy.Capabilities = new JoystickCapabilities(axes, buttons, hats, true);
// Map button elements to JoystickButtons
for (int button = 0; button < button_elements.Count; button++)
@@ -656,6 +656,7 @@ JoystickCapabilities IJoystickDriver2.GetCapabilities(int index)
return new JoystickCapabilities(
joystick.Axis.Count,
joystick.Button.Count,
+ joystick.Details.HatCount,
joystick.Details.IsConnected);
}
return new JoystickCapabilities();
@@ -269,7 +269,10 @@ public JoystickCapabilities GetCapabilities(int index)
if (result == JoystickError.NoError)
{
JoystickCapabilities caps = new JoystickCapabilities(
- mmcaps.NumAxes, mmcaps.NumButtons, true);
+ mmcaps.NumAxes,
+ mmcaps.NumButtons,
+ (mmcaps.Capabilities & JoystCapsFlags.HasPov) != 0 ? 1 : 0,
+ true);
//if ((caps.Capabilities & JoystCapsFlags.HasPov) != 0)
// gpcaps.DPadCount++;
return caps;
@@ -484,7 +484,10 @@ JoystickCapabilities IJoystickDriver2.GetCapabilities(int index)
{
JoystickDevice<X11JoyDetails> js = sticks[index_to_stick[index]];
caps = new JoystickCapabilities(
- js.Axis.Count, js.Button.Count, js.Details.State.IsConnected);
+ js.Axis.Count,
+ js.Button.Count,
+ 0, // hats not supported by /dev/js
+ js.Details.State.IsConnected);
}
return caps;
}

0 comments on commit a722827

Please sign in to comment.