diff --git a/Source/OpenTK/Platform/MacOS/HIDInput.cs b/Source/OpenTK/Platform/MacOS/HIDInput.cs index 27c4c283..49a38e64 100755 --- a/Source/OpenTK/Platform/MacOS/HIDInput.cs +++ b/Source/OpenTK/Platform/MacOS/HIDInput.cs @@ -54,6 +54,19 @@ namespace OpenTK.Platform.MacOS { #region Fields + class JoystickDetails + { + public JoystickState State; + public JoystickCapabilities Capabilities; + } + + class MacJoystick : JoystickDevice + { + internal MacJoystick(int id, int axes, int buttons) + : base(id, axes, buttons) + { } + } + readonly IOHIDManagerRef hidmanager; readonly Dictionary MouseDevices = @@ -66,8 +79,8 @@ namespace OpenTK.Platform.MacOS readonly Dictionary KeyboardIndexToDevice = new Dictionary(); - readonly Dictionary JoystickDevices = - new Dictionary(new IntPtrEqualityComparer()); + readonly Dictionary JoystickDevices = + new Dictionary(new IntPtrEqualityComparer()); readonly Dictionary JoystickIndexToDevice = new Dictionary(); @@ -208,6 +221,7 @@ namespace OpenTK.Platform.MacOS MouseState mouse; KeyboardState keyboard; + MacJoystick joystick; if (MouseDevices.TryGetValue(context, out mouse)) { MouseDevices[context] = UpdateMouse(mouse, val); @@ -215,7 +229,13 @@ namespace OpenTK.Platform.MacOS else if (KeyboardDevices.TryGetValue(context, out keyboard)) { KeyboardDevices[context] = UpdateKeyboard(keyboard, val); - }else{ + } + else if (JoystickDevices.TryGetValue(context, out joystick)) + { + JoystickDevices[context] = UpdateJoystick(joystick, val); + } + else + { //Debug.Print ("Device {0:x} not found in list of keyboards or mice", sender); } } @@ -349,22 +369,31 @@ namespace OpenTK.Platform.MacOS #region Joystick + MacJoystick CreateJoystick(CFAllocatorRef sender, CFAllocatorRef device) + { + MacJoystick joy = new MacJoystick(-1, 0, 0); + joy.Details.State.SetIsConnected(true); + + // Todo: discover joystick capabilities + joy.Details.Capabilities = new JoystickCapabilities(0, 0, true); + + return joy; + } + void AddJoystick(CFAllocatorRef sender, CFAllocatorRef device) { if (!JoystickDevices.ContainsKey(device)) { Debug.Print("Joystick device {0:x} discovered, sender is {1:x}", device, sender); - JoystickState state = new JoystickState(); - state.SetIsConnected(true); - JoystickIndexToDevice.Add(KeyboardDevices.Count, device); - JoystickDevices.Add(device, state); + MacJoystick joy = CreateJoystick(sender, device); + JoystickIndexToDevice.Add(JoystickDevices.Count, device); + JoystickDevices.Add(device, joy); } else { Debug.Print("Joystick device {0:x} reconnected, sender is {1:x}", device, sender); - JoystickState state = JoystickDevices[device]; - state.SetIsConnected(true); - JoystickDevices[device] = state; + JoystickDevices[device].Details.State.SetIsConnected(true); + //JoystickDevices[device].Details.Capabilities.SetIsConnected(true); } } @@ -372,9 +401,24 @@ namespace OpenTK.Platform.MacOS { Debug.Print("Joystick device {0:x} disconnected, sender is {1:x}", device, sender); // Keep the device in case it comes back later on - JoystickState state = JoystickDevices[device]; - state.SetIsConnected(false); - JoystickDevices[device] = state; + JoystickDevices[device].Details.State.SetIsConnected(false); + //JoystickDevices[device].Details.Capabilities.SetIsConnected(false); + } + + static MacJoystick UpdateJoystick(MacJoystick state, IOHIDValueRef val) + { + //IOHIDElementRef elem = NativeMethods.IOHIDValueGetElement(val); + //int v_int = NativeMethods.IOHIDValueGetIntegerValue(val).ToInt32(); + //HIDPage page = NativeMethods.IOHIDElementGetUsagePage(elem); + //int usage = NativeMethods.IOHIDElementGetUsage(elem); + + //switch (page) + //{ + // case HIDPage.GenericDesktop: + // break; + //} + + return state; } #endregion