[tuxdroid-svn] r301 - daemon/trunk/libs
Status: Beta
Brought to you by:
ks156
From: neimad <c2m...@c2...> - 2007-05-02 16:42:27
|
Author: neimad Date: 2007-05-02 18:42:22 +0200 (Wed, 02 May 2007) New Revision: 301 Modified: daemon/trunk/libs/USBDaemon_status_table.c Log: * Simplified the status change functions a bit. The pattern is the almost always the same and thus this could be further simplified (with shifting instead of bitfields, too). Modified: daemon/trunk/libs/USBDaemon_status_table.c =================================================================== --- daemon/trunk/libs/USBDaemon_status_table.c 2007-05-02 15:44:16 UTC (rev 300) +++ daemon/trunk/libs/USBDaemon_status_table.c 2007-05-02 16:42:22 UTC (rev 301) @@ -329,16 +329,8 @@ if ((portb.Byte & 0x01) != (new_value & 0x01)) { tcp_frame[4] = DATA_STATUS_WINGS_MOTOR_BACKWARD; - if (portb.bits.PB0) - { - log_debug("wings motor backward 0"); - tcp_frame[5] = 0; - } - else - { - log_debug("wings motor backward 1"); - tcp_frame[5] = 1; - } + tcp_frame[5] = !portb.bits.PB0; + log_debug("wings motor backward %d", tcp_frame[5]); tcp_server_send_raw(tcp_frame); } @@ -346,16 +338,8 @@ if ((portb.Byte & 0x02) != (new_value & 0x02)) { tcp_frame[4] = DATA_STATUS_SPIN_MOTOR_BACKWARD; - if (portb.bits.PB1) - { - log_debug("spin motor backward 0"); - tcp_frame[5] = 0; - } - else - { - log_debug("spin motor backward 1"); - tcp_frame[5] = 1; - } + tcp_frame[5] = !portb.bits.PB1; + log_debug("spin motor backward %d", tcp_frame[5]); tcp_server_send_raw(tcp_frame); } @@ -363,16 +347,8 @@ if ((portb.Byte & 0x04) != (new_value & 0x04)) { tcp_frame[4] = DATA_STATUS_SPIN_MOTOR_FORWARD; - if (portb.bits.PB2) - { - log_debug("spin motor forward 0"); - tcp_frame[5] = 0; - } - else - { - log_debug("spin motor forward 1"); - tcp_frame[5] = 1; - } + tcp_frame[5] = !portb.bits.PB2; + log_debug("spin motor forward %d", tcp_frame[5]); tcp_server_send_raw(tcp_frame); } @@ -380,18 +356,8 @@ if ((portb.Byte & 0x08) != (new_value & 0x08)) { tcp_frame[4] = DATA_STATUS_MOUTH_OPEN_POSITION; - if (portb.bits.PB3) - { - /* Up */ - log_debug("mouth open position 0"); - tcp_frame[5] = 0; - } - else - { - /* Down */ - log_debug("mouth open position 1"); - tcp_frame[5] = 1; - } + tcp_frame[5] = !portb.bits.PB3; + log_debug("mouth open position %d", tcp_frame[5]); tcp_server_send_raw(tcp_frame); } @@ -399,16 +365,8 @@ if ((portb.Byte & 0x10) != (new_value & 0x10)) { tcp_frame[4] = DATA_STATUS_MOUTH_CLOSED_POSITION; - if (portb.bits.PB4) - { - log_debug("mouth close position 0"); - tcp_frame[5] = 0; - } - else - { - log_debug("mouth close position 1"); - tcp_frame[5] = 1; - } + tcp_frame[5] = !portb.bits.PB4; + log_debug("mouth close position %d", tcp_frame[5]); tcp_server_send_raw(tcp_frame); } @@ -416,16 +374,8 @@ if ((portb.Byte & 0x40) != (new_value & 0x40)) { tcp_frame[4] = DATA_STATUS_CHARGER_INHIBIT_SIGNAL; - if (portb.bits.PB6) - { - log_debug("charger inhibit signal 0"); - tcp_frame[5] = 0; - } - else - { - log_debug("charger inhibit signal 1"); - tcp_frame[5] = 1; - } + tcp_frame[5] = !portb.bits.PB6; + log_debug("charger inhibit signal %d", tcp_frame[5]); tcp_server_send_raw(tcp_frame); } @@ -454,16 +404,9 @@ if ((portc.Byte & 0x02) != (new_value & 0x02)) { tcp_frame[4] = DATA_STATUS_WINGS_POSITION_SWITCH; - if (portc.bits.PB1) - { - log_debug("wings position switch 0"); - tcp_frame[5] = 0; - } - else - { - log_debug("wings position switch 1"); - tcp_frame[5] = 1; - } + tcp_frame[5] = !portc.bits.PB1; + log_debug("wings position switch %d", tcp_frame[5]); + tcp_frame[5] = 0; tcp_server_send_raw(tcp_frame); } @@ -471,16 +414,8 @@ if ((portc.Byte & 0x04) != (new_value & 0x04)) { tcp_frame[4] = DATA_STATUS_RIGHT_BLUE_LED; - if (portc.bits.PB2) - { - log_debug("right blue led off"); - tcp_frame[5] = 0; - } - else - { - log_debug("right blue led on"); - tcp_frame[5] = 1; - } + tcp_frame[5] = !portc.bits.PB2; + log_debug("right blue led %s", tcp_frame[0] ? "on" : "off"); tcp_server_send_raw(tcp_frame); } @@ -488,16 +423,8 @@ if ((portc.Byte & 0x08) != (new_value & 0x08)) { tcp_frame[4] = DATA_STATUS_LEFT_BLUE_LED; - if (portc.bits.PB3) - { - log_debug("left blue led off"); - tcp_frame[5] = 0; - } - else - { - log_debug("left blue led on"); - tcp_frame[5] = 1; - } + tcp_frame[5] = !portc.bits.PB3; + log_debug("left blue led %s", tcp_frame[5] ? "on" : "off"); tcp_server_send_raw(tcp_frame); } @@ -526,16 +453,8 @@ if ((portd.Byte & 0x01) != (new_value & 0x01)) { tcp_frame[4] = DATA_STATUS_HEAD_MOTOR_FOR_EYES; - if (portd.bits.PB0) - { - log_debug("head motor for eyes 0"); - tcp_frame[5] = 0; - } - else - { - log_debug("head motor for eyes 1"); - tcp_frame[5] = 1; - } + tcp_frame[5] = !portd.bits.PB0; + log_debug("head motor for eyes %d", tcp_frame[5]); tcp_server_send_raw(tcp_frame); } @@ -543,16 +462,8 @@ if ((portd.Byte & 0x02) != (new_value & 0x02)) { tcp_frame[4] = DATA_STATUS_HEAD_MOTOR_FOR_MOUTH; - if (portd.bits.PB1) - { - log_debug("head motor for mouth 0"); - tcp_frame[5] = 0; - } - else - { - log_debug("head motor for mouth 1"); - tcp_frame[5] = 1; - } + tcp_frame[5] = !portd.bits.PB1; + log_debug("head motor for mouth %d", tcp_frame[5]); tcp_server_send_raw(tcp_frame); } @@ -560,16 +471,8 @@ if ((portd.Byte & 0x08) != (new_value & 0x08)) { tcp_frame[4] = DATA_STATUS_SPIN_POSITION_SWITCH; - if (portd.bits.PB3) - { - log_debug("spin position switch 0"); - tcp_frame[5] = 0; - } - else - { - log_debug("spin position switch 1"); - tcp_frame[5] = 1; - } + tcp_frame[5] = !portd.bits.PB3; + log_debug("spin position switch %d", tcp_frame[5]); tcp_server_send_raw(tcp_frame); } @@ -577,16 +480,9 @@ if ((portd.Byte & 0x10) != (new_value & 0x10)) { tcp_frame[4] = DATA_STATUS_WINGS_MOTOR_FORWARD; - if (portd.bits.PB4) - { - log_debug("wings motor forward 0"); - tcp_frame[5] = 0; - } - else - { - log_debug("wings motor forward 1"); - tcp_frame[5] = 1; - } + tcp_frame[5] = !portd.bits.PB4; + log_debug("wings motor forward %d", tcp_frame[5]); + tcp_frame[5] = 0; tcp_server_send_raw(tcp_frame); } @@ -594,16 +490,8 @@ if ((portd.Byte & 0x20) != (new_value & 0x20)) { tcp_frame[4] = DATA_STATUS_IR_LED; - if (portd.bits.PB5) - { - log_debug("IR led 0"); - tcp_frame[5] = 0; - } - else - { - log_debug("IR led 1"); - tcp_frame[5] = 1; - } + tcp_frame[5] = !portd.bits.PB5; + log_debug("IR led %d", tcp_frame[5]); tcp_server_send_raw(tcp_frame); } @@ -611,16 +499,8 @@ if ((portd.Byte & 0x40) != (new_value & 0x40)) { tcp_frame[4] = DATA_STATUS_EYES_OPEN_POSITION_SWITCH; - if (portd.bits.PB6) - { - log_debug("eyes open position switch 0"); - tcp_frame[5] = 0; - } - else - { - log_debug("eyes open position switch 1"); - tcp_frame[5] = 1; - } + tcp_frame[5] = !portd.bits.PB6; + log_debug("eyes open position switch %d", tcp_frame[5]); tcp_server_send_raw(tcp_frame); } @@ -628,16 +508,8 @@ if ((portd.Byte & 0x80) != (new_value & 0x80)) { tcp_frame[4] = DATA_STATUS_EYES_CLOSED_POSITION_SWITCH; - if (portd.bits.PB7) - { - log_debug("eyes closed position switch 0"); - tcp_frame[5] = 0; - } - else - { - log_debug("eyes closed position switch 1"); - tcp_frame[5] = 1; - } + tcp_frame[5] = !portd.bits.PB7; + log_debug("eyes closed position switch %d", tcp_frame[5]); tcp_server_send_raw(tcp_frame); } @@ -666,16 +538,8 @@ if ((sensors1.Byte & 0x01) != (new_value & 0x01)) { tcp_frame[4] = DATA_STATUS_LEFT_WING_PUSH; - if (sensors1.bits.PB0) - { - log_debug("Left wing button Up"); - tcp_frame[5] = 0; - } - else - { - log_debug("Left wing button Down"); - tcp_frame[5] = 1; - } + tcp_frame[5] = !sensors1.bits.PB0; + log_debug("Left wing button %s", tcp_frame[5] ? "Down" : "Up"); tcp_server_send_raw(tcp_frame); } @@ -683,16 +547,8 @@ if ((sensors1.Byte & 0x02) != (new_value & 0x02)) { tcp_frame[4] = DATA_STATUS_RIGHT_WING_PUSH; - if (sensors1.bits.PB1) - { - log_debug("Right wing button Up"); - tcp_frame[5] = 0; - } - else - { - log_debug("Right wing button Down"); - tcp_frame[5] = 1; - } + tcp_frame[5] = !sensors1.bits.PB1; + log_debug("Right wing button %s", tcp_frame[5] ? "Down" : "Up"); tcp_server_send_raw(tcp_frame); } @@ -700,16 +556,8 @@ if ((sensors1.Byte & 0x04) != (new_value & 0x04)) { tcp_frame[4] = DATA_STATUS_POWER_PLUG_SWITCH; - if (sensors1.bits.PB2) - { - log_debug("power plug insertion switch on"); - tcp_frame[5] = 0; - } - else - { - log_debug("power plug insertion switch off"); - tcp_frame[5] = 1; - } + tcp_frame[5] = !sensors1.bits.PB2; + log_debug("power plug insertion switch %s", tcp_frame[5] ? "off" : "on"); tcp_server_send_raw(tcp_frame); } @@ -717,16 +565,8 @@ if ((sensors1.Byte & 0x08) != (new_value & 0x08)) { tcp_frame[4] = DATA_STATUS_HEAD_PUSH_SWITCH; - if (sensors1.bits.PB3) - { - log_debug("Head button Up"); - tcp_frame[5] = 0; - } - else - { - log_debug("Head button Down"); - tcp_frame[5] = 1; - } + tcp_frame[5] = !sensors1.bits.PB3; + log_debug("Head button %s", tcp_frame[5] ? "Down" : "Up"); tcp_server_send_raw(tcp_frame); } @@ -734,16 +574,8 @@ if ((sensors1.Byte & 0x10) != (new_value & 0x10)) { tcp_frame[4] = DATA_STATUS_CHARGER_LED_STATUS; - if (sensors1.bits.PB4) - { - log_debug("Charger led 1"); - tcp_frame[5] = 1; - } - else - { - log_debug("Charger led 0"); - tcp_frame[5] = 0; - } + tcp_frame[5] = sensors1.bits.PB4; + log_debug("Charger led %d", tcp_frame[5]); tcp_server_send_raw(tcp_frame); } @@ -751,16 +583,8 @@ if ((sensors1.Byte & 0x80) != (new_value & 0x80)) { tcp_frame[4] = DATA_STATUS_MUTE_STATUS; - if (sensors1.bits.PB7) - { - log_debug("mute status off"); - tcp_frame[5] = 0; - } - else - { - log_debug("mute status on"); - tcp_frame[5] = 1; - } + tcp_frame[5] = !sensors1.bits.PB7; + log_debug("mute status %s", tcp_frame[5] ? "on" : "off"); tcp_server_send_raw(tcp_frame); } |