tags:

views:

31

answers:

1

Hello,

Is there a way to get a string representation for the Constants and enums defined in IOKit?

I making a forage into IOKit and trying to console log out some parameter which USB devices return. But I'm ending up with lists of numbers. Is there another way to list what these mean?

For example in IOHIDKeys.h

enum IOHIDElementType {
    kIOHIDElementTypeInput_Misc        = 1,
    kIOHIDElementTypeInput_Button      = 2,
    kIOHIDElementTypeInput_Axis        = 3,
    kIOHIDElementTypeInput_ScanCodes   = 4,
    kIOHIDElementTypeOutput            = 129,
    kIOHIDElementTypeFeature           = 257,
    kIOHIDElementTypeCollection        = 513
};
typedef enum IOHIDElementType IOHIDElementType;

or even worse (for me) in IOHIDUsageTables.h i'm having to look up the hex value and find it in the header... e.g.:

kHIDUsage_GD_Joystick   = 0x04, /* Application Collection */
kHIDUsage_GD_GamePad    = 0x05, /* Application Collection */
kHIDUsage_GD_Keyboard   = 0x06, /* Application Collection */
kHIDUsage_GD_Keypad = 0x07, /* Application Collection */
+1  A: 

You can use the classic switch method, eg.

const char *IOHIDElemtType2str(IOHIDElementType type)
{
    switch(type)
    {
        case kIOHIDElementTypeInput_Misc:
            return "kIOHidElementTypeInput_Misc";
    }
}

and so on.

Hasturkun
yeah. I was hoping that there was something ready made, this would take a long time...
Ross
I'd definitely use `#define ENTRY(e_) case e_: return #e_;` instead of repeating the string...
Georg Fritzsche