diff options
author | gregorypierce <[email protected]> | 2003-07-29 05:15:11 +0000 |
---|---|---|
committer | gregorypierce <[email protected]> | 2003-07-29 05:15:11 +0000 |
commit | c3995076684769c391cf56a07d3248df0d5dddab (patch) | |
tree | ddc673f202b9d58cc9ffc560e6e5d8a6b0d0827c /plugins | |
parent | c0f3b9651caed83999d83d02e78bca79d05fe890 (diff) |
Update to move native pointers to Java code, to retrieve the correct device types from the HID tables, to open/close the device and prepare to poll data from the device data queues
git-svn-id: file:///home/sven/projects/JOGL/git-svn/svn-server-sync/jinput/trunk@16 e343933a-64c8-49c5-92b1-88f2ce3e89e8
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/OSX/src/native/JNIWrapper.java | 28 | ||||
-rw-r--r-- | plugins/OSX/src/native/hidinputjnilib.c | 92 |
2 files changed, 111 insertions, 9 deletions
diff --git a/plugins/OSX/src/native/JNIWrapper.java b/plugins/OSX/src/native/JNIWrapper.java index d2ded45..0613340 100644 --- a/plugins/OSX/src/native/JNIWrapper.java +++ b/plugins/OSX/src/native/JNIWrapper.java @@ -47,7 +47,12 @@ public class JNIWrapper public native void hidCreate(); public native void hidDispose(); - public native void enumDevices( ArrayList list ); + public native void enumDevices( ArrayList list ); + + private static final int HID_DEVICE_MOUSE = 0x02; + private static final int HID_DEVICE_JOYSTICK = 0x04; + private static final int HID_DEVICE_GAMEPAD = 0x05; + private static final int HID_DEVICE_KEYBOARD = 0x06; private ArrayList devices = new ArrayList(); @@ -70,7 +75,26 @@ public class JNIWrapper private void addDevice( ArrayList list, long lpDevice, int type, String productName ) { - System.out.println("Found device [" + productName + "] of type [" + type + "]"); + //System.out.println("Found device [" + productName + "] of type [" + type + "]"); + switch (type) + { + case (HID_DEVICE_MOUSE): + System.out.println("Found mouse [" + productName + "]"); + break; + case (HID_DEVICE_JOYSTICK): + System.out.println("Found joystick [" + productName + "]"); + break; + case (HID_DEVICE_GAMEPAD): + System.out.println("Found gamepad [" + productName + "]"); + break; + case (HID_DEVICE_KEYBOARD): + System.out.println("Found keyboard [" + productName + "]"); + break; + default: + System.out.println("Found device of unknown type [" + type + "] - ignoring"); + } + + System.out.println("Address of device [" + lpDevice + "]"); } public static void main (String args[]) diff --git a/plugins/OSX/src/native/hidinputjnilib.c b/plugins/OSX/src/native/hidinputjnilib.c index 2498edf..6739eaf 100644 --- a/plugins/OSX/src/native/hidinputjnilib.c +++ b/plugins/OSX/src/native/hidinputjnilib.c @@ -56,6 +56,7 @@ Boolean init( JNIEnv * env ); void createMasterPort(); void disposeMasterPort(); +void createHIDDevice(io_object_t hidDevice, IOHIDDeviceInterface ***hidDeviceInterface); Boolean showDictionaryElement (CFDictionaryRef dictionary, CFStringRef key); void showProperty(const void * key, const void * value); @@ -106,6 +107,71 @@ void disposeMasterPort() } } +void createHIDDevice( io_object_t hidDevice, IOHIDDeviceInterface ***hidDeviceInterface ) +{ + io_name_t className; + IOCFPlugInInterface **plugInInterface = NULL; + HRESULT plugInResult = S_OK; + SInt32 score = 0; + IOReturn ioReturnValue = kIOReturnSuccess; + + ioReturnValue = IOObjectGetClass(hidDevice, className); + if ( ioReturnValue != kIOReturnSuccess ) + { + printf("Failed to get class name."); + } + + printf("Found device type %s\n", className); + + ioReturnValue = IOCreatePlugInInterfaceForService(hidDevice, + kIOHIDDeviceUserClientTypeID, + kIOCFPlugInInterfaceID, + &plugInInterface, + &score); + + if (ioReturnValue == kIOReturnSuccess) + { + //Call a method of the intermediate plug-in to create the device + //interface + plugInResult = (*plugInInterface)->QueryInterface(plugInInterface, + CFUUIDGetUUIDBytes(kIOHIDDeviceInterfaceID), + (LPVOID) hidDeviceInterface); + if ( plugInResult != S_OK ) + { + printf("Couldn't create HID class device interface"); + } + + (*plugInInterface)->Release(plugInInterface); + } + + //todo, change this to be controlled from the java layer at each device + // + ioReturnValue = (**hidDeviceInterface)->open(*hidDeviceInterface, 0 ); + if ( ioReturnValue != kIOReturnSuccess ) + { + printf("Unable to open device - return [%d]\n", ioReturnValue ); + } + else + { + printf("Successfully opened device \n"); + } + + ioReturnValue = (**hidDeviceInterface)->close(*hidDeviceInterface); + if ( ioReturnValue != kIOReturnSuccess ) + { + printf("Unable to close device - return [%d]\n", ioReturnValue ); + } + else + { + printf("Successfully closed device \n"); + } + + // release the device interface + // + (**hidDeviceInterface)->Release(*hidDeviceInterface); + + +} Boolean showDictionaryElement (CFDictionaryRef dictionary, CFStringRef key) { @@ -293,6 +359,7 @@ JNIEXPORT void JNICALL Java_JNIWrapper_enumDevices hidMatchDictionary = NULL; io_object_t hidDevice = NULL; + IOHIDDeviceInterface **hidDeviceInterface = NULL; CFMutableDictionaryRef properties = 0; char path[512]; kern_return_t result; @@ -320,25 +387,36 @@ JNIEXPORT void JNICALL Java_JNIWrapper_enumDevices printf("ProductKey: "); showDictionaryElement(properties, CFSTR(kIOHIDProductKey)); //printf("SerialNumber: "); showDictionaryElement(properties, CFSTR(kIOHIDSerialNumberKey)); //showDictionaryElement(properties, CFSTR(kIOHIDLocationIDKey)); - //printf("PrimaryUsage: "); showDictionaryElement(properties, CFSTR(kIOHIDPrimaryUsageKey)); + printf("PrimaryUsage: "); showDictionaryElement(properties, CFSTR(kIOHIDPrimaryUsageKey)); //showDictionaryElement(properties, CFSTR(kIOHIDPrimaryUsagePageKey)); //showDictionaryElement(properties, CFSTR(kIOHIDElementKey)); //printf("\n\n"); CFTypeRef object = CFDictionaryGetValue (properties, CFSTR(kIOHIDProductKey)); - - (*env)->CallVoidMethod(env, obj, MID_AddDevice, - list, - (jlong)(long)hidDevice, - kIOHIDPrimaryUsageKey, - (*env)->NewStringUTF( env, CFStringGetCStringPtr ( object, CFStringGetSystemEncoding ()) ) ); + long number; + CFNumberGetValue ( CFDictionaryGetValue( properties, CFSTR(kIOHIDPrimaryUsageKey) ), kCFNumberLongType, &number); + + createHIDDevice( hidDevice, &hidDeviceInterface ); + IOObjectRelease( hidDevice ); + + if ( hidDeviceInterface != NULL ) + { + printf("Ready to use this device \n"); + + (*env)->CallVoidMethod(env, obj, MID_AddDevice, + list, + (jlong)(long)hidDeviceInterface, + (jint)number, + (*env)->NewStringUTF( env, CFStringGetCStringPtr ( object, CFStringGetSystemEncoding ()) ) ); + } //Release the properties dictionary CFRelease(properties); } + } IOObjectRelease(hidObjectIterator); |