[tuxdroid-svn] r446 - daemon/trunk/libs
Status: Beta
Brought to you by:
ks156
From: neimad <c2m...@c2...> - 2007-06-24 17:10:52
|
Author: neimad Date: 2007-06-24 19:10:50 +0200 (Sun, 24 Jun 2007) New Revision: 446 Modified: daemon/trunk/libs/USBDaemon_status_table.c daemon/trunk/libs/USBDaemon_status_table.h Log: * Made lots of functions static. Modified: daemon/trunk/libs/USBDaemon_status_table.c =================================================================== --- daemon/trunk/libs/USBDaemon_status_table.c 2007-06-24 16:56:22 UTC (rev 445) +++ daemon/trunk/libs/USBDaemon_status_table.c 2007-06-24 17:10:50 UTC (rev 446) @@ -58,130 +58,8 @@ /*_____________________ F U N C T I O N S __________________________________*/ -/************************************************************************ */ - -/* update_raw_status_table() */ - -/************************************************************************ */ -void update_raw_status_table(const unsigned char *new_status) +static void update_version_table(const unsigned char *new_status) { - switch (new_status[0]) - { - case STATUS_ID_CMD: - /* The answer from the usb_tux_connection command has been received */ - connection_status.usb_request_f = false; - connection_status.tux_id = (new_status[1] << 8) + new_status[2]; - log_debug("id retunred by tux: %i (0x%.2x%.2x)", - connection_status.tux_id, new_status[1], new_status[2]); - break; - case STATUS_PORTS_CMD: - if (portb.Byte != new_status[1]) - portb_changed(new_status[1]); - if (portc.Byte != new_status[2]) - portc_changed(new_status[2]); - if (portd.Byte != new_status[3]) - portd_changed(new_status[3]); - break; - - case STATUS_SENSORS1_CMD: - if (sensors1.Byte != new_status[1]) - sensors1_changed(new_status[1]); - break; - - case STATUS_LIGHT_CMD: - if (sensors2.level_light_high.Byte != new_status[1] - || sensors2.level_light_low.Byte != new_status[2]) - sensors2_changed(new_status[1], new_status[2], new_status[3]); - break; - - case STATUS_POSITION1_CMD: - if (position1.eyes_position.Byte != new_status[1] - || position1.mouth_position.Byte != new_status[2] - || position1.wings_position.Byte != new_status[3]) - position1_changed(new_status[1], new_status[2], new_status[3]); - break; - - case STATUS_POSITION2_CMD: - if (position2.Byte != new_status[1]) - position2_changed(new_status[1]); - break; - - case PONG_CMD: - pong_received++; - pong_event(new_status[1], pong_received); - break; - - case VERSION_CMD: - update_version_table(new_status); - break; - - case REVISION_CMD: - update_revision_table(new_status); - break; - - case AUTHOR_CMD: - update_author_table(new_status); - break; - - case SOUND_VAR_CMD: - update_sound_flash_count(new_status); - break; - - case STATUS_IR_CMD: - update_ir(new_status); - break; - - default: - if (show_invalid_raw) - log_debug("%.2x %.2x %.2x %.2x", new_status[0], new_status[1], - new_status[2], new_status[3]); - break; - } -} - -/************************************************************************ */ - -/* update_system_status_table() */ - -/************************************************************************ */ -void update_system_status_table(const unsigned char *new_status) -{ - tcp_frame_t tcp_frame; - - tcp_frame_zero(&tcp_frame); - - tcp_frame[0] = SOURCE_TUX; - tcp_frame[1] = SS_DEFAULT; - tcp_frame[2] = DATA_TP_RSP; - tcp_frame[3] = SUBDATA_TP_STATUS; - - DONGLE_status = new_status[0]; - - /*RF status change */ - if (RF_status != new_status[1]) - { - RF_status = new_status[1]; - tcp_frame[4] = DATA_STATUS_RF_CONNECTED; - tcp_frame[5] = RF_status; - tcp_server_send_raw(tcp_frame); - } - - /* Command status change */ - if (CMD_status != new_status[2]) - { - CMD_status = new_status[2]; - if (CMD_status == ACK_CMD_OK || CMD_status == ACK_CMD_KO) - cmd_status_flag = 0; - } -} - -/************************************************************************ */ - -/* update_version_table() */ - -/************************************************************************ */ -void update_version_table(const unsigned char *new_status) -{ unsigned long tmp; version_t *hw_ver; @@ -192,12 +70,7 @@ hw_version[last_cpu_ver] = *hw_ver; } -/************************************************************************ */ - -/* update_revision_table() */ - -/************************************************************************ */ -void update_revision_table(const unsigned char *new_status) +static void update_revision_table(const unsigned char *new_status) { unsigned long tmp; revision_t *hw_rev; @@ -208,12 +81,7 @@ hw_revision[last_cpu_ver] = *hw_rev; } -/************************************************************************ */ - -/* update_author_table() */ - -/************************************************************************ */ -void update_author_table(const unsigned char *new_status) +static void update_author_table(const unsigned char *new_status) { unsigned long tmp; author_t *hw_aut; @@ -224,22 +92,12 @@ hw_author[last_cpu_ver] = *hw_aut; } -/************************************************************************ */ - -/* update_sound_flash_count() */ - -/************************************************************************ */ -void update_sound_flash_count(const unsigned char *new_status) +static void update_sound_flash_count(const unsigned char *new_status) { sound_flash_count = new_status[1]; } -/************************************************************************ */ - -/* update_ir() */ - -/************************************************************************ */ -void update_ir(const unsigned char *new_status) +static void update_ir(const unsigned char *new_status) { unsigned char code; unsigned char toggle; @@ -288,12 +146,76 @@ } } -/************************************************************************ */ +static void sensors1_changed(unsigned char new_value) +{ + tcp_frame_t tcp_frame; -/* pong_event() */ + tcp_frame_zero(&tcp_frame); -/************************************************************************ */ -void pong_event(unsigned char pong_number, unsigned char pong_received) + tcp_frame[0] = SOURCE_TUX; + tcp_frame[1] = SS_DEFAULT; + tcp_frame[2] = DATA_TP_RSP; + tcp_frame[3] = SUBDATA_TP_STATUS; + + /* Left wing push */ + if ((sensors1.Byte & 0x01) != (new_value & 0x01)) + { + tcp_frame[4] = DATA_STATUS_LEFT_WING_PUSH; + tcp_frame[5] = !sensors1.bits.PB0; + log_debug("Left wing button %s", tcp_frame[5] ? "Down" : "Up"); + tcp_server_send_raw(tcp_frame); + } + + /* Right wing push */ + if ((sensors1.Byte & 0x02) != (new_value & 0x02)) + { + tcp_frame[4] = DATA_STATUS_RIGHT_WING_PUSH; + tcp_frame[5] = !sensors1.bits.PB1; + log_debug("Right wing button %s", tcp_frame[5] ? "Down" : "Up"); + tcp_server_send_raw(tcp_frame); + } + + /* power plug insertion switch */ + if ((sensors1.Byte & 0x04) != (new_value & 0x04)) + { + tcp_frame[4] = DATA_STATUS_POWER_PLUG_SWITCH; + tcp_frame[5] = !sensors1.bits.PB2; + log_debug("power plug insertion switch %s", tcp_frame[5] ? "off" : "on"); + tcp_server_send_raw(tcp_frame); + } + + /* Head push */ + if ((sensors1.Byte & 0x08) != (new_value & 0x08)) + { + tcp_frame[4] = DATA_STATUS_HEAD_PUSH_SWITCH; + tcp_frame[5] = !sensors1.bits.PB3; + log_debug("Head button %s", tcp_frame[5] ? "Down" : "Up"); + tcp_server_send_raw(tcp_frame); + } + + /* Led charger */ + if ((sensors1.Byte & 0x10) != (new_value & 0x10)) + { + tcp_frame[4] = DATA_STATUS_CHARGER_LED_STATUS; + tcp_frame[5] = sensors1.bits.PB4; + log_debug("Charger led %d", tcp_frame[5]); + tcp_server_send_raw(tcp_frame); + } + + /* mute status */ + if ((sensors1.Byte & 0x80) != (new_value & 0x80)) + { + tcp_frame[4] = DATA_STATUS_MUTE_STATUS; + tcp_frame[5] = !sensors1.bits.PB7; + log_debug("mute status %s", tcp_frame[5] ? "on" : "off"); + tcp_server_send_raw(tcp_frame); + } + + sensors1.Byte = new_value; +} + +static void sensors2_changed(unsigned char new_value_high, unsigned char new_value_low, + unsigned char new_light_mode) { tcp_frame_t tcp_frame; @@ -303,6 +225,27 @@ tcp_frame[1] = SS_DEFAULT; tcp_frame[2] = DATA_TP_RSP; tcp_frame[3] = SUBDATA_TP_STATUS; + + tcp_frame[4] = DATA_STATUS_LIGHT_LEVEL; + + sensors2.level_light_high.Byte = new_value_high; + sensors2.level_light_low.Byte = new_value_low; + sensors2.light_mode.Byte = new_light_mode; + + tcp_frame[5] = new_value_high; + tcp_frame[6] = new_value_low; +} + +static void pong_event(unsigned char pong_number, unsigned char pong_received) +{ + tcp_frame_t tcp_frame; + + tcp_frame_zero(&tcp_frame); + + tcp_frame[0] = SOURCE_TUX; + tcp_frame[1] = SS_DEFAULT; + tcp_frame[2] = DATA_TP_RSP; + tcp_frame[3] = SUBDATA_TP_STATUS; tcp_frame[4] = DATA_STATUS_PONG; tcp_frame[5] = pong_number; tcp_frame[6] = pong_received; @@ -310,12 +253,13 @@ tcp_server_send_raw(tcp_frame); } + /************************************************************************ */ /* portb_changed() */ /************************************************************************ */ -void portb_changed(unsigned char new_value) +static void portb_changed(unsigned char new_value) { tcp_frame_t tcp_frame; @@ -388,7 +332,7 @@ /* portc_changed() */ /************************************************************************ */ -void portc_changed(unsigned char new_value) +static void portc_changed(unsigned char new_value) { tcp_frame_t tcp_frame; @@ -435,7 +379,7 @@ /* portd_changed() */ /************************************************************************ */ -void portd_changed(unsigned char new_value) +static void portd_changed(unsigned char new_value) { tcp_frame_t tcp_frame; @@ -513,12 +457,15 @@ portd.Byte = new_value; } + /************************************************************************ */ -/* sensors1_changed() */ +/* position1_changed() */ /************************************************************************ */ -void sensors1_changed(unsigned char new_value) +static void position1_changed(unsigned char eyes_position, + unsigned char mouth_position, + unsigned char wings_position) { tcp_frame_t tcp_frame; @@ -529,70 +476,37 @@ tcp_frame[2] = DATA_TP_RSP; tcp_frame[3] = SUBDATA_TP_STATUS; - /* Left wing push */ - if ((sensors1.Byte & 0x01) != (new_value & 0x01)) + if (position1.eyes_position.Byte != eyes_position) { - tcp_frame[4] = DATA_STATUS_LEFT_WING_PUSH; - tcp_frame[5] = !sensors1.bits.PB0; - log_debug("Left wing button %s", tcp_frame[5] ? "Down" : "Up"); + position1.eyes_position.Byte = eyes_position; + tcp_frame[4] = DATA_STATUS_EYES_POSITION_COUNTER; + tcp_frame[5] = eyes_position; tcp_server_send_raw(tcp_frame); } - /* Right wing push */ - if ((sensors1.Byte & 0x02) != (new_value & 0x02)) + if (position1.mouth_position.Byte != mouth_position) { - tcp_frame[4] = DATA_STATUS_RIGHT_WING_PUSH; - tcp_frame[5] = !sensors1.bits.PB1; - log_debug("Right wing button %s", tcp_frame[5] ? "Down" : "Up"); + position1.mouth_position.Byte = mouth_position; + tcp_frame[4] = DATA_STATUS_MOUTH_POSITION_COUNTER; + tcp_frame[5] = mouth_position; tcp_server_send_raw(tcp_frame); } - /* power plug insertion switch */ - if ((sensors1.Byte & 0x04) != (new_value & 0x04)) + if (position1.wings_position.Byte != wings_position) { - tcp_frame[4] = DATA_STATUS_POWER_PLUG_SWITCH; - tcp_frame[5] = !sensors1.bits.PB2; - log_debug("power plug insertion switch %s", tcp_frame[5] ? "off" : "on"); + position1.wings_position.Byte = wings_position; + tcp_frame[4] = DATA_STATUS_WINGS_POSITION_COUNTER; + tcp_frame[5] = wings_position; tcp_server_send_raw(tcp_frame); } - - /* Head push */ - if ((sensors1.Byte & 0x08) != (new_value & 0x08)) - { - tcp_frame[4] = DATA_STATUS_HEAD_PUSH_SWITCH; - tcp_frame[5] = !sensors1.bits.PB3; - log_debug("Head button %s", tcp_frame[5] ? "Down" : "Up"); - tcp_server_send_raw(tcp_frame); - } - - /* Led charger */ - if ((sensors1.Byte & 0x10) != (new_value & 0x10)) - { - tcp_frame[4] = DATA_STATUS_CHARGER_LED_STATUS; - tcp_frame[5] = sensors1.bits.PB4; - log_debug("Charger led %d", tcp_frame[5]); - tcp_server_send_raw(tcp_frame); - } - - /* mute status */ - if ((sensors1.Byte & 0x80) != (new_value & 0x80)) - { - tcp_frame[4] = DATA_STATUS_MUTE_STATUS; - tcp_frame[5] = !sensors1.bits.PB7; - log_debug("mute status %s", tcp_frame[5] ? "on" : "off"); - tcp_server_send_raw(tcp_frame); - } - - sensors1.Byte = new_value; } /************************************************************************ */ -/* sensors2_changed() */ +/* position2_changed() */ /************************************************************************ */ -void sensors2_changed(unsigned char new_value_high, unsigned char new_value_low, - unsigned char new_light_mode) +static void position2_changed(unsigned char spin_position) { tcp_frame_t tcp_frame; @@ -603,65 +517,100 @@ tcp_frame[2] = DATA_TP_RSP; tcp_frame[3] = SUBDATA_TP_STATUS; - tcp_frame[4] = DATA_STATUS_LIGHT_LEVEL; + tcp_frame[4] = DATA_STATUS_SPIN_POSITION_COUNTER; + position2.Byte = spin_position; + tcp_frame[5] = spin_position; - sensors2.level_light_high.Byte = new_value_high; - sensors2.level_light_low.Byte = new_value_low; - sensors2.light_mode.Byte = new_light_mode; - - tcp_frame[5] = new_value_high; - tcp_frame[6] = new_value_low; + tcp_server_send_raw(tcp_frame); } /************************************************************************ */ -/* position1_changed() */ +/* update_raw_status_table() */ /************************************************************************ */ -void position1_changed(unsigned char eyes_position, - unsigned char mouth_position, - unsigned char wings_position) +void update_raw_status_table(const unsigned char *new_status) { - tcp_frame_t tcp_frame; + switch (new_status[0]) + { + case STATUS_ID_CMD: + /* The answer from the usb_tux_connection command has been received */ + connection_status.usb_request_f = false; + connection_status.tux_id = (new_status[1] << 8) + new_status[2]; + log_debug("id retunred by tux: %i (0x%.2x%.2x)", + connection_status.tux_id, new_status[1], new_status[2]); + break; + case STATUS_PORTS_CMD: + if (portb.Byte != new_status[1]) + portb_changed(new_status[1]); + if (portc.Byte != new_status[2]) + portc_changed(new_status[2]); + if (portd.Byte != new_status[3]) + portd_changed(new_status[3]); + break; - tcp_frame_zero(&tcp_frame); + case STATUS_SENSORS1_CMD: + if (sensors1.Byte != new_status[1]) + sensors1_changed(new_status[1]); + break; - tcp_frame[0] = SOURCE_TUX; - tcp_frame[1] = SS_DEFAULT; - tcp_frame[2] = DATA_TP_RSP; - tcp_frame[3] = SUBDATA_TP_STATUS; + case STATUS_LIGHT_CMD: + if (sensors2.level_light_high.Byte != new_status[1] + || sensors2.level_light_low.Byte != new_status[2]) + sensors2_changed(new_status[1], new_status[2], new_status[3]); + break; - if (position1.eyes_position.Byte != eyes_position) - { - position1.eyes_position.Byte = eyes_position; - tcp_frame[4] = DATA_STATUS_EYES_POSITION_COUNTER; - tcp_frame[5] = eyes_position; - tcp_server_send_raw(tcp_frame); - } + case STATUS_POSITION1_CMD: + if (position1.eyes_position.Byte != new_status[1] + || position1.mouth_position.Byte != new_status[2] + || position1.wings_position.Byte != new_status[3]) + position1_changed(new_status[1], new_status[2], new_status[3]); + break; - if (position1.mouth_position.Byte != mouth_position) - { - position1.mouth_position.Byte = mouth_position; - tcp_frame[4] = DATA_STATUS_MOUTH_POSITION_COUNTER; - tcp_frame[5] = mouth_position; - tcp_server_send_raw(tcp_frame); - } + case STATUS_POSITION2_CMD: + if (position2.Byte != new_status[1]) + position2_changed(new_status[1]); + break; - if (position1.wings_position.Byte != wings_position) - { - position1.wings_position.Byte = wings_position; - tcp_frame[4] = DATA_STATUS_WINGS_POSITION_COUNTER; - tcp_frame[5] = wings_position; - tcp_server_send_raw(tcp_frame); + case PONG_CMD: + pong_received++; + pong_event(new_status[1], pong_received); + break; + + case VERSION_CMD: + update_version_table(new_status); + break; + + case REVISION_CMD: + update_revision_table(new_status); + break; + + case AUTHOR_CMD: + update_author_table(new_status); + break; + + case SOUND_VAR_CMD: + update_sound_flash_count(new_status); + break; + + case STATUS_IR_CMD: + update_ir(new_status); + break; + + default: + if (show_invalid_raw) + log_debug("%.2x %.2x %.2x %.2x", new_status[0], new_status[1], + new_status[2], new_status[3]); + break; } } /************************************************************************ */ -/* position2_changed() */ +/* update_system_status_table() */ /************************************************************************ */ -void position2_changed(unsigned char spin_position) +void update_system_status_table(const unsigned char *new_status) { tcp_frame_t tcp_frame; @@ -672,9 +621,22 @@ tcp_frame[2] = DATA_TP_RSP; tcp_frame[3] = SUBDATA_TP_STATUS; - tcp_frame[4] = DATA_STATUS_SPIN_POSITION_COUNTER; - position2.Byte = spin_position; - tcp_frame[5] = spin_position; + DONGLE_status = new_status[0]; - tcp_server_send_raw(tcp_frame); + /*RF status change */ + if (RF_status != new_status[1]) + { + RF_status = new_status[1]; + tcp_frame[4] = DATA_STATUS_RF_CONNECTED; + tcp_frame[5] = RF_status; + tcp_server_send_raw(tcp_frame); + } + + /* Command status change */ + if (CMD_status != new_status[2]) + { + CMD_status = new_status[2]; + if (CMD_status == ACK_CMD_OK || CMD_status == ACK_CMD_KO) + cmd_status_flag = 0; + } } Modified: daemon/trunk/libs/USBDaemon_status_table.h =================================================================== --- daemon/trunk/libs/USBDaemon_status_table.h 2007-06-24 16:56:22 UTC (rev 445) +++ daemon/trunk/libs/USBDaemon_status_table.h 2007-06-24 17:10:50 UTC (rev 446) @@ -264,35 +264,10 @@ uint16_t tux_id; /** id of the tux which is currently connected or was last connected */ uint8_t wifi_channel; /** wifi channel that the RF modules will avoid; set to 0 to disable this function */ }; + extern struct connection_status_t connection_status; -/*_____________________ F U N C T I O N S __________________________________*/ extern void update_raw_status_table(const unsigned char *new_status); extern void update_system_status_table(const unsigned char *new_status); -extern void update_version_table(const unsigned char *new_status); -extern void update_revision_table(const unsigned char *new_status); - -extern void update_author_table(const unsigned char *new_status); - -extern void update_sound_flash_count(const unsigned char *new_status); - -extern void update_ir(const unsigned char *new_status); - -extern void pong_event(unsigned char pong_number, unsigned char pong_received); - -extern void portb_changed(unsigned char new_value); -extern void portc_changed(unsigned char new_value); -extern void portd_changed(unsigned char new_value); - -extern void sensors1_changed(unsigned char new_value); -extern void sensors2_changed(unsigned char new_value_high, - unsigned char new_value_low, - unsigned char new_light_mode); - -extern void position1_changed(unsigned char eyes_position, - unsigned char mouth_position, - unsigned char wings_position); -extern void position2_changed(unsigned char new_value); - #endif |