/* * Copyright (c) 2012 * Lars-Dominik Braun * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to * deal in the Software without restriction, including without limitation the * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or * sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS * IN THE SOFTWARE. */ #ifndef _DEVICE_H #define _DEVICE_H #include #include typedef enum { HIDPP_DEVID_ROOT = 0xff, } hidppDeviceId_t; /* HID++ version */ typedef struct { uint8_t major, minor; } hidppVersion_t; /* firmware type */ typedef enum { HIDPP_FW_TYPE_MAIN = 0, HIDPP_FW_TYPE_BOOT = 1, HIDPP_FW_TYPE_HARDWARE = 2, /* _OTHER >= 3 */ } hidppFirmwareType_t; /* firmware version object */ typedef struct { char prefix[4]; uint16_t version; uint16_t build; } hidppFirmware_t; /* device types */ typedef enum { HIDPP_DEV_KEYBOARD = 0, HIDPP_DEV_REMOTE_CONTROL = 1, HIDPP_DEV_NUMPAD = 2, HIDPP_DEV_MOUSE = 3, HIDPP_DEV_TOUCHPAD = 4, HIDPP_DEV_TRACKBALL = 5, HIDPP_DEV_PRESENTER = 6, HIDPP_DEV_RECEIVER = 7, } hidppDeviceType_t; /* feature id’s */ typedef enum { HIDPP_FEATURE_ROOT = 0x0000, HIDPP_FEATURE_SET = 0x0001, HIDPP_FEATURE_FIRMWARE_INFO = 0x0003, HIDPP_FEATURE_DEVICE_INFO = 0x0005, HIDPP_FEATURE_BATTERY_STATUS = 0x1000, HIDPP_FEATURE_PROGRAMMABLE_KEYS = 0x1b00, HIDPP_FEATURE_WIRELESS_STATUS = 0x1d4b, } hidppFeatureId_t; /* feature flags (bitfield) */ typedef enum { HIDPP_FF_OBSOLETE = (1 << 7), HIDPP_FF_HIDDEN = (1 << 6), HIDPP_FF_LOGITECH = (1 << 5), } hidppFeatureFlags_t; typedef struct { hidppFeatureId_t id; hidppFeatureFlags_t flags; } hidppFeature_t; struct hidppDevice { libusb_device_handle *usbDev; /* general */ hidppDeviceId_t id; hidppDeviceType_t type; hidppVersion_t hidVersion; char *name; /* feature index table */ size_t featuresCount; hidppFeature_t *features; /* firmware versions */ size_t firmwareCount; hidppFirmware_t *firmware; /* children (if any) */ size_t childrenCount; struct hidppDevice *children; } hidppDevice; typedef struct hidppDevice hidppDevice_t; void hidppDeviceDestroy (hidppDevice_t * const d); void hidppDeviceInit (hidppDevice_t * const d, libusb_device_handle * const usbDev, const hidppDeviceId_t id); void hidppDevicePrint (const hidppDevice_t * const d); bool hidppFeatureIdToIdx (const hidppDevice_t * const d, const hidppFeatureId_t id, uint8_t * const retIdx); #endif /* _DEVICE_H */