IOWarriorLib


Discussion

The IOWarrior Library provides convinience funtions to access the IOWarrior under Mac OS X 10.2.3 or later. It simplifies the process of finding and accessing IOWarrior devices .

You will need to link your software against the IOKit.framework in order to use this source code.

Make sure you are calling IOWarriorInit before calling any of the other functions.

If you are running Mac OS X 10.2.3, make sure you have updated your Developer Tools at least to the December 2002 version.

Binaries compiled on Mac OS X 10.3 using this version of the IOWarrior Library will not work on earlier systems. However, binaries on 10.2.3 should also work on 10.2.3 or later. If you are using 10.3 and want to develop appplicaton that run on 10.2.x, too, select the 10.2.7 Cross Development SDK in XCode targets inspector. You have to install the additional SDK when installing the Mac OS X Developer Tools.

$Id: IOWarriorLib.h,v 1.3 2004/02/25 21:25:02 ilja Exp $



Functions


IOWarriorCount


Returns the number of interfaces connected to this system.
int IOWarriorCountInterfaces (void);
function result
The number of IOWarrior interfaces.

IOWarriorFirstInterfaceOfType


Returns the first IOWarrior interface of type inInterfaceType.

IOWarriorHIDDeviceInterface** IOWarriorFirstInterfaceOfType (
    int inInterfaceType
);
Discussion

Use this function to get the first discovered interface of a certain type. See the Constants definitions for a list of supported IOWarrior interface types. The result of this function can be used as paramter for IOWarriorWriteToInterface or IOWarriorReadFromInterface. Returns NULL if no interface matching inInterfaceType could be found.

Parameter Descriptions
inInterfaceType
The type of the interface to be returned.
function result
Returns an interface object if found, NULL otherwise.

IOWarriorInit


Initializes the IOWarrior library. Call this before calling any other functions.
int IOWarriorInit (void);
function result
Returns 0 if successfull, otherwise return value is different from 0.

IOWarriorInterfaceListNodeAtIndex


Returns the list node element at index inIndex.
IOWarriorListNode* IOWarriorInterfaceListNodeAtIndex (
    int inIndex
);
Discussion

Use this function to obtain more information (serial number, device type) about an interface of an IOWarrior device.

Parameter Descriptions
inIndex
The index of the desired list node. First list node has index 0.
function result
A pointer to a structure of type IOWarriorListNode. NULL if index is out of bounds.

IOWarriorIsPresent


Use this function to too see of an IOWarrior device is present.
int IOWarriorIsPresent (void);
function result
Returns 1 if at least one IOWarrior is connected to this system. Returns 0 if no IOWarrior device could be discovered.

IOWarriorReadFromInterface


Reads data from a specific interface.
int IOWarriorReadFromInterface (
    IOWarriorHIDDeviceInterface** inInterface,
    int inReportID,
    int inSize,
    void* outData
);
Discussion

Use this function to read a certain amount of data associated with a certain reportID to a specific interface.

Parameter Descriptions
inInterface
The interface the data should be read from. Pass the ioWarriorHIDInterface member of an IOWarriorListNode struct. This function will not get you the data sent in interrupt mode from interface 1. Instead you will receive a copy of the last HID report sent in interrupt mode. Use IOWarriorSetInterruptCallback to receive data received in interrupt mode.
inReportID
The report ID of the request. See the IO Warrior Datasheet for the appropriate values.
inSize
The size of the data to be read.
inData
A pointer to a buffer thats at least inSize bytes long. Read data will be stored here.
function result
Returns 0 if read operation was successful, returns an error code different from 0 otherwise.

IOWarriorReadInterface0


Reads 4 byte (32 bit) from interface 0 of the first IOWarrior 40 device connected to this system using a GetOutputReport request.
int IOWarriorReadInterface0 (
    void *outData
);
Parameter Descriptions
outData
A pointer to a buffer where the data should be stored. Buffer has to be at least 4 bytes long
function result
Returns 0 if reading operation was successfull. Returns a value different from 0 otherwise.

IOWarriorReadInterface1


Reads a 7 byte output report from interface 1 of the first IOWarrior 40 device connected to this system. This function won't work for interfaces 1 of an IOWarrior 40 on Mac OS X 10.2.x.

int IOWarriorReadInterface1 (
    int inReportID,
    void *outData
);
Discussion

Use this function to obtain data from the IOWarrior when in special mode. See the IOWarrior datasheet for details.

Parameter Descriptions
inReportID
The report ID of the request. See the IO Warrior Datasheet for the appropriate values.
outData
A pointer to a buffer where the data should be stored. Buffer has to be at least 7 bytes long
function result
Returns 0 if reading operation was successfull. Returns a value different from 0 otherwise.

IOWarriorSetDeviceCallback


Sets the function to be called when IOWarrior devices ar added or removed.
void IOWarriorSetDeviceCallback (
    IOWarriorDeviceCallbackFunctionPtr inCallbackPtr,
    void* inRefCon
);
Discussion

Use this function to install a custom callback function. You function will be called whenever IOWarrior devices are added or removed from the system. You should invalidate any references to IOWarriorListNode structures you might have saved when your callback functions gets called. Be sure to call IOWarriorCountInterfaces at least once after you callback function was invoked before calling any other functions from the IOWarrior Library.


IOWarriorSetInterruptCallback


Sets the function to be called when a report data is received on inInterface.
int IOWarriorSetInterruptCallback (
    IOWarriorHIDDeviceInterface** inInterface,
    void* inBuffer,
    UInt32 inBufferSize,
    IOHIDReportCallbackFunction inCallbackPtr,
    void* inRefCon
);
Discussion

Use this function to install a custom callback routine that gets invoked when data is received on interface inInterface. This function will only work when your application was compiled on Mac OS 10.3 or later and is running on Mac OS 10.3 or later. For earlier systems the implementation of the function is hidden from the compiler using preprocessor commands, because the system does not implement the required API calls.

Parameter Descriptions
inInterface
The interface where your data arrives
inBuffer
A buffer provided by the caller.
inBufferSize
The size of inBuffer.
inCallbackPtr
A pointer to your callback function. See IOHIDLib.h for more info.
inRefCon
A reference value passed to your callback on invocation.

IOWarriorWriteInterface0


Writes a 4 byte buffer (32 bit) to interface 0 of the first IOWarrior 40 devices using a SetOutputReport request.
int IOWarriorWriteInterface0 (
    void *inData
);
Discussion

The first byte of the passed buffer becomes mapped to the pins of port 0, the second byte to the pins of port 1 and so on.

Parameter Descriptions
inData
A pointer to the data being written. Should be at least 4 bytes long.
function result
Returns 0 if writing operation was successfull. Returns a value different from 0 otherwise.

IOWarriorWriteInterface1


Writes a 7 byte output report to interface 1 of the first IOWarrior 40 device connected to this system.
int IOWarriorWriteInterface1 (
    int inReportID,
    void *inData
);
Discussion

Use the function to control IOWarrior special modes (like IIC and LCD mode) of the IOWarrior. See the IOWarrior datasheet for details.

Parameter Descriptions
inReportID
The report ID of the request. See the IO Warrior Datasheet for the appropriate values.
inData
A pointer to the data being written. Should be at least 7 bytes long.
function result
Returns 0 if writing operation was successfull. Returns a value different from 0 otherwise.

IOWarriorWriteToInterface


Writes data to a specific interface.
int IOWarriorWriteToInterface (
    IOWarriorHIDDeviceInterface** inInterface,
    int inSize,
    void* inData
);
Discussion

Use this function to write to a certain amount of data associated with a certain reportID to a specific interface.

Parameter Descriptions
inInterface
The interface the data should be written to. Pass the ioWarriorHIDInterface member of an IOWarriorListNode struct obtained earlier.
inSize
The size of the data to be written.
inData
A pointer to the data to be written. First byte is report id.
function result
Returns 0 if write operation was successful, returns an error code different from 0 otherwise.

Typedefs


IOWarriorCallbackFunctionPtr


A function pointer type for IOWarriors callback function.
typedef void (*IOWarriorDeviceCallbackFunctionPtr) (
    void* inRefCon
);

Discussion

A function pointer type for IOWarriors callback function, that gets called whenever an IOWarrior device is added or removed. You can install you own callback function using the IOWarriorSetCallback fucntion.

Structs


IOWarriorListNodeStruct


IONotificationPortRef GetNotificationPort (void);


struct IOWarriorListNodeStruct {
    IONotificationPortRef GetNotificationPort (void);
    struct IOWarriorListNodeStruct
    {
    IOWarriorHIDDeviceInterface**   ioWarriorHIDInterface;      // IOKits interface object
    struct                          IOWarriorListNodeStruct* nextNode;  // pointer to the next interface
    CFStringRef            serialNumber;        // the device serial number
    int                             interfaceType;        // the type of the interface
    bool              interfaceOpen;          
} ;
Discussion

A structure implementing a linked list node. Used to keep track of all IOWarrior Interfaces connected to the system. You can use IOWarriorCountInterfaces and IOWarriorInterfaceListNodeAtIndex to iterate trough all interfaces.

Field Descriptions
ioWarriorHIDInterface
Interface object for the systems IOKit
nextNode
Pointer to the node in the interface list.
serialNumber
The serial number of the interface.
interfaceType
The type of the interface (kIOWarrior40Interface0, kIOWarrior40Interface1, ..) .
interfaceOpened
Has the interface already been opened.

#defines


kIOWarrior24CWInterface0


#define kIOWarrior24CWInterface0 8
Discussion

Interface type indentifier for an interface 0 of an IOWarrior 24 Charge Warrior.


kIOWarrior24CWInterface1


#define kIOWarrior24CWInterface1 9
Discussion

Interface type indentifier for an interface 0 of an IOWarrior 24 Charge Warrior.


kIOWarrior24CWInterface1


#define kJoyWarrior24F8Interface0 10
Discussion

Interface type indentifier for an interface 0 of an IOWarrior 24 Charge Warrior.


kIOWarrior24CWInterface1


#define kJoyWarrior24F8Interface1 11
Discussion

Interface type indentifier for an interface 0 of an IOWarrior 24 Charge Warrior.


kIOWarrior24CWInterface1


#define kMouseWarrior24F6Interface0 12
Discussion

Interface type indentifier for an interface 0 of an IOWarrior 24 Charge Warrior.


kIOWarrior24CWInterface1


#define kMouseWarrior24F6Interface1 13
Discussion

Interface type indentifier for an interface 0 of an IOWarrior 24 Charge Warrior.


kIOWarrior24CWInterface1


#define kJoyWarrior24F14Interface0 14
Discussion

Interface type indentifier for an interface 0 of an IOWarrior 24 Charge Warrior.


kIOWarrior24CWInterface1


#define kJoyWarrior24F14Interface1 15
Discussion

Interface type indentifier for an interface 0 of an IOWarrior 24 Charge Warrior.


kIOWarrior24Interface0


#define kIOWarrior24Interface0 2
Discussion

Interface type indentifier for an interface 0 of an IOWarrior 24.


kIOWarrior24Interface1


#define kIOWarrior24Interface1 3
Discussion

Interface type indentifier for an interface 0 of an IOWarrior 24.


kIOWarrior24PVInterface0


#define kIOWarrior24PVInterface0 6
Discussion

Interface type indentifier for an interface 0 of an IOWarrior 24.


kIOWarrior24PVInterface1


#define kIOWarrior24PVInterface1 7
Discussion

Interface type indentifier for an interface 0 of an IOWarrior 24.


kIOWarrior40Interface0


#define kIOWarrior40Interface0 0
Discussion

Interface type indentifier for an interface 0 of an IOWarrior 40.


kIOWarrior40Interface1


#define kIOWarrior40Interface1 1
Discussion

Interface type indentifier for an interface 1 of an IOWarrior 40.


kIOWarrior56Interface0


#define kIOWarrior56Interface0 4
Discussion

Interface type indentifier for an interface 0 of an IOWarrior 56.


kIOWarrior56Interface1


#define kIOWarrior56Interface1 5
Discussion

Interface type indentifier for an interface 1 of an IOWarrior 56.


kIOWarriorCustomTypeInterface0


#define kIOWarriorCustomTypeInterface0 1000
Discussion

Interface type indentifier for an interface 0 of an IOWarrior 24 Charge Warrior..


kIOWarriorCustomTypeInterface1


#define kIOWarriorCustomTypeInterface1 1001
Discussion

Interface type indentifier for an interface 0 of an IOWarrior 24 Charge Warrior..

(Last Updated 3/16/2019)