[tuxdroid-svn] r1043 - software_suite_v2/middleware/tuxdriver/branches/hid_transition/src
Status: Beta
Brought to you by:
ks156
From: remi <c2m...@c2...> - 2008-04-30 13:02:44
|
Author: remi Date: 2008-04-30 15:02:40 +0200 (Wed, 30 Apr 2008) New Revision: 1043 Modified: software_suite_v2/middleware/tuxdriver/branches/hid_transition/src/tux_usb.c Log: using of the HID interface in tux_usb instead of libusb Modified: software_suite_v2/middleware/tuxdriver/branches/hid_transition/src/tux_usb.c =================================================================== --- software_suite_v2/middleware/tuxdriver/branches/hid_transition/src/tux_usb.c 2008-04-30 12:37:41 UTC (rev 1042) +++ software_suite_v2/middleware/tuxdriver/branches/hid_transition/src/tux_usb.c 2008-04-30 13:02:40 UTC (rev 1043) @@ -23,9 +23,9 @@ #include "log.h" #ifdef WIN32 -# include "usb.h" +# include "tux_hid_win32.h" #else -# include <usb.h> +# include "tux_hid_unix.h" #endif #include "tux_usb.h" @@ -33,8 +33,6 @@ # include "threading_uniform.h" #endif -static usb_dev_handle *tux_handle = NULL; -static struct usb_device *tux_device = NULL; static bool usb_connected = false; static frame_callback_t frame_callback_function; static simple_callback_t dongle_disconnect_function; @@ -55,11 +53,8 @@ static bool read_loop_started = false; static void set_connected(bool value); -static struct usb_device *usb_find_TuxDroid(void); -static struct usb_dev_handle *usb_open_TuxDroid(struct usb_device *tux_dev); static int usb_write_TuxDroid(const void *buf, int size); static int usb_read_TuxDroid(char *buf); -static void print_usb_debug(char *str); static void set_read_loop_started(bool value); static bool get_read_loop_started(void); @@ -68,15 +63,6 @@ /** * */ -static void -print_usb_debug(char *str) -{ - log_debug("USB debug : %s\n", str); -} - -/** - * - */ LIBLOCAL void tux_usb_set_frame_callback(frame_callback_t funct) { @@ -155,11 +141,6 @@ LIBLOCAL void tux_usb_init_module(void) { -#ifdef USB_DEBUG - usb_set_debug(4); -#else - usb_set_debug(0); -#endif #ifdef USE_MUTEX mutex_init(__connected_mutex); mutex_init(__read_write_mutex); @@ -244,112 +225,15 @@ /** * */ -static struct usb_device * -usb_find_TuxDroid(void) -{ - struct usb_bus *bus; - struct usb_device *tux_dev; - struct usb_device *tux_dev2; - - print_usb_debug("usb_init()"); - usb_init(); - print_usb_debug("usb_find_busses()"); - usb_find_busses(); - print_usb_debug("usb_find_devices()"); - usb_find_devices(); - - tux_dev2 = NULL; - - for (bus = usb_busses; bus; bus = bus->next) - { - for (tux_dev = bus->devices; tux_dev; tux_dev = tux_dev->next) - { - if (tux_dev->descriptor.idVendor == TUX_VID - && tux_dev->descriptor.idProduct == TUX_PID) - { - if (tux_dev->config->bNumInterfaces > 1) - { - tux_dev2 = tux_dev; - } - } - } - } - return tux_dev2; -} - -/** - * - */ -static struct usb_dev_handle * -usb_open_TuxDroid(struct usb_device *tux_dev) -{ - usb_dev_handle *tux_hdl; - int error; - - /* Open usb device */ - print_usb_debug("usb_open(tux_dev)"); - tux_hdl = usb_open(tux_dev); - - if (!tux_hdl) - { - return NULL; - } - - /* Setting configuration is normally not necessary as the snd-usb-audio - * will already have that done at this point. But in case we don't have usb - * sound support, it may help to set the configuration. */ - print_usb_debug("usb_set_configuration(tux_hdl, 1)"); - usb_set_configuration(tux_hdl, 1); - - /* Claim device interface */ - print_usb_debug("usb_claim_interface(tux_hdl, TUX_INTERFACE)"); - error = usb_claim_interface(tux_hdl, TUX_INTERFACE); - if (error != 0) - { - print_usb_debug("usb_claim_interface(tux_hdl, TUX_INTERFACE)"); - error = usb_claim_interface(tux_hdl, TUX_INTERFACE); - if (error != 0) - { - usb_reset(tux_hdl); - return NULL; - } - } - - return tux_hdl; -} - -/** - * - */ LIBLOCAL TuxUSBError tux_usb_capture(void) { read_error_counter = 0; - tux_device = usb_find_TuxDroid(); - if (!tux_device) + if (!tux_hid_capture(TUX_VID, TUX_PID)) { - log_error("Fux not found"); return TuxUSBFuxNotFound; } - - /* Old firmware should be discarded here */ -#ifndef USB_DEBUG - print_usb_debug("read tux_device->descriptor.bcdDevice"); - if (tux_device->descriptor.bcdDevice < MIN_FIRMWARE_VERSION) - { - log_error("Your fux firmware is too old"); - return TuxUSBFirmwareTooOld; - } -#endif - - /* Get Device handle */ - tux_handle = usb_open_TuxDroid(tux_device); - if (tux_handle == NULL) - { - log_error("Can't open the USB device"); - return TuxUSBHandleNotOpen; - } set_connected(true); @@ -362,19 +246,7 @@ LIBLOCAL TuxUSBError tux_usb_release(void) { - print_usb_debug("usb_release_interface(tux_handle, TUX_INTERFACE)"); - if (usb_release_interface(tux_handle, TUX_INTERFACE) < 0) - { - log_error("TuxUSBCantReleaseInterface"); - return TuxUSBCantReleaseInterface; - } - - print_usb_debug("usb_close(tux_handle)"); - if (usb_close(tux_handle) < 0) - { - log_error("Can't close the USB device"); - return TuxUSBCantCloseDevice; - } + tux_hid_release(); set_connected(false); @@ -415,10 +287,14 @@ static int usb_write_TuxDroid(const void *buf, int size) { - return usb_interrupt_write( tux_handle, - TUX_WRITE_EP, - (char *)buf, size, - TUX_WRITE_TIMEOUT); + if (!tux_hid_write(size, (char *)buf)) + { + return -ENODEV; + } + else + { + return size; + } } /** @@ -486,11 +362,14 @@ static int usb_read_TuxDroid(char *buf) { - return usb_interrupt_read( tux_handle, - TUX_READ_EP, - (char *)buf, - TUX_RECEIVE_LENGTH, - TUX_READ_TIMEOUT); + if (!tux_hid_read(TUX_RECEIVE_LENGTH, (char *)buf)) + { + return -ENODEV; + } + else + { + return TUX_RECEIVE_LENGTH; + } } /** |