[tuxdroid-svn] r1040 - software_suite_v2/middleware/tuxdriver/branches/hid_transition/src
Status: Beta
Brought to you by:
ks156
From: remi <c2m...@c2...> - 2008-04-30 12:55:31
|
Author: remi Date: 2008-04-30 14:34:03 +0200 (Wed, 30 Apr 2008) New Revision: 1040 Modified: software_suite_v2/middleware/tuxdriver/branches/hid_transition/src/tux_hid_unix.c Log: updated read, write, release interface. + cleaning Modified: software_suite_v2/middleware/tuxdriver/branches/hid_transition/src/tux_hid_unix.c =================================================================== --- software_suite_v2/middleware/tuxdriver/branches/hid_transition/src/tux_hid_unix.c 2008-04-30 10:01:05 UTC (rev 1039) +++ software_suite_v2/middleware/tuxdriver/branches/hid_transition/src/tux_hid_unix.c 2008-04-30 12:34:03 UTC (rev 1040) @@ -38,57 +38,10 @@ static int tux_device_hdl = -1; static char tux_device_path[256] = ""; -struct hiddev_usage_ref uref_out; -struct hiddev_report_info rinfo_out; +static struct hiddev_usage_ref uref_out; +static struct hiddev_report_info rinfo_out; +static struct hiddev_field_info finfo_out; -static void -showReports(int fd, unsigned report_type) -{ - struct hiddev_report_info rinfo; - struct hiddev_field_info finfo; - struct hiddev_usage_ref uref; - int i, j, ret; - - rinfo.report_type = report_type; - rinfo.report_id = HID_REPORT_ID_FIRST; - ret = ioctl(fd, HIDIOCGREPORTINFO, &rinfo); - - // Get Reports - while (ret >= 0) - { - // Copy the output report - if( report_type == HID_REPORT_TYPE_OUTPUT ) { - memcpy(&rinfo_out, &rinfo, sizeof(rinfo)); - } - - // Get Fields - for (i = 0; i < rinfo.num_fields; i++) - { - finfo.report_type = rinfo.report_type; - finfo.report_id = rinfo.report_id; - finfo.field_index = i; - ioctl(fd, HIDIOCGFIELDINFO, &finfo); - - // Get usages - for (j = 0; j < finfo.maxusage; j++) - { - uref.report_type = finfo.report_type; - uref.report_id = finfo.report_id; - uref.field_index = i; - uref.usage_index = j; - ioctl(fd, HIDIOCGUCODE, &uref); - ioctl(fd, HIDIOCGUSAGE, &uref); - - if(uref.report_type == HID_REPORT_TYPE_OUTPUT && j==0) { - memcpy(&uref_out, &uref, sizeof(uref)); - } - } - } - rinfo.report_id |= HID_REPORT_ID_NEXT; - ret = ioctl(fd, HIDIOCGREPORTINFO, &rinfo); - } -} - static bool find_dongle_from_path(char *path, int vendor_id, int product_id) { @@ -99,7 +52,6 @@ struct hiddev_devinfo device_info; int err; - /* Normal path to scan is /dev/usb */ dir = opendir(path); if (dir != NULL) { @@ -117,8 +69,9 @@ { sprintf(tux_device_path, "%s", device_path); tux_device_hdl = fd; + + closedir(dir); - closedir(dir); return true; } else @@ -154,36 +107,92 @@ return false; } -int -main(int argc, char **argv) +void LIBLOCAL +tux_hid_release(void) { - unsigned char go_am[] = "\x00\x31\x0A\x00\x00"; + if (tux_device_hdl != -1) + { + close(tux_device_hdl); + tux_device_hdl = -1; + } +} + +bool LIBLOCAL +tux_hid_write(int size, char *buffer) +{ int i; + int err; - if (tux_hid_capture(0x03EB, 0xFF07)) + rinfo_out.report_type = HID_REPORT_TYPE_OUTPUT; + rinfo_out.report_id = HID_REPORT_ID_FIRST; + + err = ioctl(tux_device_hdl, HIDIOCGREPORTINFO, &rinfo_out); + if (err < 0) { - printf("Dongle was found [%s]\n", tux_device_path); + return false; + } + + for(i = 0; i < size; i++) + { + uref_out.report_type = HID_REPORT_TYPE_OUTPUT; + uref_out.report_id = HID_REPORT_ID_FIRST; + uref_out.usage_index = i; + uref_out.value = (unsigned char)buffer[i]; - showReports(tux_device_hdl, HID_REPORT_TYPE_INPUT); - showReports(tux_device_hdl, HID_REPORT_TYPE_OUTPUT); - - for(i = 0; i < 5; i++) { - uref_out.usage_index = i; - uref_out.value = go_am[i]; - ioctl(tux_device_hdl,HIDIOCSUSAGE, &uref_out); + err = ioctl(tux_device_hdl,HIDIOCSUSAGE, &uref_out); + if (err < 0) + { + return false; } - ioctl(tux_device_hdl,HIDIOCSREPORT,&rinfo_out); - - sleep(5); - close(tux_device_hdl); - return 0; } - else + + err = ioctl(tux_device_hdl,HIDIOCSREPORT,&rinfo_out); + if (err < 0) { - printf("Dongle was not found !\n"); - return -1; + return false; } + + return true; } +bool LIBLOCAL +tux_hid_read(int size, char *buffer) +{ + int i; + int err; + + rinfo_out.report_type = HID_REPORT_TYPE_INPUT; + rinfo_out.report_id = HID_REPORT_ID_FIRST; + + err = ioctl(tux_device_hdl, HIDIOCGREPORTINFO, &rinfo_out); + if (err < 0) + { + return false; + } + + for (i = 0; i < size; i++) + { + uref_out.report_type = HID_REPORT_TYPE_INPUT; + uref_out.report_id = HID_REPORT_ID_FIRST; + uref_out.usage_index = i; + + err = ioctl(tux_device_hdl, HIDIOCGUCODE, &uref_out); + if (err < 0) + { + return false; + } + + err = ioctl(tux_device_hdl, HIDIOCGUSAGE, &uref_out); + if (err < 0) + { + return false; + } + + buffer[i] = uref_out.value; + } + + return true; +} + #endif /* Not WIN32 */ |