1 /** \file joy-osx-hidlib.h 2 * \brief Common interface for the HID implementations - header 3 * 4 * \author Christian Vogelgsang <chris@vogelgsang.org> 5 */ 6 7 /* 8 * This file is part of VICE, the Versatile Commodore Emulator. 9 * See README for copyright notice. 10 * 11 * This program is free software; you can redistribute it and/or modify 12 * it under the terms of the GNU General Public License as published by 13 * the Free Software Foundation; either version 2 of the License, or 14 * (at your option) any later version. 15 * 16 * This program is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU General Public License for more details. 20 * 21 * You should have received a copy of the GNU General Public License 22 * along with this program; if not, write to the Free Software 23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 24 * 02111-1307 USA. 25 * 26 */ 27 28 #ifndef VICE_JOY_OSX_HIDLIB_H 29 #define VICE_JOY_OSX_HIDLIB_H 30 31 #include "vice.h" 32 33 #ifdef HAS_JOYSTICK 34 35 #ifdef HAS_HIDMGR 36 /* Use Leopard's IOHIDManager API */ 37 #include <IOKit/hid/IOHIDManager.h> 38 39 typedef IOHIDDeviceRef hid_device_ref_t; 40 typedef IOHIDElementRef hid_element_ref_t; 41 42 #else 43 /* NOTE: We use the HID Utilites Library provided by Apple for free 44 45 http://developer.apple.com/samplecode/HID_Utilities_Source/index.html 46 47 Make sure to install this (static) library first! 48 */ 49 #include <Carbon/Carbon.h> 50 #include <IOKit/hid/IOHIDKeys.h> 51 #include <IOKit/hid/IOHIDUsageTables.h> 52 #include "HID_Utilities_External.h" 53 54 /* HID Mgr Types */ 55 typedef pRecDevice hid_device_ref_t; 56 typedef pRecElement hid_element_ref_t; 57 #endif 58 59 /* model a hid element */ 60 struct joy_hid_element { 61 int usage_page; 62 int usage; 63 64 int min_pvalue; /* physical value */ 65 int max_pvalue; 66 int min_lvalue; /* logical value */ 67 int max_lvalue; 68 69 hid_element_ref_t internal_element; 70 }; 71 typedef struct joy_hid_element joy_hid_element_t; 72 typedef struct joy_hid_element *joy_hid_element_ptr_t; 73 74 /* model a hid device */ 75 struct joy_hid_device { 76 int vendor_id; 77 int product_id; 78 int serial; 79 char *product_name; 80 81 int num_elements; /* number of elements in device */ 82 joy_hid_element_t *elements; 83 84 hid_device_ref_t internal_device; /* pointer to native device */ 85 86 #ifdef HAS_HIDMGR 87 CFArrayRef internal_elements; 88 #endif 89 }; 90 typedef struct joy_hid_device joy_hid_device_t; 91 typedef struct joy_hid_device *joy_hid_device_ptr_t; 92 93 /* an array of hid devices */ 94 struct joy_hid_device_array { 95 int num_devices; 96 joy_hid_device_t *devices; 97 98 #ifdef HAS_HIDMGR 99 CFArrayRef internal_devices; 100 int num_internal_devices; 101 #endif 102 103 const char *driver_name; 104 }; 105 typedef struct joy_hid_device_array joy_hid_device_array_t; 106 107 /* ----- API ----- */ 108 109 int joy_hidlib_init(void); /* return 0=ok !=0 errror */ 110 void joy_hidlib_exit(void); 111 112 joy_hid_device_array_t *joy_hidlib_enumerate_devices(void); 113 void joy_hidlib_free_devices(joy_hid_device_array_t *devices); 114 115 int joy_hidlib_open_device(joy_hid_device_t *device); 116 void joy_hidlib_close_device(joy_hid_device_t *device); 117 118 int joy_hidlib_enumerate_elements(joy_hid_device_t *device); 119 void joy_hidlib_free_elements(joy_hid_device_t *device); 120 121 int joy_hidlib_get_value(joy_hid_device_t *device, 122 joy_hid_element_t *element, 123 int *value, int phys); 124 125 #endif 126 127 #endif 128