[tuxdroid-svn] r734 - daemon/trunk/libs
Status: Beta
Brought to you by:
ks156
From: jaguarondi <c2m...@c2...> - 2007-11-27 11:20:04
|
Author: jaguarondi Date: 2007-11-27 12:20:02 +0100 (Tue, 27 Nov 2007) New Revision: 734 Modified: daemon/trunk/libs/USBDaemon_status_table.c daemon/trunk/libs/USBDaemon_status_table.h Log: * Update the status of the charger, now the charger state is correctly detected. * Added push buttons to the status. * Added some raw io to the status that are necessary to compute other status but shouldn't be sent to clients as is (like the LED charger pin, inhibit signal, power plug switch, etc.) Modified: daemon/trunk/libs/USBDaemon_status_table.c =================================================================== --- daemon/trunk/libs/USBDaemon_status_table.c 2007-11-27 10:18:44 UTC (rev 733) +++ daemon/trunk/libs/USBDaemon_status_table.c 2007-11-27 11:20:02 UTC (rev 734) @@ -75,6 +75,34 @@ log_debug("the last block used is : %d ", tux_status.sound_flash.flash_usage); } +/** + * Update the charger state according to the current status and previous state. + */ +static void update_charger_state(void) +{ + charger_status_t *state = &tux_status.battery.charger_state; + + /* Priority to unplugged. */ + if (!tux_status.io.plugged) + *state = CHARGER_UNPLUGGED; + /* Plugged, is is charging? */ + else if (!tux_status.io.charger_led_signal) + *state = CHARGER_CHARGING; + + /* TODO add *state = CHARGER_PLUGGED_NO_POWER; when it will be implemented + * in firmware. + * Plugged, not charging, do we have power? */ + + /* There's power but doesn't fast charge, is charge inhibited? */ + else if (tux_status.io.charge_inhibit) + *state = CHARGER_INHIBITED; + /* We should be in trickle mode then. */ + else + *state = CHARGER_TRICKLE; + + log_debug("charger state: %d", *state); +} + static void update_ir(const unsigned char *new_status) { unsigned char code; @@ -135,67 +163,65 @@ tcp_frame[2] = DATA_TP_RSP; tcp_frame[3] = SUBDATA_TP_STATUS; - /* Left wing push */ + /* Left wing button. */ if ((sensors1.Byte & 0x01) != (new_value & 0x01)) { + tux_status.buttons.left_flipper = (sensors1.Byte & 0x01) ? false : true; + log_debug("Left flipper %s", tux_status.buttons.left_flipper ? + "pushed" : "released"); + 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 */ + /* Right wing button. */ if ((sensors1.Byte & 0x02) != (new_value & 0x02)) { + tux_status.buttons.right_flipper = (sensors1.Byte & 0x02) ? false : true; + log_debug("Right flipper %s", tux_status.buttons.right_flipper ? + "pushed" : "released"); + 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)) + /* Power plug insertion switch and LED signal of the charger. + * Note that due to the capacitor on the plug switch, the LED signal is + * changed (meaning charging) slightly before the plug is detected (the + * pull-up and capacitor slow down the switch detection). */ + if ((sensors1.Byte & 0x14) != (new_value & 0x14)) { - 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"); + printf("sensors1: %.2x\n",sensors1.Byte); + tux_status.io.plugged = (sensors1.Byte & 0x04) ? true : false; + log_debug("io: power cable %s", + tux_status.io.plugged ? "plugged" : "unplugged"); + + tux_status.io.charger_led_signal = + (sensors1.Byte & 0x10) ? true : false; + log_debug("io: charger LED %s", tux_status.io.charger_led_signal ? + "high" : "low"); + update_charger_state(); + + tcp_frame[4] = DATA_STATUS_CHARGER_STATUS; + tcp_frame[5] = tux_status.battery.charger_state; tcp_server_send_raw(tcp_frame); } - /* Head push */ + /* Head button. */ if ((sensors1.Byte & 0x08) != (new_value & 0x08)) { + tux_status.buttons.head = (sensors1.Byte & 0x08) ? false : true; + log_debug("Head button %s", tux_status.buttons.head ? + "pressed" : "released"); + 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_STATUS; - - /* XXX should be removed when charger status will be added in firmware, - * now using this simplified status. */ - if (sensors1.bits.PB4) - { - tux_status.battery.charger_state = CHARGER_UNPLUGGED; - tcp_frame[5] = CHARGER_UNPLUGGED; - } - else - { - tux_status.battery.charger_state = CHARGER_CHARGING; - tcp_frame[5] = CHARGER_CHARGING; - } - - /*tcp_frame[5] = sensors1.bits.PB4;*/ - log_debug("Charger led %d", tcp_frame[5]); - tcp_server_send_raw(tcp_frame); - } - - /* mute status */ + /* Mute status. */ if ((sensors1.Byte & 0x80) != (new_value & 0x80)) { tcp_frame[4] = DATA_STATUS_MUTE_STATUS; @@ -369,6 +395,18 @@ tcp_server_send_raw(tcp_frame); } + /* The head push button is sampled by both tuxcore (here) and tuxaudio + * (sensors1) so we don't have to reprocess it here. */ + + /* Charge inhibit signal */ + if ((portb.Byte & 0x40) != (new_value & 0x40)) + { + tux_status.io.charge_inhibit = (portb.Byte & 0x40) ? true : false; + log_debug("io: charge %s", tux_status.io.charge_inhibit ? + "inhibitted" : "allowed"); + update_charger_state(); + } + portb.Byte = new_value; } Modified: daemon/trunk/libs/USBDaemon_status_table.h =================================================================== --- daemon/trunk/libs/USBDaemon_status_table.h 2007-11-27 10:18:44 UTC (rev 733) +++ daemon/trunk/libs/USBDaemon_status_table.h 2007-11-27 11:20:02 UTC (rev 734) @@ -366,6 +366,7 @@ float voltage; /**< Mean battery voltage */ battery_status_t status;/**< Battery level status (low, high, etc.) */ charger_status_t charger_state; /**<Battery charger state. */ + } battery; /** Audio status */ @@ -381,6 +382,26 @@ unsigned int record; unsigned int last_block_size; } audio; + + /** Raw I/O status */ + struct buttons_t + { + bool head; /**< Head push button */ + bool left_flipper; /**< Left flipper push button */ + bool right_flipper; /**< Right flipper push button */ + } buttons; + + /** Raw I/O status */ + struct io_t + { + bool plugged; /**< Power plug insertion switch, set when the + transformer is plugged to tux */ + bool charger_led_signal; /**< LED signal of the BQ2002T IC charger. + Goes low when fast charging, high otherwise + (trickle, not charging, init, etc. See the + datasheet for details. */ + bool charge_inhibit; + } io; }; /** |