pd-hid_0.7/0000755000076500007650000000000011504505103011257 5ustar hanshanspd-hid_0.7/hid_log-help.pd0000644000076500007650000000377611504504627014166 0ustar hanshans#N canvas 0 31 472 368 10; #X obj 5 2 cnv 15 450 20 empty empty hid_log 2 11 1 18 -233017 -66577 0; #X obj 422 3 pddp/pddplink http://puredata.info/dev/pddp -text pddp ; #X text 27 300 (C) Copyright 2004 Hans-Christoph Steiner ; #X text 244 314 released under the GNU GPL; #X text 98 271 For more info:; #X floatatom 35 123 8 0 0 0 - - -; #X floatatom 35 184 8 0 0 0 - - -; #X obj 28 211 hsl 200 15 0 1 0 0 empty empty empty 22 8 1 12 -262144 -1 -1 0 1; #X obj 28 103 hsl 200 15 0 1 0 0 empty empty empty 22 8 1 12 -261681 -1 -1 0 1; #X obj 25 153 hid/hid_log; #N canvas 0 22 450 300 (subpatch) 0; #X array hid_log 100 float 0; #X coords 0 1 99 0 100 100 1; #X restore 321 111 graph; #N canvas 266 69 327 317 draw_array 0; #X msg 57 52 bang; #X obj 57 73 until; #X text 88 52 start; #X obj 57 95 f; #X obj 86 95 + 1; #X obj 132 97 sel 0; #X obj 86 117 mod 100; #X obj 57 150 t f f; #X obj 94 177 s array_index; #X obj 170 262 r array_index; #X obj 57 13 loadbang; #X obj 57 207 / 100; #X text 99 207 [hid] output range: 0 to 1; #X obj 56 233 hid/hid_log; #X obj 56 283 tabwrite hid_log; #X connect 0 0 1 0; #X connect 1 0 3 0; #X connect 3 0 4 0; #X connect 3 0 7 0; #X connect 4 0 6 0; #X connect 5 0 1 1; #X connect 6 0 3 1; #X connect 6 0 5 0; #X connect 7 0 11 0; #X connect 7 1 8 0; #X connect 9 0 14 1; #X connect 10 0 0 0; #X connect 11 0 13 0; #X connect 13 0 14 0; #X restore 321 78 pd draw_array; #X text 17 40 This object maps the input range to a logarithmic curve. Humans perceive pitch and amplitude on a logarithmic scale.; #N canvas 482 227 494 344 META 0; #X text 12 125 HELP_PATCH_AUTHORS "pd meta" information added by Jonathan Wilkes for Pd version 0.42.; #X text 12 25 LICENSE GPL; #X text 12 105 AUTHOR Hans-Christoph Steiner; #X text 12 65 INLET_0 float; #X text 12 85 OUTLET_0 float; #X text 12 45 DESCRIPTION map the input range to a logarithmic curve ; #X text 12 5 KEYWORDS control abstraction; #X restore 417 337 pd META; #X connect 6 0 7 0; #X connect 8 0 5 0; #X connect 8 0 9 0; #X connect 9 0 7 0; pd-hid_0.7/hid_exp.pd0000644000076500007650000000041611504504627013237 0ustar hanshans#N canvas 4 31 499 325 10; #X obj 72 38 inlet; #X obj 72 258 outlet; #X text 120 38 input range: 0 to 1; #X text 128 258 output range: 0 to 1; #X text 7 9 [hid_exp]; #X obj 73 142 dbtorms; #X obj 73 120 * 100; #X connect 0 0 6 0; #X connect 5 0 1 0; #X connect 6 0 5 0; pd-hid_0.7/hid_polar.pd0000644000076500007650000000147311504504627013564 0ustar hanshans#N canvas 189 157 472 415 10; #X obj 30 58 inlet; #X obj 25 313 outlet; #X text 73 313 output range: 0 to 1; #X text 72 57 input range: 0 to 1; #X text 11 5 [hid_polar]; #X obj 232 312 outlet; #X obj 224 56 inlet; #X text 264 57 input range: 0 to 1; #X text 29 29 x-axis value; #X text 221 26 y-axis value; #X obj 252 140 - 1; #X obj 252 120 * 2; #X obj 29 140 - 1; #X obj 29 120 * 2; #X text 61 125 convert range to -1 to 1; #X text 280 312 output range: 0 to 1; #X text 245 371 released under the GNU GPL; #X text 28 357 (C) Copyright 2005 Hans-Christoph Steiner ; #X text 23 331 radius; #X text 230 332 angle; #X obj 88 218 hid_vector; #X connect 0 0 13 0; #X connect 6 0 11 0; #X connect 10 0 20 1; #X connect 11 0 10 0; #X connect 12 0 20 0; #X connect 13 0 12 0; #X connect 20 0 1 0; #X connect 20 1 5 0; pd-hid_0.7/hid_cuberoot.pd0000644000076500007650000000050511504504627014264 0ustar hanshans#N canvas 612 444 440 357 10; #X obj 72 63 inlet; #X obj 72 240 outlet; #X text 120 63 input range: 0 to 1; #X text 128 240 output range: 0 to 1; #X obj 73 162 pow 0.333333; #X text 41 18 [hid_cuberoot]; #X obj 72 95 min 1; #X obj 72 115 max 0; #X connect 0 0 6 0; #X connect 4 0 1 0; #X connect 6 0 7 0; #X connect 7 0 4 0; pd-hid_0.7/HID Utilities Source/0000755000076500007650000000000011504505103015040 5ustar hanshanspd-hid_0.7/HID Utilities Source/HID_Utilities_CFM.h0000644000076500007650000000621011504504627020346 0ustar hanshans/* File: HID_Utilities_CFM.h Contains: External interface for HID Utilities, can be used with either library or source DRI: George Warner Copyright: Copyright © 2002 Apple Computer, Inc., All Rights Reserved Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. ("Apple") in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this Apple software constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this Apple software. In consideration of your agreement to abide by the following terms, and subject to these terms, Apple grants you a personal, non-exclusive license, under AppleÕs copyrights in this original Apple software (the "Apple Software"), to use, reproduce, modify and redistribute the Apple Software, with or without modifications, in source and/or binary forms; provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Computer, Inc. may be used to endorse or promote products derived from the Apple Software without specific prior written permission from Apple. Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by Apple herein, including but not limited to any patent rights that may be infringed by your derivative works or by other works in which the Apple Software may be incorporated. The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ #ifndef _HID_Utilities_CFM_h_ #define _HID_Utilities_CFM_h_ // ================================== #ifdef __cplusplus extern "C" { #endif // ================================== //includes #include "HID_Utilities_External.h" // ================================== // sets up CFM function pointers. Required to be called prior using an HID Utility function from CFM OSStatus SetupHIDCFM (void); // should be called prior to shut down to properly close te bundles void TearDownHIDCFM (void); #ifdef __cplusplus } #endif #endif // _HID_Utilities_External_h_ pd-hid_0.7/HID Utilities Source/HIDLib.h0000644000076500007650000000515311504504627016262 0ustar hanshans/* File: HIDLib.h Contains: Include file to define kBuildingLibrary constant (only include when building libraries) DRI: George Warner Copyright: Copyright © 2002 Apple Computer, Inc., All Rights Reserved Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. ("Apple") in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this Apple software constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this Apple software. In consideration of your agreement to abide by the following terms, and subject to these terms, Apple grants you a personal, non-exclusive license, under AppleÕs copyrights in this original Apple software (the "Apple Software"), to use, reproduce, modify and redistribute the Apple Software, with or without modifications, in source and/or binary forms; provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Computer, Inc. may be used to endorse or promote products derived from the Apple Software without specific prior written permission from Apple. Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by Apple herein, including but not limited to any patent rights that may be infringed by your derivative works or by other works in which the Apple Software may be incorporated. The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define kBuildingLibrary 1pd-hid_0.7/HID Utilities Source/HID_Queue_Utilities.h0000644000076500007650000001256211504504627021034 0ustar hanshans/* File: HID_Queue_Utilities.h Contains: Definition of the HID queue functions for the HID utilites. DRI: George Warner Copyright: Copyright © 2002 Apple Computer, Inc., All Rights Reserved Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. ("Apple") in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this Apple software constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this Apple software. In consideration of your agreement to abide by the following terms, and subject to these terms, Apple grants you a personal, non-exclusive license, under AppleÕs copyrights in this original Apple software (the "Apple Software"), to use, reproduce, modify and redistribute the Apple Software, with or without modifications, in source and/or binary forms; provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Computer, Inc. may be used to endorse or promote products derived from the Apple Software without specific prior written permission from Apple. Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by Apple herein, including but not limited to any patent rights that may be infringed by your derivative works or by other works in which the Apple Software may be incorporated. The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _HID_Queue_Utilities_h_ #define _HID_Queue_Utilities_h_ #include "HID_Utilities.h" // ================================== #ifdef __cplusplus extern "C" { #endif // ================================== enum { kDeviceQueueSize = 50 // this is wired kernel memory so should be set to as small as possible // but should account for the maximum possible events in the queue // USB updates will likely occur at 100 Hz so one must account for this rate of // if states change quickly (updates are only posted on state changes) }; // ================================== // queues specific element, performing any device queue set up required extern unsigned long HIDQueueElement (pRecDevice pDevice, pRecElement pElement); // adds all elements to queue, performing any device queue set up required extern unsigned long HIDQueueDevice (pRecDevice pDevice); // removes element for queue, if last element in queue will release queue and device extern unsigned long HIDDequeueElement (pRecDevice pDevice, pRecElement pElement); // completely removes all elements from queue and releases queue and device extern unsigned long HIDDequeueDevice (pRecDevice pDevice); // releases all device queues for quit or rebuild (must be called) extern unsigned long HIDReleaseAllDeviceQueues (void); // releases interface to device, should be done prior to exiting application (called from HIDReleaseDeviceList) extern unsigned long HIDCloseReleaseInterface (pRecDevice pDevice); // returns true if an event is avialable for the element and fills out *pHIDEvent structure, returns false otherwise // pHIDEvent is a poiner to a IOHIDEventStruct, using void here for compatibility, users can cast a required extern unsigned char HIDGetEvent (pRecDevice pDevice, void * pHIDEvent); // returns current value for element, creating device interface as required, polling element extern long HIDGetElementValue (pRecDevice pDevice, pRecElement pElement); // Set an elements value // NOTE: This should only be used when a single element report needs to be sent. // If multiple elements reports are to be send then transactions should be used. extern long HIDSetElementValue (pRecDevice pDevice, pRecElement pElement,IOHIDEventStruct* pIOHIDEvent); // Set a callback to be called when a queue goes from empty to non-empty extern long HIDSetQueueCallback (pRecDevice pDevice, IOHIDCallbackFunction callback); #if 0 // Get a report from a device extern long HIDGetReport (pRecDevice pDevice,const IOHIDReportType reportType, const UInt32 reportID, void* reportBuffer, UInt32* reportBufferSize); // Send a report to a device extern long HIDSetReport (pRecDevice pDevice,const IOHIDReportType reportType, const UInt32 reportID, void* reportBuffer, const UInt32 reportBufferSize); #endif #ifdef __cplusplus } #endif #endif // _HID_Queue_Utilities_h_ pd-hid_0.7/HID Utilities Source/HID_Error_Handler.c0000644000076500007650000000757111504504627020442 0ustar hanshans/* File: Error Handler.c Contains: Implementation of the HID utility error handlers for the HID Utilities DRI: George Warner Copyright: Copyright © 2002 Apple Computer, Inc., All Rights Reserved Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. ("Apple") in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this Apple software constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this Apple software. In consideration of your agreement to abide by the following terms, and subject to these terms, Apple grants you a personal, non-exclusive license, under AppleÕs copyrights in this original Apple software (the "Apple Software"), to use, reproduce, modify and redistribute the Apple Software, with or without modifications, in source and/or binary forms; provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Computer, Inc. may be used to endorse or promote products derived from the Apple Software without specific prior written permission from Apple. Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by Apple herein, including but not limited to any patent rights that may be infringed by your derivative works or by other works in which the Apple Software may be incorporated. The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if !defined (kBuildingLibrary) #define kVerboseErrors // system includes ---------------------------------------------------------- #ifdef kVerboseErrors #include #endif #endif // not kBuildingLibrary #include // project includes --------------------------------------------------------- #include "HID_Utilities_Internal.h" // globals (internal/private) ----------------------------------------------- // prototypes (internal/private) -------------------------------------------- // functions (internal/private) --------------------------------------------- #pragma mark - // ------------------------------------- // central error reporting void HIDReportErrorNum (char * strError, long numError) { char errMsgCStr [256]; sprintf (errMsgCStr, "%s #%ld (0x%lx)", strError, numError, numError); // out as debug string #ifdef kVerboseErrors { Str255 strErr = "\p"; CopyCStringToPascal (errMsgCStr, strErr); DebugStr (strErr); } #endif // kVerboseErrors } // ------------------------------------- void HIDReportError (char * strError) { char errMsgCStr [256]; sprintf (errMsgCStr, "%s", strError); // out as debug string #ifdef kVerboseErrors { Str255 strErr = "\p"; CopyCStringToPascal (errMsgCStr, strErr); DebugStr (strErr); } #endif // kVerboseErrors } pd-hid_0.7/HID Utilities Source/HID_Transaction_Utilities.h0000644000076500007650000001235511504504627022235 0ustar hanshans/* File: HID_Transaction_Utilities.h Contains: Implementation of the HID queue functions for the HID utilites. DRI: George Warner Copyright: Copyright © 2002 Apple Computer, Inc., All Rights Reserved Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. ("Apple") in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this Apple software constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this Apple software. In consideration of your agreement to abide by the following terms, and subject to these terms, Apple grants you a personal, non-exclusive license, under AppleÕs copyrights in this original Apple software (the "Apple Software"), to use, reproduce, modify and redistribute the Apple Software, with or without modifications, in source and/or binary forms; provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Computer, Inc. may be used to endorse or promote products derived from the Apple Software without specific prior written permission from Apple. Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by Apple herein, including but not limited to any patent rights that may be infringed by your derivative works or by other works in which the Apple Software may be incorporated. The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _HID_Transaction_Utilities_h_ #define _HID_Transaction_Utilities_h_ #include "HID_Utilities.h" // ================================== #ifdef __cplusplus extern "C" { #endif // ================================== // Create and open an transaction interface to device, required prior to extracting values or building Transactions extern unsigned long HIDTransactionAddElement(pRecDevice pDevice, pRecElement pElement); // removes an element from a Transaction extern unsigned long HIDTransactionRemoveElement(pRecDevice pDevice, pRecElement pElement); // return true if this transaction contains this element extern Boolean HIDTransactionHasElement(pRecDevice pDevice, pRecElement pElement); /* This changes the default value of an element, when the values of the */ /* elements are cleared, on clear or commit, they are reset to the */ /* default value */ /* This call can be made on elements that are not in the transaction, but */ /* has undefined behavior if made on elements not in the transaction */ /* which are later added to the transaction. */ /* In other words, an element should be added before its default is */ /* set, for well defined behavior. */ extern unsigned long HIDTransactionSetElementDefault(pRecDevice pDevice, pRecElement pElement,IOHIDEventStruct* pValueEvent); /* Get the current setting of an element's default value */ extern unsigned long HIDTransactionGetElementDefault(pRecDevice pDevice, pRecElement pElement,IOHIDEventStruct* pValueEvent); /* Add a change to the transaction, by setting an element value */ /* The change is not actually made until it is commited */ /* The element must be part of the transaction or this call will fail */ extern unsigned long HIDTransactionSetElementValue(pRecDevice pDevice, pRecElement pElement,IOHIDEventStruct* pValueEvent); /* Get the current setting of an element value */ extern unsigned long HIDTransactionGetElementValue(pRecDevice pDevice, pRecElement pElement,IOHIDEventStruct* pValueEvent); /* Commit the transaction, or clear all the changes and start over */ /* timoutMS is the timeout in milliseconds, a zero timeout will cause */ /* this call to be non-blocking (returning queue empty) if there */ /* is a NULL callback, and blocking forever until the queue is */ /* non-empty if their is a valid callback */ /* callback, if non-NULL is a callback to be called when data is */ /* inserted to the queue */ /* callbackTarget and callbackRefcon are passed to the callback */ extern unsigned long HIDTransactionCommit(pRecDevice pDevice); /* Clear all the changes and start over */ extern unsigned long HIDTransactionClear(pRecDevice pDevice); #ifdef __cplusplus } #endif #endif // _HID_Transaction_Utilities_h_ pd-hid_0.7/HID Utilities Source/HID_Utilities_Internal.h0000644000076500007650000000536211504504627021524 0ustar hanshans/* File: HID_Utilities_Internal.h Contains: Definition of HID Utilities internal functions DRI: George Warner Copyright: Copyright © 2002 Apple Computer, Inc., All Rights Reserved Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. ("Apple") in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this Apple software constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this Apple software. In consideration of your agreement to abide by the following terms, and subject to these terms, Apple grants you a personal, non-exclusive license, under AppleÕs copyrights in this original Apple software (the "Apple Software"), to use, reproduce, modify and redistribute the Apple Software, with or without modifications, in source and/or binary forms; provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Computer, Inc. may be used to endorse or promote products derived from the Apple Software without specific prior written permission from Apple. Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by Apple herein, including but not limited to any patent rights that may be infringed by your derivative works or by other works in which the Apple Software may be incorporated. The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _HID_Utilities_Internal_h_ #define _HID_Utilities_Internal_h_ // Moved into specific "HID_xxx.h" files. #include "HID_Error_Handler.h" #endif // _HID_Utilities_Internal_h_ pd-hid_0.7/HID Utilities Source/HID_Utilities.c0000644000076500007650000030260411504504627017662 0ustar hanshans/* File: HID_Utilities.c Contains: Implementation of HID Utilities DRI: George Warner Copyright: Copyright © 2002 Apple Computer, Inc., All Rights Reserved Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. ("Apple") in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this Apple software constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this Apple software. In consideration of your agreement to abide by the following terms, and subject to these terms, Apple grants you a personal, non-exclusive license, under AppleÕs copyrights in this original Apple software (the "Apple Software"), to use, reproduce, modify and redistribute the Apple Software, with or without modifications, in source and/or binary forms; provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Computer, Inc. may be used to endorse or promote products derived from the Apple Software without specific prior written permission from Apple. Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by Apple herein, including but not limited to any patent rights that may be infringed by your derivative works or by other works in which the Apple Software may be incorporated. The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "HID_Utilities_Internal.h" #include "HID_Utilities_External.h" #include #include #include #include //================================================================================================ #define USE_NOTIFICATIONS 1 //================================================================================================ // local (static) functions //================================================================================================ static void hid_GetCollectionElements (CFMutableDictionaryRef deviceProperties, pRecElement *ppCurrentCollection); static pRecDevice hid_DisposeDevice (pRecDevice ppDevice); //================================================================================================ // globals //================================================================================================ #if USE_NOTIFICATIONS static IONotificationPortRef gNotifyPort; static io_iterator_t gAddedIter; static CFRunLoopRef gRunLoop; #endif USE_NOTIFICATIONS // for element retrieval static pRecDevice gCurrentGetDevice = NULL; static Boolean gAddAsChild = false; static int gDepth = false; static pRecDevice gpDeviceList = NULL; static UInt32 gNumDevices = 0; #pragma mark private functions // ================================== // private functions static UInt32 hid_CountCurrentDevices (void); // extracts actual specific element information from each element CF dictionary entry static void hid_GetElementInfo (CFTypeRef refElement, pRecElement pElement) { long number; CFTypeRef refType; // type, usagePage, usage already stored refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementCookieKey)); if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number)) pElement->cookie = (IOHIDElementCookie) number; else pElement->cookie = (IOHIDElementCookie) 0; refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementMinKey)); if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number)) pElement->min = number; else pElement->min = 0; // pElement->calMax = pElement->min; pElement->userMin = kDefaultUserMin; refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementMaxKey)); if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number)) pElement->max = number; else pElement->max = 0; // pElement->calMin = pElement->max; pElement->userMax = kDefaultUserMax; refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementScaledMinKey)); if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number)) pElement->scaledMin = number; else pElement->scaledMin = 0; refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementScaledMaxKey)); if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number)) pElement->scaledMax = number; else pElement->scaledMax = 0; refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementSizeKey)); if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number)) pElement->size = number; else pElement->size = 0; refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementIsRelativeKey)); if (refType) pElement->relative = CFBooleanGetValue (refType); else pElement->relative = 0; refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementIsWrappingKey)); if (refType) pElement->wrapping = CFBooleanGetValue (refType); else pElement->wrapping = false; refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementIsNonLinearKey)); if (refType) pElement->nonLinear = CFBooleanGetValue (refType); else pElement->wrapping = false; #ifdef kIOHIDElementHasPreferredStateKey refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementHasPreferredStateKey)); #else // Mac OS X 10.0 has spelling error refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementHasPreferedStateKey)); #endif if (refType) pElement->preferredState = CFBooleanGetValue (refType); else pElement->preferredState = false; refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementHasNullStateKey)); if (refType) pElement->nullState = CFBooleanGetValue (refType); else pElement->nullState = false; refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementUnitKey)); if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number)) pElement->units = number; else pElement->units = 0; refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementUnitExponentKey)); if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number)) pElement->unitExp = number; else pElement->unitExp = 0; refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementNameKey)); if (refType) if (!CFStringGetCString (refType, pElement->name, 256, CFStringGetSystemEncoding ())) HIDReportError ("CFStringGetCString error retrieving pElement->name."); if (!*pElement->name) { // set name from vendor id, product id & usage info look up if (!HIDGetElementNameFromVendorProductUsage (gCurrentGetDevice->vendorID, gCurrentGetDevice->productID, pElement->usagePage, pElement->usage, pElement->name)) { // set name from vendor id/product id look up HIDGetElementNameFromVendorProductCookie (gCurrentGetDevice->vendorID, gCurrentGetDevice->productID, (long) pElement->cookie, pElement->name); if (!*pElement->name) { // if no name HIDGetUsageName (pElement->usagePage, pElement->usage, pElement->name); if (!*pElement->name) // if not usage sprintf (pElement->name, "Element"); } } } } // --------------------------------- // examines CF dictionary vlaue in device element hierarchy to determine if it is element of interest or a collection of more elements // if element of interest allocate storage, add to list and retrieve element specific info // if collection then pass on to deconstruction collection into additional individual elements static void hid_AddElement (CFTypeRef refElement, pRecElement * ppElementCurrent) { pRecDevice pDevice = gCurrentGetDevice; pRecElement pElement = NULL; long elementType, usagePage, usage; CFTypeRef refElementType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementTypeKey)); CFTypeRef refUsagePage = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementUsagePageKey)); CFTypeRef refUsage = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementUsageKey)); if (refElementType) CFNumberGetValue (refElementType, kCFNumberLongType, &elementType); if (refUsagePage) CFNumberGetValue (refUsagePage, kCFNumberLongType, &usagePage); if (refUsage) CFNumberGetValue (refUsage, kCFNumberLongType, &usage); if (NULL == pDevice) return; if (elementType) { // look at types of interest if (elementType != kIOHIDElementTypeCollection) { if (usagePage && usage) // if valid usage and page { switch (usagePage) // only interested in kHIDPage_GenericDesktop and kHIDPage_Button { case kHIDPage_GenericDesktop: { switch (usage) // look at usage to determine function { case kHIDUsage_GD_X: case kHIDUsage_GD_Y: case kHIDUsage_GD_Z: case kHIDUsage_GD_Rx: case kHIDUsage_GD_Ry: case kHIDUsage_GD_Rz: pElement = (pRecElement) malloc (sizeof (recElement)); if (pElement) pDevice->axis++; break; case kHIDUsage_GD_Slider: pElement = (pRecElement) malloc (sizeof (recElement)); if (pElement) pDevice->sliders++; break; case kHIDUsage_GD_Dial: pElement = (pRecElement) malloc (sizeof (recElement)); if (pElement) pDevice->dials++; break; case kHIDUsage_GD_Wheel: pElement = (pRecElement) malloc (sizeof (recElement)); if (pElement) pDevice->wheels++; break; case kHIDUsage_GD_Hatswitch: pElement = (pRecElement) malloc (sizeof (recElement)); if (pElement) pDevice->hats++; break; default: pElement = (pRecElement) malloc (sizeof (recElement)); break; } } break; case kHIDPage_Button: pElement = (pRecElement) malloc (sizeof (recElement)); if (pElement) pDevice->buttons++; break; default: // just add a generic element pElement = (pRecElement) malloc (sizeof (recElement)); break; } } #if 0 else HIDReportError ("CFNumberGetValue error when getting value for refUsage or refUsagePage."); #endif 0 } else // collection pElement = (pRecElement) malloc (sizeof (recElement)); } else HIDReportError ("CFNumberGetValue error when getting value for refElementType."); if (pElement) // add to list { // this code builds a binary tree based on the collection hierarchy of inherent in the device element layout // it preserves the structure of the lements as collections have children and elements are siblings to each other // clear record bzero(pElement,sizeof(recElement)); // get element info pElement->type = elementType; pElement->usagePage = usagePage; pElement->usage = usage; pElement->depth = 0; // assume root object hid_GetElementInfo (refElement, pElement); // count elements pDevice->totalElements++; switch (pElement->type) { case kIOHIDElementTypeInput_Misc: case kIOHIDElementTypeInput_Button: case kIOHIDElementTypeInput_Axis: case kIOHIDElementTypeInput_ScanCodes: pDevice->inputs++; break; case kIOHIDElementTypeOutput: pDevice->outputs++; break; case kIOHIDElementTypeFeature: pDevice->features++; break; case kIOHIDElementTypeCollection: pDevice->collections++; break; default: HIDReportErrorNum ("Unknown element type : ", pElement->type); } if (NULL == *ppElementCurrent) // if at list head { pDevice->pListElements = pElement; // add current element *ppElementCurrent = pElement; // set current element to element we just added } else // have exsiting structure { if (gAddAsChild) // if the previous element was a collection, let's add this as a child of the previous { // this iteration should not be needed but there maybe some untested degenerate case which this code will ensure works while ((*ppElementCurrent)->pChild) // step down tree until free child node found *ppElementCurrent = (*ppElementCurrent)->pChild; (*ppElementCurrent)->pChild = pElement; // insert there pElement->depth = (*ppElementCurrent)->depth + 1; } else // add as sibling { // this iteration should not be needed but there maybe some untested degenerate case which this code will ensure works while ((*ppElementCurrent)->pSibling) // step down tree until free sibling node found *ppElementCurrent = (*ppElementCurrent)->pSibling; (*ppElementCurrent)->pSibling = pElement; // insert there pElement->depth = (*ppElementCurrent)->depth; } pElement->pPrevious = *ppElementCurrent; // point to previous *ppElementCurrent = pElement; // set current to our collection } if (elementType == kIOHIDElementTypeCollection) // if this element is a collection of other elements { gAddAsChild = true; // add next set as children to this element gDepth++; hid_GetCollectionElements ((CFMutableDictionaryRef) refElement, &pElement); // recursively process the collection gDepth--; } gAddAsChild = false; // add next as this elements sibling (when return from a collection or with non-collections) } #if 0 else HIDReportError ("hid_AddElement - no element added."); #endif } // --------------------------------- // collects information from each array member in device element list (each array memeber = element) static void hid_GetElementsCFArrayHandler (const void * value, void * parameter) { if (CFGetTypeID (value) == CFDictionaryGetTypeID ()) hid_AddElement ((CFTypeRef) value, (pRecElement *) parameter); } // --------------------------------- // handles retrieval of element information from arrays of elements in device IO registry information static void hid_GetElements (CFTypeRef refElementCurrent, pRecElement *ppCurrentElement) { CFTypeID type = CFGetTypeID (refElementCurrent); if (type == CFArrayGetTypeID()) // if element is an array { CFRange range = {0, CFArrayGetCount (refElementCurrent)}; // CountElementsCFArrayHandler called for each array member CFArrayApplyFunction (refElementCurrent, range, hid_GetElementsCFArrayHandler, ppCurrentElement); } } // --------------------------------- // handles extracting element information from element collection CF types // used from top level element decoding and hierarchy deconstruction to flatten device element list static void hid_GetCollectionElements (CFMutableDictionaryRef deviceProperties, pRecElement *ppCurrentCollection) { CFTypeRef refElementTop = CFDictionaryGetValue (deviceProperties, CFSTR(kIOHIDElementKey)); if (refElementTop) hid_GetElements (refElementTop, ppCurrentCollection); else HIDReportError ("hid_GetCollectionElements: CFDictionaryGetValue error when creating CFTypeRef for kIOHIDElementKey."); } // --------------------------------- // use top level element usage page and usage to discern device usage page and usage setting appropriate values in device record static void hid_TopLevelElementHandler (const void * value, void * parameter) { CFTypeRef refCF = 0; if ((NULL == value) || (NULL == parameter)) return; // (kIOReturnBadArgument) if (CFGetTypeID (value) != CFDictionaryGetTypeID ()) return; // (kIOReturnBadArgument) refCF = CFDictionaryGetValue (value, CFSTR(kIOHIDElementUsagePageKey)); if (!CFNumberGetValue (refCF, kCFNumberLongType, &((pRecDevice) parameter)->usagePage)) HIDReportError ("CFNumberGetValue error retrieving pDevice->usagePage."); refCF = CFDictionaryGetValue (value, CFSTR(kIOHIDElementUsageKey)); if (!CFNumberGetValue (refCF, kCFNumberLongType, &((pRecDevice) parameter)->usage)) HIDReportError ("CFNumberGetValue error retrieving pDevice->usage."); } // --------------------------------- // extracts device info from CF dictionary records in IO registry static void hid_GetDeviceInfo (io_object_t hidDevice, CFMutableDictionaryRef hidProperties, pRecDevice pDevice) { CFMutableDictionaryRef usbProperties = 0; io_registry_entry_t parent1, parent2; // Mac OS X currently is not mirroring all USB properties to HID page so need to look at USB device page also // get dictionary for usb properties: step up two levels and get CF dictionary for USB properties if ((KERN_SUCCESS == IORegistryEntryGetParentEntry (hidDevice, kIOServicePlane, &parent1)) && (KERN_SUCCESS == IORegistryEntryGetParentEntry (parent1, kIOServicePlane, &parent2)) && (KERN_SUCCESS == IORegistryEntryCreateCFProperties (parent2, &usbProperties, kCFAllocatorDefault, kNilOptions))) { if (usbProperties) { CFTypeRef refCF = 0; // get device info // try hid dictionary first, if fail then go to usb dictionary // get transport refCF = CFDictionaryGetValue (hidProperties, CFSTR(kIOHIDTransportKey)); if (refCF) { if (!CFStringGetCString (refCF, pDevice->transport, 256, CFStringGetSystemEncoding ())) HIDReportError ("CFStringGetCString error retrieving pDevice->transport."); } // get vendorID refCF = CFDictionaryGetValue (hidProperties, CFSTR(kIOHIDVendorIDKey)); if (!refCF) refCF = CFDictionaryGetValue (usbProperties, CFSTR("idVendor")); if (refCF) { if (!CFNumberGetValue (refCF, kCFNumberLongType, &pDevice->vendorID)) HIDReportError ("CFNumberGetValue error retrieving pDevice->vendorID."); } // get product ID refCF = CFDictionaryGetValue (hidProperties, CFSTR(kIOHIDProductIDKey)); if (!refCF) refCF = CFDictionaryGetValue (usbProperties, CFSTR("idProduct")); if (refCF) { if (!CFNumberGetValue (refCF, kCFNumberLongType, &pDevice->productID)) HIDReportError ("CFNumberGetValue error retrieving pDevice->productID."); } // get product version refCF = CFDictionaryGetValue (hidProperties, CFSTR(kIOHIDVersionNumberKey)); if (refCF) { if (!CFNumberGetValue (refCF, kCFNumberLongType, &pDevice->version)) HIDReportError ("CFNumberGetValue error retrieving pDevice->version."); } // get manufacturer name refCF = CFDictionaryGetValue (hidProperties, CFSTR(kIOHIDManufacturerKey)); if (!refCF) refCF = CFDictionaryGetValue (usbProperties, CFSTR("USB Vendor Name")); if (refCF) { if (!CFStringGetCString (refCF, pDevice->manufacturer, 256, CFStringGetSystemEncoding ())) HIDReportError ("CFStringGetCString error retrieving pDevice->manufacturer."); } // get product name refCF = CFDictionaryGetValue (hidProperties, CFSTR(kIOHIDProductKey)); if (!refCF) refCF = CFDictionaryGetValue (usbProperties, CFSTR("USB Product Name")); if (refCF) { if (!CFStringGetCString (refCF, pDevice->product, 256, CFStringGetSystemEncoding ())) HIDReportError ("CFStringGetCString error retrieving pDevice->product."); } // get serial refCF = CFDictionaryGetValue (hidProperties, CFSTR(kIOHIDSerialNumberKey)); if (refCF) { if (!CFStringGetCString (refCF, pDevice->serial, 256, CFStringGetSystemEncoding ())) HIDReportError ("CFStringGetCString error retrieving pDevice->serial."); } // get location ID refCF = CFDictionaryGetValue (hidProperties, CFSTR(kIOHIDLocationIDKey)); if (!refCF) refCF = CFDictionaryGetValue (usbProperties, CFSTR("locationID")); if (refCF) { if (!CFNumberGetValue (refCF, kCFNumberLongType, &pDevice->locID)) HIDReportError ("CFNumberGetValue error retrieving pDevice->locID."); } // get usage page and usage refCF = CFDictionaryGetValue (hidProperties, CFSTR(kIOHIDPrimaryUsagePageKey)); if (refCF) { if (!CFNumberGetValue (refCF, kCFNumberLongType, &pDevice->usagePage)) HIDReportError ("CFNumberGetValue error retrieving pDevice->usagePage."); refCF = CFDictionaryGetValue (hidProperties, CFSTR(kIOHIDPrimaryUsageKey)); if (refCF) if (!CFNumberGetValue (refCF, kCFNumberLongType, &pDevice->usage)) HIDReportError ("CFNumberGetValue error retrieving pDevice->usage."); } if (NULL == refCF) // get top level element HID usage page or usage { // use top level element instead CFTypeRef refCFTopElement = 0; refCFTopElement = CFDictionaryGetValue (hidProperties, CFSTR(kIOHIDElementKey)); { // refCFTopElement points to an array of element dictionaries CFRange range = {0, CFArrayGetCount (refCFTopElement)}; CFArrayApplyFunction (refCFTopElement, range, hid_TopLevelElementHandler, NULL); } } } else HIDReportError ("IORegistryEntryCreateCFProperties failed to create usbProperties."); CFRelease (usbProperties); if (kIOReturnSuccess != IOObjectRelease (parent2)) HIDReportError ("IOObjectRelease error with parent2."); if (kIOReturnSuccess != IOObjectRelease (parent1)) HIDReportError ("IOObjectRelease error with parent1."); } } // --------------------------------- // adds device to linked list of devices passed in (handles NULL lists properly) // (returns where you just stored it) static pRecDevice* hid_AddDevice (pRecDevice *ppListDeviceHead, pRecDevice pNewDevice) { pRecDevice* result = NULL; if (NULL == *ppListDeviceHead) result = ppListDeviceHead; else { pRecDevice pDevicePrevious = NULL, pDevice = *ppListDeviceHead; while (pDevice) { pDevicePrevious = pDevice; pDevice = pDevicePrevious->pNext; } result = &pDevicePrevious->pNext; } pNewDevice->pNext = NULL; *result = pNewDevice; return result; } // --------------------------------- // given a IO device object build a flat device record including device info and elements static pRecDevice hid_BuildDevice (io_object_t hidDevice) { pRecDevice pDevice = (pRecDevice) malloc (sizeof (recDevice)); if (NULL != pDevice) { // get dictionary for HID properties CFMutableDictionaryRef hidProperties = 0; kern_return_t result = IORegistryEntryCreateCFProperties (hidDevice, &hidProperties, kCFAllocatorDefault, kNilOptions); // clear record bzero(pDevice, sizeof(recDevice)); if ((result == KERN_SUCCESS) && (NULL != hidProperties)) { pRecElement pCurrentElement = NULL; // create device interface result = HIDCreateOpenDeviceInterface (hidDevice, pDevice); if (kIOReturnSuccess != result) HIDReportErrorNum ("HIDCreateOpenDeviceInterface failed.", result); hid_GetDeviceInfo (hidDevice, hidProperties, pDevice); // hidDevice used to find parents in registry tree // set current device for use in getting elements gCurrentGetDevice = pDevice; // Add all elements hid_GetCollectionElements (hidProperties, &pCurrentElement); gCurrentGetDevice = NULL; CFRelease (hidProperties); } else HIDReportErrorNum ("IORegistryEntryCreateCFProperties error when creating deviceProperties.", result); } else HIDReportError ("malloc error when allocating pRecDevice."); return pDevice; } #if USE_NOTIFICATIONS //================================================================================================ // // hid_DeviceNotification // // This routine will get called whenever any kIOGeneralInterest notification happens. We are // interested in the kIOMessageServiceIsTerminated message so that's what we look for. Other // messages are defined in IOMessage.h. // //================================================================================================ // static void hid_DeviceNotification( void *refCon, io_service_t service, natural_t messageType, void *messageArgument ) { pRecDevice pDevice = (pRecDevice) refCon; if (messageType == kIOMessageServiceIsTerminated) { printf("Device 0x%08x \"%s\"removed.\n", service, pDevice->product); // Free the data we're no longer using now that the device is going away hid_DisposeDevice (pDevice); } } #else static void hid_RemovalCallbackFunction(void * target, IOReturn result, void * refcon, void * sender) { hid_DisposeDevice ((pRecDevice) target); } #endif USE_NOTIFICATIONS //================================================================================================ // // hid_AddDevices // // This routine is the callback for our IOServiceAddMatchingNotification. When we get called // we will look at all the devices that were added and we will: // // 1. Create some private data to relate to each device. // 2. Submit an IOServiceAddInterestNotification of type kIOGeneralInterest for this device, // using the refCon field to store a pointer to our data. When we get called with // this interest notification, we can grab the refCon and access our private data. // //================================================================================================ // // --------------------------------- // given a IO device iterator, iterate it and add all its devices static void hid_AddDevices (void *refCon, io_iterator_t iterator) { // NOTE: refcon passed in is used to point to the device list head pRecDevice* pListDeviceHead = (pRecDevice*) refCon; IOReturn result = kIOReturnSuccess; io_object_t ioHIDDeviceObject = NULL; while (ioHIDDeviceObject = IOIteratorNext (iterator)) { pRecDevice* pNewDeviceAt = NULL; pRecDevice pNewDevice = hid_BuildDevice (ioHIDDeviceObject); if (pNewDevice) { #if 0 // set true for verbose output printf("\nhid_AddDevices: pNewDevice = {t: \"%s\", v: %ld, p: %ld, v: %ld, m: \"%s\", " \ "p: \"%s\", l: %ld, u: %4.4lX:%4.4lX, #e: %ld, #f: %ld, #i: %ld, #o: %ld, " \ "#c: %ld, #a: %ld, #b: %ld, #h: %ld, #s: %ld, #d: %ld, #w: %ld}.", pNewDevice->transport, pNewDevice->vendorID, pNewDevice->productID, pNewDevice->version, pNewDevice->manufacturer, pNewDevice->product, pNewDevice->locID, pNewDevice->usagePage, pNewDevice->usage, pNewDevice->totalElements, pNewDevice->features, pNewDevice->inputs, pNewDevice->outputs, pNewDevice->collections, pNewDevice->axis, pNewDevice->buttons, pNewDevice->hats, pNewDevice->sliders, pNewDevice->dials, pNewDevice->wheels ); fflush(stdout); #elif 0 // otherwise output brief description printf("\nhid_AddDevices: pNewDevice = {m: \"%s\" p: \"%s\", vid: %ld, pid: %ld, loc: %8.8lX, usage: %4.4lX:%4.4lX}.", pNewDevice->manufacturer, pNewDevice->product, pNewDevice->vendorID, pNewDevice->productID, pNewDevice->locID, pNewDevice->usagePage, pNewDevice->usage ); fflush(stdout); #endif pNewDeviceAt = hid_AddDevice (pListDeviceHead, pNewDevice); } #if USE_NOTIFICATIONS // Register for an interest notification of this device being removed. Use a reference to our // private data as the refCon which will be passed to the notification callback. result = IOServiceAddInterestNotification( gNotifyPort, // notifyPort ioHIDDeviceObject, // service kIOGeneralInterest, // interestType hid_DeviceNotification, // callback pNewDevice, // refCon (io_object_t*) &pNewDevice->notification); // notification if (KERN_SUCCESS != result) HIDReportErrorNum ("hid_AddDevices: IOServiceAddInterestNotification error: x0%8.8lX.", result); #else result = (*(IOHIDDeviceInterface**)pNewDevice->interface)->setRemovalCallback (pNewDevice->interface, hid_RemovalCallbackFunction,pNewDeviceAt,0); #endif USE_NOTIFICATIONS // release the device object, it is no longer needed result = IOObjectRelease (ioHIDDeviceObject); if (KERN_SUCCESS != result) HIDReportErrorNum ("hid_AddDevices: IOObjectRelease error with ioHIDDeviceObject.", result); } } // --------------------------------- // disposes of the element list associated with a device and the memory associated with the list // uses depthwise recursion to dispose both collections and elements. static void hid_DisposeDeviceElements (pRecElement pElement) { if (pElement) { if (pElement->pChild) hid_DisposeDeviceElements (pElement->pChild); if (pElement->pSibling) hid_DisposeDeviceElements (pElement->pSibling); free (pElement); } } // --------------------------------- // disposes of a single device, closing and releaseing interface, freeing memory fro device and elements, setting device pointer to NULL // all your device no longer belong to us... (i.e., you do not 'own' the device anymore) static pRecDevice hid_DisposeDevice (pRecDevice pDevice) { kern_return_t result = KERN_SUCCESS; pRecDevice pDeviceNext = NULL; if (HIDIsValidDevice(pDevice)) { // save next device prior to disposing of this device pDeviceNext = pDevice->pNext; result = HIDDequeueDevice (pDevice); #if 0 if (kIOReturnSuccess != result) HIDReportErrorNum ("hid_DisposeDevice: HIDDequeueDevice error: 0x%8.8X.", result); #endif 1 hid_DisposeDeviceElements (pDevice->pListElements); pDevice->pListElements = NULL; result = HIDCloseReleaseInterface (pDevice); // function sanity checks interface value (now application does not own device) if (kIOReturnSuccess != result) HIDReportErrorNum ("hid_DisposeDevice: HIDCloseReleaseInterface error: 0x%8.8X.", result); #if USE_NOTIFICATIONS if (pDevice->interface) { // replace (*pDevice->interface)->Release(pDevice->interface); result = IODestroyPlugInInterface (pDevice->interface); if (kIOReturnSuccess != result) HIDReportErrorNum ("hid_DisposeDevice: IODestroyPlugInInterface error: 0x%8.8X.", result); } if (pDevice->notification) { result = IOObjectRelease((io_object_t) pDevice->notification); if (kIOReturnSuccess != result) HIDReportErrorNum ("hid_DisposeDevice: IOObjectRelease error: 0x%8.8X.", result); } #endif USE_NOTIFICATIONS // remove this device from the device list if (gpDeviceList == pDevice) // head of list? gpDeviceList = pDeviceNext; else { pRecDevice pDeviceTemp = pDeviceNext = gpDeviceList; // we're going to return this if we don't find ourselfs in the list while (pDeviceTemp) { if (pDeviceTemp->pNext == pDevice) // found us! { // take us out of linked list pDeviceTemp->pNext = pDeviceNext = pDevice->pNext; break; } pDeviceTemp = pDeviceTemp->pNext; } } free (pDevice); } // update device count gNumDevices = hid_CountCurrentDevices (); return pDeviceNext; } // --------------------------------- // count number of devices in global device list (gpDeviceList) static UInt32 hid_CountCurrentDevices (void) { pRecDevice pDevice = gpDeviceList; UInt32 devices = 0; while (pDevice) { devices++; pDevice = pDevice->pNext; } return devices; } // --------------------------------- // matches type masks passed in to actual element types (which are not set up to be used as a mask static Boolean hid_MatchElementTypeMask (IOHIDElementType type, HIDElementTypeMask typeMask) { if (typeMask & kHIDElementTypeInput) if ((type == kIOHIDElementTypeInput_Misc) || (type == kIOHIDElementTypeInput_Button) || (type == kIOHIDElementTypeInput_Axis) || (type == kIOHIDElementTypeInput_ScanCodes)) return true; if (typeMask & kHIDElementTypeOutput) if (type == kIOHIDElementTypeOutput) return true; if (typeMask & kHIDElementTypeFeature) if (type == kIOHIDElementTypeFeature) return true; if (typeMask & kHIDElementTypeCollection) if (type == kIOHIDElementTypeCollection) return true; return false; } // --------------------------------- static pRecElement hid_GetDeviceElement (pRecElement pElement, HIDElementTypeMask typeMask) { // we are asking for this element if (NULL != pElement) { if (hid_MatchElementTypeMask (pElement->type, typeMask)) // if the type match what we are looking for return pElement; // return the element else return HIDGetNextDeviceElement (pElement, typeMask); // else get the next one } return NULL; } #define FAKE_IT 0 // set true for debugging; returns the usage & usage page as numbers // --------------------------------- // Load the usage strings from the resource (XML) file into a CFPropertyListRef static CFPropertyListRef xml_load_usage_strings(void) { CFPropertyListRef tCFPropertyListRef = NULL; CFURLRef resFileCFURLRef = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("HID_usage_strings"), CFSTR("plist"), NULL); if (NULL != resFileCFURLRef) { CFDataRef resCFDataRef; if (CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault, resFileCFURLRef, &resCFDataRef, nil, nil, nil)) { if (NULL != resCFDataRef) { CFStringRef errorString; tCFPropertyListRef = CFPropertyListCreateFromXMLData(kCFAllocatorDefault, resCFDataRef, kCFPropertyListImmutable, &errorString); if (NULL == tCFPropertyListRef) CFShow(errorString); CFRelease(resCFDataRef); } } CFRelease(resFileCFURLRef); } return tCFPropertyListRef; } // --------------------------------- // Find a usage string in the resource (XML) file static Boolean xml_GetUsageName(const long valueUsagePage, const long valueUsage, char* pCstr) { static CFPropertyListRef tCFPropertyListRef = NULL; Boolean results = false; if (NULL == tCFPropertyListRef) tCFPropertyListRef = xml_load_usage_strings(); if (NULL != tCFPropertyListRef) { if (CFDictionaryGetTypeID() == CFGetTypeID(tCFPropertyListRef)) { CFDictionaryRef pageCFDictionaryRef; CFStringRef pageKeyCFStringRef; pageKeyCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("0x%4.4lX"), valueUsagePage); if (CFDictionaryGetValueIfPresent(tCFPropertyListRef, pageKeyCFStringRef, (const void**) &pageCFDictionaryRef)) { CFStringRef pageCFStringRef; if (CFDictionaryGetValueIfPresent(pageCFDictionaryRef, CFSTR("Name"), (const void**) &pageCFStringRef)) { //CFShow(pageCFStringRef); } { CFStringRef fullCFStringRef = NULL; CFStringRef usageKeyCFStringRef; CFStringRef usageCFStringRef; usageKeyCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("0x%4.4lX"), valueUsage); if (CFDictionaryGetValueIfPresent(pageCFDictionaryRef, usageKeyCFStringRef, (const void**) &usageCFStringRef)) { fullCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%@ %@"), pageCFStringRef, usageCFStringRef); // CFShow(usageCFStringRef); } #if FAKE_IT else { fullCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%@ #%@"), pageCFStringRef, usageKeyCFStringRef); } #endif if (fullCFStringRef) { // CFShow(fullCFStringRef); results = CFStringGetCString( fullCFStringRef, pCstr, CFStringGetLength(fullCFStringRef) * sizeof(UniChar) + 1, kCFStringEncodingMacRoman); CFRelease(fullCFStringRef); } CFRelease(usageKeyCFStringRef); } } CFRelease(pageKeyCFStringRef); } //++CFRelease(tCFPropertyListRef); // Leak this! } return results; } #pragma mark public functions // ================================= // public functions // --------------------------------- // Create and open an interface to device, required prior to extracting values or building queues // Note: appliction now owns the device and must close and release it prior to exiting unsigned long HIDCreateOpenDeviceInterface (UInt32 hidDevice, pRecDevice pDevice) { IOReturn result = kIOReturnSuccess; HRESULT plugInResult = S_OK; SInt32 score = 0; IOCFPlugInInterface ** ppPlugInInterface = NULL; if (NULL == pDevice->interface) { result = IOCreatePlugInInterfaceForService (hidDevice, kIOHIDDeviceUserClientTypeID, kIOCFPlugInInterfaceID, &ppPlugInInterface, &score); if (kIOReturnSuccess == result) { // Call a method of the intermediate plug-in to create the device interface plugInResult = (*ppPlugInInterface)->QueryInterface (ppPlugInInterface, CFUUIDGetUUIDBytes (kIOHIDDeviceInterfaceID), (void *) &(pDevice->interface)); if (S_OK != plugInResult) HIDReportErrorNum ("CouldnÕt query HID class device interface from plugInInterface", plugInResult); IODestroyPlugInInterface (ppPlugInInterface); // replace (*ppPlugInInterface)->Release (ppPlugInInterface) } else HIDReportErrorNum ("Failed to create **plugInInterface via IOCreatePlugInInterfaceForService.", result); } if (NULL != pDevice->interface) { result = (*(IOHIDDeviceInterface**)pDevice->interface)->open (pDevice->interface, 0); if (kIOReturnSuccess != result) HIDReportErrorNum ("Failed to open pDevice->interface via open.", result); } return result; } // --------------------------------- // builds list of device with elements (allocates memory and captures devices) // list is allcoated internally within HID Utilites and can be accessed via accessor functions // structures within list are considered flat and user accessable, but not user modifiable // can be called again to rebuild list to account for new devices (will do the right thing in case of disposing existing list) // returns true if succesful Boolean HIDBuildDeviceList (UInt32 usagePage, UInt32 usage) { IOReturn result = kIOReturnSuccess; mach_port_t masterPort = NULL; if (NULL != gpDeviceList) HIDReleaseDeviceList (); result = IOMasterPort (bootstrap_port, &masterPort); if (kIOReturnSuccess != result) HIDReportErrorNum ("IOMasterPort error with bootstrap_port.", result); else { CFMutableDictionaryRef hidMatchDictionary = NULL; // Set up matching dictionary to search the I/O Registry for HID devices we are interested in. Dictionary reference is NULL if error. { CFNumberRef refUsage = NULL, refUsagePage = NULL; // Set up a matching dictionary to search I/O Registry by class name for all HID class devices. hidMatchDictionary = IOServiceMatching (kIOHIDDeviceKey); if (NULL != hidMatchDictionary) { if (usagePage) { // Add key for device type (joystick, in this case) to refine the matching dictionary. refUsagePage = CFNumberCreate (kCFAllocatorDefault, kCFNumberLongType, &usagePage); CFDictionarySetValue (hidMatchDictionary, CFSTR (kIOHIDPrimaryUsagePageKey), refUsagePage); CFRelease (refUsagePage); if (usage) { refUsage = CFNumberCreate (kCFAllocatorDefault, kCFNumberLongType, &usage); CFDictionarySetValue (hidMatchDictionary, CFSTR (kIOHIDPrimaryUsageKey), refUsage); CFRelease (refUsage); } } CFRetain(hidMatchDictionary); } else HIDReportError ("Failed to get HID CFMutableDictionaryRef via IOServiceMatching."); } #if USE_NOTIFICATIONS // Create a notification port and add its run loop event source to our run loop // This is how async notifications get set up. { CFRunLoopSourceRef runLoopSource; gNotifyPort = IONotificationPortCreate(masterPort); runLoopSource = IONotificationPortGetRunLoopSource(gNotifyPort); gRunLoop = CFRunLoopGetCurrent(); CFRunLoopAddSource(gRunLoop, runLoopSource, kCFRunLoopDefaultMode); // Now set up a notification to be called when a device is first matched by I/O Kit. result = IOServiceAddMatchingNotification(gNotifyPort, // notifyPort kIOFirstMatchNotification, // notificationType hidMatchDictionary, // matching hid_AddDevices, // callback &gpDeviceList, // refCon &gAddedIter // notification ); // call it now to add all existing devices hid_AddDevices(&gpDeviceList,gAddedIter); } #else { io_iterator_t hidObjectIterator = NULL; // Now search I/O Registry for matching devices. result = IOServiceGetMatchingServices (masterPort, hidMatchDictionary, &hidObjectIterator); if (kIOReturnSuccess != result) HIDReportErrorNum ("Failed to create IO object iterator, error:", result); else if (NULL == hidObjectIterator) // likely no HID devices which matched selection criteria are connected HIDReportError ("Warning: Could not find any matching devices, thus iterator creation failed."); if (NULL != hidObjectIterator) { hid_AddDevices(&gpDeviceList,hidObjectIterator); result = IOObjectRelease (hidObjectIterator); // release the iterator if (kIOReturnSuccess != result) HIDReportErrorNum ("IOObjectRelease error with hidObjectIterator.", result); gNumDevices = hid_CountCurrentDevices (); return true; } } #endif USE_NOTIFICATIONS // IOServiceGetMatchingServices consumes a reference to the dictionary, so we don't need to release the dictionary ref. hidMatchDictionary = NULL; } return false; } // --------------------------------- // release list built by above function // MUST be called prior to application exit to properly release devices // if not called (or app crashes) devices can be recovered by pluging into different location in USB chain void HIDReleaseDeviceList (void) { while (NULL != gpDeviceList) gpDeviceList = hid_DisposeDevice (gpDeviceList); // dispose current device return next device will set gpDeviceList to NULL gNumDevices = 0; } // --------------------------------- // does a device list exist Boolean HIDHaveDeviceList (void) { if (NULL != gpDeviceList) return true; return false; } // --------------------------------- // how many HID devices have been found // returns 0 if no device list exist UInt32 HIDCountDevices (void) { gNumDevices = hid_CountCurrentDevices (); return gNumDevices; } // --------------------------------- // how many elements does a specific device have // returns 0 if device is invlaid or NULL UInt32 HIDCountDeviceElements (pRecDevice pDevice, HIDElementTypeMask typeMask) { long count = 0; if (HIDIsValidDevice(pDevice)) { if (typeMask & kHIDElementTypeInput) count += pDevice->inputs; if (typeMask & kHIDElementTypeOutput) count += pDevice->outputs; if (typeMask & kHIDElementTypeFeature) count += pDevice->features; if (typeMask & kHIDElementTypeCollection) count += pDevice->collections; } return count; } // --------------------------------- // get the first device in the device list // returns NULL if no list exists pRecDevice HIDGetFirstDevice (void) { return gpDeviceList; } // --------------------------------- // get next device in list given current device as parameter // returns NULL if end of list pRecDevice HIDGetNextDevice (pRecDevice pDevice) { if (NULL != pDevice) return pDevice->pNext; else return NULL; } // --------------------------------- // get the first element of device passed in as parameter // returns NULL if no list exists or device does not exists or is NULL pRecElement HIDGetFirstDeviceElement (pRecDevice pDevice, HIDElementTypeMask typeMask) { if (HIDIsValidDevice(pDevice)) { if (hid_MatchElementTypeMask (pDevice->pListElements->type, typeMask)) // ensure first type matches return pDevice->pListElements; else return HIDGetNextDeviceElement (pDevice->pListElements, typeMask); } else return NULL; } // --------------------------------- // get next element of given device in list given current element as parameter // will walk down each collection then to next element or collection (depthwise traverse) // returns NULL if end of list // uses mask of HIDElementTypeMask to restrict element found // use kHIDElementTypeIO to get previous HIDGetNextDeviceElement functionality pRecElement HIDGetNextDeviceElement (pRecElement pElement, HIDElementTypeMask typeMask) { // should only have elements passed in (though someone could mix calls and pass us a collection) // collection means return the next child or sibling (in that order) // element means returnt he next sibling (as elements can't have children if (NULL != pElement) { if (pElement->pChild) { if (pElement->type != kIOHIDElementTypeCollection) HIDReportError ("Malformed element list: found child of element."); else return hid_GetDeviceElement (pElement->pChild, typeMask); // return the child of this element } else if (pElement->pSibling) { return hid_GetDeviceElement (pElement->pSibling, typeMask); //return the sibling of this element } else // at end back up correctly { pRecElement pPreviousElement = NULL; // malformed device ending in collection if (pElement->type == kIOHIDElementTypeCollection) HIDReportError ("Malformed device: found collection at end of element chain."); // walk back up tree to element prior to first collection ecountered and take next element while (NULL != pElement->pPrevious) { pPreviousElement = pElement; pElement = pElement->pPrevious; // look at previous element // if we have a collection and the previous element is the branch element (should have both a colection and next element attached to it) // if we found a collection, which we are not at the sibling level that actually does have siblings if (((pElement->type == kIOHIDElementTypeCollection) && (pPreviousElement != pElement->pSibling) && pElement->pSibling) || // or if we are at the top (NULL == pElement->pPrevious)) // at top of tree break; } if (NULL == pElement->pPrevious) return NULL; // got to top of list with only a collection as the first element // now we must have been down the child route so go down the sibling route pElement = pElement->pSibling; // element of interest return hid_GetDeviceElement (pElement, typeMask); // otherwise return this element } } return NULL; } // --------------------------------- // get previous element of given device in list given current element as parameter // this wlaks directly up the tree to the top element and does not search at each level // returns NULL if beginning of list // uses mask of HIDElementTypeMask to restrict element found // use kHIDElementTypeIO to get non-collection elements pRecElement HIDGetPreviousDeviceElement (pRecElement pElement, HIDElementTypeMask typeMask) { pRecElement pPreviousElement = pElement->pPrevious; // walk back up tree to element prior while (pPreviousElement && !hid_MatchElementTypeMask (pPreviousElement->type, typeMask)) { pElement = pPreviousElement; // look at previous element pPreviousElement = pElement->pPrevious; } return pPreviousElement; // return this element } // --------------------------------- // returns C string type name given a type enumeration passed in as parameter (see IOHIDKeys.h) // returns "Unknown Type" for invalid types void HIDGetTypeName (IOHIDElementType theType, char * cstrName) { switch (theType) { case kIOHIDElementTypeInput_Misc: sprintf(cstrName, "Miscellaneous Input"); break; case kIOHIDElementTypeInput_Button: sprintf(cstrName, "Button Input"); break; case kIOHIDElementTypeInput_Axis: sprintf(cstrName, "Axis Input"); break; case kIOHIDElementTypeInput_ScanCodes: sprintf(cstrName, "Scan Code Input"); break; case kIOHIDElementTypeOutput: sprintf(cstrName, "Output"); break; case kIOHIDElementTypeFeature: sprintf(cstrName, "Feature"); break; case kIOHIDElementTypeCollection: sprintf(cstrName, "Collection"); break; default: sprintf(cstrName, "Unknown Type"); break; } } // --------------------------------- // returns C string usage given usage page and usage passed in as parameters (see IOUSBHIDParser.h) // returns usage page and usage values in string form for unknown values void HIDGetUsageName (const long valueUsagePage, const long valueUsage, char * cstrName) { if (xml_GetUsageName(valueUsagePage, valueUsage, cstrName)) return; switch (valueUsagePage) { case kHIDPage_Undefined: switch (valueUsage) { default: sprintf (cstrName, "Undefined Page, Usage 0x%lx", valueUsage); break; } break; case kHIDPage_GenericDesktop: switch (valueUsage) { case kHIDUsage_GD_Pointer: sprintf (cstrName, "Pointer"); break; case kHIDUsage_GD_Mouse: sprintf (cstrName, "Mouse"); break; case kHIDUsage_GD_Joystick: sprintf (cstrName, "Joystick"); break; case kHIDUsage_GD_GamePad: sprintf (cstrName, "GamePad"); break; case kHIDUsage_GD_Keyboard: sprintf (cstrName, "Keyboard"); break; case kHIDUsage_GD_Keypad: sprintf (cstrName, "Keypad"); break; case kHIDUsage_GD_MultiAxisController: sprintf (cstrName, "Multi-Axis Controller"); break; case kHIDUsage_GD_X: sprintf (cstrName, "X-Axis"); break; case kHIDUsage_GD_Y: sprintf (cstrName, "Y-Axis"); break; case kHIDUsage_GD_Z: sprintf (cstrName, "Z-Axis"); break; case kHIDUsage_GD_Rx: sprintf (cstrName, "X-Rotation"); break; case kHIDUsage_GD_Ry: sprintf (cstrName, "Y-Rotation"); break; case kHIDUsage_GD_Rz: sprintf (cstrName, "Z-Rotation"); break; case kHIDUsage_GD_Slider: sprintf (cstrName, "Slider"); break; case kHIDUsage_GD_Dial: sprintf (cstrName, "Dial"); break; case kHIDUsage_GD_Wheel: sprintf (cstrName, "Wheel"); break; case kHIDUsage_GD_Hatswitch: sprintf (cstrName, "Hatswitch"); break; case kHIDUsage_GD_CountedBuffer: sprintf (cstrName, "Counted Buffer"); break; case kHIDUsage_GD_ByteCount: sprintf (cstrName, "Byte Count"); break; case kHIDUsage_GD_MotionWakeup: sprintf (cstrName, "Motion Wakeup"); break; case kHIDUsage_GD_Start: sprintf (cstrName, "Start"); break; case kHIDUsage_GD_Select: sprintf (cstrName, "Select"); break; case kHIDUsage_GD_Vx: sprintf (cstrName, "X-Velocity"); break; case kHIDUsage_GD_Vy: sprintf (cstrName, "Y-Velocity"); break; case kHIDUsage_GD_Vz: sprintf (cstrName, "Z-Velocity"); break; case kHIDUsage_GD_Vbrx: sprintf (cstrName, "X-Rotation Velocity"); break; case kHIDUsage_GD_Vbry: sprintf (cstrName, "Y-Rotation Velocity"); break; case kHIDUsage_GD_Vbrz: sprintf (cstrName, "Z-Rotation Velocity"); break; case kHIDUsage_GD_Vno: sprintf (cstrName, "Vno"); break; case kHIDUsage_GD_SystemControl: sprintf (cstrName, "System Control"); break; case kHIDUsage_GD_SystemPowerDown: sprintf (cstrName, "System Power Down"); break; case kHIDUsage_GD_SystemSleep: sprintf (cstrName, "System Sleep"); break; case kHIDUsage_GD_SystemWakeUp: sprintf (cstrName, "System Wake Up"); break; case kHIDUsage_GD_SystemContextMenu: sprintf (cstrName, "System Context Menu"); break; case kHIDUsage_GD_SystemMainMenu: sprintf (cstrName, "System Main Menu"); break; case kHIDUsage_GD_SystemAppMenu: sprintf (cstrName, "System App Menu"); break; case kHIDUsage_GD_SystemMenuHelp: sprintf (cstrName, "System Menu Help"); break; case kHIDUsage_GD_SystemMenuExit: sprintf (cstrName, "System Menu Exit"); break; case kHIDUsage_GD_SystemMenu: sprintf (cstrName, "System Menu"); break; case kHIDUsage_GD_SystemMenuRight: sprintf (cstrName, "System Menu Right"); break; case kHIDUsage_GD_SystemMenuLeft: sprintf (cstrName, "System Menu Left"); break; case kHIDUsage_GD_SystemMenuUp: sprintf (cstrName, "System Menu Up"); break; case kHIDUsage_GD_SystemMenuDown: sprintf (cstrName, "System Menu Down"); break; case kHIDUsage_GD_DPadUp: sprintf (cstrName, "DPad Up"); break; case kHIDUsage_GD_DPadDown: sprintf (cstrName, "DPad Down"); break; case kHIDUsage_GD_DPadRight: sprintf (cstrName, "DPad Right"); break; case kHIDUsage_GD_DPadLeft: sprintf (cstrName, "DPad Left"); break; case kHIDUsage_GD_Reserved: sprintf (cstrName, "Reserved"); break; default: sprintf (cstrName, "Generic Desktop Usage 0x%lx", valueUsage); break; } break; case kHIDPage_Simulation: switch (valueUsage) { default: sprintf (cstrName, "Simulation Usage 0x%lx", valueUsage); break; } break; case kHIDPage_VR: switch (valueUsage) { default: sprintf (cstrName, "VR Usage 0x%lx", valueUsage); break; } break; case kHIDPage_Sport: switch (valueUsage) { default: sprintf (cstrName, "Sport Usage 0x%lx", valueUsage); break; } break; case kHIDPage_Game: switch (valueUsage) { default: sprintf (cstrName, "Game Usage 0x%lx", valueUsage); break; } break; case kHIDPage_KeyboardOrKeypad: switch (valueUsage) { default: sprintf (cstrName, "Keyboard Usage 0x%lx", valueUsage); break; } break; case kHIDPage_LEDs: switch (valueUsage) { // some LED usages case kHIDUsage_LED_IndicatorRed: sprintf (cstrName, "Red LED"); break; case kHIDUsage_LED_IndicatorGreen: sprintf (cstrName, "Green LED"); break; case kHIDUsage_LED_IndicatorAmber: sprintf (cstrName, "Amber LED"); break; case kHIDUsage_LED_GenericIndicator: sprintf (cstrName, "Generic LED"); break; case kHIDUsage_LED_SystemSuspend: sprintf (cstrName, "System Suspend LED"); break; case kHIDUsage_LED_ExternalPowerConnected: sprintf (cstrName, "External Power LED"); break; default: sprintf (cstrName, "LED Usage 0x%lx", valueUsage); break; } break; case kHIDPage_Button: switch (valueUsage) { default: sprintf (cstrName, "Button #%ld", valueUsage); break; } break; case kHIDPage_Ordinal: switch (valueUsage) { default: sprintf (cstrName, "Ordinal Instance %lx", valueUsage); break; } break; case kHIDPage_Telephony: switch (valueUsage) { default: sprintf (cstrName, "Telephony Usage 0x%lx", valueUsage); break; } break; case kHIDPage_Consumer: switch (valueUsage) { default: sprintf (cstrName, "Consumer Usage 0x%lx", valueUsage); break; } break; case kHIDPage_Digitizer: switch (valueUsage) { default: sprintf (cstrName, "Digitizer Usage 0x%lx", valueUsage); break; } break; case kHIDPage_PID: if (((valueUsage >= 0x02) && (valueUsage <= 0x1F)) || ((valueUsage >= 0x29) && (valueUsage <= 0x2F)) || ((valueUsage >= 0x35) && (valueUsage <= 0x3F)) || ((valueUsage >= 0x44) && (valueUsage <= 0x4F)) || (valueUsage == 0x8A) || (valueUsage == 0x93) || ((valueUsage >= 0x9D) && (valueUsage <= 0x9E)) || ((valueUsage >= 0xA1) && (valueUsage <= 0xA3)) || ((valueUsage >= 0xAD) && (valueUsage <= 0xFFFF))) sprintf (cstrName, "PID Reserved"); else switch (valueUsage) { case 0x00: sprintf (cstrName, "PID Undefined Usage"); break; case kHIDUsage_PID_PhysicalInterfaceDevice: sprintf (cstrName, "Physical Interface Device"); break; case kHIDUsage_PID_Normal: sprintf (cstrName, "Normal Force"); break; case kHIDUsage_PID_SetEffectReport: sprintf (cstrName, "Set Effect Report"); break; case kHIDUsage_PID_EffectBlockIndex: sprintf (cstrName, "Effect Block Index"); break; case kHIDUsage_PID_ParamBlockOffset: sprintf (cstrName, "Parameter Block Offset"); break; case kHIDUsage_PID_ROM_Flag: sprintf (cstrName, "ROM Flag"); break; case kHIDUsage_PID_EffectType: sprintf (cstrName, "Effect Type"); break; case kHIDUsage_PID_ET_ConstantForce: sprintf (cstrName, "Effect Type Constant Force"); break; case kHIDUsage_PID_ET_Ramp: sprintf (cstrName, "Effect Type Ramp"); break; case kHIDUsage_PID_ET_CustomForceData: sprintf (cstrName, "Effect Type Custom Force Data"); break; case kHIDUsage_PID_ET_Square: sprintf (cstrName, "Effect Type Square"); break; case kHIDUsage_PID_ET_Sine: sprintf (cstrName, "Effect Type Sine"); break; case kHIDUsage_PID_ET_Triangle: sprintf (cstrName, "Effect Type Triangle"); break; case kHIDUsage_PID_ET_SawtoothUp: sprintf (cstrName, "Effect Type Sawtooth Up"); break; case kHIDUsage_PID_ET_SawtoothDown: sprintf (cstrName, "Effect Type Sawtooth Down"); break; case kHIDUsage_PID_ET_Spring: sprintf (cstrName, "Effect Type Spring"); break; case kHIDUsage_PID_ET_Damper: sprintf (cstrName, "Effect Type Damper"); break; case kHIDUsage_PID_ET_Inertia: sprintf (cstrName, "Effect Type Inertia"); break; case kHIDUsage_PID_ET_Friction: sprintf (cstrName, "Effect Type Friction"); break; case kHIDUsage_PID_Duration: sprintf (cstrName, "Effect Duration"); break; case kHIDUsage_PID_SamplePeriod: sprintf (cstrName, "Effect Sample Period"); break; case kHIDUsage_PID_Gain: sprintf (cstrName, "Effect Gain"); break; case kHIDUsage_PID_TriggerButton: sprintf (cstrName, "Effect Trigger Button"); break; case kHIDUsage_PID_TriggerRepeatInterval: sprintf (cstrName, "Effect Trigger Repeat Interval"); break; case kHIDUsage_PID_AxesEnable: sprintf (cstrName, "Axis Enable"); break; case kHIDUsage_PID_DirectionEnable: sprintf (cstrName, "Direction Enable"); break; case kHIDUsage_PID_Direction: sprintf (cstrName, "Direction"); break; case kHIDUsage_PID_TypeSpecificBlockOffset: sprintf (cstrName, "Type Specific Block Offset"); break; case kHIDUsage_PID_BlockType: sprintf (cstrName, "Block Type"); break; case kHIDUsage_PID_SetEnvelopeReport: sprintf (cstrName, "Set Envelope Report"); break; case kHIDUsage_PID_AttackLevel: sprintf (cstrName, "Envelope Attack Level"); break; case kHIDUsage_PID_AttackTime: sprintf (cstrName, "Envelope Attack Time"); break; case kHIDUsage_PID_FadeLevel: sprintf (cstrName, "Envelope Fade Level"); break; case kHIDUsage_PID_FadeTime: sprintf (cstrName, "Envelope Fade Time"); break; case kHIDUsage_PID_SetConditionReport: sprintf (cstrName, "Set Condition Report"); break; case kHIDUsage_PID_CP_Offset: sprintf (cstrName, "Condition CP Offset"); break; case kHIDUsage_PID_PositiveCoefficient: sprintf (cstrName, "Condition Positive Coefficient"); break; case kHIDUsage_PID_NegativeCoefficient: sprintf (cstrName, "Condition Negative Coefficient"); break; case kHIDUsage_PID_PositiveSaturation: sprintf (cstrName, "Condition Positive Saturation"); break; case kHIDUsage_PID_NegativeSaturation: sprintf (cstrName, "Condition Negative Saturation"); break; case kHIDUsage_PID_DeadBand: sprintf (cstrName, "Condition Dead Band"); break; case kHIDUsage_PID_DownloadForceSample: sprintf (cstrName, "Download Force Sample"); break; case kHIDUsage_PID_IsochCustomForceEnable: sprintf (cstrName, "Isoch Custom Force Enable"); break; case kHIDUsage_PID_CustomForceDataReport: sprintf (cstrName, "Custom Force Data Report"); break; case kHIDUsage_PID_CustomForceData: sprintf (cstrName, "Custom Force Data"); break; case kHIDUsage_PID_CustomForceVendorDefinedData: sprintf (cstrName, "Custom Force Vendor Defined Data"); break; case kHIDUsage_PID_SetCustomForceReport: sprintf (cstrName, "Set Custom Force Report"); break; case kHIDUsage_PID_CustomForceDataOffset: sprintf (cstrName, "Custom Force Data Offset"); break; case kHIDUsage_PID_SampleCount: sprintf (cstrName, "Custom Force Sample Count"); break; case kHIDUsage_PID_SetPeriodicReport: sprintf (cstrName, "Set Periodic Report"); break; case kHIDUsage_PID_Offset: sprintf (cstrName, "Periodic Offset"); break; case kHIDUsage_PID_Magnitude: sprintf (cstrName, "Periodic Magnitude"); break; case kHIDUsage_PID_Phase: sprintf (cstrName, "Periodic Phase"); break; case kHIDUsage_PID_Period: sprintf (cstrName, "Periodic Period"); break; case kHIDUsage_PID_SetConstantForceReport: sprintf (cstrName, "Set Constant Force Report"); break; case kHIDUsage_PID_SetRampForceReport: sprintf (cstrName, "Set Ramp Force Report"); break; case kHIDUsage_PID_RampStart: sprintf (cstrName, "Ramp Start"); break; case kHIDUsage_PID_RampEnd: sprintf (cstrName, "Ramp End"); break; case kHIDUsage_PID_EffectOperationReport: sprintf (cstrName, "Effect Operation Report"); break; case kHIDUsage_PID_EffectOperation: sprintf (cstrName, "Effect Operation"); break; case kHIDUsage_PID_OpEffectStart: sprintf (cstrName, "Op Effect Start"); break; case kHIDUsage_PID_OpEffectStartSolo: sprintf (cstrName, "Op Effect Start Solo"); break; case kHIDUsage_PID_OpEffectStop: sprintf (cstrName, "Op Effect Stop"); break; case kHIDUsage_PID_LoopCount: sprintf (cstrName, "Op Effect Loop Count"); break; case kHIDUsage_PID_DeviceGainReport: sprintf (cstrName, "Device Gain Report"); break; case kHIDUsage_PID_DeviceGain: sprintf (cstrName, "Device Gain"); break; case kHIDUsage_PID_PoolReport: sprintf (cstrName, "PID Pool Report"); break; case kHIDUsage_PID_RAM_PoolSize: sprintf (cstrName, "RAM Pool Size"); break; case kHIDUsage_PID_ROM_PoolSize: sprintf (cstrName, "ROM Pool Size"); break; case kHIDUsage_PID_ROM_EffectBlockCount: sprintf (cstrName, "ROM Effect Block Count"); break; case kHIDUsage_PID_SimultaneousEffectsMax: sprintf (cstrName, "Simultaneous Effects Max"); break; case kHIDUsage_PID_PoolAlignment: sprintf (cstrName, "Pool Alignment"); break; case kHIDUsage_PID_PoolMoveReport: sprintf (cstrName, "PID Pool Move Report"); break; case kHIDUsage_PID_MoveSource: sprintf (cstrName, "Move Source"); break; case kHIDUsage_PID_MoveDestination: sprintf (cstrName, "Move Destination"); break; case kHIDUsage_PID_MoveLength: sprintf (cstrName, "Move Length"); break; case kHIDUsage_PID_BlockLoadReport: sprintf (cstrName, "PID Block Load Report"); break; case kHIDUsage_PID_BlockLoadStatus: sprintf (cstrName, "Block Load Status"); break; case kHIDUsage_PID_BlockLoadSuccess: sprintf (cstrName, "Block Load Success"); break; case kHIDUsage_PID_BlockLoadFull: sprintf (cstrName, "Block Load Full"); break; case kHIDUsage_PID_BlockLoadError: sprintf (cstrName, "Block Load Error"); break; case kHIDUsage_PID_BlockHandle: sprintf (cstrName, "Block Handle"); break; case kHIDUsage_PID_BlockFreeReport: sprintf (cstrName, "PID Block Free Report"); break; case kHIDUsage_PID_TypeSpecificBlockHandle: sprintf (cstrName, "Type Specific Block Handle"); break; case kHIDUsage_PID_StateReport: sprintf (cstrName, "PID State Report"); break; case kHIDUsage_PID_EffectPlaying: sprintf (cstrName, "Effect Playing"); break; case kHIDUsage_PID_DeviceControlReport: sprintf (cstrName, "PID Device Control Report"); break; case kHIDUsage_PID_DeviceControl: sprintf (cstrName, "PID Device Control"); break; case kHIDUsage_PID_DC_EnableActuators: sprintf (cstrName, "Device Control Enable Actuators"); break; case kHIDUsage_PID_DC_DisableActuators: sprintf (cstrName, "Device Control Disable Actuators"); break; case kHIDUsage_PID_DC_StopAllEffects: sprintf (cstrName, "Device Control Stop All Effects"); break; case kHIDUsage_PID_DC_DeviceReset: sprintf (cstrName, "Device Control Reset"); break; case kHIDUsage_PID_DC_DevicePause: sprintf (cstrName, "Device Control Pause"); break; case kHIDUsage_PID_DC_DeviceContinue: sprintf (cstrName, "Device Control Continue"); break; case kHIDUsage_PID_DevicePaused: sprintf (cstrName, "Device Paused"); break; case kHIDUsage_PID_ActuatorsEnabled: sprintf (cstrName, "Actuators Enabled"); break; case kHIDUsage_PID_SafetySwitch: sprintf (cstrName, "Safety Switch"); break; case kHIDUsage_PID_ActuatorOverrideSwitch: sprintf (cstrName, "Actuator Override Switch"); break; case kHIDUsage_PID_ActuatorPower: sprintf (cstrName, "Actuator Power"); break; case kHIDUsage_PID_StartDelay: sprintf (cstrName, "Start Delay"); break; case kHIDUsage_PID_ParameterBlockSize: sprintf (cstrName, "Parameter Block Size"); break; case kHIDUsage_PID_DeviceManagedPool: sprintf (cstrName, "Device Managed Pool"); break; case kHIDUsage_PID_SharedParameterBlocks: sprintf (cstrName, "Shared Parameter Blocks"); break; case kHIDUsage_PID_CreateNewEffectReport: sprintf (cstrName, "Create New Effect Report"); break; case kHIDUsage_PID_RAM_PoolAvailable: sprintf (cstrName, "RAM Pool Available"); break; default: sprintf (cstrName, "PID Usage 0x%lx", valueUsage); break; } break; case kHIDPage_Unicode: switch (valueUsage) { default: sprintf (cstrName, "Unicode Usage 0x%lx", valueUsage); break; } break; case kHIDPage_PowerDevice: if (((valueUsage >= 0x06) && (valueUsage <= 0x0F)) || ((valueUsage >= 0x26) && (valueUsage <= 0x2F)) || ((valueUsage >= 0x39) && (valueUsage <= 0x3F)) || ((valueUsage >= 0x48) && (valueUsage <= 0x4F)) || ((valueUsage >= 0x58) && (valueUsage <= 0x5F)) || (valueUsage == 0x6A) || ((valueUsage >= 0x74) && (valueUsage <= 0xFC))) sprintf (cstrName, "Power Device Reserved"); else switch (valueUsage) { case kHIDUsage_PD_Undefined: sprintf (cstrName, "Power Device Undefined Usage"); break; case kHIDUsage_PD_iName: sprintf (cstrName, "Power Device Name Index"); break; case kHIDUsage_PD_PresentStatus: sprintf (cstrName, "Power Device Present Status"); break; case kHIDUsage_PD_ChangedStatus: sprintf (cstrName, "Power Device Changed Status"); break; case kHIDUsage_PD_UPS: sprintf (cstrName, "Uninterruptible Power Supply"); break; case kHIDUsage_PD_PowerSupply: sprintf (cstrName, "Power Supply"); break; case kHIDUsage_PD_BatterySystem: sprintf (cstrName, "Battery System Power Module"); break; case kHIDUsage_PD_BatterySystemID: sprintf (cstrName, "Battery System ID"); break; case kHIDUsage_PD_Battery: sprintf (cstrName, "Battery"); break; case kHIDUsage_PD_BatteryID: sprintf (cstrName, "Battery ID"); break; case kHIDUsage_PD_Charger: sprintf (cstrName, "Charger"); break; case kHIDUsage_PD_ChargerID: sprintf (cstrName, "Charger ID"); break; case kHIDUsage_PD_PowerConverter: sprintf (cstrName, "Power Converter Power Module"); break; case kHIDUsage_PD_PowerConverterID: sprintf (cstrName, "Power Converter ID"); break; case kHIDUsage_PD_OutletSystem: sprintf (cstrName, "Outlet System power module"); break; case kHIDUsage_PD_OutletSystemID: sprintf (cstrName, "Outlet System ID"); break; case kHIDUsage_PD_Input: sprintf (cstrName, "Power Device Input"); break; case kHIDUsage_PD_InputID: sprintf (cstrName, "Power Device Input ID"); break; case kHIDUsage_PD_Output: sprintf (cstrName, "Power Device Output"); break; case kHIDUsage_PD_OutputID: sprintf (cstrName, "Power Device Output ID"); break; case kHIDUsage_PD_Flow: sprintf (cstrName, "Power Device Flow"); break; case kHIDUsage_PD_FlowID: sprintf (cstrName, "Power Device Flow ID"); break; case kHIDUsage_PD_Outlet: sprintf (cstrName, "Power Device Outlet"); break; case kHIDUsage_PD_OutletID: sprintf (cstrName, "Power Device Outlet ID"); break; case kHIDUsage_PD_Gang: sprintf (cstrName, "Power Device Gang"); break; case kHIDUsage_PD_GangID: sprintf (cstrName, "Power Device Gang ID"); break; case kHIDUsage_PD_PowerSummary: sprintf (cstrName, "Power Device Power Summary"); break; case kHIDUsage_PD_PowerSummaryID: sprintf (cstrName, "Power Device Power Summary ID"); break; case kHIDUsage_PD_Voltage: sprintf (cstrName, "Power Device Voltage"); break; case kHIDUsage_PD_Current: sprintf (cstrName, "Power Device Current"); break; case kHIDUsage_PD_Frequency: sprintf (cstrName, "Power Device Frequency"); break; case kHIDUsage_PD_ApparentPower: sprintf (cstrName, "Power Device Apparent Power"); break; case kHIDUsage_PD_ActivePower: sprintf (cstrName, "Power Device RMS Power"); break; case kHIDUsage_PD_PercentLoad: sprintf (cstrName, "Power Device Percent Load"); break; case kHIDUsage_PD_Temperature: sprintf (cstrName, "Power Device Temperature"); break; case kHIDUsage_PD_Humidity: sprintf (cstrName, "Power Device Humidity"); break; case kHIDUsage_PD_BadCount: sprintf (cstrName, "Power Device Bad Condition Count"); break; case kHIDUsage_PD_ConfigVoltage: sprintf (cstrName, "Power Device Nominal Voltage"); break; case kHIDUsage_PD_ConfigCurrent: sprintf (cstrName, "Power Device Nominal Current"); break; case kHIDUsage_PD_ConfigFrequency: sprintf (cstrName, "Power Device Nominal Frequency"); break; case kHIDUsage_PD_ConfigApparentPower: sprintf (cstrName, "Power Device Nominal Apparent Power"); break; case kHIDUsage_PD_ConfigActivePower: sprintf (cstrName, "Power Device Nominal RMS Power"); break; case kHIDUsage_PD_ConfigPercentLoad: sprintf (cstrName, "Power Device Nominal Percent Load"); break; case kHIDUsage_PD_ConfigTemperature: sprintf (cstrName, "Power Device Nominal Temperature"); break; case kHIDUsage_PD_ConfigHumidity: sprintf (cstrName, "Power Device Nominal Humidity"); break; case kHIDUsage_PD_SwitchOnControl: sprintf (cstrName, "Power Device Switch On Control"); break; case kHIDUsage_PD_SwitchOffControl: sprintf (cstrName, "Power Device Switch Off Control"); break; case kHIDUsage_PD_ToggleControl: sprintf (cstrName, "Power Device Toogle Sequence Control"); break; case kHIDUsage_PD_LowVoltageTransfer: sprintf (cstrName, "Power Device Min Transfer Voltage"); break; case kHIDUsage_PD_HighVoltageTransfer: sprintf (cstrName, "Power Device Max Transfer Voltage"); break; case kHIDUsage_PD_DelayBeforeReboot: sprintf (cstrName, "Power Device Delay Before Reboot"); break; case kHIDUsage_PD_DelayBeforeStartup: sprintf (cstrName, "Power Device Delay Before Startup"); break; case kHIDUsage_PD_DelayBeforeShutdown: sprintf (cstrName, "Power Device Delay Before Shutdown"); break; case kHIDUsage_PD_Test: sprintf (cstrName, "Power Device Test Request/Result"); break; case kHIDUsage_PD_ModuleReset: sprintf (cstrName, "Power Device Reset Request/Result"); break; case kHIDUsage_PD_AudibleAlarmControl: sprintf (cstrName, "Power Device Audible Alarm Control"); break; case kHIDUsage_PD_Present: sprintf (cstrName, "Power Device Present"); break; case kHIDUsage_PD_Good: sprintf (cstrName, "Power Device Good"); break; case kHIDUsage_PD_InternalFailure: sprintf (cstrName, "Power Device Internal Failure"); break; case kHIDUsage_PD_VoltageOutOfRange: sprintf (cstrName, "Power Device Voltage Out Of Range"); break; case kHIDUsage_PD_FrequencyOutOfRange: sprintf (cstrName, "Power Device Frequency Out Of Range"); break; case kHIDUsage_PD_Overload: sprintf (cstrName, "Power Device Overload"); break; case kHIDUsage_PD_OverCharged: sprintf (cstrName, "Power Device Over Charged"); break; case kHIDUsage_PD_OverTemperature: sprintf (cstrName, "Power Device Over Temperature"); break; case kHIDUsage_PD_ShutdownRequested: sprintf (cstrName, "Power Device Shutdown Requested"); break; case kHIDUsage_PD_ShutdownImminent: sprintf (cstrName, "Power Device Shutdown Imminent"); break; case kHIDUsage_PD_SwitchOnOff: sprintf (cstrName, "Power Device On/Off Switch Status"); break; case kHIDUsage_PD_Switchable: sprintf (cstrName, "Power Device Switchable"); break; case kHIDUsage_PD_Used: sprintf (cstrName, "Power Device Used"); break; case kHIDUsage_PD_Boost: sprintf (cstrName, "Power Device Boosted"); break; case kHIDUsage_PD_Buck: sprintf (cstrName, "Power Device Bucked"); break; case kHIDUsage_PD_Initialized: sprintf (cstrName, "Power Device Initialized"); break; case kHIDUsage_PD_Tested: sprintf (cstrName, "Power Device Tested"); break; case kHIDUsage_PD_AwaitingPower: sprintf (cstrName, "Power Device Awaiting Power"); break; case kHIDUsage_PD_CommunicationLost: sprintf (cstrName, "Power Device Communication Lost"); break; case kHIDUsage_PD_iManufacturer: sprintf (cstrName, "Power Device Manufacturer String Index"); break; case kHIDUsage_PD_iProduct: sprintf (cstrName, "Power Device Product String Index"); break; case kHIDUsage_PD_iserialNumber: sprintf (cstrName, "Power Device Serial Number String Index"); break; default: sprintf (cstrName, "Power Device Usage 0x%lx", valueUsage); break; } break; case kHIDPage_BatterySystem: if (((valueUsage >= 0x0A) && (valueUsage <= 0x0F)) || ((valueUsage >= 0x1E) && (valueUsage <= 0x27)) || ((valueUsage >= 0x30) && (valueUsage <= 0x3F)) || ((valueUsage >= 0x4C) && (valueUsage <= 0x5F)) || ((valueUsage >= 0x6C) && (valueUsage <= 0x7F)) || ((valueUsage >= 0x90) && (valueUsage <= 0xBF)) || ((valueUsage >= 0xC3) && (valueUsage <= 0xCF)) || ((valueUsage >= 0xDD) && (valueUsage <= 0xEF)) || ((valueUsage >= 0xF2) && (valueUsage <= 0xFF))) sprintf (cstrName, "Power Device Reserved"); else switch (valueUsage) { case kHIDUsage_BS_Undefined: sprintf (cstrName, "Battery System Undefined"); break; case kHIDUsage_BS_SMBBatteryMode: sprintf (cstrName, "SMB Mode"); break; case kHIDUsage_BS_SMBBatteryStatus: sprintf (cstrName, "SMB Status"); break; case kHIDUsage_BS_SMBAlarmWarning: sprintf (cstrName, "SMB Alarm Warning"); break; case kHIDUsage_BS_SMBChargerMode: sprintf (cstrName, "SMB Charger Mode"); break; case kHIDUsage_BS_SMBChargerStatus: sprintf (cstrName, "SMB Charger Status"); break; case kHIDUsage_BS_SMBChargerSpecInfo: sprintf (cstrName, "SMB Charger Extended Status"); break; case kHIDUsage_BS_SMBSelectorState: sprintf (cstrName, "SMB Selector State"); break; case kHIDUsage_BS_SMBSelectorPresets: sprintf (cstrName, "SMB Selector Presets"); break; case kHIDUsage_BS_SMBSelectorInfo: sprintf (cstrName, "SMB Selector Info"); break; case kHIDUsage_BS_OptionalMfgFunction1: sprintf (cstrName, "Battery System Optional SMB Mfg Function 1"); break; case kHIDUsage_BS_OptionalMfgFunction2: sprintf (cstrName, "Battery System Optional SMB Mfg Function 2"); break; case kHIDUsage_BS_OptionalMfgFunction3: sprintf (cstrName, "Battery System Optional SMB Mfg Function 3"); break; case kHIDUsage_BS_OptionalMfgFunction4: sprintf (cstrName, "Battery System Optional SMB Mfg Function 4"); break; case kHIDUsage_BS_OptionalMfgFunction5: sprintf (cstrName, "Battery System Optional SMB Mfg Function 5"); break; case kHIDUsage_BS_ConnectionToSMBus: sprintf (cstrName, "Battery System Connection To System Management Bus"); break; case kHIDUsage_BS_OutputConnection: sprintf (cstrName, "Battery System Output Connection Status"); break; case kHIDUsage_BS_ChargerConnection: sprintf (cstrName, "Battery System Charger Connection"); break; case kHIDUsage_BS_BatteryInsertion: sprintf (cstrName, "Battery System Battery Insertion"); break; case kHIDUsage_BS_Usenext: sprintf (cstrName, "Battery System Use Next"); break; case kHIDUsage_BS_OKToUse: sprintf (cstrName, "Battery System OK To Use"); break; case kHIDUsage_BS_BatterySupported: sprintf (cstrName, "Battery System Battery Supported"); break; case kHIDUsage_BS_SelectorRevision: sprintf (cstrName, "Battery System Selector Revision"); break; case kHIDUsage_BS_ChargingIndicator: sprintf (cstrName, "Battery System Charging Indicator"); break; case kHIDUsage_BS_ManufacturerAccess: sprintf (cstrName, "Battery System Manufacturer Access"); break; case kHIDUsage_BS_RemainingCapacityLimit: sprintf (cstrName, "Battery System Remaining Capacity Limit"); break; case kHIDUsage_BS_RemainingTimeLimit: sprintf (cstrName, "Battery System Remaining Time Limit"); break; case kHIDUsage_BS_AtRate: sprintf (cstrName, "Battery System At Rate..."); break; case kHIDUsage_BS_CapacityMode: sprintf (cstrName, "Battery System Capacity Mode"); break; case kHIDUsage_BS_BroadcastToCharger: sprintf (cstrName, "Battery System Broadcast To Charger"); break; case kHIDUsage_BS_PrimaryBattery: sprintf (cstrName, "Battery System Primary Battery"); break; case kHIDUsage_BS_ChargeController: sprintf (cstrName, "Battery System Charge Controller"); break; case kHIDUsage_BS_TerminateCharge: sprintf (cstrName, "Battery System Terminate Charge"); break; case kHIDUsage_BS_TerminateDischarge: sprintf (cstrName, "Battery System Terminate Discharge"); break; case kHIDUsage_BS_BelowRemainingCapacityLimit: sprintf (cstrName, "Battery System Below Remaining Capacity Limit"); break; case kHIDUsage_BS_RemainingTimeLimitExpired: sprintf (cstrName, "Battery System Remaining Time Limit Expired"); break; case kHIDUsage_BS_Charging: sprintf (cstrName, "Battery System Charging"); break; case kHIDUsage_BS_Discharging: sprintf (cstrName, "Battery System Discharging"); break; case kHIDUsage_BS_FullyCharged: sprintf (cstrName, "Battery System Fully Charged"); break; case kHIDUsage_BS_FullyDischarged: sprintf (cstrName, "Battery System Fully Discharged"); break; case kHIDUsage_BS_ConditioningFlag: sprintf (cstrName, "Battery System Conditioning Flag"); break; case kHIDUsage_BS_AtRateOK: sprintf (cstrName, "Battery System At Rate OK"); break; case kHIDUsage_BS_SMBErrorCode: sprintf (cstrName, "Battery System SMB Error Code"); break; case kHIDUsage_BS_NeedReplacement: sprintf (cstrName, "Battery System Need Replacement"); break; case kHIDUsage_BS_AtRateTimeToFull: sprintf (cstrName, "Battery System At Rate Time To Full"); break; case kHIDUsage_BS_AtRateTimeToEmpty: sprintf (cstrName, "Battery System At Rate Time To Empty"); break; case kHIDUsage_BS_AverageCurrent: sprintf (cstrName, "Battery System Average Current"); break; case kHIDUsage_BS_Maxerror: sprintf (cstrName, "Battery System Max Error"); break; case kHIDUsage_BS_RelativeStateOfCharge: sprintf (cstrName, "Battery System Relative State Of Charge"); break; case kHIDUsage_BS_AbsoluteStateOfCharge: sprintf (cstrName, "Battery System Absolute State Of Charge"); break; case kHIDUsage_BS_RemainingCapacity: sprintf (cstrName, "Battery System Remaining Capacity"); break; case kHIDUsage_BS_FullChargeCapacity: sprintf (cstrName, "Battery System Full Charge Capacity"); break; case kHIDUsage_BS_RunTimeToEmpty: sprintf (cstrName, "Battery System Run Time To Empty"); break; case kHIDUsage_BS_AverageTimeToEmpty: sprintf (cstrName, "Battery System Average Time To Empty"); break; case kHIDUsage_BS_AverageTimeToFull: sprintf (cstrName, "Battery System Average Time To Full"); break; case kHIDUsage_BS_CycleCount: sprintf (cstrName, "Battery System Cycle Count"); break; case kHIDUsage_BS_BattPackModelLevel: sprintf (cstrName, "Battery System Batt Pack Model Level"); break; case kHIDUsage_BS_InternalChargeController: sprintf (cstrName, "Battery System Internal Charge Controller"); break; case kHIDUsage_BS_PrimaryBatterySupport: sprintf (cstrName, "Battery System Primary Battery Support"); break; case kHIDUsage_BS_DesignCapacity: sprintf (cstrName, "Battery System Design Capacity"); break; case kHIDUsage_BS_SpecificationInfo: sprintf (cstrName, "Battery System Specification Info"); break; case kHIDUsage_BS_ManufacturerDate: sprintf (cstrName, "Battery System Manufacturer Date"); break; case kHIDUsage_BS_SerialNumber: sprintf (cstrName, "Battery System Serial Number"); break; case kHIDUsage_BS_iManufacturerName: sprintf (cstrName, "Battery System Manufacturer Name Index"); break; case kHIDUsage_BS_iDevicename: sprintf (cstrName, "Battery System Device Name Index"); break; case kHIDUsage_BS_iDeviceChemistry: sprintf (cstrName, "Battery System Device Chemistry Index"); break; case kHIDUsage_BS_ManufacturerData: sprintf (cstrName, "Battery System Manufacturer Data"); break; case kHIDUsage_BS_Rechargable: sprintf (cstrName, "Battery System Rechargable"); break; case kHIDUsage_BS_WarningCapacityLimit: sprintf (cstrName, "Battery System Warning Capacity Limit"); break; case kHIDUsage_BS_CapacityGranularity1: sprintf (cstrName, "Battery System Capacity Granularity 1"); break; case kHIDUsage_BS_CapacityGranularity2: sprintf (cstrName, "Battery System Capacity Granularity 2"); break; case kHIDUsage_BS_iOEMInformation: sprintf (cstrName, "Battery System OEM Information Index"); break; case kHIDUsage_BS_InhibitCharge: sprintf (cstrName, "Battery System Inhibit Charge"); break; case kHIDUsage_BS_EnablePolling: sprintf (cstrName, "Battery System Enable Polling"); break; case kHIDUsage_BS_ResetToZero: sprintf (cstrName, "Battery System Reset To Zero"); break; case kHIDUsage_BS_ACPresent: sprintf (cstrName, "Battery System AC Present"); break; case kHIDUsage_BS_BatteryPresent: sprintf (cstrName, "Battery System Battery Present"); break; case kHIDUsage_BS_PowerFail: sprintf (cstrName, "Battery System Power Fail"); break; case kHIDUsage_BS_AlarmInhibited: sprintf (cstrName, "Battery System Alarm Inhibited"); break; case kHIDUsage_BS_ThermistorUnderRange: sprintf (cstrName, "Battery System Thermistor Under Range"); break; case kHIDUsage_BS_ThermistorHot: sprintf (cstrName, "Battery System Thermistor Hot"); break; case kHIDUsage_BS_ThermistorCold: sprintf (cstrName, "Battery System Thermistor Cold"); break; case kHIDUsage_BS_ThermistorOverRange: sprintf (cstrName, "Battery System Thermistor Over Range"); break; case kHIDUsage_BS_VoltageOutOfRange: sprintf (cstrName, "Battery System Voltage Out Of Range"); break; case kHIDUsage_BS_CurrentOutOfRange: sprintf (cstrName, "Battery System Current Out Of Range"); break; case kHIDUsage_BS_CurrentNotRegulated: sprintf (cstrName, "Battery System Current Not Regulated"); break; case kHIDUsage_BS_VoltageNotRegulated: sprintf (cstrName, "Battery System Voltage Not Regulated"); break; case kHIDUsage_BS_MasterMode: sprintf (cstrName, "Battery System Master Mode"); break; case kHIDUsage_BS_ChargerSelectorSupport: sprintf (cstrName, "Battery System Charger Support Selector"); break; case kHIDUsage_BS_ChargerSpec: sprintf (cstrName, "attery System Charger Specification"); break; case kHIDUsage_BS_Level2: sprintf (cstrName, "Battery System Charger Level 2"); break; case kHIDUsage_BS_Level3: sprintf (cstrName, "Battery System Charger Level 3"); break; default: sprintf (cstrName, "Battery System Usage 0x%lx", valueUsage); break; } break; case kHIDPage_AlphanumericDisplay: switch (valueUsage) { default: sprintf (cstrName, "Alphanumeric Display Usage 0x%lx", valueUsage); break; } break; case kHIDPage_BarCodeScanner: switch (valueUsage) { default: sprintf (cstrName, "Bar Code Scanner Usage 0x%lx", valueUsage); break; } break; case kHIDPage_Scale: switch (valueUsage) { default: sprintf (cstrName, "Scale Usage 0x%lx", valueUsage); break; } break; case kHIDPage_CameraControl: switch (valueUsage) { default: sprintf (cstrName, "Camera Control Usage 0x%lx", valueUsage); break; } break; case kHIDPage_Arcade: switch (valueUsage) { default: sprintf (cstrName, "Arcade Usage 0x%lx", valueUsage); break; } break; default: if (valueUsagePage > kHIDPage_VendorDefinedStart) sprintf (cstrName, "Vendor Defined Usage 0x%lx", valueUsage); else sprintf (cstrName, "Page: 0x%lx, Usage: 0x%lx", valueUsagePage, valueUsage); break; } } // --------------------------------- // returns calibrated value given raw value passed in // calibrated value is equal to min and max values returned by HIDGetElementValue since device list built scaled to element reported min and max values /* SInt32 HIDCalibrateValue (SInt32 value, pRecElement pElement) { if (NULL != pElement) { float deviceScale = pElement->max - pElement->min; float readScale = pElement->calMax - pElement->calMin; if (readScale == 0) return value; // no scaling as else return ((value - pElement->calMin) * deviceScale / readScale) + pElement->min; } else return 0; // bad element passed in } */ // --------------------------------- // returns scaled value given raw value passed in // scaled value is equal to current value assumed to be in the range of element reported min and max values scaled to user min and max scaled values SInt32 HIDScaleValue (SInt32 value, pRecElement pElement) { float deviceScale = pElement->userMax - pElement->userMin; float readScale = pElement->max - pElement->min; if (readScale == 0) return value; else return (value - pElement->min) * deviceScale / readScale + pElement->userMin; } // --------------------------------- // convert an element type to a mask HIDElementTypeMask HIDConvertElementTypeToMask (const long type) { HIDElementTypeMask result = kHIDElementTypeAll; switch (type) { case kIOHIDElementTypeInput_Misc: case kIOHIDElementTypeInput_Button: case kIOHIDElementTypeInput_Axis: case kIOHIDElementTypeInput_ScanCodes: result = kHIDElementTypeInput; break; case kIOHIDElementTypeOutput: result = kHIDElementTypeOutput; break; case kIOHIDElementTypeFeature: result = kHIDElementTypeFeature; break; case kIOHIDElementTypeCollection: result = kHIDElementTypeCollection; break; default: result = kHIDElementTypeAll; break; } return result; } Boolean HIDFindDevice(const pRecDevice pSearchDevice, pRecDevice *ppFoundDevice) { pRecDevice pDevice, pBestDevice = NULL; long bestScore = 0; // iterate over all devices pDevice = HIDGetFirstDevice(); while (pDevice) { long deviceScore = 1; if (pSearchDevice->vendorID && (pSearchDevice->vendorID == pDevice->vendorID)) { deviceScore += 10; if (pSearchDevice->productID && (pSearchDevice->productID == pDevice->productID)) deviceScore += 8; } if ((pSearchDevice->usagePage && (pSearchDevice->usagePage == pDevice->usagePage)) && (pSearchDevice->usage && (pSearchDevice->usage == pDevice->usage))) deviceScore += 9; if (pSearchDevice->locID && (pSearchDevice->locID == pDevice->locID)) deviceScore += 5; if (deviceScore > bestScore) { pBestDevice = pDevice; bestScore = deviceScore; #if 0 // set true to output scoring informaton printf("\n-HIDFindDevice(%ld:%ld)-I-Debug, better score: %ld.",pSearchElement->usagePage, pSearchElement->usage, score); HIDPrintElement(pBestElement); #endif } pDevice = HIDGetNextDevice(pDevice); } if (NULL != pBestDevice) { *ppFoundDevice = pBestDevice; #if 0 // set true to output scoring informaton printf("\n-HIDFindDevice(%ld:%ld)-I-Debug, best score: %ld.",pSearchElement->usagePage, pSearchElement->usage, bestScore); HIDPrintElement(pBestElement); printf("\n"); #endif return true; } else return false; } // --------------------------------- // find the device and element for this action // Device: serial, vendorID, productID, location, usagePage, usage // Element: cookie, usagePage, usage, Boolean HIDFindActionDeviceAndElement(const pRecDevice pSearchDevice, const pRecElement pSearchElement, pRecDevice *ppFoundDevice, pRecElement *ppFoundElement) { pRecDevice pDevice, pBestDevice = NULL; pRecElement pElement, pBestElement = NULL; HIDElementTypeMask hidMask = HIDConvertElementTypeToMask (pSearchElement->type); long bestScore = 0; // iterate over all devices pDevice = HIDGetFirstDevice(); while (pDevice) { long deviceScore = 1; if (pSearchDevice->vendorID && (pSearchDevice->vendorID == pDevice->vendorID)) { deviceScore += 10; if (pSearchDevice->productID && (pSearchDevice->productID == pDevice->productID)) deviceScore += 8; } if ((pSearchDevice->usagePage && (pSearchDevice->usagePage == pDevice->usagePage)) && (pSearchDevice->usage && (pSearchDevice->usage == pDevice->usage))) deviceScore += 9; if (pSearchDevice->locID && (pSearchDevice->locID == pDevice->locID)) deviceScore += 5; // iterate over all elements of this device pElement = HIDGetFirstDeviceElement(pDevice, hidMask); while (pElement) { long score = deviceScore; if ((pSearchElement->usagePage && (pSearchElement->usagePage == pElement->usagePage)) && (pSearchElement->usage && (pSearchElement->usage == pElement->usage))) { score += 5; if (pSearchElement->cookie && (pSearchElement->cookie == pElement->cookie)) score += 4; } else score = 0; #if 0 // set true to output scoring informaton if (kHIDPage_KeyboardOrKeypad != pElement->usagePage) // skip keyboards here { printf("\n-HIDFindActionDeviceAndElement(%ld:%ld)-I-Debug, score: %ld.",pSearchElement->usagePage, pSearchElement->usage, score); HIDPrintElement(pElement); } #endif if (score > bestScore) { pBestDevice = pDevice; pBestElement = pElement; bestScore = score; #if 0 // set true to output scoring informaton printf("\n-HIDFindActionDeviceAndElement(%ld:%ld)-I-Debug, better score: %ld.",pSearchElement->usagePage, pSearchElement->usage, score); HIDPrintElement(pBestElement); #endif } pElement = HIDGetNextDeviceElement(pElement, hidMask); } pDevice = HIDGetNextDevice(pDevice); } if ((NULL != pBestDevice) || (NULL != pBestElement)) { *ppFoundDevice = pBestDevice; *ppFoundElement = pBestElement; #if 0 // set true to output scoring informaton printf("\n-HIDFindActionDeviceAndElement(%ld:%ld)-I-Debug, best score: %ld.",pSearchElement->usagePage, pSearchElement->usage, bestScore); HIDPrintElement(pBestElement); printf("\n"); #endif return true; } else return false; } // --------------------------------- // find the device and element for this action // Device: serial, vendorID, productID, location, usagePage, usage // Element: cookie, usagePage, usage, Boolean HIDFindSubElement(const pRecElement pStartElement, const pRecElement pSearchElement, pRecElement *ppFoundElement) { pRecElement pElement, pBestElement = NULL; HIDElementTypeMask hidMask = HIDConvertElementTypeToMask (pSearchElement->type); long bestScore = 0; if ((NULL == pStartElement) || (NULL == pSearchElement) || (NULL == ppFoundElement)) return false; // iterate over all children of this element pElement = pStartElement->pChild; while (pElement) { long score = 0; #if 0 // set true to output searching informaton printf("\n-HIDFindSubElement, search = {t:%.2lX, u:%.4lX:%.4lX}, match = {t:%.2lX, u:%.4lX:%.4lX, s:\"%s\"}", pSearchElement->type, pSearchElement->usagePage, pSearchElement->usage, pElement->type, pElement->usagePage, pElement->usage, pElement->name); fflush(stdout); #endif if ((pSearchElement->usagePage && (pSearchElement->usagePage == pElement->usagePage)) && (pSearchElement->usage && (pSearchElement->usage == pElement->usage))) { score += 4; if (pSearchElement->cookie && (pSearchElement->cookie == pElement->cookie)) score += 5; } #if 0 // set true to output searching informaton if (kHIDPage_KeyboardOrKeypad != pElement->usagePage) // skip keyboards here { printf("\n-HIDFindSubElement(%ld:%ld)-I-Debug, score: %ld.",pSearchElement->usagePage, pSearchElement->usage, score); HIDPrintElement(pElement); } #endif if (score > bestScore) { pBestElement = pElement; bestScore = score; #if 0 // set true to output searching informaton printf("\n-HIDFindSubElement(%ld:%ld)-I-Debug, better score: %ld.",pSearchElement->usagePage, pSearchElement->usage, score); HIDPrintElement(pBestElement); #endif } pElement = HIDGetNextDeviceElement(pElement, hidMask); } #if 0 // set true to output searching informaton if (pBestElement) { printf("\n-HIDFindSubElement(%ld:%ld)-I-Debug, best score: %ld.",pSearchElement->usagePage, pSearchElement->usage, bestScore); HIDPrintElement(pBestElement); printf("\n"); } #endif *ppFoundElement = pBestElement; return (NULL != pBestElement); } // print out all of an elements information int HIDPrintElement(const pRecElement pElement) { int results; int count; printf("\n"); if (gDepth != pElement->depth) printf("%d",gDepth); for (count = 0;count < pElement->depth;count++) printf(" | "); #if 0 // this is verbose results = printf("-HIDPrintElement = {name: \"%s\", t: 0x%.2lX, u:%ld:%ld, c: %ld, min/max: %ld/%ld, scaled: %ld/%ld, size: %ld, rel: %s, wrap: %s, nonLinear: %s, preferred: %s, nullState: %s, units: %ld, exp: %ld, cal: %ld/%ld, user: %ld/%ld, depth: %ld}.", pElement->name, // name of element (c string) pElement->type, // the type defined by IOHIDElementType in IOHIDKeys.h pElement->usagePage, // usage page from IOUSBHIDParser.h which defines general usage pElement->usage, // usage within above page from IOUSBHIDParser.h which defines specific usage (long) pElement->cookie, // unique value (within device of specific vendorID and productID) which identifies element, will NOT change pElement->min, // reported min value possible pElement->max, // reported max value possible pElement->scaledMin, // reported scaled min value possible pElement->scaledMax, // reported scaled max value possible pElement->size, // size in bits of data return from element pElement->relative ? "YES" : "NO", // are reports relative to last report (deltas) pElement->wrapping ? "YES" : "NO", // does element wrap around (one value higher than max is min) pElement->nonLinear ? "YES" : "NO", // are the values reported non-linear relative to element movement pElement->preferredState ? "YES" : "NO",// does element have a preferred state (such as a button) pElement->nullState ? "YES" : "NO", // does element have null state pElement->units, // units value is reported in (not used very often) pElement->unitExp, // exponent for units (also not used very often) pElement->calMin, // min returned value (for calibrate call) pElement->calMax, // max returned value pElement->userMin, // user set min to scale to (for scale call) pElement->userMax, // user set max pElement->depth ); #else // this is brief results = printf("-HIDPrintElement = {t: 0x%lX, u:%ld:%ld, c: %ld, name: \"%s\", d: %ld}.", pElement->type, // the type defined by IOHIDElementType in IOHIDKeys.h pElement->usagePage, // usage page from IOUSBHIDParser.h which defines general usage pElement->usage, // usage within above page from IOUSBHIDParser.h which defines specific usage (long) pElement->cookie, // unique value (within device of specific vendorID and productID) which identifies element, will NOT change pElement->name, // name of element (c string) pElement->depth ); #endif fflush(stdout); return results; } // return true if this is a valid device pointer Boolean HIDIsValidDevice(const pRecDevice pSearchDevice) { pRecDevice pDevice = gpDeviceList; while (pDevice) { if (pDevice == pSearchDevice) return true; pDevice = pDevice->pNext; } return false; } // return true if this is a valid element pointer for this device Boolean HIDIsValidElement(const pRecDevice pSearchDevice, const pRecElement pSearchElement) { if (HIDIsValidDevice(pSearchDevice)) { pRecElement pRecElementTemp = HIDGetFirstDeviceElement(pSearchDevice,kHIDElementTypeAll); while (pRecElementTemp) { if (pRecElementTemp == pSearchElement) return true; pRecElementTemp = HIDGetNextDeviceElement(pRecElementTemp,kHIDElementTypeAll); } } return false; } pd-hid_0.7/HID Utilities Source/HID Utilities Read Me.rtf0000644000076500007650000004545411504504627021321 0ustar hanshans{\rtf1\mac\ansicpg10000\cocoartf102 {\fonttbl\f0\fswiss\fcharset77 Helvetica;} {\colortbl;\red255\green255\blue255;} \vieww17000\viewh11120\viewkind0 \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural \f0\fs22 \cf0 HID Utilities Source\ Human Interface Device Manager Utility Functions\ \ Version 3.7 28 Oct 2K2\ General cleanup for web posting.\ \ Version 3.6 23 Oct 2K2\ Added new API's: HIDSetElementValue, HIDSetQueueCallback, HIDGetReport, HIDSetReport & HIDPrintElement,\ Note: & have been incorporated into .\ \ Version 3.5 10 Aug 2K2\ HIDConfigureAction now only checks kHIDElementTypeInput elements.\ Changed some "for (x=0;x)\ \ Version 3.3 Added output transaction support for UPS & FFB devices (see & ).\ \ Version 3.2 Since 10.2 changed the cookie numbers (by adding a usage == -1element for arrays) a cookie agnostic method of getting\ device and element names was needed. Plus the nested (device & element) switch statements hardcoding the strings.\ So all the device, element & cookie strings have been moved out of the source file(s) and put into XML data files instead.\ NOTE: all local (static) routines now begin with "hid_" instead of "HID".\ All references to "Kernel/IOKit/hidsystem/" now (correctly) point to "IOKit/hid/" instead.\ \ Version 3.1: Added the basics of a element naming scheme. Right now it just supports one device (macally iShock) but as I get more \ device info I can add other devices (feel free to add to the name lookup file and send me the results). Added bad device \ and element chencking in config/save. Fixed one case of swapped usage page and usage variables. Fixed a few leaks \ noted by a developer. Add a NULL check to top level element handler to prevent NULL deference also noted by developer. \ Checked build with gcc3. Rebuilt bundle and static lib.\ \ Version 3.0: Major Change: Added CFM support.\ Project now can be built in three different ways with the interface being straight C with Mac OS X type reliance, thus completely\ suitable for CFM or MachO binary formats and Carbon, Cocoa, or command line interfaces.\ \ - Static Library: For use with Mac OS X MachO projects. The build product (in the build directory) can be static linked\ into any exisiting Mac OS X MachO project. The project should include HID_Utilities_External.h only for declarations.\ \ - Source: This is just including the HID Utilities source files in the target project. Works as previous, but now all the \ declarations needed are in the HID_Utilities_External.h header file.\ \ - Dynamic Library: Should only be used by CFM applications. There are some notes which MUST be followed. See the HID Explorer\ or the HID Config Save samples for CW7 projects which show the actual use of the library. The dylib is housed in a bundle\ which the CFM app finds at runtime and calls into. This bundle is included and the dylib project will automatically place\ the actual dylib in the bundle (contents/MacOS/). NOTE: The path to this is an absolute path for the build product of the \ project, you MUST modify this if you rebuild the dylib (which never be required). To do this select the prject name in the\ Files tab and Get Info. Point the build product to the HID.bundle/contents/MacOS/ directory in the HID Utilities directory.\ Then point the intermediates to the intermediates directory already in the build directory. This is required since the build\ product path is absolute and can't be project relative (yes, a bug has been filed). Again, this is only if you wnat to rebuild\ the dylib used for CFM applications. Also note, you must copy the HID.bundle into your application directory (if you are using\ the method in the sample to find the bundle) for your CFM application to use it.\ \ Other Notes:\ The interface is now completely Mac OS X type free. This means minor mods to your projects. See the element and device structures\ for guidence on the types. For example cookies now should be void *'s. Fixed a couple bugs in allocating queues. CLean up error\ checking to only dump DebugStrs if the source is used (vice the static or dynamic libraries).\ \ Version 2.0: Update. Fixed some 10.1 issues, notably spelling errors in constants and include differences. Fixed 10.0.x errors, notably \ type errors in retrieving element info, negative value handling (see GetElementValue), queuing error, and other minor changes.\ Major change in element list handling... Elements are now stored in a binary tree to mimic the tree sturcture of the \ device. This allows hierarchial diplay and parsing (See HID Explorer sample). Additionally, some of the routine declarations \ have chnaged to work with this tree structure, one can still get same list functionality by using GetNextDeviceElement routine \ with kHIDElementTypeIO constant. Collections are now stored in tree, so users of these functions must understand if they are \ looking at a valid IO element or a collection. Lastly, new parsing strings and two new headers are included to aid in decoding \ PID and power device elements.\ \ Version 1.0: Initial release featuring functions to get HID device list, get devices and elements, poll for values, setup queues and get events, \ handle configuration set up and saving/restoring of configurations.\ \ ----\ \ This group of utilities is stand alone code to help developers work more easily with the HID Manager for Mac OS X with both MachO and CFM support. \ It provides a high level abstract of the current HID interface that sacrifices slight flexibility in favor single function set up, device and element \ retrieval, current value and event query, and configuration. This sample is the source code for the Utilities and does not provide a sample of the \ utilization. There are other samples which provide complete working examples of a HID device explorer and a simple game implementation. More samples \ will be forth coming shortly.\ \ This set of utilities is constantly evolving to both address any bugs and provide better support for developer requested features.\ Any suggestions and/or bugs can be directed to the Apple bug reporter at:\ \ \ // ==================================\ \ // Device and Element Interfaces\ \ enum HIDElementTypeMask\ \{\ kHIDElementTypeInput = 1 << 1,\ kHIDElementTypeOutput = 1 << 2,\ kHIDElementTypeFeature = 1 << 3,\ kHIDElementTypeCollection = 1 << 4,\ kHIDElementTypeIO = kHIDElementTypeInput | kHIDElementTypeOutput | kHIDElementTypeFeature,\ kHIDElementTypeAll = kHIDElementTypeIO | kHIDElementTypeCollection\ \};\ typedef enum HIDElementTypeMask HIDElementTypeMask;\ \ \ struct recElement\ \{\ unsigned long type; // the type defined by IOHIDElementType in IOHIDKeys.h\ long usagePage; // usage page from IOUSBHIDParser.h which defines general usage\ long usage; // usage within above page from IOUSBHIDParser.h which defines specific usage\ void * cookie; // unique value (within device of specific vendorID and productID) which identifies element, will NOT change\ long min; // reported min value possible\ long max; // reported max value possible\ long scaledMin; // reported scaled min value possible\ long scaledMax; // reported scaled max value possible\ long size; // size in bits of data return from element\ unsigned char relative; // are reports relative to last report (deltas)\ unsigned char wrapping; // does element wrap around (one value higher than max is min)\ unsigned char nonLinear; // are the values reported non-linear relative to element movement\ unsigned char preferredState; // does element have a preferred state (such as a button)\ unsigned char nullState; // does element have null state\ long units; // units value is reported in (not used very often)\ long unitExp; // exponent for units (also not used very often)\ char name[256]; // name of element (not used often)\ \ // runtime variables\ long minReport; // min returned value\ long maxReport; // max returned value (calibrate call)\ long userMin; // user set value to scale to (scale call)\ long userMax; \ \ struct recElement * pPrevious; // previous element (NULL at list head)\ struct recElement * pChild; // next child (only of collections)\ struct recElement * pSibling; // next sibling (for elements and collections)\ \ \};\ typedef struct recElement recElement;\ typedef recElement* pRecElement;\ \ struct recDevice\ \{\ void * interface; // interface to device, NULL = no interface\ void * queue; // device queue, NULL = no queue\ char transport[256]; // device transport\ long vendorID; // id for device vendor, unique across all devices\ long productID; // id for particular product, unique across all of a vendors devices\ long version; // version of product\ char manufacturer[256]; // name of manufacturer\ char product[256]; // name of product\ char serial[256]; // serial number of specific product, can be assumed unique across specific product or specific vendor (not used often)\ long locID; // long representing location in USB (or other I/O) chain which device is pluged into, can identify specific device on machine\ long usage; // usage page from IOUSBHID Parser.h which defines general usage\ long usagePage; // usage within above page from IOUSBHID Parser.h which defines specific usage\ long totalElements; // number of total elements (should be total of all elements on device including collections) (calculated, not reported by device)\ long features; // number of elements of type kIOHIDElementTypeFeature\ long inputs; // number of elements of type kIOHIDElementTypeInput_Misc or kIOHIDElementTypeInput_Button or kIOHIDElementTypeInput_Axis or kIOHIDElementTypeInput_ScanCodes\ long outputs; // number of elements of type kIOHIDElementTypeOutput\ long collections; // number of elements of type kIOHIDElementTypeCollection\ long axis; // number of axis (calculated, not reported by device)\ long buttons; // number of buttons (calculated, not reported by device)\ long hats; // number of hat switches (calculated, not reported by device)\ long sliders; // number of sliders (calculated, not reported by device)\ long dials; // number of dials (calculated, not reported by device)\ long wheels; // number of wheels (calculated, not reported by device)\ recElement* pListElements; // head of linked list of elements \ struct recDevice* pNext; // next device\ \};\ typedef struct recDevice recDevice;\ typedef recDevice* pRecDevice;\ \ // ==================================\ \ // builds list of device with elements (allocates memory and captures devices)\ // list is allcoated internally within HID Utilites and can be accessed via accessor functions\ // structures within list are considered flat and user accessable, butnot user modifiable\ // can be called again to rebuild list to account for new devices (will do the right thing in case of disposing existing list)\ unsigned char HIDBuildDeviceList (unsigned long usagePage, unsigned long usage);\ \ // release list built by above function\ // MUST be called prior to application exit to properly release devices\ // if not called (or app crashes) devices can be recovered by pluging into different location in USB chain\ void HIDReleaseDeviceList (void);\ \ // does a device list exist\ unsigned char HIDHaveDeviceList (void);\ \ // how many HID devices have been found\ // returns 0 if no device list exist\ unsigned long HIDCountDevices (void);\ \ // how many elements does a specific device have\ // returns 0 if device is invalid or NULL\ // uses mask of HIDElementTypeMask to restrict element found\ // use kHIDElementTypeIO to get non-collection elements\ unsigned long HIDCountDeviceElements (pRecDevice pDevice, HIDElementTypeMask typeMask);\ \ // get the first device in the device list\ // returns NULL if no list exists\ pRecDevice HIDGetFirstDevice (void);\ \ // get next device in list given current device as parameter\ // returns NULL if end of list\ pRecDevice HIDGetNextDevice (pRecDevice pDevice);\ \ // get the first element of device passed in as parameter\ // returns NULL if no list exists or device does not exists or is NULL\ // uses mask of HIDElementTypeMask to restrict element found\ // use kHIDElementTypeIO to get previous HIDGetFirstDeviceElement functionality\ pRecElement HIDGetFirstDeviceElement (pRecDevice pDevice, HIDElementTypeMask typeMask);\ \ // get next element of given device in list given current element as parameter\ // will walk down each collection then to next element or collection (depthwise traverse)\ // returns NULL if end of list\ // uses mask of HIDElementTypeMask to restrict element found\ // use kHIDElementTypeIO to get previous HIDGetNextDeviceElement functionality\ pRecElement HIDGetNextDeviceElement (pRecElement pElement, HIDElementTypeMask typeMask);\ \ // get previous element of given device in list given current element as parameter\ // this wlaks directly up the tree to the top element and does not search at each level\ // returns NULL if beginning of list\ // uses mask of HIDElementTypeMask to restrict element found\ // use kHIDElementTypeIO to get non-collection elements\ pRecElement HIDGetPreviousDeviceElement (pRecElement pElement, HIDElementTypeMask typeMask);\ \ // returns C string type name given a type enumeration passed in as parameter (see IOHIDKeys.h)\ // returns empty string for invlid types\ void HIDGetTypeName (unsigned long type, char * cstrName);\ \ // returns C string usage given usage page and usage passed in as parameters (see IOUSBHIDParser.h)\ // returns usage page and usage values in string form for unknown values\ void HIDGetUsageName (long valueUsagePage, long valueUsage, char * cstrName);\ \ // ==================================\ \ // Element Event Queue and Value Interfaces\ \ enum\ \{\ kDefaultUserMin = 0, // default user min and max used for scaling\ kDefaultUserMax = 255\ \};\ \ enum\ \{\ kDeviceQueueSize = 50 // this is wired kernel memory so should be set to as small as possible\ // but should account for the maximum possible events in the queue\ // USB updates will likely occur at 100 Hz so one must account for this rate of\ // if states change quickly (updates are only posted on state changes)\ \};\ \ // ==================================\ \ // queues specific element, performing any device queue set up required\ unsigned long HIDQueueElement (pRecDevice pDevice, pRecElement pElement);\ \ // adds all elements to queue, performing any device queue set up required\ unsigned long HIDQueueDevice (pRecDevice pDevice);\ \ // removes element for queue, if last element in queue will release queue and device\ unsigned long HIDDequeueElement (pRecDevice pDevice, pRecElement pElement);\ \ // completely removes all elements from queue and releases queue and device\ unsigned long HIDDequeueDevice (pRecDevice pDevice);\ \ // returns true if an event is avialable for the element and fills out *pHIDEvent structure, returns false otherwise\ // pHIDEvent is a poiner to a IOHIDEventStruct, using void here for compatibility, users can cast a required\ unsigned char HIDGetEvent (pRecDevice pDevice, void * pHIDEvent);\ \ // returns current value for element, creating device interface as required, polling element\ // Note: this DOES NOT release the inteface so applications must properly release devices via ReleaseHIDDeviceList\ long HIDGetElementValue (pRecDevice pDevice, pRecElement pElement);\ \ // returns calibrated value given raw value passed in\ // calibrated value is equal to min and max values returned by HIDGetElementValue since device list built scaled to element reported min and max values\ long HIDCalibrateValue (long value, pRecElement pElement);\ \ // returns scaled value given raw value passed in\ // scaled value is equal to current value assumed to be in the range of element reported min and max values scaled to user min and max scaled values\ long HIDScaleValue (long value, pRecElement pElement);\ \ // ==================================\ \ // Conguration and Save Interfaces\ \ enum\ \{\ kPercentMove = 10 // precent of overall range a element must move to register\ \};\ \ struct recSaveHID\ \{\ long actionCookie;\ // device\ // need to add serial number when I have a test case\ long vendorID;\ long productID;\ long locID;\ long usage;\ long usagePage;\ // elements\ long usagePageE;\ long usageE;\ void * cookie;\ \};\ typedef struct recSaveHID recSaveHID;\ typedef recSaveHID * pRecSaveHID;\ \ // polls all devices and elements for a change greater than kPercentMove. Times out after given time\ // returns true and pointer to device and element if found\ // returns false and NULL for both parameters if not found\ unsigned char HIDConfigureAction (pRecDevice * ppDevice, pRecElement * ppElement, float timeout);\ \ // take input records, save required info\ // assume file is open and at correct position.\ void HIDSaveElementConfig (FILE * fileRef, pRecDevice pDevice, pRecElement pElement, long actionCookie);\ \ // take file, read one record (assume file position is correct and file is open)\ // search for matching device\ // return pDevice, pElement and cookie for action\ long HIDRestoreElementConfig (FILE * fileRef, pRecDevice * ppDevice, pRecElement * ppElement);\ \ ----\ \ Requirements: Mac OS X, Project Builder (CodeWarrior 7 for sample CFM projects)\ \ We hope this helps people get up and running with HID Manager in a quick and painless manner.\ \ ggs}pd-hid_0.7/HID Utilities Source/PID.h0000644000076500007650000002105711504504627015644 0ustar hanshans/* File: PID.h DRI: George Warner Contains: Definition of the PID constants (NOTE: Moved into ) DRI: George Warner Copyright: Copyright © 2002 Apple Computer, Inc., All Rights Reserved Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. ("Apple") in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this Apple software constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this Apple software. In consideration of your agreement to abide by the following terms, and subject to these terms, Apple grants you a personal, non-exclusive license, under AppleÕs copyrights in this original Apple software (the "Apple Software"), to use, reproduce, modify and redistribute the Apple Software, with or without modifications, in source and/or binary forms; provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Computer, Inc. may be used to endorse or promote products derived from the Apple Software without specific prior written permission from Apple. Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by Apple herein, including but not limited to any patent rights that may be infringed by your derivative works or by other works in which the Apple Software may be incorporated. The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef __PID__ #define __PID__ #ifdef __cplusplus extern "C" { #endif #if PRAGMA_IMPORT #pragma import on #endif /* Physical Interface Device Page (0x0F) */ /* This section provides detailed descriptions of the usages employed by Digitizer Devices. */ enum { kHIDUsage_PID_PhysicalInterfaceDevice = 0x01, /* CA - A collection of PID usages */ /* 0x02 - 0x1F Reserved */ kHIDUsage_PID_Normal = 0x20, /* DV - A force applied perpendicular to the surface of an object */ kHIDUsage_PID_SetEffectReport = 0x21, /* XXX */ kHIDUsage_PID_EffectBlockIndex = 0x22, /* XXX */ kHIDUsage_PID_ParamBlockOffset = 0x23, /* XXX */ kHIDUsage_PID_ROM_Flag = 0x24, /* XXX */ kHIDUsage_PID_EffectType = 0x25, /* XXX */ kHIDUsage_PID_ET_ConstantForce = 0x26, /* XXX */ kHIDUsage_PID_ET_Ramp = 0x27, /* XXX */ kHIDUsage_PID_ET_CustomForceData = 0x28, /* XXX */ /* 0x29 - 0x2F Reserved */ kHIDUsage_PID_ET_Square = 0x30, /* XXX */ kHIDUsage_PID_ET_Sine = 0x31, /* XXX */ kHIDUsage_PID_ET_Triangle = 0x32, /* XXX */ kHIDUsage_PID_ET_SawtoothUp = 0x33, /* XXX */ kHIDUsage_PID_ET_SawtoothDown = 0x34, /* XXX */ /* 0x35 - 0x3F Reserved */ kHIDUsage_PID_ET_Spring = 0x40, /* XXX */ kHIDUsage_PID_ET_Damper = 0x41, /* XXX */ kHIDUsage_PID_ET_Inertia = 0x42, /* XXX */ kHIDUsage_PID_ET_Friction = 0x43, /* XXX */ /* 0x44 - 0x4F Reserved */ kHIDUsage_PID_Duration = 0x50, /* XXX */ kHIDUsage_PID_SamplePeriod = 0x51, /* XXX */ kHIDUsage_PID_Gain = 0x52, /* XXX */ kHIDUsage_PID_TriggerButton = 0x53, /* XXX */ kHIDUsage_PID_TriggerRepeatInterval = 0x54, /* XXX */ kHIDUsage_PID_AxesEnable = 0x55, /* XXX */ kHIDUsage_PID_DirectionEnable = 0x56, /* XXX */ kHIDUsage_PID_Direction = 0x57, /* XXX */ kHIDUsage_PID_TypeSpecificBlockOffset = 0x58, /* XXX */ kHIDUsage_PID_BlockType = 0x59, /* XXX */ kHIDUsage_PID_SetEnvelopeReport = 0x5A, /* XXX */ kHIDUsage_PID_AttackLevel = 0x5B, /* XXX */ kHIDUsage_PID_AttackTime = 0x5C, /* XXX */ kHIDUsage_PID_FadeLevel = 0x5D, /* XXX */ kHIDUsage_PID_FadeTime = 0x5E, /* XXX */ kHIDUsage_PID_SetConditionReport = 0x5F, /* XXX */ kHIDUsage_PID_CP_Offset = 0x60, /* XXX */ kHIDUsage_PID_PositiveCoefficient = 0x61, /* XXX */ kHIDUsage_PID_NegativeCoefficient = 0x62, /* XXX */ kHIDUsage_PID_PositiveSaturation = 0x63, /* XXX */ kHIDUsage_PID_NegativeSaturation = 0x64, /* XXX */ kHIDUsage_PID_DeadBand = 0x65, /* XXX */ kHIDUsage_PID_DownloadForceSample = 0x66, /* XXX */ kHIDUsage_PID_IsochCustomForceEnable = 0x67, /* XXX */ kHIDUsage_PID_CustomForceDataReport = 0x68, /* XXX */ kHIDUsage_PID_CustomForceData = 0x69, /* XXX */ kHIDUsage_PID_CustomForceVendorDefinedData = 0x6A, /* XXX */ kHIDUsage_PID_SetCustomForceReport = 0x6B, /* XXX */ kHIDUsage_PID_CustomForceDataOffset = 0x6C, /* XXX */ kHIDUsage_PID_SampleCount = 0x6D, /* XXX */ kHIDUsage_PID_SetPeriodicReport = 0x6E, /* XXX */ kHIDUsage_PID_Offset = 0x6F, /* XXX */ kHIDUsage_PID_Magnitude = 0x70, /* XXX */ kHIDUsage_PID_Phase = 0x71, /* XXX */ kHIDUsage_PID_Period = 0x72, /* XXX */ kHIDUsage_PID_SetConstantForceReport = 0x73, /* XXX */ kHIDUsage_PID_SetRampForceReport = 0x74, /* XXX */ kHIDUsage_PID_RampStart = 0x75, /* XXX */ kHIDUsage_PID_RampEnd = 0x76, /* XXX */ kHIDUsage_PID_EffectOperationReport = 0x77, /* XXX */ kHIDUsage_PID_EffectOperation = 0x78, /* XXX */ kHIDUsage_PID_OpEffectStart = 0x79, /* XXX */ kHIDUsage_PID_OpEffectStartSolo = 0x7A, /* XXX */ kHIDUsage_PID_OpEffectStop = 0x7B, /* XXX */ kHIDUsage_PID_LoopCount = 0x7C, /* XXX */ kHIDUsage_PID_DeviceGainReport = 0x7D, /* XXX */ kHIDUsage_PID_DeviceGain = 0x7E, /* XXX */ kHIDUsage_PID_PoolReport = 0x7F, /* XXX */ kHIDUsage_PID_RAM_PoolSize = 0x80, /* XXX */ kHIDUsage_PID_ROM_PoolSize = 0x81, /* XXX */ kHIDUsage_PID_ROM_EffectBlockCount = 0x82, /* XXX */ kHIDUsage_PID_SimultaneousEffectsMax = 0x83, /* XXX */ kHIDUsage_PID_PoolAlignment = 0x84, /* XXX */ kHIDUsage_PID_PoolMoveReport = 0x85, /* XXX */ kHIDUsage_PID_MoveSource = 0x86, /* XXX */ kHIDUsage_PID_MoveDestination = 0x87, /* XXX */ kHIDUsage_PID_MoveLength = 0x88, /* XXX */ kHIDUsage_PID_BlockLoadReport = 0x89, /* XXX */ /* 0x8A Reserved */ kHIDUsage_PID_BlockLoadStatus = 0x8B, /* XXX */ kHIDUsage_PID_BlockLoadSuccess = 0x8C, /* XXX */ kHIDUsage_PID_BlockLoadFull = 0x8D, /* XXX */ kHIDUsage_PID_BlockLoadError = 0x8E, /* XXX */ kHIDUsage_PID_BlockHandle = 0x8F, /* XXX */ kHIDUsage_PID_BlockFreeReport = 0x90, /* XXX */ kHIDUsage_PID_TypeSpecificBlockHandle = 0x91, /* XXX */ kHIDUsage_PID_StateReport = 0x92, /* XXX */ /* 0x93 Reserved */ kHIDUsage_PID_EffectPlaying = 0x94, /* XXX */ kHIDUsage_PID_DeviceControlReport = 0x95, /* XXX */ kHIDUsage_PID_DeviceControl = 0x96, /* XXX */ kHIDUsage_PID_DC_EnableActuators = 0x97, /* XXX */ kHIDUsage_PID_DC_DisableActuators = 0x98, /* XXX */ kHIDUsage_PID_DC_StopAllEffects = 0x99, /* XXX */ kHIDUsage_PID_DC_DeviceReset = 0x9A, /* XXX */ kHIDUsage_PID_DC_DevicePause = 0x9B, /* XXX */ kHIDUsage_PID_DC_DeviceContinue = 0x9C, /* XXX */ /* 0x9d - 0x9E Reserved */ kHIDUsage_PID_DevicePaused = 0x9F, /* XXX */ kHIDUsage_PID_ActuatorsEnabled = 0xA0, /* XXX */ /* 0xA1 - 0xA3 Reserved */ kHIDUsage_PID_SafetySwitch = 0xA4, /* XXX */ kHIDUsage_PID_ActuatorOverrideSwitch = 0xA5, /* XXX */ kHIDUsage_PID_ActuatorPower = 0xA6, /* XXX */ kHIDUsage_PID_StartDelay = 0xA7, /* XXX */ kHIDUsage_PID_ParameterBlockSize = 0xA8, /* XXX */ kHIDUsage_PID_DeviceManagedPool = 0xA9, /* XXX */ kHIDUsage_PID_SharedParameterBlocks = 0xAA, /* XXX */ kHIDUsage_PID_CreateNewEffectReport = 0xAB, /* XXX */ kHIDUsage_PID_RAM_PoolAvailable = 0xAC, /* XXX */ /* 0xAD - 0xFFFF Reserved */ kHIDUsage_PID_Reserved = 0xFFFF }; #ifdef __cplusplus } #endif #endif /* __PID__ */ pd-hid_0.7/HID Utilities Source/HID_Name_Lookup.h0000644000076500007650000000740511504504627020126 0ustar hanshans/* File: HID_Name_Lookup.h Contains: Definition of the HID device name lookup functions for the HID utilites. DRI: George Warner Copyright: Copyright © 2002 Apple Computer, Inc., All Rights Reserved Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. ("Apple") in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this Apple software constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this Apple software. In consideration of your agreement to abide by the following terms, and subject to these terms, Apple grants you a personal, non-exclusive license, under AppleÕs copyrights in this original Apple software (the "Apple Software"), to use, reproduce, modify and redistribute the Apple Software, with or without modifications, in source and/or binary forms; provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Computer, Inc. may be used to endorse or promote products derived from the Apple Software without specific prior written permission from Apple. Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by Apple herein, including but not limited to any patent rights that may be infringed by your derivative works or by other works in which the Apple Software may be incorporated. The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _HID_Name_Lookup_h_ #define _HID_Name_Lookup_h_ #include "HID_Utilities.h" // ================================== #ifdef __cplusplus extern "C" { #endif // ================================== // Note: Now that as the device data has now been moved into external .XML files these // constansts should no longer be used. They will eventually be eliminated from this header. #define kMicrosoft 1118 #define kSideWinderFFB2 27 #define kLogitech 1133 #define kWingManStrikeForce3D 49797 #define kMacally 8738 #define kiShock 16400 #define kiShockIIFFB 16416 #define kMacsense 1635 #define kFunPadF107 38916 // ================================== // set name from vendor id/product id look up (using cookies) extern Boolean HIDGetElementNameFromVendorProductCookie (const long vendorID, const long productID, const long cookie, char * pName); // set name from vendor id/product id look up (using usage page & usage) extern Boolean HIDGetElementNameFromVendorProductUsage (const long vendorID, const long productID, const long pUsagePage, const long pUsage, char * pName); // ================================== #ifdef __cplusplus } #endif #endif // _HID_Name_Lookup_h_ pd-hid_0.7/HID Utilities Source/HID_Utilities_External.h0000644000076500007650000006046411504504627021536 0ustar hanshans/* File: HID_Utilities_External.h Contains: Definition of the HID Utilities exported functions External interface for HID Utilities, can be used with either library or source Check notes below for usage. Some type casting is required so library is framework and carbon free DRI: George Warner Copyright: Copyright © 2002 Apple Computer, Inc., All Rights Reserved Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. ("Apple") in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this Apple software constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this Apple software. In consideration of your agreement to abide by the following terms, and subject to these terms, Apple grants you a personal, non-exclusive license, under AppleÕs copyrights in this original Apple software (the "Apple Software"), to use, reproduce, modify and redistribute the Apple Software, with or without modifications, in source and/or binary forms; provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Computer, Inc. may be used to endorse or promote products derived from the Apple Software without specific prior written permission from Apple. Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by Apple herein, including but not limited to any patent rights that may be infringed by your derivative works or by other works in which the Apple Software may be incorporated. The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ #ifndef _HID_Utilities_External_h_ #define _HID_Utilities_External_h_ // ================================== #if PRAGMA_ONCE #pragma once #endif #ifdef __cplusplus extern "C" { #endif #if PRAGMA_IMPORT #pragma import on #endif #pragma options align=mac68k // ================================== //includes #if TARGET_RT_MAC_CFM // from IOHIDKeys.h (IOKit) // this can't be included since the orginal file has framework includes // developers may need to add definitions here enum IOHIDElementType { kIOHIDElementTypeInput_Misc = 1, kIOHIDElementTypeInput_Button = 2, kIOHIDElementTypeInput_Axis = 3, kIOHIDElementTypeInput_ScanCodes = 4, kIOHIDElementTypeOutput = 129, kIOHIDElementTypeFeature = 257, kIOHIDElementTypeCollection = 513 }; typedef enum IOHIDElementType IOHIDElementType; enum IOHIDReportType { kIOHIDReportTypeInput = 0, kIOHIDReportTypeOutput, kIOHIDReportTypeFeature, kIOHIDReportTypeCount }; typedef enum IOHIDReportType IOHIDReportType; typedef void (*IOHIDCallbackFunction)(void * target, unsigned long result, void* refcon, void * sender); typedef void* IOHIDEventStruct; #else #include #endif TARGET_RT_MAC_CFM #if 0 #include #include "PID.h" // NOTE: These are now in #include "IOHIDPowerUsage.h" // NOTE: These are now in #endif #include // ================================== // Device and Element Interfaces typedef enum HIDElementTypeMask { kHIDElementTypeInput = 1 << 1, kHIDElementTypeOutput = 1 << 2, kHIDElementTypeFeature = 1 << 3, kHIDElementTypeCollection = 1 << 4, kHIDElementTypeIO = kHIDElementTypeInput | kHIDElementTypeOutput | kHIDElementTypeFeature, kHIDElementTypeAll = kHIDElementTypeIO | kHIDElementTypeCollection }HIDElementTypeMask; struct recElement { unsigned long type; // the type defined by IOHIDElementType in IOHIDKeys.h long usagePage; // usage page from IOUSBHIDParser.h which defines general usage long usage; // usage within above page from IOUSBHIDParser.h which defines specific usage void * cookie; // unique value (within device of specific vendorID and productID) which identifies element, will NOT change long min; // reported min value possible long max; // reported max value possible long scaledMin; // reported scaled min value possible long scaledMax; // reported scaled max value possible long size; // size in bits of data return from element unsigned char relative; // are reports relative to last report (deltas) unsigned char wrapping; // does element wrap around (one value higher than max is min) unsigned char nonLinear; // are the values reported non-linear relative to element movement unsigned char preferredState; // does element have a preferred state (such as a button) unsigned char nullState; // does element have null state long units; // units value is reported in (not used very often) long unitExp; // exponent for units (also not used very often) char name[256]; // name of element (c string) // runtime variables long initialCenter; // center value at start up unsigned char hasCenter; // whether or not to use center for calibration long minReport; // min returned value long maxReport; // max returned value (calibrate call) long userMin; // user set value to scale to (scale call) long userMax; struct recElement * pPrevious; // previous element (NULL at list head) struct recElement * pChild; // next child (only of collections) struct recElement * pSibling; // next sibling (for elements and collections) long depth; }; typedef struct recElement recElement; typedef recElement* pRecElement; struct recDevice { void * interface; // interface to device, NULL = no interface void * queue; // device queue, NULL = no queue void * queueRunLoopSource; // device queue run loop source, NULL == no source void * transaction; // output transaction interface, NULL == no interface void * notification; // notifications char transport[256]; // device transport (c string) long vendorID; // id for device vendor, unique across all devices long productID; // id for particular product, unique across all of a vendors devices long version; // version of product char manufacturer[256]; // name of manufacturer char product[256]; // name of product char serial[256]; // serial number of specific product, can be assumed unique across specific product or specific vendor (not used often) long locID; // long representing location in USB (or other I/O) chain which device is pluged into, can identify specific device on machine long usage; // usage page from IOUSBHID Parser.h which defines general usage long usagePage; // usage within above page from IOUSBHID Parser.h which defines specific usage long totalElements; // number of total elements (should be total of all elements on device including collections) (calculated, not reported by device) long features; // number of elements of type kIOHIDElementTypeFeature long inputs; // number of elements of type kIOHIDElementTypeInput_Misc or kIOHIDElementTypeInput_Button or kIOHIDElementTypeInput_Axis or kIOHIDElementTypeInput_ScanCodes long outputs; // number of elements of type kIOHIDElementTypeOutput long collections; // number of elements of type kIOHIDElementTypeCollection long axis; // number of axis (calculated, not reported by device) long buttons; // number of buttons (calculated, not reported by device) long hats; // number of hat switches (calculated, not reported by device) long sliders; // number of sliders (calculated, not reported by device) long dials; // number of dials (calculated, not reported by device) long wheels; // number of wheels (calculated, not reported by device) recElement* pListElements; // head of linked list of elements struct recDevice* pNext; // next device }; typedef struct recDevice recDevice; typedef recDevice* pRecDevice; // ================================== // HID Utilities interface // ================================== // Create and open an interface to device, required prior to extracting values or building queues // Note: appliction now owns the device and must close and release it prior to exiting extern unsigned long HIDCreateOpenDeviceInterface (UInt32 hidDevice, pRecDevice pDevice); // builds list of device with elements (allocates memory and captures devices) // list is allcoated internally within HID Utilites and can be accessed via accessor functions // structures within list are considered flat and user accessable, butnot user modifiable // can be called again to rebuild list to account for new devices (will do the right thing in case of disposing existing list) // usagePage, usage are each a numDeviceTypes sized array of matching usage and usage pages // returns true if succesful extern Boolean HIDBuildMultiDeviceList (UInt32 *pUsagePage, UInt32 *pUsage, UInt32 numDeviceTypes); // same as above but this uses a single usagePage and usage extern Boolean HIDBuildDeviceList (UInt32 usagePage, UInt32 usage); // updates the current device list for any new/removed devices // if this is called before HIDBuildDeviceList the it functions like HIDBuildMultiDeviceList // usagePage, usage are each a numDeviceTypes sized array of matching usage and usage pages // returns true if successful which means if any device were added or removed (the device config changed) extern Boolean HIDUpdateDeviceList (UInt32 *pUsagePage, UInt32 *pUsage, UInt32 numDeviceTypes); // release list built by above function // MUST be called prior to application exit to properly release devices // if not called (or app crashes) devices can be recovered by pluging into different location in USB chain extern void HIDReleaseDeviceList (void); // does a device list exist extern Boolean HIDHaveDeviceList (void); // how many HID devices have been found // returns 0 if no device list exist extern UInt32 HIDCountDevices (void); // how many elements does a specific device have // returns 0 if device is invalid or NULL // uses mask of HIDElementTypeMask to restrict element found // use kHIDElementTypeIO to get non-collection elements extern UInt32 HIDCountDeviceElements (pRecDevice pDevice, HIDElementTypeMask typeMask); // get the first device in the device list // returns NULL if no list exists extern pRecDevice HIDGetFirstDevice (void); // get next device in list given current device as parameter // returns NULL if end of list extern pRecDevice HIDGetNextDevice (pRecDevice pDevice); // get the first element of device passed in as parameter // returns NULL if no list exists or device does not exists or is NULL // uses mask of HIDElementTypeMask to restrict element found // use kHIDElementTypeIO to get previous HIDGetFirstDeviceElement functionality extern pRecElement HIDGetFirstDeviceElement (pRecDevice pDevice, HIDElementTypeMask typeMask); // get next element of given device in list given current element as parameter // will walk down each collection then to next element or collection (depthwise traverse) // returns NULL if end of list // uses mask of HIDElementTypeMask to restrict element found // use kHIDElementTypeIO to get previous HIDGetNextDeviceElement functionality extern pRecElement HIDGetNextDeviceElement (pRecElement pElement, HIDElementTypeMask typeMask); // get previous element of given device in list given current element as parameter // this walks directly up the tree to the top element and does not search at each level // returns NULL if beginning of list // uses mask of HIDElementTypeMask to restrict element found // use kHIDElementTypeIO to get non-collection elements extern pRecElement HIDGetPreviousDeviceElement (pRecElement pElement, HIDElementTypeMask typeMask); // ================================== // Name Lookup Interfaces // returns C string type name given a type enumeration passed in as parameter (see IOHIDKeys.h) // returns empty string for invlid types extern void HIDGetTypeName (IOHIDElementType theType, char * cstrName); // set name from vendor id/product id look up (using cookies) extern Boolean HIDGetElementNameFromVendorProductCookie (const long vendorID, const long productID, const long cookie, char * pName); // set name from vendor id/product id look up (using usage page & usage) extern Boolean HIDGetElementNameFromVendorProductUsage (const long vendorID, const long productID, const long pUsagePage, const long pUsage, char * pName); // returns C string usage given usage page and usage passed in as parameters (see IOUSBHIDParser.h) // returns usage page and usage values in string form for unknown values extern void HIDGetUsageName (long valueUsagePage, long valueUsage, char * cstrName); // --------------------------------- // convert an element type to a mask extern HIDElementTypeMask HIDConvertElementTypeToMask (const long type); // find this device extern Boolean HIDFindDevice(const pRecDevice pSearchDevice, pRecDevice *ppFoundDevice); // find the device and element for this action // Device: serial, vendorID, productID, location, usagePage, usage // Element: cookie, usagePage, usage, extern Boolean HIDFindActionDeviceAndElement(const pRecDevice pSearchDevice, const pRecElement pSearchElement, pRecDevice *ppFoundDevice, pRecElement *ppFoundElement); // find the device and element for this action // Device: serial, vendorID, productID, location, usagePage, usage // Element: cookie, usagePage, usage, extern Boolean HIDFindSubElement(const pRecElement pStartElement, const pRecElement pSearchElement, pRecElement *ppFoundElement); // print out all of an elements information extern int HIDPrintElement(const pRecElement pElement); // return true if this is a valid device pointer extern Boolean HIDIsValidDevice(const pRecDevice pSearchDevice); // return true if this is a valid element pointer for this device extern Boolean HIDIsValidElement(const pRecDevice pSearchDevice, const pRecElement pSearchElement); // ================================== // Element Event Queue and Value Interfaces enum { kDefaultUserMin = 0, // default user min and max used for scaling kDefaultUserMax = 255 }; enum { kDeviceQueueSize = 50 // this is wired kernel memory so should be set to as small as possible // but should account for the maximum possible events in the queue // USB updates will likely occur at 100 Hz so one must account for this rate of // if states change quickly (updates are only posted on state changes) }; // ================================== // queues specific element, performing any device queue set up required extern unsigned long HIDQueueElement (pRecDevice pDevice, pRecElement pElement); // adds all elements to queue, performing any device queue set up required extern unsigned long HIDQueueDevice (pRecDevice pDevice); // removes element for queue, if last element in queue will release queue and device extern unsigned long HIDDequeueElement (pRecDevice pDevice, pRecElement pElement); // completely removes all elements from queue and releases queue and device extern unsigned long HIDDequeueDevice (pRecDevice pDevice); // releases all device queues for quit or rebuild (must be called) extern unsigned long HIDReleaseAllDeviceQueues (void); // releases interface to device, should be done prior to exiting application (called from HIDReleaseDeviceList) extern unsigned long HIDCloseReleaseInterface (pRecDevice pDevice); // returns true if an event is avialable for the element and fills out *pHIDEvent structure, returns false otherwise // pHIDEvent is a poiner to a IOHIDEventStruct, using void here for compatibility, users can cast a required extern unsigned char HIDGetEvent (pRecDevice pDevice, void * pHIDEvent); // returns current value for element, creating device interface as required, polling element extern long HIDGetElementValue (pRecDevice pDevice, pRecElement pElement); // Set an elements value // NOTE: This should only be used when a single element report needs to be sent. // If multiple elements reports are to be send then transactions should be used. // pIOHIDEvent is a poiner to a IOHIDEventStruct, using void here for compatibility, users can cast a required extern long HIDSetElementValue (pRecDevice pDevice, pRecElement pElement,void* pIOHIDEvent); // Set a callback to be called when a queue goes from empty to non-empty extern long HIDSetQueueCallback (pRecDevice pDevice, IOHIDCallbackFunction callback,void* callbackTarget, void* callbackRefcon); #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_2 // Get a report from a device extern long HIDGetReport (pRecDevice pDevice,const IOHIDReportType reportType, const unsigned long reportID, void* reportBuffer, unsigned long* reportBufferSize); // Send a report to a device extern long HIDSetReport (pRecDevice pDevice,const IOHIDReportType reportType, const unsigned long reportID, void* reportBuffer, const unsigned long reportBufferSize); #endif MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_2 // ================================== // HUD utilities interfaces // returns calibrated value given raw value passed in // calibrated value is equal to min and max values returned by HIDGetElementValue since device list built scaled to element reported min and max values extern SInt32 HIDCalibrateValue (SInt32 value, pRecElement pElement); // returns scaled value given raw value passed in // scaled value is equal to current value assumed to be in the range of element reported min and max values scaled to user min and max scaled values extern SInt32 HIDScaleValue (SInt32 value, pRecElement pElement); // ================================== // Conguration and Save Interfaces enum { kPercentMove = 10 // precent of overall range a element must move to register }; typedef struct recSaveHID { long actionCookie; // device // need to add serial number when I have a test case long vendorID; long productID; long locID; long usage; long usagePage; // elements long usagePageE; long usageE; void * cookie; }recSaveHID,*pRecSaveHID; // polls all devices and elements for a change greater than kPercentMove. Times out after given time // returns true and pointer to device and element if found // returns false and NULL for both parameters if not found extern unsigned char HIDConfigureAction (pRecDevice * ppDevice, pRecElement * ppElement, float timeout); // -- These are routines to use if the applcation wants HID Utilities to do the file handling -- // Note: the FILE* is a MachO posix FILE and will not work with the MW MSL FILE* type. // take input records, save required info // assume file is open and at correct position. extern void HIDSaveElementConfig (FILE* fileRef, pRecDevice pDevice, pRecElement pElement, long actionCookie); // take file, read one record (assume file position is correct and file is open) // search for matching device // return pDevice, pElement and cookie for action extern long HIDRestoreElementConfig (FILE* fileRef, pRecDevice * ppDevice, pRecElement * ppElement); // -- These routines use the CFPreferences API's. // Save the device & element values into the specified key in the specified applications preferences extern Boolean HIDSaveElementPref (CFStringRef keyCFStringRef, CFStringRef appCFStringRef, pRecDevice pDevice, pRecElement pElement); // Find the specified preference in the specified application // search for matching device and element // return pDevice, pElement that matches extern Boolean HIDRestoreElementPref (CFStringRef keyCFStringRef, CFStringRef appCFStringRef, pRecDevice * ppDevice, pRecElement * ppElement); // -- These are routines to use if the client wants to use their own file handling -- // Set up a config record for saving // takes an input records, returns record user can save as they want // Note: the save rec must be pre-allocated by the calling app and will be filled out extern void HIDSetElementConfig (pRecSaveHID pConfigRec, pRecDevice pDevice, pRecElement pElement, long actionCookie); // Get matching element from config record // takes a pre-allocated and filled out config record // search for matching device // return pDevice, pElement and cookie for action extern long HIDGetElementConfig (pRecSaveHID pConfigRec, pRecDevice * ppDevice, pRecElement * ppElement); // ================================== // Output Transaction interface // Create and open an transaction interface to device, required prior to extracting values or building Transactions extern unsigned long HIDTransactionAddElement(pRecDevice pDevice, pRecElement pElement); // removes an element from a Transaction extern unsigned long HIDTransactionRemoveElement(pRecDevice pDevice, pRecElement pElement); // return true if this transaction contains this element extern Boolean HIDTransactionHasElement(pRecDevice pDevice, pRecElement pElement); /* This changes the default value of an element, when the values of the */ /* elements are cleared, on clear or commit, they are reset to the */ /* default value */ /* This call can be made on elements that are not in the transaction, but */ /* has undefined behavior if made on elements not in the transaction */ /* which are later added to the transaction. */ /* In other words, an element should be added before its default is */ /* set, for well defined behavior. */ // pHIDEvent is a poiner to a IOHIDEventStruct, using void here for compatibility, users can cast a required extern unsigned long HIDTransactionSetElementDefault(pRecDevice pDevice, pRecElement pElement,IOHIDEventStruct* pValueEvent); /* Get the current setting of an element's default value */ // pHIDEvent is a poiner to a IOHIDEventStruct, using void here for compatibility, users can cast a required extern unsigned long HIDTransactionGetElementDefault(pRecDevice pDevice, pRecElement pElement,IOHIDEventStruct* pValueEvent); /* Add a change to the transaction, by setting an element value */ /* The change is not actually made until it is commited */ /* The element must be part of the transaction or this call will fail */ // pHIDEvent is a poiner to a IOHIDEventStruct, using void here for compatibility, users can cast a required extern unsigned long HIDTransactionSetElementValue(pRecDevice pDevice, pRecElement pElement,IOHIDEventStruct* pValueEvent); /* Get the current setting of an element value */ // pHIDEvent is a poiner to a IOHIDEventStruct, using void here for compatibility, users can cast a required extern unsigned long HIDTransactionGetElementValue(pRecDevice pDevice, pRecElement pElement,IOHIDEventStruct* pValueEvent); /* Commit the transaction, or clear all the changes and start over */ /* timoutMS is the timeout in milliseconds, a zero timeout will cause */ /* this call to be non-blocking (returning queue empty) if there */ /* is a NULL callback, and blocking forever until the queue is */ /* non-empty if their is a valid callback */ /* callback, if non-NULL is a callback to be called when data is */ /* inserted to the queue */ /* callbackTarget and callbackRefcon are passed to the callback */ extern unsigned long HIDTransactionCommit(pRecDevice pDevice); /* Clear all the changes and start over */ extern unsigned long HIDTransactionClear(pRecDevice pDevice); // ================================== #pragma options align=reset #ifdef PRAGMA_IMPORT_OFF #pragma import off #elif PRAGMA_IMPORT #pragma import reset #endif #ifdef __cplusplus } #endif // ================================== #endif // _HID_Utilities_External_h_ pd-hid_0.7/HID Utilities Source/ImmrHIDUtilAddOn.h0000644000076500007650000000064611504504627020226 0ustar hanshans/* * ImmrHIDUtilAddOn.h * UseFFAPIFromHIDUtilities * * Created by rlacroix on Wed Oct 16 2002. * Copyright (c) 2002 Immersion Corporation. All rights reserved. * */ //extern io_object_t AllocateHIDObjectFromRecDevice( pRecDevice pDevice ); //extern Boolean FreeHIDObject( io_object_t hidDevice ); io_service_t AllocateHIDObjectFromRecDevice( pRecDevice pDevice ); bool FreeHIDObject( io_service_t hidDevice ); pd-hid_0.7/HID Utilities Source/HID Utilities Slib.pbproj/0000755000076500007650000000000011504505103021545 5ustar hanshanspd-hid_0.7/HID Utilities Source/HID Utilities Slib.pbproj/project.pbxproj0000644000076500007650000001727511504504627024647 0ustar hanshans// !$*UTF8*$! { archiveVersion = 1; classes = { }; objectVersion = 38; objects = { 11019ECA0367675E0CCB177F = { fileRef = F94745EF01B301760ACA2316; isa = PBXBuildFile; settings = { }; }; 113C0C5F036745F00CCB177F = { fileEncoding = 4; isa = PBXFileReference; path = HID_Transaction_Utilities.c; refType = 4; }; 113C0C60036745F00CCB177F = { fileRef = 113C0C5F036745F00CCB177F; isa = PBXBuildFile; settings = { }; }; 11AB43E70369956C0CCB177F = { isa = PBXFileReference; path = "HID Utilities Read Me.rtf"; refType = 4; }; //110 //111 //112 //113 //114 //3A0 //3A1 //3A2 //3A3 //3A4 3A1E2F8308593DC100E32947 = { fileEncoding = 4; isa = PBXFileReference; path = HID_APIs.h; refType = 4; }; 3A1E2F8408593DC100E32947 = { fileRef = 3A1E2F8308593DC100E32947; isa = PBXBuildFile; settings = { }; }; 3A1E2F8508593DD700E32947 = { fileEncoding = 4; isa = PBXFileReference; path = ImmrHIDUtilAddOn.h; refType = 4; }; 3A1E2F8608593DD700E32947 = { fileRef = 3A1E2F8508593DD700E32947; isa = PBXBuildFile; settings = { }; }; 3A1E2F8708593DE400E32947 = { fileEncoding = 4; isa = PBXFileReference; path = ImmrHIDUtilAddOn.c; refType = 4; }; 3A1E2F8808593DE400E32947 = { fileRef = 3A1E2F8708593DE400E32947; isa = PBXBuildFile; settings = { }; }; //3A0 //3A1 //3A2 //3A3 //3A4 //F60 //F61 //F62 //F63 //F64 F65F9D7E01B4915C01CA2317 = { children = ( ); isa = PBXGroup; name = "Libraries and Frameworks"; refType = 4; }; //F60 //F61 //F62 //F63 //F64 //F90 //F91 //F92 //F93 //F94 F94467BD024699CF0ACA2316 = { fileEncoding = 4; isa = PBXFileReference; path = HID_Name_Lookup.c; refType = 4; }; F94467BF024699CF0ACA2316 = { fileRef = F94467BD024699CF0ACA2316; isa = PBXBuildFile; settings = { }; }; F94467C302469A860ACA2316 = { fileEncoding = 4; isa = PBXFileReference; path = HID_Name_Lookup.h; refType = 4; }; F94467C402469A860ACA2316 = { fileRef = F94467C302469A860ACA2316; isa = PBXBuildFile; settings = { }; }; F94745C901B2DAC40ACA2316 = { buildStyles = ( F94745CB01B2DAC40ACA2316, F94745CC01B2DAC40ACA2316, ); hasScannedForEncodings = 1; isa = PBXProject; mainGroup = F94745CA01B2DAC40ACA2316; productRefGroup = F94745CF01B2DB060ACA2316; projectDirPath = ""; targets = ( F94745D101B2DB060ACA2316, ); }; F94745CA01B2DAC40ACA2316 = { children = ( 11AB43E70369956C0CCB177F, F94745CE01B2DB060ACA2316, F94745CD01B2DB060ACA2316, F94745E201B2DB720ACA2316, F65F9D7E01B4915C01CA2317, F94745CF01B2DB060ACA2316, ); isa = PBXGroup; refType = 4; }; F94745CB01B2DAC40ACA2316 = { buildRules = ( ); buildSettings = { COPY_PHASE_STRIP = NO; }; isa = PBXBuildStyle; name = Development; }; F94745CC01B2DAC40ACA2316 = { buildRules = ( ); buildSettings = { COPY_PHASE_STRIP = YES; }; isa = PBXBuildStyle; name = Deployment; }; F94745CD01B2DB060ACA2316 = { children = ( F94745EB01B2E50A0ACA2316, F94467C302469A860ACA2316, F94745F001B301760ACA2316, ); isa = PBXGroup; name = "Internal Headers"; refType = 4; }; F94745CE01B2DB060ACA2316 = { children = ( F94467BD024699CF0ACA2316, F94745D601B2DB130ACA2316, F94745F301B3062C0ACA2316, F94745DA01B2DB130ACA2316, 113C0C5F036745F00CCB177F, F94745E601B2DB720ACA2316, 3A1E2F8708593DE400E32947, ); isa = PBXGroup; name = Source; refType = 4; }; F94745CF01B2DB060ACA2316 = { children = ( F94745D001B2DB060ACA2316, ); isa = PBXGroup; name = Products; refType = 4; }; F94745D001B2DB060ACA2316 = { isa = PBXLibraryReference; path = libHIDUtilities.a; refType = 3; }; F94745D101B2DB060ACA2316 = { buildPhases = ( F94745D201B2DB060ACA2316, F94745D301B2DB060ACA2316, F94745D401B2DB060ACA2316, F94745D501B2DB060ACA2316, ); buildSettings = { DEBUGGING_SYMBOLS = NO; LIBRARY_STYLE = STATIC; OPTIMIZATION_CFLAGS = "-O3"; OTHER_LDFLAGS = ""; OTHER_LIBTOOL_FLAGS = ""; OTHER_REZFLAGS = ""; PRECOMPILE_PREFIX_HEADER = YES; PREFIX_HEADER = HIDLib.h; PRODUCT_NAME = libHIDUtilities.a; REZ_EXECUTABLE = YES; SECTORDER_FLAGS = ""; WARNING_CFLAGS = "-Wmost -Wno-four-char-constants -Wno-unknown-pragmas"; }; dependencies = ( ); isa = PBXLibraryTarget; name = libHIDUtilities.a; productName = libHIDUtilities.a; productReference = F94745D001B2DB060ACA2316; }; F94745D201B2DB060ACA2316 = { buildActionMask = 2147483647; files = ( F94745EC01B2E50A0ACA2316, F94745F201B301760ACA2316, F94467C402469A860ACA2316, 11019ECA0367675E0CCB177F, 3A1E2F8408593DC100E32947, 3A1E2F8608593DD700E32947, ); isa = PBXHeadersBuildPhase; runOnlyForDeploymentPostprocessing = 0; }; F94745D301B2DB060ACA2316 = { buildActionMask = 2147483647; files = ( F94745DF01B2DB140ACA2316, F94745E101B2DB140ACA2316, F94745EA01B2DB720ACA2316, F94745F401B3062C0ACA2316, F94467BF024699CF0ACA2316, 113C0C60036745F00CCB177F, 3A1E2F8808593DE400E32947, ); isa = PBXSourcesBuildPhase; runOnlyForDeploymentPostprocessing = 0; }; F94745D401B2DB060ACA2316 = { buildActionMask = 2147483647; files = ( ); isa = PBXFrameworksBuildPhase; runOnlyForDeploymentPostprocessing = 0; }; F94745D501B2DB060ACA2316 = { buildActionMask = 2147483647; files = ( ); isa = PBXRezBuildPhase; runOnlyForDeploymentPostprocessing = 0; }; F94745D601B2DB130ACA2316 = { fileEncoding = 4; isa = PBXFileReference; path = HID_Config_Utilities.c; refType = 4; }; F94745DA01B2DB130ACA2316 = { fileEncoding = 4; isa = PBXFileReference; path = HID_Queue_Utilities.c; refType = 4; }; F94745DF01B2DB140ACA2316 = { fileRef = F94745D601B2DB130ACA2316; isa = PBXBuildFile; settings = { }; }; F94745E101B2DB140ACA2316 = { fileRef = F94745DA01B2DB130ACA2316; isa = PBXBuildFile; settings = { }; }; F94745E201B2DB720ACA2316 = { children = ( F94745E301B2DB720ACA2316, F94745E401B2DB720ACA2316, F94745EF01B301760ACA2316, 3A1E2F8308593DC100E32947, 3A1E2F8508593DD700E32947, ); isa = PBXGroup; name = "External Headers"; refType = 4; }; F94745E301B2DB720ACA2316 = { fileEncoding = 4; isa = PBXFileReference; path = IOHIDPowerUsage.h; refType = 4; }; F94745E401B2DB720ACA2316 = { fileEncoding = 4; isa = PBXFileReference; path = PID.h; refType = 4; }; F94745E601B2DB720ACA2316 = { fileEncoding = 4; isa = PBXFileReference; path = HID_Utilities.c; refType = 4; }; F94745EA01B2DB720ACA2316 = { fileRef = F94745E601B2DB720ACA2316; isa = PBXBuildFile; settings = { }; }; F94745EB01B2E50A0ACA2316 = { fileEncoding = 4; isa = PBXFileReference; path = HIDLib.h; refType = 4; }; F94745EC01B2E50A0ACA2316 = { fileRef = F94745EB01B2E50A0ACA2316; isa = PBXBuildFile; settings = { }; }; F94745EF01B301760ACA2316 = { fileEncoding = 4; isa = PBXFileReference; path = HID_Utilities_External.h; refType = 4; }; F94745F001B301760ACA2316 = { fileEncoding = 4; isa = PBXFileReference; path = HID_Utilities_Internal.h; refType = 4; }; F94745F201B301760ACA2316 = { fileRef = F94745F001B301760ACA2316; isa = PBXBuildFile; settings = { }; }; F94745F301B3062C0ACA2316 = { fileEncoding = 4; isa = PBXFileReference; path = HID_Error_Handler.c; refType = 4; }; F94745F401B3062C0ACA2316 = { fileRef = F94745F301B3062C0ACA2316; isa = PBXBuildFile; settings = { }; }; }; rootObject = F94745C901B2DAC40ACA2316; } pd-hid_0.7/HID Utilities Source/IOHIDPowerUsage.h0000644000076500007650000004255111504504627020070 0ustar hanshans/* File: IOHIDPowerUsage.h Contains: Definition of the HID power usage constants (NOTE: Moved into ) DRI: George Warner Copyright: Copyright © 2002 Apple Computer, Inc., All Rights Reserved Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. ("Apple") in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this Apple software constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this Apple software. In consideration of your agreement to abide by the following terms, and subject to these terms, Apple grants you a personal, non-exclusive license, under AppleÕs copyrights in this original Apple software (the "Apple Software"), to use, reproduce, modify and redistribute the Apple Software, with or without modifications, in source and/or binary forms; provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Computer, Inc. may be used to endorse or promote products derived from the Apple Software without specific prior written permission from Apple. Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by Apple herein, including but not limited to any patent rights that may be infringed by your derivative works or by other works in which the Apple Software may be incorporated. The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef __IOHIDPowerUsage__ #define __IOHIDPowerUsage__ #ifndef __MACTYPES__ //#include #endif #ifndef __MACERRORS__ //#include #endif #ifdef __cplusplus extern "C" { #endif enum { kHIDPage_PowerDevice = 0x84, /* Power Device Page */ kHIDPage_BatterySystem = 0x85, /* Battery System Page */ /* Usage Types: CA- Application Collection CL- logical Collection CP- Pyiscal Collection DF- Dynamic Flag DV- Dynamic Value SF- Static Flag SV- Static Value Usgae Implementations: I- Input O- Output F- Feature */ /* Power Device Page (0x84) */ /* This section provides detailed descriptions of the usages employed by Power Devices. */ kHIDUsage_PD_Undefined = 0x00, /* Power Device Undefined Usage */ kHIDUsage_PD_iName = 0x01, /* CL- Power Device Name Index */ kHIDUsage_PD_PresentStatus = 0x02, /* CL- Power Device Present Status */ kHIDUsage_PD_ChangedStatus = 0x03, /* CA- Power Device Changed Status */ kHIDUsage_PD_UPS = 0x04, /* CA- Uninterruptible Power Supply */ kHIDUsage_PD_PowerSupply = 0x05, /* CA- Power Supply */ /* Reserved 0x06 - 0x0F */ kHIDUsage_PD_BatterySystem = 0x10, /* CP- Battery System power module */ kHIDUsage_PD_BatterySystemID = 0x11, /* SV IF- Battery System ID */ kHIDUsage_PD_Battery = 0x12, /* CP- Battery */ kHIDUsage_PD_BatteryID = 0x13, /* SV IF- Battery ID */ kHIDUsage_PD_Charger = 0x14, /* CP- Charger */ kHIDUsage_PD_ChargerID = 0x15, /* SV IF- Charger ID */ kHIDUsage_PD_PowerConverter = 0x16, /* CP- Power Converter power module */ kHIDUsage_PD_PowerConverterID = 0x17, /* SV IF- Power Converter ID */ kHIDUsage_PD_OutletSystem = 0x18, /* CP- Outlet System power module */ kHIDUsage_PD_OutletSystemID = 0x19, /* SV IF-Outlet System ID */ kHIDUsage_PD_Input = 0x1A, /* CP- Power Device Input */ kHIDUsage_PD_InputID = 0x1B, /* SV IF- Power Device Input ID */ kHIDUsage_PD_Output = 0x1C, /* CP- Power Device Output */ kHIDUsage_PD_OutputID = 0x1D, /* SV IF- Power Device Output ID */ kHIDUsage_PD_Flow = 0x1E, /* CP- Power Device Flow */ kHIDUsage_PD_FlowID = 0x1F, /* Item IF- Power Device Flow ID */ kHIDUsage_PD_Outlet = 0x20, /* CP- Power Device Outlet */ kHIDUsage_PD_OutletID = 0x21, /* SV IF- Power Device Outlet ID */ kHIDUsage_PD_Gang = 0x22, /* CL/CP- Power Device Gang */ kHIDUsage_PD_GangID = 0x23, /* SV IF- Power Device Gang ID */ kHIDUsage_PD_PowerSummary = 0x24, /* CL/CP- Power Device Power Summary */ kHIDUsage_PD_PowerSummaryID = 0x25, /* SV IF- Power Device Power Summary ID */ /* Reserved 0x26 - 0x2F */ kHIDUsage_PD_Voltage = 0x30, /* DV IF- Power Device Voltage */ kHIDUsage_PD_Current = 0x31, /* DV IF- Power Device Current */ kHIDUsage_PD_Frequency = 0x32, /* DV IF- Power Device Frequency */ kHIDUsage_PD_ApparentPower = 0x33, /* DV IF- Power Device Apparent Power */ kHIDUsage_PD_ActivePower = 0x34, /* DV IF- Power Device RMS Power */ kHIDUsage_PD_PercentLoad = 0x35, /* DV IF- Power Device Percent Load */ kHIDUsage_PD_Temperature = 0x36, /* DV IF- Power Device Temperature */ kHIDUsage_PD_Humidity = 0x37, /* DV IF- Power Device Humidity */ kHIDUsage_PD_BadCount = 0x38, /* DV IF- Power Device Bad Condition Count */ /* Reserved 0x39 - 0x3F */ kHIDUsage_PD_ConfigVoltage = 0x40, /* SV/DV F- Power Device Nominal Voltage */ kHIDUsage_PD_ConfigCurrent = 0x41, /* SV/DV F- Power Device Nominal Current */ kHIDUsage_PD_ConfigFrequency = 0x42, /* SV/DV F- Power Device Nominal Frequency */ kHIDUsage_PD_ConfigApparentPower = 0x43, /* SV/DV F- Power Device Nominal Apparent Power */ kHIDUsage_PD_ConfigActivePower = 0x44, /* SV/DV F- Power Device Nominal RMS Power */ kHIDUsage_PD_ConfigPercentLoad = 0x45, /* SV/DV F- Power Device Nominal Percent Load */ kHIDUsage_PD_ConfigTemperature = 0x46, /* SV/DV F- Power Device Nominal Temperature */ kHIDUsage_PD_ConfigHumidity = 0x47, /* SV/DV F- Power Device Nominal Humidity */ /* Reserved 0x48 - 0x4F */ kHIDUsage_PD_SwitchOnControl = 0x50, /* DV F- Power Device Switch On Control */ kHIDUsage_PD_SwitchOffControl = 0x51, /* DV F- Power Device Switch Off Control */ kHIDUsage_PD_ToggleControl = 0x52, /* DV F- Power Device Toogle Sequence Control */ kHIDUsage_PD_LowVoltageTransfer = 0x53, /* DV F- Power Device Min Transfer Voltage */ kHIDUsage_PD_HighVoltageTransfer = 0x54, /* DV F- Power Device Max Transfer Voltage */ kHIDUsage_PD_DelayBeforeReboot = 0x55, /* DV F- Power Device Delay Before Reboot */ kHIDUsage_PD_DelayBeforeStartup = 0x56, /* DV F- Power Device Delay Before Startup */ kHIDUsage_PD_DelayBeforeShutdown = 0x57, /* DV F- Power Device Delay Before Shutdown */ kHIDUsage_PD_Test = 0x58, /* DV F- Power Device Test Request/Result */ kHIDUsage_PD_ModuleReset = 0x59, /* DV F- Power Device Reset Request/Result */ kHIDUsage_PD_AudibleAlarmControl = 0x5A, /* DV F- Power Device Audible Alarm Control */ /* Reserved 0x5B - 0x5F */ kHIDUsage_PD_Present = 0x60, /* DV IOF- Power Device Present */ kHIDUsage_PD_Good = 0x61, /* DV IOF- Power Device Good */ kHIDUsage_PD_InternalFailure = 0x62, /* DV IOF- Power Device Internal Failure */ kHIDUsage_PD_VoltageOutOfRange = 0x63, /* DV IOF- Power Device Voltage Out Of Range */ kHIDUsage_PD_FrequencyOutOfRange = 0x64, /* DV IOF- Power Device Frequency Out Of Range */ kHIDUsage_PD_Overload = 0x65, /* DV IOF- Power Device Overload */ kHIDUsage_PD_OverCharged = 0x66, /* DV IOF- Power Device Over Charged */ kHIDUsage_PD_OverTemperature = 0x67, /* DV IOF- Power Device Over Temperature */ kHIDUsage_PD_ShutdownRequested = 0x68, /* DV IOF- Power Device Shutdown Requested */ kHIDUsage_PD_ShutdownImminent = 0x69, /* DV IOF- Power Device Shutdown Imminent */ /* Reserved 0x6A */ kHIDUsage_PD_SwitchOnOff = 0x6B, /* DV IOF- Power Device On/Off Switch Status */ kHIDUsage_PD_Switchable = 0x6C, /* DV IOF- Power Device Switchable */ kHIDUsage_PD_Used = 0x6D, /* DV IOF- Power Device Used */ kHIDUsage_PD_Boost = 0x6E, /* DV IOF- Power Device Boosted */ kHIDUsage_PD_Buck = 0x6F, /* DV IOF- Power Device Bucked */ kHIDUsage_PD_Initialized = 0x70, /* DV IOF- Power Device Initialized */ kHIDUsage_PD_Tested = 0x71, /* DV IOF- Power Device Tested */ kHIDUsage_PD_AwaitingPower = 0x72, /* DV IOF- Power Device Awaiting Power */ kHIDUsage_PD_CommunicationLost = 0x73, /* DV IOF- Power Device Communication Lost */ /* Reserved 0x74 - 0xFC */ kHIDUsage_PD_iManufacturer = 0xFD, /* SV F- Power Device Manufacturer String Index */ kHIDUsage_PD_iProduct = 0xFE, /* SV F- Power Device Product String Index */ kHIDUsage_PD_iserialNumber = 0xFF, /* SV F- Power Device Serial Number String Index */ /* Battery System Page (x85) */ /* This section provides detailed descriptions of the usages employed by Battery Systems. */ kHIDUsage_BS_Undefined = 0x00, /* Battery System Undefined */ kHIDUsage_BS_SMBBatteryMode = 0x01, /* CL - SMB Mode */ kHIDUsage_BS_SMBBatteryStatus = 0x02, /* CL - SMB Status */ kHIDUsage_BS_SMBAlarmWarning = 0x03, /* CL - SMB Alarm Warning */ kHIDUsage_BS_SMBChargerMode = 0x04, /* CL - SMB Charger Mode */ kHIDUsage_BS_SMBChargerStatus = 0x05, /* CL - SMB Charger Status */ kHIDUsage_BS_SMBChargerSpecInfo = 0x06, /* CL - SMB Charger Extended Status */ kHIDUsage_BS_SMBSelectorState = 0x07, /* CL - SMB Selector State */ kHIDUsage_BS_SMBSelectorPresets = 0x08, /* CL - SMB Selector Presets */ kHIDUsage_BS_SMBSelectorInfo = 0x09, /* CL - SMB Selector Info */ /* Reserved 0x0A - 0x0F */ kHIDUsage_BS_OptionalMfgFunction1 = 0x10, /* DV F - Battery System Optional SMB Mfg Function 1 */ kHIDUsage_BS_OptionalMfgFunction2 = 0x11, /* DV F - Battery System Optional SMB Mfg Function 2 */ kHIDUsage_BS_OptionalMfgFunction3 = 0x12, /* DV F - Battery System Optional SMB Mfg Function 3 */ kHIDUsage_BS_OptionalMfgFunction4 = 0x13, /* DV F - Battery System Optional SMB Mfg Function 4 */ kHIDUsage_BS_OptionalMfgFunction5 = 0x14, /* DV F - Battery System Optional SMB Mfg Function 5 */ kHIDUsage_BS_ConnectionToSMBus = 0x15, /* DF F - Battery System Connection To System Management Bus */ kHIDUsage_BS_OutputConnection = 0x16, /* DF F - Battery System Output Connection Status */ kHIDUsage_BS_ChargerConnection = 0x17, /* DF F - Battery System Charger Connection */ kHIDUsage_BS_BatteryInsertion = 0x18, /* DF F - Battery System Battery Insertion */ kHIDUsage_BS_Usenext = 0x19, /* DF F - Battery System Use Next */ kHIDUsage_BS_OKToUse = 0x1A, /* DF F - Battery System OK To Use */ kHIDUsage_BS_BatterySupported = 0x1B, /* DF F - Battery System Battery Supported */ kHIDUsage_BS_SelectorRevision = 0x1C, /* DF F - Battery System Selector Revision */ kHIDUsage_BS_ChargingIndicator = 0x1D, /* DF F - Battery System Charging Indicator */ /* Reserved 0x1E - 0x27 */ kHIDUsage_BS_ManufacturerAccess = 0x28, /* DV F - Battery System Manufacturer Access */ kHIDUsage_BS_RemainingCapacityLimit = 0x29, /* DV F - Battery System Remaining Capacity Limit */ kHIDUsage_BS_RemainingTimeLimit = 0x2A, /* DV F - Battery System Remaining Time Limit */ kHIDUsage_BS_AtRate = 0x2B, /* DV F - Battery System At Rate... */ kHIDUsage_BS_CapacityMode = 0x2C, /* DV F - Battery System Capacity Mode */ kHIDUsage_BS_BroadcastToCharger = 0x2D, /* DV F - Battery System Broadcast To Charger */ kHIDUsage_BS_PrimaryBattery = 0x2E, /* DV F - Battery System Primary Battery */ kHIDUsage_BS_ChargeController = 0x2F, /* DV F - Battery System Charge Controller */ /* Reserved 0x30 - 0x3F */ kHIDUsage_BS_TerminateCharge = 0x40, /* DF IOF - Battery System Terminate Charge */ kHIDUsage_BS_TerminateDischarge = 0x41, /* DF IOF - Battery System Terminate Discharge */ kHIDUsage_BS_BelowRemainingCapacityLimit = 0x42, /* DF IOF - Battery System Below Remaining Capacity Limit */ kHIDUsage_BS_RemainingTimeLimitExpired = 0x43, /* DF IOF - Battery System Remaining Time Limit Expired */ kHIDUsage_BS_Charging = 0x44, /* DF IOF - Battery System Charging */ kHIDUsage_BS_Discharging = 0x45, /* DV IOF - Battery System Discharging */ kHIDUsage_BS_FullyCharged = 0x46, /* DF IOF - Battery System Fully Charged */ kHIDUsage_BS_FullyDischarged = 0x47, /* DV IOF - Battery System Fully Discharged */ kHIDUsage_BS_ConditioningFlag = 0x48, /* DV IOF - Battery System Conditioning Flag */ kHIDUsage_BS_AtRateOK = 0x49, /* DV IOF - Battery System At Rate OK */ kHIDUsage_BS_SMBErrorCode = 0x4A, /* DF IOF - Battery System SMB Error Code */ kHIDUsage_BS_NeedReplacement = 0x4B, /* DF IOF - Battery System Need Replacement */ /* Reserved 0x4C - 0x5F */ kHIDUsage_BS_AtRateTimeToFull = 0x60, /* DV IF - Battery System At Rate Time To Full */ kHIDUsage_BS_AtRateTimeToEmpty = 0x61, /* DV IF - Battery System At Rate Time To Empty */ kHIDUsage_BS_AverageCurrent = 0x62, /* DV IF - Battery System Average Current */ kHIDUsage_BS_Maxerror = 0x63, /* DV IF - Battery System Max Error */ kHIDUsage_BS_RelativeStateOfCharge = 0x64, /* DV IF - Battery System Relative State Of Charge */ kHIDUsage_BS_AbsoluteStateOfCharge = 0x65, /* DV IF - Battery System Absolute State Of Charge */ kHIDUsage_BS_RemainingCapacity = 0x66, /* DV IF - Battery System Remaining Capacity */ kHIDUsage_BS_FullChargeCapacity = 0x67, /* DV IF - Battery System Full Charge Capacity */ kHIDUsage_BS_RunTimeToEmpty = 0x68, /* DV IF - Battery System Run Time To Empty */ kHIDUsage_BS_AverageTimeToEmpty = 0x69, /* DV IF - Battery System Average Time To Empty */ kHIDUsage_BS_AverageTimeToFull = 0x6A, /* DV IF - Battery System Average Time To Full */ kHIDUsage_BS_CycleCount = 0x6B, /* DV IF - Battery System Cycle Count */ /* Reserved 0x6C - 0x7F */ kHIDUsage_BS_BattPackModelLevel = 0x80, /* SV F - Battery System Batt Pack Model Level */ kHIDUsage_BS_InternalChargeController = 0x81, /* SF F - Battery System Internal Charge Controller */ kHIDUsage_BS_PrimaryBatterySupport = 0x82, /* SF F - Battery System Primary Battery Support */ kHIDUsage_BS_DesignCapacity = 0x83, /* SV F - Battery System Design Capacity */ kHIDUsage_BS_SpecificationInfo = 0x84, /* SV F - Battery System Specification Info */ kHIDUsage_BS_ManufacturerDate = 0x85, /* SV F - Battery System Manufacturer Date */ kHIDUsage_BS_SerialNumber = 0x86, /* SV F - Battery System Serial Number */ kHIDUsage_BS_iManufacturerName = 0x87, /* SV F - Battery System Manufacturer Name Index */ kHIDUsage_BS_iDevicename = 0x88, /* SV F - Battery System Device Name Index */ kHIDUsage_BS_iDeviceChemistry = 0x89, /* SV F - Battery System Device Chemistry Index */ kHIDUsage_BS_ManufacturerData = 0x8A, /* SV F - Battery System Manufacturer Data */ kHIDUsage_BS_Rechargable = 0x8B, /* SV F - Battery System Rechargable */ kHIDUsage_BS_WarningCapacityLimit = 0x8C, /* SV F - Battery System Warning Capacity Limit */ kHIDUsage_BS_CapacityGranularity1 = 0x8D, /* SV F - Battery System Capacity Granularity 1 */ kHIDUsage_BS_CapacityGranularity2 = 0x8E, /* SV F - Battery System Capacity Granularity 2 */ kHIDUsage_BS_iOEMInformation = 0x8F, /* SV F - Battery System OEM Information Index */ /* Reserved 0x90 - 0xBF */ kHIDUsage_BS_InhibitCharge = 0xC0, /* DF IOF - Battery System Inhibit Charge */ kHIDUsage_BS_EnablePolling = 0xC1, /* DF IOF - Battery System Enable Polling */ kHIDUsage_BS_ResetToZero = 0xC2, /* DF IOF - Battery System Reset To Zero */ /* Reserved 0xC3 - 0xCF */ kHIDUsage_BS_ACPresent = 0xD0, /* DF IOF - Battery System AC Present */ kHIDUsage_BS_BatteryPresent = 0xD1, /* DF IOF - Battery System Battery Present */ kHIDUsage_BS_PowerFail = 0xD2, /* DF IOF - Battery System Power Fail */ kHIDUsage_BS_AlarmInhibited = 0xD3, /* DF IOF - Battery System Alarm Inhibited */ kHIDUsage_BS_ThermistorUnderRange = 0xD4, /* DF IOF - Battery System Thermistor Under Range */ kHIDUsage_BS_ThermistorHot = 0xD5, /* DF IOF - Battery System Thermistor Hot */ kHIDUsage_BS_ThermistorCold = 0xD6, /* DF IOF - Battery System Thermistor Cold */ kHIDUsage_BS_ThermistorOverRange = 0xD7, /* DF IOF - Battery System Thermistor Over Range */ kHIDUsage_BS_VoltageOutOfRange = 0xD8, /* DF IOF - Battery System Voltage Out Of Range */ kHIDUsage_BS_CurrentOutOfRange = 0xD9, /* DF IOF - Battery System Current Out Of Range */ kHIDUsage_BS_CurrentNotRegulated = 0xDA, /* DF IOF - Battery System Current Not Regulated */ kHIDUsage_BS_VoltageNotRegulated = 0xDB, /* DF IOF - Battery System Voltage Not Regulated */ kHIDUsage_BS_MasterMode = 0xDC, /* DF IOF - Battery System Master Mode */ /* Reserved 0xDD - 0xEF */ kHIDUsage_BS_ChargerSelectorSupport = 0xF0, /* SF F- Battery System Charger Support Selector */ kHIDUsage_BS_ChargerSpec = 0xF1, /* SF F- Battery System Charger Specification */ kHIDUsage_BS_Level2 = 0xF2, /* SF F- Battery System Charger Level 2 */ kHIDUsage_BS_Level3 = 0xF3 /* SF F- Battery System Charger Level 3 */ /* Reserved 0xF2 - 0xFF */ }; #ifdef __cplusplus } #endif #endif /* __IOHIDPowerUsage__ */ pd-hid_0.7/HID Utilities Source/HID_Config_Utilities.h0000644000076500007650000000762411504504627021160 0ustar hanshans/* File: HID_Config_Utilities.h Contains: Definition of the interfaces to DRI: George Warner Copyright: Copyright © 2002 Apple Computer, Inc., All Rights Reserved Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. ("Apple") in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this Apple software constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this Apple software. In consideration of your agreement to abide by the following terms, and subject to these terms, Apple grants you a personal, non-exclusive license, under AppleÕs copyrights in this original Apple software (the "Apple Software"), to use, reproduce, modify and redistribute the Apple Software, with or without modifications, in source and/or binary forms; provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Computer, Inc. may be used to endorse or promote products derived from the Apple Software without specific prior written permission from Apple. Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by Apple herein, including but not limited to any patent rights that may be infringed by your derivative works or by other works in which the Apple Software may be incorporated. The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _HID_Config_Utilities_h_ #define _HID_Config_Utilities_h_ #include #include "HID_Utilities.h" enum { kPercentMove = 10 // precent of overall range a element must move to register }; struct recSaveHID { long actionCookie; // device // need to add serial number when I have a test case long vendorID; long productID; long locID; long usage; long usagePage; // elements long usagePageE; long usageE; void * cookie; }; typedef struct recSaveHID recSaveHID; typedef recSaveHID * pRecSaveHID; // polls all devices and elements for a change greater than kPercentMove. Times out after given time // returns true and pointer to device and element if found // returns false and NULL for both parameters if not found extern unsigned char HIDConfigureAction (pRecDevice * ppDevice, pRecElement * ppElement, float timeout); // take input records, save required info // assume file is open and at correct position. extern void HIDSaveElementConfig (FILE * fileRef, pRecDevice pDevice, pRecElement pElement, long actionCookie); // take file, read one record (assume file position is correct and file is open) // search for matching device // return pDevice, pElement and cookie for action extern long HIDRestoreElementConfig (FILE * fileRef, pRecDevice * ppDevice, pRecElement * ppElement); #endif pd-hid_0.7/HID Utilities Source/HID_Queue_Utilities.c0000644000076500007650000005560311504504627021032 0ustar hanshans/* File: HID_Queue_Utilities.c Contains: Implementation of the HID queue functions for the HID utilites. DRI: George Warner Copyright: Copyright © 2002 Apple Computer, Inc., All Rights Reserved Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. ("Apple") in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this Apple software constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this Apple software. In consideration of your agreement to abide by the following terms, and subject to these terms, Apple grants you a personal, non-exclusive license, under AppleÕs copyrights in this original Apple software (the "Apple Software"), to use, reproduce, modify and redistribute the Apple Software, with or without modifications, in source and/or binary forms; provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Computer, Inc. may be used to endorse or promote products derived from the Apple Software without specific prior written permission from Apple. Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by Apple herein, including but not limited to any patent rights that may be infringed by your derivative works or by other works in which the Apple Software may be incorporated. The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ //#include #include "HID_Utilities_Internal.h" #include "HID_Utilities_External.h" // ================================== // compiler directives // ================================== #define USE_ASYNC_EVENTS TRUE #define REPORT_ERRORS FALSE // ================================== #if REPORT_ERRORS #define HIDREPORTERRORNUM(s,n) HIDReportErrorNum(s,n) #define HIDREPORTERROR(s) HIDReportError(s) #else #define HIDREPORTERRORNUM(s,n) do {} while (false) #define HIDREPORTERROR(s) do {} while (false) #endif // ================================== // private functions // ================================== // creates a queue for a device static IOReturn hid_CreateQueue (pRecDevice pDevice) { IOReturn result = kIOReturnError; // assume failure (pessimist!) if (HIDIsValidDevice(pDevice)) { if (NULL == pDevice->queue) // do we already have a queue { if (NULL != pDevice->interface) { pDevice->queue = (void *) (*(IOHIDDeviceInterface**) pDevice->interface)->allocQueue (pDevice->interface); // alloc queue if (pDevice->queue) { result = (*(IOHIDQueueInterface**) pDevice->queue)->create (pDevice->queue, 0, kDeviceQueueSize); // create actual queue if (kIOReturnSuccess != result) HIDREPORTERRORNUM ("hid_CreateQueue - Failed to create queue via create", result); } else { HIDREPORTERROR ("hid_CreateQueue - Failed to alloc IOHIDQueueInterface ** via allocQueue"); result = kIOReturnError; // synthesis error } } else HIDREPORTERRORNUM ("hid_CreateQueue - Device inteface does not exist for queue creation", result); } } else HIDREPORTERRORNUM ("hid_CreateQueue - Invalid Device", result); return result; } // --------------------------------- // returns true if queue is empty false otherwise // error if no device, empty if no queue static unsigned char hid_IsDeviceQueueEmpty (pRecDevice pDevice) { if (HIDIsValidDevice(pDevice)) // need valid device { if (pDevice->queue) // and queue { pRecElement pElement = HIDGetFirstDeviceElement (pDevice, kHIDElementTypeIO); while (pElement) { if ((*(IOHIDQueueInterface**) pDevice->queue)->hasElement (pDevice->queue, pElement->cookie)) return false; pElement = HIDGetNextDeviceElement (pElement, kHIDElementTypeIO); } } else HIDREPORTERROR ("hid_IsDeviceQueueEmpty - no queue."); } else HIDREPORTERROR ("hid_IsDeviceQueueEmpty - Invalid device."); return true; } // --------------------------------- // disposes and releases queue, sets queue to NULL,. // Note: will have no effect if device or queue do not exist static IOReturn hid_DisposeReleaseQueue (pRecDevice pDevice) { IOReturn result = kIOReturnError; // assume failure (pessimist!) if (HIDIsValidDevice(pDevice)) // need valid device { if (pDevice->queue) // and queue { // stop queue result = (*(IOHIDQueueInterface**) pDevice->queue)->stop (pDevice->queue); if (kIOReturnSuccess != result) HIDREPORTERRORNUM ("hid_DisposeReleaseQueue - Failed to stop queue.", result); // dispose of queue result = (*(IOHIDQueueInterface**) pDevice->queue)->dispose (pDevice->queue); if (kIOReturnSuccess != result) HIDREPORTERRORNUM ("hid_DisposeReleaseQueue - Failed to dipose queue.", result); // release the queue result = (*(IOHIDQueueInterface**) pDevice->queue)->Release (pDevice->queue); if (kIOReturnSuccess != result) HIDREPORTERRORNUM ("hid_DisposeReleaseQueue - Failed to release queue.", result); pDevice->queue = NULL; } else HIDREPORTERROR ("hid_DisposeReleaseQueue - no queue."); } else HIDREPORTERROR ("hid_DisposeReleaseQueue - Invalid device."); return result; } // ================================== // public functions // --------------------------------- // queues specific element, performing any device queue set up required // queue is started and ready to return events on exit from this function unsigned long HIDQueueElement (pRecDevice pDevice, pRecElement pElement) { IOReturn result = kIOReturnError; // assume failure (pessimist!) if (HIDIsValidElement(pDevice,pElement)) { if (NULL == pDevice->interface) // must have interface { HIDREPORTERROR ("HIDQueueElement - Device does not have interface."); return kIOReturnError; } if (NULL == pDevice->queue) // if no queue create queue result = hid_CreateQueue (pDevice); if ((kIOReturnSuccess != result) || (NULL == pDevice->queue)) { HIDREPORTERRORNUM ("HIDQueueElement - problem creating queue.", result); if (kIOReturnSuccess != result) return result; else return kIOReturnError; } // stop queue result = (*(IOHIDQueueInterface**) pDevice->queue)->stop (pDevice->queue); if (kIOReturnSuccess != result) HIDREPORTERROR ("HIDQueueElement - Failed to stop queue."); // queue element if (!(*(IOHIDQueueInterface**) pDevice->queue)->hasElement (pDevice->queue, pElement->cookie)) { result = (*(IOHIDQueueInterface**) pDevice->queue)->addElement (pDevice->queue, pElement->cookie, 0); if (kIOReturnSuccess != result) HIDREPORTERROR ("HIDQueueElement - Failed to add Element to queue."); } // restart queue result = (*(IOHIDQueueInterface**) pDevice->queue)->start (pDevice->queue); if (kIOReturnSuccess != result) HIDREPORTERROR ("HIDQueueElement - Failed to start queue."); } else { HIDREPORTERROR ("HIDQueueElement - Invalid Device and/or element."); return kIOReturnBadArgument; } return result; } // --------------------------------- // adds all elements to queue, performing any device queue set up required // queue is started and ready to return events on exit from this function unsigned long HIDQueueDevice (pRecDevice pDevice) { IOReturn result = kIOReturnError; // assume failure (pessimist!) pRecElement pElement; if (HIDIsValidDevice(pDevice)) { // error checking if (NULL == pDevice) { HIDREPORTERROR ("HIDQueueDevice - Device does not exist."); return kIOReturnBadArgument; } if (NULL == pDevice->interface) // must have interface { HIDREPORTERROR ("HIDQueueDevice - Device does not have interface."); return kIOReturnError; } if (NULL == pDevice->queue) // if no queue create queue result = hid_CreateQueue (pDevice); if ((kIOReturnSuccess != result) || (NULL == pDevice->queue)) { HIDREPORTERRORNUM ("HIDQueueDevice - problem creating queue.", result); if (kIOReturnSuccess != result) return result; else return kIOReturnError; } // stop queue result = (*(IOHIDQueueInterface**) pDevice->queue)->stop (pDevice->queue); if (kIOReturnSuccess != result) HIDREPORTERRORNUM ("HIDQueueDevice - Failed to stop queue.", result); // queue element //¥ pElement = HIDGetFirstDeviceElement (pDevice, kHIDElementTypeIO); pElement = HIDGetFirstDeviceElement (pDevice, kHIDElementTypeInput | kHIDElementTypeFeature); while (pElement) { if (!(*(IOHIDQueueInterface**) pDevice->queue)->hasElement (pDevice->queue, pElement->cookie)) { result = (*(IOHIDQueueInterface**) pDevice->queue)->addElement (pDevice->queue, pElement->cookie, 0); if (kIOReturnSuccess != result) HIDREPORTERRORNUM ("HIDQueueDevice - Failed to add element to queue.", result); } //¥ pElement = HIDGetNextDeviceElement (pElement, kHIDElementTypeIO); pElement = HIDGetNextDeviceElement (pElement, kHIDElementTypeInput | kHIDElementTypeFeature); } // start queue result = (*(IOHIDQueueInterface**) pDevice->queue)->start (pDevice->queue); if (kIOReturnSuccess != result) HIDREPORTERRORNUM ("HIDQueueDevice - Failed to start queue.", result); } else HIDREPORTERROR ("HIDQueueDevice - Invalid device."); return result; } // --------------------------------- // removes element for queue, if last element in queue will release queue and closes device interface unsigned long HIDDequeueElement (pRecDevice pDevice, pRecElement pElement) { IOReturn result = kIOReturnError; // assume failure (pessimist!) if (HIDIsValidElement(pDevice,pElement)) { if (!pDevice || !pElement) result = kIOReturnBadArgument; else { if ((pDevice->interface) && (pDevice->queue)) { // stop queue result = (*(IOHIDQueueInterface**) pDevice->queue)->stop (pDevice->queue); if (kIOReturnSuccess != result) HIDREPORTERRORNUM ("HIDDequeueElement - Failed to stop queue.", result); if ((*(IOHIDQueueInterface**) pDevice->queue)->hasElement (pDevice->queue, pElement->cookie)) // if has element then remove { result = (*(IOHIDQueueInterface**) pDevice->queue)->removeElement (pDevice->queue, pElement->cookie); if (kIOReturnSuccess != result) HIDREPORTERRORNUM ("HIDDequeueElement - Failed to add element to queue", result); } if (hid_IsDeviceQueueEmpty (pDevice)) // release device queue and close interface if queue empty { result = hid_DisposeReleaseQueue (pDevice); if (kIOReturnSuccess != result) HIDREPORTERRORNUM ("HIDDequeueElement - Failed to dispose and release queue.", result); } else // not empty so restart queue { result = (*(IOHIDQueueInterface**) pDevice->queue)->start (pDevice->queue); if (kIOReturnSuccess != result) HIDREPORTERRORNUM ("HIDDequeueElement - Failed to start queue.", result); } } else { HIDREPORTERROR ("HIDDequeueElement - No device inteface or queue."); return kIOReturnError; } } } else HIDREPORTERROR ("HIDDequeueElement - Invalid device."); return result; } // --------------------------------- // completely removes all elements from queue and releases queue and closes device interface // does not release device interfaces, application must call HIDReleaseDeviceList on exit unsigned long HIDDequeueDevice (pRecDevice pDevice) { IOReturn result = kIOReturnSuccess; if (HIDIsValidDevice(pDevice)) { if ((pDevice->interface) && (pDevice->queue)) { // iterate through elements and if queued, remove pRecElement pElement = HIDGetFirstDeviceElement (pDevice, kHIDElementTypeIO); while (pElement) { if ((*(IOHIDQueueInterface**) pDevice->queue)->hasElement (pDevice->queue, pElement->cookie)) { result = (*(IOHIDQueueInterface**) pDevice->queue)->removeElement (pDevice->queue, pElement->cookie); if (kIOReturnSuccess != result) HIDREPORTERRORNUM ("HIDDequeueDevice - Failed to remove element from queue.", result); } pElement = HIDGetNextDeviceElement (pElement, kHIDElementTypeIO); } } // ensure queue is disposed and released // interface will be closed and released on call to HIDReleaseDeviceList result = hid_DisposeReleaseQueue (pDevice); if (kIOReturnSuccess != result) HIDREPORTERRORNUM ("removeElement - Failed to dispose and release queue.", result); #if USE_ASYNC_EVENTS else if (NULL != pDevice->queueRunLoopSource) { if (CFRunLoopContainsSource(CFRunLoopGetCurrent(), pDevice->queueRunLoopSource, kCFRunLoopDefaultMode)) CFRunLoopRemoveSource(CFRunLoopGetCurrent(), pDevice->queueRunLoopSource, kCFRunLoopDefaultMode); CFRelease(pDevice->queueRunLoopSource); pDevice->queueRunLoopSource = NULL; } #endif USE_ASYNC_EVENTS } else { HIDREPORTERROR ("HIDDequeueDevice - Invalid device."); result = kIOReturnBadArgument; } return result; } // --------------------------------- // releases all device queues for quit or rebuild (must be called) // does not release device interfaces, application must call HIDReleaseDeviceList on exit unsigned long HIDReleaseAllDeviceQueues (void) { IOReturn result = kIOReturnBadArgument; pRecDevice pDevice = HIDGetFirstDevice (); while (pDevice) { result = HIDDequeueDevice (pDevice); if (kIOReturnSuccess != result) HIDREPORTERRORNUM ("HIDReleaseAllDeviceQueues - Could not dequeue device.", result); pDevice = HIDGetNextDevice (pDevice); } return result; } // --------------------------------- // Closes and releases interface to device, should be done prior to exting application // Note: will have no affect if device or interface do not exist // application will "own" the device if interface is not closed // (device may have to be plug and re-plugged in different location to get it working again without a restart) unsigned long HIDCloseReleaseInterface (pRecDevice pDevice) { IOReturn result = kIOReturnSuccess; if (HIDIsValidDevice(pDevice) && (NULL != pDevice->interface)) { // close the interface result = (*(IOHIDDeviceInterface**) pDevice->interface)->close (pDevice->interface); if (kIOReturnNotOpen == result) { // do nothing as device was not opened, thus can't be closed } else if (kIOReturnSuccess != result) HIDREPORTERRORNUM ("HIDCloseReleaseInterface - Failed to close IOHIDDeviceInterface.", result); //release the interface result = (*(IOHIDDeviceInterface**) pDevice->interface)->Release (pDevice->interface); if (kIOReturnSuccess != result) HIDREPORTERRORNUM ("HIDCloseReleaseInterface - Failed to release interface.", result); pDevice->interface = NULL; } return result; } // --------------------------------- // Get the next event in the queue for a device // elements or entire device should be queued prior to calling this with HIDQueueElement or HIDQueueDevice // returns true if an event is avialable for the element and fills out *pHIDEvent structure, returns false otherwise // Note: kIOReturnUnderrun returned from getNextEvent indicates an empty queue not an error condition // Note: application should pass in a pointer to a IOHIDEventStruct cast to a void (for CFM compatibility) unsigned char HIDGetEvent (pRecDevice pDevice, void * pHIDEvent) { IOReturn result = kIOReturnBadArgument; AbsoluteTime zeroTime = {0,0}; if (HIDIsValidDevice(pDevice)) { if (pDevice->queue) { result = (*(IOHIDQueueInterface**) pDevice->queue)->getNextEvent (pDevice->queue, (IOHIDEventStruct *)pHIDEvent, zeroTime, 0); if (kIOReturnUnderrun == result) return false; // no events in queue not an error per say else if (kIOReturnSuccess != result) // actual error versus just an empty queue HIDREPORTERRORNUM ("HIDGetEvent - Could not get HID event via getNextEvent.", result); else return true; } else HIDREPORTERROR ("HIDGetEvent - queue does not exist."); } else HIDREPORTERROR ("HIDGetEvent - invalid device."); return false; // did not get event } // --------------------------------- // returns current value for element, polling element // will return 0 on error conditions which should be accounted for by application long HIDGetElementValue (pRecDevice pDevice, pRecElement pElement) { IOReturn result = kIOReturnBadArgument; IOHIDEventStruct hidEvent; hidEvent.value = 0; hidEvent.longValueSize = 0; hidEvent.longValue = nil; if (HIDIsValidElement(pDevice, pElement)) { if (NULL != pDevice->interface) { // ++ NOTE: If the element type is feature then use queryElementValue instead of getElementValue if (kIOHIDElementTypeFeature == pElement->type) { result = (*(IOHIDDeviceInterface**) pDevice->interface)->queryElementValue (pDevice->interface, pElement->cookie, &hidEvent,0,NULL,NULL,NULL); if (kIOReturnUnsupported == result) // unless it's unsuported. goto try_getElementValue; else if (kIOReturnSuccess != result) HIDREPORTERRORNUM ("HIDGetElementValue - Could not get HID element value via queryElementValue.", result); } else if (pElement->type <= kIOHIDElementTypeInput_ScanCodes) { try_getElementValue: result = (*(IOHIDDeviceInterface**) pDevice->interface)->getElementValue (pDevice->interface, pElement->cookie, &hidEvent); if (kIOReturnSuccess != result) HIDREPORTERRORNUM ("HIDGetElementValue - Could not get HID element value via getElementValue.", result); } // on 10.0.x this returns the incorrect result for negative ranges, so fix it!!! // this is not required on Mac OS X 10.1+ if ((pElement->min < 0) && (hidEvent.value > pElement->max)) // assume range problem hidEvent.value = hidEvent.value + pElement->min - pElement->max - 1; } else HIDREPORTERROR ("HIDGetElementValue - no interface for device."); } else HIDREPORTERROR ("HIDGetElementValue - invalid device and/or element."); // record min and max for auto scale and auto ... /* if (hidEvent.value < pElement->calMin) pElement->calMin = hidEvent.value; if (hidEvent.value > pElement->calMax) pElement->calMax = hidEvent.value; */ // auto user scale return hidEvent.value; } // --------------------------------- // Set an elements value // NOTE: This should only be used when a single element of a report needs to be sent. // If multiple elements are to be send then transactions should be used. long HIDSetElementValue (pRecDevice pDevice, pRecElement pElement,void* pIOHIDEvent) { IOHIDEventStruct* pMyIOHIDEvent = (IOHIDEventStruct*) pIOHIDEvent; IOReturn result = kIOReturnError; // assume failure (pessimist!) if (HIDIsValidElement(pDevice, pElement)) { if (NULL != pDevice->interface) { result = (*(IOHIDDeviceInterface**) pDevice->interface)->setElementValue (pDevice->interface, pElement->cookie, pMyIOHIDEvent, -1, nil, nil, nil); if (kIOReturnSuccess != result) HIDREPORTERRORNUM ("HIDSetElementValue - Could not set HID element value via setElementValue.", result); } else HIDREPORTERROR ("HIDSetElementValue - no interface for device."); } else HIDREPORTERROR ("HIDSetElementValue - invalid device and/or element."); return result; } // --------------------------------- // Set a callback to be called when a queue goes from empty to non-empty /* long HIDSetQueueCallback (pRecDevice pDevice, IOHIDCallbackFunction callback) { IOReturn result = kIOReturnError; // assume failure (pessimist!) if (HIDIsValidDevice(pDevice)) { #if USE_ASYNC_EVENTS // if we don't have a queue runloop sourceÉ if (NULL == pDevice->queueRunLoopSource) { // then create one result = (*(IOHIDQueueInterface**) pDevice->queue)->createAsyncEventSource((void *) pDevice->queue, (CFRunLoopSourceRef*) &pDevice->queueRunLoopSource); if (kIOReturnSuccess != result) HIDREPORTERRORNUM ("HIDSetQueueCallback - Failed to createAsyncEventSource error: ", result); } // if we have one nowÉ if (NULL != pDevice->queueRunLoopSource) { // and it's not already attached to our runloopÉ if (!CFRunLoopContainsSource(CFRunLoopGetCurrent(), pDevice->queueRunLoopSource, kCFRunLoopDefaultMode)) // then attach it now. CFRunLoopAddSource(CFRunLoopGetCurrent(), pDevice->queueRunLoopSource, kCFRunLoopDefaultMode); } // now install our callback result = (*(IOHIDQueueInterface**) pDevice->queue)->setEventCallout(pDevice->queue, callback, pDevice, pDevice); if (kIOReturnSuccess != result) HIDREPORTERRORNUM ("HIDSetQueueCallback - Could not set HID queue callback via setEventCallout.", result); #endif USE_ASYNC_EVENTS } else HIDREPORTERROR ("HIDSetQueueCallback - invalid device and/or element."); return result; } */ #if 1 // --------------------------------- // Get a report from a device long HIDGetReport (pRecDevice pDevice,const IOHIDReportType reportType, const UInt32 reportID, void* reportBuffer, UInt32* reportBufferSize) { IOReturn result = kIOReturnError; // assume failure (pessimist!) if (HIDIsValidDevice(pDevice)) { if (NULL != pDevice->interface) { result = (*(IOHIDDeviceInterface**) pDevice->interface)->getReport (pDevice->interface, reportType, reportID, reportBuffer, reportBufferSize, -1, nil, nil, nil); if (kIOReturnSuccess != result) HIDREPORTERRORNUM ("HIDGetReport - Could not getReport, error: ", result); } else HIDREPORTERROR ("HIDGetReport - no interface for device."); } else HIDREPORTERROR ("HIDGetReport - invalid device."); return result; } // --------------------------------- // Send a report to a device long HIDSetReport (pRecDevice pDevice,const IOHIDReportType reportType, const UInt32 reportID, void* reportBuffer, const UInt32 reportBufferSize) { IOReturn result = kIOReturnError; // assume failure (pessimist!) if (HIDIsValidDevice(pDevice)) { if (NULL != pDevice->interface) { result = (*(IOHIDDeviceInterface**) pDevice->interface)->setReport (pDevice->interface, reportType, reportID, reportBuffer, reportBufferSize, -1, nil, nil, nil); if (kIOReturnSuccess != result) HIDREPORTERRORNUM ("HIDGetReport - Could not setReport; error: ", result); } else HIDREPORTERROR ("HIDGetReport - no interface for device."); } else HIDREPORTERROR ("HIDGetReport - invalid device."); return result; } #endifpd-hid_0.7/HID Utilities Source/HID_Error_Handler.h0000644000076500007650000000641511504504627020443 0ustar hanshans/* File: HID_Error_Handler.h Contains: Definition of the interfaces to DRI: George Warner Copyright: Copyright © 2002 Apple Computer, Inc., All Rights Reserved Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. ("Apple") in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this Apple software constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this Apple software. In consideration of your agreement to abide by the following terms, and subject to these terms, Apple grants you a personal, non-exclusive license, under AppleÕs copyrights in this original Apple software (the "Apple Software"), to use, reproduce, modify and redistribute the Apple Software, with or without modifications, in source and/or binary forms; provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Computer, Inc. may be used to endorse or promote products derived from the Apple Software without specific prior written permission from Apple. Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by Apple herein, including but not limited to any patent rights that may be infringed by your derivative works or by other works in which the Apple Software may be incorporated. The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ // Usage notes: // include control -------------------------------------------------- #ifndef Error_Handler_h #define Error_Handler_h // includes --------------------------------------------------------- #ifdef __cplusplus extern "C" { #endif // structures (public) ----------------------------------------------- // public function declarations ------------------------------------- // Error reporter, can be set to report however the application desires extern void HIDReportError (char * strError); // Error with numeric code reporter, can be set to report however the application desires extern void HIDReportErrorNum (char * strError, long numError); #ifdef __cplusplus } #endif #endif // Error_Handler_hpd-hid_0.7/HID Utilities Source/LICENSE.txt0000644000076500007650000000452111504504627016677 0ustar hanshansCopyright © 2002 Apple Computer, Inc., All Rights Reserved IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. ("Apple") in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this Apple software constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this Apple software. . In consideration of your agreement to abide by the following terms, and subject to these terms, Apple grants you a personal, non-exclusive license, under Apple’s copyrights in this original Apple software (the "Apple Software"), to use, reproduce, modify and redistribute the Apple Software, with or without modifications, in source and/or binary forms; provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Computer, Inc. may be used to endorse or promote products derived from the Apple Software without specific prior written permission from Apple. Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by Apple herein, including but not limited to any patent rights that may be infringed by your derivative works or by other works in which the Apple Software may be incorporated. . The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. . IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. pd-hid_0.7/HID Utilities Source/HID_Utilities.h0000644000076500007650000003163011504504627017665 0ustar hanshans/* File: HID_Utilities.h Contains: External interface for HID Utilities DRI: George Warner Copyright: Copyright © 2002 Apple Computer, Inc., All Rights Reserved Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. ("Apple") in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this Apple software constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this Apple software. In consideration of your agreement to abide by the following terms, and subject to these terms, Apple grants you a personal, non-exclusive license, under AppleÕs copyrights in this original Apple software (the "Apple Software"), to use, reproduce, modify and redistribute the Apple Software, with or without modifications, in source and/or binary forms; provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Computer, Inc. may be used to endorse or promote products derived from the Apple Software without specific prior written permission from Apple. Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by Apple herein, including but not limited to any patent rights that may be infringed by your derivative works or by other works in which the Apple Software may be incorporated. The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _HID_Utilities_h_ #define _HID_Utilities_h_ #include #include // 10.0.x //#include // 10.1.x #include #include // ================================== #ifdef __cplusplus extern "C" { #endif // ================================== enum { kDefaultUserMin = 0, // default user min and max used for scaling kDefaultUserMax = 255, }; typedef enum HIDElementTypeMask { kHIDElementTypeInput = 1 << 1, kHIDElementTypeOutput = 1 << 2, kHIDElementTypeFeature = 1 << 3, kHIDElementTypeCollection = 1 << 4, kHIDElementTypeIO = kHIDElementTypeInput | kHIDElementTypeOutput | kHIDElementTypeFeature, kHIDElementTypeAll = kHIDElementTypeIO | kHIDElementTypeCollection }HIDElementTypeMask; struct recElement { IOHIDElementType type; // the type defined by IOHIDElementType in IOHIDKeys.h long usagePage; // usage page from IOUSBHIDParser.h which defines general usage long usage; // usage within above page from IOUSBHIDParser.h which defines specific usage IOHIDElementCookie cookie; // unique value (within device of specific vendorID and productID) which identifies element, will NOT change long min; // reported min value possible long max; // reported max value possible long scaledMin; // reported scaled min value possible long scaledMax; // reported scaled max value possible long size; // size in bits of data return from element Boolean relative; // are reports relative to last report (deltas) Boolean wrapping; // does element wrap around (one value higher than max is min) Boolean nonLinear; // are the values reported non-linear relative to element movement Boolean preferredState; // does element have a preferred state (such as a button) Boolean nullState; // does element have null state long units; // units value is reported in (not used very often) long unitExp; // exponent for units (also not used very often) Str255 name; // name of element (not used often) // runtime variables long minReport; // min returned value long maxReport; // max returned value (calibrate call) long userMin; // user set value to scale to (scale call) long userMax; struct recElement * pPrevious; // previous element (NULL at list head) struct recElement * pChild; // next child (only of collections) struct recElement * pSibling; // next sibling (for elements and collections) }; typedef struct recElement recElement; typedef recElement* pRecElement; struct recDevice { IOHIDDeviceInterface ** interface; // interface to device, NULL = no interface IOHIDQueueInterface ** queue; // device queue, NULL = no queue CFRunLoopSourceRef queueRunLoopSource; // device queue run loop source, NULL == no source IOHIDOutputTransactionInterface ** transaction; // output transaction interface, NULL == no transaction io_object_t notification; // notifications Str255 transport; // device transport long vendorID; // id for device vendor, unique across all devices long productID; // id for particular product, unique across all of a vendors devices long version; // version of product Str255 manufacturer; // name of manufacturer Str255 product; // name of product Str255 serial; // serial number of specific product, can be assumed unique across specific product or specific vendor (not used often) long locID; // long representing location in USB (or other I/O) chain which device is pluged into, can identify specific device on machine long usage; // usage page from IOUSBHID Parser.h which defines general usage long usagePage; // usage within above page from IOUSBHID Parser.h which defines specific usage long totalElements; // number of total elements (should be total of all elements on device including collections) (calculated, not reported by device) long features; // number of elements of type kIOHIDElementTypeFeature long inputs; // number of elements of type kIOHIDElementTypeInput_Misc or kIOHIDElementTypeInput_Button or kIOHIDElementTypeInput_Axis or kIOHIDElementTypeInput_ScanCodes long outputs; // number of elements of type kIOHIDElementTypeOutput long collections; // number of elements of type kIOHIDElementTypeCollection long axis; // number of axis (calculated, not reported by device) long buttons; // number of buttons (calculated, not reported by device) long hats; // number of hat switches (calculated, not reported by device) long sliders; // number of sliders (calculated, not reported by device) long dials; // number of dials (calculated, not reported by device) long wheels; // number of wheels (calculated, not reported by device) recElement* pListElements; // head of linked list of elements struct recDevice* pNext; // next device }; typedef struct recDevice recDevice; typedef recDevice* pRecDevice; // ================================== // Create and open an interface to device, required prior to extracting values or building queues // Note: appliction now owns the device and must close and release it prior to exiting extern IOReturn HIDCreateOpenDeviceInterface (io_object_t hidDevice, pRecDevice pDevice); // builds list of device with elements (allocates memory and captures devices) // list is allcoated internally within HID Utilites and can be accessed via accessor functions // structures within list are considered flat and user accessable, butnot user modifiable // can be called again to rebuild list to account for new devices (will do the right thing in case of disposing existing list) extern Boolean HIDBuildDeviceList (UInt32 usagePage, UInt32 usage); // release list built by above function // MUST be called prior to application exit to properly release devices // if not called (or app crashes) devices can be recovered by pluging into different location in USB chain extern void HIDReleaseDeviceList (void); // does a device list exist extern Boolean HIDHaveDeviceList (void); // how many HID devices have been found // returns 0 if no device list exist extern UInt32 HIDCountDevices (void); // how many elements does a specific device have // returns 0 if device is invalid or NULL // uses mask of HIDElementTypeMask to restrict element found // use kHIDElementTypeIO to get non-collection elements extern UInt32 HIDCountDeviceElements (pRecDevice pDevice, HIDElementTypeMask typeMask); // get the first device in the device list // returns NULL if no list exists extern pRecDevice HIDGetFirstDevice (void); // get next device in list given current device as parameter // returns NULL if end of list extern pRecDevice HIDGetNextDevice (pRecDevice pDevice); // get the first element of device passed in as parameter // returns NULL if no list exists or device does not exists or is NULL // uses mask of HIDElementTypeMask to restrict element found // use kHIDElementTypeIO to get previous HIDGetFirstDeviceElement functionality extern pRecElement HIDGetFirstDeviceElement (pRecDevice pDevice, HIDElementTypeMask typeMask); // get next element of given device in list given current element as parameter // will walk down each collection then to next element or collection (depthwise traverse) // returns NULL if end of list // uses mask of HIDElementTypeMask to restrict element found // use kHIDElementTypeIO to get previous HIDGetNextDeviceElement functionality extern pRecElement HIDGetNextDeviceElement (pRecElement pElement, HIDElementTypeMask typeMask); // get previous element of given device in list given current element as parameter // this wlaks directly up the tree to the top element and does not search at each level // returns NULL if beginning of list // uses mask of HIDElementTypeMask to restrict element found // use kHIDElementTypeIO to get non-collection elements extern pRecElement HIDGetPreviousDeviceElement (pRecElement pElement, HIDElementTypeMask typeMask); // returns C string type name given a type enumeration passed in as parameter (see IOHIDKeys.h) // returns empty string for invlid types extern void HIDGetTypeName (IOHIDElementType type, char * cstrName); // returns C string usage given usage page and usage passed in as parameters (see IOUSBHIDParser.h) // returns usage page and usage values in string form for unknown values extern void HIDGetUsageName (long valueUsagePage, long valueUsage, char * cstrName); // returns calibrated value given raw value passed in // calibrated value is equal to min and max values returned by HIDGetElementValue since device list built scaled to element reported min and max values extern SInt32 HIDCalibrateValue (SInt32 value, pRecElement pElement); // returns scaled value given raw value passed in // scaled value is equal to current value assumed to be in the range of element reported min and max values scaled to user min and max scaled values extern SInt32 HIDScaleValue (SInt32 value, pRecElement pElement); // --------------------------------- // convert an element type to a mask extern HIDElementTypeMask HIDConvertElementTypeToMask (const long type); // find this device extern Boolean HIDFindDevice(const pRecDevice pSearchDevice, pRecDevice *ppFoundDevice); // find the device and element for this action // Device: serial, vendorID, productID, location, usagePage, usage // Element: cookie, usagePage, usage, extern Boolean HIDFindActionDeviceAndElement(const pRecDevice pSearchDevice, const pRecElement pSearchElement, pRecDevice *ppFoundDevice, pRecElement *ppFoundElement); // find the device and element for this action // Device: serial, vendorID, productID, location, usagePage, usage // Element: cookie, usagePage, usage, extern Boolean HIDFindSubElement(const pRecElement pStartElement, const pRecElement pSearchElement, pRecElement *ppFoundElement); // print out all of an elements information extern int HIDPrintElement(const pRecElement pElement); // return true if this is a valid device pointer extern Boolean HIDIsValidDevice(const pRecDevice pSearchDevice); // return true if this is a valid element pointer for this device extern Boolean HIDIsValidElement(const pRecDevice pSearchDevice, const pRecElement pSearchElement); #ifdef __cplusplus } #endif #endif // _HID_Utilities_h_ pd-hid_0.7/HID Utilities Source/HID_CFM.c0000644000076500007650000001761411504504627016320 0ustar hanshans/* File: HID_CFM.c Contains: Implementation of the CFM interfaces to the HID Utilities bundle DRI: George Warner Copyright: Copyright © 2002 Apple Computer, Inc., All Rights Reserved Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. ("Apple") in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this Apple software constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this Apple software. In consideration of your agreement to abide by the following terms, and subject to these terms, Apple grants you a personal, non-exclusive license, under AppleÕs copyrights in this original Apple software (the "Apple Software"), to use, reproduce, modify and redistribute the Apple Software, with or without modifications, in source and/or binary forms; provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Computer, Inc. may be used to endorse or promote products derived from the Apple Software without specific prior written permission from Apple. Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by Apple herein, including but not limited to any patent rights that may be infringed by your derivative works or by other works in which the Apple Software may be incorporated. The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ // Note: All the HID API's are defined externally in the file "HID_APIs.h". // How they are used in this file is defined via one or two macros: // // The DO_API micro takes four parameters: // #define DO_API(r,n,p,a) // r - what the API Returns // n - the Name of the API // p - the Parameters to the API // a - the Arguments passed by the API // // DO_APIr is used when an API returns a value. // DO_API is used when an API doesn't return a value. // // For example: // // if you have a routine that doesn't return a value: // // void MyFunction(const UInt32 pSelector, void* pPtr); // // It's macro would look like this: // // DO_API( // void, // this is what the function returns // MyFunction, // this is its Name // (const UInt32 pSelector, void* pPtr), // these are its parameters // (pSelector, pPtr)) // and these are just the arguments (no type info) // // If it returns a value like this // // OSStatus MyFunction2(const UInt32 pSelector, void* pPtr); // // It's macro would look like this: // // DO_APIr( // OSStatus, // this is what the function returns // MyFunction2, // this is its Name // (const UInt32 pSelector, void* pPtr), // these are its parameters // (pSelector, pPtr)) // and these are just the arguments (no type info) // // ================================== // includes // ================================== #include "HID_Utilities_CFM.h" typedef OSStatus HRESULT; typedef UInt32 IOByteCount; typedef unsigned int io_service_t; typedef unsigned int io_object_t; #define S_OK ((HRESULT)0x00000000L) // ================================== // define a ProcPtr type for each API #define DO_API(r,n,p,a) typedef r (*fp##n##Type)##p; #include "HID_APIs.h" // ================================== // declare storage for each API's function pointers #define DO_API(r,n,p,a) static fp##n##Type fp##n = NULL; #include "HID_APIs.h" // ================================== // globals // ================================== CFURLRef gBundleURL = NULL; CFBundleRef gBundle = NULL; // ================================== // setup the CFM to MachO (HID) connection // ================================== OSStatus SetupHIDCFM (void) { Boolean didLoad = false; // Flag that indicates the status returned when attempting to load a bundle's executable code. CFBundleRef refMainBundle = NULL; CFURLRef refMainBundleURL = NULL, refPathBundleURL = NULL; // See the Core Foundation URL Services chapter for details. // get app bundle (even for a CFM app!) refMainBundle = CFBundleGetMainBundle(); if (!refMainBundle) { DebugStr ("\pCould open main bundle"); return paramErr; } // create a URL to the app bundle refMainBundleURL = CFBundleCopyBundleURL (refMainBundle); if (!refMainBundleURL) { DebugStr ("\pCould not copy main bundle URL"); return paramErr; } #if 0 // This should only be true if the app is bundled // create a URL that points to the app's directory refPathBundleURL = CFURLCreateCopyDeletingLastPathComponent (kCFAllocatorDefault, refMainBundleURL); if (!refPathBundleURL) { DebugStr ("\pCould not create new parent URL deleting last path component"); if (refMainBundleURL != NULL) CFRelease (refMainBundleURL); return paramErr; } #else refPathBundleURL = refMainBundleURL; refMainBundleURL = NULL; #endif // create a URL to the HID library bundle gBundleURL = CFURLCreateCopyAppendingPathComponent (kCFAllocatorDefault, refPathBundleURL, CFSTR("HID.bundle"), true); // release created URLs if (refMainBundleURL != NULL) CFRelease (refMainBundleURL); if (refPathBundleURL != NULL) CFRelease (refPathBundleURL); // did we actaully get a bundle URL if (!gBundleURL) { DebugStr ("\pCould not create HID bundle URL"); return paramErr; } // get the actual bundle for the HID library gBundle = CFBundleCreate (kCFAllocatorDefault, gBundleURL); if (!gBundle) { DebugStr ("\pCould not create HID MachO library bundle"); CFShow(gBundleURL); return paramErr; } if (!CFBundleLoadExecutable (gBundle)) // If the code was successfully loaded, look for our function. { DebugStr ("\pCould not load MachO executable"); return paramErr; } // Now that the code is loaded, search for the functions we want by name. // for each API, look up it's function pointer and store it the local ProcPtr. #define DO_API(r,n,p,a) fp##n = (fp##n##Type) CFBundleGetFunctionPointerForName (gBundle, CFSTR(#n));; #include "HID_APIs.h" return noErr; } // ================================== // tear down the CFM to MachO (HID) connection // ================================== void TearDownHIDCFM (void) { // disassociate function pointers (assign null to each one) #define DO_API(r,n,p,a) fp##n = NULL; #include "HID_APIs.h" if (gBundle != NULL) { CFBundleUnloadExecutable (gBundle); // Unload the bundle's executable code. if (gBundleURL != NULL) CFRelease (gBundleURL); CFRelease (gBundle); } } // Now for each API declare a (CFM) routine that calls thru the local ProcPtr to the MachO glue. // Note: we use two different macros here: with & without a return value. #define DO_API(r,n,p,a) void n##p { (*fp##n)##a;} #define DO_APIr(r,n,p,a) r n##p { return (r) (*fp##n)##a;} #include "HID_APIs.h" // ================================== pd-hid_0.7/HID Utilities Source/HID_Transaction_Utilities.c0000644000076500007650000002641411504504627022231 0ustar hanshans/* File: HID_Transaction_Utilities.h Contains: Definitions of the HID queue functions for the HID utilites. DRI: George Warner Copyright: Copyright © 2002 Apple Computer, Inc., All Rights Reserved Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. ("Apple") in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this Apple software constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this Apple software. In consideration of your agreement to abide by the following terms, and subject to these terms, Apple grants you a personal, non-exclusive license, under AppleÕs copyrights in this original Apple software (the "Apple Software"), to use, reproduce, modify and redistribute the Apple Software, with or without modifications, in source and/or binary forms; provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Computer, Inc. may be used to endorse or promote products derived from the Apple Software without specific prior written permission from Apple. Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by Apple herein, including but not limited to any patent rights that may be infringed by your derivative works or by other works in which the Apple Software may be incorporated. The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include "HID_Utilities_Internal.h" #include "HID_Utilities_External.h" // ================================== // private functions // creates a transaction for a device, allocates and creates the transaction interface if required static IOReturn hid_CreateTransaction(pRecDevice pDevice) { IOReturn result = kIOReturnSuccess; if (HIDIsValidDevice(pDevice)) { if (NULL == pDevice->transaction) // if we don't already have a transactionÉ { if (NULL != pDevice->interface) // and we do have an interfaceÉ { pDevice->transaction = (void *) (*(IOHIDDeviceInterface**) pDevice->interface)->allocOutputTransaction (pDevice->interface); // alloc Transaction if (pDevice->transaction) // if it was successfulÉ { result = (*(IOHIDOutputTransactionInterface**) pDevice->transaction)->create (pDevice->transaction); // create actual transaction if (kIOReturnSuccess != result) HIDReportErrorNum ("\nFailed to create transaction via create: error = %ld.", result); } else { HIDReportError ("\nhid_CreateTransaction failed to allocOutputTransaction"); if (!result) result = kIOReturnError; // synthesis error } } else HIDReportErrorNum ("\nhid_CreateTransaction failed: Device inteface does not exist.", result); } } return result; } // ================================== // public functions // --------------------------------- // add an element to a Transaction unsigned long HIDTransactionAddElement(pRecDevice pDevice, pRecElement pElement) { IOReturn result = hid_CreateTransaction(pDevice); if (HIDIsValidElement(pDevice,pElement)) { if (pDevice->transaction) { result = (*(IOHIDOutputTransactionInterface**) pDevice->transaction)->addElement (pDevice->transaction,pElement->cookie); // add element if (kIOReturnSuccess != result) HIDReportErrorNum ("\nHIDTransactionAddElement failed to add Element: error = %ld.", result); } else { HIDReportError ("\nHIDTransactionAddElement failed: no transaction interface"); if (!result) result = kIOReturnError; // synthesis error } } return result; } // removes an element from a Transaction unsigned long HIDTransactionRemoveElement(pRecDevice pDevice, pRecElement pElement) { IOReturn result = hid_CreateTransaction(pDevice); if (HIDIsValidElement(pDevice,pElement)) { if (pDevice->transaction) { result = (*(IOHIDOutputTransactionInterface**) pDevice->transaction)->removeElement (pDevice->transaction,pElement->cookie); // remove element if (kIOReturnSuccess != result) HIDReportErrorNum ("\nHIDTransactionRemoveElement failed to remove Element: error = %ld.", result); } else { HIDReportError ("\nHIDTransactionRemoveElement failed: no transaction interface"); if (!result) result = kIOReturnError; // synthesis error } } return result; } // return true if this transaction contains this element Boolean HIDTransactionHasElement(pRecDevice pDevice, pRecElement pElement) { Boolean result = false; if (HIDIsValidElement(pDevice,pElement)) { (void) hid_CreateTransaction(pDevice); if (pDevice->transaction) { result = (*(IOHIDOutputTransactionInterface**) pDevice->transaction)->hasElement (pDevice->transaction,pElement->cookie); // remove element } else { HIDReportError ("\nHIDTransactionHasElement failed: no transaction interface"); } } return result; } /* This changes the default value of an element, when the values of the */ /* elements are cleared, on clear or commit, they are reset to the */ /* default value */ /* This call can be made on elements that are not in the transaction, but */ /* has undefined behavior if made on elements not in the transaction */ /* which are later added to the transaction. */ /* In other words, an element should be added before its default is */ /* set, for well defined behavior. */ unsigned long HIDTransactionSetElementDefault(pRecDevice pDevice, pRecElement pElement,IOHIDEventStruct* pValueEvent) { IOReturn result = hid_CreateTransaction(pDevice); if (HIDIsValidElement(pDevice,pElement)) { if (pDevice->transaction) { result = (*(IOHIDOutputTransactionInterface**) pDevice->transaction)->setElementDefault (pDevice->transaction,pElement->cookie, pValueEvent); if (kIOReturnSuccess != result) HIDReportErrorNum ("\nHIDTransactionSetElementDefault failed to set Element Default: error = %ld.", result); } else { HIDReportError ("\nHIDTransactionSetElementDefault failed: no transaction interface"); if (!result) result = kIOReturnError; // synthesis error } } return result; } /* Get the current setting of an element's default value */ unsigned long HIDTransactionGetElementDefault(pRecDevice pDevice, pRecElement pElement,IOHIDEventStruct* pValueEvent) { IOReturn result = hid_CreateTransaction(pDevice); if (HIDIsValidElement(pDevice,pElement)) { if (pDevice->transaction) { result = (*(IOHIDOutputTransactionInterface**) pDevice->transaction)->getElementDefault (pDevice->transaction,pElement->cookie, pValueEvent); if (kIOReturnSuccess != result) HIDReportErrorNum ("\nHIDTransactionGetElementDefault failed to get Element Default: error = %ld.", result); } else { HIDReportError ("\nHIDTransactionGetElementDefault failed: no transaction interface"); if (!result) result = kIOReturnError; // synthesis error } } return result; } /* Add a change to the transaction, by setting an element value */ /* The change is not actually made until it is commited */ /* The element must be part of the transaction or this call will fail */ unsigned long HIDTransactionSetElementValue(pRecDevice pDevice, pRecElement pElement,IOHIDEventStruct* pValueEvent) { IOReturn result = hid_CreateTransaction(pDevice); if (HIDIsValidElement(pDevice,pElement)) { if (pDevice->transaction) { result = (*(IOHIDOutputTransactionInterface**) pDevice->transaction)->setElementValue (pDevice->transaction,pElement->cookie, pValueEvent); if (kIOReturnSuccess != result) HIDReportErrorNum ("\nHIDTransactionSetElementValue failed to set Element Default: error = %ld.", result); } else { HIDReportError ("\nHIDTransactionSetElementValue failed: no transaction interface"); if (!result) result = kIOReturnError; // synthesis error } } return result; } /* Get the current setting of an element value */ unsigned long HIDTransactionGetElementValue(pRecDevice pDevice, pRecElement pElement,IOHIDEventStruct* pValueEvent) { IOReturn result = hid_CreateTransaction(pDevice); if (HIDIsValidElement(pDevice,pElement)) { if (pDevice->transaction) { result = (*(IOHIDOutputTransactionInterface**) pDevice->transaction)->getElementValue (pDevice->transaction,pElement->cookie, pValueEvent); if (kIOReturnSuccess != result) HIDReportErrorNum ("\nHIDTransactionGetElementValue failed to get Element Default: error = %ld.", result); } else { HIDReportError ("\nHIDTransactionGetElementValue failed: no transaction interface"); if (!result) result = kIOReturnError; // synthesis error } } return result; } /* Commit the transaction, or clear all the changes and start over */ unsigned long HIDTransactionCommit(pRecDevice pDevice) { IOReturn result = hid_CreateTransaction(pDevice); if (HIDIsValidDevice(pDevice)) { if (pDevice->transaction) { #if 0000 // NOTE: this code is to workaround a bug where if you commit transactions // too fast then some of the reports get dropped. // (fixed in 10.2.1) static AbsoluteTime nextTime = {0,0}; // first time this should be no delay if (nextTime.hi || nextTime.lo) MPDelayUntil(&nextTime); #endif result = (*(IOHIDOutputTransactionInterface**) pDevice->transaction)->commit (pDevice->transaction,-1,NULL,NULL,NULL); if (kIOReturnSuccess != result) HIDReportErrorNum ("\nHIDTransactionCommit failed to commit: error = %ld.", result); #if 0000 nextTime = AddDurationToAbsolute(20 * kDurationMillisecond,UpTime()); #endif } else { HIDReportError ("\nHIDTransactionCommit failed: no transaction interface"); if (!result) result = kIOReturnError; // synthesis error } } return result; } /* Clear all the changes and start over */ unsigned long HIDTransactionClear(pRecDevice pDevice) { IOReturn result = hid_CreateTransaction(pDevice); if (HIDIsValidDevice(pDevice)) { if (pDevice->transaction) { result = (*(IOHIDOutputTransactionInterface**) pDevice->transaction)->clear (pDevice->transaction); if (kIOReturnSuccess != result) HIDReportErrorNum ("\nHIDTransactionClear failed to get Element Default: error = %ld.", result); } else { HIDReportError ("\nHIDTransactionClear failed: no transaction interface"); if (!result) result = kIOReturnError; // synthesis error } } return result; } pd-hid_0.7/HID Utilities Source/English.lproj/0000755000076500007650000000000011504505103017556 5ustar hanshanspd-hid_0.7/HID Utilities Source/English.lproj/HID_device_usage_strings.plist0000644000076500007650000003521011504504627025526 0ustar hanshans 1452 516 1:6 Keyboard Name Apple Extended USB Keyboard 770 1:1 Pointer 1:2 Mouse 1:48 X-Axis 1:49 Y-Axis 9:1 Button Name Apple Optical USB Mouse Name Mitsumi Electric 1118 7 1:48 X-Axis 1:49 Y-Axis 9:1 Button A 9:2 Button B 9:3 Button C 9:4 Button X 9:5 Button Y 9:6 Button Z 9:7 Left Trigger 9:8 Right Trigger 9:9 Secondary Option 2 9:10 Secondary Option 1 Name SideWinder Game Pad USB 26 1:48 Wheel 1:49 Left Pedal [Brake] 1:50 Right Pedal [Gas] 9:1 Button A 9:2 Button B 9:3 Button C 9:4 Button X 9:5 Button Y 9:6 Button Z 9:7 Left Trigger 9:8 Right Trigger Name SideWinder Precision Racing Wheel USB v1.0 27 1:48 X-Axis 1:49 Y-Axis 1:53 Rz-Axis 1:54 Throttle 1:57 Hat Switch 9:1 Button 1 [Trigger] 9:2 Button 2 9:3 Button 3 9:4 Button 4 9:5 Button 5 9:6 Button 6 9:7 Button 7 9:8 Button 8 Name SideWinder FFB 2 Joystick 39 1:48 X-Axis 1:49 Y-Axis 9:1 Button 1 9:2 Button 2 9:3 Button 3 9:4 Button 4 9:5 Button 5 9:6 Button 6 Name SideWinder Plug and Play Game Pad 56 1:48 X-Axis 1:49 Y-Axis 1:53 Rz-Axis 1:54 Throttle 1:57 Hat Switch 9:1 Button 1 [Trigger] 9:2 Button 2 9:3 Button 3 9:4 Button 4 9:5 Button 5 9:6 Button 6 9:7 Button 7 9:8 Button 8 Name SideWinder Precision 2 Joystick 60 1:48 X-Axis 1:49 Y-Axis 1:54 Throttle 9:1 Button 1 [Trigger] 9:2 Button 2 9:3 Button 3 9:4 Button 4 9:5 Button 5 9:6 Button 6 9:7 Button 7 9:8 Button 8 Name SideWinder Joystick Name Microsoft 1133 49200 1:1 Pointer 1:2 Mouse 1:48 X-Axis 1:49 Y-Axis 1:56 Wheel 9:1 Left Button 9:2 Right Button 9:3 Middle Button Name iFeel Mouse 49671 1:48 X-Axis 1:49 Y-Axis 1:53 Rz-Axis 1:54 Throttle 1:57 Hat Switch 9:1 Button 1 [Trigger] 9:2 Button 2 9:3 Button 3 9:4 Button 4 9:5 Button 5 9:6 Button 6 9:7 Button 7 Name WingMan Extreme Digital 3D 49797 1:48 X-Axis 1:49 Y-Axis 1:53 Rz-Axis 1:54 Throttle 1:57 Hat Switch 1 65280:2 Thumb Wheel 9:1 Button 1 [Trigger] 9:10 Hat Switch 2 - Up 9:11 Hat Switch 2 - Right 9:12 Hat Switch 2 - Down 9:13 Hat Switch 2 - Left 9:14 Hat Switch 2 - Up Right 9:15 Hat Switch 2 - Down Right 9:16 Hat Switch 2 - Down Left 9:17 Hat Switch 2 - Up Left 9:2 Button 2 9:3 Button 3 9:4 Button 4 9:5 Button 5 9:6 Button 6 9:7 Button 7 9:8 Button 8 9:9 Button 9 Name WingMan Strike Force 3D 49811 1:48 Wheel 1:49 Pedals 9:1 Button 1 9:2 Button 2 9:3 Button 3 9:4 Button 4 9:5 Button 5 9:6 Button 6 65280:1 Left Pedal [Brake] Name WingMan Formula Force GP 50433 1:48 X-Axis 1:49 Y-Axis 1:56 Wheel 9:1 Left Button 9:2 Right Button 9:3 Middle Button Name Cordless Mouse Name Logitech 1293 2051 1:48 Left Stick X-Axis 1:49 Left Stick Y-Axis 1:50 Right Stick Y-Axis 1:53 Right Stick X-Axis 1:57 Direction Pad 9:1 Button 1 9:2 Button 2 9:3 Button 3 9:4 Button 4 9:5 Left Top Trigger 9:6 Left Bottom Trigger 9:7 Right Top Trigger 9:8 Right Bottom Trigger 9:9 ESC 9:10 Mouse 9:11 Eater 9:12 Right Stick Button 9:13 Left Stick Button Name Nostromo n45 Name Belkin 1635 38916 1:48 Left Stick X-Axis 1:49 Left Stick Y-Axis 1:57 Hat Switch 2:186 Right Stick X-Axis 2:187 Right Stick Y-Axis 9:1 Button 1 9:2 Button 2 9:3 Button 3 9:4 Button 4 9:5 L1 Trigger 9:6 R1 Trigger 9:7 L2 Trigger 9:8 R2 Trigger Name FunPad F-107 Name Macsense 8738 16400 9:1 D-Pad Up 9:2 D-Pad Down 9:3 D-Pad Left 9:4 D-Pad Right 9:5 Button 5 (Triangle) 9:6 Button 6 (Circle) 9:7 Button 7 (Cross) 9:8 Button 8 (Square) 9:9 Button C 9:10 Button B [Select] 9:11 Button A [Start] 9:12 Button F 9:13 R1 Trigger 9:14 R2 Trigger 9:15 L1 Trigger 9:16 L2 Trigger 9:17 Left Stick Button 9:18 Right Stick Button 9:19 D Button 9:20 E Button 1:48 Left Stick X-Axis 1:49 Left Stick Y-Axis 1:53 Right Stick X-Axis 1:54 Right Stick Y-Axis Name iShock 16416 1:1 Pointer 1:5 GamePad 1:48 Left Stick X-Axis 1:49 Left Stick Y-Axis 1:53 Right Stick X-Axis 1:54 Right Stick Y-Axis 9:1 D-Pad Up 9:10 Button 2 [Select] 9:11 Button 3 [Start] 9:12 R1 Button 9:13 R2 Trigger 9:14 L1 Trigger 9:15 L2 Trigger 9:16 Left Stick Button 9:17 Right Stick Button 9:2 D-Pad Down 9:3 D-Pad Left 9:4 D-Pad Right 9:5 A Button 9:6 B Button 9:7 C Button 9:8 D Button 9:9 Button 1 Name iShock II FFB Game Controler Name Macally 1699 65284 1:48 Wheel 1:49 Left Pedal [Brake] 1:50 Right Pedal [Gas] 9:1 Top Left Thumb 9:2 Top Right Thumb 9:3 Bottom Left Thumb 9:4 Bottom Right Thumb 9:5 Right Horn 9:6 Left Horn Name R440 Force Feedback Name Saitek 1973 39169 1:48 X-Axis 1:49 Y-Axis 1:54 Throttle 1:57 Hat Switch 9:1 Button 1 [Trigger] 9:2 Button 2 9:3 Button 3 9:4 Button 4 Name X8-33GU 2 IN 1 Joystick Name Saitek 1149 12293 1:48 X-Axis 1:49 Y-Axis 1:50 Throttle 1:57 Hat Switch 9:1 Button 1 [Trigger] 9:2 Button 2 9:3 Button 3 9:4 Button 4 9:5 Button 5 9:6 Button 6 [Thumb Wheel Button] 9:7 Button 7 9:8 Button 8 9:9 Button 9 [Thumb Wheel Left] 9:10 Button 10 [Thumb Wheel Right] Name Eliminator Precision Pro Joystick Name Gravis pd-hid_0.7/HID Utilities Source/English.lproj/HID_cookie_strings.plist0000644000076500007650000001140711504504627024356 0ustar hanshans 1118 Name Microsoft 27 Name SideWinder FFB 2 Joystick 27 Button 1 [Trigger] 28 Button 2 29 Button 3 30 Button 4 31 Button 5 32 Button 6 33 Button 7 34 Button 8 89 X-Axis 90 Y-Axis 91 Rz-Axis 92 Throttle 93 Hat Switch 1133 Name Logitech 49797 Name WingMan Strike Force 3D 5 Button 1 [Trigger] 6 Button 2 7 Button 3 8 Button 4 9 Button 5 10 Button 6 11 Button 7 16 Hat Switch 2 24 X-Axis 25 Y-Axis 26 Hat Switch 1 27 Rz-Axis 28 Throttle 29 Button 9 30 Button 8 1635 Name Macsense 38916 Name FunPad F-107 3 Button 1 4 Button 2 5 Button 3 6 Button 4 7 L1 Trigger 8 R1 Trigger 9 L2 Trigger 10 R2 Trigger 11 Right Stick X-Axis 12 Right Stick Y-Axis 13 Left Stick X-Axis 14 Left Stick Y-Axis 15 Hat Switch 8738 Name Macally 16400 Name iShock 3 D-Pad Up 4 D-Pad Down 5 D-Pad Left 6 D-Pad Right 7 Up Button 8 Right Button 9 Down Button 10 Left Button 11 C Button 12 B Button [Select] 13 A Button [Start] 14 F Button 15 R1 Trigger 16 R2 Trigger 17 L1 Trigger 18 L2 Trigger 19 Left Stick Button 20 Right Stick Button 21 D Button 22 E Button 23 Left Stick X-Axis 24 Left Stick Y-Axis 25 Right Stick X-Axis 26 Right Stick Y-Axis 16416 Name iShock II FFB Game Controler 3 D-Pad Up 4 D-Pad Down 5 D-Pad Left 6 D-Pad Right 7 A Button 8 B Button 9 C Button 10 D Button 11 Button 1 12 Button 2 [Select] 13 Button 3 [Start] 14 R1 Button 15 R2 Trigger 16 L1 Trigger 17 L2 Trigger 18 Left Stick Button 19 Right Stick Button 20 Left Stick X-Axis 21 Left Stick Y-Axis 22 Right Stick X-Axis 23 Right Stick Y-Axis pd-hid_0.7/HID Utilities Source/English.lproj/HID_usage_strings.plist0000644000076500007650000002141211504504627024206 0ustar hanshans 0x0001 Name Generic Desktop 0x0001 Pointer 0x0002 Mouse 0x0004 Joystick 0x0005 GamePad 0x0006 Keyboard 0x0007 Keypad 0x0008 MultiAxisController 0x0030 X 0x0031 Y 0x0032 Z 0x0033 Rx 0x0034 Ry 0x0035 Rz 0x0036 Slider 0x0037 Dial 0x0038 Wheel 0x0039 Hatswitch 0x003A Counted Buffer 0x003B Byte Count 0x003C Motion Wakeup 0x003D Start 0x003E Select 0x0040 Vx 0x0041 Vy 0x0042 Vz 0x0043 Vbrx 0x0044 Vbry 0x0045 Vbrz 0x0046 Vno 0x0080 System Control 0x0081 System Power Down 0x0082 System Sleep 0x0083 System Wake Up 0x0084 SystemContext Menu 0x0085 System Main Menu 0x0086 System App Menu 0x0087 System Menu help 0x0088 System Menu Exit 0x0089 System Menu 0x008A System Menu Right 0x008B System Menu Left 0x008C System Menu Up 0x008D System Menu Down 0x0090 DPad Up 0x0091 DPad Down 0x0092 DPad Right 0x0093 DPad Left 0x0002 Name Simulation 0x0001 Flight Simulation Device 0x0002 Automobile Simulation Device 0x0003 Tank Simulation Device 0x0004 Spaceship Simulation Device 0x0005 Submarine Simulation Device 0x0006 Sailing Simulation Device 0x0007 Motorcycle Simulation Device 0x0008 Sports Simulation Device 0x0009 Airplane Simulation Device 0x000A Helicopter Simulation Device 0x000B Magic Carpet Simulation Device 0x000C Bicycle Simulation Device 0x0020 Flight Control Stick 0x0021 Flight Stick 0x0022 Cyclic Control 0x0023 Cyclic Trim 0x0024 Flight Yoke 0x0025 Track Control 0x00B0 Aileron 0x00B1 Aileron Trim 0x00B2 Anti Torque Control 0x00B5 Collective Control 0x00B6 Dive Brake 0x00B7 Electronic Countermeasures 0x00B8 Elevator 0x00B9 Elevator Trim 0x00BA Rudder 0x00BB Throttle 0x00BC Flight Communications 0x00BD Flare Release 0x00BE Landing Gear 0x00BF Toe Brake 0x00C0 Trigger 0x00C1 Weapons Arm 0x00C2 Weapons 0x00C3 Wing Flaps 0x00C4 Accelerator 0x00C5 Brake 0x00C6 Clutch 0x00C7 Shifter 0x00C8 Steering 0x00C9 Turret Direction 0x00CA Barrel Elevation 0x00CB Dive Plane 0x00CC Ballast 0x00CD Bicycle Crank 0x00CE Handle Bars 0x00CF Front Brake 0x00D0 Rear Brake 0x0003 Name Virtual Reality 0x0001 Belt 0x0002 Body Suit 0x0003 Flexor 0x0004 Glove 0x0005 Head Tracker 0x0006 Head Mounted Display 0x0007 Hand Tracker 0x0008 Oculometer 0x0009 Vest 0x000A Animatronic Device 0x0020 Stereo Enable 0x0021 Display Enable 0x0004 Name Sport 0x0001 Baseball Bat 0x0002 Golf Club 0x0003 Rowing Machine 0x0004 Treadmill 0x0030 Oar 0x0031 Slope 0x0032 Rate 0x0033 Stick Speed 0x0034 Stick Face Angle 0x0035 Stick Heel Or Toe 0x0036 Stick Follow Through 0x0037 Stick Tempo 0x0038 Stick Type 0x0039 Stick Height 0x0050 Putter 0x0051 1 Iron 0x0052 2 Iron 0x0053 3 Iron 0x0054 4 Iron 0x0055 5 Iron 0x0056 6 Iron 0x0057 7 Iron 0x0058 8 Iron 0x0059 9 Iron 0x005A 10 Iron 0x005B 11 Iron 0x005C Sand Wedge 0x005D Loft Wedge 0x005E Power Wedge 0x005F 1 Wood 0x0060 3 Wood 0x0061 5 Wood 0x0062 7 Wood 0x0063 9 Wood 0x0005 Name Game 0x0001 3D Game Controller 0x0002 Pinball Device 0x0003 Gun 0x0020 Point of View 0x0021 Turn Right Or Left 0x0022 Pitch Up Or Down 0x0023 Roll Right Or Left 0x0024 Move Right Or Left 0x0025 Move Forward Or Backward 0x0026 Move Up Or Down 0x0027 Lean Right Or Left 0x0029 Lean Forward Or Backward 0x0029 Height Of POV 0x002A Flipper 0x002B Secondary Flipper 0x002C Bump 0x002D New Game 0x002E Shoot Ball 0x002F Player 0x0030 Gun Bolt 0x0031 Gun Clip 0x0032 Gun 0x0033 Gun Single Shot 0x0034 Gun Burst 0x0035 Gun Automatic 0x0036 Gun Safety 0x0037 Gamepad Fire Or Jump 0x0039 Gamepad Trigger pd-hid_0.7/HID Utilities Source/HID_Config_Utilities.c0000644000076500007650000003414511504504627021151 0ustar hanshans/* File: HID_Config_Utilities.c Contains: Implementation of the HID configuration utilities for the HID utilities. DRI: George Warner Copyright: Copyright © 2002 Apple Computer, Inc., All Rights Reserved Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. ("Apple") in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this Apple software constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this Apple software. In consideration of your agreement to abide by the following terms, and subject to these terms, Apple grants you a personal, non-exclusive license, under AppleÕs copyrights in this original Apple software (the "Apple Software"), to use, reproduce, modify and redistribute the Apple Software, with or without modifications, in source and/or binary forms; provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Computer, Inc. may be used to endorse or promote products derived from the Apple Software without specific prior written permission from Apple. Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by Apple herein, including but not limited to any patent rights that may be infringed by your derivative works or by other works in which the Apple Software may be incorporated. The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include // malloc #include // clock #include #include "HID_Utilities_Internal.h" #include "HID_Utilities_External.h" // --------------------------------- // polls all devices and elements for a change greater than kPercentMove. Times out after given time // returns 1 and pointer to device and element if found // returns 0 and NULL for both parameters if not found unsigned char HIDConfigureAction (pRecDevice * ppDevice, pRecElement * ppElement, float timeout) { long numDevices, maxElements = 0; long * saveValueArray; pRecDevice pDevice = NULL; pRecElement pElement = NULL; short deviceNum = 0; unsigned char found = 0, done = 0; clock_t start = clock (), end; if (!HIDHaveDeviceList ()) // if we do not have a device list if (0 == HIDBuildDeviceList (kHIDPage_GenericDesktop, 0)) // if we could not build another list (use generic page) return 0; // return 0 // build list of device and elements to save current values numDevices = HIDCountDevices (); pDevice = HIDGetFirstDevice (); while (pDevice) { long numElements = HIDCountDeviceElements (pDevice, kHIDElementTypeInput); if (numElements > maxElements) maxElements = numElements; pDevice = HIDGetNextDevice (pDevice); } saveValueArray = (long *) malloc (sizeof (long) * numDevices * maxElements); // 2D array to save values bzero(saveValueArray,sizeof (long) * numDevices * maxElements); // clear array // store current values deviceNum = 0; pDevice = HIDGetFirstDevice (); while (pDevice) { short elementNum = 0; pElement = HIDGetFirstDeviceElement (pDevice, kHIDElementTypeInput); while (pElement) { *(saveValueArray + (deviceNum * maxElements) + elementNum) = HIDGetElementValue (pDevice, pElement); pElement = HIDGetNextDeviceElement (pElement, kHIDElementTypeInput); elementNum++; } pDevice = HIDGetNextDevice (pDevice); deviceNum++; } // poll all devices and elements, compare current value to save +/- kPercentMove while ((!found) && (!done)) { double secs; // are we done? end = clock(); secs = (double)(end - start) / CLOCKS_PER_SEC; if (secs > timeout) done = 1; deviceNum = 0; pDevice = HIDGetFirstDevice (); while (pDevice) { short elementNum = 0; pElement = HIDGetFirstDeviceElement (pDevice, kHIDElementTypeInput); while (pElement) { // ignore force feedback devices AND arrays if ((kHIDPage_PID != pElement->usagePage) && (-1 != pElement->usage)) { long initialValue = *(saveValueArray + (deviceNum * maxElements) + elementNum); long value = HIDGetElementValue (pDevice, pElement); long delta = (float)(pElement->max - pElement->min) * kPercentMove * 0.01; if (((initialValue + delta) < value) || ((initialValue - delta) > value)) { found = 1; break; } } pElement = HIDGetNextDeviceElement (pElement, kHIDElementTypeInput); elementNum++; } if (found) break; pDevice = HIDGetNextDevice (pDevice); deviceNum++; } } // return device and element moved if (found) { *ppDevice = pDevice; *ppElement = pElement; return 1; } else { *ppDevice = NULL; *ppElement = NULL; return 0; } } // --------------------------------- // takes input records, save required info // assume file is open and at correct position. // will always write to file (if file exists) size of recSaveHID, even if device and or element is bad void HIDSaveElementConfig (FILE * fileRef, pRecDevice pDevice, pRecElement pElement, long actionCookie) { recSaveHID saveRec; if (HIDIsValidElement(pDevice,pElement)) { // clear rec bzero(&saveRec,sizeof(recSaveHID)); saveRec.actionCookie = actionCookie; // must save // actionCookie // Device: serial,vendorID, productID, location, usagePage, usage // Element: cookie, usagePage, usage, // need to add serial number when I have a test case saveRec.vendorID = pDevice->vendorID; saveRec.productID = pDevice->productID; saveRec.locID = pDevice->locID; saveRec.usage = pDevice->usage; saveRec.usagePage = pDevice->usagePage; saveRec.usagePageE = pElement->usagePage; saveRec.usageE = pElement->usage; saveRec.cookie = pElement->cookie; // write to file if (fileRef) fwrite ((void *)&saveRec, sizeof (recSaveHID), 1, fileRef); } } // --------------------------------- // take file, read one record (assume file position is correct and file is open) // search for matching device // return pDevice, pElement and cookie for action long HIDRestoreElementConfig (FILE * fileRef, pRecDevice * ppDevice, pRecElement * ppElement) { // Device: serial,vendorID, productID, location, usagePage, usage // Element: cookie, usagePage, usage, pRecDevice pDevice, pFoundDevice = NULL; pRecElement pElement, pFoundElement = NULL; recSaveHID restoreRec; fread ((void *) &restoreRec, 1, sizeof (recSaveHID), fileRef); // compare to current device list for matches // look for device if (restoreRec.locID && restoreRec.vendorID && restoreRec.productID) { // look for specific device type plug in to same port pDevice = HIDGetFirstDevice (); while (pDevice) { if ((restoreRec.locID == pDevice->locID) && (restoreRec.vendorID == pDevice->vendorID) && (restoreRec.productID == pDevice->productID)) pFoundDevice = pDevice; if (pFoundDevice) break; pDevice = HIDGetNextDevice (pDevice); } if (pFoundDevice) { pElement = HIDGetFirstDeviceElement (pFoundDevice, kHIDElementTypeIO); while (pElement) { if (restoreRec.cookie == pElement->cookie) pFoundElement = pElement; if (pFoundElement) break; pElement = HIDGetNextDeviceElement (pElement, kHIDElementTypeIO); } // if no cookie match (should NOT occur) match on usage pElement = HIDGetFirstDeviceElement (pFoundDevice, kHIDElementTypeIO); while (pElement) { if ((restoreRec.usageE == pElement->usage) && (restoreRec.usagePageE == pElement->usagePage)) pFoundElement = pElement; if (pFoundElement) break; pElement = HIDGetNextDeviceElement (pElement, kHIDElementTypeIO); } } } // if we have not found a match, look at just vendor and product if ((NULL == pFoundDevice) && (restoreRec.vendorID && restoreRec.productID)) { pDevice = HIDGetFirstDevice (); while (pDevice) { if ((restoreRec.vendorID == pDevice->vendorID) && (restoreRec.productID == pDevice->productID)) pFoundDevice = pDevice; if (pFoundDevice) break; pDevice = HIDGetNextDevice (pDevice); } // match elements by cookie since same device type if (pFoundDevice) { pElement = HIDGetFirstDeviceElement (pFoundDevice, kHIDElementTypeIO); while (pElement) { if (restoreRec.cookie == pElement->cookie) pFoundElement = pElement; if (pFoundElement) break; pElement = HIDGetNextDeviceElement (pElement, kHIDElementTypeIO); } // if no cookie match (should NOT occur) match on usage pElement = HIDGetFirstDeviceElement (pFoundDevice, kHIDElementTypeIO); while (pElement) { if ((restoreRec.usageE == pElement->usage) && (restoreRec.usagePageE == pElement->usagePage)) pFoundElement = pElement; if (pFoundElement) break; pElement = HIDGetNextDeviceElement (pElement, kHIDElementTypeIO); } } } // if we have not found a match look for just same type of device if ((NULL == pFoundDevice) && (restoreRec.usage && restoreRec.usagePage)) { pDevice = HIDGetFirstDevice (); while (pDevice) { if ((restoreRec.usage == pDevice->usage) && (restoreRec.usagePage == pDevice->usagePage)) pFoundDevice = pDevice; if (pFoundDevice) break; pDevice = HIDGetNextDevice (pDevice); } // match elements by type if (pFoundDevice) { pElement = HIDGetFirstDeviceElement (pFoundDevice, kHIDElementTypeIO); while (pElement) { if ((restoreRec.usageE == pElement->usage) && (restoreRec.usagePageE == pElement->usagePage)) pFoundElement = pElement; if (pFoundElement) break; pElement = HIDGetNextDeviceElement (pElement, kHIDElementTypeIO); } } } // if still not found just get first device if (NULL == pFoundDevice) { pFoundDevice = HIDGetFirstDevice (); // match elements by type if (pFoundDevice) { pElement = HIDGetFirstDeviceElement (pFoundDevice, kHIDElementTypeIO); while (pElement) { if ((restoreRec.usageE == pElement->usage) && (restoreRec.usagePageE == pElement->usagePage)) pFoundElement = pElement; if (pFoundElement) break; pElement = HIDGetNextDeviceElement (pElement, kHIDElementTypeIO); } } } if ((NULL == pFoundDevice) || (NULL == pFoundElement)) { // no HID device *ppDevice = NULL; *ppElement = NULL; return restoreRec.actionCookie; } else { // no HID device *ppDevice = pFoundDevice; *ppElement = pFoundElement; return restoreRec.actionCookie; } } // --------------------------------- // Find the specified preference in the specified application // search for matching device and element // return pDevice, pElement that matches Boolean HIDRestoreElementPref (CFStringRef keyCFStringRef, CFStringRef appCFStringRef, pRecDevice * ppDevice, pRecElement * ppElement) { Boolean found = false; if ((NULL != keyCFStringRef) && (NULL != appCFStringRef) && (NULL != ppDevice) && (NULL != ppElement)) { CFPropertyListRef prefCFPropertyListRef = CFPreferencesCopyAppValue(keyCFStringRef, appCFStringRef); if (NULL != prefCFPropertyListRef) { if (CFStringGetTypeID() == CFGetTypeID(prefCFPropertyListRef)) { char buffer[256]; if (CFStringGetCString((CFStringRef) prefCFPropertyListRef, buffer, sizeof(buffer), kCFStringEncodingASCII)) { recDevice searchDevice; recElement searchElement; int count = sscanf(buffer, "d:{v:%ld, p:%ld, l:%ld, p:%ld, u:%ld}, e:{t:%ld, p:%ld, u:%ld, c:%ld}", &searchDevice.vendorID, &searchDevice.productID, &searchDevice.locID, &searchDevice.usagePage, &searchDevice.usage, &searchElement.type, &searchElement.usagePage, &searchElement.usage, (long*) &searchElement.cookie); if (9 == count) // if we found all nine parametersÉ { // and can find a device & element that matches theseÉ if (HIDFindActionDeviceAndElement(&searchDevice, &searchElement,ppDevice, ppElement)) { found = true; } } } } else { // We found the entry with this key but it's the wrong type; delete it. CFPreferencesSetAppValue(keyCFStringRef, NULL, appCFStringRef); (void) CFPreferencesAppSynchronize(appCFStringRef); } CFRelease(prefCFPropertyListRef); } } return found; } // --------------------------------- // Save the device & element values into the specified key in the specified applications preferences Boolean HIDSaveElementPref (const CFStringRef keyCFStringRef, CFStringRef appCFStringRef, pRecDevice pDevice, pRecElement pElement) { Boolean success = false; if ((NULL != keyCFStringRef) && (NULL != appCFStringRef) && HIDIsValidElement(pDevice,pElement)) { CFStringRef prefCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("d:{v:%ld, p:%ld, l:%ld, p:%ld, u:%ld}, e:{t:%ld, p:%ld, u:%ld, c:%ld}"), pDevice->vendorID, pDevice->productID, pDevice->locID, pDevice->usagePage, pDevice->usage, pElement->type, pElement->usagePage, pElement->usage, pElement->cookie); if (NULL != prefCFStringRef) { CFPreferencesSetAppValue(keyCFStringRef, prefCFStringRef, kCFPreferencesCurrentApplication); CFRelease(prefCFStringRef); success = true; } } return success; } pd-hid_0.7/HID Utilities Source/ImmrHIDUtilAddOn.c0000644000076500007650000000515011504504627020214 0ustar hanshans/* * ImmrHIDUtilAddOn.c * UseFFAPIFromHIDUtilities * * Created by rlacroix on Wed Oct 16 2002. * Copyright (c) 2002 Immersion Corporation. All rights reserved. * */ #include #include #include #include #include #include #include "HID_Utilities_External.h" #include "ImmrHIDUtilAddOn.h" //--------------------------------------------------------------------------------- // // AllocateHIDObjectFromRecDevice() // // returns: // NULL, or acceptable io_object_t // //--------------------------------------------------------------------------------- io_service_t AllocateHIDObjectFromRecDevice( pRecDevice pDevice ) { CFMutableDictionaryRef matchingDict; UInt32 locationID = pDevice->locID; CFNumberRef refUsage = NULL; mach_port_t masterPort = NULL; IOReturn result = kIOReturnSuccess; io_service_t hidDevice = NULL; do // while( 0 ) { result = IOMasterPort (bootstrap_port, &masterPort); if( result != kIOReturnSuccess ) { break; } // Set up the matching criteria for the devices we're interested in. // We are interested in instances of class IOHIDDevice. // matchingDict is consumed below (in IOServiceGetMatchingService) // so we have no leak here. // matchingDict = IOServiceMatching(kIOHIDDeviceKey); if (!matchingDict) { break; } // Add a key for locationID to our matching dictionary. This works for matching to // IOHIDDevices, so we will only look for a device attached to that particular port // on the machine. // refUsage = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &locationID); CFDictionaryAddValue( matchingDict, CFSTR(kIOHIDLocationIDKey), refUsage); CFRelease(refUsage); // IOServiceGetMatchingService assumes that we already know that there is only one device // that matches. This way we don't have to do the whole iteration dance to look at each // device that matches. This is a new API in 10.2 // hidDevice = IOServiceGetMatchingService( masterPort, matchingDict); } while( 0 ); // Free master port if we created one. // if (masterPort) mach_port_deallocate(mach_task_self(), masterPort); return hidDevice; } //--------------------------------------------------------------------------------- // // FreeHIDObject() // //--------------------------------------------------------------------------------- bool FreeHIDObject( io_service_t hidDevice ) { kern_return_t kr; kr = IOObjectRelease(hidDevice); return( kIOReturnSuccess == kr ); }pd-hid_0.7/HID Utilities Source/HID_APIs.h0000644000076500007650000002550411504504627016511 0ustar hanshans /* File: HID_APIs.h Contains: Definition of the HID Utilities exported API's DRI: George Warner Copyright: Copyright © 2002 Apple Computer, Inc., All Rights Reserved Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. ("Apple") in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this Apple software constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this Apple software. In consideration of your agreement to abide by the following terms, and subject to these terms, Apple grants you a personal, non-exclusive license, under AppleÕs copyrights in this original Apple software (the "Apple Software"), to use, reproduce, modify and redistribute the Apple Software, with or without modifications, in source and/or binary forms; provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Computer, Inc. may be used to endorse or promote products derived from the Apple Software without specific prior written permission from Apple. Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by Apple herein, including but not limited to any patent rights that may be infringed by your derivative works or by other works in which the Apple Software may be incorporated. The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ // ---------------------------------------------------------------- // The DO_API micro takes four parameters: // #define DO_API(r,n,p,a) // r - what the API Returns // n - the Name of the API // p - the Parameters to the API // a - the Arguments passed by the API // // DO_APIr is used when an API returns a value. // DO_API is used when an API doesn't return a value. // // For example: // // if you have a routine that doesn't return a value: // // void MyFunction(const UInt32 pSelector, void* pPtr); // // It's macro would look like this: // // DO_API( // void, // this is what the function returns // MyFunction, // this is its Name // (const UInt32 pSelector, void* pPtr), // these are its parameters // (pSelector, pPtr)) // and these are just the arguments (no type info) // // If it returns a value like this // // OSStatus MyFunction2(const UInt32 pSelector, void* pPtr); // // It's macro would look like this: // // DO_APIr( // OSStatus, // this is what the function returns // MyFunction2, // this is its Name // (const UInt32 pSelector, void* pPtr), // these are its parameters // (pSelector, pPtr)) // and these are just the arguments (no type info) // #ifndef DO_API // if this isn't definedÉ #define DO_API // É then don't do anything. #endif #ifndef DO_APIr // if this isn't definedÉ #define DO_APIr DO_API // É then do the same as DO_API #endif DO_APIr(Boolean, HIDBuildDeviceList, (UInt32 usagePage, UInt32 usage), (usagePage, usage)) DO_APIr(Boolean, HIDFindActionDeviceAndElement, (const pRecDevice pSearchDevice, const pRecElement pSearchElement,pRecDevice *ppFoundDevice, pRecElement *ppFoundElement), (pSearchDevice, pSearchElement,ppFoundDevice, ppFoundElement)) DO_APIr(Boolean, HIDFindDevice, (const pRecDevice pSearchDevice, pRecDevice *ppFoundDevice), (pSearchDevice, ppFoundDevice)) DO_APIr(Boolean, HIDFindSubElement, (const pRecElement pStartElement, const pRecElement pSearchElement, pRecElement *ppFoundElement), (pStartElement, pSearchElement, ppFoundElement)) DO_APIr(Boolean, HIDGetElementNameFromVendorProductCookie, (const long vendorID, const long productID, const long cookie, char * pName), (vendorID, productID, cookie, pName)) DO_APIr(Boolean, HIDGetElementNameFromVendorProductUsage, (const long vendorID, const long productID, const long pUsagePage, const long pUsage, char * pName), (vendorID, productID, pUsagePage, pUsage, pName)) DO_APIr(Boolean, HIDHaveDeviceList, (void), ()) DO_APIr(Boolean, HIDIsValidDevice, (const pRecDevice pSearchDevice), (pSearchDevice)) DO_APIr(Boolean, HIDIsValidElement, (const pRecDevice pSearchDevice, const pRecElement pSearchElement), (pSearchDevice, pSearchElement)) DO_APIr(Boolean, HIDRestoreElementPref, (CFStringRef keyCFStringRef, CFStringRef appCFStringRef, pRecDevice * ppDevice, pRecElement * ppElement), (keyCFStringRef, appCFStringRef, ppDevice, ppElement)) DO_APIr(Boolean, HIDSaveElementPref, (CFStringRef keyCFStringRef, CFStringRef appCFStringRef, pRecDevice pDevice, pRecElement pElement), (keyCFStringRef, appCFStringRef, pDevice, pElement)) DO_APIr(Boolean, HIDTransactionHasElement, (pRecDevice pDevice, pRecElement pElement), (pDevice, pElement)) DO_APIr(HIDElementTypeMask, HIDConvertElementTypeToMask, (const long type), (type)) DO_APIr(int, HIDPrintElement, (const pRecElement pElement), (pElement)) DO_APIr(long, HIDGetElementValue, (pRecDevice pDevice, pRecElement pElement), (pDevice, pElement)) //DO_APIr(long, HIDGetReport, (pRecDevice pDevice,const IOHIDReportType reportType, const unsigned long reportID, void* reportBuffer, unsigned long* reportBufferSize), (pDevice,reportType, reportID, reportBuffer, reportBufferSize)) DO_APIr(long, HIDRestoreElementConfig, (FILE * fileRef, pRecDevice * ppDevice, pRecElement * ppElement), (fileRef, ppDevice, ppElement)) DO_APIr(long, HIDSetElementValue, (pRecDevice pDevice, pRecElement pElement,void* pIOHIDEvent), (pDevice, pElement,pIOHIDEvent)) DO_APIr(long, HIDSetQueueCallback, (pRecDevice pDevice, IOHIDCallbackFunction callback,void* callbackTarget, void* callbackRefcon), (pDevice, callback,callbackTarget, callbackRefcon)) //DO_APIr(long, HIDSetReport, (pRecDevice pDevice,const IOHIDReportType reportType, const unsigned long reportID, void* reportBuffer, const unsigned long reportBufferSize),(pDevice,reportType, reportID, reportBuffer, reportBufferSize)) DO_APIr(pRecDevice, HIDGetFirstDevice, (void), ()) DO_APIr(pRecDevice, HIDGetNextDevice, (pRecDevice pDevice), (pDevice)) DO_APIr(pRecElement, HIDGetFirstDeviceElement, (pRecDevice pDevice, HIDElementTypeMask typeMask), (pDevice, typeMask)) DO_APIr(pRecElement, HIDGetNextDeviceElement, (pRecElement pElement, HIDElementTypeMask typeMask), (pElement, typeMask)) DO_APIr(pRecElement, HIDGetPreviousDeviceElement, (pRecElement pElement, HIDElementTypeMask typeMask), (pElement, typeMask)) DO_APIr(SInt32, HIDCalibrateValue, (SInt32 value, pRecElement pElement), (value, pElement)) DO_APIr(SInt32, HIDScaleValue, (SInt32 value, pRecElement pElement), (value, pElement)) DO_APIr(UInt32, HIDCountDeviceElements, (pRecDevice pDevice, HIDElementTypeMask typeMask), (pDevice, typeMask)) DO_APIr(UInt32, HIDCountDevices, (void), ()) DO_APIr(unsigned char, HIDConfigureAction, (pRecDevice * ppDevice, pRecElement * ppElement, float timeout), (ppDevice, ppElement, timeout)) DO_APIr(unsigned char, HIDGetEvent, (pRecDevice pDevice, void * pHIDEvent), (pDevice, pHIDEvent)) DO_APIr(unsigned long, HIDQueueElement, (pRecDevice pDevice, pRecElement pElement), (pDevice, pElement)) DO_APIr(unsigned long, HIDCloseReleaseInterface, (pRecDevice pDevice), (pDevice)) DO_APIr(unsigned long, HIDCreateOpenDeviceInterface, (UInt32 hidDevice, pRecDevice pDevice), (hidDevice, pDevice)) DO_APIr(unsigned long, HIDDequeueDevice, (pRecDevice pDevice), (pDevice)) DO_APIr(unsigned long, HIDDequeueElement, (pRecDevice pDevice, pRecElement pElement), (pDevice, pElement)) DO_APIr(unsigned long, HIDQueueDevice, (pRecDevice pDevice), (pDevice)) DO_APIr(unsigned long, HIDReleaseAllDeviceQueues, (void), ()) DO_APIr(unsigned long, HIDTransactionAddElement, (pRecDevice pDevice, pRecElement pElement), (pDevice, pElement)) DO_APIr(unsigned long, HIDTransactionClear, (pRecDevice pDevice), (pDevice)) DO_APIr(unsigned long, HIDTransactionCommit, (pRecDevice pDevice), (pDevice)) DO_APIr(unsigned long, HIDTransactionGetElementDefault, (pRecDevice pDevice, pRecElement pElement,IOHIDEventStruct* pValueEvent), (pDevice, pElement,pValueEvent)) DO_APIr(unsigned long, HIDTransactionGetElementValue, (pRecDevice pDevice, pRecElement pElement,IOHIDEventStruct* pValueEvent), (pDevice, pElement,pValueEvent)) DO_APIr(unsigned long, HIDTransactionRemoveElement, (pRecDevice pDevice, pRecElement pElement), (pDevice, pElement)) DO_APIr(unsigned long, HIDTransactionSetElementDefault, (pRecDevice pDevice, pRecElement pElement,IOHIDEventStruct* pValueEvent), (pDevice, pElement,pValueEvent)) DO_APIr(unsigned long, HIDTransactionSetElementValue, (pRecDevice pDevice, pRecElement pElement,IOHIDEventStruct* pValueEvent), (pDevice, pElement,pValueEvent)) DO_API(void, HIDGetTypeName, (IOHIDElementType theType, char * cstrName), (theType, cstrName)) DO_API(void, HIDGetUsageName, (long valueUsagePage, long valueUsage, char * cstrName), (valueUsagePage, valueUsage, cstrName)) DO_API(void, HIDReleaseDeviceList, (void), ()) DO_API(void, HIDSaveElementConfig, (FILE * fileRef, pRecDevice pDevice, pRecElement pElement, long actionCookie), (fileRef, pDevice, pElement, actionCookie)) DO_APIr(io_object_t, AllocateHIDObjectFromRecDevice,(pRecDevice pDevice),(pDevice)) DO_APIr(Boolean, FreeHIDObject,(io_object_t hidDevice), (hidDevice)) #undef DO_API #undef DO_APIr pd-hid_0.7/HID Utilities Source/HID_Name_Lookup.c0000644000076500007650000003220311504504627020113 0ustar hanshans/* File: HID_Name_Lookup.c Contains: Implementation of the HID device name lookup functions for the HID utilites. DRI: George Warner Copyright: Copyright © 2002 Apple Computer, Inc., All Rights Reserved Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. ("Apple") in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this Apple software constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this Apple software. In consideration of your agreement to abide by the following terms, and subject to these terms, Apple grants you a personal, non-exclusive license, under AppleÕs copyrights in this original Apple software (the "Apple Software"), to use, reproduce, modify and redistribute the Apple Software, with or without modifications, in source and/or binary forms; provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Computer, Inc. may be used to endorse or promote products derived from the Apple Software without specific prior written permission from Apple. Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by Apple herein, including but not limited to any patent rights that may be infringed by your derivative works or by other works in which the Apple Software may be incorporated. The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "HID_Utilities_Internal.h" #include "HID_Name_Lookup.h" #define FAKE_IT 1 // set true for debugging; returns the vendor, product & cookie (or usage info) as numbers. // --------------------------------- // Load the element strings from the given resource (XML) file into a CFPropertyListRef static CFPropertyListRef xml_load(const CFStringRef pResourceName,const CFStringRef pResourceExtension) { CFPropertyListRef tCFPropertyListRef = NULL; CFURLRef resFileCFURLRef = CFBundleCopyResourceURL(CFBundleGetMainBundle(), pResourceName, pResourceExtension, NULL); if (NULL != resFileCFURLRef) { CFDataRef resCFDataRef; if (CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault, resFileCFURLRef, &resCFDataRef, nil, nil, nil)) { if (NULL != resCFDataRef) { CFStringRef errorString; tCFPropertyListRef = CFPropertyListCreateFromXMLData(kCFAllocatorDefault, resCFDataRef, kCFPropertyListImmutable, &errorString); if (NULL == tCFPropertyListRef) CFShow(errorString); CFRelease(resCFDataRef); } } CFRelease(resFileCFURLRef); } return tCFPropertyListRef; } // --------------------------------- // Find an element string in the resource (XML) file static Boolean xml_search_cookie(const long pVendorID, const long pProductID, const long pCookie, char* pCstr) { static CFPropertyListRef tCFPropertyListRef = NULL; Boolean results = false; if (NULL == tCFPropertyListRef) tCFPropertyListRef = xml_load(CFSTR("HID_cookie_strings"), CFSTR("plist")); if (NULL != tCFPropertyListRef) { if (CFDictionaryGetTypeID() == CFGetTypeID(tCFPropertyListRef)) { CFDictionaryRef vendorCFDictionaryRef; CFStringRef vendorKeyCFStringRef; vendorKeyCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%ld"), pVendorID); if (CFDictionaryGetValueIfPresent(tCFPropertyListRef, vendorKeyCFStringRef, (const void**) &vendorCFDictionaryRef)) { CFDictionaryRef productCFDictionaryRef; CFStringRef productKeyCFStringRef; CFStringRef vendorCFStringRef; if (CFDictionaryGetValueIfPresent(vendorCFDictionaryRef, CFSTR("Name"), (const void**) &vendorCFStringRef)) { //CFShow(vendorCFStringRef); } productKeyCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%ld"), pProductID); if (CFDictionaryGetValueIfPresent(vendorCFDictionaryRef, productKeyCFStringRef, (const void**) &productCFDictionaryRef)) { CFStringRef fullCFStringRef = NULL; CFStringRef cookieKeyCFStringRef; CFStringRef productCFStringRef; CFStringRef cookieCFStringRef; if (CFDictionaryGetValueIfPresent(productCFDictionaryRef, CFSTR("Name"), (const void**) &productCFStringRef)) { //CFShow(productCFStringRef); } cookieKeyCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%ld"), pCookie); if (CFDictionaryGetValueIfPresent(productCFDictionaryRef, cookieKeyCFStringRef, (const void**) &cookieCFStringRef)) { fullCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%@ %@ %@"), vendorCFStringRef, productCFStringRef, cookieCFStringRef); // CFShow(cookieCFStringRef); } #if FAKE_IT else { fullCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%@ %@ #%@"), vendorCFStringRef, productCFStringRef, cookieKeyCFStringRef); } #endif if (fullCFStringRef) { // CFShow(fullCFStringRef); results = CFStringGetCString( fullCFStringRef, pCstr, CFStringGetLength(fullCFStringRef) * sizeof(UniChar) + 1, kCFStringEncodingMacRoman); CFRelease(fullCFStringRef); } CFRelease(cookieKeyCFStringRef); } CFRelease(productKeyCFStringRef); } CFRelease(vendorKeyCFStringRef); } //++CFRelease(tCFPropertyListRef); // Leak this! } return results; } // --------------------------------- // Find an element string in the resource (XML) file static Boolean xml_search_usage(const long pVendorID, const long pProductID, const long pUsagePage, const long pUsage, char* pCstr) { static CFPropertyListRef tCFPropertyListRef = NULL; Boolean results = false; if (NULL == tCFPropertyListRef) tCFPropertyListRef = xml_load(CFSTR("HID_device_usage_strings"), CFSTR("plist")); if (NULL != tCFPropertyListRef) { if (CFDictionaryGetTypeID() == CFGetTypeID(tCFPropertyListRef)) { CFDictionaryRef vendorCFDictionaryRef; CFStringRef vendorKeyCFStringRef; vendorKeyCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%ld"), pVendorID); if (CFDictionaryGetValueIfPresent(tCFPropertyListRef, vendorKeyCFStringRef, (const void**) &vendorCFDictionaryRef)) { CFDictionaryRef productCFDictionaryRef; CFStringRef productKeyCFStringRef; CFStringRef vendorCFStringRef; if (!CFDictionaryGetValueIfPresent(vendorCFDictionaryRef, CFSTR("Name"), (const void**) &vendorCFStringRef)) { vendorCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("v: %ld"), pVendorID); //CFShow(vendorCFStringRef); } productKeyCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%ld"), pProductID); if (CFDictionaryGetValueIfPresent(vendorCFDictionaryRef, productKeyCFStringRef, (const void**) &productCFDictionaryRef)) { CFStringRef fullCFStringRef = NULL; CFStringRef usageKeyCFStringRef; CFStringRef productCFStringRef; CFStringRef usageCFStringRef; if (CFDictionaryGetValueIfPresent(productCFDictionaryRef, CFSTR("Name"), (const void**) &productCFStringRef)) { //CFShow(productCFStringRef); } usageKeyCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%ld:%ld"), pUsagePage, pUsage); if (CFDictionaryGetValueIfPresent(productCFDictionaryRef, usageKeyCFStringRef, (const void**) &usageCFStringRef)) { fullCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%@ %@ %@"), vendorCFStringRef, productCFStringRef, usageCFStringRef); // CFShow(usageCFStringRef); } #if FAKE_IT else { fullCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%@ %@ #%@"), vendorCFStringRef, productCFStringRef, usageKeyCFStringRef); } #endif if (fullCFStringRef) { // CFShow(fullCFStringRef); results = CFStringGetCString( fullCFStringRef, pCstr, CFStringGetLength(fullCFStringRef) * sizeof(UniChar) + 1, kCFStringEncodingMacRoman); CFRelease(fullCFStringRef); } CFRelease(usageKeyCFStringRef); } CFRelease(productKeyCFStringRef); } CFRelease(vendorKeyCFStringRef); } //++CFRelease(tCFPropertyListRef); // Leak this! } return results; } // --------------------------------- // set name from vendor id/product id look up Boolean HIDGetElementNameFromVendorProductCookie (const long pVendorID, const long pProductID, const long pCookie, char * pName) { Boolean result = false; *pName = 0; // clear name if (xml_search_cookie(pVendorID, pProductID, pCookie, pName)) return true; switch (pVendorID) { case kMacally: switch (pProductID) { case kiShock: result = true; switch (pCookie) { case 3: sprintf(pName, "D-Pad Up"); break; case 4: sprintf(pName, "D-Pad Down"); break; case 5: sprintf(pName, "D-Pad Left"); break; case 6: sprintf(pName, "D-Pad Right"); break; case 7: sprintf(pName, "Up Button"); break; case 8: sprintf(pName, "Right Button"); break; case 9: sprintf(pName, "Down Button"); break; case 10: sprintf(pName, "Left Button"); break; case 11: sprintf(pName, "C Button"); break; case 12: sprintf(pName, "B Button [Select]"); break; case 13: sprintf(pName, "A Button [Start]"); break; case 14: sprintf(pName, "F Button"); break; case 15: sprintf(pName, "R1 Trigger"); break; case 16: sprintf(pName, "R2 Trigger"); break; case 17: sprintf(pName, "L1 Trigger"); break; case 18: sprintf(pName, "L2 Trigger"); break; case 19: sprintf(pName, "Left Stick Button"); break; case 20: sprintf(pName, "Right Stick Button"); break; case 21: sprintf(pName, "D Button"); break; case 22: sprintf(pName, "E Button"); break; case 23: sprintf(pName, "Left Stick X-Axis"); break; case 24: sprintf(pName, "Left Stick Y-Axis"); break; case 25: sprintf(pName, "Right Stick X-Axis"); break; case 26: sprintf(pName, "Right Stick Y-Axis"); break; default: #if FAKE_IT sprintf(pName, "#{V:Macally, P:iShock, C:%ld}#", pCookie); #else result = false; #endif FAKE_IT break; } break; default: #if FAKE_IT sprintf(pName, "#{V:Macally, P:%ld, C:%ld}#", pProductID, pCookie); break; #else result = false; #endif FAKE_IT break; } break; case kMacsense: switch (pProductID) { case kFunPadF107: result = true; switch (pCookie) { case 3: sprintf(pName, "Button 1"); break; case 4: sprintf(pName, "Button 2"); break; case 5: sprintf(pName, "Button 3"); break; case 6: sprintf(pName, "Button 4"); break; case 7: sprintf(pName, "L1 Trigger"); break; case 8: sprintf(pName, "R1 Trigger"); break; case 9: sprintf(pName, "L2 Trigger"); break; case 10: sprintf(pName, "R2 Trigger"); break; case 11: sprintf(pName, "Right Stick X-Axis"); break; case 12: sprintf(pName, "Right Stick Y-Axis"); break; case 13: sprintf(pName, "Left Stick X-Axis"); break; case 14: sprintf(pName, "Left Stick Y-Axis"); break; case 15: sprintf(pName, "Hat Switch"); break; default: #if FAKE_IT sprintf(pName, "#{V:Macsense, P:FunPad F-107, C:%ld}#", pCookie); #else result = false; #endif FAKE_IT break; } default: #if FAKE_IT sprintf(pName, "#{V:Macsense, P:%ld, C:%ld}#", pProductID, pCookie); #else result = false; #endif FAKE_IT break; } break; default: #if FAKE_IT sprintf(pName, "#{V:%ld, P:%ld, C:%ld}#", pVendorID, pProductID, pCookie); #else result = false; #endif FAKE_IT break; } return result; } // --------------------------------- // set name from vendor id/product id & usage look up Boolean HIDGetElementNameFromVendorProductUsage (const long pVendorID, const long pProductID, const long pUsagePage, const long pUsage, char * pName) { Boolean result = false; *pName = 0; // clear name if (xml_search_usage(pVendorID, pProductID, pUsagePage, pUsage, pName)) return true; #if FAKE_IT sprintf(pName, "#{V:%ld, P:%ld, U:%ld:%ld}#", pVendorID, pProductID, pUsagePage, pUsage); result = true; #endif return result; } pd-hid_0.7/buttongate-help.pd0000644000076500007650000000361311504504627014723 0ustar hanshans#N canvas 0 31 463 514 10; #X obj 5 2 cnv 15 450 20 empty empty buttongate 2 11 1 18 -233017 -66577 0; #X obj 160 287 bng 25 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; #X obj 160 151 loadbang; #X msg 160 171 1; #X obj 160 199 metro 150; #X text 27 470 (C) Copyright 2004 Hans-Christoph Steiner ; #X text 244 484 released under the GNU GPL; #X obj 223 417 pddp/pddplink ../all_about_hid.pd -text all_about_hid ; #X text 114 418 For more info:; #X text 17 38 [buttongate] is a simple gate controlled by a HID button. You must specify the device and the button which controls the gate. The left inlet takes the data to be gated. The right inlet is for sending optional control messages to the HID.; #X obj 160 244 buttongate 0 btn_0; #X text 18 119 The first button on the first device controls this gate: ; #X text 15 237 data to be gated -->; #X text 292 237 <-- msgs to [hid]; #X obj 281 288 bng 25 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; #X msg 310 197 refresh; #X msg 299 176 open 2; #X text 39 294 button pressed->; #X text 310 293 <-- button released; #X text 23 348 Keyboard keys can also be used to control this object. You can get the [hid] keycode from here:; #X obj 324 368 ev_key-list; #X obj 422 3 pddp/pddplink http://puredata.info/dev/pddp -text pddp ; #N canvas 504 253 494 344 META 0; #X text 12 165 HELP_PATCH_AUTHORS "pd meta" information added by Jonathan Wilkes for Pd version 0.42.; #X text 12 25 LICENSE GPL; #X text 12 145 AUTHOR Hans-Christoph Steiner; #X text 12 45 DESCRIPTION simple gate controlled by a HID button; #X text 12 65 INLET_0 bang; #X text 12 85 INLET_1 open refresh; #X text 12 105 OUTLET_0 bang; #X text 12 125 OUTLET_1 bang; #X text 12 5 KEYWORDS control user_input abstraction; #X restore 406 463 pd META; #X connect 2 0 3 0; #X connect 3 0 4 0; #X connect 4 0 10 0; #X connect 10 0 1 0; #X connect 10 1 14 0; #X connect 15 0 10 1; #X connect 16 0 10 1; pd-hid_0.7/deg2hid-help.pd0000644000076500007650000000244411504504627014056 0ustar hanshans#N canvas 0 31 483 323 10; #X obj 5 2 cnv 15 450 20 empty empty deg2hid 2 11 1 18 -233017 -66577 0; #X obj 422 3 pddp/pddplink http://puredata.info/dev/pddp -text pddp ; #X text 254 269 released under the GNU GPL; #X text 185 228 For more info:; #X text 40 254 (C) Copyright 2005 Hans-Christoph Steiner ; #X text 290 159 related objects:; #X obj 323 184 hid/rad2hid; #X floatatom 56 203 7 0 0 1 - - -; #X obj 59 103 hsl 300 15 -720 720 0 0 empty empty degrees 6 7 1 10 -262131 -1 -1 0 0; #X floatatom 82 133 5 0 0 0 - - -; #X text 26 34 This object converts numbers from the [hid] range (0 to 1) to radians (-pi to pi) with the 0's lining up in the same place. ; #X obj 244 184 hid/hid2rad; #X obj 402 184 hid/hid2deg; #X obj 56 168 hid/deg2hid; #N canvas 504 253 494 344 META 0; #X text 12 155 HELP_PATCH_AUTHORS "pd meta" information added by Jonathan Wilkes for Pd version 0.42.; #X text 12 25 LICENSE GPL; #X text 12 95 INLET_0 float; #X text 12 115 OUTLET_0 float; #X text 12 135 AUTHOR Hans-Christoph Steiner; #X text 12 45 DESCRIPTION convert numbers from the [hid] range (0 to 1) to radians (-pi to pi) with the 0's lining up in the same place. ; #X text 12 5 KEYWORDS control conversion abstraction; #X restore 427 293 pd META; #X connect 8 0 13 0; #X connect 9 0 13 0; #X connect 13 0 7 0; pd-hid_0.7/hid_menu-help.pd0000644000076500007650000000061111504504627014332 0ustar hanshans#N canvas 0 31 473 316 10; #X obj 5 2 cnv 15 450 20 empty empty hid_menu 2 11 1 18 -233017 -66577 0; #X obj 422 3 pddp/pddplink http://puredata.info/dev/pddp -text pddp ; #X text 27 270 (C) Copyright 2004 Hans-Christoph Steiner ; #X text 244 284 released under the GNU GPL; #X text 161 235 For more info:; #X obj 266 234 pddp/pddplink ../all_about_hid.pd -text all_about_hid ; pd-hid_0.7/hid-help.pd0000644000076500007650000004046011504504627013314 0ustar hanshans#N canvas 0 31 715 555 10; #X floatatom 27 439 5 0 0 0 - - -; #X floatatom 83 439 5 0 0 0 - - -; #X floatatom 63 395 6 0 0 0 - - -; #X obj 191 164 tgl 35 0 empty empty empty 0 -6 0 8 -24198 -1 -1 0 25 ; #X floatatom 571 340 12 0 0 1 value - -; #X symbolatom 531 356 15 0 0 1 event_code - -; #X symbolatom 492 372 15 0 0 1 event_type - -; #X obj 2 2 cnv 15 700 20 empty empty hid 2 11 1 18 -233017 -66577 0 ; #X text 274 332 outlet message format:; #X floatatom 138 343 5 0 0 1 ev_syn - -; #X obj 111 342 +; #X msg 111 322 1; #X msg 374 140 close; #X msg 374 119 refresh; #X text 435 117 refresh device list; #X text 422 533 released under the GNU GPL; #X msg 436 201 poll 20; #X msg 374 201 poll 2; #X text 370 186 start polling and set the poll delay in ms; #X text 356 33 !!! This software is very much alpha \, so any aspect of it could change without notice !!!; #X obj 16 291 route key rel abs syn; #X obj 9 502 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1 ; #N canvas 278 328 631 544 Event_Codes 0; #X text 28 48 (For a complete listing of Linux Input Events \, see /usr/include/linux/input.h.); #X obj 11 9 cnv 15 580 30 empty empty Event_Codes 20 12 1 14 -225271 -66577 0; #X text 32 118 EVENT CODE; #X text 162 118 #define; #X text 232 118 number; #X text 32 133 -----------------------------------; #X text 32 148 X Axis; #X text 32 163 Y Axis; #X text 32 178 Z Axis; #X text 32 193 Horizontal Wheel; #X text 32 208 Dial; #X text 32 223 Wheel; #X text 32 238 Misc; #X text 162 148 REL_X; #X text 162 163 REL_Y; #X text 162 178 REL_Z; #X text 162 193 REL_HWHEEL; #X text 162 208 REL_DIAL; #X text 162 223 REL_WHEEL; #X text 162 238 REL_MISC; #X text 247 148 0; #X text 247 163 1; #X text 247 178 2; #X text 247 193 6; #X text 247 208 7; #X text 247 223 8; #X text 247 238 9; #X text 307 118 EVENT CODE; #X text 457 118 #define; #X text 547 118 number; #X text 307 148 Absolute X; #X text 307 163 Absolute Y; #X text 307 178 Absolute Z; #X text 307 193 RX; #X text 307 208 RY; #X text 307 223 RZ; #X text 307 238 Throttle; #X text 307 253 Rudder; #X text 307 268 Wheel; #X text 307 283 Gas Pedal; #X text 307 298 Brake Pedal; #X text 307 313 Hat Switch 0 X-axis; #X text 307 328 Hat Switch 0 Y-axis; #X text 307 343 Hat Switch 1 X-axis; #X text 307 358 Hat Switch 1 Y-axis; #X text 307 373 Hat Switch 2 X-axis; #X text 307 388 Hat Switch 2 Y-axis; #X text 307 403 Hat Switch 3 X-axis; #X text 307 418 Hat Switch 3 Y-axis; #X text 307 433 Pressure; #X text 307 448 Distance; #X text 307 463 Tilt X-Axis; #X text 307 478 Tilt Y-Axis; #X text 307 493 Misc; #X text 457 148 ABS_X; #X text 457 163 ABS_Y; #X text 457 178 ABS_Z; #X text 457 193 ABS_RX; #X text 457 208 ABS_RY; #X text 457 223 ABS_RZ; #X text 457 238 ABS_THROTTLE; #X text 457 253 ABS_RUDDER; #X text 457 268 ABS_WHEEL; #X text 457 283 ABS_GAS; #X text 457 298 ABS_BRAKE; #X text 457 313 ABS_HAT0X; #X text 457 328 ABS_HAT0Y; #X text 457 343 ABS_HAT1X; #X text 457 358 ABS_HAT1Y; #X text 457 373 ABS_HAT2X; #X text 457 388 ABS_HAT2Y; #X text 457 403 ABS_HAT3X; #X text 457 418 ABS_HAT3Y; #X text 457 433 ABS_PRESSURE; #X text 457 448 ABS_DISTANCE; #X text 457 463 ABS_TILT_X; #X text 457 478 ABS_TILT_Y; #X text 457 493 ABS_MISC; #X text 563 148 0; #X text 563 163 1; #X text 563 178 2; #X text 563 193 3; #X text 563 208 4; #X text 563 223 5; #X text 563 238 6; #X text 563 253 7; #X text 563 268 8; #X text 563 283 9; #X text 563 298 10; #X text 563 313 16; #X text 563 328 17; #X text 563 343 18; #X text 563 358 19; #X text 563 373 20; #X text 563 388 21; #X text 563 403 22; #X text 563 418 23; #X text 563 433 24; #X text 563 448 25; #X text 563 463 26; #X text 563 478 27; #X text 563 493 28; #X obj 30 89 cnv 15 250 25 empty empty Relative_Axes 20 12 1 12 -241660 -66577 0; #X obj 308 89 cnv 15 280 25 empty empty Absolute_Axes 20 12 1 12 -241660 -66577 0; #X text 307 133 ----------------------------------------; #X text 32 285 EVENT CODE; #X text 138 285 #define; #X text 232 285 number; #X text 32 300 -----------------------------------; #X obj 30 256 cnv 15 250 25 empty empty Joystick_Buttons 20 12 1 12 -241660 -66577 0; #X text 138 315 BTN_TRIGGER; #X text 32 315 Trigger; #X text 32 330 Thumb; #X text 32 345 Thumb 2; #X text 32 360 Top; #X text 32 375 Top 2; #X text 32 390 Pinkie; #X text 32 405 Base 1; #X text 138 404 BTN_BASE; #X text 138 330 BTN_THUMB; #X text 138 345 BTN_THUMB2; #X text 138 360 BTN_TOP; #X text 138 375 BTN_TOP2; #X text 138 390 BTN_PINKIE; #X text 245 315 288; #X text 245 330 289; #X text 245 345 290; #X text 245 360 291; #X text 245 375 292; #X text 245 390 293; #X text 245 405 294; #X text 245 419 295; #X text 245 434 296; #X text 245 448 297; #X text 138 418 BTN_BASE2; #X text 138 433 BTN_BASE3; #X text 138 447 BTN_BASE4; #X text 32 419 Base 2; #X text 32 434 Base 3; #X text 32 448 Base 4; #X text 32 463 Base 5; #X text 32 477 Base 6; #X text 138 462 BTN_BASE5; #X text 138 476 BTN_BASE6; #X text 245 463 298; #X text 245 477 299; #X restore 593 91 pd Event_Codes; #N canvas 50 289 469 317 Event_Types 0; #X text 28 48 (For a complete listing of Linux Input Events \, see /usr/include/linux/input.h.); #X text 61 90 EVENT TYPE; #X text 61 135 Keys and Buttons; #X text 61 150 Relative Axes; #X text 61 165 Absolute Axes; #X text 61 180 Misc Events; #X text 61 195 LED Event; #X text 61 210 Sounds; #X text 61 225 Autorepeat Values; #X text 61 240 Force Feedback; #X text 230 90 #define; #X text 230 135 EV_KEY; #X text 230 150 EV_REL; #X text 230 165 EV_ABS; #X text 230 180 EV_MSC; #X text 230 195 EV_LED; #X text 230 210 EV_SND; #X text 230 225 EV_REP; #X text 230 240 EV_FF; #X text 315 90 number; #X text 331 120 0; #X text 331 135 1; #X text 331 150 2; #X text 331 165 3; #X text 331 180 4; #X text 331 195 17; #X text 331 210 18; #X text 331 225 20; #X text 331 240 21; #X obj 11 9 cnv 15 400 30 empty empty Event_Types 20 12 1 14 -262131 -66577 0; #X text 230 120 EV_SYN; #X text 61 270 Force Feedback Status; #X text 61 120 Syncronization Events; #X text 230 270 EV_FF_STATUS; #X text 331 270 23; #X text 61 105 -------------------------------------------; #X text 331 255 22; #X text 230 255 EV_PWR; #X text 61 255 Power Events (for UPS); #X restore 593 71 pd Event_Types; #N canvas 0 22 450 300 Event_Values 0; #X text 28 48 (For a complete listing of Linux Input Events \, see /usr/include/linux/input.h.); #X obj 11 9 cnv 15 400 30 empty empty Event_Values 20 12 1 14 -261681 -66577 0; #X restore 593 111 pd Event_Values; #X floatatom 140 439 5 0 0 0 - - -; #X obj 421 394 route abs_hat0x abs_hat0y abs_hat1x abs_hat1y; #X floatatom 421 416 7 0 0 0 - - -; #X msg 374 161 print; #X obj 304 250 hid 0; #X text 437 141 close the device; #X text 437 162 print the device and element lists; #X text 9 212 Any non-zero value starts polling \,; #X text 8 225 0 stops the polling. If the number; #X text 9 238 is greater than 1 \, then the poll; #X text 9 251 delay is set to that number.; #X obj 27 419 route rel_x rel_y rel_z rel_wheel; #X floatatom 196 439 5 0 0 0 - - -; #X obj 492 321 unpack s s f; #X text 298 346 event_type event_code value; #X obj 63 374 route abs_x abs_y abs_z abs_rx abs_ry abs_rz abs_throttle ; #X obj 421 432 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 -1; #X floatatom 498 416 7 0 0 0 - - -; #X obj 498 432 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1; #X floatatom 576 416 7 0 0 0 - - -; #X obj 576 432 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1; #X floatatom 653 416 7 0 0 0 - - -; #X obj 653 432 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1; #X floatatom 113 395 6 0 0 0 - - -; #X floatatom 163 395 6 0 0 0 - - -; #X floatatom 213 395 6 0 0 0 - - -; #X floatatom 263 395 6 0 0 0 - - -; #X floatatom 313 395 6 0 0 0 - - -; #X floatatom 363 395 6 0 0 0 - - -; #X obj 39 502 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1 ; #X obj 69 502 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1 ; #X obj 99 502 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1 ; #X obj 129 502 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 159 502 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 189 502 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 219 502 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 249 502 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 279 502 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 309 502 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 339 502 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 369 502 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 399 502 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 9 460 route btn_0 btn_1 btn_2 btn_3 btn_4 btn_5 btn_6 btn_7 btn_8 btn_9 btn_10 btn_11 btn_12 btn_13 btn_14 btn_15; #X obj 429 502 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 459 502 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X msg 25 155 debug 0; #X msg 298 145 info; #N canvas 752 103 411 235 see 0; #N canvas 108 318 543 264 route 0; #X obj 27 14 inlet; #X obj 72 226 outlet; #X obj 19 226 outlet; #X obj 172 226 outlet; #X obj 222 204 symbol; #X obj 222 226 outlet; #X obj 272 204 symbol; #X obj 272 226 outlet; #X obj 322 204 symbol; #X obj 322 226 outlet; #X obj 372 204 symbol; #X obj 372 226 outlet; #X obj 122 225 outlet; #X obj 422 204 symbol; #X obj 422 226 outlet; #X obj 472 204 symbol; #X obj 472 226 outlet; #X obj 26 63 route open device poll total product manufacturer transport type vendorID productID; #X connect 0 0 17 0; #X connect 4 0 5 0; #X connect 6 0 7 0; #X connect 8 0 9 0; #X connect 10 0 11 0; #X connect 13 0 14 0; #X connect 15 0 16 0; #X connect 17 0 2 0; #X connect 17 1 1 0; #X connect 17 2 12 0; #X connect 17 3 3 0; #X connect 17 4 4 0; #X connect 17 5 6 0; #X connect 17 6 8 0; #X connect 17 7 10 0; #X connect 17 8 13 0; #X connect 17 9 15 0; #X restore 117 70 pd route info; #X obj 81 96 tgl 15 0 empty empty open 0 -6 0 8 -262144 -1 -1 0 1; #X obj 110 22 inlet; #X obj 123 43 print info; #X symbolatom 304 93 0 0 0 0 productID - -; #X symbolatom 304 112 0 0 0 0 vendorID - -; #X symbolatom 304 151 0 0 0 0 transport - -; #X symbolatom 304 171 0 0 0 0 manufacturer - -; #X symbolatom 186 192 0 0 0 0 product - -; #X floatatom 97 140 5 0 0 0 device - -; #X floatatom 97 162 5 0 0 0 poll - -; #X symbolatom 304 131 0 0 0 0 type - -; #X floatatom 97 182 5 0 0 0 total - -; #X connect 0 0 1 0; #X connect 0 1 9 0; #X connect 0 2 10 0; #X connect 0 3 12 0; #X connect 0 4 8 0; #X connect 0 5 7 0; #X connect 0 6 6 0; #X connect 0 7 11 0; #X connect 0 8 5 0; #X connect 0 9 4 0; #X connect 2 0 0 0; #X connect 2 0 3 0; #X restore 420 271 pd see device info; #N canvas 553 77 380 450 open 0; #X obj 77 61 hradio 15 1 0 8 empty empty empty 0 -6 0 8 -262144 -1 -1 0; #X msg 78 81 open mouse \$1; #X obj 121 201 hradio 15 1 0 8 empty empty empty 0 -6 0 8 -262144 -1 -1 0; #X msg 130 221 open keyboard \$1; #X obj 50 13 hradio 15 1 0 8 empty empty empty 0 -6 0 8 -262144 -1 -1 0; #X obj 55 417 outlet; #X obj 85 108 hradio 15 1 0 8 empty empty empty 0 -6 0 8 -262144 -1 -1 0; #X msg 94 128 open joystick \$1; #X msg 59 33 open pointer \$1; #X obj 101 155 hradio 15 1 0 8 empty empty empty 0 -6 0 8 -262144 -1 -1 0; #X msg 110 175 open gamepad \$1; #X obj 137 244 hradio 15 1 0 8 empty empty empty 0 -6 0 8 -262144 -1 -1 0; #X msg 146 264 open keypad \$1; #X obj 141 291 hradio 15 1 0 8 empty empty empty 0 -6 0 8 -262144 -1 -1 0; #X msg 150 311 open multiaxiscontroller \$1; #X text 155 342 or just open the first one:; #X msg 138 363 open mouse; #X msg 159 381 open joystick; #X connect 0 0 1 0; #X connect 1 0 5 0; #X connect 2 0 3 0; #X connect 3 0 5 0; #X connect 4 0 8 0; #X connect 6 0 7 0; #X connect 7 0 5 0; #X connect 8 0 5 0; #X connect 9 0 10 0; #X connect 10 0 5 0; #X connect 11 0 12 0; #X connect 12 0 5 0; #X connect 13 0 14 0; #X connect 14 0 5 0; #X connect 16 0 5 0; #X connect 17 0 5 0; #X restore 203 59 pd open by device type; #N canvas 796 51 470 320 open 0; #X text 217 82 Gravis/Destroyer Tiltpad; #X msg 76 81 open 0x047D 0x4008; #X msg 73 53 open 0x046d 0xc01d; #X text 211 53 Logitech USB-PS/2 Optical Mouse; #X obj 10 277 outlet; #X text 9 12 You can use the hex values of the USB vendor and product IDs (it is not case sensitive):; #X text 221 111 Overtone CUI v1.0; #X msg 80 110 open 0x1043 0x0015; #X msg 83 136 open 0x06a3 0xff12; #X text 221 134 Saitek Cyborgforce; #X connect 1 0 4 0; #X connect 2 0 4 0; #X connect 7 0 4 0; #X connect 8 0 4 0; #X restore 174 37 pd open by vendor/product ID; #N canvas 114 93 467 346 test 0; #X obj 144 45 inlet; #X obj 88 104 route DESKTOP; #X obj 87 158 route DESKTOP57; #X obj 70 207 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; #X floatatom 95 212 5 0 0 0 - - -; #X obj 148 215 spigot; #X obj 146 256 print test; #X obj 189 192 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1; #X obj 292 122 spigot; #X obj 290 163 print test; #X obj 333 99 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1 ; #X connect 0 0 1 0; #X connect 0 0 8 0; #X connect 1 0 2 0; #X connect 2 0 3 0; #X connect 2 0 4 0; #X connect 2 0 5 0; #X connect 5 0 6 0; #X connect 7 0 5 1; #X connect 8 0 9 0; #X connect 10 0 8 1; #X restore 197 303 pd test; #X msg 504 201 poll 200; #X text 69 533 (C) Copyright 2004 Hans-Christoph Steiner ; #N canvas 162 133 570 420 serin 0; #X obj 209 61 cnv 15 15 15 empty \$0-debug-canvas 0 4 8 0 14 -233017 -1 0; #X obj 60 61 hradio 15 1 1 10 empty empty empty 0 -6 0 8 -261689 -1 -1 0; #X obj 60 13 inlet; #X msg 200 202 label \$1; #X obj 200 180 makefilename %d; #X obj 59 108 int; #X obj 59 337 outlet; #X msg 201 306 set \$1 \$2; #X obj 59 266 trigger bang anything; #X obj 201 286 list; #X msg 60 210 debug \$1; #X obj 200 225 send \$0-debug-canvas; #X connect 1 0 5 0; #X connect 2 0 1 0; #X connect 3 0 11 0; #X connect 4 0 3 0; #X connect 5 0 4 0; #X connect 5 0 10 0; #X connect 7 0 6 0; #X connect 8 0 6 0; #X connect 8 1 9 0; #X connect 9 0 7 0; #X connect 10 0 8 0; #X coords 0 -1 1 1 165 17 1 60 60; #X restore 25 134 pd serin; #X msg 262 114 open 0; #X obj 249 300 pddp/print; #N canvas 162 133 570 420 serin 0; #X obj 286 61 cnv 15 30 15 empty \$0-open-canvas 0 4 8 0 14 -233017 -1 0; #X obj 60 61 hradio 15 1 1 15 empty empty empty 0 -6 0 8 -225271 -1 -1 0; #X obj 60 13 inlet; #X msg 200 202 label \$1; #X obj 200 180 makefilename %d; #X obj 59 108 int; #X obj 59 337 outlet; #X msg 201 306 set \$1 \$2; #X obj 59 266 trigger bang anything; #X obj 201 286 list; #X msg 60 210 open \$1; #X obj 200 225 send \$0-open-canvas; #X connect 1 0 5 0; #X connect 2 0 1 0; #X connect 3 0 11 0; #X connect 4 0 3 0; #X connect 5 0 4 0; #X connect 5 0 10 0; #X connect 7 0 6 0; #X connect 8 0 6 0; #X connect 8 1 9 0; #X connect 9 0 7 0; #X connect 10 0 8 0; #X coords 0 -1 1 1 257 17 1 60 60; #X restore 262 92 pd serin; #N canvas 504 253 494 344 META 0; #X text 12 145 HELP_PATCH_AUTHORS "pd meta" information added by Jonathan Wilkes for Pd version 0.42.; #X text 12 25 LICENSE GPL; #X text 12 125 AUTHOR Hans-Christoph Steiner; #X text 12 65 INLET_0; #X text 12 85 OUTLET_0; #X text 12 105 OUTLET_1; #X text 12 5 KEYWORDS control user_input; #X text 12 45 DESCRIPTION; #X restore 657 523 pd META; #X connect 3 0 29 0; #X connect 9 0 10 1; #X connect 10 0 9 0; #X connect 11 0 10 0; #X connect 12 0 29 0; #X connect 13 0 29 0; #X connect 16 0 29 0; #X connect 17 0 29 0; #X connect 20 0 67 0; #X connect 20 1 36 0; #X connect 20 2 40 0; #X connect 20 3 11 0; #X connect 26 0 27 0; #X connect 26 1 42 0; #X connect 26 2 44 0; #X connect 26 3 46 0; #X connect 27 0 41 0; #X connect 28 0 29 0; #X connect 29 0 20 0; #X connect 29 0 38 0; #X connect 29 0 75 0; #X connect 29 0 80 0; #X connect 29 1 72 0; #X connect 36 0 0 0; #X connect 36 1 1 0; #X connect 36 2 25 0; #X connect 36 3 37 0; #X connect 38 0 6 0; #X connect 38 1 5 0; #X connect 38 2 4 0; #X connect 40 0 2 0; #X connect 40 1 48 0; #X connect 40 2 49 0; #X connect 40 3 50 0; #X connect 40 4 51 0; #X connect 40 5 52 0; #X connect 40 6 53 0; #X connect 40 7 26 0; #X connect 42 0 43 0; #X connect 44 0 45 0; #X connect 46 0 47 0; #X connect 67 0 21 0; #X connect 67 1 54 0; #X connect 67 2 55 0; #X connect 67 3 56 0; #X connect 67 4 57 0; #X connect 67 5 58 0; #X connect 67 6 59 0; #X connect 67 7 60 0; #X connect 67 8 61 0; #X connect 67 9 62 0; #X connect 67 10 63 0; #X connect 67 11 64 0; #X connect 67 12 65 0; #X connect 67 13 66 0; #X connect 67 14 68 0; #X connect 67 15 69 0; #X connect 70 0 29 0; #X connect 71 0 29 0; #X connect 73 0 29 0; #X connect 74 0 29 0; #X connect 76 0 29 0; #X connect 78 0 70 0; #X connect 79 0 29 0; #X connect 81 0 79 0; pd-hid_0.7/hid_one2two-help.pd0000644000076500007650000000266311504504627014774 0ustar hanshans#N canvas 0 31 473 316 10; #X obj 5 2 cnv 15 450 20 empty empty hid_one2two 2 11 1 18 -233017 -66577 0; #X obj 422 3 pddp/pddplink http://puredata.info/dev/pddp -text pddp ; #X text 27 270 (C) Copyright 2004 Hans-Christoph Steiner ; #X text 244 284 released under the GNU GPL; #X floatatom 153 110 5 0 0 0 - - -; #X floatatom 83 176 5 0 0 0 - - -; #X obj 156 91 hsl 128 15 0 1 0 0 empty empty empty -2 -6 0 8 -262144 -1 -1 0 1; #X obj 86 203 hsl 128 15 0 1 0 0 empty empty empty -2 -6 0 8 -262144 -1 -1 0 1; #X text 98 243 For more info:; #X floatatom 263 176 5 0 0 0 - - -; #X obj 266 203 hsl 128 15 0 1 0 0 empty empty empty -2 -6 0 8 -262144 -1 -1 0 1; #X text 18 28 Simple one-to-two mapping object. The first inlet is passed thru \, the range of the output data on the second inlet starts at the point in the input range specified as an arugment.; #X obj 153 145 hid/hid_one2two 0.3; #N canvas 483 31 494 344 META 0; #X text 12 145 HELP_PATCH_AUTHORS "pd meta" information added by Jonathan Wilkes for Pd version 0.42.; #X text 12 25 LICENSE GPL; #X text 12 125 AUTHOR Hans-Christoph Steiner; #X text 12 65 INLET_0 float; #X text 12 105 OUTLET_1 float; #X text 12 85 OUTLET_0 float; #X text 12 45 DESCRIPTION simple one-to-two mapping object; #X text 12 5 KEYWORDS control abstraction; #X restore 419 270 pd META; #X connect 4 0 12 0; #X connect 5 0 7 0; #X connect 6 0 4 0; #X connect 9 0 10 0; #X connect 12 0 5 0; #X connect 12 1 9 0; pd-hid_0.7/input_arrays.h0000644000076500007650000000163011504504627014162 0ustar hanshans#ifndef _INPUT_ARRAYS_H #define _INPUT_ARRAYS_H extern char *ev[32]; extern char *ev_syn[512]; extern char *ev_key[512]; extern char *ev_rel[16]; extern char *ev_abs[64]; extern char *ev_msc[8]; extern char *ev_led[16]; extern char *ev_snd[8]; extern char *ev_rep[2]; extern char *ev_ff[128]; extern char *ev_pwr[1]; extern char *ev_ff_status[2]; extern char *ev_5[16]; extern char *ev_6[16]; extern char *ev_7[16]; extern char *ev_8[16]; extern char *ev_9[16]; extern char *ev_10[16]; extern char *ev_11[16]; extern char *ev_12[16]; extern char *ev_13[16]; extern char *ev_14[16]; extern char *ev_15[16]; extern char *ev_16[16]; extern char *ev_19[16]; extern char *ev_24[16]; extern char *ev_25[16]; extern char *ev_26[16]; extern char *ev_27[16]; extern char *ev_28[16]; extern char *ev_29[16]; extern char *ev_30[16]; extern char *ev_31[16]; extern char **event_names[32]; #endif /* #ifndef _INPUT_ARRAYS_H */ pd-hid_0.7/hid_graph.pd0000644000076500007650000000210111504504627013535 0ustar hanshans#N canvas 606 208 100 116 10; #X obj 103 188 inlet; #N canvas 0 22 466 316 graph5 0; #X array \$0_ 100 float 2; #X coords 0 1 100 0 100 100 1; #X restore 0 16 graph; #X obj 198 378 outlet; #X text 238 311 gives a range of 0-100; #X text 245 379 output range 0 to 1; #X text 79 167 [hid_graph]; #X obj 198 310 * 100; #X text 143 190 input range: 0 to 1; #X obj 103 237 route reset; #X obj 75 380 f; #X obj 45 380 +; #X msg 89 348 0; #X msg 45 348 1; #X obj 45 464 / 100; #X obj 45 441 trigger f f; #X obj 21 278 trigger bang bang; #X msg 21 303 100; #X obj 21 322 until; #X obj 198 333 tabread \$0_; #X obj 45 496 tabwrite \$0_; #X obj -7 229 loadbang; #X connect 0 0 8 0; #X connect 6 0 18 0; #X connect 8 0 15 0; #X connect 8 1 6 0; #X connect 9 0 10 1; #X connect 10 0 14 0; #X connect 10 0 9 0; #X connect 11 0 9 1; #X connect 11 0 10 1; #X connect 12 0 10 0; #X connect 13 0 19 0; #X connect 14 0 13 0; #X connect 14 1 19 1; #X connect 15 0 16 0; #X connect 15 1 11 0; #X connect 16 0 17 0; #X connect 17 0 12 0; #X connect 18 0 2 0; #X connect 20 0 15 0; #X coords 0 0 1 1 100 116 1; pd-hid_0.7/hid_square.pd0000644000076500007650000000056311504504627013746 0ustar hanshans#N canvas 608 576 483 309 10; #X obj 72 63 inlet; #X obj 72 240 outlet; #X text 120 63 input range: 0 to 1; #X text 128 240 output range: 0 to 1; #X obj 72 149 t f f; #X obj 72 172 *; #X text 7 9 [hid_square]; #X obj 72 95 min 1; #X obj 72 115 max 0; #X connect 0 0 7 0; #X connect 4 0 5 0; #X connect 4 1 5 1; #X connect 5 0 1 0; #X connect 7 0 8 0; #X connect 8 0 4 0; pd-hid_0.7/keygate.pd0000644000076500007650000000202711504504627013250 0ustar hanshans#N canvas 326 22 530 481 10; #X obj 44 36 inlet; #X obj 44 365 outlet; #X obj 44 334 spigot; #X text 109 401 (C) Copyright 2004 Hans-Christoph Steiner ; #X text 326 415 released under the GNU GPL; #X text 16 444 $Author: eighthave $; #X text 16 461 $Date: 2004-11-25 02:42:49 $; #X text 16 427 $Revision: 1.1 $; #X obj 132 26 loadbang; #X text 5 6 [keygate]; #X obj 182 333 spigot; #X obj 182 365 outlet; #X obj 273 204 - 1; #X obj 273 224 abs; #X obj 236 27 keyname; #X msg 132 60 0; #X msg 183 60 1; #X obj 243 181 t f f; #X obj 243 157 f; #X obj 243 107 sel \$1; #X obj 243 86 symbol; #X obj 236 57 trigger bang float; #X connect 0 0 2 0; #X connect 0 0 10 0; #X connect 2 0 1 0; #X connect 8 0 15 0; #X connect 8 0 16 0; #X connect 10 0 11 0; #X connect 12 0 13 0; #X connect 13 0 10 1; #X connect 14 0 21 0; #X connect 14 1 20 1; #X connect 15 0 2 1; #X connect 16 0 10 1; #X connect 17 0 2 1; #X connect 17 1 12 0; #X connect 18 0 17 0; #X connect 19 0 18 0; #X connect 20 0 19 0; #X connect 21 0 20 0; #X connect 21 1 18 1; pd-hid_0.7/examples/0000755000076500007650000000000011504505103013075 5ustar hanshanspd-hid_0.7/examples/spiral-joystick.pd0000644000076500007650000000300711504504627016563 0ustar hanshans#N canvas 400 56 478 473 10; #X declare -path ..; #X obj 134 99 tgl 25 0 empty empty start 1 12 1 9 -225271 -1 -1 1 1 ; #X msg 216 118 open \$1; #X obj 180 98 nbx 2 14 -1e+37 1e+37 0 0 empty \$0-device-number empty 0 -6 0 14 -166441 -1 -1 10 256; #X msg 81 99 print; #X obj 172 282 osc~; #X obj 105 345 *~; #X obj 105 389 dac~; #X obj 65 283 line~; #X msg 65 261 \$1 5; #X text 25 32 This patch uses the angle of the joystick to control pitch and the distance from the centerpoint to control amplitude. The joystick Z/twist is mapped to pan.; #X obj 105 366 pan/equal_power_pan~; #X text 254 432 released under the GNU GPL; #X text 40 417 (C) Copyright 2005 Hans-Christoph Steiner ; #X obj 172 262 pow 3; #X text 196 211 set 440 as start; #X obj 172 241 + 7.60591; #X text 194 223 (7.60591 ^ 3 = 440.001); #X text 14 9 spiral_joystick; #X obj 134 142 hid/joystick 3; #X obj 147 171 mapping/reverse; #X obj 107 198 mapping/spiral; #X obj 65 242 hid/hid_cube; #X msg 167 118 print; #X obj 389 10 pddp/dsp; #X obj 216 97 hradio 15 1 1 15 \$0-device-number empty choose_a_device 0 -6 1 9 -225271 -1 -1 10; #X connect 0 0 18 0; #X connect 1 0 18 0; #X connect 3 0 18 0; #X connect 4 0 5 0; #X connect 5 0 10 0; #X connect 7 0 5 1; #X connect 8 0 7 0; #X connect 10 0 6 0; #X connect 10 1 6 1; #X connect 13 0 4 0; #X connect 15 0 13 0; #X connect 18 0 20 0; #X connect 18 1 19 0; #X connect 18 2 10 1; #X connect 19 0 20 1; #X connect 20 0 21 0; #X connect 20 1 15 0; #X connect 21 0 8 0; #X connect 22 0 18 0; #X connect 24 0 1 0; pd-hid_0.7/examples/polar-joystick.pd0000644000076500007650000000272211504504627016411 0ustar hanshans#N canvas 254 77 472 478 10; #X declare -path ..; #X obj 163 119 tgl 25 0 empty empty start 1 12 1 9 -225271 -1 -1 0 1; #X msg 226 138 open \$1; #X obj 226 118 hradio 15 1 1 15 \$0-device-number empty choose_a_device 0 -6 1 9 -225271 -1 -1 0; #X obj 190 119 nbx 2 14 -1e+37 1e+37 0 0 empty \$0-device-number empty 0 -6 0 14 -166441 -1 -1 0 256; #X msg 112 119 print; #X obj 177 285 mtof; #X obj 177 305 osc~; #X obj 118 355 *~; #X obj 118 401 dac~; #X obj 77 305 line~; #X msg 77 283 \$1 5; #X text 25 38 This patch uses the angle of the joystick to control pitch and the distance from the centerpoint to control amplitude. The joystick Z/twist is mapped to pan.; #X obj 118 379 pan/equal_power_pan~; #X text 254 444 released under the GNU GPL; #X text 40 429 (C) Copyright 2005 Hans-Christoph Steiner ; #X text 14 9 polar_joystick; #X obj 163 164 hid/joystick 3; #X obj 177 194 mapping/reverse; #X obj 102 216 mapping/polar; #X obj 77 264 hid/hid_cube; #X obj 391 11 pddp/dsp; #X obj 177 265 mapping/notescale 60 72; #X obj 177 245 mapping/stepper; #X connect 0 0 16 0; #X connect 1 0 16 0; #X connect 2 0 1 0; #X connect 4 0 16 0; #X connect 5 0 6 0; #X connect 6 0 7 1; #X connect 7 0 12 0; #X connect 9 0 7 0; #X connect 10 0 9 0; #X connect 12 0 8 0; #X connect 12 1 8 1; #X connect 16 0 18 0; #X connect 16 1 17 0; #X connect 16 2 12 1; #X connect 17 0 18 1; #X connect 18 0 19 0; #X connect 18 1 22 0; #X connect 19 0 10 0; #X connect 21 0 5 0; #X connect 22 0 21 0; pd-hid_0.7/hid_squareroot.pd0000644000076500007650000000047111504504627014650 0ustar hanshans#N canvas 170 430 436 353 10; #X obj 72 63 inlet; #X obj 72 240 outlet; #X text 120 63 input range: 0 to 1; #X text 128 240 output range: 0 to 1; #X text 41 18 [hid_sqrt]; #X obj 72 143 sqrt; #X obj 72 95 min 1; #X obj 72 115 max 0; #X connect 0 0 6 0; #X connect 5 0 1 0; #X connect 6 0 7 0; #X connect 7 0 5 0; pd-hid_0.7/hid_smooth-help.pd0000644000076500007650000000261511504504627014705 0ustar hanshans#N canvas 0 31 475 392 10; #X text 27 340 (C) Copyright 2004 Hans-Christoph Steiner ; #X text 244 354 released under the GNU GPL; #X floatatom 102 195 5 0 0 0 - - -; #X floatatom 102 251 5 0 0 0 - - -; #X text 98 303 For more info:; #X obj 102 131 noise4hidhelp; #X obj 105 273 hsl 250 15 0 1 0 0 empty empty empty 22 8 1 12 -262144 -1 -1 0 1; #X obj 105 164 hsl 250 15 0 1 0 0 empty empty empty 22 8 1 12 -262144 -1 -1 0 1; #X obj 5 2 cnv 15 450 20 empty empty hid_smooth 2 11 1 18 -233017 -66577 0; #X obj 422 3 pddp/pddplink http://puredata.info/dev/pddp -text pddp ; #X obj 102 221 hid/hid_smooth; #X text 18 36 Smooths a stream of numbers using weighted averaging of the last 10 values. This object is an shortcut for [hid_average] with the default settings.; #X obj 102 94 tgl 30 0 empty empty start 1 15 1 12 -90049 -1 -1 0 1 ; #N canvas 485 31 494 344 META 0; #X text 12 135 HELP_PATCH_AUTHORS "pd meta" information added by Jonathan Wilkes for Pd version 0.42.; #X text 12 25 LICENSE GPL; #X text 12 115 AUTHOR Hans-Christoph Steiner; #X text 12 95 OUTLET_0 float; #X text 12 45 DESCRIPTION smooth a stream of numbers using weighted averaging of the last 10 values; #X text 12 75 INLET_0 float; #X text 12 5 KEYWORDS control filter abstraction; #X restore 422 361 pd META; #X connect 2 0 10 0; #X connect 3 0 6 0; #X connect 5 0 7 0; #X connect 7 0 2 0; #X connect 10 0 3 0; #X connect 12 0 5 0; pd-hid_0.7/hid_one2three-help.pd0000644000076500007650000000317511504504627015271 0ustar hanshans#N canvas 0 31 473 313 10; #X obj 5 2 cnv 15 450 20 empty empty hid_one2three 2 11 1 18 -233017 -66577 0; #X obj 422 3 pddp/pddplink http://puredata.info/dev/pddp -text pddp ; #X text 27 270 (C) Copyright 2004 Hans-Christoph Steiner ; #X text 244 284 released under the GNU GPL; #X floatatom 153 110 5 0 0 0 - - -; #X floatatom 23 176 5 0 0 0 - - -; #X obj 156 91 hsl 128 15 0 1 0 0 empty empty empty -2 -6 0 8 -262144 -1 -1 0 1; #X obj 26 203 hsl 128 15 0 1 0 0 empty empty empty -2 -6 0 8 -262144 -1 -1 0 1; #X text 98 243 For more info:; #X floatatom 173 176 5 0 0 0 - - -; #X obj 176 203 hsl 128 15 0 1 0 0 empty empty empty -2 -6 0 8 -262144 -1 -1 0 1; #X obj 153 145 hid/hid_one2three 0.3 0.7; #X floatatom 323 176 5 0 0 0 - - -; #X obj 326 203 hsl 128 15 0 1 0 0 empty empty empty -2 -6 0 8 -262144 -1 -1 0 1; #X text 18 28 Simple one-to-three mapping object. The first inlet is passed thru \, the range of the output data on the other inlet starts at the points in the input range specified as arugments.; #N canvas 483 31 494 344 META 0; #X text 12 165 HELP_PATCH_AUTHORS "pd meta" information added by Jonathan Wilkes for Pd version 0.42.; #X text 12 25 LICENSE GPL; #X text 12 145 AUTHOR Hans-Christoph Steiner; #X text 12 45 DESCRIPTION simple one-to-three mapping object; #X text 12 65 INLET_0 float; #X text 12 125 OUTLET_2 float; #X text 12 105 OUTLET_1 float; #X text 12 85 OUTLET_0 float; #X text 12 5 KEYWORDS control abstraction; #X restore 420 280 pd META; #X connect 4 0 11 0; #X connect 5 0 7 0; #X connect 6 0 4 0; #X connect 9 0 10 0; #X connect 11 0 5 0; #X connect 11 1 9 0; #X connect 11 2 12 0; #X connect 12 0 13 0; pd-hid_0.7/rad2hid-help.pd0000644000076500007650000000244711504504627014070 0ustar hanshans#N canvas 0 31 467 307 10; #X obj 5 2 cnv 15 450 20 empty empty rad2hid 2 11 1 18 -233017 -66577 0; #X obj 422 3 pddp/pddplink http://puredata.info/dev/pddp -text pddp ; #X text 234 269 released under the GNU GPL; #X text 165 228 For more info:; #X text 20 254 (C) Copyright 2005 Hans-Christoph Steiner ; #X text 300 168 related objects:; #X obj 233 184 hid/rad2hid; #X obj 312 184 hid/deg2hid; #X obj 391 184 hid/hid2deg; #X floatatom 69 195 5 0 0 1 hid - -; #X obj 72 95 hsl 128 15 -3.14159 3.14159 0 0 empty empty radians 6 7 1 10 -262131 -1 -1 0 0; #X floatatom 95 125 9 0 0 0 - - -; #X obj 69 160 hid/rad2hid; #X text 21 35 This object converts numbers from radians (-pi to pi) to the [hid] range (0 to 1) with the 0's lining up in the same place. ; #N canvas 477 31 494 344 META 0; #X text 12 135 HELP_PATCH_AUTHORS "pd meta" information added by Jonathan Wilkes for Pd version 0.42.; #X text 12 25 LICENSE GPL; #X text 12 115 AUTHOR Hans-Christoph Steiner; #X text 12 45 DESCRIPTION convert numbers from radians (-pi to pi) to the [hid] range (0 to 1) with 0's lining up in the same place; #X text 12 75 INLET_0 float; #X text 12 95 OUTLET_0 float; #X text 12 5 KEYWORDS control user_input abstraction; #X restore 416 275 pd META; #X connect 10 0 12 0; #X connect 10 0 11 0; #X connect 12 0 9 0; pd-hid_0.7/hid_exp-help.pd0000644000076500007650000000403011504504627014161 0ustar hanshans#N canvas 0 31 472 353 10; #X obj 5 2 cnv 15 450 20 empty empty hid_exp 2 11 1 18 -233017 -66577 0; #X obj 422 3 pddp/pddplink http://puredata.info/dev/pddp -text pddp ; #X text 27 300 (C) Copyright 2004 Hans-Christoph Steiner ; #X text 244 314 released under the GNU GPL; #X text 98 271 For more info:; #X floatatom 35 123 8 0 0 0 - - -; #X floatatom 35 180 8 0 0 0 - - -; #X obj 28 201 hsl 200 15 0 1 0 0 empty empty empty 22 8 1 12 -262144 -1 -1 0 1; #X obj 28 103 hsl 200 15 0 1 0 0 empty empty empty 22 8 1 12 -261681 -1 -1 0 1; #X obj 25 153 hid/hid_exp; #N canvas 0 22 450 300 (subpatch) 0; #X array hid_exp 100 float 0; #X coords 0 1 99 0 100 100 1; #X restore 321 116 graph; #N canvas 266 69 327 317 draw_array 0; #X msg 57 52 bang; #X obj 57 73 until; #X text 88 52 start; #X obj 57 95 f; #X obj 86 95 + 1; #X obj 132 97 sel 0; #X obj 86 117 mod 100; #X obj 57 150 t f f; #X obj 94 177 s array_index; #X obj 170 262 r array_index; #X obj 57 13 loadbang; #X obj 57 207 / 100; #X text 99 207 [hid] output range: 0 to 1; #X obj 56 233 hid/hid_exp; #X obj 56 283 tabwrite hid_exp; #X connect 0 0 1 0; #X connect 1 0 3 0; #X connect 3 0 4 0; #X connect 3 0 7 0; #X connect 4 0 6 0; #X connect 5 0 1 1; #X connect 6 0 3 1; #X connect 6 0 5 0; #X connect 7 0 11 0; #X connect 7 1 8 0; #X connect 9 0 14 1; #X connect 10 0 0 0; #X connect 11 0 13 0; #X connect 13 0 14 0; #X restore 321 78 pd draw_array; #X text 17 39 This object maps the input range to a exponential curve \, the inverse of a logarithmic curve.; #N canvas 478 206 494 344 META 0; #X text 12 135 HELP_PATCH_AUTHORS "pd meta" information added by Jonathan Wilkes for Pd version 0.42.; #X text 12 25 LICENSE GPL; #X text 12 75 INLET_0 float; #X text 12 95 OUTLET_0 float; #X text 12 115 AUTHOR Hans-Christoph Steiner; #X text 12 45 DESCRIPTION map the input range to a exponential curve \, the inverse of a logarithmic curve; #X text 12 5 KEYWORDS control conversion abstraction; #X restore 420 323 pd META; #X connect 8 0 5 0; #X connect 8 0 9 0; #X connect 9 0 6 0; #X connect 9 0 7 0; pd-hid_0.7/hid_one2three.pd0000644000076500007650000000046511504504627014342 0ustar hanshans#N canvas 0 22 454 304 10; #X text 27 16 hid_one2three; #X obj 184 19 inlet; #X obj 66 248 outlet; #X obj 177 249 outlet; #X obj 121 124 hid_one2two \$1; #X obj 196 159 hid_one2two \$2; #X obj 293 250 outlet; #X connect 1 0 4 0; #X connect 4 0 2 0; #X connect 4 1 5 0; #X connect 5 0 3 0; #X connect 5 1 6 0; pd-hid_0.7/hid_average-help.pd0000644000076500007650000000310411504504627015000 0ustar hanshans#N canvas 0 31 479 396 10; #X text 27 340 (C) Copyright 2004 Hans-Christoph Steiner ; #X text 244 354 released under the GNU GPL; #X floatatom 122 189 5 0 0 0 - - -; #X floatatom 102 251 5 0 0 0 - - -; #X text 98 303 For more info:; #X obj 223 194 hsl 85 18 0.1 10 1 1 empty empty average_count 0 9 1 12 -228992 -1 -1 5800 0; #X floatatom 219 223 5 0 0 0 - - -; #X obj 102 131 noise4hidhelp; #X obj 105 281 hsl 250 15 0 1 0 0 empty empty empty -2 -6 0 8 -262144 -1 -1 0 1; #X obj 125 158 hsl 250 15 0 1 0 0 empty empty empty -2 -6 0 8 -262144 -1 -1 0 1; #X obj 5 2 cnv 15 450 20 empty empty hid_average 2 11 1 18 -233017 -66577 0; #X obj 422 3 pddp/pddplink http://puredata.info/dev/pddp -text pddp ; #X obj 102 221 hid/hid_average; #X text 18 36 Smooths a stream of numbers using weighted averaging. By default \, the average is the last 10 values. You can set this using the right inlet.; #X obj 102 95 tgl 30 0 empty empty start 1 15 1 12 -90049 -1 -1 0 1 ; #N canvas 504 253 494 344 META 0; #X text 12 165 HELP_PATCH_AUTHORS "pd meta" information added by Jonathan Wilkes for Pd version 0.42.; #X text 12 25 LICENSE GPL; #X text 12 85 INLET_0 float; #X text 12 125 OUTLET_0 float; #X text 12 145 AUTHOR Hans-Christoph Steiner; #X text 12 45 DESCRIPTION smooths a stream of numbers using weighted averaging; #X text 12 105 INLET_1 float; #X text 12 5 KEYWORDS control conversion abstraction; #X restore 426 369 pd META; #X connect 3 0 8 0; #X connect 5 0 12 1; #X connect 6 0 12 1; #X connect 7 0 9 0; #X connect 7 0 12 0; #X connect 9 0 2 0; #X connect 12 0 3 0; #X connect 14 0 7 0; pd-hid_0.7/buttongate.pd0000644000076500007650000000200211504504627013764 0ustar hanshans#N canvas 367 43 525 408 10; #X obj 303 81 hid \$1; #X obj 303 24 inlet; #X obj 303 106 route key; #X obj 303 127 route \$2; #X obj 104 26 inlet; #X obj 104 295 outlet; #X obj 104 264 spigot; #X text 10 324 (C) Copyright 2004 Hans-Christoph Steiner ; #X text 226 340 released under the GNU GPL; #X text 16 371 $Author: eighthave $; #X text 16 388 $Date: 2004-11-25 02:42:49 $; #X text 16 354 $Revision: 1.2 $; #X obj 192 16 loadbang; #X obj 303 147 unpack f f; #X text 5 6 [buttongate]; #X obj 242 263 spigot; #X obj 242 295 outlet; #X obj 333 195 - 1; #X obj 333 215 abs; #X msg 192 50 0; #X msg 243 50 1; #X obj 303 168 t f f; #X connect 0 0 2 0; #X connect 1 0 0 0; #X connect 2 0 3 0; #X connect 3 0 13 0; #X connect 4 0 6 0; #X connect 4 0 15 0; #X connect 6 0 5 0; #X connect 12 0 19 0; #X connect 12 0 20 0; #X connect 13 0 21 0; #X connect 15 0 16 0; #X connect 17 0 18 0; #X connect 18 0 15 1; #X connect 19 0 6 1; #X connect 20 0 15 1; #X connect 20 0 0 0; #X connect 21 0 6 1; #X connect 21 1 17 0; pd-hid_0.7/hid2rad-help.pd0000644000076500007650000000244011504504627014061 0ustar hanshans#N canvas 0 36 471 311 10; #X obj 5 2 cnv 15 450 20 empty empty hid2rad 2 11 1 18 -233017 -66577 0; #X obj 422 3 pddp/pddplink http://puredata.info/dev/pddp -text pddp ; #X text 254 249 released under the GNU GPL; #X text 185 208 For more info:; #X text 40 234 (C) Copyright 2005 Hans-Christoph Steiner ; #X text 276 148 related objects:; #X obj 233 164 hid/rad2hid; #X obj 308 164 hid/deg2hid; #X obj 383 164 hid/hid2deg; #X obj 69 150 hid/hid2rad; #X floatatom 69 185 9 0 0 1 radians - -; #X obj 72 85 hsl 128 15 0 1 0 0 empty empty hid 6 7 1 10 -262131 -1 -1 0 0; #X floatatom 95 115 5 0 0 0 - - -; #X text 26 34 This object converts numbers from the [hid] range (0 to 1) to radians (-pi to pi) with the 0's lining up in the same place. ; #N canvas 504 253 494 344 META 0; #X text 12 145 HELP_PATCH_AUTHORS "pd meta" information added by Jonathan Wilkes for Pd version 0.42.; #X text 12 25 LICENSE GPL; #X text 12 85 INLET_0 float; #X text 12 105 OUTLET_0 float; #X text 12 125 AUTHOR Hans-Christoph Steiner; #X text 12 45 DESCRIPTION convert numbers from the [hid] range (0 to 1) to radians (-pi to pi) with the 0's lining up in the same place. ; #X text 12 5 KEYWORDS control conversion abstraction; #X restore 417 283 pd META; #X connect 9 0 10 0; #X connect 11 0 9 0; #X connect 12 0 9 0; pd-hid_0.7/hid_rel2abs.pd0000644000076500007650000000104211504504627013771 0ustar hanshans#N canvas 0 22 466 316 10; #X obj 137 20 inlet; #X obj 221 272 outlet; #X floatatom 221 81 5 0 0 0 - - -; #X obj 137 81 route reset; #X obj 221 174 +; #X obj 281 174 f; #X obj 232 195 min \$2; #X obj 232 214 max \$1; #X obj 260 137 f \$1; #X obj 215 26 loadbang; #X msg 215 45 reset; #X connect 0 0 3 0; #X connect 3 0 8 0; #X connect 3 1 2 0; #X connect 3 1 4 0; #X connect 4 0 1 0; #X connect 4 0 6 0; #X connect 5 0 4 1; #X connect 6 0 7 0; #X connect 7 0 5 0; #X connect 8 0 4 1; #X connect 8 0 5 0; #X connect 9 0 10 0; #X connect 10 0 3 0; pd-hid_0.7/keyboard.pd0000644000076500007650000000040111504504627013411 0ustar hanshans#N canvas 0 22 470 320 10; #X msg 96 64 start; #X msg 105 83 stop; #X obj 77 30 inlet; #X obj 77 107 hid \$1; #X obj 77 139 route key; #X obj 77 273 outlet; #X connect 0 0 3 0; #X connect 1 0 3 0; #X connect 2 0 3 0; #X connect 3 0 4 0; #X connect 4 0 5 0; pd-hid_0.7/README.txt0000644000076500007650000000166411504504627012776 0ustar hanshans hid - a Pd object for getting data from USB HID devices [hid] is an object for reading data from USB HID devices like keyboards, mice, joysticks, gamepads, keypads, and all sorts of other esoteric controllers like USB knobs, touchscreens, Apple IR Remotes, etc. It represents the data with a cross-platform message scheme which is then translated to the underlying native API for input devices (Linux input.h or Mac OS X HID Utilities). For GNU/Linux, there are varying restrictions on getting the USB HID data, so you will need to make sure you have permissions to read the /dev/input/event* devices in order to get data with [hid]. There are some docs to help you with this: http://puredata.info/docs/tutorials/HowToReadHIDDevicesInLinuxWithoutBeingRoot/ For those interested in output support, and a cleaner message system, checkout the alpha [hidio]: http://puredata.info/community/projects/software/hidio http://puredata.info/dev/HidIO pd-hid_0.7/hid_one2two.pd0000644000076500007650000000064511504504627014044 0ustar hanshans#N canvas 205 314 470 320 10; #X obj 131 38 inlet; #X text 20 14 hid_one2two; #X obj 131 253 outlet; #X obj 233 252 outlet; #X obj 249 103 f \$1; #X obj 160 124 max \$1; #X obj 160 154 - \$1; #X obj 249 74 loadbang; #X obj 249 122 hid_invert; #X obj 233 194 /; #X connect 0 0 2 0; #X connect 0 0 5 0; #X connect 4 0 8 0; #X connect 5 0 6 0; #X connect 6 0 9 0; #X connect 7 0 4 0; #X connect 8 0 9 1; #X connect 9 0 3 0; pd-hid_0.7/hid_squareroot-help.pd0000644000076500007650000000407411504504627015601 0ustar hanshans#N canvas 0 31 476 357 10; #X obj 5 2 cnv 15 450 20 empty empty hid_squareroot 2 11 1 18 -233017 -66577 0; #X obj 422 3 pddp/pddplink http://puredata.info/dev/pddp -text pddp ; #X text 27 300 (C) Copyright 2004 Hans-Christoph Steiner ; #X text 244 314 released under the GNU GPL; #X text 98 271 For more info:; #X floatatom 25 133 8 0 0 0 - - -; #X floatatom 25 194 8 0 0 0 - - -; #X obj 28 221 hsl 200 15 0 1 0 0 empty empty empty 22 8 1 12 -262144 -1 -1 0 1; #X obj 28 103 hsl 200 15 0 1 0 0 empty empty empty 22 8 1 12 -261681 -1 -1 0 1; #X obj 25 163 hid/hid_squareroot; #N canvas 0 22 450 300 (subpatch) 0; #X array hid_squareroot 100 float 0; #X coords 0 1 99 0 100 100 1; #X restore 321 111 graph; #N canvas 266 69 327 317 draw_array 0; #X msg 57 52 bang; #X obj 57 73 until; #X text 88 52 start; #X obj 57 95 f; #X obj 86 95 + 1; #X obj 132 97 sel 0; #X obj 86 117 mod 100; #X obj 57 150 t f f; #X obj 94 177 s array_index; #X obj 170 262 r array_index; #X obj 57 13 loadbang; #X obj 57 207 / 100; #X text 99 207 [hid] output range: 0 to 1; #X obj 56 233 hid/hid_squareroot; #X obj 56 283 tabwrite hid_squareroot; #X connect 0 0 1 0; #X connect 1 0 3 0; #X connect 3 0 4 0; #X connect 3 0 7 0; #X connect 4 0 6 0; #X connect 5 0 1 1; #X connect 6 0 3 1; #X connect 6 0 5 0; #X connect 7 0 11 0; #X connect 7 1 8 0; #X connect 9 0 14 1; #X connect 10 0 0 0; #X connect 11 0 13 0; #X connect 13 0 14 0; #X restore 321 78 pd draw_array; #X text 15 34 This object maps the input range to a square root curve \, i.e. [pow 0.5] \, "square root of X" \, or X^0.5.; #N canvas 485 31 494 344 META 0; #X text 12 135 HELP_PATCH_AUTHORS "pd meta" information added by Jonathan Wilkes for Pd version 0.42.; #X text 12 25 LICENSE GPL; #X text 12 115 AUTHOR Hans-Christoph Steiner; #X text 12 95 OUTLET_0 float; #X text 12 45 DESCRIPTION map the input range to a square curve \, i.e. [pow 2] \, "X squared" \, or X^2.; #X text 12 75 INLET_0 float; #X text 12 5 KEYWORDS control abstraction; #X restore 423 316 pd META; #X connect 5 0 9 0; #X connect 6 0 7 0; #X connect 8 0 5 0; #X connect 9 0 6 0; pd-hid_0.7/hid_rel2abs-help.pd0000644000076500007650000000262711504504627014731 0ustar hanshans#N canvas 487 359 469 312 10; #X obj 5 2 cnv 15 450 20 empty empty hid_rel2abs 2 11 1 18 -233017 -66577 0; #X obj 422 3 pddp/pddplink http://puredata.info/dev/pddp -text pddp ; #X text 27 270 (C) Copyright 2004 Hans-Christoph Steiner ; #X text 244 284 released under the GNU GPL; #X text 30 38 Converts relative axis data into an absolute position. ; #X obj 175 116 mouse; #X msg 193 73 open 1; #X msg 204 91 open 2; #X obj 157 75 tgl 25 0 empty empty empty 0 -6 0 8 -24198 -1 -1 0 1 ; #X floatatom 112 207 5 0 0 0 - - -; #X floatatom 153 207 5 0 0 0 - - -; #X floatatom 252 208 5 0 0 0 - - -; #X floatatom 211 208 5 0 0 0 - - -; #X obj 252 174 hid/hid_rel2abs 0 100; #X obj 73 175 hid/hid_rel2abs -10 10; #X text 98 240 For more info:; #X msg 73 129 reset; #X msg 284 129 reset; #N canvas 485 31 494 344 META 0; #X text 12 135 HELP_PATCH_AUTHORS "pd meta" information added by Jonathan Wilkes for Pd version 0.42.; #X text 12 25 LICENSE GPL; #X text 12 115 AUTHOR Hans-Christoph Steiner; #X text 12 95 OUTLET_0 float; #X text 12 45 DESCRIPTION convert relative axis data into an absolute position.; #X text 12 75 INLET_0 float reset; #X text 12 5 KEYWORDS control abstraction; #X restore 415 267 pd META; #X connect 5 0 10 0; #X connect 5 0 14 0; #X connect 5 1 12 0; #X connect 5 1 13 0; #X connect 6 0 5 0; #X connect 7 0 5 0; #X connect 8 0 5 0; #X connect 13 0 11 0; #X connect 14 0 9 0; #X connect 17 0 14 0; pd-hid_0.7/keygate-help.pd0000644000076500007650000000317311504504627014201 0ustar hanshans#N canvas 0 31 462 494 10; #X obj 5 2 cnv 15 450 20 empty empty keygate 2 11 1 18 -233017 -66577 0; #X obj 160 257 bng 25 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; #X obj 160 121 loadbang; #X msg 160 141 1; #X obj 160 169 metro 150; #X text 33 416 (C) Copyright 2004 Hans-Christoph Steiner ; #X text 250 430 released under the GNU GPL; #X obj 237 369 pddp/pddplink ../all_about_hid.pd -text all_about_hid ; #X text 128 370 For more info:; #X text 15 207 data to be gated -->; #X obj 281 258 bng 25 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; #X obj 40 300 keyname; #X symbolatom 79 324 10 0 0 0 - - -; #X text 157 324 <-- check here for the keyname symbol; #X obj 160 214 keygate f; #X text 17 38 [keygate] is a simple gate controlled by a keyboard. You must specify the name of the key which controls the gate. The left inlet takes the data to be gated.; #X text 18 89 The "f" key on the any keyboard controls this gate:; #X text 310 263 <-- key released; #X text 41 264 key pressed -->; #X obj 422 3 pddp/pddplink http://puredata.info/dev/pddp -text pddp ; #N canvas 472 31 494 344 META 0; #X text 12 145 HELP_PATCH_AUTHORS "pd meta" information added by Jonathan Wilkes for Pd version 0.42.; #X text 12 25 LICENSE GPL; #X text 12 125 AUTHOR Hans-Christoph Steiner; #X text 12 85 OUTLET_0 bang; #X text 12 105 OUTLET_1 bang; #X text 12 45 DESCRIPTION simple gate controlled by a keyboard; #X text 12 65 INLET_0 bang; #X text 12 5 KEYWORDS control user_input abstraction; #X restore 407 462 pd META; #X connect 2 0 3 0; #X connect 3 0 4 0; #X connect 4 0 14 0; #X connect 11 1 12 0; #X connect 14 0 1 0; #X connect 14 1 10 0; pd-hid_0.7/hid_lowpass-help.pd0000644000076500007650000000330611504504627015062 0ustar hanshans#N canvas 0 31 475 392 10; #X obj 5 2 cnv 15 450 20 empty empty hid_lowpass 2 11 1 18 -233017 -66577 0; #X obj 422 3 pddp/pddplink http://puredata.info/dev/pddp -text pddp ; #X text 27 340 (C) Copyright 2004 Hans-Christoph Steiner ; #X text 244 354 released under the GNU GPL; #X floatatom 112 199 5 0 0 0 - - -; #X floatatom 112 255 5 0 0 0 - - -; #X text 98 312 For more info:; #X obj 102 225 hid/hid_lowpass; #X obj 194 198 hsl 75 18 1 100 1 1 empty empty refresh(Hz) 4 9 1 12 -228992 -1 -1 0 0; #X floatatom 216 225 5 0 0 0 - - -; #X obj 105 272 hsl 250 15 0 1 0 0 empty empty empty -2 -6 0 8 -262144 -1 -1 0 1; #X obj 105 173 hsl 250 15 0 1 0 0 empty empty empty -2 -6 0 8 -262144 -1 -1 0 1; #X text 20 35 Smooths a stream of numbers by converting it to an audio signal and low-pass filtering that signal. By default \, the the filter is set to 10 Hz. You can set this using the right inlet. The lower the frequency \, the smoother the data \, but the greater the latency. ; #X obj 102 140 noise4hidhelp; #X obj 102 105 tgl 30 0 empty empty start 1 15 1 12 -90049 -1 -1 0 1; #N canvas 482 227 494 344 META 0; #X text 12 135 HELP_PATCH_AUTHORS "pd meta" information added by Jonathan Wilkes for Pd version 0.42.; #X text 12 25 LICENSE GPL; #X text 12 115 AUTHOR Hans-Christoph Steiner; #X text 12 75 INLET_0 float; #X text 12 95 OUTLET_0 float; #X text 12 45 DESCRIPTION smooth a stream of numbers by converting it to an audio signal and low-pass filtering that signal; #X text 12 5 KEYWORDS signal filter abstraction; #X restore 422 362 pd META; #X connect 7 0 5 0; #X connect 7 0 10 0; #X connect 8 0 7 1; #X connect 8 0 9 0; #X connect 11 0 4 0; #X connect 11 0 7 0; #X connect 13 0 11 0; #X connect 14 0 13 0; pd-hid_0.7/joystick-help.pd0000644000076500007650000001134311504504627014405 0ustar hanshans#N canvas 0 31 670 468 10; #X obj 168 91 tgl 25 0 empty empty empty 0 -6 0 8 -225271 -1 -1 0 1 ; #X floatatom 63 234 7 0 0 3 Y-axis - -; #X floatatom 9 234 7 0 0 3 X-axis - -; #X obj 212 324 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 252 324 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 293 324 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 334 324 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X floatatom 123 234 7 0 0 3 twist - -; #X floatatom 182 234 5 0 0 3 throttle - -; #X obj 375 324 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 416 324 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 456 324 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 497 324 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 538 324 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 579 324 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X symbolatom 335 234 6 0 0 3 code - -; #X floatatom 400 234 5 0 0 3 value - -; #X text 345 199 buttons; #X obj 2 2 cnv 15 650 20 empty empty joystick 2 11 1 18 -233017 -66577 0; #X msg 215 93 open 1; #X text 1 412 (C) Copyright 2004 Hans-Christoph Steiner ; #X text 218 426 released under the GNU GPL; #X text 414 426 $Author: eighthave $; #X text 414 413 $Revision: 1.11 $; #X obj 239 375 pddp/pddplink ../all_about_hid.pd -text all_about_hid ; #X text 130 376 For more info:; #X floatatom 245 234 5 0 0 3 hat0X - -; #X floatatom 288 234 5 0 0 3 hat0Y - -; #X obj 212 291 route btn_0 btn_1 btn_2 btn_3 btn_4 btn_5 btn_6 btn_7 btn_8 btn_9; #X obj 168 154 joystick 0; #N canvas 674 327 446 497 joystick_noise 0; #X obj 73 25 inlet; #X obj 219 426 dac~; #X obj 168 376 *~; #X obj 201 398 linearpan~; #X obj 70 168 hid/hid_invert; #X obj 70 242 mtof; #X obj 168 313 osc~; #X msg 57 88 \; pd dsp \$1; #X obj 70 193 hid/hid_squareroot; #X obj 287 11 inlet; #X obj 203 323 hid/hid_log; #X obj 180 65 joystick 0; #X obj 168 287 +~; #X obj 238 212 *~; #X obj 238 179 osc~; #X obj 304 143 * 300; #X obj 238 143 * 200; #X obj 304 123 hid/hid_square; #X obj 304 179 +; #X obj 238 123 hid/hid_exp; #X obj 203 360 line~; #X msg 203 342 \$1 5; #X obj 70 218 notescale 40 80; #X connect 0 0 7 0; #X connect 0 0 11 0; #X connect 2 0 3 0; #X connect 3 0 1 0; #X connect 3 1 1 1; #X connect 4 0 8 0; #X connect 5 0 12 0; #X connect 6 0 2 0; #X connect 8 0 22 0; #X connect 9 0 11 0; #X connect 10 0 21 0; #X connect 11 0 19 0; #X connect 11 1 4 0; #X connect 11 1 17 0; #X connect 11 2 3 1; #X connect 11 3 10 0; #X connect 12 0 6 0; #X connect 13 0 12 1; #X connect 14 0 13 0; #X connect 15 0 18 0; #X connect 16 0 14 0; #X connect 16 0 18 1; #X connect 17 0 15 0; #X connect 18 0 13 1; #X connect 19 0 16 0; #X connect 20 0 2 1; #X connect 21 0 20 0; #X connect 22 0 5 0; #X restore 440 155 pd joystick_noise; #X obj 440 92 tgl 25 0 empty empty empty 0 -6 0 8 -225271 -1 -1 0 1 ; #X text 333 73 Select your device and turn on to make noise:; #X obj 619 3 pddp/pddplink http://puredata.info/dev/pddp -text pddp ; #X msg 503 125 open \$1; #X obj 503 105 hradio 15 1 1 8 \$0-device-number empty choose_a_device 0 -6 1 9 -262144 -1 -1 2; #X obj 477 105 nbx 1 14 -1e+37 1e+37 0 0 empty \$0-device-number empty 0 -6 0 14 -166441 -1 -1 0 256; #X text 8 35 Use a joystick device with Pd. This object auto-calibrates the output of axis data. Move each element of the device thru its full range to calibrate it.; #X obj 335 215 unpack s f; #X text 422 177 (remember to calibrate all parts; #X text 430 190 of the joystick first); #X msg 394 120 print; #X msg 220 112 open 2; #X msg 225 131 open 3; #N canvas 674 84 494 344 META 0; #X text 12 245 HELP_PATCH_AUTHORS "pd meta" information added by Jonathan Wilkes for Pd version 0.42.; #X text 12 25 LICENSE GPL; #X text 12 225 AUTHOR Hans-Christoph Steiner; #X text 12 85 OUTLET_0 float; #X text 12 45 DESCRIPTION use a joystick device with Pd; #X text 12 65 INLET_0 float open print; #X text 12 105 OUTLET_1 float; #X text 12 125 OUTLET_2 float; #X text 12 145 OUTLET_3 float; #X text 12 165 OUTLET_4 float; #X text 12 185 OUTLET_5 float; #X text 12 205 OUTLET_6 list; #X text 12 5 KEYWORDS control user_input abstraction; #X restore 610 436 pd META; #X connect 0 0 29 0; #X connect 19 0 29 0; #X connect 28 0 3 0; #X connect 28 1 4 0; #X connect 28 2 5 0; #X connect 28 3 6 0; #X connect 28 4 9 0; #X connect 28 5 10 0; #X connect 28 6 11 0; #X connect 28 7 12 0; #X connect 28 8 13 0; #X connect 28 9 14 0; #X connect 29 0 2 0; #X connect 29 1 1 0; #X connect 29 2 7 0; #X connect 29 3 8 0; #X connect 29 4 26 0; #X connect 29 5 27 0; #X connect 29 6 28 0; #X connect 29 6 38 0; #X connect 31 0 30 0; #X connect 34 0 30 1; #X connect 35 0 34 0; #X connect 38 0 15 0; #X connect 38 1 16 0; #X connect 42 0 30 0; #X connect 43 0 29 0; pd-hid_0.7/hid_invert.pd0000644000076500007650000000050711504504627013753 0ustar hanshans#N canvas 360 364 381 307 10; #X obj 70 32 inlet; #X obj 84 249 outlet; #X text 140 249 output range: 0 to 1; #X text 9 5 [hid_invert]; #X text 118 32 input range: 0 to 1; #X obj 84 142 -; #X msg 70 122 1; #X obj 70 103 t b f; #X connect 0 0 7 0; #X connect 5 0 1 0; #X connect 6 0 5 0; #X connect 7 0 6 0; #X connect 7 1 5 1; pd-hid_0.7/hid2rad.pd0000644000076500007650000000112611504504627013133 0ustar hanshans#N canvas 8 31 432 344 10; #X obj 88 30 inlet; #X obj 89 264 outlet; #X text 19 9 [hid2rad]; #X obj 89 198 * 6.28318; #X obj 88 101 moses 0.5; #X obj 88 56 min 1; #X obj 88 74 max 0; #X obj 147 133 - 1; #X text 133 63 its a [hid] object \, so limit input range; #X text 129 28 input range: 0 to 1; #X text 143 264 output range: -pi to pi; #X text 232 311 released under the GNU GPL; #X text 15 297 (C) Copyright 2005 Hans-Christoph Steiner ; #X connect 0 0 5 0; #X connect 3 0 1 0; #X connect 4 0 3 0; #X connect 4 1 7 0; #X connect 5 0 6 0; #X connect 6 0 4 0; #X connect 7 0 3 0; pd-hid_0.7/hid_square-help.pd0000644000076500007650000000403011504504627014665 0ustar hanshans#N canvas 0 31 476 357 10; #X obj 5 2 cnv 15 450 20 empty empty hid_square 2 11 1 18 -233017 -66577 0; #X obj 422 3 pddp/pddplink http://puredata.info/dev/pddp -text pddp ; #X text 27 300 (C) Copyright 2004 Hans-Christoph Steiner ; #X text 244 314 released under the GNU GPL; #X text 98 271 For more info:; #X floatatom 25 123 8 0 0 0 - - -; #X floatatom 25 184 8 0 0 0 - - -; #X obj 28 211 hsl 200 15 0 1 0 0 empty empty empty 22 8 1 12 -262144 -1 -1 0 1; #X obj 28 103 hsl 200 15 0 1 0 0 empty empty empty 22 8 1 12 -261681 -1 -1 0 1; #X obj 25 153 hid/hid_square; #N canvas 0 22 450 300 (subpatch) 0; #X array hid_square 100 float 0; #X coords 0 1 99 0 100 100 1; #X restore 321 111 graph; #N canvas 266 69 327 317 draw_array 0; #X msg 57 52 bang; #X obj 57 73 until; #X text 88 52 start; #X obj 57 95 f; #X obj 86 95 + 1; #X obj 132 97 sel 0; #X obj 86 117 mod 100; #X obj 57 150 t f f; #X obj 94 177 s array_index; #X obj 170 262 r array_index; #X obj 57 13 loadbang; #X obj 57 207 / 100; #X text 99 207 [hid] output range: 0 to 1; #X obj 56 233 hid/hid_square; #X obj 56 283 tabwrite hid_square; #X connect 0 0 1 0; #X connect 1 0 3 0; #X connect 3 0 4 0; #X connect 3 0 7 0; #X connect 4 0 6 0; #X connect 5 0 1 1; #X connect 6 0 3 1; #X connect 6 0 5 0; #X connect 7 0 11 0; #X connect 7 1 8 0; #X connect 9 0 14 1; #X connect 10 0 0 0; #X connect 11 0 13 0; #X connect 13 0 14 0; #X restore 321 78 pd draw_array; #X text 15 34 This object maps the input range to a square curve \, i.e. [pow 2] \, "X squared" \, or X^2.; #N canvas 485 31 494 344 META 0; #X text 12 135 HELP_PATCH_AUTHORS "pd meta" information added by Jonathan Wilkes for Pd version 0.42.; #X text 12 25 LICENSE GPL; #X text 12 115 AUTHOR Hans-Christoph Steiner; #X text 12 95 OUTLET_0 float; #X text 12 45 DESCRIPTION map the input range to a square curve \, i.e. [pow 2] \, "X squared" \, or X^2.; #X text 12 75 INLET_0 float; #X text 12 5 KEYWORDS control abstraction; #X restore 421 319 pd META; #X connect 5 0 9 0; #X connect 6 0 7 0; #X connect 8 0 5 0; #X connect 9 0 6 0; pd-hid_0.7/hid_lowpass.pd0000644000076500007650000000072111504504627014132 0ustar hanshans#N canvas 666 425 438 310 10; #X obj 67 31 inlet; #X obj 67 235 outlet; #X text 7 266 (C) Copyright 2004 Hans-Christoph Steiner ; #X text 224 280 released under the GNU GPL; #X obj 252 30 inlet; #X obj 69 157 snapshot~; #X obj 68 58 t b f; #X obj 97 85 sig~; #X obj 97 115 lop~ 10; #X text 9 9 [hid_lowpass]; #X connect 0 0 6 0; #X connect 4 0 8 1; #X connect 5 0 1 0; #X connect 6 0 5 0; #X connect 6 1 7 0; #X connect 7 0 8 0; #X connect 8 0 5 0; pd-hid_0.7/hid_cube-help.pd0000644000076500007650000000403411504504627014307 0ustar hanshans#N canvas 0 31 472 353 10; #X obj 5 2 cnv 15 450 20 empty empty hid_graph 2 11 1 18 -233017 -66577 0; #X obj 422 3 pddp/pddplink http://puredata.info/dev/pddp -text pddp ; #X text 17 280 (C) Copyright 2004 Hans-Christoph Steiner ; #X text 234 294 released under the GNU GPL; #X text 88 251 For more info:; #X floatatom 25 123 8 0 0 0 - - -; #X floatatom 25 177 8 0 0 0 - - -; #X obj 28 201 hsl 200 15 0 1 0 0 empty empty empty 22 8 1 12 -262144 -1 -1 0 1; #X obj 28 103 hsl 200 15 0 1 0 0 empty empty empty 22 8 1 12 -261681 -1 -1 0 1; #X obj 25 153 hid/hid_cube; #X text 15 34 This object maps the input range to a cube curve \, i.e. [pow 3] or "X to power of 3".; #N canvas 0 22 450 300 (subpatch) 0; #X array hid_cube 100 float 0; #X coords 0 1 99 0 100 100 1; #X restore 321 111 graph; #N canvas 266 69 327 317 draw_array 0; #X msg 57 52 bang; #X obj 57 73 until; #X text 88 52 start; #X obj 57 95 f; #X obj 86 95 + 1; #X obj 132 97 sel 0; #X obj 86 117 mod 100; #X obj 57 150 t f f; #X obj 94 177 s array_index; #X obj 170 262 r array_index; #X obj 57 13 loadbang; #X obj 57 207 / 100; #X text 99 207 [hid] output range: 0 to 1; #X obj 56 233 hid/hid_cube; #X obj 56 283 tabwrite hid_cube; #X connect 0 0 1 0; #X connect 1 0 3 0; #X connect 3 0 4 0; #X connect 3 0 7 0; #X connect 4 0 6 0; #X connect 5 0 1 1; #X connect 6 0 3 1; #X connect 6 0 5 0; #X connect 7 0 11 0; #X connect 7 1 8 0; #X connect 9 0 14 1; #X connect 10 0 0 0; #X connect 11 0 13 0; #X connect 13 0 14 0; #X restore 321 78 pd draw_array; #N canvas 478 206 494 344 META 0; #X text 12 135 HELP_PATCH_AUTHORS "pd meta" information added by Jonathan Wilkes for Pd version 0.42.; #X text 12 25 LICENSE GPL; #X text 12 75 INLET_0 float; #X text 12 95 OUTLET_0 float; #X text 12 115 AUTHOR Hans-Christoph Steiner; #X text 12 45 DESCRIPTION this object maps the input range to a cube curve \, i.e. [pow 3] or "X to power of 3".; #X text 12 5 KEYWORDS control conversion abstraction; #X restore 415 326 pd META; #X connect 5 0 9 0; #X connect 6 0 7 0; #X connect 8 0 5 0; #X connect 9 0 6 0; pd-hid_0.7/hid2deg-help.pd0000644000076500007650000000237111504504627014055 0ustar hanshans#N canvas 0 31 483 323 10; #X obj 5 2 cnv 15 450 20 empty empty hid2deg 2 11 1 18 -233017 -66577 0; #X obj 422 3 pddp/pddplink http://puredata.info/dev/pddp -text pddp ; #X text 254 269 released under the GNU GPL; #X text 185 228 For more info:; #X text 40 254 (C) Copyright 2005 Hans-Christoph Steiner ; #X text 290 164 related objects:; #X obj 323 184 hid/rad2hid; #X obj 401 184 hid/deg2hid; #X floatatom 69 185 7 0 0 1 degrees - -; #X obj 72 85 hsl 128 15 0 1 0 0 empty empty hid 6 7 1 10 -262131 -1 -1 0 0; #X floatatom 95 115 5 0 0 0 - - -; #X obj 245 184 hid/hid2rad; #X obj 69 150 hid/hid2deg; #X text 26 34 This object converts numbers from the [hid] range (0 to 1) to degrees (0 to 360) with the 0 being north.; #N canvas 504 253 494 344 META 0; #X text 12 145 HELP_PATCH_AUTHORS "pd meta" information added by Jonathan Wilkes for Pd version 0.42.; #X text 12 25 LICENSE GPL; #X text 12 85 INLET_0 float; #X text 12 105 OUTLET_0 float; #X text 12 125 AUTHOR Hans-Christoph Steiner; #X text 12 45 DESCRIPTION convert numbers from the [hid] range (0 to 1) to degrees (0 to 360) with the 0 being north.; #X text 12 5 KEYWORDS control conversion abstraction; #X restore 427 293 pd META; #X connect 9 0 12 0; #X connect 10 0 12 0; #X connect 12 0 8 0; pd-hid_0.7/keyboard-help.pd0000644000076500007650000001155611504504627014354 0ustar hanshans#N canvas 0 31 567 507 10; #X obj 168 91 tgl 25 0 empty empty empty 0 -6 0 8 -225271 -1 -1 0 1 ; #X obj 11 369 tgl 20 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1 ; #X symbolatom 168 222 12 0 0 0 code - -; #X floatatom 296 222 5 0 0 1 value - -; #X obj 168 195 unpack symbol float; #X text 239 238 buttons; #X obj 2 2 cnv 15 550 20 empty empty keyboard 2 11 1 18 -233017 -66577 0; #X msg 204 93 open 1; #X text 1 432 (C) Copyright 2004 Hans-Christoph Steiner ; #X text 218 446 released under the GNU GPL; #X text 414 446 $Author: eighthave $; #X text 414 433 $Revision: 1.4 $; #X obj 348 402 pddp/pddplink ../all_about_hid.pd -text all_about_hid ; #X text 239 403 For more info:; #X msg 209 112 open 3; #X obj 32 369 tgl 20 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1 ; #X obj 53 369 tgl 20 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1 ; #X obj 74 369 tgl 20 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1 ; #X obj 95 369 tgl 20 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1 ; #X obj 116 369 tgl 20 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 137 369 tgl 20 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 158 369 tgl 20 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 179 369 tgl 20 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 200 369 tgl 20 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 221 369 tgl 20 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 242 369 tgl 20 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 263 369 tgl 20 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 284 369 tgl 20 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 305 369 tgl 20 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 326 369 tgl 20 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 347 369 tgl 20 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 368 369 tgl 20 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 389 369 tgl 20 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 410 369 tgl 20 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 431 369 tgl 20 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 452 369 tgl 20 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 473 369 tgl 20 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 494 369 tgl 20 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X text 117 270 Most keyboards can detect multiple keys at the same time. You can test yours by pressing and holding keys and counting how many "X"s are shown below; #X text 8 36 Use a keyboard device with Pd. This object gives you raw access to the keyboard events. Pd does not need to have focus in order get the key events. No matter which application has focus \, this object will get keyboard events.; #X obj 75 315 route key_4 key_5 key_6 key_7 key_8 key_9 key_10 key_11 key_12 key_13 key_14 key_15 key_16 key_17 key_18 key_19 key_20 key_21 key_22 key_23 key_24 key_25 key_26 key_27; #X obj 519 3 pddp/pddplink http://puredata.info/dev/pddp -text pddp ; #X obj 168 174 hid/keyboard 0; #X msg 109 123 print; #N canvas 162 133 570 420 serin 0; #X obj 286 61 cnv 15 30 15 empty \$0-open-canvas 1 4 8 0 14 -233017 -1 0; #X obj 60 61 hradio 15 1 1 15 empty empty empty 0 -6 0 8 -225271 -1 -1 1; #X obj 60 13 inlet; #X msg 200 202 label \$1; #X obj 200 180 makefilename %d; #X obj 59 108 int; #X obj 59 337 outlet; #X msg 201 306 set \$1 \$2; #X obj 59 266 trigger bang anything; #X obj 201 286 list; #X msg 60 210 open \$1; #X obj 200 225 send \$0-open-canvas; #X connect 1 0 5 0; #X connect 2 0 1 0; #X connect 3 0 11 0; #X connect 4 0 3 0; #X connect 5 0 4 0; #X connect 5 0 10 0; #X connect 7 0 6 0; #X connect 8 0 6 0; #X connect 8 1 9 0; #X connect 9 0 7 0; #X connect 10 0 8 0; #X coords 0 -1 1 1 257 17 1 60 60; #X restore 216 131 pd serin; #X msg 216 152 open 1; #N canvas 577 31 494 344 META 0; #X text 12 125 HELP_PATCH_AUTHORS "pd meta" information added by Jonathan Wilkes for Pd version 0.42.; #X text 12 25 LICENSE GPL; #X text 12 105 AUTHOR Hans-Christoph Steiner; #X text 12 65 INLET_0 float open print; #X text 12 45 DESCRIPTION use a keyboard device with Pd; #X text 12 85 OUTLET_0 list; #X text 12 5 KEYWORDS control user_input abstraction; #X restore 509 478 pd META; #X connect 0 0 42 0; #X connect 4 0 2 0; #X connect 4 1 3 0; #X connect 7 0 42 0; #X connect 14 0 42 0; #X connect 40 0 1 0; #X connect 40 1 15 0; #X connect 40 2 16 0; #X connect 40 3 17 0; #X connect 40 4 18 0; #X connect 40 5 19 0; #X connect 40 6 20 0; #X connect 40 7 21 0; #X connect 40 8 22 0; #X connect 40 9 23 0; #X connect 40 10 24 0; #X connect 40 11 25 0; #X connect 40 12 26 0; #X connect 40 13 27 0; #X connect 40 14 28 0; #X connect 40 15 29 0; #X connect 40 16 30 0; #X connect 40 17 31 0; #X connect 40 18 32 0; #X connect 40 19 33 0; #X connect 40 20 34 0; #X connect 40 21 35 0; #X connect 40 22 36 0; #X connect 40 23 37 0; #X connect 42 0 4 0; #X connect 42 0 40 0; #X connect 43 0 42 0; #X connect 44 0 45 0; #X connect 45 0 42 0; pd-hid_0.7/hid_cube.pd0000644000076500007650000000046611504504627013366 0ustar hanshans#N canvas 0 31 483 309 10; #X obj 72 63 inlet; #X obj 72 240 outlet; #X text 120 63 input range: 0 to 1; #X text 128 240 output range: 0 to 1; #X obj 72 166 pow 3; #X text 7 9 [hid_cube]; #X obj 72 106 min 1; #X obj 72 126 max 0; #X connect 0 0 6 0; #X connect 4 0 1 0; #X connect 6 0 7 0; #X connect 7 0 4 0; pd-hid_0.7/LICENSE.txt0000644000076500007650000010451311504504627013120 0ustar hanshans GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . pd-hid_0.7/hid_darwin.c0000644000076500007650000017264611504504627013565 0ustar hanshans#ifdef __APPLE__ /* * Apple Darwin HID Manager support for Pd [hid] object * * some code from SuperCollider3's SC_HID.cpp by Jan Truetzschler Falkenstein * * Copyright (c) 2004 Hans-Christoph All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * */ /* struct IOHIDEventStruct */ /* { */ /* IOHIDElementType type; */ /* IOHIDElementCookie elementCookie; */ /* SInt32 value; */ /* AbsoluteTime timestamp; */ /* UInt32 longValueSize; */ /* void * longValue; */ /* }; */ /* typedef struct { */ /* natural_t hi; */ /* natural_t lo; */ /* } AbsoluteTime; */ #include #include "HID_Utilities_External.h" #include "ImmrHIDUtilAddOn.h" #include #include #include #include #include "hid.h" #define DEBUG(x) //#define DEBUG(x) x /*============================================================================== * GLOBAL VARS *======================================================================== */ /* store device pointers so I don't have to query them all the time */ pRecDevice device_pointer[MAX_DEVICES]; // this stuff is moving to the t_hid_element struct /* store element pointers for elements that are not queued (absolute axes) */ //pRecElement element[MAX_DEVICES][MAX_ELEMENTS]; /* number of active elements per device */ //unsigned short element_count[MAX_DEVICES]; /*============================================================================== * FUNCTION PROTOTYPES *============================================================================== */ /* conversion functions */ static char *convertEventsFromDarwinToLinux(pRecElement element); /*============================================================================== * EVENT TYPE/CODE CONVERSION FUNCTIONS *============================================================================== */ /* * This function is needed to translate the USB HID relative flag into the * [hid]/linux style events */ static void convert_axis_to_symbols(pRecElement pCurrentHIDElement, t_hid_element *new_element, char *axis) { char buffer[MAXPDSTRING]; if (pCurrentHIDElement->relative) { new_element->type = gensym("rel"); snprintf(buffer, sizeof(buffer), "rel_%s", axis); new_element->name = gensym(buffer); } else { new_element->type = gensym("abs"); snprintf(buffer, sizeof(buffer), "abs_%s", axis); new_element->name = gensym(buffer); } } static void get_usage_symbols(pRecElement pCurrentHIDElement, t_hid_element *new_element) { // debug_print(LOG_DEBUG,"get_usage_symbols"); char buffer[MAXPDSTRING]; if(new_element == NULL) { debug_print(LOG_EMERG,"[hid] new_element == NULL!! This is a bug, please report it."); return; } if(pCurrentHIDElement == NULL) { debug_print(LOG_EMERG,"[hid] pCurrentHIDElement == NULL!! This is a bug, please report it."); return; } switch(pCurrentHIDElement->type) { case kIOHIDElementTypeInput_Button: new_element->type = gensym("key"); break; } switch (pCurrentHIDElement->usagePage) { case kHIDPage_GenericDesktop: switch (pCurrentHIDElement->usage) { case kHIDUsage_GD_X: convert_axis_to_symbols(pCurrentHIDElement, new_element, "x"); break; case kHIDUsage_GD_Y: convert_axis_to_symbols(pCurrentHIDElement, new_element, "y"); break; case kHIDUsage_GD_Z: convert_axis_to_symbols(pCurrentHIDElement, new_element, "z"); break; case kHIDUsage_GD_Rx: convert_axis_to_symbols(pCurrentHIDElement, new_element, "rx"); break; case kHIDUsage_GD_Ry: convert_axis_to_symbols(pCurrentHIDElement, new_element, "ry"); break; case kHIDUsage_GD_Rz: convert_axis_to_symbols(pCurrentHIDElement, new_element, "rz"); break; case kHIDUsage_GD_Slider: new_element->type = gensym("abs"); new_element->name = gensym("abs_throttle"); break; case kHIDUsage_GD_Dial: new_element->type = gensym("abs"); new_element->name = gensym("abs_ry"); break; case kHIDUsage_GD_Wheel: new_element->type = gensym("rel"); new_element->name = gensym("rel_wheel"); break; case kHIDUsage_GD_Hatswitch: // this is still a mystery how to handle new_element->type = gensym("abs"); new_element->name = gensym("hatswitch"); break; default: new_element->type = gensym("DESKTOP"); snprintf(buffer, sizeof(buffer), "DESKTOP%ld", pCurrentHIDElement->usage); new_element->name = gensym(buffer); } break; case kHIDPage_Simulation: switch (pCurrentHIDElement->usage) { case kHIDUsage_Sim_Rudder: new_element->type = gensym("abs"); new_element->name = gensym("abs_rz"); break; case kHIDUsage_Sim_Throttle: new_element->type = gensym("abs"); new_element->name = gensym("abs_throttle"); break; default: new_element->type = gensym("SIMULATION"); snprintf(buffer, sizeof(buffer), "SIMULATION%ld", pCurrentHIDElement->usage); new_element->name = gensym(buffer); } break; case kHIDPage_KeyboardOrKeypad: new_element->type = gensym("key"); /* temporary kludge until I feel like writing the translation table */ snprintf(buffer, sizeof(buffer), "key_%ld", pCurrentHIDElement->usage); new_element->name = gensym(buffer); break; case kHIDPage_Button: new_element->type = gensym("key"); /* HID Manager button numbers start at 1, [hid] start at 0 */ snprintf(buffer, sizeof(buffer), "btn_%ld", pCurrentHIDElement->usage - 1); new_element->name = gensym(buffer); break; case kHIDPage_LEDs: /* temporary kludge until I feel like writing the translation table */ new_element->type = gensym("led"); snprintf(buffer, sizeof(buffer), "led_%ld", pCurrentHIDElement->usage); new_element->name = gensym(buffer); break; case kHIDPage_PID: /* temporary kludge until I feel like writing the translation table */ new_element->type = gensym("ff"); snprintf(buffer, sizeof(buffer), "ff_%ld", pCurrentHIDElement->usage); new_element->name = gensym(buffer); break; default: /* the rest are "vendor defined" so no translation table is possible */ snprintf(buffer, sizeof(buffer), "0x%04x", (unsigned int) pCurrentHIDElement->usagePage); new_element->type = gensym(buffer); snprintf(buffer, sizeof(buffer), "0x%04x", (unsigned int) pCurrentHIDElement->usage); new_element->name = gensym(buffer); } } static t_float get_type_name_instance(t_symbol *type, t_symbol *name, int argc, t_hid_element **argv) { int i; int instance_count = 0; for(i=0; iname == name) && (argv[i]->type == type) ) { ++instance_count; // post("found %d instances of %s %s", instance_count, type->s_name, name->s_name); } } return((t_float) instance_count); } /* * Linux input events report hatswitches as absolute axes with -1, 0, 1 as * possible values. MacOS X HID Manager reports hatswitches as a specific * hatswitch type with each direction represented by a unique number. This * function converts the unique number to the Linux style axes. */ /* * hmm, not sure how to implement this cleanly yet, * MacOS X represents this as one event, while [hid] represents it as two * distinct axes. So the conversion requires an added hid_output_event(). void hid_convert_hatswitch_values(IOHIDEventStruct event, t_symbol *type, t_atom *usage) { case 0: name = gensym("abs_hat0y");value = 1; hid_output_event(x, type, name, value); name = gensym("abs_hat0x");value = 0; break; case 1: name = gensym("abs_hat0y");value = 1; hid_output_event(x, type, name, value); name = gensym("abs_hat0x");value = 1; break; case 2: name = gensym("abs_hat0y");value = 0; hid_output_event(x, type, name, value); name = gensym("abs_hat0x");value = 1; break; case 3: name = gensym("abs_hat0y");value = -1; hid_output_event(x, type, name, value); name = gensym("abs_hat0x");value = 1; break; case 4: name = gensym("abs_hat0y");value = -1; hid_output_event(x, type, name, value); name = gensym("abs_hat0x");value = 0; break; case 5: name = gensym("abs_hat0y");value = -1; hid_output_event(x, type, name, value); name = gensym("abs_hat0x");value = -1; break; case 6: name = gensym("abs_hat0y");value = 0; hid_output_event(x, type, name, value); name = gensym("abs_hat0x");value = -1; break; case 7: name = gensym("abs_hat0y");value = 1; hid_output_event(x, type, name, value); name = gensym("abs_hat0x");value = -1; break; case 8: name = gensym("abs_hat0y");value = 0; hid_output_event(x, type, name, value); name = gensym("abs_hat0x");value = 0; break; } } */ /* ============================================================================== */ /* DARWIN-SPECIFIC SUPPORT FUNCTIONS */ /* ============================================================================== */ short get_device_number_by_id(unsigned short vendor_id, unsigned short product_id) { debug_print(LOG_DEBUG,"get_device_number_from_usage"); pRecDevice pCurrentHIDDevice; t_int i; short return_device_number = -1; if( !HIDHaveDeviceList() ) hid_build_device_list(); pCurrentHIDDevice = HIDGetFirstDevice(); i = HIDCountDevices(); while(pCurrentHIDDevice != NULL) { --i; debug_print(LOG_INFO,"compare 0x%04x == 0x%04x 0x%04x == 0x%04x", pCurrentHIDDevice->vendorID, vendor_id, pCurrentHIDDevice->productID, product_id); if( (pCurrentHIDDevice->vendorID == vendor_id) && (pCurrentHIDDevice->productID == product_id) ) { return_device_number = i; pCurrentHIDDevice = NULL; } else pCurrentHIDDevice = HIDGetNextDevice(pCurrentHIDDevice); } return(return_device_number); } short get_device_number_from_usage(short device_number, unsigned short usage_page, unsigned short usage) { // debug_print(LOG_DEBUG,"get_device_number_from_usage"); pRecDevice pCurrentHIDDevice; t_int i; short return_device_number = -1; t_int total_devices = 0; char cstrDeviceName[MAXPDSTRING]; if( !HIDHaveDeviceList() ) hid_build_device_list(); pCurrentHIDDevice = HIDGetFirstDevice(); while(pCurrentHIDDevice != NULL) { if( (pCurrentHIDDevice->usagePage == usage_page) && (pCurrentHIDDevice->usage == usage) ) { ++total_devices; } pCurrentHIDDevice = HIDGetNextDevice(pCurrentHIDDevice); } i = total_devices; return_device_number = HIDCountDevices(); pCurrentHIDDevice = HIDGetFirstDevice(); while( (pCurrentHIDDevice != NULL) && (i > device_number) ) { return_device_number--; if( (pCurrentHIDDevice->usagePage == usage_page) && (pCurrentHIDDevice->usage == usage) ) { i--; HIDGetUsageName(pCurrentHIDDevice->usagePage, pCurrentHIDDevice->usage, cstrDeviceName); debug_print(LOG_DEBUG,"[hid]: found a %s at %d/%d: %s %s" ,cstrDeviceName, i, total_devices, pCurrentHIDDevice->manufacturer, pCurrentHIDDevice->product); } pCurrentHIDDevice = HIDGetNextDevice(pCurrentHIDDevice); } if(i < total_devices) return(return_device_number); else return(-1); } static void hid_build_element_list(t_hid *x) { char type_name[256]; char usage_name[256]; pRecElement pCurrentHIDElement; pRecDevice pCurrentHIDDevice = device_pointer[x->x_device_number]; t_hid_element *new_element; element_count[x->x_device_number] = 0; if( HIDIsValidDevice(pCurrentHIDDevice) ) { /* queuing one element at a time only works for the first element, so * try queuing the whole device, then removing specific elements from * the queue */ HIDQueueDevice(pCurrentHIDDevice); pCurrentHIDElement = HIDGetFirstDeviceElement( pCurrentHIDDevice, kHIDElementTypeInput ); while( pCurrentHIDElement != NULL) { /* these two functions just get the pretty names for display */ HIDGetTypeName((IOHIDElementType) pCurrentHIDElement->type, type_name); HIDGetUsageName(pCurrentHIDElement->usagePage, pCurrentHIDElement->usage, usage_name); new_element = getbytes(sizeof(t_hid_element)); new_element->os_pointer = (void *) pCurrentHIDElement; get_usage_symbols(pCurrentHIDElement, new_element); new_element->relative = pCurrentHIDElement->relative; new_element->instance = get_type_name_instance(new_element->type, new_element->name, element_count[x->x_device_number], element[x->x_device_number]); if( (pCurrentHIDElement->usagePage == kHIDPage_GenericDesktop) && (!pCurrentHIDElement->relative) ) { switch(pCurrentHIDElement->usage) { case kHIDUsage_GD_X: case kHIDUsage_GD_Y: case kHIDUsage_GD_Z: case kHIDUsage_GD_Rx: case kHIDUsage_GD_Ry: case kHIDUsage_GD_Rz: case kHIDUsage_GD_Slider: case kHIDUsage_GD_Dial: case kHIDUsage_GD_Wheel: //case kHIDUsage_GD_Hatswitch: // hatswitches are more like buttons, so queue them debug_print(LOG_INFO,"[hid] storing absolute axis to poll %s, %s (0x%04x 0x%04x)", type_name, usage_name, pCurrentHIDElement->usagePage, pCurrentHIDElement->usage); if(HIDDequeueElement(pCurrentHIDDevice,pCurrentHIDElement) != kIOReturnSuccess) debug_print(LOG_ERR,"[hid] could not dequeue element"); new_element->polled = 1; break; } } else { debug_print(LOG_INFO,"[hid] queuing element %s, %s (0x%04x 0x%04x)", type_name, usage_name, pCurrentHIDElement->usagePage, pCurrentHIDElement->usage); } new_element->min = pCurrentHIDElement->min; new_element->max = pCurrentHIDElement->max; debug_print(LOG_DEBUG,"\tlogical min %d max %d", pCurrentHIDElement->min,pCurrentHIDElement->max); element[x->x_device_number][element_count[x->x_device_number]] = new_element; ++element_count[x->x_device_number]; pCurrentHIDElement = HIDGetNextDeviceElement(pCurrentHIDElement, kHIDElementTypeInput); } } } static void hid_print_element_list(t_hid *x) { // debug_print(LOG_DEBUG,"hid_print_element_list"); int i; pRecElement pCurrentHIDElement; pRecDevice pCurrentHIDDevice; t_hid_element *current_element; char type_name[256]; char usage_name[256]; pCurrentHIDDevice = device_pointer[x->x_device_number]; if ( ! HIDIsValidDevice(pCurrentHIDDevice) ) { error("[hid]: device %d is not a valid device\n",x->x_device_number); return; } post("[hid] found %d elements:",element_count[x->x_device_number]); post("\n TYPE\tCODE\t#\tEVENT NAME"); post("-----------------------------------------------------------"); for(i=0; ix_device_number]; i++) { current_element = element[x->x_device_number][i]; pCurrentHIDElement = (pRecElement) current_element->os_pointer; HIDGetTypeName((IOHIDElementType) pCurrentHIDElement->type, type_name); HIDGetUsageName(pCurrentHIDElement->usagePage, pCurrentHIDElement->usage, usage_name); post(" %s\t%s\t%d\t%s, %s", current_element->type->s_name, current_element->name->s_name,(int) current_element->instance, type_name, usage_name); } post(""); } void hid_ff_print( t_hid *x ) { debug_print(LOG_DEBUG,"hid_ff_print"); HRESULT result; UInt32 value; if ( x->x_has_ff ) { result = FFDeviceGetForceFeedbackProperty( (FFDeviceObjectReference) x->x_ff_device, FFPROP_AUTOCENTER, &value, (IOByteCount) sizeof( value ) ); if ( result == FF_OK ) post( "autocenter: %d",value ); result = FFDeviceGetForceFeedbackProperty( (FFDeviceObjectReference) x->x_ff_device, FFPROP_FFGAIN, &value, (IOByteCount) sizeof( value ) ); if ( result == FF_OK ) post( "gain: %d", value ); } // FFEffectGetParameters( ); } static void hid_print_device_list(t_hid *x) { char device_type_buffer[256]; t_int i, numdevs; unsigned int j; pRecDevice pCurrentHIDDevice = NULL; if( HIDHaveDeviceList() ) { numdevs = (t_int) HIDCountDevices(); post(""); /* display device list in console */ for(i=0; i < numdevs; i++) { pCurrentHIDDevice = device_pointer[i]; post("__________________________________________________"); post("Device %d: '%s' '%s' version %d @ location 0x%08x", i, pCurrentHIDDevice->manufacturer, pCurrentHIDDevice->product, pCurrentHIDDevice->version,pCurrentHIDDevice->locID); HIDGetUsageName(pCurrentHIDDevice->usagePage, pCurrentHIDDevice->usage, device_type_buffer); for(j=0; j< strlen(device_type_buffer); ++j) device_type_buffer[j] = tolower(device_type_buffer[j]); post("\tdevice type: %s\tusage page: 0x%04x\tusage: 0x%04x", device_type_buffer, pCurrentHIDDevice->usagePage, pCurrentHIDDevice->usage); post("\tvendorID: 0x%04x\tproductID: 0x%04x", pCurrentHIDDevice->vendorID, pCurrentHIDDevice->productID); } post(""); } } /* ============================================================================== * STATUS/INFO OUTPUT * ============================================================================== */ void hid_platform_specific_info(t_hid *x) { unsigned int i; pRecDevice pCurrentHIDDevice = NULL; char vendor_id_string[7]; char product_id_string[7]; char device_type_buffer[256]; t_symbol *output_symbol; t_atom *output_atom = getbytes(sizeof(t_atom)); if(x->x_device_number > -1) { // pCurrentHIDDevice = hid_get_device_by_number(x->x_device_number); pCurrentHIDDevice = device_pointer[x->x_device_number]; if(pCurrentHIDDevice != NULL) { /* product */ SETSYMBOL(output_atom, gensym(pCurrentHIDDevice->product)); outlet_anything( x->x_status_outlet, gensym("product"), 1, output_atom); /* manufacturer */ SETSYMBOL(output_atom, gensym(pCurrentHIDDevice->manufacturer)); outlet_anything( x->x_status_outlet, gensym("manufacturer"), 1, output_atom); /* serial number */ if(pCurrentHIDDevice->serial != NULL) { output_symbol = gensym(pCurrentHIDDevice->serial); if( output_symbol != &s_ ) { /* the serial is rarely used on USB devices, so test for it */ SETSYMBOL(output_atom, output_symbol); outlet_anything( x->x_status_outlet, gensym("serial"), 1, output_atom); } } /* transport */ SETSYMBOL(output_atom, gensym(pCurrentHIDDevice->transport)); outlet_anything( x->x_status_outlet, gensym("transport"), 1, output_atom); /* vendor id */ sprintf(vendor_id_string,"0x%04x", (unsigned int)pCurrentHIDDevice->vendorID); SETSYMBOL(output_atom, gensym(vendor_id_string)); outlet_anything( x->x_status_outlet, gensym("vendorID"), 1, output_atom); /* product id */ sprintf(product_id_string,"0x%04x", (unsigned int)pCurrentHIDDevice->productID); SETSYMBOL(output_atom, gensym(product_id_string)); outlet_anything( x->x_status_outlet, gensym("productID"), 1, output_atom); /* type */ HIDGetUsageName(pCurrentHIDDevice->usagePage, pCurrentHIDDevice->usage, device_type_buffer); for(i=0; i< strlen(device_type_buffer); ++i) device_type_buffer[i] = tolower(device_type_buffer[i]); SETSYMBOL(output_atom, gensym(device_type_buffer)); outlet_anything( x->x_status_outlet, gensym("type"), 1, output_atom); } } freebytes(output_atom,sizeof(t_atom)); } /* ============================================================================== */ /* Pd [hid] FUNCTIONS */ /* ============================================================================== */ void hid_get_events(t_hid *x) { unsigned int i; pRecDevice pCurrentHIDDevice; t_hid_element *current_element; IOHIDEventStruct event; pCurrentHIDDevice = device_pointer[x->x_device_number]; /* get the queued events first and store them */ // while( (HIDGetEvent(pCurrentHIDDevice, (void*) &event)) && (event_counter < MAX_EVENTS_PER_POLL) ) while(HIDGetEvent(pCurrentHIDDevice, (void*) &event)) { i=0; do { current_element = element[x->x_device_number][i]; ++i; } while( (i < element_count[x->x_device_number]) && (((pRecElement)current_element->os_pointer)->cookie != (IOHIDElementCookie) event.elementCookie) ); current_element->value = event.value; debug_print(LOG_DEBUG,"output this: %s %s %d prev %d",current_element->type->s_name, current_element->name->s_name, current_element->value, current_element->previous_value); } /* absolute axes don't need to be queued, they can just be polled */ for(i=0; i< element_count[x->x_device_number]; ++i) { current_element = element[x->x_device_number][i]; if(current_element->polled) { current_element->value = HIDGetElementValue(pCurrentHIDDevice, (pRecElement)current_element->os_pointer); } } } t_int hid_open_device(t_hid *x, short device_number) { debug_print(LOG_DEBUG,"hid_open_device"); t_int result = 0; pRecDevice pCurrentHIDDevice = NULL; io_service_t hidDevice = 0; FFDeviceObjectReference ffDeviceReference = NULL; /* rebuild device list to make sure the list is current */ if( !HIDHaveDeviceList() ) hid_build_device_list(); // pCurrentHIDDevice = hid_get_device_by_number(device_number); pCurrentHIDDevice = device_pointer[device_number]; if( HIDIsValidDevice(pCurrentHIDDevice) ) { x->x_device_number = device_number; } else { debug_error(x,LOG_ERR,"[hid]: device %d is not a valid device\n",device_number); return(1); } debug_print(LOG_WARNING,"[hid] opened device %d: %s %s", device_number, pCurrentHIDDevice->manufacturer, pCurrentHIDDevice->product); hid_build_element_list(x); hidDevice = AllocateHIDObjectFromRecDevice( pCurrentHIDDevice ); if( FFIsForceFeedback(hidDevice) == FF_OK ) { debug_print(LOG_WARNING,"\tdevice has Force Feedback support"); if( FFCreateDevice(hidDevice,&ffDeviceReference) == FF_OK ) { x->x_has_ff = 1; x->x_ff_device = ffDeviceReference; } else { x->x_has_ff = 0; post("[hid]: FF device creation failed!"); return( -1 ); } } return(result); } t_int hid_close_device(t_hid *x) { debug_print(LOG_DEBUG,"hid_close_device"); t_int result = 0; // pRecDevice pCurrentHIDDevice = hid_get_device_by_number(x->x_device_number); pRecDevice pCurrentHIDDevice = device_pointer[x->x_device_number]; HIDDequeueDevice(pCurrentHIDDevice); // this doesn't seem to be needed at all, but why not use it? // result = HIDCloseReleaseInterface(pCurrentHIDDevice); return(result); } void hid_build_device_list(void) { int device_number = 0; pRecDevice pCurrentHIDDevice; debug_print(LOG_DEBUG,"hid_build_device_list"); debug_print(LOG_WARNING,"[hid] Building device list..."); if(HIDBuildDeviceList (0, 0)) post("[hid]: no HID devices found\n"); /* The most recently discovered HID is the first element of the list here. I * want the oldest to be number 0 rather than the newest. */ device_number = (int) HIDCountDevices(); pCurrentHIDDevice = HIDGetFirstDevice(); while(pCurrentHIDDevice != NULL) { --device_number; if(device_number < MAX_DEVICES) device_pointer[device_number] = pCurrentHIDDevice; pCurrentHIDDevice = HIDGetNextDevice(pCurrentHIDDevice); } device_count = (unsigned int) HIDCountDevices(); // set the global variable debug_print(LOG_WARNING,"[hid] completed device list."); } void hid_print(t_hid *x) { if( !HIDHaveDeviceList() ) hid_build_device_list(); hid_print_device_list(x); if(x->x_device_open) { hid_print_element_list(x); hid_ff_print(x); } } void hid_platform_specific_free(t_hid *x) { debug_print(LOG_DEBUG,"hid_platform_specific_free"); /* only call this if the last instance is being freed */ if (hid_instance_count < 1) { DEBUG(post("RELEASE ALL hid_instance_count: %d", hid_instance_count);); HIDReleaseAllDeviceQueues(); HIDReleaseDeviceList(); } } /* ============================================================================== * FORCE FEEDBACK * ============================================================================== */ /* -------------------------------------------------------------------------- * FF "Properties" * autocenter ( 0/1 ), ffgain (overall feedback gain 0-10000) */ t_int hid_ff_autocenter(t_hid *x, t_float value) { debug_print(LOG_DEBUG,"hid_ff_autocenter"); HRESULT result; UInt32 autocenter_value; if( x->x_has_ff ) { if ( value > 0 ) autocenter_value = 1; else if ( value <= 0 ) autocenter_value = 0; /* FFPROP_AUTOCENTER is either 0 or 1 */ result = FFDeviceSetForceFeedbackProperty( (FFDeviceObjectReference) x->x_ff_device, FFPROP_AUTOCENTER, &autocenter_value ); if ( result != FF_OK ) { post("[hid]: ff_autocenter failed!"); } } return(0); } t_int hid_ff_gain(t_hid *x, t_float value) { debug_print(LOG_DEBUG,"hid_ff_gain"); HRESULT result; UInt32 ffgain_value; if( x->x_has_ff ) { if ( value > 1 ) value = 1; else if ( value < 0 ) value = 0; ffgain_value = value * 10000; /* FFPROP_FFGAIN has a integer range of 0-10000 */ result = FFDeviceSetForceFeedbackProperty( (FFDeviceObjectReference)x->x_ff_device, FFPROP_FFGAIN, &ffgain_value ); if ( result != FF_OK ) { post("[hid]: ff_gain failed!"); } } return(0); } /* -------------------------------------------------------------------------- * FF "Commands" * continue, pause, reset, setactuatorsoff, setactuatorson, stopall */ t_int hid_ff_send_ff_command (t_hid *x, UInt32 ff_command) { HRESULT result = 0; if( x->x_has_ff ) { result = FFDeviceSendForceFeedbackCommand( x->x_ff_device, ff_command ); } return ( (t_int) result ); } t_int hid_ff_continue( t_hid *x ) { debug_print(LOG_DEBUG,"hid_ff_continue"); return( hid_ff_send_ff_command( x, FFSFFC_CONTINUE ) ); } t_int hid_ff_pause( t_hid *x ) { debug_print(LOG_DEBUG,"hid_ff_pause"); return( hid_ff_send_ff_command( x, FFSFFC_PAUSE ) ); } t_int hid_ff_reset( t_hid *x ) { debug_print(LOG_DEBUG,"hid_ff_reset"); return( hid_ff_send_ff_command( x, FFSFFC_RESET ) ); } t_int hid_ff_setactuatorsoff( t_hid *x ) { debug_print(LOG_DEBUG,"hid_ff_setactuatorsoff"); return( hid_ff_send_ff_command( x, FFSFFC_SETACTUATORSOFF ) ); } t_int hid_ff_setactuatorson( t_hid *x ) { debug_print(LOG_DEBUG,"hid_ff_setactuatorson"); return( hid_ff_send_ff_command( x, FFSFFC_SETACTUATORSON ) ); } t_int hid_ff_stopall( t_hid *x ) { debug_print(LOG_DEBUG,"hid_ff_stopall"); return( hid_ff_send_ff_command( x, FFSFFC_STOPALL ) ); } t_int hid_ff_motors( t_hid *x, t_float value ) { if ( value > 0 ) { return ( hid_ff_setactuatorson( x ) ); } else { return ( hid_ff_setactuatorsoff( x ) ); } } /* -------------------------------------------------------------------------- * FF test functions */ t_int hid_ff_fftest ( t_hid *x, t_float value) { debug_print(LOG_DEBUG,"hid_ff_fftest"); return( 0 ); } /* ---------------------------------------------------------------------------------------------------- * the big monster look up table (not used yet) */ //void HIDGetUsageName (const long valueUsagePage, const long valueUsage, char * cstrName) char *convertEventsFromDarwinToLinux(pRecElement element) { char *cstrName = ""; // this allows these definitions to exist in an XML .plist file /* if (xml_GetUsageName(valueUsagePage, valueUsage, cstrName)) */ /* return; */ switch (element->usagePage) { case kHIDPage_Undefined: switch (element->usage) { default: sprintf (cstrName, "Undefined Page, Usage 0x%lx", element->usage); break; } break; case kHIDPage_GenericDesktop: switch (element->usage) { case kHIDUsage_GD_Pointer: sprintf (cstrName, "Pointer"); break; case kHIDUsage_GD_Mouse: sprintf (cstrName, "Mouse"); break; case kHIDUsage_GD_Joystick: sprintf (cstrName, "Joystick"); break; case kHIDUsage_GD_GamePad: sprintf (cstrName, "GamePad"); break; case kHIDUsage_GD_Keyboard: sprintf (cstrName, "Keyboard"); break; case kHIDUsage_GD_Keypad: sprintf (cstrName, "Keypad"); break; case kHIDUsage_GD_MultiAxisController: sprintf (cstrName, "Multi-Axis Controller"); break; case kHIDUsage_GD_X: sprintf (cstrName, "X-Axis"); break; case kHIDUsage_GD_Y: sprintf (cstrName, "Y-Axis"); break; case kHIDUsage_GD_Z: sprintf (cstrName, "Z-Axis"); break; case kHIDUsage_GD_Rx: sprintf (cstrName, "X-Rotation"); break; case kHIDUsage_GD_Ry: sprintf (cstrName, "Y-Rotation"); break; case kHIDUsage_GD_Rz: sprintf (cstrName, "Z-Rotation"); break; case kHIDUsage_GD_Slider: sprintf (cstrName, "Slider"); break; case kHIDUsage_GD_Dial: sprintf (cstrName, "Dial"); break; case kHIDUsage_GD_Wheel: sprintf (cstrName, "Wheel"); break; case kHIDUsage_GD_Hatswitch: sprintf (cstrName, "Hatswitch"); break; case kHIDUsage_GD_CountedBuffer: sprintf (cstrName, "Counted Buffer"); break; case kHIDUsage_GD_ByteCount: sprintf (cstrName, "Byte Count"); break; case kHIDUsage_GD_MotionWakeup: sprintf (cstrName, "Motion Wakeup"); break; case kHIDUsage_GD_Start: sprintf (cstrName, "Start"); break; case kHIDUsage_GD_Select: sprintf (cstrName, "Select"); break; case kHIDUsage_GD_Vx: sprintf (cstrName, "X-Velocity"); break; case kHIDUsage_GD_Vy: sprintf (cstrName, "Y-Velocity"); break; case kHIDUsage_GD_Vz: sprintf (cstrName, "Z-Velocity"); break; case kHIDUsage_GD_Vbrx: sprintf (cstrName, "X-Rotation Velocity"); break; case kHIDUsage_GD_Vbry: sprintf (cstrName, "Y-Rotation Velocity"); break; case kHIDUsage_GD_Vbrz: sprintf (cstrName, "Z-Rotation Velocity"); break; case kHIDUsage_GD_Vno: sprintf (cstrName, "Vno"); break; case kHIDUsage_GD_SystemControl: sprintf (cstrName, "System Control"); break; case kHIDUsage_GD_SystemPowerDown: sprintf (cstrName, "System Power Down"); break; case kHIDUsage_GD_SystemSleep: sprintf (cstrName, "System Sleep"); break; case kHIDUsage_GD_SystemWakeUp: sprintf (cstrName, "System Wake Up"); break; case kHIDUsage_GD_SystemContextMenu: sprintf (cstrName, "System Context Menu"); break; case kHIDUsage_GD_SystemMainMenu: sprintf (cstrName, "System Main Menu"); break; case kHIDUsage_GD_SystemAppMenu: sprintf (cstrName, "System App Menu"); break; case kHIDUsage_GD_SystemMenuHelp: sprintf (cstrName, "System Menu Help"); break; case kHIDUsage_GD_SystemMenuExit: sprintf (cstrName, "System Menu Exit"); break; case kHIDUsage_GD_SystemMenu: sprintf (cstrName, "System Menu"); break; case kHIDUsage_GD_SystemMenuRight: sprintf (cstrName, "System Menu Right"); break; case kHIDUsage_GD_SystemMenuLeft: sprintf (cstrName, "System Menu Left"); break; case kHIDUsage_GD_SystemMenuUp: sprintf (cstrName, "System Menu Up"); break; case kHIDUsage_GD_SystemMenuDown: sprintf (cstrName, "System Menu Down"); break; case kHIDUsage_GD_DPadUp: sprintf (cstrName, "DPad Up"); break; case kHIDUsage_GD_DPadDown: sprintf (cstrName, "DPad Down"); break; case kHIDUsage_GD_DPadRight: sprintf (cstrName, "DPad Right"); break; case kHIDUsage_GD_DPadLeft: sprintf (cstrName, "DPad Left"); break; case kHIDUsage_GD_Reserved: sprintf (cstrName, "Reserved"); break; default: sprintf (cstrName, "Generic Desktop Usage 0x%lx", element->usage); break; } break; case kHIDPage_Simulation: switch (element->usage) { default: sprintf (cstrName, "Simulation Usage 0x%lx", element->usage); break; } break; case kHIDPage_VR: switch (element->usage) { default: sprintf (cstrName, "VR Usage 0x%lx", element->usage); break; } break; case kHIDPage_Sport: switch (element->usage) { default: sprintf (cstrName, "Sport Usage 0x%lx", element->usage); break; } break; case kHIDPage_Game: switch (element->usage) { default: sprintf (cstrName, "Game Usage 0x%lx", element->usage); break; } break; case kHIDPage_KeyboardOrKeypad: switch (element->usage) { default: sprintf (cstrName, "Keyboard Usage 0x%lx", element->usage); break; } break; case kHIDPage_LEDs: switch (element->usage) { // some LED usages case kHIDUsage_LED_IndicatorRed: sprintf (cstrName, "Red LED"); break; case kHIDUsage_LED_IndicatorGreen: sprintf (cstrName, "Green LED"); break; case kHIDUsage_LED_IndicatorAmber: sprintf (cstrName, "Amber LED"); break; case kHIDUsage_LED_GenericIndicator: sprintf (cstrName, "Generic LED"); break; case kHIDUsage_LED_SystemSuspend: sprintf (cstrName, "System Suspend LED"); break; case kHIDUsage_LED_ExternalPowerConnected: sprintf (cstrName, "External Power LED"); break; default: sprintf (cstrName, "LED Usage 0x%lx", element->usage); break; } break; case kHIDPage_Button: switch (element->usage) { default: sprintf (cstrName, "Button #%ld", element->usage); break; } break; case kHIDPage_Ordinal: switch (element->usage) { default: sprintf (cstrName, "Ordinal Instance %lx", element->usage); break; } break; case kHIDPage_Telephony: switch (element->usage) { default: sprintf (cstrName, "Telephony Usage 0x%lx", element->usage); break; } break; case kHIDPage_Consumer: switch (element->usage) { default: sprintf (cstrName, "Consumer Usage 0x%lx", element->usage); break; } break; case kHIDPage_Digitizer: switch (element->usage) { default: sprintf (cstrName, "Digitizer Usage 0x%lx", element->usage); break; } break; case kHIDPage_PID: if (((element->usage >= 0x02) && (element->usage <= 0x1F)) || ((element->usage >= 0x29) && (element->usage <= 0x2F)) || ((element->usage >= 0x35) && (element->usage <= 0x3F)) || ((element->usage >= 0x44) && (element->usage <= 0x4F)) || (element->usage == 0x8A) || (element->usage == 0x93) || ((element->usage >= 0x9D) && (element->usage <= 0x9E)) || ((element->usage >= 0xA1) && (element->usage <= 0xA3)) || ((element->usage >= 0xAD) && (element->usage <= 0xFFFF))) sprintf (cstrName, "PID Reserved"); else switch (element->usage) { case 0x00: sprintf (cstrName, "PID Undefined Usage"); break; case kHIDUsage_PID_PhysicalInterfaceDevice: sprintf (cstrName, "Physical Interface Device"); break; case kHIDUsage_PID_Normal: sprintf (cstrName, "Normal Force"); break; case kHIDUsage_PID_SetEffectReport: sprintf (cstrName, "Set Effect Report"); break; case kHIDUsage_PID_EffectBlockIndex: sprintf (cstrName, "Effect Block Index"); break; case kHIDUsage_PID_ParamBlockOffset: sprintf (cstrName, "Parameter Block Offset"); break; case kHIDUsage_PID_ROM_Flag: sprintf (cstrName, "ROM Flag"); break; case kHIDUsage_PID_EffectType: sprintf (cstrName, "Effect Type"); break; case kHIDUsage_PID_ET_ConstantForce: sprintf (cstrName, "Effect Type Constant Force"); break; case kHIDUsage_PID_ET_Ramp: sprintf (cstrName, "Effect Type Ramp"); break; case kHIDUsage_PID_ET_CustomForceData: sprintf (cstrName, "Effect Type Custom Force Data"); break; case kHIDUsage_PID_ET_Square: sprintf (cstrName, "Effect Type Square"); break; case kHIDUsage_PID_ET_Sine: sprintf (cstrName, "Effect Type Sine"); break; case kHIDUsage_PID_ET_Triangle: sprintf (cstrName, "Effect Type Triangle"); break; case kHIDUsage_PID_ET_SawtoothUp: sprintf (cstrName, "Effect Type Sawtooth Up"); break; case kHIDUsage_PID_ET_SawtoothDown: sprintf (cstrName, "Effect Type Sawtooth Down"); break; case kHIDUsage_PID_ET_Spring: sprintf (cstrName, "Effect Type Spring"); break; case kHIDUsage_PID_ET_Damper: sprintf (cstrName, "Effect Type Damper"); break; case kHIDUsage_PID_ET_Inertia: sprintf (cstrName, "Effect Type Inertia"); break; case kHIDUsage_PID_ET_Friction: sprintf (cstrName, "Effect Type Friction"); break; case kHIDUsage_PID_Duration: sprintf (cstrName, "Effect Duration"); break; case kHIDUsage_PID_SamplePeriod: sprintf (cstrName, "Effect Sample Period"); break; case kHIDUsage_PID_Gain: sprintf (cstrName, "Effect Gain"); break; case kHIDUsage_PID_TriggerButton: sprintf (cstrName, "Effect Trigger Button"); break; case kHIDUsage_PID_TriggerRepeatInterval: sprintf (cstrName, "Effect Trigger Repeat Interval"); break; case kHIDUsage_PID_AxesEnable: sprintf (cstrName, "Axis Enable"); break; case kHIDUsage_PID_DirectionEnable: sprintf (cstrName, "Direction Enable"); break; case kHIDUsage_PID_Direction: sprintf (cstrName, "Direction"); break; case kHIDUsage_PID_TypeSpecificBlockOffset: sprintf (cstrName, "Type Specific Block Offset"); break; case kHIDUsage_PID_BlockType: sprintf (cstrName, "Block Type"); break; case kHIDUsage_PID_SetEnvelopeReport: sprintf (cstrName, "Set Envelope Report"); break; case kHIDUsage_PID_AttackLevel: sprintf (cstrName, "Envelope Attack Level"); break; case kHIDUsage_PID_AttackTime: sprintf (cstrName, "Envelope Attack Time"); break; case kHIDUsage_PID_FadeLevel: sprintf (cstrName, "Envelope Fade Level"); break; case kHIDUsage_PID_FadeTime: sprintf (cstrName, "Envelope Fade Time"); break; case kHIDUsage_PID_SetConditionReport: sprintf (cstrName, "Set Condition Report"); break; case kHIDUsage_PID_CP_Offset: sprintf (cstrName, "Condition CP Offset"); break; case kHIDUsage_PID_PositiveCoefficient: sprintf (cstrName, "Condition Positive Coefficient"); break; case kHIDUsage_PID_NegativeCoefficient: sprintf (cstrName, "Condition Negative Coefficient"); break; case kHIDUsage_PID_PositiveSaturation: sprintf (cstrName, "Condition Positive Saturation"); break; case kHIDUsage_PID_NegativeSaturation: sprintf (cstrName, "Condition Negative Saturation"); break; case kHIDUsage_PID_DeadBand: sprintf (cstrName, "Condition Dead Band"); break; case kHIDUsage_PID_DownloadForceSample: sprintf (cstrName, "Download Force Sample"); break; case kHIDUsage_PID_IsochCustomForceEnable: sprintf (cstrName, "Isoch Custom Force Enable"); break; case kHIDUsage_PID_CustomForceDataReport: sprintf (cstrName, "Custom Force Data Report"); break; case kHIDUsage_PID_CustomForceData: sprintf (cstrName, "Custom Force Data"); break; case kHIDUsage_PID_CustomForceVendorDefinedData: sprintf (cstrName, "Custom Force Vendor Defined Data"); break; case kHIDUsage_PID_SetCustomForceReport: sprintf (cstrName, "Set Custom Force Report"); break; case kHIDUsage_PID_CustomForceDataOffset: sprintf (cstrName, "Custom Force Data Offset"); break; case kHIDUsage_PID_SampleCount: sprintf (cstrName, "Custom Force Sample Count"); break; case kHIDUsage_PID_SetPeriodicReport: sprintf (cstrName, "Set Periodic Report"); break; case kHIDUsage_PID_Offset: sprintf (cstrName, "Periodic Offset"); break; case kHIDUsage_PID_Magnitude: sprintf (cstrName, "Periodic Magnitude"); break; case kHIDUsage_PID_Phase: sprintf (cstrName, "Periodic Phase"); break; case kHIDUsage_PID_Period: sprintf (cstrName, "Periodic Period"); break; case kHIDUsage_PID_SetConstantForceReport: sprintf (cstrName, "Set Constant Force Report"); break; case kHIDUsage_PID_SetRampForceReport: sprintf (cstrName, "Set Ramp Force Report"); break; case kHIDUsage_PID_RampStart: sprintf (cstrName, "Ramp Start"); break; case kHIDUsage_PID_RampEnd: sprintf (cstrName, "Ramp End"); break; case kHIDUsage_PID_EffectOperationReport: sprintf (cstrName, "Effect Operation Report"); break; case kHIDUsage_PID_EffectOperation: sprintf (cstrName, "Effect Operation"); break; case kHIDUsage_PID_OpEffectStart: sprintf (cstrName, "Op Effect Start"); break; case kHIDUsage_PID_OpEffectStartSolo: sprintf (cstrName, "Op Effect Start Solo"); break; case kHIDUsage_PID_OpEffectStop: sprintf (cstrName, "Op Effect Stop"); break; case kHIDUsage_PID_LoopCount: sprintf (cstrName, "Op Effect Loop Count"); break; case kHIDUsage_PID_DeviceGainReport: sprintf (cstrName, "Device Gain Report"); break; case kHIDUsage_PID_DeviceGain: sprintf (cstrName, "Device Gain"); break; case kHIDUsage_PID_PoolReport: sprintf (cstrName, "PID Pool Report"); break; case kHIDUsage_PID_RAM_PoolSize: sprintf (cstrName, "RAM Pool Size"); break; case kHIDUsage_PID_ROM_PoolSize: sprintf (cstrName, "ROM Pool Size"); break; case kHIDUsage_PID_ROM_EffectBlockCount: sprintf (cstrName, "ROM Effect Block Count"); break; case kHIDUsage_PID_SimultaneousEffectsMax: sprintf (cstrName, "Simultaneous Effects Max"); break; case kHIDUsage_PID_PoolAlignment: sprintf (cstrName, "Pool Alignment"); break; case kHIDUsage_PID_PoolMoveReport: sprintf (cstrName, "PID Pool Move Report"); break; case kHIDUsage_PID_MoveSource: sprintf (cstrName, "Move Source"); break; case kHIDUsage_PID_MoveDestination: sprintf (cstrName, "Move Destination"); break; case kHIDUsage_PID_MoveLength: sprintf (cstrName, "Move Length"); break; case kHIDUsage_PID_BlockLoadReport: sprintf (cstrName, "PID Block Load Report"); break; case kHIDUsage_PID_BlockLoadStatus: sprintf (cstrName, "Block Load Status"); break; case kHIDUsage_PID_BlockLoadSuccess: sprintf (cstrName, "Block Load Success"); break; case kHIDUsage_PID_BlockLoadFull: sprintf (cstrName, "Block Load Full"); break; case kHIDUsage_PID_BlockLoadError: sprintf (cstrName, "Block Load Error"); break; case kHIDUsage_PID_BlockHandle: sprintf (cstrName, "Block Handle"); break; case kHIDUsage_PID_BlockFreeReport: sprintf (cstrName, "PID Block Free Report"); break; case kHIDUsage_PID_TypeSpecificBlockHandle: sprintf (cstrName, "Type Specific Block Handle"); break; case kHIDUsage_PID_StateReport: sprintf (cstrName, "PID State Report"); break; case kHIDUsage_PID_EffectPlaying: sprintf (cstrName, "Effect Playing"); break; case kHIDUsage_PID_DeviceControlReport: sprintf (cstrName, "PID Device Control Report"); break; case kHIDUsage_PID_DeviceControl: sprintf (cstrName, "PID Device Control"); break; case kHIDUsage_PID_DC_EnableActuators: sprintf (cstrName, "Device Control Enable Actuators"); break; case kHIDUsage_PID_DC_DisableActuators: sprintf (cstrName, "Device Control Disable Actuators"); break; case kHIDUsage_PID_DC_StopAllEffects: sprintf (cstrName, "Device Control Stop All Effects"); break; case kHIDUsage_PID_DC_DeviceReset: sprintf (cstrName, "Device Control Reset"); break; case kHIDUsage_PID_DC_DevicePause: sprintf (cstrName, "Device Control Pause"); break; case kHIDUsage_PID_DC_DeviceContinue: sprintf (cstrName, "Device Control Continue"); break; case kHIDUsage_PID_DevicePaused: sprintf (cstrName, "Device Paused"); break; case kHIDUsage_PID_ActuatorsEnabled: sprintf (cstrName, "Actuators Enabled"); break; case kHIDUsage_PID_SafetySwitch: sprintf (cstrName, "Safety Switch"); break; case kHIDUsage_PID_ActuatorOverrideSwitch: sprintf (cstrName, "Actuator Override Switch"); break; case kHIDUsage_PID_ActuatorPower: sprintf (cstrName, "Actuator Power"); break; case kHIDUsage_PID_StartDelay: sprintf (cstrName, "Start Delay"); break; case kHIDUsage_PID_ParameterBlockSize: sprintf (cstrName, "Parameter Block Size"); break; case kHIDUsage_PID_DeviceManagedPool: sprintf (cstrName, "Device Managed Pool"); break; case kHIDUsage_PID_SharedParameterBlocks: sprintf (cstrName, "Shared Parameter Blocks"); break; case kHIDUsage_PID_CreateNewEffectReport: sprintf (cstrName, "Create New Effect Report"); break; case kHIDUsage_PID_RAM_PoolAvailable: sprintf (cstrName, "RAM Pool Available"); break; default: sprintf (cstrName, "PID Usage 0x%lx", element->usage); break; } break; case kHIDPage_Unicode: switch (element->usage) { default: sprintf (cstrName, "Unicode Usage 0x%lx", element->usage); break; } break; case kHIDPage_PowerDevice: if (((element->usage >= 0x06) && (element->usage <= 0x0F)) || ((element->usage >= 0x26) && (element->usage <= 0x2F)) || ((element->usage >= 0x39) && (element->usage <= 0x3F)) || ((element->usage >= 0x48) && (element->usage <= 0x4F)) || ((element->usage >= 0x58) && (element->usage <= 0x5F)) || (element->usage == 0x6A) || ((element->usage >= 0x74) && (element->usage <= 0xFC))) sprintf (cstrName, "Power Device Reserved"); else switch (element->usage) { case kHIDUsage_PD_Undefined: sprintf (cstrName, "Power Device Undefined Usage"); break; case kHIDUsage_PD_iName: sprintf (cstrName, "Power Device Name Index"); break; case kHIDUsage_PD_PresentStatus: sprintf (cstrName, "Power Device Present Status"); break; case kHIDUsage_PD_ChangedStatus: sprintf (cstrName, "Power Device Changed Status"); break; case kHIDUsage_PD_UPS: sprintf (cstrName, "Uninterruptible Power Supply"); break; case kHIDUsage_PD_PowerSupply: sprintf (cstrName, "Power Supply"); break; case kHIDUsage_PD_BatterySystem: sprintf (cstrName, "Battery System Power Module"); break; case kHIDUsage_PD_BatterySystemID: sprintf (cstrName, "Battery System ID"); break; case kHIDUsage_PD_Battery: sprintf (cstrName, "Battery"); break; case kHIDUsage_PD_BatteryID: sprintf (cstrName, "Battery ID"); break; case kHIDUsage_PD_Charger: sprintf (cstrName, "Charger"); break; case kHIDUsage_PD_ChargerID: sprintf (cstrName, "Charger ID"); break; case kHIDUsage_PD_PowerConverter: sprintf (cstrName, "Power Converter Power Module"); break; case kHIDUsage_PD_PowerConverterID: sprintf (cstrName, "Power Converter ID"); break; case kHIDUsage_PD_OutletSystem: sprintf (cstrName, "Outlet System power module"); break; case kHIDUsage_PD_OutletSystemID: sprintf (cstrName, "Outlet System ID"); break; case kHIDUsage_PD_Input: sprintf (cstrName, "Power Device Input"); break; case kHIDUsage_PD_InputID: sprintf (cstrName, "Power Device Input ID"); break; case kHIDUsage_PD_Output: sprintf (cstrName, "Power Device Output"); break; case kHIDUsage_PD_OutputID: sprintf (cstrName, "Power Device Output ID"); break; case kHIDUsage_PD_Flow: sprintf (cstrName, "Power Device Flow"); break; case kHIDUsage_PD_FlowID: sprintf (cstrName, "Power Device Flow ID"); break; case kHIDUsage_PD_Outlet: sprintf (cstrName, "Power Device Outlet"); break; case kHIDUsage_PD_OutletID: sprintf (cstrName, "Power Device Outlet ID"); break; case kHIDUsage_PD_Gang: sprintf (cstrName, "Power Device Gang"); break; case kHIDUsage_PD_GangID: sprintf (cstrName, "Power Device Gang ID"); break; case kHIDUsage_PD_PowerSummary: sprintf (cstrName, "Power Device Power Summary"); break; case kHIDUsage_PD_PowerSummaryID: sprintf (cstrName, "Power Device Power Summary ID"); break; case kHIDUsage_PD_Voltage: sprintf (cstrName, "Power Device Voltage"); break; case kHIDUsage_PD_Current: sprintf (cstrName, "Power Device Current"); break; case kHIDUsage_PD_Frequency: sprintf (cstrName, "Power Device Frequency"); break; case kHIDUsage_PD_ApparentPower: sprintf (cstrName, "Power Device Apparent Power"); break; case kHIDUsage_PD_ActivePower: sprintf (cstrName, "Power Device RMS Power"); break; case kHIDUsage_PD_PercentLoad: sprintf (cstrName, "Power Device Percent Load"); break; case kHIDUsage_PD_Temperature: sprintf (cstrName, "Power Device Temperature"); break; case kHIDUsage_PD_Humidity: sprintf (cstrName, "Power Device Humidity"); break; case kHIDUsage_PD_BadCount: sprintf (cstrName, "Power Device Bad Condition Count"); break; case kHIDUsage_PD_ConfigVoltage: sprintf (cstrName, "Power Device Nominal Voltage"); break; case kHIDUsage_PD_ConfigCurrent: sprintf (cstrName, "Power Device Nominal Current"); break; case kHIDUsage_PD_ConfigFrequency: sprintf (cstrName, "Power Device Nominal Frequency"); break; case kHIDUsage_PD_ConfigApparentPower: sprintf (cstrName, "Power Device Nominal Apparent Power"); break; case kHIDUsage_PD_ConfigActivePower: sprintf (cstrName, "Power Device Nominal RMS Power"); break; case kHIDUsage_PD_ConfigPercentLoad: sprintf (cstrName, "Power Device Nominal Percent Load"); break; case kHIDUsage_PD_ConfigTemperature: sprintf (cstrName, "Power Device Nominal Temperature"); break; case kHIDUsage_PD_ConfigHumidity: sprintf (cstrName, "Power Device Nominal Humidity"); break; case kHIDUsage_PD_SwitchOnControl: sprintf (cstrName, "Power Device Switch On Control"); break; case kHIDUsage_PD_SwitchOffControl: sprintf (cstrName, "Power Device Switch Off Control"); break; case kHIDUsage_PD_ToggleControl: sprintf (cstrName, "Power Device Toogle Sequence Control"); break; case kHIDUsage_PD_LowVoltageTransfer: sprintf (cstrName, "Power Device Min Transfer Voltage"); break; case kHIDUsage_PD_HighVoltageTransfer: sprintf (cstrName, "Power Device Max Transfer Voltage"); break; case kHIDUsage_PD_DelayBeforeReboot: sprintf (cstrName, "Power Device Delay Before Reboot"); break; case kHIDUsage_PD_DelayBeforeStartup: sprintf (cstrName, "Power Device Delay Before Startup"); break; case kHIDUsage_PD_DelayBeforeShutdown: sprintf (cstrName, "Power Device Delay Before Shutdown"); break; case kHIDUsage_PD_Test: sprintf (cstrName, "Power Device Test Request/Result"); break; case kHIDUsage_PD_ModuleReset: sprintf (cstrName, "Power Device Reset Request/Result"); break; case kHIDUsage_PD_AudibleAlarmControl: sprintf (cstrName, "Power Device Audible Alarm Control"); break; case kHIDUsage_PD_Present: sprintf (cstrName, "Power Device Present"); break; case kHIDUsage_PD_Good: sprintf (cstrName, "Power Device Good"); break; case kHIDUsage_PD_InternalFailure: sprintf (cstrName, "Power Device Internal Failure"); break; case kHIDUsage_PD_VoltageOutOfRange: sprintf (cstrName, "Power Device Voltage Out Of Range"); break; case kHIDUsage_PD_FrequencyOutOfRange: sprintf (cstrName, "Power Device Frequency Out Of Range"); break; case kHIDUsage_PD_Overload: sprintf (cstrName, "Power Device Overload"); break; case kHIDUsage_PD_OverCharged: sprintf (cstrName, "Power Device Over Charged"); break; case kHIDUsage_PD_OverTemperature: sprintf (cstrName, "Power Device Over Temperature"); break; case kHIDUsage_PD_ShutdownRequested: sprintf (cstrName, "Power Device Shutdown Requested"); break; case kHIDUsage_PD_ShutdownImminent: sprintf (cstrName, "Power Device Shutdown Imminent"); break; case kHIDUsage_PD_SwitchOnOff: sprintf (cstrName, "Power Device On/Off Switch Status"); break; case kHIDUsage_PD_Switchable: sprintf (cstrName, "Power Device Switchable"); break; case kHIDUsage_PD_Used: sprintf (cstrName, "Power Device Used"); break; case kHIDUsage_PD_Boost: sprintf (cstrName, "Power Device Boosted"); break; case kHIDUsage_PD_Buck: sprintf (cstrName, "Power Device Bucked"); break; case kHIDUsage_PD_Initialized: sprintf (cstrName, "Power Device Initialized"); break; case kHIDUsage_PD_Tested: sprintf (cstrName, "Power Device Tested"); break; case kHIDUsage_PD_AwaitingPower: sprintf (cstrName, "Power Device Awaiting Power"); break; case kHIDUsage_PD_CommunicationLost: sprintf (cstrName, "Power Device Communication Lost"); break; case kHIDUsage_PD_iManufacturer: sprintf (cstrName, "Power Device Manufacturer String Index"); break; case kHIDUsage_PD_iProduct: sprintf (cstrName, "Power Device Product String Index"); break; case kHIDUsage_PD_iserialNumber: sprintf (cstrName, "Power Device Serial Number String Index"); break; default: sprintf (cstrName, "Power Device Usage 0x%lx", element->usage); break; } break; case kHIDPage_BatterySystem: if (((element->usage >= 0x0A) && (element->usage <= 0x0F)) || ((element->usage >= 0x1E) && (element->usage <= 0x27)) || ((element->usage >= 0x30) && (element->usage <= 0x3F)) || ((element->usage >= 0x4C) && (element->usage <= 0x5F)) || ((element->usage >= 0x6C) && (element->usage <= 0x7F)) || ((element->usage >= 0x90) && (element->usage <= 0xBF)) || ((element->usage >= 0xC3) && (element->usage <= 0xCF)) || ((element->usage >= 0xDD) && (element->usage <= 0xEF)) || ((element->usage >= 0xF2) && (element->usage <= 0xFF))) sprintf (cstrName, "Power Device Reserved"); else switch (element->usage) { case kHIDUsage_BS_Undefined: sprintf (cstrName, "Battery System Undefined"); break; case kHIDUsage_BS_SMBBatteryMode: sprintf (cstrName, "SMB Mode"); break; case kHIDUsage_BS_SMBBatteryStatus: sprintf (cstrName, "SMB Status"); break; case kHIDUsage_BS_SMBAlarmWarning: sprintf (cstrName, "SMB Alarm Warning"); break; case kHIDUsage_BS_SMBChargerMode: sprintf (cstrName, "SMB Charger Mode"); break; case kHIDUsage_BS_SMBChargerStatus: sprintf (cstrName, "SMB Charger Status"); break; case kHIDUsage_BS_SMBChargerSpecInfo: sprintf (cstrName, "SMB Charger Extended Status"); break; case kHIDUsage_BS_SMBSelectorState: sprintf (cstrName, "SMB Selector State"); break; case kHIDUsage_BS_SMBSelectorPresets: sprintf (cstrName, "SMB Selector Presets"); break; case kHIDUsage_BS_SMBSelectorInfo: sprintf (cstrName, "SMB Selector Info"); break; case kHIDUsage_BS_OptionalMfgFunction1: sprintf (cstrName, "Battery System Optional SMB Mfg Function 1"); break; case kHIDUsage_BS_OptionalMfgFunction2: sprintf (cstrName, "Battery System Optional SMB Mfg Function 2"); break; case kHIDUsage_BS_OptionalMfgFunction3: sprintf (cstrName, "Battery System Optional SMB Mfg Function 3"); break; case kHIDUsage_BS_OptionalMfgFunction4: sprintf (cstrName, "Battery System Optional SMB Mfg Function 4"); break; case kHIDUsage_BS_OptionalMfgFunction5: sprintf (cstrName, "Battery System Optional SMB Mfg Function 5"); break; case kHIDUsage_BS_ConnectionToSMBus: sprintf (cstrName, "Battery System Connection To System Management Bus"); break; case kHIDUsage_BS_OutputConnection: sprintf (cstrName, "Battery System Output Connection Status"); break; case kHIDUsage_BS_ChargerConnection: sprintf (cstrName, "Battery System Charger Connection"); break; case kHIDUsage_BS_BatteryInsertion: sprintf (cstrName, "Battery System Battery Insertion"); break; case kHIDUsage_BS_Usenext: sprintf (cstrName, "Battery System Use Next"); break; case kHIDUsage_BS_OKToUse: sprintf (cstrName, "Battery System OK To Use"); break; case kHIDUsage_BS_BatterySupported: sprintf (cstrName, "Battery System Battery Supported"); break; case kHIDUsage_BS_SelectorRevision: sprintf (cstrName, "Battery System Selector Revision"); break; case kHIDUsage_BS_ChargingIndicator: sprintf (cstrName, "Battery System Charging Indicator"); break; case kHIDUsage_BS_ManufacturerAccess: sprintf (cstrName, "Battery System Manufacturer Access"); break; case kHIDUsage_BS_RemainingCapacityLimit: sprintf (cstrName, "Battery System Remaining Capacity Limit"); break; case kHIDUsage_BS_RemainingTimeLimit: sprintf (cstrName, "Battery System Remaining Time Limit"); break; case kHIDUsage_BS_AtRate: sprintf (cstrName, "Battery System At Rate..."); break; case kHIDUsage_BS_CapacityMode: sprintf (cstrName, "Battery System Capacity Mode"); break; case kHIDUsage_BS_BroadcastToCharger: sprintf (cstrName, "Battery System Broadcast To Charger"); break; case kHIDUsage_BS_PrimaryBattery: sprintf (cstrName, "Battery System Primary Battery"); break; case kHIDUsage_BS_ChargeController: sprintf (cstrName, "Battery System Charge Controller"); break; case kHIDUsage_BS_TerminateCharge: sprintf (cstrName, "Battery System Terminate Charge"); break; case kHIDUsage_BS_TerminateDischarge: sprintf (cstrName, "Battery System Terminate Discharge"); break; case kHIDUsage_BS_BelowRemainingCapacityLimit: sprintf (cstrName, "Battery System Below Remaining Capacity Limit"); break; case kHIDUsage_BS_RemainingTimeLimitExpired: sprintf (cstrName, "Battery System Remaining Time Limit Expired"); break; case kHIDUsage_BS_Charging: sprintf (cstrName, "Battery System Charging"); break; case kHIDUsage_BS_Discharging: sprintf (cstrName, "Battery System Discharging"); break; case kHIDUsage_BS_FullyCharged: sprintf (cstrName, "Battery System Fully Charged"); break; case kHIDUsage_BS_FullyDischarged: sprintf (cstrName, "Battery System Fully Discharged"); break; case kHIDUsage_BS_ConditioningFlag: sprintf (cstrName, "Battery System Conditioning Flag"); break; case kHIDUsage_BS_AtRateOK: sprintf (cstrName, "Battery System At Rate OK"); break; case kHIDUsage_BS_SMBErrorCode: sprintf (cstrName, "Battery System SMB Error Code"); break; case kHIDUsage_BS_NeedReplacement: sprintf (cstrName, "Battery System Need Replacement"); break; case kHIDUsage_BS_AtRateTimeToFull: sprintf (cstrName, "Battery System At Rate Time To Full"); break; case kHIDUsage_BS_AtRateTimeToEmpty: sprintf (cstrName, "Battery System At Rate Time To Empty"); break; case kHIDUsage_BS_AverageCurrent: sprintf (cstrName, "Battery System Average Current"); break; case kHIDUsage_BS_Maxerror: sprintf (cstrName, "Battery System Max Error"); break; case kHIDUsage_BS_RelativeStateOfCharge: sprintf (cstrName, "Battery System Relative State Of Charge"); break; case kHIDUsage_BS_AbsoluteStateOfCharge: sprintf (cstrName, "Battery System Absolute State Of Charge"); break; case kHIDUsage_BS_RemainingCapacity: sprintf (cstrName, "Battery System Remaining Capacity"); break; case kHIDUsage_BS_FullChargeCapacity: sprintf (cstrName, "Battery System Full Charge Capacity"); break; case kHIDUsage_BS_RunTimeToEmpty: sprintf (cstrName, "Battery System Run Time To Empty"); break; case kHIDUsage_BS_AverageTimeToEmpty: sprintf (cstrName, "Battery System Average Time To Empty"); break; case kHIDUsage_BS_AverageTimeToFull: sprintf (cstrName, "Battery System Average Time To Full"); break; case kHIDUsage_BS_CycleCount: sprintf (cstrName, "Battery System Cycle Count"); break; case kHIDUsage_BS_BattPackModelLevel: sprintf (cstrName, "Battery System Batt Pack Model Level"); break; case kHIDUsage_BS_InternalChargeController: sprintf (cstrName, "Battery System Internal Charge Controller"); break; case kHIDUsage_BS_PrimaryBatterySupport: sprintf (cstrName, "Battery System Primary Battery Support"); break; case kHIDUsage_BS_DesignCapacity: sprintf (cstrName, "Battery System Design Capacity"); break; case kHIDUsage_BS_SpecificationInfo: sprintf (cstrName, "Battery System Specification Info"); break; case kHIDUsage_BS_ManufacturerDate: sprintf (cstrName, "Battery System Manufacturer Date"); break; case kHIDUsage_BS_SerialNumber: sprintf (cstrName, "Battery System Serial Number"); break; case kHIDUsage_BS_iManufacturerName: sprintf (cstrName, "Battery System Manufacturer Name Index"); break; case kHIDUsage_BS_iDevicename: sprintf (cstrName, "Battery System Device Name Index"); break; case kHIDUsage_BS_iDeviceChemistry: sprintf (cstrName, "Battery System Device Chemistry Index"); break; case kHIDUsage_BS_ManufacturerData: sprintf (cstrName, "Battery System Manufacturer Data"); break; case kHIDUsage_BS_Rechargable: sprintf (cstrName, "Battery System Rechargable"); break; case kHIDUsage_BS_WarningCapacityLimit: sprintf (cstrName, "Battery System Warning Capacity Limit"); break; case kHIDUsage_BS_CapacityGranularity1: sprintf (cstrName, "Battery System Capacity Granularity 1"); break; case kHIDUsage_BS_CapacityGranularity2: sprintf (cstrName, "Battery System Capacity Granularity 2"); break; case kHIDUsage_BS_iOEMInformation: sprintf (cstrName, "Battery System OEM Information Index"); break; case kHIDUsage_BS_InhibitCharge: sprintf (cstrName, "Battery System Inhibit Charge"); break; case kHIDUsage_BS_EnablePolling: sprintf (cstrName, "Battery System Enable Polling"); break; case kHIDUsage_BS_ResetToZero: sprintf (cstrName, "Battery System Reset To Zero"); break; case kHIDUsage_BS_ACPresent: sprintf (cstrName, "Battery System AC Present"); break; case kHIDUsage_BS_BatteryPresent: sprintf (cstrName, "Battery System Battery Present"); break; case kHIDUsage_BS_PowerFail: sprintf (cstrName, "Battery System Power Fail"); break; case kHIDUsage_BS_AlarmInhibited: sprintf (cstrName, "Battery System Alarm Inhibited"); break; case kHIDUsage_BS_ThermistorUnderRange: sprintf (cstrName, "Battery System Thermistor Under Range"); break; case kHIDUsage_BS_ThermistorHot: sprintf (cstrName, "Battery System Thermistor Hot"); break; case kHIDUsage_BS_ThermistorCold: sprintf (cstrName, "Battery System Thermistor Cold"); break; case kHIDUsage_BS_ThermistorOverRange: sprintf (cstrName, "Battery System Thermistor Over Range"); break; case kHIDUsage_BS_VoltageOutOfRange: sprintf (cstrName, "Battery System Voltage Out Of Range"); break; case kHIDUsage_BS_CurrentOutOfRange: sprintf (cstrName, "Battery System Current Out Of Range"); break; case kHIDUsage_BS_CurrentNotRegulated: sprintf (cstrName, "Battery System Current Not Regulated"); break; case kHIDUsage_BS_VoltageNotRegulated: sprintf (cstrName, "Battery System Voltage Not Regulated"); break; case kHIDUsage_BS_MasterMode: sprintf (cstrName, "Battery System Master Mode"); break; case kHIDUsage_BS_ChargerSelectorSupport: sprintf (cstrName, "Battery System Charger Support Selector"); break; case kHIDUsage_BS_ChargerSpec: sprintf (cstrName, "attery System Charger Specification"); break; case kHIDUsage_BS_Level2: sprintf (cstrName, "Battery System Charger Level 2"); break; case kHIDUsage_BS_Level3: sprintf (cstrName, "Battery System Charger Level 3"); break; default: sprintf (cstrName, "Battery System Usage 0x%lx", element->usage); break; } break; case kHIDPage_AlphanumericDisplay: switch (element->usage) { default: sprintf (cstrName, "Alphanumeric Display Usage 0x%lx", element->usage); break; } break; case kHIDPage_BarCodeScanner: switch (element->usage) { default: sprintf (cstrName, "Bar Code Scanner Usage 0x%lx", element->usage); break; } break; case kHIDPage_Scale: switch (element->usage) { default: sprintf (cstrName, "Scale Usage 0x%lx", element->usage); break; } break; case kHIDPage_CameraControl: switch (element->usage) { default: sprintf (cstrName, "Camera Control Usage 0x%lx", element->usage); break; } break; case kHIDPage_Arcade: switch (element->usage) { default: sprintf (cstrName, "Arcade Usage 0x%lx", element->usage); break; } break; default: if (element->usagePage > kHIDPage_VendorDefinedStart) sprintf (cstrName, "Vendor Defined Usage 0x%lx", element->usage); else sprintf (cstrName, "Page: 0x%lx, Usage: 0x%lx", element->usagePage, element->usage); break; } return(cstrName); } #endif /* #ifdef __APPLE__ */ pd-hid_0.7/mouse-help.pd0000644000076500007650000001156611504504627013705 0ustar hanshans#N canvas 0 31 660 430 10; #X symbolatom 211 280 6 0 0 1 code - -; #X obj 130 118 tgl 25 0 empty empty empty 0 -6 0 8 -225271 -1 -1 0 1; #X floatatom 339 280 5 0 0 1 value - -; #X floatatom 140 280 5 0 0 3 wheel - -; #X floatatom 85 280 7 0 0 3 Y - -; #X floatatom 31 280 7 0 0 3 X - -; #X obj 193 347 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 232 346 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 271 346 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X msg 175 95 open 0; #X msg 180 114 open 1; #X msg 185 133 open 2; #N canvas 94 191 532 519 mouse-noise 0; #X obj 26 18 inlet; #X obj 199 314 noise~; #X obj 155 336 osc~; #X obj 113 387 *~; #X msg 167 65 \; pd dsp 1; #X obj 139 488 dac~; #X obj 386 13 inlet; #X text 448 14 open msgs; #X text 340 169 get button value only; #X obj 199 336 *~; #X obj 312 207 / 2; #X obj 113 448 pan/linear_pan~; #X obj 276 426 line; #X msg 276 403 \$1 20; #X obj 276 318 +; #X msg 313 294 0; #X obj 155 242 abs; #X obj 201 169 unpack symbol float; #X obj 110 335 line~; #X msg 110 312 \$1 3; #X obj 155 314 * 20; #X obj 276 339 min 20; #X obj 276 358 max 0; #X obj 276 294 int; #X obj 276 379 / 20; #X obj 155 287 mtof; #X obj 155 203 hid/hid_rel2abs 0 1; #X obj 155 223 - 1; #X obj 155 267 mapping/notescale 30 60; #X obj 200 403 loadbang; #X msg 200 424 0.5; #X obj 26 250 select 0; #X msg 26 272 0; #X text 11 224 mute on finish; #X obj 26 43 trigger float float bang; #X obj 312 318 float; #X obj 132 149 hid/mouse; #X connect 0 0 34 0; #X connect 1 0 9 0; #X connect 2 0 3 1; #X connect 3 0 11 0; #X connect 6 0 36 0; #X connect 9 0 3 1; #X connect 10 0 9 1; #X connect 11 0 5 0; #X connect 11 1 5 1; #X connect 12 0 11 1; #X connect 13 0 12 0; #X connect 14 0 21 0; #X connect 15 0 14 1; #X connect 15 0 35 1; #X connect 16 0 28 0; #X connect 17 1 10 0; #X connect 18 0 3 0; #X connect 19 0 18 0; #X connect 20 0 2 0; #X connect 21 0 22 0; #X connect 22 0 24 0; #X connect 22 0 35 0; #X connect 23 0 14 0; #X connect 24 0 13 0; #X connect 25 0 20 0; #X connect 26 0 27 0; #X connect 27 0 16 0; #X connect 28 0 25 0; #X connect 29 0 30 0; #X connect 30 0 11 1; #X connect 31 0 32 0; #X connect 32 0 19 0; #X connect 34 0 31 0; #X connect 34 1 36 0; #X connect 34 2 4 0; #X connect 35 0 14 1; #X connect 36 0 19 0; #X connect 36 1 26 0; #X connect 36 2 23 0; #X connect 36 3 17 0; #X restore 407 188 pd mouse-noise; #X obj 407 131 tgl 25 0 empty empty empty 0 -6 0 8 -225271 -1 -1 0 1; #X text 354 107 turn this on to make some noise with the mouse; #X obj 211 253 unpack symbol float; #X text 282 296 buttons; #X obj 310 346 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 349 346 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 388 346 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 427 346 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 466 346 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 2 2 cnv 15 650 20 empty empty mouse 2 11 1 18 -233017 -66577 0; #X obj 505 346 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 496 396 pddp/pddplink ../all_about_hid.pd -text all_about_hid ; #X text 387 397 For more info:; #X obj 544 346 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1; #X obj 193 326 route btn_0 btn_1 btn_2 btn_3 btn_4 btn_5 btn_6 btn_7 btn_8; #X text 12 36 Use a mouse device with Pd. This object auto-calibrates the output of axis data. Move the device around as fast as possible in each axis to calibrate it.; #X text 13 123 turn on polling:; #X msg 180 158 refresh; #X obj 619 3 pddp/pddplink http://puredata.info/dev/pddp -text pddp ; #X msg 500 160 open \$1; #X obj 500 140 hradio 15 1 1 8 \$0-device-number empty choose_a_device 0 -6 1 9 -262144 -1 -1 1; #X obj 474 140 nbx 1 14 -1e+37 1e+37 0 0 empty \$0-device-number empty 0 -6 0 14 -166441 -1 -1 0 256; #X msg 76 154 print; #X obj 130 183 hid/mouse 1; #N canvas 472 31 494 344 META 0; #X text 12 185 HELP_PATCH_AUTHORS "pd meta" information added by Jonathan Wilkes for Pd version 0.42.; #X text 12 25 LICENSE GPL; #X text 12 165 AUTHOR Hans-Christoph Steiner; #X text 12 45 DESCRIPTION use a mouse device with Pd; #X text 12 65 INLET_0 float print open refresh; #X text 12 85 OUTLET_0 float; #X text 12 105 OUTLET_1 float; #X text 12 125 OUTLET_2 float; #X text 12 145 OUTLET_3 list; #X text 12 5 KEYWORDS control user_input abstraction; #X restore 604 400 pd META; #X connect 1 0 36 0; #X connect 9 0 36 0; #X connect 10 0 36 0; #X connect 11 0 36 0; #X connect 13 0 12 0; #X connect 15 0 0 0; #X connect 15 1 2 0; #X connect 27 0 6 0; #X connect 27 1 7 0; #X connect 27 2 8 0; #X connect 27 3 17 0; #X connect 27 4 18 0; #X connect 27 5 19 0; #X connect 27 6 20 0; #X connect 27 7 21 0; #X connect 27 8 23 0; #X connect 27 9 26 0; #X connect 30 0 36 0; #X connect 32 0 12 1; #X connect 33 0 32 0; #X connect 35 0 36 0; #X connect 36 0 5 0; #X connect 36 1 4 0; #X connect 36 2 3 0; #X connect 36 3 15 0; #X connect 36 3 27 0; pd-hid_0.7/hid.h0000644000076500007650000001074711504504627012217 0ustar hanshans#ifndef _HID_H #define _HID_H #include #include #ifdef __linux__ #include #endif /* __linux__ */ #include /* * this is automatically generated from linux/input.h by * make-arrays-from-input.h.pl to be the cross-platform event types and codes */ #include "input_arrays.h" #define HID_MAJOR_VERSION 0 #define HID_MINOR_VERSION 7 /* static char *version = "$Revision: 1.29 $"; */ /*------------------------------------------------------------------------------ * GLOBAL DEFINES */ #define DEFAULT_DELAY 5 /* this is set to simplify data structures (arrays instead of linked lists) */ #define MAX_DEVICES 128 /* think 64 is the limit per device as defined in the OS */ #define MAX_ELEMENTS 64 /* this is limited so that the object doesn't cause a click getting too many * events from the OS's event queue */ #define MAX_EVENTS_PER_POLL 64 /*------------------------------------------------------------------------------ * CLASS DEF */ typedef struct _hid { t_object x_obj; t_int x_fd; void *x_ff_device; short x_device_number; short x_instance; t_int x_has_ff; t_int x_started; t_int x_device_open; t_int x_delay; t_clock *x_clock; t_outlet *x_data_outlet; t_outlet *x_status_outlet; } t_hid; /*------------------------------------------------------------------------------ * GLOBAL VARIABLES */ /* count the number of instances of this object so that certain free() * functions can be called only after the final instance is detroyed. */ EXTERN t_int hid_instance_count; /* this is used to test for the first instance to execute */ EXTERN double last_execute_time[MAX_DEVICES]; EXTERN unsigned short global_debug_level; /* built up when the elements of an open device are enumerated */ typedef struct _hid_element { #ifdef __linux__ /* GNU/Linux store type and code to compare against */ __u16 linux_type; __u16 linux_code; #else void *os_pointer; // pRecElement on Mac OS X; ... on Windows #endif /* __linux__ */ t_symbol *type; // Linux "type"; HID "usagePage" t_symbol *name; // Linux "code"; HID "usage" unsigned char polled; // is it polled or queued? (maybe only on Mac OS X?) unsigned char relative; // relative data gets output everytime t_int min; // from device report t_int max; // from device report t_float instance; // usage page/usage instance # ([absolute throttle 2 163( t_int value; // output the sum of events in a poll for relative axes t_int previous_value; //only output on change on abs and buttons } t_hid_element; /* mostly for status querying */ EXTERN unsigned short device_count; /* store element structs to eliminate symbol table lookups, etc. */ EXTERN t_hid_element *element[MAX_DEVICES][MAX_ELEMENTS]; /* number of active elements per device */ EXTERN unsigned short element_count[MAX_DEVICES]; /*------------------------------------------------------------------------------ * FUNCTION PROTOTYPES FOR DIFFERENT PLATFORMS */ /* support functions */ void debug_print(t_int debug_level, const char *fmt, ...); void debug_error(t_hid *x, t_int debug_level, const char *fmt, ...); void hid_output_event(t_hid *x, t_hid_element *output_data); /* the old way void hid_output_event(t_hid *x, t_symbol *type, t_symbol *code, t_float value); */ /* generic, cross-platform functions implemented in a separate file for each * platform */ t_int hid_open_device(t_hid *x, short device_number); t_int hid_close_device(t_hid *x); void hid_build_device_list(void); void hid_get_events(t_hid *x); void hid_print(t_hid* x); /* print info to the console */ void hid_platform_specific_info(t_hid* x); /* device info on the status outlet */ void hid_platform_specific_free(t_hid *x); short get_device_number_by_id(unsigned short vendor_id, unsigned short product_id); short get_device_number_from_usage(short device_number, unsigned short usage_page, unsigned short usage); /* cross-platform force feedback functions */ t_int hid_ff_autocenter(t_hid *x, t_float value); t_int hid_ff_gain(t_hid *x, t_float value); t_int hid_ff_motors(t_hid *x, t_float value); t_int hid_ff_continue(t_hid *x); t_int hid_ff_pause(t_hid *x); t_int hid_ff_reset(t_hid *x); t_int hid_ff_stopall(t_hid *x); // these are just for testing... t_int hid_ff_fftest (t_hid *x, t_float value); void hid_ff_print(t_hid *x); #endif /* #ifndef _HID_H */ pd-hid_0.7/hid_graph-help.pd0000644000076500007650000000260211504504627014471 0ustar hanshans#N canvas 0 31 495 470 10; #X obj 5 2 cnv 15 450 20 empty empty hid_graph 2 11 1 18 -233017 -66577 0; #X obj 422 3 pddp/pddplink http://puredata.info/dev/pddp -text pddp ; #X text 27 410 (C) Copyright 2004 Hans-Christoph Steiner ; #X text 244 424 released under the GNU GPL; #X text 98 381 For more info:; #X msg 19 150 reset; #X floatatom 115 163 5 0 0 0 - - -; #X floatatom 114 314 5 0 0 0 - - -; #X obj 98 341 hsl 250 15 0 1 0 0 empty empty empty 22 8 1 12 -262144 -1 -1 0 1; #X obj 98 138 hsl 250 15 0 1 0 0 empty empty empty 22 8 1 12 -261681 -1 -1 0 1; #X obj 95 187 hid/hid_graph; #X text 18 33 This object allows you to draw an arbitrary curve \, which is then applied to the input range. To change the curve \, click anywhere on the black diagonal line and start dragging.; #X text 19 86 There are 100 points in [hid_graph] \, each one pixel in size.; #N canvas 478 206 494 344 META 0; #X text 12 135 HELP_PATCH_AUTHORS "pd meta" information added by Jonathan Wilkes for Pd version 0.42.; #X text 12 25 LICENSE GPL; #X text 12 75 INLET_0 float; #X text 12 95 OUTLET_0 float; #X text 12 115 AUTHOR Hans-Christoph Steiner; #X text 12 45 DESCRIPTION draw an arbitrary curve \, which is then applied to the input range; #X text 12 5 KEYWORDS control conversion GUI abstraction; #X restore 442 441 pd META; #X connect 9 0 6 0; #X connect 9 0 10 0; #X connect 10 0 7 0; #X connect 10 0 8 0; pd-hid_0.7/notescale.pd0000644000076500007650000000131711504504627013575 0ustar hanshans#N canvas 37 318 444 446 10; #X obj 64 49 inlet; #X obj 64 389 outlet; #X obj 64 325 int; #X obj 64 297 expr $f1 * ($f3 - $f2) + $f2; #X obj 357 231 f \$2; #X obj 159 230 f \$1; #X obj 159 257 expr if ($f1 == $f2 \, 0 \, $f1) \; if ($f1 == $f2 \, 127 \, $f2); #X text 10 7 [notescale]; #X obj 229 152 loadbang; #X obj 229 179 t b b; #X text 114 49 input range: 0 to 1; #X obj 64 96 min 1; #X obj 64 116 max 0; #X text 123 389 output range: MIDI note #s; #X connect 0 0 11 0; #X connect 2 0 1 0; #X connect 3 0 2 0; #X connect 4 0 6 1; #X connect 5 0 6 0; #X connect 6 0 3 1; #X connect 6 1 3 2; #X connect 8 0 9 0; #X connect 9 0 5 0; #X connect 9 1 4 0; #X connect 11 0 12 0; #X connect 12 0 3 0; #X connect 12 0 9 0; pd-hid_0.7/hid_centered-help.pd0000644000076500007650000000316511504504627015166 0ustar hanshans#N canvas 0 31 468 398 10; #X obj 5 2 cnv 15 450 20 empty empty hid_centered 2 11 1 18 -233017 -66577 0; #X obj 422 3 pddp/pddplink http://puredata.info/dev/pddp -text pddp ; #X text 27 320 (C) Copyright 2004 Hans-Christoph Steiner ; #X text 244 334 released under the GNU GPL; #X text 98 291 For more info:; #X obj 102 234 hid/hid_centered; #X obj 137 105 tgl 25 0 empty empty empty 0 -6 0 8 -225271 -1 -1 0 1; #X msg 200 138 open \$1; #X obj 200 118 hradio 15 1 1 8 \$0-device-number empty choose_a_device 0 -6 1 9 -262144 -1 -1 7; #X obj 174 118 nbx 1 14 -1e+37 1e+37 0 0 empty \$0-device-number empty 0 -6 0 14 -166441 -1 -1 0 256; #X obj 137 170 joystick 0; #X obj 205 235 hid/hid_centered; #X floatatom 205 256 5 0 0 0 Y - -; #X floatatom 102 255 5 0 0 0 X - -; #X floatatom 205 216 5 0 0 0 Y - -; #X floatatom 102 215 5 0 0 0 X - -; #X text 19 34 Convert the standard "0 to 1" [hid] format to "-1 to 1" so that 0 is the center point of the range. With a joystick \, for example \, this can make the center point of the joystick (0 \, 0) rather than (0.5 \, 0.5).; #N canvas 478 206 494 344 META 0; #X text 12 145 HELP_PATCH_AUTHORS "pd meta" information added by Jonathan Wilkes for Pd version 0.42.; #X text 12 35 LICENSE GPL; #X text 12 85 INLET_0 float; #X text 12 105 OUTLET_0 float; #X text 12 125 AUTHOR Hans-Christoph Steiner; #X text 12 55 DESCRIPTION convert the standard "0 to 1" [hid] format to "-1 to 1" so that 0 is the center point of the range; #X text 12 5 KEYWORDS control conversion abstraction needs_work (connections) ; #X restore 408 368 pd META; #X connect 6 0 10 0; #X connect 7 0 10 0; #X connect 8 0 7 0; pd-hid_0.7/rad2hid.pd0000644000076500007650000000124411504504627013134 0ustar hanshans#N canvas 258 110 429 400 10; #X obj 42 36 inlet; #X obj 140 297 outlet; #X text 19 9 [rad2hid]; #X obj 141 234 % 628318; #X obj 127 167 moses 0; #X obj 141 255 / 628318; #X obj 42 96 * 100000; #X obj 41 167 % 628318; #X obj 42 136 moses -314159; #X obj 85 200 + 628318; #X text 10 66 % is an int operation \, we want floats \, so convert to large integers; #X text 225 351 released under the GNU GPL; #X text 8 337 (C) Copyright 2005 Hans-Christoph Steiner ; #X connect 0 0 6 0; #X connect 3 0 5 0; #X connect 4 0 9 0; #X connect 4 1 3 0; #X connect 5 0 1 0; #X connect 6 0 8 0; #X connect 7 0 9 0; #X connect 8 0 7 0; #X connect 8 1 4 0; #X connect 9 0 3 0; pd-hid_0.7/TODO0000644000076500007650000002143711504504627011770 0ustar hanshans ______________________________________________________________________________ - switch to snprintf in hid_darwin.c, replace all sprintf()s with snprintf()s. ______________________________________________________________________________ - deal with hatswitches!! Because of the currnently implementation of the conversion of the MacOS X style event to the Linux style event, an event with a value of zero is output on the unchanged axis when the hatswitch is moved in along the X or Y axis (as opposed to diagonally). but this might be fixed... - fix up hatswitch logic... hmmm on Mac OS X, just make the next element in the array always be the Y axis of the hatswitch, then when receiving a hatswitch event, output, increment, then output again (yes, its a hack). - what do standard hatswitches output on the various platforms? they should probably always output like axes, but then the CUI will be screwed ______________________________________________________________________________ = fix key names on Mac OS X I think they are unimplemented... :-( ______________________________________________________________________________ = array lookups for symbols implementation idea #2: this array should be built by hid_build_elements_list(). Then each time it fetches an event using the element_pointer array, it would also get the stored usage_page and usage symbols, and instance t_float. So I need to make an element struct like: struct _hid_element { void *element; t_symbol *type; // HID "usage page" t_symbol *usage; // Linux "code" t_float instance; t_float previous_value; //only output on change on abs and buttons } t_hid_element; For Linux input.h, instead void *element, store the type and code numbers to compare against ______________________________________________________________________________ = make only the first executed instance fetch the data the function is ugen_getsortno() -- returns an integer which increases eachtime DSP is restarted. You can add the function call (to the ugen chain for instance) each time you see ugen_getsortno() return an integer greater than the previous one you've ______________________________________________________________________________ = output one value per poll - for relative axes, sum up all events and output one http://lists.apple.com/archives/mac-games-dev/2005/Oct/msg00060.html - current method only works for instances in the same patch... ______________________________________________________________________________ = [poll 1( message set to exact delay based on block size to eliminate the jitter of the messages being processed every block, have [poll 1( set the time to the poll size (~1.5ms for 44,100) ______________________________________________________________________________ = iterate through elements and do a proper queue of the ones we want: - also, label multiple instances of the same usage http://mud.5341.com/msg/8455.html ______________________________________________________________________________ = make second inlet for specific status requests [human->pd]) - [vendor(, [product( - [range( - [poll( - [name( - [type( ______________________________________________________________________________ = output device data on open - Logical Min/Max i.e. [range -127 127( - device string [name Trackpad( ______________________________________________________________________________ = get tablets working on Mac OS X http://www.versiontracker.com/php/feedback/article.php?story=20051221163326829 http://www.wacom-europe.com/forum/topic.asp?TOPIC_ID=2719&ARCHIVE= ______________________________________________________________________________ = block devices like mice/keyboards etc from outputting at least document the procedure needed Mac OS X: http://lists.apple.com/archives/usb/2005/Aug/msg00068.html ______________________________________________________________________________ = open devices by name i.e "Trackpad" a la Max's [hi] ______________________________________________________________________________ = = autoscaling based on Logical min/max - this is probably essential for input, the question is how to find out what the data range is easily. - output would be handy, rather than autoscale, to save on CPU - this should probably be done in Pd space ______________________________________________________________________________ = test verbose names - matju says symbols are compared by pointer, so they are fast - try verbose names like: syn = sync snd = sound msc = misc rep = repeat pwr = power - maybe these too abs = absolute rel = relative btn = button - maybe make the type the full name, with the code using the abbreviation - change generic ev_9 to type_9 - change word "code" to "element" ______________________________________________________________________________ = event name changes - make key/button Type "button" rather than "key" (undecided on this one) ______________________________________________________________________________ = hid/serial - open/close status outlet - [send ( to send data - [tgl] 1/0 for open/close ______________________________________________________________________________ = linux input synch events (EV_SYN) - these seem to be generated by the Linux kernel, so they probably don't fit in with the [hid] scheme. Probably the best thing is to ditch them, or figure out whether they should be used in controlling the flow of event data, as they are intended. ______________________________________________________________________________ = writing support! - Linux example: http://www.linuxjournal.com/article/6429 ______________________________________________________________________________ = profile [hid] object and usage - find out if [autoscale] takes a lot of CPU power, or where in [hid] is using CPU where it doesn't have to be ______________________________________________________________________________ = Report available FF effects - check against HID Utilities Source/PID.h ______________________________________________________________________________ = pollfn for mouse-like devices - determine whether using a pollfn is actually better than using a t_clock - any device that acts like a system mouse can be used with a pollfn, since the mouse data will go thru Pd's network port, triggering the pollfn. - this is probably unnecessary since the t_clock seems to run well at 1ms delay - at standard block size (64 samples), one block = ~1.5ms ______________________________________________________________________________ = check out using USB timestamp - use the USB timestamp to correctly space the output data (meh, probably not useful) /----------------------------------------------------------------------------\ ------------------------------------------------------------------------------ BUGS BUGS BUGS BUGS BUGS BUGS BUGS BUGS BUGS BUGS BUGS BUGS BUGS BUGS BUGS ------------------------------------------------------------------------------ \----------------------------------------------------------------------------/ ______________________________________________________________________________ - BUG: crashes when you try yo open "mouse" with no args ______________________________________________________________________________ - BUG: on Mac OS X, polling starts without hid_build_device_list() or hid_open() - when polling starts, hid_build_device_list() should be called before starting ______________________________________________________________________________ - BUG: figure out how to prevent segfaults on mismapped devices/elements - it should gracefully ignore things where it currently segfaults - looks like its in build_device_list ______________________________________________________________________________ - BUG: multiple instances pointing to the same device don't have seperate close/free - closing the device on one instance closing that same device on all other instances of [hid] - deleting that instance also closes the device for all other instances pointing to that same device ______________________________________________________________________________ - BUG: getting events from the queue doesn't output a 0 value event when the motion stops, so when the mouse stops, the sound keeps playing. This is probably only a problem on relative axes. This will probably have to be implemented on a platform-specific level: - On Darwin/MacOSX, I think that the HIDGetEvent() loop will have to be followed by one call to HIDGetElementValue() ______________________________________________________________________________ - BUG: on MacOS X, two keyboard key codes are reported as hatswitches abs abs_hat0x Button Input, Keyboard Usage 0x39 abs abs_hat0y Button Input, Keyboard Usage 0x39 I am pretty sure this is just a hid_print_element_list() display problem. pd-hid_0.7/hid_invert-help.pd0000644000076500007650000000212511504504627014677 0ustar hanshans#N canvas 0 31 469 312 10; #X obj 5 2 cnv 15 450 20 empty empty hid_invert 2 11 1 18 -233017 -66577 0; #X obj 422 3 pddp/pddplink http://puredata.info/dev/pddp -text pddp ; #X text 27 270 (C) Copyright 2004 Hans-Christoph Steiner ; #X text 244 284 released under the GNU GPL; #X floatatom 153 90 5 0 0 0 - - -; #X floatatom 153 166 5 0 0 0 - - -; #X obj 153 126 hid/hid_invert; #X obj 156 71 hsl 128 15 0 1 0 0 empty empty empty -2 -6 0 8 -262144 -1 -1 0 1; #X obj 156 183 hsl 128 15 0 1 0 0 empty empty empty -2 -6 0 8 -262144 -1 -1 0 1; #X text 27 43 Inverts the stream of numbers.; #X text 98 233 For more info:; #N canvas 504 253 494 344 META 0; #X text 12 125 HELP_PATCH_AUTHORS "pd meta" information added by Jonathan Wilkes for Pd version 0.42.; #X text 12 25 LICENSE GPL; #X text 12 105 AUTHOR Hans-Christoph Steiner; #X text 12 45 DESCRIPTION invert the stream of numbers.; #X text 12 65 INLET_0 float; #X text 12 85 OUTLET_0 float; #X text 12 5 KEYWORDS control abstraction; #X restore 417 277 pd META; #X connect 4 0 6 0; #X connect 5 0 8 0; #X connect 6 0 5 0; #X connect 7 0 4 0; pd-hid_0.7/Makefile0000644000076500007650000003504611504504627012741 0ustar hanshans## Pd library template version 1.0.6 # For instructions on how to use this template, see: # http://puredata.info/docs/developer/MakefileTemplate LIBRARY_NAME = hid # add your .c source files, one object per file, to the SOURCES # variable, help files will be included automatically SOURCES = hid.c # list all pd objects (i.e. myobject.pd) files here, and their helpfiles will # be included automatically PDOBJECTS = buttongate.pd deg2hid.pd hid2deg.pd hid2rad.pd hid_average.pd hid_centered.pd hid_cube.pd hid_cuberoot.pd hid_exp.pd hid_graph.pd hid_invert.pd hid_log.pd hid_lowpass.pd hid_menu.pd hid_one2four.pd hid_one2three.pd hid_one2two.pd hid_polar.pd hid_rel2abs.pd hid_smooth.pd hid_spiral.pd hid_square.pd hid_squareroot.pd joystick.pd keyboard.pd keygate.pd mouse.pd notescale.pd rad2hid.pd # example patches and related files, in the 'examples' subfolder EXAMPLES = polar-joystick.pd spiral-joystick.pd # manuals and related files, in the 'manual' subfolder MANUAL = # if you want to include any other files in the source and binary tarballs, # list them here. This can be anything from header files, test patches, # documentation, etc. README.txt and LICENSE.txt are required and therefore # automatically included EXTRA_DIST = TODO hid.h input_arrays.h # NOTE: modified to build using platform-specific files and APIs EXTRA_SOURCES = input_arrays.c hid_linux.c hid_darwin.c #------------------------------------------------------------------------------# # # things you might need to edit if you are using other C libraries # #------------------------------------------------------------------------------# # -I"$(PD_INCLUDE)/pd" supports the header location for 0.43 CFLAGS = -I"$(PD_INCLUDE)/pd" -Wall -W -g LDFLAGS = LIBS = #------------------------------------------------------------------------------# # # you shouldn't need to edit anything below here, if we did it right :) # #------------------------------------------------------------------------------# # get library version from meta file LIBRARY_VERSION = $(shell sed -n 's|^\#X text [0-9][0-9]* [0-9][0-9]* VERSION \(.*\);|\1|p' $(LIBRARY_NAME)-meta.pd) CFLAGS += -DPD -DVERSION='"$(LIBRARY_VERSION)"' PD_INCLUDE = $(PD_PATH)/include # where to install the library, overridden below depending on platform prefix = /usr/local libdir = $(prefix)/lib pkglibdir = $(libdir)/pd-externals objectsdir = $(pkglibdir) INSTALL = install INSTALL_PROGRAM = $(INSTALL) -p -m 644 INSTALL_DATA = $(INSTALL) -p -m 644 INSTALL_DIR = $(INSTALL) -p -m 755 -d ALLSOURCES := $(SOURCES) $(SOURCES_android) $(SOURCES_cygwin) $(SOURCES_macosx) \ $(SOURCES_iphoneos) $(SOURCES_linux) $(SOURCES_windows) DISTDIR=$(LIBRARY_NAME)-$(LIBRARY_VERSION) ORIGDIR=pd-$(LIBRARY_NAME:~=)_$(LIBRARY_VERSION) UNAME := $(shell uname -s) ifeq ($(UNAME),Darwin) CPU := $(shell uname -p) ifeq ($(CPU),arm) # iPhone/iPod Touch SOURCES += $(SOURCES_iphoneos) EXTENSION = pd_darwin OS = iphoneos PD_PATH = /Applications/Pd-extended.app/Contents/Resources IPHONE_BASE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin CC=$(IPHONE_BASE)/gcc CPP=$(IPHONE_BASE)/cpp CXX=$(IPHONE_BASE)/g++ ISYSROOT = -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk IPHONE_CFLAGS = -miphoneos-version-min=3.0 $(ISYSROOT) -arch armv6 OPT_CFLAGS = -fast -funroll-loops -fomit-frame-pointer CFLAGS := $(IPHONE_CFLAGS) $(OPT_CFLAGS) $(CFLAGS) LDFLAGS += -arch armv6 -bundle -undefined dynamic_lookup $(ISYSROOT) LIBS += -lc STRIP = strip -x DISTBINDIR=$(DISTDIR)-$(OS) else # Mac OS X SOURCES += $(SOURCES_macosx) EXTENSION = pd_darwin OS = macosx PD_PATH = /Applications/Pd-extended.app/Contents/Resources OPT_CFLAGS = -ftree-vectorize -ftree-vectorizer-verbose=2 -fast # build universal 32-bit on 10.4 and 32/64 on newer ifeq ($(shell uname -r | sed 's|\([0-9][0-9]*\)\.[0-9][0-9]*\.[0-9][0-9]*|\1|'), 8) FAT_FLAGS = -arch ppc -arch i386 -mmacosx-version-min=10.4 else FAT_FLAGS = -arch ppc -arch i386 -arch x86_64 -mmacosx-version-min=10.4 SOURCES += $(SOURCES_iphoneos) endif # NOTE: kludge, this doesn't build universal FAT_FLAGS = -mmacosx-version-min=10.4 CFLAGS += $(FAT_FLAGS) -fPIC -I/sw/include LDFLAGS += $(FAT_FLAGS) -bundle -undefined dynamic_lookup -L/sw/lib # if the 'pd' binary exists, check the linking against it to aid with stripping LDFLAGS += $(shell test -e $(PD_PATH)/bin/pd && echo -bundle_loader $(PD_PATH)/bin/pd) LIBS += -lc STRIP = strip -x DISTBINDIR=$(DISTDIR)-$(OS) # install into ~/Library/Pd on Mac OS X since /usr/local isn't used much pkglibdir=$(HOME)/Library/Pd endif endif ifeq ($(UNAME),Linux) CPU := $(shell uname -m) SOURCES += $(SOURCES_linux) EXTENSION = pd_linux OS = linux PD_PATH = /usr OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer CFLAGS += -fPIC LDFLAGS += -Wl,--export-dynamic -shared -fPIC LIBS += -lc STRIP = strip --strip-unneeded -R .note -R .comment DISTBINDIR=$(DISTDIR)-$(OS)-$(shell uname -m) endif ifeq ($(UNAME),GNU) # GNU/Hurd, should work like GNU/Linux for basically all externals CPU := $(shell uname -m) SOURCES += $(SOURCES_linux) EXTENSION = pd_linux OS = linux PD_PATH = /usr OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer CFLAGS += -fPIC LDFLAGS += -Wl,--export-dynamic -shared -fPIC LIBS += -lc STRIP = strip --strip-unneeded -R .note -R .comment DISTBINDIR=$(DISTDIR)-$(OS)-$(shell uname -m) endif ifeq ($(UNAME),GNU/kFreeBSD) # Debian GNU/kFreeBSD, should work like GNU/Linux for basically all externals CPU := $(shell uname -m) SOURCES += $(SOURCES_linux) EXTENSION = pd_linux OS = linux PD_PATH = /usr OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer CFLAGS += -fPIC LDFLAGS += -Wl,--export-dynamic -shared -fPIC LIBS += -lc STRIP = strip --strip-unneeded -R .note -R .comment DISTBINDIR=$(DISTDIR)-$(OS)-$(shell uname -m) endif ifeq (CYGWIN,$(findstring CYGWIN,$(UNAME))) CPU := $(shell uname -m) SOURCES += $(SOURCES_cygwin) EXTENSION = dll OS = cygwin PD_PATH = $(cygpath $(PROGRAMFILES))/pd OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer CFLAGS += LDFLAGS += -Wl,--export-dynamic -shared -L"$(PD_PATH)/src" -L"$(PD_PATH)/bin" LIBS += -lc -lpd STRIP = strip --strip-unneeded -R .note -R .comment DISTBINDIR=$(DISTDIR)-$(OS) endif ifeq (MINGW,$(findstring MINGW,$(UNAME))) CPU := $(shell uname -m) SOURCES += $(SOURCES_windows) EXTENSION = dll OS = windows PD_PATH = $(shell cd "$(PROGRAMFILES)"/pd && pwd) OPT_CFLAGS = -O3 -funroll-loops -fomit-frame-pointer CFLAGS += -mms-bitfields LDFLAGS += -s -shared -Wl,--enable-auto-import LIBS += -L"$(PD_PATH)/src" -L"$(PD_PATH)/bin" -L"$(PD_PATH)/obj" -lpd -lwsock32 -lkernel32 -luser32 -lgdi32 STRIP = strip --strip-unneeded -R .note -R .comment DISTBINDIR=$(DISTDIR)-$(OS) endif # in case somebody manually set the HELPPATCHES above HELPPATCHES ?= $(SOURCES:.c=-help.pd) $(PDOBJECTS:.pd=-help.pd) CFLAGS += $(OPT_CFLAGS) .PHONY = install libdir_install single_install install-doc install-exec install-examples install-manual clean dist etags $(LIBRARY_NAME) all: $(SOURCES:.c=.$(EXTENSION)) %.o: %.c $(CC) -IHID\ Utilities\ Source $(CFLAGS) -o "$*.o" -c "$*.c" HID_UTILITIES_SOURCE = HID\ Utilities\ Source $(HID_UTILITIES_SOURCE)/build/Default/libHIDUtilities.a: # Apple changed the XCode CLI tool's name in xcode2... arg # if on non-Mac OS X, this target just echos a message cd $(HID_UTILITIES_SOURCE) && \ (test -x /usr/bin/xcodebuild && /usr/bin/xcodebuild) || \ (test -x /usr/bin/pbxbuild && /usr/bin/pbxbuild) || \ echo "Not building Apple HID Utilities" hid.pd_darwin: hid.o input_arrays.o hid_darwin.o $(HID_UTILITIES_SOURCE)/build/Default/libHIDUtilities.a $(CC) $(LDFLAGS) -o hid.$(EXTENSION) hid.o input_arrays.o hid_darwin.o \ $(LIBS) $(HID_UTILITIES_SOURCE)/build/Default/libHIDUtilities.a \ -framework Carbon -framework IOKit -weak_framework ForceFeedback chmod a-x hid.$(EXTENSION) hid.pd_linux: hid.o input_arrays.o hid_linux.o $(CC) $(LDFLAGS) -o hid.$(EXTENSION) hid.o input_arrays.o hid_linux.o $(LIBS) chmod a-x hid.$(EXTENSION) # this links everything into a single binary file $(LIBRARY_NAME): $(SOURCES:.c=.o) $(LIBRARY_NAME).o $(CC) $(LDFLAGS) -o $(LIBRARY_NAME).$(EXTENSION) $(SOURCES:.c=.o) $(LIBRARY_NAME).o $(LIBS) chmod a-x $(LIBRARY_NAME).$(EXTENSION) install: libdir_install # The meta and help files are explicitly installed to make sure they are # actually there. Those files are not optional, then need to be there. libdir_install: $(SOURCES:.c=.$(EXTENSION)) install-doc install-examples install-manual $(INSTALL_DIR) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) $(INSTALL_DATA) $(LIBRARY_NAME)-meta.pd \ $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) test -z "$(strip $(SOURCES))" || (\ $(INSTALL_PROGRAM) $(SOURCES:.c=.$(EXTENSION)) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) && \ $(STRIP) $(addprefix $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/,$(SOURCES:.c=.$(EXTENSION)))) test -z "$(strip $(PDOBJECTS))" || \ $(INSTALL_DATA) $(PDOBJECTS) \ $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) # install library linked as single binary single_install: $(LIBRARY_NAME) install-doc install-exec $(INSTALL_DIR) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) $(INSTALL_PROGRAM) $(LIBRARY_NAME).$(EXTENSION) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) $(STRIP) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/$(LIBRARY_NAME).$(EXTENSION) install-doc: $(INSTALL_DIR) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) test -z "$(strip $(SOURCES) $(PDOBJECTS))" || \ $(INSTALL_DATA) $(HELPPATCHES) \ $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) $(INSTALL_DATA) README.txt $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/README.txt $(INSTALL_DATA) LICENSE.txt $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/LICENSE.txt install-examples: test -z "$(strip $(EXAMPLES))" || \ $(INSTALL_DIR) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/examples && \ for file in $(EXAMPLES); do \ $(INSTALL_DATA) examples/$$file $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/examples; \ done install-manual: test -z "$(strip $(MANUAL))" || \ $(INSTALL_DIR) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/manual && \ for file in $(MANUAL); do \ $(INSTALL_DATA) manual/$$file $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/manual; \ done clean: -rm -f -- $(EXTRA_SOURCES:.c=.o) -rm -f -- $(SOURCES:.c=.o) $(SOURCES_LIB:.c=.o) -rm -f -- $(SOURCES:.c=.$(EXTENSION)) -rm -f -- $(LIBRARY_NAME).o -rm -f -- $(LIBRARY_NAME).$(EXTENSION) -rm -rf -- "HID Utilities Source/build" distclean: clean -rm -f -- $(DISTBINDIR).tar.gz -rm -rf -- $(DISTBINDIR) -rm -f -- $(DISTDIR).tar.gz -rm -rf -- $(DISTDIR) -rm -f -- $(ORIGDIR).tar.gz -rm -rf -- $(ORIGDIR) $(DISTBINDIR): $(INSTALL_DIR) $(DISTBINDIR) libdir: all $(DISTBINDIR) $(INSTALL_DATA) $(LIBRARY_NAME)-meta.pd $(DISTBINDIR) $(INSTALL_DATA) $(SOURCES) $(DISTBINDIR) $(INSTALL_DATA) $(HELPPATCHES) $(DISTBINDIR) test -z "$(strip $(EXTRA_DIST))" || \ $(INSTALL_DATA) $(EXTRA_DIST) $(DISTBINDIR) # tar --exclude-vcs -czpf $(DISTBINDIR).tar.gz $(DISTBINDIR) $(DISTDIR): $(INSTALL_DIR) $(DISTDIR) $(ORIGDIR): $(INSTALL_DIR) $(ORIGDIR) dist: $(DISTDIR) $(INSTALL_DIR) "$(DISTDIR)/HID Utilities Source" $(INSTALL_DIR) "$(DISTDIR)/HID Utilities Source/HID Utilities Slib.pbproj" $(INSTALL_DATA) "HID Utilities Source/HID Utilities Slib.pbproj/project.pbxproj" \ "$(DISTDIR)/HID Utilities Source/HID Utilities Slib.pbproj" $(INSTALL_DIR) "$(DISTDIR)/HID Utilities Source/English.lproj" $(INSTALL_DATA) "HID Utilities Source/English.lproj/HID_cookie_strings.plist" \ "HID Utilities Source/English.lproj/HID_device_usage_strings.plist" \ "HID Utilities Source/English.lproj/HID_usage_strings.plist" \ "$(DISTDIR)/HID Utilities Source/English.lproj" $(INSTALL_DATA) "HID Utilities Source/HID Utilities Read Me.rtf" \ "HID Utilities Source/HID_APIs.h" \ "HID Utilities Source/HID_CFM.c" \ "HID Utilities Source/HID_Config_Utilities.c" \ "HID Utilities Source/HID_Config_Utilities.h" \ "HID Utilities Source/HID_Error_Handler.c" \ "HID Utilities Source/HID_Error_Handler.h" \ "HID Utilities Source/HID_Name_Lookup.c" \ "HID Utilities Source/HID_Name_Lookup.h" \ "HID Utilities Source/HID_Queue_Utilities.c" \ "HID Utilities Source/HID_Queue_Utilities.h" \ "HID Utilities Source/HID_Transaction_Utilities.c" \ "HID Utilities Source/HID_Transaction_Utilities.h" \ "HID Utilities Source/HID_Utilities.c" \ "HID Utilities Source/HID_Utilities.h" \ "HID Utilities Source/HID_Utilities_CFM.h" \ "HID Utilities Source/HID_Utilities_External.h" \ "HID Utilities Source/HID_Utilities_Internal.h" \ "HID Utilities Source/HIDLib.h" \ "HID Utilities Source/ImmrHIDUtilAddOn.c" \ "HID Utilities Source/ImmrHIDUtilAddOn.h" \ "HID Utilities Source/IOHIDPowerUsage.h" \ "HID Utilities Source/LICENSE.txt" \ "HID Utilities Source/PID.h" \ "$(DISTDIR)/HID Utilities Source" $(INSTALL_DATA) Makefile $(DISTDIR) $(INSTALL_DATA) README.txt $(DISTDIR) $(INSTALL_DATA) LICENSE.txt $(DISTDIR) $(INSTALL_DATA) $(EXTRA_SOURCES) $(DISTDIR) $(INSTALL_DATA) $(LIBRARY_NAME)-meta.pd $(DISTDIR) test -z "$(strip $(ALLSOURCES))" || \ $(INSTALL_DATA) $(ALLSOURCES) $(DISTDIR) test -z "$(strip $(PDOBJECTS))" || \ $(INSTALL_DATA) $(PDOBJECTS) $(DISTDIR) test -z "$(strip $(HELPPATCHES))" || \ $(INSTALL_DATA) $(HELPPATCHES) $(DISTDIR) test -z "$(strip $(EXTRA_DIST))" || \ $(INSTALL_DATA) $(EXTRA_DIST) $(DISTDIR) test -z "$(strip $(EXAMPLES))" || \ $(INSTALL_DIR) $(DISTDIR)/examples && \ for file in $(EXAMPLES); do \ $(INSTALL_DATA) examples/$$file $(DISTDIR)/examples; \ done test -z "$(strip $(MANUAL))" || \ $(INSTALL_DIR) $(DISTDIR)/manual && \ for file in $(MANUAL); do \ $(INSTALL_DATA) manual/$$file $(DISTDIR)/manual; \ done tar --exclude-vcs -czpf $(DISTDIR).tar.gz $(DISTDIR) # make a Debian source package dpkg-source: debclean make distclean dist mv $(DISTDIR) $(ORIGDIR) tar --exclude-vcs -czpf ../$(ORIGDIR).orig.tar.gz $(ORIGDIR) rm -f -- $(DISTDIR).tar.gz rm -rf -- $(DISTDIR) $(ORIGDIR) cd .. && dpkg-source -b $(LIBRARY_NAME) etags: etags *.h $(SOURCES) ../../pd/src/*.[ch] /usr/include/*.h /usr/include/*/*.h showsetup: @echo "CFLAGS: $(CFLAGS)" @echo "LDFLAGS: $(LDFLAGS)" @echo "LIBS: $(LIBS)" @echo "PD_INCLUDE: $(PD_INCLUDE)" @echo "PD_PATH: $(PD_PATH)" @echo "objectsdir: $(objectsdir)" @echo "LIBRARY_NAME: $(LIBRARY_NAME)" @echo "LIBRARY_VERSION: $(LIBRARY_VERSION)" @echo "SOURCES: $(SOURCES)" @echo "PDOBJECTS: $(PDOBJECTS)" @echo "ALLSOURCES: $(ALLSOURCES)" @echo "UNAME: $(UNAME)" @echo "CPU: $(CPU)" @echo "pkglibdir: $(pkglibdir)" @echo "DISTDIR: $(DISTDIR)" @echo "ORIGDIR: $(ORIGDIR)" pd-hid_0.7/hid_average.pd0000644000076500007650000000072411504504627014057 0ustar hanshans#N canvas 0 35 462 312 10; #X obj 67 31 inlet; #X obj 67 235 outlet; #X obj 102 78 loadbang; #X msg 76 113 weight; #X obj 67 149 average \$1; #X msg 130 113 10; #X text 27 266 (C) Copyright 2004 Hans-Christoph Steiner ; #X text 244 280 released under the GNU GPL; #X text 9 9 [hid_average]; #X obj 272 30 inlet; #X connect 0 0 4 0; #X connect 2 0 5 0; #X connect 2 0 3 0; #X connect 3 0 4 0; #X connect 4 0 1 0; #X connect 5 0 4 1; #X connect 9 0 4 1; pd-hid_0.7/hid_spiral-help.pd0000644000076500007650000000354011504504627014664 0ustar hanshans#N canvas 0 31 475 480 10; #X obj 5 2 cnv 15 450 20 empty empty hid_spiral 2 11 1 18 -233017 -66577 0; #X obj 422 3 pddp/pddplink http://puredata.info/dev/pddp -text pddp ; #X text 245 451 released under the GNU GPL; #X floatatom 70 283 5 0 0 0 - - -; #X floatatom 70 375 5 0 0 0 radius-> - -; #X text 175 408 For more info:; #X text 28 437 (C) Copyright 2005 Hans-Christoph Steiner ; #X obj 73 201 hsl 128 15 0 1 0 0 empty empty x-axis 133 7 1 10 -225280 -1 -1 0 0; #X obj 127 143 vsl 15 128 0 1 0 0 empty empty y-axis -6 -9 1 10 -261681 -1 -1 0 0; #X floatatom 136 376 8 0 0 1 <-angle - -; #X floatatom 127 283 5 0 0 0 - - -; #X obj 127 305 t b f; #X text 246 271 related objects:; #X text 264 324 example:; #X msg 70 126 0.5; #X text 15 126 center:; #X obj 323 324 spiral-joystick; #X obj 70 335 hid/hid_spiral; #X obj 362 271 hid/hid_polar; #X text 23 32 Converts cartesian coordinates(x \, y) to spiral in polar coordinates (radius \, angle). The angle is from 0 to 1 The angle 0 is at cartesian (1 \, 0) or far right center.; #X text 24 81 The angle will just keep going up/down as long as there is rotation rather than reset like [hid_polar].; #N canvas 485 31 494 344 META 0; #X text 12 175 HELP_PATCH_AUTHORS "pd meta" information added by Jonathan Wilkes for Pd version 0.42.; #X text 12 25 LICENSE GPL; #X text 12 155 AUTHOR Hans-Christoph Steiner; #X text 12 115 OUTLET_0 float; #X text 12 45 DESCRIPTION convert cartesian coordinates(x \, y) to spiral in polar coordinates (radius \, angle); #X text 12 75 INLET_0 float bang; #X text 12 95 INLET_1 float; #X text 12 135 OUTLET_1 float; #X text 12 5 KEYWORDS control conversion abstraction; #X restore 424 439 pd META; #X connect 3 0 17 0; #X connect 7 0 3 0; #X connect 8 0 10 0; #X connect 10 0 11 0; #X connect 11 0 17 0; #X connect 11 1 17 1; #X connect 14 0 7 0; #X connect 17 0 4 0; #X connect 17 1 9 0; pd-hid_0.7/hid_centered.pd0000644000076500007650000000041611504504627014234 0ustar hanshans#N canvas 0 32 389 315 10; #X obj 71 32 inlet; #X obj 71 249 outlet; #X text 119 32 input range: 0 to 1; #X text 9 5 [hid_centered]; #X obj 71 130 * 2; #X obj 71 152 - 1; #X text 127 249 output range: -1 to 1; #X connect 0 0 4 0; #X connect 4 0 5 0; #X connect 5 0 1 0; pd-hid_0.7/deg2hid.pd0000644000076500007650000000130411504504627013122 0ustar hanshans#N canvas 0 31 444 356 10; #X obj 88 30 inlet; #X obj 89 264 outlet; #X text 232 311 released under the GNU GPL; #X text 15 297 (C) Copyright 2005 Hans-Christoph Steiner ; #X text 143 264 output range: 0 to 360 \, 0 = north/top; #X text 19 9 [deg2hid]; #X text 129 28 input range: 0 to 360 \, 0 = east/right; #X obj 88 170 / 360; #X text 162 108 % is an int operation; #X text 169 126 this saves accuracy; #X obj 89 121 % 3.6e+07; #X obj 89 142 / 100000; #X obj 89 100 * 100000; #X obj 45 210 moses 0; #X obj 45 230 + 1; #X connect 0 0 12 0; #X connect 7 0 13 0; #X connect 10 0 11 0; #X connect 11 0 7 0; #X connect 12 0 10 0; #X connect 13 0 14 0; #X connect 13 1 1 0; #X connect 14 0 1 0; pd-hid_0.7/hid_log.pd0000644000076500007650000000041711504504627013225 0ustar hanshans#N canvas 297 485 422 322 10; #X obj 31 45 inlet; #X obj 31 282 outlet; #X text 79 45 input range: 0 to 1; #X text 87 282 output range: 0 to 1; #X text 9 5 [hid_log]; #X obj 30 145 rmstodb; #X obj 30 175 / 100; #X connect 0 0 5 0; #X connect 5 0 6 0; #X connect 6 0 1 0; pd-hid_0.7/mouse.pd0000644000076500007650000000412611504504627012751 0ustar hanshans#N canvas 273 44 783 608 10; #X obj 130 18 inlet; #X obj 25 521 outlet; #X obj 179 521 outlet; #X obj 442 472 outlet; #X obj 570 472 outlet; #X obj 246 24 loadbang; #X text 24 544 X; #X text 184 544 Y; #X text 444 493 wheel; #X obj 25 323 mapping/autoscale -1 1; #X obj 179 323 mapping/autoscale -1 1; #X obj 137 288 route rel_x rel_y rel_wheel; #X obj 398 313 print MOUSE_UNIMPLEMENTED_EVENT; #X obj 195 210 route rel key; #X text 554 493 button code/value list; #X text 71 562 (C) Copyright 2004 Hans-Christoph Steiner ; #X text 288 576 released under the GNU GPL; #X text 484 576 $Author: eighthave $; #X text 484 563 $Revision: 1.7 $; #X msg 193 472 0; #X msg 100 151 poll \$1; #X obj 100 106 s \$0-poll; #X obj 259 357 r \$0-poll; #X obj 100 131 r \$0-poll; #X obj 213 359 bang; #X msg 33 472 0; #X text 41 489 zero when no motion; #X obj 43 48 loadbang; #X obj 213 401 delay; #X obj 207 444 metro; #X msg 213 422 1; #X msg 185 422 0; #X obj 109 357 r \$0-poll; #X obj 63 359 bang; #X obj 63 401 delay; #X obj 57 444 metro; #X msg 63 422 1; #X msg 35 422 0; #X obj 108 378 * 2; #X obj 258 378 * 2; #X msg 246 134 open mouse \$1; #X obj 195 180 hid; #X msg 43 71 10; #X obj 130 63 route poll open; #X obj 246 48 float \$1; #X connect 0 0 43 0; #X connect 5 0 44 0; #X connect 9 0 1 0; #X connect 9 0 33 0; #X connect 10 0 2 0; #X connect 10 0 24 0; #X connect 11 0 9 0; #X connect 11 1 10 0; #X connect 11 2 3 0; #X connect 13 0 11 0; #X connect 13 1 4 0; #X connect 19 0 2 0; #X connect 20 0 41 0; #X connect 22 0 39 0; #X connect 23 0 20 0; #X connect 24 0 28 0; #X connect 24 0 31 0; #X connect 25 0 1 0; #X connect 27 0 42 0; #X connect 28 0 30 0; #X connect 29 0 19 0; #X connect 30 0 29 0; #X connect 31 0 29 0; #X connect 32 0 38 0; #X connect 33 0 34 0; #X connect 33 0 37 0; #X connect 34 0 36 0; #X connect 35 0 25 0; #X connect 36 0 35 0; #X connect 37 0 35 0; #X connect 38 0 34 1; #X connect 38 0 35 1; #X connect 39 0 28 1; #X connect 39 0 29 1; #X connect 40 0 41 0; #X connect 41 0 13 0; #X connect 42 0 21 0; #X connect 43 0 21 0; #X connect 43 1 40 0; #X connect 43 2 41 0; #X connect 44 0 40 0; pd-hid_0.7/hid_one2four-help.pd0000644000076500007650000000347211504504627015135 0ustar hanshans#N canvas 0 31 464 340 10; #X obj 5 2 cnv 15 450 20 empty empty hid_one2four 2 11 1 18 -233017 -66577 0; #X obj 422 3 pddp/pddplink http://puredata.info/dev/pddp -text pddp ; #X text 27 270 (C) Copyright 2004 Hans-Christoph Steiner ; #X text 244 284 released under the GNU GPL; #X floatatom 82 110 5 0 0 0 - - -; #X floatatom 23 186 5 0 0 0 - - -; #X obj 85 91 hsl 128 15 0 1 0 0 empty empty empty -2 -6 0 8 -262144 -1 -1 0 1; #X obj 26 208 hsl 75 15 0 1 0 0 empty empty empty -2 -6 0 8 -262144 -1 -1 0 1; #X text 98 243 For more info:; #X text 18 28 Simple one-to-three mapping object. The first inlet is passed thru \, the range of the output data on the other inlet starts at the points in the input range specified as arugments.; #X obj 82 145 hid/hid_one2four 0.3 0.6 0.9; #X floatatom 113 186 5 0 0 0 - - -; #X obj 116 208 hsl 75 15 0 1 0 0 empty empty empty -2 -6 0 8 -262144 -1 -1 0 1; #X floatatom 203 186 5 0 0 0 - - -; #X obj 206 208 hsl 75 15 0 1 0 0 empty empty empty -2 -6 0 8 -262144 -1 -1 0 1; #X floatatom 293 186 5 0 0 0 - - -; #X obj 296 208 hsl 75 15 0 1 0 0 empty empty empty -2 -6 0 8 -262144 -1 -1 0 1; #N canvas 474 31 494 344 META 0; #X text 12 185 HELP_PATCH_AUTHORS "pd meta" information added by Jonathan Wilkes for Pd version 0.42.; #X text 12 25 LICENSE GPL; #X text 12 165 AUTHOR Hans-Christoph Steiner; #X text 12 45 DESCRIPTION simple one-to-three mapping object; #X text 12 65 INLET_0 float; #X text 12 125 OUTLET_2 float; #X text 12 145 OUTLET_3 float; #X text 12 105 OUTLET_1 float; #X text 12 85 OUTLET_0 float; #X text 12 5 KEYWORDS control abstraction; #X restore 409 311 pd META; #X connect 4 0 10 0; #X connect 5 0 7 0; #X connect 6 0 4 0; #X connect 10 0 5 0; #X connect 10 1 11 0; #X connect 10 2 13 0; #X connect 10 3 15 0; #X connect 11 0 12 0; #X connect 13 0 14 0; #X connect 15 0 16 0; pd-hid_0.7/hid_cuberoot-help.pd0000644000076500007650000000413011504504627015210 0ustar hanshans#N canvas 2 31 464 319 10; #X obj 5 2 cnv 15 450 20 empty empty hid_cuberoot 2 11 1 18 -233017 -66577 0; #X obj 422 3 pddp/pddplink http://puredata.info/dev/pddp -text pddp ; #X text 27 255 (C) Copyright 2004 Hans-Christoph Steiner ; #X text 244 269 released under the GNU GPL; #X text 98 226 For more info:; #X floatatom 35 123 8 0 0 0 - - -; #X floatatom 34 177 8 0 0 0 - - -; #X obj 28 201 hsl 200 15 0 1 0 0 empty empty empty 22 8 1 12 -262144 -1 -1 0 1; #X obj 28 93 hsl 200 15 0 1 0 0 empty empty empty 22 8 1 12 -261681 -1 -1 0 1; #X obj 25 153 hid/hid_cuberoot; #N canvas 0 22 450 300 (subpatch) 0; #X array hid_cuberoot 100 float 0; #X coords 0 1 99 0 100 100 1; #X restore 321 111 graph; #N canvas 266 69 327 317 draw_array 0; #X msg 57 52 bang; #X obj 57 73 until; #X text 88 52 start; #X obj 57 95 f; #X obj 86 95 + 1; #X obj 132 97 sel 0; #X obj 86 117 mod 100; #X obj 57 150 t f f; #X obj 94 177 s array_index; #X obj 170 262 r array_index; #X obj 57 13 loadbang; #X obj 57 207 / 100; #X text 99 207 [hid] output range: 0 to 1; #X obj 56 233 hid/hid_cuberoot; #X obj 56 283 tabwrite hid_cuberoot; #X connect 0 0 1 0; #X connect 1 0 3 0; #X connect 3 0 4 0; #X connect 3 0 7 0; #X connect 4 0 6 0; #X connect 5 0 1 1; #X connect 6 0 3 1; #X connect 6 0 5 0; #X connect 7 0 11 0; #X connect 7 1 8 0; #X connect 9 0 14 1; #X connect 10 0 0 0; #X connect 11 0 13 0; #X connect 13 0 14 0; #X restore 321 78 pd draw_array; #X text 15 34 This object maps the input range to a cube root curve \, i.e. [pow 0.333333] \, "cube root of X" \, or X^0.333333.; #N canvas 478 206 494 344 META 0; #X text 12 135 HELP_PATCH_AUTHORS "pd meta" information added by Jonathan Wilkes for Pd version 0.42.; #X text 12 25 LICENSE GPL; #X text 12 75 INLET_0 float; #X text 12 95 OUTLET_0 float; #X text 12 115 AUTHOR Hans-Christoph Steiner; #X text 12 45 DESCRIPTION map the input range to a cube root curve \, i.e. [pow 0.333333] \, "cube root of X" \, or X^0.333333; #X text 12 5 KEYWORDS control conversion abstraction; #X restore 410 294 pd META; #X connect 8 0 5 0; #X connect 8 0 9 0; #X connect 9 0 6 0; #X connect 9 0 7 0; pd-hid_0.7/hid2deg.pd0000644000076500007650000000162211504504627013125 0ustar hanshans#N canvas 0 31 444 356 10; #X obj 88 30 inlet; #X obj 89 264 outlet; #X obj 88 56 min 1; #X obj 88 74 max 0; #X text 133 63 its a [hid] object \, so limit input range; #X text 232 311 released under the GNU GPL; #X text 15 297 (C) Copyright 2005 Hans-Christoph Steiner ; #X text 19 9 [hid2deg]; #X text 129 28 input range: 0 to 1 \, 0 = east/right; #X text 143 264 output range: 0 to 360 \, 0 = north/top; #X obj 88 100 * 360; #X text 162 189 % is an int operation; #X text 169 207 this saves accuracy; #X obj 88 148 abs; #X obj 88 123 - 450; #X text 131 122 <- rotate zero to north; #X text 130 148 <- change direction of rotation; #X obj 89 202 % 3.6e+07; #X obj 89 223 / 100000; #X obj 89 181 * 100000; #X connect 0 0 2 0; #X connect 2 0 3 0; #X connect 3 0 10 0; #X connect 10 0 14 0; #X connect 13 0 19 0; #X connect 14 0 13 0; #X connect 17 0 18 0; #X connect 18 0 1 0; #X connect 19 0 17 0; pd-hid_0.7/hid_linux.c0000644000076500007650000005434711504504627013435 0ustar hanshans/* this code only works for Linux kernels */ #ifdef __linux__ #include #include #include #include #include #include #include #include #include #include "hid.h" #define DEBUG(x) //#define DEBUG(x) x #define LINUX_BLOCK_DEVICE "/dev/input/event" /*------------------------------------------------------------------------------ * from evtest.c from the ff-utils package */ /* from asm/types.h and linux/input.h __kernel__ sections */ #define BITS_PER_LONG (sizeof(long) * 8) #define NBITS(x) (((x)/BITS_PER_LONG)+1) #define LONG(x) ((x)/BITS_PER_LONG) #define test_bit(bit, array) ((array[LONG(bit)] >> (bit%BITS_PER_LONG)) & 1) #define ISBITSET(x,i) ((x[i>>3] & (1<<(i&7)))!=0) /* * from an email from Vojtech: * * The application reading the device is supposed to queue all events up to * the SYN_REPORT event, and then process them, so that a mouse pointer * will move diagonally instead of following the sides of a rectangle, * which would be very annoying. */ /* ------------------------------------------------------------------------------ */ /* LINUX-SPECIFIC SUPPORT FUNCTIONS */ /* ------------------------------------------------------------------------------ */ t_symbol* hid_convert_linux_buttons_to_numbers(__u16 linux_code) { char hid_code[MAXPDSTRING]; if(linux_code >= 0x100) { if(linux_code < BTN_MOUSE) /* numbered buttons */ snprintf(hid_code, MAXPDSTRING,"btn_%d",linux_code - BTN_MISC); else if(linux_code < BTN_JOYSTICK) /* mouse buttons */ snprintf(hid_code, MAXPDSTRING,"btn_%d",linux_code - BTN_MOUSE); else if(linux_code < BTN_GAMEPAD) /* joystick buttons */ snprintf(hid_code, MAXPDSTRING,"btn_%d",linux_code - BTN_JOYSTICK); else if(linux_code < BTN_DIGI) /* gamepad buttons */ snprintf(hid_code, MAXPDSTRING,"btn_%d",linux_code - BTN_GAMEPAD); else if(linux_code < BTN_WHEEL) /* tablet buttons */ snprintf(hid_code, MAXPDSTRING,"btn_%d",linux_code - BTN_DIGI); else if(linux_code < KEY_OK) /* wheel buttons */ snprintf(hid_code, MAXPDSTRING,"btn_%d",linux_code - BTN_WHEEL); else return 0; } return gensym(hid_code); } /* Georg Holzmann: implementation of the keys */ /* JMZ: use t_symbol instead of char[] (s.a.) AND * appended "key_" in the array so we don't have to append it each time AND * made the table static */ t_symbol* hid_convert_linux_keys(__u16 linux_code) { if(linux_code > 226) return 0; static char key_names[227][32] = { "key_reserved", "key_esc", "key_1", "key_2", "key_3", "key_4", "key_5", "key_6", "key_7", "key_8", "key_9", "key_0", "key_minus", "key_equal", "key_backspace", "key_tab", "key_q", "key_w", "key_e", "key_r", "key_t", "key_y", "key_u", "key_i", "key_o", "key_p","key_leftbrace", "key_rightbrace", "key_enter", "key_leftctrl", "key_a","key_s", "key_d", "key_f", "key_g", "key_h", "key_j", "key_k", "key_l", "key_semicolon", "key_apostrophe", "key_grave", "key_leftshift", "key_backslash", "key_z","key_x", "key_c", "key_v", "key_b", "key_n", "key_m", "key_comma", "key_dot", "key_slash","key_rightshift", "key_kpasterisk", "key_leftalt", "key_space", "key_capslock", "key_f1", "key_f2", "key_f3", "key_f4", "key_f5", "key_f6", "key_f7", "key_f8", "key_f9", "key_f10","key_numlock", "key_scrolllock", "key_kp7", "key_kp8", "key_kp9", "key_kpminus", "key_kp4", "key_kp5", "key_kp6", "key_kpplus", "key_kp1", "key_kp2", "key_kp3", "key_kp3", "key_kpdot","key_103rd", "key_f13", "key_102nd", "key_f11", "key_f12", "key_f14", "key_f15", "key_f16", "key_f17", "key_f18", "key_f19", "key_f20", "key_kpenter", "key_rightctrl", "key_kpslash","key_sysrq", "key_rightalt", "key_linefeed", "key_home", "key_up", "key_pageup", "key_left", "key_right", "key_end", "key_down", "key_pagedown", "key_insert", "key_delete", "key_macro","key_mute", "key_volumedown", "key_volumeup", "key_power", "key_kpequal", "key_kpplusminus", "key_pause", "key_f21", "key_f22", "key_f23", "key_f24", "key_kpcomma", "key_leftmeta","key_rightmeta", "key_compose", "key_stop", "key_again", "key_props", "key_undo", "key_front", "key_copy", "key_open","key_paste", "key_find","key_cut","key_help", "key_menu", "key_calc", "key_setup", "key_sleep", "key_wakeup", "key_file", "key_sendfile", "key_deletefile","key_xfer","key_prog1", "key_prog2", "key_www","key_msdos", "key_coffee", "key_direction", "key_cyclewindows", "key_mail", "key_bookmarks","key_computer", "key_back", "key_forward", "key_colsecd", "key_ejectcd", "key_ejectclosecd","key_nextsong","key_playpause","key_previoussong", "key_stopcd", "key_record","key_rewind", "key_phone", "key_iso", "key_config", "key_homepage", "key_refresh", "key_exit","key_move", "key_edit", "key_scrollup", "key_scrolldown", "key_kpleftparen", "key_kprightparen","key_intl1", "key_intl2", "key_intl3","key_intl4", "key_intl5", "key_intl6", "key_intl7","key_intl8", "key_intl9", "key_lang1", "key_lang2", "key_lang3", "key_lang4", "key_lang5", "key_lang6", "key_lang7", "key_lang8", "key_lang9", "key_playcd", "key_pausecd", "key_prog3","key_prog4", "key_suspend", "key_close", "key_play", "key_fastforward", "key_bassboost","key_print", "key_hp", "key_camera", "key_sound", "key_question", "key_email", "key_chat", "key_search", "key_connect", "key_finance", "key_sport", "key_shop", "key_alterase","key_cancel", "key_brightnessdown", "key_brightnessup", "key_media" }; return gensym(key_names[linux_code]); // TODO: this should just return the char * } void hid_print_element_list(t_hid *x) { debug_print(LOG_DEBUG,"hid_print_element_list"); unsigned long element_bitmask[EV_MAX][NBITS(KEY_MAX)]; // char event_type_string[256]; // char event_code_string[256]; char *event_type_name = ""; t_int i, j; /* counts for various event types */ t_int syn_count,key_count,rel_count,abs_count,msc_count,led_count, snd_count,rep_count,ff_count,pwr_count,ff_status_count; /* get bitmask representing supported element (axes, keys, etc.) */ memset(element_bitmask, 0, sizeof(element_bitmask)); ioctl(x->x_fd, EVIOCGBIT(0, EV_MAX), element_bitmask[0]); post("\nSupported events:"); /* init all count vars */ syn_count = key_count = rel_count = abs_count = msc_count = led_count = 0; snd_count = rep_count = ff_count = pwr_count = ff_status_count = 0; /* cycle through all possible event types * i = i j = j */ for(i = 1; i < EV_MAX; i++) { if(test_bit(i, element_bitmask[0])) { /* make pretty names for event types */ switch(i) { // case EV_SYN: event_type_name = "Synchronization"; break; case EV_KEY: event_type_name = "Keys/Buttons"; break; case EV_REL: event_type_name = "Relative Axis"; break; case EV_ABS: event_type_name = "Absolute Axis"; break; case EV_MSC: event_type_name = "Miscellaneous"; break; case EV_LED: event_type_name = "LEDs"; break; case EV_SND: event_type_name = "System Sounds"; break; case EV_REP: event_type_name = "Autorepeat Values"; break; case EV_FF: event_type_name = "Force Feedback"; break; case EV_PWR: event_type_name = "Power"; break; case EV_FF_STATUS: event_type_name = "Force Feedback Status"; break; default: event_type_name = "UNSUPPORTED"; } /* get bitmask representing supported button types */ ioctl(x->x_fd, EVIOCGBIT(i, KEY_MAX), element_bitmask[i]); post(""); post(" TYPE\tCODE\tEVENT NAME"); post("-----------------------------------------------------------"); /* cycle through all possible event codes (axes, keys, etc.) * testing to see which are supported. * i = i j = j */ for(j = 0; j < KEY_MAX; j++) { if(test_bit(j, element_bitmask[i])) { if((i == EV_KEY) && (j >= BTN_MISC) && (j < KEY_OK) ) { t_symbol * hid_codesym = hid_convert_linux_buttons_to_numbers(j); if(hid_codesym) { post(" %s\t%s\t%s (%s)", ev[i] ? ev[i] : "?", hid_codesym->s_name, event_type_name, event_names[i] ? (event_names[i][j] ? event_names[i][j] : "?") : "?"); } } else if(i != EV_SYN) { post(" %s\t%s\t%s", ev[i] ? ev[i] : "?", event_names[i][j] ? event_names[i][j] : "?", event_type_name); /* post(" Event code %d (%s)", j, names[i] ? (names[i][j] ? names[i][j] : "?") : "?"); */ } switch(i) { /* * the API changed at some point... EV_SYN seems to be the new name * from "Reset" events to "Syncronization" events */ /* #ifdef EV_RST */ /* case EV_RST: syn_count++; break; */ /* #else */ /* case EV_SYN: syn_count++; break; */ /* #endif */ case EV_KEY: key_count++; break; case EV_REL: rel_count++; break; case EV_ABS: abs_count++; break; case EV_MSC: msc_count++; break; case EV_LED: led_count++; break; case EV_SND: snd_count++; break; case EV_REP: rep_count++; break; case EV_FF: ff_count++; break; case EV_PWR: pwr_count++; break; case EV_FF_STATUS: ff_status_count++; break; } } } } } post("\nDetected:"); // if(syn_count > 0) post (" %d Synchronization types",syn_count); if(key_count > 0) post (" %d Key/Button types",key_count); if(rel_count > 0) post (" %d Relative Axis types",rel_count); if(abs_count > 0) post (" %d Absolute Axis types",abs_count); if(msc_count > 0) post (" %d Misc types",msc_count); if(led_count > 0) post (" %d LED types",led_count); if(snd_count > 0) post (" %d System Sound types",snd_count); if(rep_count > 0) post (" %d Key Repeat types",rep_count); if(ff_count > 0) post (" %d Force Feedback types",ff_count); if(pwr_count > 0) post (" %d Power types",pwr_count); if(ff_status_count > 0) post (" %d Force Feedback types",ff_status_count); } void hid_print_device_list(void) { debug_print(LOG_DEBUG,"hid_print_device_list"); int i,fd; char device_output_string[MAXPDSTRING] = "Unknown"; char dev_handle_name[FILENAME_MAX] = "/dev/input/event0"; post(""); for(i=0;ix_fd < 0 ) return; element_count[x->x_device_number] = 0; /* get bitmask representing supported elements (axes, keys, etc.) */ memset(element_bitmask, 0, sizeof(element_bitmask)); if( ioctl(x->x_fd, EVIOCGBIT(0, EV_MAX), element_bitmask[0]) < 0 ) perror("[hid] error: evdev ioctl: element_bitmask"); memset(abs_bitmask, 0, sizeof(abs_bitmask)); if( ioctl(x->x_fd, EVIOCGBIT(EV_ABS, sizeof(abs_bitmask)), abs_bitmask) < 0 ) perror("[hid] error: evdev ioctl: abs_bitmask"); for( i = 1; i < EV_MAX; i++ ) { if(test_bit(i, element_bitmask[0])) { /* get bitmask representing supported elements */ ioctl(x->x_fd, EVIOCGBIT(i, KEY_MAX), element_bitmask[i]); /* cycle through all possible event codes (axes, keys, etc.) * testing to see which are supported. */ for(j = 0; j < KEY_MAX; j++) { if(test_bit(j, element_bitmask[i])) { new_element = getbytes(sizeof(t_hid_element)); if( (i == EV_ABS) && (j < ABS_MAX) && (test_bit(j, abs_bitmask)) ) { if(ioctl(x->x_fd, EVIOCGABS(j), &abs_features) < 0) { post("[hid]: EVIOCGABS ioctl error for element: 0x%03x", j, j); perror("[hid]: EVIOCGABS ioctl error:"); } new_element->min = abs_features.minimum; new_element->max = abs_features.maximum; } else { new_element->min = 0; new_element->max = 0; } new_element->linux_type = i; /* the int from linux/input.h */ new_element->type = gensym(ev[i] ? ev[i] : "?"); /* the symbol */ new_element->linux_code = j; if((i == EV_KEY) && (j >= BTN_MISC) && (j < KEY_OK) ) { new_element->name = hid_convert_linux_buttons_to_numbers(j); } else { new_element->name = gensym(event_names[i][j] ? event_names[i][j] : "?"); } if( i == EV_REL ) new_element->relative = 1; else new_element->relative = 0; element[x->x_device_number][element_count[x->x_device_number]] = new_element; ++element_count[x->x_device_number]; } } } } } /* ------------------------------------------------------------------------------ */ /* Pd [hid] FUNCTIONS */ /* ------------------------------------------------------------------------------ */ void hid_get_events(t_hid *x) { /* for debugging, counts how many events are processed each time hid_read() is called */ DEBUG(t_int event_counter = 0;); unsigned short i; t_hid_element *output_element = NULL; /* this will go into the generic read function declared in hid.h and * implemented in hid_linux.c */ struct input_event hid_input_event; if(x->x_fd < 0) return; while( read (x->x_fd, &(hid_input_event), sizeof(struct input_event)) > -1 ) { if( hid_input_event.type != EV_SYN ) { for( i=0; i < element_count[x->x_device_number]; ++i ) { output_element = element[x->x_device_number][i]; if( (hid_input_event.type == output_element->linux_type) && \ (hid_input_event.code == output_element->linux_code) ) { output_element->value = hid_input_event.value; debug_print(9,"i: %d linux_type: %d linux_code: %d", i, output_element->linux_type, output_element->linux_code); debug_print(9,"value to output: %d",output_element->value); break; } } if( output_element != NULL ) hid_output_event(x, output_element); } DEBUG(++event_counter;); } DEBUG( if(event_counter > 0) debug_print(8,"output %d events",event_counter); ); return; } void hid_print(t_hid* x) { hid_print_device_list(); hid_print_element_list(x); } t_int hid_open_device(t_hid *x, short device_number) { debug_print(LOG_DEBUG,"hid_open_device"); char device_name[MAXPDSTRING] = "Unknown"; char block_device[FILENAME_MAX] = "/dev/input/event0"; struct input_event hid_input_event; x->x_fd = -1; x->x_device_number = device_number; snprintf(block_device,FILENAME_MAX,"/dev/input/event%d",x->x_device_number); /* open the device read-only, non-exclusive */ x->x_fd = open(block_device, O_RDONLY | O_NONBLOCK); /* test if device open */ if(x->x_fd < 0 ) { error("[hid] open %s failed",block_device); x->x_fd = -1; return 1; } /* read input_events from the HID_DEVICE stream * It seems that is just there to flush the input event queue */ while (read (x->x_fd, &(hid_input_event), sizeof(struct input_event)) > -1); /* get name of device */ ioctl(x->x_fd, EVIOCGNAME(sizeof(device_name)), device_name); post ("[hid] opened device %d (%s): %s", x->x_device_number,block_device,device_name); hid_build_element_list(x); return (0); } /* * Under GNU/Linux, the device is a filehandle */ t_int hid_close_device(t_hid *x) { debug_print(LOG_DEBUG,"hid_close_device"); if(x->x_fd <0) return 0; else return (close(x->x_fd)); } void hid_build_device_list(void) { /* * since in GNU/Linux the device list is the input event devices * (/dev/input/event?), nothing needs to be done as of yet to refresh * the device list. Once the device name can be other things in addition * the current t_float, then this will probably need to be changed. */ int fd; unsigned int i; unsigned int last_active_device = 0; char device_name[MAXPDSTRING] = "Unknown"; char block_device[FILENAME_MAX] = "/dev/input/event0"; struct input_event x_input_event; debug_print(LOG_DEBUG,"hid_build_device_list"); debug_print(LOG_WARNING,"[hid] Building device list..."); for(i=0; i -1); /* get name of device */ ioctl(fd, EVIOCGNAME(sizeof(device_name)), device_name); post("Found '%s' on '%s'",device_name, &block_device); close (fd); } last_active_device = i; } device_count = last_active_device ; // set the global variable debug_print(LOG_WARNING,"[hid] completed device list."); } void hid_platform_specific_free(t_hid *x) { /* nothing to be done here on GNU/Linux */ } /* device info on the status outlet */ void hid_platform_specific_info(t_hid* x) { struct input_id my_id; char device_name[MAXPDSTRING] = "Unknown"; char vendor_id_string[7]; char product_id_string[7]; t_atom *output_atom = getbytes(sizeof(t_atom)); ioctl(x->x_fd, EVIOCGID, &my_id); snprintf(vendor_id_string,7,"0x%04x", my_id.vendor); SETSYMBOL(output_atom, gensym(vendor_id_string)); outlet_anything( x->x_status_outlet, gensym("vendorID"), 1, output_atom); snprintf(product_id_string,7,"0x%04x", my_id.product); SETSYMBOL(output_atom, gensym(product_id_string)); outlet_anything( x->x_status_outlet, gensym("productID"), 1, output_atom); ioctl(x->x_fd, EVIOCGNAME(sizeof(device_name)), device_name); SETSYMBOL(output_atom, gensym(device_name)); outlet_anything( x->x_status_outlet, gensym("name"), 1, output_atom); freebytes(output_atom,sizeof(t_atom)); } short get_device_number_by_id(unsigned short vendor_id, unsigned short product_id) { int i, fd; char dev_handle_name[FILENAME_MAX]; struct input_id my_id; for(i=0;i -1 ) { ioctl(fd, EVIOCGID, &my_id); if( (vendor_id == my_id.vendor) && (product_id == my_id.product) ) return i; } } return -1; } short get_device_number_from_usage(short device_number, unsigned short usage_page, unsigned short usage) { return -1; } /* ------------------------------------------------------------------------------ */ /* FORCE FEEDBACK FUNCTIONS */ /* ------------------------------------------------------------------------------ */ /* cross-platform force feedback functions */ t_int hid_ff_autocenter( t_hid *x, t_float value ) { return ( 0 ); } t_int hid_ff_gain( t_hid *x, t_float value ) { return ( 0 ); } t_int hid_ff_motors( t_hid *x, t_float value ) { return ( 0 ); } t_int hid_ff_continue( t_hid *x ) { return ( 0 ); } t_int hid_ff_pause( t_hid *x ) { return ( 0 ); } t_int hid_ff_reset( t_hid *x ) { return ( 0 ); } t_int hid_ff_stopall( t_hid *x ) { return ( 0 ); } // these are just for testing... t_int hid_ff_fftest ( t_hid *x, t_float value) { return ( 0 ); } void hid_ff_print( t_hid *x ) { } #endif /* #ifdef __linux__ */ pd-hid_0.7/hid_smooth.pd0000644000076500007650000000024511504504627013754 0ustar hanshans#N canvas 346 512 462 312 10; #X obj 67 31 inlet; #X obj 67 256 outlet; #X text 9 9 [hid_smooth]; #X obj 67 149 hid_average; #X connect 0 0 3 0; #X connect 3 0 1 0; pd-hid_0.7/notescale-help.pd0000644000076500007650000000367711504504627014536 0ustar hanshans#N canvas 0 31 464 467 10; #X floatatom 26 85 5 0 0 0 - - -; #X floatatom 26 160 0 0 0 0 - - -; #X obj 2 2 cnv 15 450 20 empty empty notescale 2 11 1 18 -233017 -66577 0; #X obj 418 3 pddp/pddplink http://puredata.info/dev/pddp -text pddp ; #X floatatom 137 266 5 0 0 0 - - -; #X obj 140 330 hsl 128 15 0 127 0 0 empty empty empty -2 -6 0 8 -262144 -1 -1 0 1; #X text 17 393 (C) Copyright 2004 Hans-Christoph Steiner ; #X text 234 407 released under the GNU GPL; #X floatatom 150 160 0 0 0 0 - - -; #X floatatom 297 160 0 0 0 0 - - -; #X obj 213 83 hsl 128 15 0 1 0 0 empty empty empty -2 -6 0 8 -225271 -1 -1 0 0; #X text 17 426 $Revision: 1.3 $$Date: 2006-03-17 04:58:30 $; #X text 18 439 $Author: eighthave $; #X obj 140 244 hsl 128 15 0 1 0 0 empty empty empty -2 -6 0 8 -262131 -1 -1 0 0; #X obj 26 130 notescale 30 60; #X floatatom 137 347 5 0 0 0 - - -; #X text 13 193 If you use [notescale] with no arguments \, then the output range defaults to 0-127.; #X floatatom 202 109 5 0 0 0 - - -; #X obj 26 105 / 100; #X text 18 35 [notescale] scales a stream of numbers to a MIDI note number. It takes an input range of 0 to 1 \, and outputs MIDI note numbers based on an output range set as arguments.; #X obj 137 297 notescale; #X obj 150 130 notescale 15 120; #X obj 297 130 notescale 24 48; #N canvas 474 31 494 344 META 0; #X text 12 125 HELP_PATCH_AUTHORS "pd meta" information added by Jonathan Wilkes for Pd version 0.42.; #X text 12 25 LICENSE GPL; #X text 12 105 AUTHOR Hans-Christoph Steiner; #X text 12 45 DESCRIPTION scale a stream of numbers to a MIDI note number; #X text 12 65 INLET_0 float; #X text 12 85 OUTLET_0 float; #X text 12 5 KEYWORDS control abstraction; #X restore 406 435 pd META; #X connect 0 0 18 0; #X connect 4 0 20 0; #X connect 5 0 15 0; #X connect 10 0 17 0; #X connect 10 0 21 0; #X connect 10 0 22 0; #X connect 13 0 4 0; #X connect 14 0 1 0; #X connect 18 0 14 0; #X connect 20 0 5 0; #X connect 21 0 8 0; #X connect 22 0 9 0; pd-hid_0.7/joystick.pd0000644000076500007650000000452511504504627013463 0ustar hanshans#N canvas 123 51 723 589 10; #X obj 157 30 inlet; #X obj 287 160 print UNKNOWN_JOYSTICK_EVENT_TYPE; #X obj 118 508 outlet; #X obj 380 342 outlet; #X obj 446 317 outlet; #X text 132 244 codes (0=X 1=Y 6=throttle 7=rudder \, 16=hat0X \, 17=hat0Y) ; #X obj 625 262 outlet; #X obj 157 107 hid \$1; #X obj 183 468 outlet; #X obj 249 428 outlet; #X obj 315 387 outlet; #X text 574 280 button code/value list; #X text 171 509 X-axis; #X text 232 468 Y-axis; #X text 302 430 twist; #X text 11 552 (C) Copyright 2004 Hans-Christoph Steiner ; #X text 228 566 released under the GNU GPL; #X text 424 566 $Author: eighthave $; #X text 424 553 $Revision: 1.6 $$Date: 2005-06-04 15:51:39 $; #X text 367 388 throttle/slider; #X text 426 343 hat0x; #X text 496 319 hat0y; #X obj 315 368 mapping/autoscale 0 1; #X obj 249 409 mapping/autoscale 0 1; #X obj 183 449 mapping/autoscale 0 1; #X obj 118 489 mapping/autoscale 0 1; #X text 8 6 [joystick]; #X obj 159 139 route abs key ff; #X msg 23 300 reset; #N canvas 657 99 454 304 reset_on_open 0; #X obj 37 19 inlet; #X obj 37 226 outlet; #X obj 37 116 select open; #X obj 37 196 spigot 0; #X obj 37 64 unpack symbol float; #X obj 165 85 t f b; #X obj 165 148 !=; #X obj 181 126 f -1; #X text 9 256 This object sends a bang to the outlet when getting an [open( message that opens a new device but not when opening the existing device.; #X connect 0 0 4 0; #X connect 2 0 3 0; #X connect 3 0 1 0; #X connect 4 0 2 0; #X connect 4 1 5 0; #X connect 5 0 6 0; #X connect 5 0 7 1; #X connect 5 1 7 0; #X connect 6 0 3 1; #X connect 7 0 6 1; #X restore 23 110 pd reset_on_open; #X obj 118 264 route abs_x abs_y abs_rz abs_throttle abs_hat0x abs_hat0y ; #X obj 26 78 route float; #X obj 256 34 loadbang; #X obj 256 58 float \$1; #X msg 224 84 open joystick \$1; #X obj 156 58 route open; #X connect 0 0 31 0; #X connect 0 0 35 0; #X connect 7 0 27 0; #X connect 22 0 10 0; #X connect 23 0 9 0; #X connect 24 0 8 0; #X connect 25 0 2 0; #X connect 27 0 30 0; #X connect 27 1 6 0; #X connect 28 0 25 0; #X connect 28 0 24 0; #X connect 28 0 23 0; #X connect 28 0 22 0; #X connect 29 0 28 0; #X connect 30 0 25 0; #X connect 30 1 24 0; #X connect 30 2 23 0; #X connect 30 3 22 0; #X connect 30 4 3 0; #X connect 30 5 4 0; #X connect 31 1 29 0; #X connect 32 0 33 0; #X connect 33 0 34 0; #X connect 34 0 7 0; #X connect 35 0 34 0; #X connect 35 1 7 0; pd-hid_0.7/hid_spiral.pd0000644000076500007650000000247511504504627013744 0ustar hanshans#N canvas 492 167 669 441 10; #X obj 30 58 inlet; #X obj 25 363 outlet; #X text 73 363 output range: 0 to 1; #X text 72 57 input range: 0 to 1; #X obj 232 362 outlet; #X obj 222 58 inlet; #X text 264 57 input range: 0 to 1; #X text 29 29 x-axis value; #X text 221 26 y-axis value; #X text 11 5 [hid_spiral]; #X text 254 411 released under the GNU GPL; #X text 40 396 (C) Copyright 2005 Hans-Christoph Steiner ; #X obj 268 258 +; #X obj 299 258 f; #X msg 219 227 1; #X msg 315 227 -1; #X obj 232 327 +; #X obj 164 140 t f f; #X obj 194 161 delta; #X obj 105 109 hid_polar; #X obj 269 291 * 1; #X obj 221 185 moses -0.4; #X obj 271 205 moses 0.4; #X text 260 110 changes over 0.4 mean one rotation. I can't move fast enough on my joystick to get near a change of 0.4 This might not work on other devices \, like tablets \, but we'll cross that bridge when we get to it (i.e. when I get a tablet); #X text 280 362 output range: infinite \, one rotation = 1; #X connect 0 0 19 0; #X connect 5 0 19 1; #X connect 12 0 13 0; #X connect 12 0 20 0; #X connect 13 0 12 1; #X connect 14 0 12 0; #X connect 15 0 12 0; #X connect 16 0 4 0; #X connect 17 0 16 0; #X connect 17 1 18 0; #X connect 18 0 21 0; #X connect 19 0 1 0; #X connect 19 1 17 0; #X connect 20 0 16 1; #X connect 21 0 14 0; #X connect 21 1 22 0; #X connect 22 1 15 0; pd-hid_0.7/input_arrays.c0000644000076500007650000005275411504504627014172 0ustar hanshans#include "hid.h" int ev_total = 32; /* # of elements in array */ char *ev[32] = { "syn","key","rel","abs","msc","ev_5", "ev_6","ev_7","ev_8","ev_9","ev_10","ev_11", "ev_12","ev_13","ev_14","ev_15","ev_16","led", "snd","ev_19","rep","ff","pwr","ff_status", "ev_24","ev_25","ev_26","ev_27","ev_28","ev_29", "ev_30","ev_31" }; int ev_syn_total = 512; /* # of elements in array */ char *ev_syn[512] = { "syn_report","syn_config","syn_2","syn_3","syn_4","syn_5", "syn_6","syn_7","syn_8","syn_9","syn_10","syn_11", "syn_12","syn_13","syn_14","syn_15","syn_16","syn_17", "syn_18","syn_19","syn_20","syn_21","syn_22","syn_23", "syn_24","syn_25","syn_26","syn_27","syn_28","syn_29", "syn_30","syn_31","syn_32","syn_33","syn_34","syn_35", "syn_36","syn_37","syn_38","syn_39","syn_40","syn_41", "syn_42","syn_43","syn_44","syn_45","syn_46","syn_47", "syn_48","syn_49","syn_50","syn_51","syn_52","syn_53", "syn_54","syn_55","syn_56","syn_57","syn_58","syn_59", "syn_60","syn_61","syn_62","syn_63","syn_64","syn_65", "syn_66","syn_67","syn_68","syn_69","syn_70","syn_71", "syn_72","syn_73","syn_74","syn_75","syn_76","syn_77", "syn_78","syn_79","syn_80","syn_81","syn_82","syn_83", "syn_84","syn_85","syn_86","syn_87","syn_88","syn_89", "syn_90","syn_91","syn_92","syn_93","syn_94","syn_95", "syn_96","syn_97","syn_98","syn_99","syn_100","syn_101", "syn_102","syn_103","syn_104","syn_105","syn_106","syn_107", "syn_108","syn_109","syn_110","syn_111","syn_112","syn_113", "syn_114","syn_115","syn_116","syn_117","syn_118","syn_119", "syn_120","syn_121","syn_122","syn_123","syn_124","syn_125", "syn_126","syn_127","syn_128","syn_129","syn_130","syn_131", "syn_132","syn_133","syn_134","syn_135","syn_136","syn_137", "syn_138","syn_139","syn_140","syn_141","syn_142","syn_143", "syn_144","syn_145","syn_146","syn_147","syn_148","syn_149", "syn_150","syn_151","syn_152","syn_153","syn_154","syn_155", "syn_156","syn_157","syn_158","syn_159","syn_160","syn_161", "syn_162","syn_163","syn_164","syn_165","syn_166","syn_167", "syn_168","syn_169","syn_170","syn_171","syn_172","syn_173", "syn_174","syn_175","syn_176","syn_177","syn_178","syn_179", "syn_180","syn_181","syn_182","syn_183","syn_184","syn_185", "syn_186","syn_187","syn_188","syn_189","syn_190","syn_191", "syn_192","syn_193","syn_194","syn_195","syn_196","syn_197", "syn_198","syn_199","syn_200","syn_201","syn_202","syn_203", "syn_204","syn_205","syn_206","syn_207","syn_208","syn_209", "syn_210","syn_211","syn_212","syn_213","syn_214","syn_215", "syn_216","syn_217","syn_218","syn_219","syn_220","syn_221", "syn_222","syn_223","syn_224","syn_225","syn_226","syn_227", "syn_228","syn_229","syn_230","syn_231","syn_232","syn_233", "syn_234","syn_235","syn_236","syn_237","syn_238","syn_239", "syn_240","syn_241","syn_242","syn_243","syn_244","syn_245", "syn_246","syn_247","syn_248","syn_249","syn_250","syn_251", "syn_252","syn_253","syn_254","syn_255","syn_256","syn_257", "syn_258","syn_259","syn_260","syn_261","syn_262","syn_263", "syn_264","syn_265","syn_266","syn_267","syn_268","syn_269", "syn_270","syn_271","syn_272","syn_273","syn_274","syn_275", "syn_276","syn_277","syn_278","syn_279","syn_280","syn_281", "syn_282","syn_283","syn_284","syn_285","syn_286","syn_287", "syn_288","syn_289","syn_290","syn_291","syn_292","syn_293", "syn_294","syn_295","syn_296","syn_297","syn_298","syn_299", "syn_300","syn_301","syn_302","syn_303","syn_304","syn_305", "syn_306","syn_307","syn_308","syn_309","syn_310","syn_311", "syn_312","syn_313","syn_314","syn_315","syn_316","syn_317", "syn_318","syn_319","syn_320","syn_321","syn_322","syn_323", "syn_324","syn_325","syn_326","syn_327","syn_328","syn_329", "syn_330","syn_331","syn_332","syn_333","syn_334","syn_335", "syn_336","syn_337","syn_338","syn_339","syn_340","syn_341", "syn_342","syn_343","syn_344","syn_345","syn_346","syn_347", "syn_348","syn_349","syn_350","syn_351","syn_352","syn_353", "syn_354","syn_355","syn_356","syn_357","syn_358","syn_359", "syn_360","syn_361","syn_362","syn_363","syn_364","syn_365", "syn_366","syn_367","syn_368","syn_369","syn_370","syn_371", "syn_372","syn_373","syn_374","syn_375","syn_376","syn_377", "syn_378","syn_379","syn_380","syn_381","syn_382","syn_383", "syn_384","syn_385","syn_386","syn_387","syn_388","syn_389", "syn_390","syn_391","syn_392","syn_393","syn_394","syn_395", "syn_396","syn_397","syn_398","syn_399","syn_400","syn_401", "syn_402","syn_403","syn_404","syn_405","syn_406","syn_407", "syn_408","syn_409","syn_410","syn_411","syn_412","syn_413", "syn_414","syn_415","syn_416","syn_417","syn_418","syn_419", "syn_420","syn_421","syn_422","syn_423","syn_424","syn_425", "syn_426","syn_427","syn_428","syn_429","syn_430","syn_431", "syn_432","syn_433","syn_434","syn_435","syn_436","syn_437", "syn_438","syn_439","syn_440","syn_441","syn_442","syn_443", "syn_444","syn_445","syn_446","syn_447","syn_448","syn_449", "syn_450","syn_451","syn_452","syn_453","syn_454","syn_455", "syn_456","syn_457","syn_458","syn_459","syn_460","syn_461", "syn_462","syn_463","syn_464","syn_465","syn_466","syn_467", "syn_468","syn_469","syn_470","syn_471","syn_472","syn_473", "syn_474","syn_475","syn_476","syn_477","syn_478","syn_479", "syn_480","syn_481","syn_482","syn_483","syn_484","syn_485", "syn_486","syn_487","syn_488","syn_489","syn_490","syn_491", "syn_492","syn_493","syn_494","syn_495","syn_496","syn_497", "syn_498","syn_499","syn_500","syn_501","syn_502","syn_503", "syn_504","syn_505","syn_506","syn_507","syn_508","syn_509", "syn_510","syn_511" }; int ev_key_total = 512; /* # of elements in array */ char *ev_key[512] = { "key_reserved","key_esc","key_1","key_2","key_3","key_4", "key_5","key_6","key_7","key_8","key_9","key_0", "key_minus","key_equal","key_backspace","key_tab","key_q","key_w", "key_e","key_r","key_t","key_y","key_u","key_i", "key_o","key_p","key_leftbrace","key_rightbrace","key_enter","key_leftctrl", "key_a","key_s","key_d","key_f","key_g","key_h", "key_j","key_k","key_l","key_semicolon","key_apostrophe","key_grave", "key_leftshift","key_backslash","key_z","key_x","key_c","key_v", "key_b","key_n","key_m","key_comma","key_dot","key_slash", "key_rightshift","key_kpasterisk","key_leftalt","key_space","key_capslock","key_f1", "key_f2","key_f3","key_f4","key_f5","key_f6","key_f7", "key_f8","key_f9","key_f10","key_numlock","key_scrolllock","key_kp7", "key_kp8","key_kp9","key_kpminus","key_kp4","key_kp5","key_kp6", "key_kpplus","key_kp1","key_kp2","key_kp3","key_kp0","key_kpdot", "key_84","key_zenkakuhankaku","key_102nd","key_f11","key_f12","key_ro", "key_katakana","key_hiragana","key_henkan","key_katakanahiragana","key_muhenkan","key_kpjpcomma", "key_kpenter","key_rightctrl","key_kpslash","key_sysrq","key_rightalt","key_linefeed", "key_home","key_up","key_pageup","key_left","key_right","key_end", "key_down","key_pagedown","key_insert","key_delete","key_macro","key_mute", "key_volumedown","key_volumeup","key_power","key_kpequal","key_kpplusminus","key_pause", "key_120","key_kpcomma","key_hanguel","key_hanja","key_yen","key_leftmeta", "key_rightmeta","key_compose","key_stop","key_again","key_props","key_undo", "key_front","key_copy","key_open","key_paste","key_find","key_cut", "key_help","key_menu","key_calc","key_setup","key_sleep","key_wakeup", "key_file","key_sendfile","key_deletefile","key_xfer","key_prog1","key_prog2", "key_www","key_msdos","key_coffee","key_direction","key_cyclewindows","key_mail", "key_bookmarks","key_computer","key_back","key_forward","key_closecd","key_ejectcd", "key_ejectclosecd","key_nextsong","key_playpause","key_previoussong","key_stopcd","key_record", "key_rewind","key_phone","key_iso","key_config","key_homepage","key_refresh", "key_exit","key_move","key_edit","key_scrollup","key_scrolldown","key_kpleftparen", "key_kprightparen","key_181","key_182","key_f13","key_f14","key_f15", "key_f16","key_f17","key_f18","key_f19","key_f20","key_f21", "key_f22","key_f23","key_f24","key_195","key_196","key_197", "key_198","key_199","key_playcd","key_pausecd","key_prog3","key_prog4", "key_204","key_suspend","key_close","key_play","key_fastforward","key_bassboost", "key_print","key_hp","key_camera","key_sound","key_question","key_email", "key_chat","key_search","key_connect","key_finance","key_sport","key_shop", "key_alterase","key_cancel","key_brightnessdown","key_brightnessup","key_media","key_227", "key_228","key_229","key_230","key_231","key_232","key_233", "key_234","key_235","key_236","key_237","key_238","key_239", "key_unknown","key_241","key_242","key_243","key_244","key_245", "key_246","key_247","key_248","key_249","key_250","key_251", "key_252","key_253","key_254","key_255","btn_0","btn_1", "btn_2","btn_3","btn_4","btn_5","btn_6","btn_7", "btn_8","btn_9","key_266","key_267","key_268","key_269", "key_270","key_271","btn_left","btn_right","btn_middle","btn_side", "btn_extra","btn_forward","btn_back","btn_task","key_280","key_281", "key_282","key_283","key_284","key_285","key_286","key_287", "btn_trigger","btn_thumb","btn_thumb2","btn_top","btn_top2","btn_pinkie", "btn_base","btn_base2","btn_base3","btn_base4","btn_base5","btn_base6", "key_300","key_301","key_302","btn_dead","btn_a","btn_b", "btn_c","btn_x","btn_y","btn_z","btn_tl","btn_tr", "btn_tl2","btn_tr2","btn_select","btn_start","btn_mode","btn_thumbl", "btn_thumbr","key_319","btn_tool_pen","btn_tool_rubber","btn_tool_brush","btn_tool_pencil", "btn_tool_airbrush","btn_tool_finger","btn_tool_mouse","btn_tool_lens","key_328","key_329", "btn_touch","btn_stylus","btn_stylus2","btn_tool_doubletap","btn_tool_tripletap","key_335", "btn_gear_down","btn_gear_up","key_338","key_339","key_340","key_341", "key_342","key_343","key_344","key_345","key_346","key_347", "key_348","key_349","key_350","key_351","key_ok","key_select", "key_goto","key_clear","key_power2","key_option","key_info","key_time", "key_vendor","key_archive","key_program","key_channel","key_favorites","key_epg", "key_pvr","key_mhp","key_language","key_title","key_subtitle","key_angle", "key_zoom","key_mode","key_keyboard","key_screen","key_pc","key_tv", "key_tv2","key_vcr","key_vcr2","key_sat","key_sat2","key_cd", "key_tape","key_radio","key_tuner","key_player","key_text","key_dvd", "key_aux","key_mp3","key_audio","key_video","key_directory","key_list", "key_memo","key_calendar","key_red","key_green","key_yellow","key_blue", "key_channelup","key_channeldown","key_first","key_last","key_ab","key_next", "key_restart","key_slow","key_shuffle","key_break","key_previous","key_digits", "key_teen","key_twen","key_416","key_417","key_418","key_419", "key_420","key_421","key_422","key_423","key_424","key_425", "key_426","key_427","key_428","key_429","key_430","key_431", "key_432","key_433","key_434","key_435","key_436","key_437", "key_438","key_439","key_440","key_441","key_442","key_443", "key_444","key_445","key_446","key_447","key_del_eol","key_del_eos", "key_ins_line","key_del_line","key_452","key_453","key_454","key_455", "key_456","key_457","key_458","key_459","key_460","key_461", "key_462","key_463","key_fn","key_fn_esc","key_fn_f1","key_fn_f2", "key_fn_f3","key_fn_f4","key_fn_f5","key_fn_f6","key_fn_f7","key_fn_f8", "key_fn_f9","key_fn_f10","key_fn_f11","key_fn_f12","key_fn_1","key_fn_2", "key_fn_d","key_fn_e","key_fn_f","key_fn_s","key_fn_b","key_485", "key_486","key_487","key_488","key_489","key_490","key_491", "key_492","key_493","key_494","key_495","key_496","key_497", "key_498","key_499","key_500","key_501","key_502","key_503", "key_504","key_505","key_506","key_507","key_508","key_509", "key_510","key_511" }; int ev_rel_total = 16; /* # of elements in array */ char *ev_rel[16] = { "rel_x","rel_y","rel_z","rel_rx","rel_ry","rel_rz", "rel_hwheel","rel_dial","rel_wheel","rel_misc","rel_10","rel_11", "rel_12","rel_13","rel_14","rel_15" }; int ev_abs_total = 64; /* # of elements in array */ char *ev_abs[64] = { "abs_x","abs_y","abs_z","abs_rx","abs_ry","abs_rz", "abs_throttle","abs_rudder","abs_wheel","abs_gas","abs_brake","abs_11", "abs_12","abs_13","abs_14","abs_15","abs_hat0x","abs_hat0y", "abs_hat1x","abs_hat1y","abs_hat2x","abs_hat2y","abs_hat3x","abs_hat3y", "abs_pressure","abs_distance","abs_tilt_x","abs_tilt_y","abs_tool_width","abs_29", "abs_30","abs_31","abs_volume","abs_33","abs_34","abs_35", "abs_36","abs_37","abs_38","abs_39","abs_misc","abs_41", "abs_42","abs_43","abs_44","abs_45","abs_46","abs_47", "abs_48","abs_49","abs_50","abs_51","abs_52","abs_53", "abs_54","abs_55","abs_56","abs_57","abs_58","abs_59", "abs_60","abs_61","abs_62","abs_63" }; int ev_msc_total = 8; /* # of elements in array */ char *ev_msc[8] = { "msc_serial","msc_pulseled","msc_gesture","msc_raw","msc_scan","msc_5", "msc_6","msc_7" }; int ev_led_total = 16; /* # of elements in array */ char *ev_led[16] = { "led_numl","led_capsl","led_scrolll","led_compose","led_kana","led_sleep", "led_suspend","led_mute","led_misc","led_mail","led_charging","led_11", "led_12","led_13","led_14","led_15" }; int ev_snd_total = 8; /* # of elements in array */ char *ev_snd[8] = { "snd_click","snd_bell","snd_tone","snd_3","snd_4","snd_5", "snd_6","snd_7" }; int ev_rep_total = 2; /* # of elements in array */ char *ev_rep[2] = { "rep_delay","rep_period" }; int ev_ff_total = 128; /* # of elements in array */ char *ev_ff[128] = { "ff_0","ff_1","ff_2","ff_3","ff_4","ff_5", "ff_6","ff_7","ff_8","ff_9","ff_10","ff_11", "ff_12","ff_13","ff_14","ff_15","ff_16","ff_17", "ff_18","ff_19","ff_20","ff_21","ff_22","ff_23", "ff_24","ff_25","ff_26","ff_27","ff_28","ff_29", "ff_30","ff_31","ff_32","ff_33","ff_34","ff_35", "ff_36","ff_37","ff_38","ff_39","ff_40","ff_41", "ff_42","ff_43","ff_44","ff_45","ff_46","ff_47", "ff_48","ff_49","ff_50","ff_51","ff_52","ff_53", "ff_54","ff_55","ff_56","ff_57","ff_58","ff_59", "ff_60","ff_61","ff_62","ff_63","ff_64","ff_65", "ff_66","ff_67","ff_68","ff_69","ff_70","ff_71", "ff_72","ff_73","ff_74","ff_75","ff_76","ff_77", "ff_78","ff_79","ff_rumble","ff_periodic","ff_constant","ff_spring", "ff_friction","ff_damper","ff_inertia","ff_ramp","ff_square","ff_triangle", "ff_sine","ff_saw_up","ff_saw_down","ff_custom","ff_94","ff_95", "ff_gain","ff_autocenter","ff_98","ff_99","ff_100","ff_101", "ff_102","ff_103","ff_104","ff_105","ff_106","ff_107", "ff_108","ff_109","ff_110","ff_111","ff_112","ff_113", "ff_114","ff_115","ff_116","ff_117","ff_118","ff_119", "ff_120","ff_121","ff_122","ff_123","ff_124","ff_125", "ff_126","ff_127" }; char *ev_pwr[1] = { NULL }; int ev_ff_status_total = 2; /* # of elements in array */ char *ev_ff_status[2] = { "ff_status_stopped","ff_status_playing" }; int ev_5_total = 16; /* # of elements in array */ char *ev_5[16] = { "ev_5_1","ev_5_2","ev_5_3","ev_5_4","ev_5_5","ev_5_6", "ev_5_7","ev_5_8","ev_5_9","ev_5_10","ev_5_11","ev_5_12", "ev_5_13","ev_5_14","ev_5_15","ev_5_16" }; int ev_6_total = 16; /* # of elements in array */ char *ev_6[16] = { "ev_6_1","ev_6_2","ev_6_3","ev_6_4","ev_6_5","ev_6_6", "ev_6_7","ev_6_8","ev_6_9","ev_6_10","ev_6_11","ev_6_12", "ev_6_13","ev_6_14","ev_6_15","ev_6_16" }; int ev_7_total = 16; /* # of elements in array */ char *ev_7[16] = { "ev_7_1","ev_7_2","ev_7_3","ev_7_4","ev_7_5","ev_7_6", "ev_7_7","ev_7_8","ev_7_9","ev_7_10","ev_7_11","ev_7_12", "ev_7_13","ev_7_14","ev_7_15","ev_7_16" }; int ev_8_total = 16; /* # of elements in array */ char *ev_8[16] = { "ev_8_1","ev_8_2","ev_8_3","ev_8_4","ev_8_5","ev_8_6", "ev_8_7","ev_8_8","ev_8_9","ev_8_10","ev_8_11","ev_8_12", "ev_8_13","ev_8_14","ev_8_15","ev_8_16" }; int ev_9_total = 16; /* # of elements in array */ char *ev_9[16] = { "ev_9_1","ev_9_2","ev_9_3","ev_9_4","ev_9_5","ev_9_6", "ev_9_7","ev_9_8","ev_9_9","ev_9_10","ev_9_11","ev_9_12", "ev_9_13","ev_9_14","ev_9_15","ev_9_16" }; int ev_10_total = 16; /* # of elements in array */ char *ev_10[16] = { "ev_10_1","ev_10_2","ev_10_3","ev_10_4","ev_10_5","ev_10_6", "ev_10_7","ev_10_8","ev_10_9","ev_10_10","ev_10_11","ev_10_12", "ev_10_13","ev_10_14","ev_10_15","ev_10_16" }; int ev_11_total = 16; /* # of elements in array */ char *ev_11[16] = { "ev_11_1","ev_11_2","ev_11_3","ev_11_4","ev_11_5","ev_11_6", "ev_11_7","ev_11_8","ev_11_9","ev_11_10","ev_11_11","ev_11_12", "ev_11_13","ev_11_14","ev_11_15","ev_11_16" }; int ev_12_total = 16; /* # of elements in array */ char *ev_12[16] = { "ev_12_1","ev_12_2","ev_12_3","ev_12_4","ev_12_5","ev_12_6", "ev_12_7","ev_12_8","ev_12_9","ev_12_10","ev_12_11","ev_12_12", "ev_12_13","ev_12_14","ev_12_15","ev_12_16" }; int ev_13_total = 16; /* # of elements in array */ char *ev_13[16] = { "ev_13_1","ev_13_2","ev_13_3","ev_13_4","ev_13_5","ev_13_6", "ev_13_7","ev_13_8","ev_13_9","ev_13_10","ev_13_11","ev_13_12", "ev_13_13","ev_13_14","ev_13_15","ev_13_16" }; int ev_14_total = 16; /* # of elements in array */ char *ev_14[16] = { "ev_14_1","ev_14_2","ev_14_3","ev_14_4","ev_14_5","ev_14_6", "ev_14_7","ev_14_8","ev_14_9","ev_14_10","ev_14_11","ev_14_12", "ev_14_13","ev_14_14","ev_14_15","ev_14_16" }; int ev_15_total = 16; /* # of elements in array */ char *ev_15[16] = { "ev_15_1","ev_15_2","ev_15_3","ev_15_4","ev_15_5","ev_15_6", "ev_15_7","ev_15_8","ev_15_9","ev_15_10","ev_15_11","ev_15_12", "ev_15_13","ev_15_14","ev_15_15","ev_15_16" }; int ev_16_total = 16; /* # of elements in array */ char *ev_16[16] = { "ev_16_1","ev_16_2","ev_16_3","ev_16_4","ev_16_5","ev_16_6", "ev_16_7","ev_16_8","ev_16_9","ev_16_10","ev_16_11","ev_16_12", "ev_16_13","ev_16_14","ev_16_15","ev_16_16" }; int ev_19_total = 16; /* # of elements in array */ char *ev_19[16] = { "ev_19_1","ev_19_2","ev_19_3","ev_19_4","ev_19_5","ev_19_6", "ev_19_7","ev_19_8","ev_19_9","ev_19_10","ev_19_11","ev_19_12", "ev_19_13","ev_19_14","ev_19_15","ev_19_16" }; int ev_24_total = 16; /* # of elements in array */ char *ev_24[16] = { "ev_24_1","ev_24_2","ev_24_3","ev_24_4","ev_24_5","ev_24_6", "ev_24_7","ev_24_8","ev_24_9","ev_24_10","ev_24_11","ev_24_12", "ev_24_13","ev_24_14","ev_24_15","ev_24_16" }; int ev_25_total = 16; /* # of elements in array */ char *ev_25[16] = { "ev_25_1","ev_25_2","ev_25_3","ev_25_4","ev_25_5","ev_25_6", "ev_25_7","ev_25_8","ev_25_9","ev_25_10","ev_25_11","ev_25_12", "ev_25_13","ev_25_14","ev_25_15","ev_25_16" }; int ev_26_total = 16; /* # of elements in array */ char *ev_26[16] = { "ev_26_1","ev_26_2","ev_26_3","ev_26_4","ev_26_5","ev_26_6", "ev_26_7","ev_26_8","ev_26_9","ev_26_10","ev_26_11","ev_26_12", "ev_26_13","ev_26_14","ev_26_15","ev_26_16" }; int ev_27_total = 16; /* # of elements in array */ char *ev_27[16] = { "ev_27_1","ev_27_2","ev_27_3","ev_27_4","ev_27_5","ev_27_6", "ev_27_7","ev_27_8","ev_27_9","ev_27_10","ev_27_11","ev_27_12", "ev_27_13","ev_27_14","ev_27_15","ev_27_16" }; int ev_28_total = 16; /* # of elements in array */ char *ev_28[16] = { "ev_28_1","ev_28_2","ev_28_3","ev_28_4","ev_28_5","ev_28_6", "ev_28_7","ev_28_8","ev_28_9","ev_28_10","ev_28_11","ev_28_12", "ev_28_13","ev_28_14","ev_28_15","ev_28_16" }; int ev_29_total = 16; /* # of elements in array */ char *ev_29[16] = { "ev_29_1","ev_29_2","ev_29_3","ev_29_4","ev_29_5","ev_29_6", "ev_29_7","ev_29_8","ev_29_9","ev_29_10","ev_29_11","ev_29_12", "ev_29_13","ev_29_14","ev_29_15","ev_29_16" }; int ev_30_total = 16; /* # of elements in array */ char *ev_30[16] = { "ev_30_1","ev_30_2","ev_30_3","ev_30_4","ev_30_5","ev_30_6", "ev_30_7","ev_30_8","ev_30_9","ev_30_10","ev_30_11","ev_30_12", "ev_30_13","ev_30_14","ev_30_15","ev_30_16" }; int ev_31_total = 16; /* # of elements in array */ char *ev_31[16] = { "ev_31_1","ev_31_2","ev_31_3","ev_31_4","ev_31_5","ev_31_6", "ev_31_7","ev_31_8","ev_31_9","ev_31_10","ev_31_11","ev_31_12", "ev_31_13","ev_31_14","ev_31_15","ev_31_16" }; char **event_names[32] = {ev_syn, ev_key,ev_rel,ev_abs,ev_msc,ev_5,ev_6, ev_7,ev_8,ev_9,ev_10,ev_11,ev_12, ev_13,ev_14,ev_15,ev_16,ev_led,ev_snd, ev_19,ev_rep,ev_ff,ev_pwr,ev_ff_status,ev_24, ev_25,ev_26,ev_27,ev_28,ev_29,ev_30,ev_31 }; pd-hid_0.7/hid.c0000644000076500007650000003643411504504627012213 0ustar hanshans/* --------------------------------------------------------------------------*/ /* */ /* interface to native HID (Human Interface Devices) API */ /* Written by Hans-Christoph Steiner */ /* */ /* Copyright (c) 2004-2006 Hans-Christoph Steiner */ /* */ /* This program is free software; you can redistribute it and/or */ /* modify it under the terms of the GNU General Public License */ /* as published by the Free Software Foundation; either version 3 */ /* of the License, or (at your option) any later version. */ /* */ /* See file LICENSE for further informations on licensing terms. */ /* */ /* This program is distributed in the hope that it will be useful, */ /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ /* GNU General Public License for more details. */ /* */ /* You should have received a copy of the GNU General Public License */ /* along with this program; if not, write to the Free Software Foundation, */ /* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* */ /* --------------------------------------------------------------------------*/ #include #include #include #include #include #include "hid.h" /*------------------------------------------------------------------------------ * LOCAL DEFINES */ #define DEBUG(x) //#define DEBUG(x) x unsigned short global_debug_level = 0; /* higher numbers means more messages */ static t_class *hid_class; /*------------------------------------------------------------------------------ * FUNCTION PROTOTYPES */ //static void hid_poll(t_hid *x, t_float f); static void hid_open(t_hid *x, t_symbol *s, int argc, t_atom *argv); //static t_int hid_close(t_hid *x); //static t_int hid_read(t_hid *x,int fd); //static void hid_float(t_hid* x, t_floatarg f); /*------------------------------------------------------------------------------ * GLOBAL VARIABLES DECLARED extern IN hid.h */ t_int hid_instance_count; unsigned short device_count; /* this is used to test for the first instance to execute */ double last_execute_time[MAX_DEVICES]; /* store element structs to eliminate symbol table lookups, etc. */ t_hid_element *element[MAX_DEVICES][MAX_ELEMENTS]; /* number of active elements per device */ unsigned short element_count[MAX_DEVICES]; /*------------------------------------------------------------------------------ * SUPPORT FUNCTIONS */ void debug_print(t_int message_debug_level, const char *fmt, ...) { if(message_debug_level <= global_debug_level) { char buf[MAXPDSTRING]; va_list ap; //t_int arg[8]; va_start(ap, fmt); vsnprintf(buf, MAXPDSTRING-1, fmt, ap); post(buf); va_end(ap); } } void debug_error(t_hid *x, t_int message_debug_level, const char *fmt, ...) { if(message_debug_level <= global_debug_level) { char buf[MAXPDSTRING]; va_list ap; //t_int arg[8]; va_start(ap, fmt); vsnprintf(buf, MAXPDSTRING-1, fmt, ap); pd_error(x, buf); va_end(ap); } } static void output_status(t_hid *x, t_symbol *selector, t_float output_value) { t_atom *output_atom = getbytes(sizeof(t_atom)); SETFLOAT(output_atom, output_value); outlet_anything( x->x_status_outlet, selector, 1, output_atom); freebytes(output_atom,sizeof(t_atom)); } static void output_open_status(t_hid *x) { output_status(x, gensym("open"), x->x_device_open); } static void output_device_number(t_hid *x) { output_status(x, gensym("device"), x->x_device_number); } static void output_poll_time(t_hid *x) { output_status(x, gensym("poll"), x->x_delay); } static void output_device_count(t_hid *x) { output_status(x, gensym("total"), device_count); } static void output_element_ranges(t_hid *x) { if( (x->x_device_number > -1) && (x->x_device_open) ) { unsigned int i; t_atom output_data[4]; for(i=0;ix_device_number];++i) { SETSYMBOL(output_data, element[x->x_device_number][i]->type); SETSYMBOL(output_data + 1, element[x->x_device_number][i]->name); SETFLOAT(output_data + 2, element[x->x_device_number][i]->min); SETFLOAT(output_data + 3, element[x->x_device_number][i]->max); outlet_anything(x->x_status_outlet, gensym("range"), 4, output_data); } } } static unsigned int name_to_usage(char *usage_name) { // output usagepage << 16 + usage if(strcmp(usage_name,"pointer") == 0) return(0x00010001); if(strcmp(usage_name,"mouse") == 0) return(0x00010002); if(strcmp(usage_name,"joystick") == 0) return(0x00010004); if(strcmp(usage_name,"gamepad") == 0) return(0x00010005); if(strcmp(usage_name,"keyboard") == 0) return(0x00010006); if(strcmp(usage_name,"keypad") == 0) return(0x00010007); if(strcmp(usage_name,"multiaxiscontroller") == 0) return(0x00010008); return(0); } static short get_device_number_from_arguments(int argc, t_atom *argv) { short device_number = -1; unsigned short device_type_instance; unsigned int usage; unsigned short vendor_id; unsigned short product_id; char device_type_string[MAXPDSTRING] = ""; t_symbol *first_argument; t_symbol *second_argument; if(argc == 1) { first_argument = atom_getsymbolarg(0,argc,argv); if(first_argument == &s_) { // single float arg means device # device_number = (short) atom_getfloatarg(0,argc,argv); if(device_number < 0) device_number = -1; debug_print(LOG_DEBUG,"[hid] setting device# to %d",device_number); } else { // single symbol arg means first instance of a device type atom_string(argv, device_type_string, MAXPDSTRING-1); usage = name_to_usage(device_type_string); device_number = get_device_number_from_usage(0, usage >> 16, usage & 0xffff); debug_print(LOG_INFO,"[hid] using 0x%04x 0x%04x for %s", usage >> 16, usage & 0xffff, device_type_string); } } else if(argc == 2) { first_argument = atom_getsymbolarg(0,argc,argv); second_argument = atom_getsymbolarg(1,argc,argv); if( second_argument == &s_ ) { /* a symbol then a float means match on usage */ atom_string(argv, device_type_string, MAXPDSTRING-1); usage = name_to_usage(device_type_string); device_type_instance = atom_getfloatarg(1,argc,argv); debug_print(LOG_DEBUG,"[hid] looking for %s at #%d", device_type_string, device_type_instance); device_number = get_device_number_from_usage(device_type_instance, usage >> 16, usage & 0xffff); } else { /* two symbols means idVendor and idProduct in hex */ vendor_id = (unsigned short) strtol(first_argument->s_name, NULL, 16); product_id = (unsigned short) strtol(second_argument->s_name, NULL, 16); device_number = get_device_number_by_id(vendor_id,product_id); } } return(device_number); } void hid_output_event(t_hid *x, t_hid_element *output_data) { if( (output_data->value != output_data->previous_value) || (output_data->relative) ) // relative data should always be output { #if 1 // this is [hid] compatible t_atom event_data[2]; SETSYMBOL(event_data, output_data->name); SETFLOAT(event_data + 1, output_data->value); outlet_anything(x->x_data_outlet,output_data->type,2,event_data); #else // this outputs instance number, for [hid] v2 t_atom event_data[3]; SETSYMBOL(event_data, output_data->name); SETFLOAT(event_data + 1, output_data->instance); SETFLOAT(event_data + 2, output_data->value); outlet_anything(x->x_data_outlet,output_data->type,3,event_data); #endif } } /* stop polling the device */ static void stop_poll(t_hid* x) { debug_print(LOG_DEBUG,"stop_poll"); if (x->x_started) { clock_unset(x->x_clock); debug_print(LOG_INFO,"[hid] polling stopped"); x->x_started = 0; } } /*------------------------------------------------------------------------------ * METHODS FOR [hid]'s MESSAGES */ void hid_poll(t_hid* x, t_float f) { debug_print(LOG_DEBUG,"hid_poll"); /* if the user sets the delay less than 2, set to block size */ if( f > 2 ) x->x_delay = (t_int)f; else if( f > 0 ) //TODO make this the actual time between message processing x->x_delay = 1.54; if(x->x_device_number > -1) { if(!x->x_device_open) hid_open(x,gensym("open"),0,NULL); if(!x->x_started) { clock_delay(x->x_clock, x->x_delay); debug_print(LOG_DEBUG,"[hid] polling started"); x->x_started = 1; } } } static void hid_set_from_float(t_hid *x, t_floatarg f) { /* values greater than 1 set the polling delay time */ /* 1 and 0 for start/stop so you can use a [tgl] */ if(f > 1) { x->x_delay = (t_int)f; hid_poll(x,f); } else if(f == 1) { if(! x->x_started) hid_poll(x,f); } else if(f == 0) { stop_poll(x); } } /* close the device */ t_int hid_close(t_hid *x) { debug_print(LOG_DEBUG,"hid_close"); /* just to be safe, stop it first */ stop_poll(x); if(! hid_close_device(x)) { debug_print(LOG_INFO,"[hid] closed device %d",x->x_device_number); x->x_device_open = 0; return (0); } return (1); } /* hid_open behavoir * current state action * --------------------------------------- * closed / same device open * open / same device no action * closed / different device open * open / different device close open */ static void hid_open(t_hid *x, t_symbol *s, int argc, t_atom *argv) { debug_print(LOG_DEBUG,"hid_%s",s->s_name); /* store running state to be restored after the device has been opened */ t_int started = x->x_started; short device_number = get_device_number_from_arguments(argc, argv); if(device_number > -1) { if( (device_number != x->x_device_number) && (x->x_device_open) ) hid_close(x); if(! x->x_device_open) { if(hid_open_device(x,device_number)) error("[hid] can not open device %d",device_number); else { x->x_device_open = 1; x->x_device_number = device_number; } } } else debug_print(LOG_WARNING,"[hid] device does not exist"); /* restore the polling state so that when I [tgl] is used to start/stop [hid], * the [tgl]'s state will continue to accurately reflect [hid]'s state */ if(started) hid_set_from_float(x,x->x_delay); debug_print(LOG_DEBUG,"[hid] set device# to %d",device_number); output_open_status(x); output_device_number(x); } t_int hid_read(t_hid *x, int fd) { // debug_print(LOG_DEBUG,"hid_read"); unsigned int i; double right_now = clock_getlogicaltime(); t_hid_element *current_element; if(right_now > last_execute_time[x->x_device_number]) { hid_get_events(x); last_execute_time[x->x_device_number] = right_now; /* post("executing: instance %d/%d at %ld", x->x_instance, hid_instance_count, right_now);*/ } for(i=0; i< element_count[x->x_device_number]; ++i) { current_element = element[x->x_device_number][i]; if(current_element->previous_value != current_element->value) { hid_output_event(x, current_element); if(!current_element->relative) current_element->previous_value = current_element->value; } } if (x->x_started) { clock_delay(x->x_clock, x->x_delay); } // TODO: why is this 1? return 1; } static void hid_info(t_hid *x) { output_open_status(x); output_device_number(x); output_device_count(x); output_poll_time(x); output_element_ranges(x); hid_platform_specific_info(x); } static void hid_float(t_hid* x, t_floatarg f) { debug_print(LOG_DEBUG,"hid_float"); hid_set_from_float(x,f); } static void hid_debug(t_hid *x, t_float f) { global_debug_level = f; } /*------------------------------------------------------------------------------ * system functions */ static void hid_free(t_hid* x) { debug_print(LOG_DEBUG,"hid_free"); hid_close(x); clock_free(x->x_clock); hid_instance_count--; hid_platform_specific_free(x); } /* create a new instance of this class */ static void *hid_new(t_symbol *s, int argc, t_atom *argv) { t_hid *x = (t_hid *)pd_new(hid_class); unsigned int i; debug_print(LOG_DEBUG,"hid_%s",s->s_name); /* only display the version when the first instance is loaded */ if(!hid_instance_count) { post("[hid] %d.%d, written by Hans-Christoph Steiner ", HID_MAJOR_VERSION, HID_MINOR_VERSION); post("\tcompiled on "__DATE__" at "__TIME__ " "); } #if !defined(__linux__) && !defined(__APPLE__) error(" !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !!"); error(" This is a dummy, since this object only works GNU/Linux and MacOS X!"); error(" !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !!"); #endif /* init vars */ x->x_has_ff = 0; x->x_device_open = 0; x->x_started = 0; x->x_delay = DEFAULT_DELAY; for(i=0; ix_clock = clock_new(x, (t_method)hid_read); /* create anything outlet used for HID data */ x->x_data_outlet = outlet_new(&x->x_obj, 0); x->x_status_outlet = outlet_new(&x->x_obj, 0); x->x_device_number = get_device_number_from_arguments(argc, argv); x->x_instance = hid_instance_count; hid_instance_count++; return (x); } void hid_setup(void) { debug_print(LOG_DEBUG,"hid_setup"); hid_class = class_new(gensym("hid"), (t_newmethod)hid_new, (t_method)hid_free, sizeof(t_hid), CLASS_DEFAULT, A_GIMME,0); /* add inlet datatype methods */ class_addfloat(hid_class,(t_method) hid_float); class_addbang(hid_class,(t_method) hid_read); /* class_addanything(hid_class,(t_method) hid_anything); */ /* add inlet message methods */ class_addmethod(hid_class,(t_method) hid_debug,gensym("debug"),A_DEFFLOAT,0); class_addmethod(hid_class,(t_method) hid_build_device_list,gensym("refresh"),0); class_addmethod(hid_class,(t_method) hid_print,gensym("print"),0); class_addmethod(hid_class,(t_method) hid_info,gensym("info"),0); class_addmethod(hid_class,(t_method) hid_open,gensym("open"),A_GIMME,0); class_addmethod(hid_class,(t_method) hid_close,gensym("close"),0); class_addmethod(hid_class,(t_method) hid_poll,gensym("poll"),A_DEFFLOAT,0); /* force feedback messages */ class_addmethod(hid_class,(t_method) hid_ff_autocenter, gensym("ff_autocenter"),A_DEFFLOAT,0); class_addmethod(hid_class,(t_method) hid_ff_gain,gensym("ff_gain"),A_DEFFLOAT,0); class_addmethod(hid_class,(t_method) hid_ff_motors,gensym("ff_motors"),A_DEFFLOAT,0); class_addmethod(hid_class,(t_method) hid_ff_continue,gensym("ff_continue"),0); class_addmethod(hid_class,(t_method) hid_ff_pause,gensym("ff_pause"),0); class_addmethod(hid_class,(t_method) hid_ff_reset,gensym("ff_reset"),0); class_addmethod(hid_class,(t_method) hid_ff_stopall,gensym("ff_stopall"),0); /* ff tests */ class_addmethod(hid_class,(t_method) hid_ff_fftest,gensym("fftest"),A_DEFFLOAT,0); class_addmethod(hid_class,(t_method) hid_ff_print,gensym("ff_print"),0); } pd-hid_0.7/hid_one2four.pd0000644000076500007650000000062311504504627014202 0ustar hanshans#N canvas 0 22 458 308 10; #X obj 184 19 inlet; #X obj 66 248 outlet; #X obj 177 249 outlet; #X obj 121 124 hid_one2two \$1; #X obj 196 159 hid_one2two \$2; #X obj 293 250 outlet; #X text 27 16 hid_one2four; #X obj 385 249 outlet; #X obj 289 188 hid_one2two \$3; #X connect 0 0 3 0; #X connect 3 0 1 0; #X connect 3 1 4 0; #X connect 4 0 2 0; #X connect 4 1 8 0; #X connect 8 0 5 0; #X connect 8 1 7 0; pd-hid_0.7/hid-meta.pd0000644000076500007650000000045711504504627013314 0ustar hanshans#N canvas 10 22 200 200 10; #N canvas 20 22 420 300 META 1; #X text 10 10 META this is a prototype of a libdir meta file; #X text 10 30 NAME hid; #X text 10 50 AUTHOR Hans-Christoph Steiner; #X text 10 70 DESCRIPTION; #X text 10 90 LICENSE GNU GPL; #X text 10 110 VERSION 0.7; #X restore 10 10 pd META; pd-hid_0.7/hid_menu.pd0000644000076500007650000000061611504504627013411 0ustar hanshans#N canvas 469 172 202 29 10; #X obj 131 138 inlet; #X obj 15 350 outlet; #X obj 1 2 popup 200 25 grey90 HID_device none; #X msg 15 318 open \$1; #X obj 251 141 prepend append; #X msg 131 203 options; #X obj 131 176 route options; #X connect 0 0 6 0; #X connect 2 0 3 0; #X connect 3 0 1 0; #X connect 4 0 2 0; #X connect 5 0 2 0; #X connect 6 0 5 0; #X connect 6 1 4 0; #X coords 0 0 1 1 202 29 1; pd-hid_0.7/hid_polar-help.pd0000644000076500007650000000337611504504627014516 0ustar hanshans#N canvas 0 31 482 455 10; #X obj 5 2 cnv 15 450 20 empty empty hid_polar 2 11 1 18 -233017 -66577 0; #X obj 422 3 pddp/pddplink http://puredata.info/dev/pddp -text pddp ; #X text 244 411 released under the GNU GPL; #X floatatom 98 248 5 0 0 0 - - -; #X floatatom 98 335 7 0 0 0 radius-> - -; #X text 124 370 For more info:; #X obj 98 295 hid/hid_polar; #X text 27 397 (C) Copyright 2005 Hans-Christoph Steiner ; #X obj 101 161 hsl 128 15 0 1 0 0 empty empty x-axis 133 7 1 10 -225280 -1 -1 0 0; #X obj 157 103 vsl 15 128 0 1 0 0 empty empty y-axis -6 -9 1 10 -261681 -1 -1 0 0; #X floatatom 159 335 7 0 0 1 <-angle - -; #X floatatom 157 248 5 0 0 0 - - -; #X obj 157 270 t b f; #X obj 334 335 polar-joystick; #X text 275 273 related objects:; #X text 273 334 example:; #X msg 97 86 0.5; #X text 43 86 center:; #X obj 381 293 hid/hid_spiral; #X obj 225 293 hid/hid2rad; #X obj 303 293 hid/hid2deg; #N canvas 504 253 494 344 META 0; #X text 12 175 HELP_PATCH_AUTHORS "pd meta" information added by Jonathan Wilkes for Pd version 0.42.; #X text 12 25 LICENSE GPL; #X text 12 155 AUTHOR Hans-Christoph Steiner; #X text 12 45 DESCRIPTION convert cartesian coordinates (x \, y) to polar coordinates (radius \, angle); #X text 12 75 INLET_0 float bang; #X text 12 95 INLET_1 float; #X text 12 115 OUTLET_0 float; #X text 12 135 OUTLET_1 float; #X text 12 5 KEYWORDS control conversion abstraction; #X restore 419 411 pd META; #X text 17 29 Converts cartesian coordinates (x \, y) to polar coordinates (radius \, angle). The angle is in radians (-pi to pi). The angle 0 is at cartesian (1 \, 0.5) or to the right.; #X connect 3 0 6 0; #X connect 6 0 4 0; #X connect 6 1 10 0; #X connect 8 0 3 0; #X connect 9 0 11 0; #X connect 11 0 12 0; #X connect 12 0 6 0; #X connect 12 1 6 1;