hid.h

Go to the documentation of this file.
00001 #ifndef __INCLUDED_HID_H__
00002 #define __INCLUDED_HID_H__
00003 
00004 #include <stdio.h>
00005 #include <usb.h>
00006 #include <hidparser.h>
00007 
00015 #ifndef byte
00016   typedef unsigned char byte;
00017 #endif
00018 
00019 #ifdef HAVE_STDBOOL_H
00020 #  include <stdbool.h>
00021 #else
00022 #  define bool  _Bool
00023 #  define true  1
00024 #  define false 0
00025 #endif
00026 
00027 typedef enum hid_return_t {
00028   HID_RET_SUCCESS = 0,
00029   HID_RET_INVALID_PARAMETER,
00030   HID_RET_NOT_INITIALISED,
00031   HID_RET_ALREADY_INITIALISED,
00032   HID_RET_FAIL_FIND_BUSSES,
00033   HID_RET_FAIL_FIND_DEVICES,
00034   HID_RET_FAIL_OPEN_DEVICE,
00035   HID_RET_DEVICE_NOT_FOUND,
00036   HID_RET_DEVICE_NOT_OPENED,
00037   HID_RET_DEVICE_ALREADY_OPENED,
00038   HID_RET_FAIL_CLOSE_DEVICE,
00039   HID_RET_FAIL_CLAIM_IFACE,
00040   HID_RET_FAIL_DETACH_DRIVER,
00041   HID_RET_NOT_HID_DEVICE,
00042   HID_RET_HID_DESC_SHORT,
00043   HID_RET_REPORT_DESC_SHORT,
00044   HID_RET_REPORT_DESC_LONG,
00045   HID_RET_FAIL_ALLOC,
00046   HID_RET_OUT_OF_SPACE,
00047   HID_RET_FAIL_SET_REPORT,
00048   HID_RET_FAIL_GET_REPORT,
00049   HID_RET_FAIL_INT_READ,
00050   HID_RET_NOT_FOUND,
00051   HID_RET_TIMEOUT
00052 } hid_return;
00053 
00054 struct usb_dev_handle;
00055 
00064 typedef struct HIDInterface_t {
00065   struct usb_dev_handle *dev_handle;
00066   struct usb_device *device;
00067   int interface;
00068   char id[32];
00069   HIDData* hid_data;
00070   HIDParser* hid_parser;
00071 } HIDInterface;
00072 
00073 typedef bool (*matcher_fn_t)(struct usb_dev_handle const* usbdev,
00074     void* custom, unsigned int len);
00075 
00076 typedef struct HIDInterfaceMatcher_t {
00077   unsigned short vendor_id;
00078   unsigned short product_id;
00079 #ifndef SWIG
00080   matcher_fn_t matcher_fn;  
00081   void* custom_data;       
00082   unsigned int custom_data_length; 
00083 #endif
00084 } HIDInterfaceMatcher;
00085 
00086 #define HID_ID_MATCH_ANY 0x0000
00087 
00095 typedef enum HIDDebugLevel_t {
00096   HID_DEBUG_NONE = 0x0,   
00097   HID_DEBUG_ERRORS = 0x1, 
00098   HID_DEBUG_WARNINGS = 0x2, 
00099   HID_DEBUG_NOTICES = 0x4,  
00100   HID_DEBUG_TRACES = 0x8, 
00101   HID_DEBUG_ASSERTS = 0x10, 
00102   HID_DEBUG_NOTRACES = HID_DEBUG_ERRORS | HID_DEBUG_WARNINGS | HID_DEBUG_NOTICES | HID_DEBUG_ASSERTS,
00104   HID_DEBUG_ALL = HID_DEBUG_ERRORS | HID_DEBUG_WARNINGS | HID_DEBUG_NOTICES | HID_DEBUG_TRACES | HID_DEBUG_ASSERTS
00105 } HIDDebugLevel;
00106   
00107 #ifdef __cplusplus
00108 extern "C" {
00109 #endif
00110 
00111 void hid_set_debug(HIDDebugLevel const level);
00112 void hid_set_debug_stream(FILE* const outstream);
00113 void hid_set_usb_debug(int const level);
00114 
00115 HIDInterface* hid_new_HIDInterface();
00116 
00117 void hid_delete_HIDInterface(HIDInterface** const hidif);
00118 
00119 void hid_reset_HIDInterface(HIDInterface* const hidif);
00120 
00121 hid_return hid_init();
00122 
00123 hid_return hid_cleanup();
00124 
00125 bool hid_is_initialised();
00126 
00127 hid_return hid_open(HIDInterface* const hidif, int const interface,
00128     HIDInterfaceMatcher const* const matcher);
00129 hid_return hid_force_open(HIDInterface* const hidif, int const interface,
00130     HIDInterfaceMatcher const* const matcher, unsigned short retries);
00131 
00132 hid_return hid_close(HIDInterface* const hidif);
00133 
00134 bool hid_is_opened(HIDInterface const* const hidif);
00135 
00136 const char *hid_strerror(hid_return ret);
00137 
00138 hid_return hid_get_input_report(HIDInterface* const hidif, int const path[],
00139     unsigned int const depth, char* const buffer, unsigned int const size);
00140 
00141 hid_return hid_set_output_report(HIDInterface* const hidif, int const path[],
00142     unsigned int const depth, char const* const buffer, unsigned int const size);
00143 
00144 hid_return hid_get_feature_report(HIDInterface* const hidif, int const path[],
00145     unsigned int const depth, char* const buffer, unsigned int const size);
00146 
00147 hid_return hid_set_feature_report(HIDInterface* const hidif, int const path[],
00148     unsigned int const depth, char const* const buffer, unsigned int const size);
00149 
00150 hid_return hid_get_item_value(HIDInterface* const hidif,
00151                               int const path[], unsigned int const depth,
00152                               double *const value);
00153 
00154 /*
00155 hid_return hid_get_item_string(HIDInterface* const hidif,
00156                                int const path[], unsigned int const depth,
00157                                char *const value, unsigned int const maxlen);
00158 
00159 hid_return hid_set_item_value(HIDInterface* const hidif,
00160                               int const path[], unsigned int const depth,
00161                               double const value);
00162 */
00163 hid_return hid_write_identification(FILE* const out,
00164     HIDInterface const* const hidif);
00165 
00166 hid_return hid_dump_tree(FILE* const out, HIDInterface* const hidif);
00167 
00168 hid_return hid_interrupt_read(HIDInterface* const hidif, unsigned int const ep,
00169     char* const bytes, unsigned int const size, unsigned int const timeout);
00170 
00171 hid_return hid_interrupt_write(HIDInterface* const hidif, unsigned int const ep,
00172     const char* const bytes, unsigned int const size, unsigned int const timeout);
00173 
00174 hid_return hid_set_idle(HIDInterface * const hidif,
00175     unsigned duration, unsigned report_id);
00176 
00177 
00178 #ifdef __cplusplus
00179 }
00180 #endif
00181 
00182 #endif /* __INCLUDED_HID_H__ */
00183 
00184 /* COPYRIGHT --
00185  *
00186  * This file is part of libhid, a user-space HID access library.
00187  * libhid is (c) 2003-2006
00188  *   Martin F. Krafft <libhid@pobox.madduck.net>
00189  *   Charles Lepple <clepple+libhid@ghz.cc>
00190  *   Arnaud Quette <arnaud.quette@free.fr> && <arnaud.quette@mgeups.com>
00191  * and distributed under the terms of the GNU General Public License.
00192  * See the file ./COPYING in the source distribution for more information.
00193  *
00194  * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
00195  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES
00196  * OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00197  */

Generated on Sun Mar 30 15:28:24 2008 for libhid by  doxygen 1.5.1