[tuxdroid-svn] r735 - daemon/trunk/libs
Status: Beta
Brought to you by:
ks156
From: jaguarondi <c2m...@c2...> - 2007-11-27 14:57:12
|
Author: jaguarondi Date: 2007-11-27 15:57:05 +0100 (Tue, 27 Nov 2007) New Revision: 735 Modified: daemon/trunk/libs/USBDaemon_status_table.c daemon/trunk/libs/USBDaemon_status_table.h Log: * Cleaned the IR status. Added a status to indicate when the remote button is pressed or released. The RC5_code indicates the latest code received, even if the button has been released. * Added a function called each time a new status series is received. Used currently to detect a timeout when the remote button is released. Modified: daemon/trunk/libs/USBDaemon_status_table.c =================================================================== --- daemon/trunk/libs/USBDaemon_status_table.c 2007-11-27 11:20:02 UTC (rev 734) +++ daemon/trunk/libs/USBDaemon_status_table.c 2007-11-27 14:57:05 UTC (rev 735) @@ -46,8 +46,6 @@ unsigned char CMD_status = 0; unsigned char pong_received; unsigned char cmd_status_flag; -static unsigned char last_remote_key = 0xFF; -static unsigned char last_toggle_key = 0xFF; unsigned char sound_flash_count = 0; /** @@ -64,6 +62,15 @@ struct connection_status_t connection_status; /** + * timer used to determine when no IR signal are received anymore. + */ +static unsigned int ir_timeout; +/** Number of status series received without any IR signal before the remote + * button is considered released. '1' obviously doesn't work, you need at least + * to have 2 status series without any IR signal. */ +#define IR_TIMEOUT 2 + +/** * Update tux_status with the given properties of the sound flash. */ static void update_sound_flash_properties(const unsigned char *data) @@ -103,43 +110,36 @@ log_debug("charger state: %d", *state); } +/** + * Get the new value of the IR RC5 code. + */ static void update_ir(const unsigned char *new_status) { - unsigned char code; - unsigned char toggle; - unsigned char check; - unsigned char new_code; + uint8_t code = new_status[1]; tcp_frame_t tcp_frame; - unsigned char i; - code = new_status[1] & 0x3F; - toggle = new_status[1] & 0x40; - check = new_status[1] & 0x80; - - if (last_remote_key == code) + /* This bit should always be 1 in the current protocol when an IR signal is + * received (meaning the remote button is pressed). */ + if ((code & 0x80) == 0) { - if (last_toggle_key == toggle) - new_code = 0; - else - { - last_remote_key = code; - last_toggle_key = toggle; - new_code = 1; - } + /* We consider the button to be released otherwise. */ + tux_status.buttons.RC5_receiving = false; + return; } - else - { - last_remote_key = code; - last_toggle_key = toggle; - new_code = 1; - } - if (new_code) + tux_status.buttons.RC5_receiving = true; + ir_timeout = IR_TIMEOUT; + + /* Keep toggle and value. */ + code &= 0x7F; + + if (code != tux_status.buttons.RC5_code) { - log_debug("Remote code : %.2x", code); + tux_status.buttons.RC5_code = code; + /* Remove the toggle for logging. */ + log_debug("IR RC5 code : %.2x", code & 0x3F); - for (i = 0; i < sizeof(tcp_frame); i++) - tcp_frame[i] = '\0'; + tcp_frame_zero(&tcp_frame); tcp_frame[0] = SOURCE_TUX; tcp_frame[1] = SS_DEFAULT; @@ -607,6 +607,23 @@ tcp_server_send_raw(tcp_frame); } +/** + * Called each time there's a new status series sent by tux. + * This function can be used to defer operations after a couple of status. + */ +static void new_status_from_tux(void) +{ + if (ir_timeout) + if (!--ir_timeout) + { + unsigned char tmp[] = {0, 0, 0}; + /* Sending 0 here indicates that the button is not pressed anymore. + * Other parameters are not taken into account so sending 0 is + * enough. */ + update_ir(tmp); + } +} + /************************************************************************ */ /* update_raw_status_table() */ /************************************************************************ */ @@ -631,9 +648,12 @@ break; case STATUS_SENSORS1_CMD: + /* This is the first status sent by tux when sending all status each + * 100ms approximately. */ + new_status_from_tux(); if (sensors1.Byte != new_status[1]) sensors1_changed(new_status[1]); - + tux_status.audio.play_internal_sound = new_status[2]; tux_status.audio.streaming = new_status[3]; audio_event(new_status[2], new_status[3]); @@ -649,6 +669,9 @@ { int light_level; light_level = (new_status[1] << 8) + new_status[2]; + /* This combines the 2 light level types of measurement into one + * single value (there are 2 values for the polarizing resistor of + * the photodiode. */ if (new_status[3] == 0) light_level = light_level / 8 + 1000; /* 1128 is the maximum value when there is no light Modified: daemon/trunk/libs/USBDaemon_status_table.h =================================================================== --- daemon/trunk/libs/USBDaemon_status_table.h 2007-11-27 11:20:02 UTC (rev 734) +++ daemon/trunk/libs/USBDaemon_status_table.h 2007-11-27 14:57:05 UTC (rev 735) @@ -296,7 +296,9 @@ CHARGER_INHIBITED = 4, /**< the CPU has inhibited the charger */ } charger_status_t; -/** States of the battery level */ +/** States of the battery level + * \todo TODO write the function that would compute the battery state depending + * on the battery voltage, load and charger status */ typedef enum battery_status { FULL, @@ -305,7 +307,6 @@ EMPTY, } battery_status_t; - /** * Tux status table. * @@ -351,8 +352,6 @@ space remaining in the flash */ } sound_flash; - - /** Battery status. * 'loaded' can be used to filter out 'level' measurements that occurred * when the motors were running as the battery voltage is highly affected @@ -377,8 +376,7 @@ bool streaming; /**< Set when audio data is streamed through the RF link */ bool mute; /**< Set when the amplifier has been muted */ - audiorec_status_t record_state; /**< XXX need to define the enum for - the states */ + audiorec_status_t record_state; /**< States of the recording process */ unsigned int record; unsigned int last_block_size; } audio; @@ -389,6 +387,18 @@ bool head; /**< Head push button */ bool left_flipper; /**< Left flipper push button */ bool right_flipper; /**< Right flipper push button */ + uint8_t RC5_code; /**< Last code of the Tuxdroid remote button pressed. + - Bit 6 is the toggle bit, it's toggled each time you + press a remote key and should be used to + differentiate successive key presses of the same + button. + - Bits 5-0 are the 6 bits RC5 command code. */ + bool RC5_receiving; /**< Set when the remote button is pressed, cleared + when released. If you're clicking the remote + buttons very quickly, RC5_receiving will miss the + button releases in between. You should use the + toggle bit of the remote code to differentiate + successive key presses. */ } buttons; /** Raw I/O status */ |