[tuxdroid-svn] r333 - daemon/trunk/libs
Status: Beta
Brought to you by:
ks156
From: jaguarondi <c2m...@c2...> - 2007-05-31 16:16:02
|
Author: jaguarondi Date: 2007-05-31 18:15:58 +0200 (Thu, 31 May 2007) New Revision: 333 Modified: daemon/trunk/libs/USBDaemon_command_tux.c daemon/trunk/libs/USBDaemon_command_tux.h daemon/trunk/libs/USBDaemon_usb_enum.c daemon/trunk/libs/USBDaemon_usb_enum.h Log: - UPD: added definitions for the various USB commands - ADD: functions to deal with the ID and the sleep mode Modified: daemon/trunk/libs/USBDaemon_command_tux.c =================================================================== --- daemon/trunk/libs/USBDaemon_command_tux.c 2007-05-31 12:13:32 UTC (rev 332) +++ daemon/trunk/libs/USBDaemon_command_tux.c 2007-05-31 16:15:58 UTC (rev 333) @@ -25,6 +25,7 @@ #include <stdio.h> #include <usb.h> #include "USBDaemon_status_table.h" +#include "USBDaemon_usb_enum.h" #include "USBDaemon_command_tux.h" #include "USBDaemon_usb_readWrite.h" #include "USBDaemon_globals.h" @@ -34,6 +35,13 @@ #include "USBDaemon_pidfile.h" /*_____________________ F U N C T I O N S __________________________________*/ +unsigned char connect_to_tux(uint16_t id); +unsigned char disconnect_from_tux(void); +unsigned char id_lookup(void); +unsigned char change_id(uint16_t id); +unsigned char wakeup_tux(void); +unsigned char free_wifi_channel(unsigned char wifi_channel); +unsigned char random_tux_connection(void); /************************************************************************** */ @@ -489,7 +497,7 @@ case TUX_CMD_STRUCT_SUB_CH_GENERAL: if (current_audio_channel != 0) { - ACK = send_usb_dongle_cmd(0x02, 0, 0, 0); + ACK = send_usb_dongle_cmd(USB_AUDIO_CMD, 0, 0, 0); current_audio_channel = 0; } else @@ -498,7 +506,7 @@ case TUX_CMD_STRUCT_SUB_CH_TTS: if (current_audio_channel != 1) { - ACK = send_usb_dongle_cmd(0x02, 1, 0, 0); + ACK = send_usb_dongle_cmd(USB_AUDIO_CMD, 1, 0, 0); current_audio_channel = 1; } else @@ -833,15 +841,96 @@ /* send_usb_donglecmd() */ /************************************************************************ */ -unsigned char send_usb_dongle_cmd(unsigned char cmd, unsigned char param1, +unsigned char send_usb_dongle_cmd(USB_DONGLE_COMMANDS cmd, unsigned char param1, unsigned char param2, unsigned char param3) { unsigned char usb_frame[TUX_SEND_LENGTH]; - usb_frame[0] = 1; + usb_frame[0] = USB_DONGLE_CMD; usb_frame[1] = cmd; usb_frame[2] = param1; usb_frame[3] = param2; usb_frame[4] = param3; return usb_write_TuxDroid(usb_frame); } + +/** + * \brief Connect to a tux by its ID + */ +unsigned char connect_to_tux(uint16_t id) +{ + return send_usb_dongle_cmd(USB_CONNECTION_CMD, USB_CONNECTION_CONNECT, (uint8_t)id, (uint8_t)(id>>8)); +} + +/** + * \brief Disconnect from tux + */ +unsigned char disconnect_from_tux(void) +{ + return send_usb_dongle_cmd(USB_CONNECTION_CMD, USB_CONNECTION_DISCONNECT, 0, 0); +} + +/** + * \brief Get the ID of the first disconnected tux which is discoverred + * + * The first disconnected tux that will detect this command will reply with + * it's ID and disconnect immediately. You can then connect to the tux with the + * ID you just got. + * + * In order to get the ID's of more than one disconnected tux, you have to + * issue this command multiple times until you don't get any new ID. + */ +unsigned char id_lookup(void) +{ + return send_usb_dongle_cmd(USB_CONNECTION_CMD, USB_CONNECTION_ID_LOOKUP, 0, 0); +} + +/** + * \brief Changes the ID of a disconnected tux + * + * You have to push on the head button of tux for XXX seconds while sending + * this command in order to validate the ID change request, this in order to + * avoid stealing a tux too easily. + */ +unsigned char change_id(uint16_t id) +{ + return send_usb_dongle_cmd(USB_CONNECTION_CMD, USB_CONNECTION_CHANGE_ID, (uint8_t)id, (uint8_t)(id>>8)); +} + +/** + * \brief Wake-up a tux if it's in sleep mode. + */ +unsigned char wakeup_tux(void) +{ + return send_usb_dongle_cmd(USB_CONNECTION_CMD, USB_CONNECTION_ID_LOOKUP, 0, 0); +} + +/** + * \brief Configure the RF module to avoid a given wifi channel + * + * This sets the frequencies to avoid in the dongle but these settings take + * effect only when a connection is initiated with a tux. This function should + * be called before conneting to a tux or you have to disconnect and reconnect + * to change it on the go. + */ +unsigned char free_wifi_channel(unsigned char wifi_channel) +{ + /* + * Conversion of the lower and higher frequencies of a wifi channel into + * ATR2406 channel numbers. + */ + uint8_t lower_ATR_channel = (uint8_t)(wifi_channel - 1) * 6; + uint8_t higher_ATR_channel = (uint8_t)(wifi_channel - 1) * 6 + 26; + + return send_usb_dongle_cmd(USB_CONNECTION_CMD, USB_CONNECTION_CHANGE_ID, lower_ATR_channel, higher_ATR_channel); +} + +/** + * \brief Connect to the first tux discovered + * + * Used to catch any disconnected tux, request it's ID and connect to it. + */ +unsigned char random_tux_connection(void) +{ + return 0; +} Modified: daemon/trunk/libs/USBDaemon_command_tux.h =================================================================== --- daemon/trunk/libs/USBDaemon_command_tux.h 2007-05-31 12:13:32 UTC (rev 332) +++ daemon/trunk/libs/USBDaemon_command_tux.h 2007-05-31 16:15:58 UTC (rev 333) @@ -25,6 +25,7 @@ #define __USBDAEMON_COMMAND_TUX_H__ /*_____________________ I N C L U D E S____________________________________ */ +#include "USBDaemon_usb_enum.h" /*_____________________ D E F I N E S ______________________________________*/ @@ -46,7 +47,7 @@ extern unsigned char send_usb_tux_cmd(unsigned char cmd, unsigned char param1, unsigned char param2, unsigned char param3); -extern unsigned char send_usb_dongle_cmd(unsigned char cmd, +extern unsigned char send_usb_dongle_cmd(USB_DONGLE_COMMANDS cmd, unsigned char param1, unsigned char param2, unsigned char param3); Modified: daemon/trunk/libs/USBDaemon_usb_enum.c =================================================================== --- daemon/trunk/libs/USBDaemon_usb_enum.c 2007-05-31 12:13:32 UTC (rev 332) +++ daemon/trunk/libs/USBDaemon_usb_enum.c 2007-05-31 16:15:58 UTC (rev 333) @@ -139,8 +139,9 @@ TUX_USB_STATUS = TUX_USB_CONNECTED; - /* Reinit audio channel */ - send_usb_dongle_cmd(0x02, 0, 0, 0); + /* Resets audio channel selection; there are 2 audio interfaces in the + * dongle, the second is dedicated to TTS. */ + send_usb_dongle_cmd(USB_AUDIO_CMD, 0, 0, 0); /* select the first audio channel */ current_audio_channel = 0; return 1; Modified: daemon/trunk/libs/USBDaemon_usb_enum.h =================================================================== --- daemon/trunk/libs/USBDaemon_usb_enum.h 2007-05-31 12:13:32 UTC (rev 332) +++ daemon/trunk/libs/USBDaemon_usb_enum.h 2007-05-31 16:15:58 UTC (rev 333) @@ -36,6 +36,31 @@ TUX_USB_CONNECTED = 1 } TUX_USB_CONN_STATUS; +typedef enum +{ + USB_TUX_CMD = 0, + USB_DONGLE_CMD = 1, + USB_BOOTLOADER_CMD = 2, +} USB_HEADER_TYPE; + +typedef enum +{ + USB_CONNECTION_CMD = 0, + USB_STATUS_CMD = 1, + USB_AUDIO_CMD = 2, + USB_VERSION_CMD = 6, +} USB_DONGLE_COMMANDS; + +typedef enum +{ + USB_CONNECTION_CONNECT = 1, + USB_CONNECTION_DISCONNECT = 2, + USB_CONNECTION_ID_LOOKUP = 3, + USB_CONNECTION_CHANGE_ID = 4, + USB_CONNECTION_WAKEUP = 5, + USB_CONNECTION_WIRELESS_CHANNEL = 6, +} USB_ID_PARAM1; + /*_____________________ V A R I A B L E S __________________________________*/ extern usb_dev_handle *tux_handle; extern TUX_USB_CONN_STATUS TUX_USB_STATUS; |