(Apple) Move hid_pad.c to input/

This commit is contained in:
twinaphex 2014-05-03 07:08:10 +02:00
parent 77401692cb
commit 6b0f9d3698
2 changed files with 19 additions and 19 deletions

View File

@ -14,7 +14,7 @@
*/ */
#include <IOKit/hid/IOHIDManager.h> #include <IOKit/hid/IOHIDManager.h>
#include "../../input/apple_input.h" #include "apple_input.h"
struct apple_pad_connection struct apple_pad_connection
{ {
@ -33,7 +33,7 @@ void apple_pad_send_control(struct apple_pad_connection* connection, uint8_t* da
// NOTE: I pieced this together through trial and error, any corrections are welcome // NOTE: I pieced this together through trial and error, any corrections are welcome
static void hid_device_input_callback(void* context, IOReturn result, void* sender, IOHIDValueRef value) static void hid_device_input_callback(void* context, IOReturn result, void* sender, IOHIDValueRef value)
{ {
struct apple_pad_connection* connection = context; struct apple_pad_connection* connection = (struct apple_pad_connection*)context;
IOHIDElementRef element = IOHIDValueGetElement(value); IOHIDElementRef element = IOHIDValueGetElement(value);
uint32_t type = IOHIDElementGetType(element); uint32_t type = IOHIDElementGetType(element);
@ -90,7 +90,9 @@ static void hid_device_report(void* context, IOReturn result, void *sender, IOHI
static void hid_manager_device_attached(void* context, IOReturn result, void* sender, IOHIDDeviceRef device) static void hid_manager_device_attached(void* context, IOReturn result, void* sender, IOHIDDeviceRef device)
{ {
char device_name[1024];
struct apple_pad_connection* connection = calloc(1, sizeof(struct apple_pad_connection)); struct apple_pad_connection* connection = calloc(1, sizeof(struct apple_pad_connection));
connection->device = device; connection->device = device;
connection->slot = MAX_PLAYERS; connection->slot = MAX_PLAYERS;
@ -99,7 +101,6 @@ static void hid_manager_device_attached(void* context, IOReturn result, void* se
IOHIDDeviceRegisterRemovalCallback(device, hid_device_removed, connection); IOHIDDeviceRegisterRemovalCallback(device, hid_device_removed, connection);
CFStringRef device_name_ref = IOHIDDeviceGetProperty(device, CFSTR(kIOHIDProductKey)); CFStringRef device_name_ref = IOHIDDeviceGetProperty(device, CFSTR(kIOHIDProductKey));
char device_name[1024];
CFStringGetCString(device_name_ref, device_name, sizeof(device_name), kCFStringEncodingUTF8); CFStringGetCString(device_name_ref, device_name, sizeof(device_name), kCFStringEncodingUTF8);
connection->slot = apple_joypad_connect(device_name, connection); connection->slot = apple_joypad_connect(device_name, connection);
@ -126,27 +127,27 @@ static void append_matching_dictionary(CFMutableArrayRef array, uint32_t page, u
CFRelease(matcher); CFRelease(matcher);
} }
void osx_pad_init() void osx_pad_init(void)
{ {
if (!g_hid_manager) if (g_hid_manager)
{ return;
g_hid_manager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
CFMutableArrayRef matcher = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks); g_hid_manager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
append_matching_dictionary(matcher, kHIDPage_GenericDesktop, kHIDUsage_GD_Joystick);
append_matching_dictionary(matcher, kHIDPage_GenericDesktop, kHIDUsage_GD_GamePad);
IOHIDManagerSetDeviceMatchingMultiple(g_hid_manager, matcher); CFMutableArrayRef matcher = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
CFRelease(matcher); append_matching_dictionary(matcher, kHIDPage_GenericDesktop, kHIDUsage_GD_Joystick);
append_matching_dictionary(matcher, kHIDPage_GenericDesktop, kHIDUsage_GD_GamePad);
IOHIDManagerRegisterDeviceMatchingCallback(g_hid_manager, hid_manager_device_attached, 0); IOHIDManagerSetDeviceMatchingMultiple(g_hid_manager, matcher);
IOHIDManagerScheduleWithRunLoop(g_hid_manager, CFRunLoopGetMain(), kCFRunLoopCommonModes); CFRelease(matcher);
IOHIDManagerOpen(g_hid_manager, kIOHIDOptionsTypeNone); IOHIDManagerRegisterDeviceMatchingCallback(g_hid_manager, hid_manager_device_attached, 0);
} IOHIDManagerScheduleWithRunLoop(g_hid_manager, CFRunLoopGetMain(), kCFRunLoopCommonModes);
IOHIDManagerOpen(g_hid_manager, kIOHIDOptionsTypeNone);
} }
void osx_pad_quit() void osx_pad_quit(void)
{ {
if (g_hid_manager) if (g_hid_manager)
{ {
@ -158,4 +159,3 @@ void osx_pad_quit()
g_hid_manager = 0; g_hid_manager = 0;
} }

View File

@ -21,7 +21,7 @@
#include "../apple/iOS/bluetooth/btpad.c" #include "../apple/iOS/bluetooth/btpad.c"
#include "../apple/iOS/bluetooth/btpad_queue.c" #include "../apple/iOS/bluetooth/btpad_queue.c"
#elif defined(OSX) #elif defined(OSX)
#include "../apple/OSX/hid_pad.c" #include "apple_hid_pad.c"
#endif #endif
#include "../apple/common/hidpad/wiimote.c" #include "../apple/common/hidpad/wiimote.c"