1 /*! 2 * @file libhid.h 3 * @brief HID Library - User API 4 * 5 * @author Copyright (C) 2003 - 2007 6 * Arnaud Quette <arnaud.quette@free.fr> && <arnaud.quette@mgeups.com> 7 * Charles Lepple <clepple@ghz.cc> 8 * Peter Selinger <selinger@users.sourceforge.net> 9 * Arjen de Korte <adkorte-guest@alioth.debian.org> 10 * 11 * This program is sponsored by MGE UPS SYSTEMS - opensource.mgeups.com 12 * 13 * This program is free software; you can redistribute it and/or modify 14 * it under the terms of the GNU General Public License as published by 15 * the Free Software Foundation; either version 2 of the License, or 16 * (at your option) any later version. 17 * 18 * This program is distributed in the hope that it will be useful, 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 * GNU General Public License for more details. 22 * 23 * You should have received a copy of the GNU General Public License 24 * along with this program; if not, write to the Free Software 25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 26 * 27 * -------------------------------------------------------------------------- */ 28 29 #ifndef _LIBHID_H 30 #define _LIBHID_H 31 32 #include "config.h" 33 34 #include <sys/types.h> 35 #include "hidtypes.h" 36 37 #include "timehead.h" 38 #ifdef SHUT_MODE 39 #include "libshut.h" 40 typedef SHUTDevice_t HIDDevice_t; 41 typedef char HIDDeviceMatcher_t; 42 typedef int hid_dev_handle_t; 43 typedef shut_communication_subdriver_t communication_subdriver_t; 44 #else 45 #include "libusb.h" 46 typedef USBDevice_t HIDDevice_t; 47 typedef USBDeviceMatcher_t HIDDeviceMatcher_t; 48 typedef usb_dev_handle * hid_dev_handle_t; 49 typedef usb_communication_subdriver_t communication_subdriver_t; 50 #endif 51 52 /* use explicit booleans */ 53 #ifndef FALSE 54 typedef enum ebool { FALSE, TRUE } bool_t; 55 #else 56 typedef int bool_t; 57 #endif 58 59 /* Device open modes */ 60 #define MODE_OPEN 0 /* open a HID device for the first time */ 61 #define MODE_REOPEN 1 /* reopen a HID device that was opened before */ 62 63 #define MAX_TS 2 /* validity period of a gotten report (2 sec) */ 64 65 /* ---------------------------------------------------------------------- */ 66 67 /* structure to describe an item in a usage table */ 68 typedef struct { 69 const char *usage_name; 70 const HIDNode_t usage_code; 71 } usage_lkp_t; 72 73 extern usage_lkp_t hid_usage_lkp[]; 74 75 /* an object of type usage_tables_t is a NULL-terminated array of 76 * pointers to individual usage tables. */ 77 typedef usage_lkp_t *usage_tables_t; 78 79 extern communication_subdriver_t *comm_driver; 80 extern HIDDesc_t *pDesc; /* parsed Report Descriptor */ 81 82 /* report buffer structure: holds data about most recent report for 83 each given report id */ 84 typedef struct reportbuf_s { 85 time_t ts[256]; /* timestamp when report was retrieved */ 86 int len[256]; /* size of report data */ 87 unsigned char *data[256]; /* report data (allocated) */ 88 } reportbuf_t; 89 90 extern reportbuf_t *reportbuf; /* buffer for most recent reports */ 91 92 extern int interrupt_only; 93 extern unsigned int interrupt_size; 94 95 /* ---------------------------------------------------------------------- */ 96 97 /* 98 * HIDGetItemValue 99 * -------------------------------------------------------------------------- */ 100 int HIDGetItemValue(hid_dev_handle_t udev, const char *hidpath, double *Value, usage_tables_t *utab); 101 102 /* 103 * HIDGetItemString 104 * -------------------------------------------------------------------------- */ 105 char *HIDGetItemString(hid_dev_handle_t udev, const char *hidpath, char *buf, size_t buflen, usage_tables_t *utab); 106 107 /* 108 * HIDSetItemValue 109 * -------------------------------------------------------------------------- */ 110 bool_t HIDSetItemValue(hid_dev_handle_t udev, const char *hidpath, double value, usage_tables_t *utab); 111 112 /* 113 * GetItemData 114 * -------------------------------------------------------------------------- */ 115 HIDData_t *HIDGetItemData(const char *hidpath, usage_tables_t *utab); 116 117 /* 118 * GetDataItem 119 * -------------------------------------------------------------------------- */ 120 char *HIDGetDataItem(const HIDData_t *hiddata, usage_tables_t *utab); 121 122 /* 123 * HIDGetDataValue 124 * -------------------------------------------------------------------------- */ 125 int HIDGetDataValue(hid_dev_handle_t udev, HIDData_t *hiddata, double *Value, int age); 126 127 /* 128 * HIDSetDataValue 129 * -------------------------------------------------------------------------- */ 130 int HIDSetDataValue(hid_dev_handle_t udev, HIDData_t *hiddata, double Value); 131 132 /* 133 * HIDGetIndexString 134 * -------------------------------------------------------------------------- */ 135 char *HIDGetIndexString(hid_dev_handle_t udev, int Index, char *buf, size_t buflen); 136 137 /* 138 * HIDGetEvents 139 * -------------------------------------------------------------------------- */ 140 int HIDGetEvents(hid_dev_handle_t udev, HIDData_t **event, int eventlen); 141 142 /* 143 * Support functions 144 * -------------------------------------------------------------------------- */ 145 void HIDDumpTree(hid_dev_handle_t udev, usage_tables_t *utab); 146 const char *HIDDataType(const HIDData_t *hiddata); 147 148 void free_report_buffer(reportbuf_t *rbuf); 149 reportbuf_t *new_report_buffer(HIDDesc_t *pDesc); 150 151 #endif /* _LIBHID_H */ 152