[tuxdroid-svn] r798 - in firmware: tuxcore/trunk tuxdefs
Status: Beta
Brought to you by:
ks156
From: jaguarondi <c2m...@c2...> - 2007-12-14 16:42:44
|
Author: jaguarondi Date: 2007-12-14 17:42:38 +0100 (Fri, 14 Dec 2007) New Revision: 798 Modified: firmware/tuxcore/trunk/led.c firmware/tuxcore/trunk/led.h firmware/tuxcore/trunk/main.c firmware/tuxcore/trunk/parser.c firmware/tuxdefs/api.h firmware/tuxdefs/config.h Log: * Now sending LED status and did some cleanup. Modified: firmware/tuxcore/trunk/led.c =================================================================== --- firmware/tuxcore/trunk/led.c 2007-12-14 13:34:39 UTC (rev 797) +++ firmware/tuxcore/trunk/led.c 2007-12-14 16:42:38 UTC (rev 798) @@ -31,6 +31,8 @@ /** Buffer the LEDs values before being applied on the I/O port. */ uint8_t leds_buffer = 0; +/** Flag set when the LED status changed. */ +bool led_f; /** Left LED status structure. */ led_t left_led = @@ -294,6 +296,8 @@ { if (!led->var.speed_cnt) { + /* LED status is changing. */ + led_f = true; if (led->command.setpoint > led->status.intensity) { if (led->status.intensity + led->command.step @@ -355,7 +359,7 @@ This function should be called at a regular interval, which is the time basis for the delays. */ -static inline void control_call(led_t *led) +static inline void control_effects(led_t *led) { /* Do we need fading? */ if (led->status.fading) @@ -388,9 +392,18 @@ */ void led_control(bool mask) { - control_call(&left_led); - control_call(&right_led); + static bool previous_mask = false; + if (previous_mask != mask) + { + previous_mask = mask; + /* LED status is changing. */ + led_f = true; + } + + control_effects(&left_led); + control_effects(&right_led); + /* This circumvent the bug we have when the OCR values are too low (<5 it * seems), interrupt priority of the comparisons is higher than the * overflow so when 2 interrupts occurs nearly simultaneously, the compare Modified: firmware/tuxcore/trunk/led.h =================================================================== --- firmware/tuxcore/trunk/led.h 2007-12-14 13:34:39 UTC (rev 797) +++ firmware/tuxcore/trunk/led.h 2007-12-14 16:42:38 UTC (rev 798) @@ -74,6 +74,7 @@ extern led_t left_led; extern led_t right_led; +extern bool led_f; void led_init(void); void led_shutdown(void); Modified: firmware/tuxcore/trunk/main.c =================================================================== --- firmware/tuxcore/trunk/main.c 2007-12-14 13:34:39 UTC (rev 797) +++ firmware/tuxcore/trunk/main.c 2007-12-14 16:42:38 UTC (rev 798) @@ -276,6 +276,19 @@ FifoPut(statusFifo, spin_move_counter); FifoPut(statusFifo, gStatus.pos); FifoPut(statusFifo, 0); + if (led_f) + { + led_f = false; + FifoPut(statusFifo, STATUS_LED_CMD); + FifoPut(statusFifo, left_led.status.intensity); + FifoPut(statusFifo, right_led.status.intensity); + FifoPut(statusFifo, left_led.status.fading | + (left_led.status.pulsing << 1) | + (right_led.status.fading << 2) | + (right_led.status.pulsing << 3) | + /* Also add the mask. */ + (cond_flags.eyes_closed << 4)); + } if (sensorsStatus & LIGHT_FLAG) /* send light measurement */ { sensorsStatus &= ~LIGHT_FLAG; Modified: firmware/tuxcore/trunk/parser.c =================================================================== --- firmware/tuxcore/trunk/parser.c 2007-12-14 13:34:39 UTC (rev 797) +++ firmware/tuxcore/trunk/parser.c 2007-12-14 16:42:38 UTC (rev 798) @@ -133,11 +133,11 @@ stop_spinning(); } /* Leds */ - else if (command[0] == LED_BLINK_RANGE_CMD) + else if (command[0] == LED_PULSE_RANGE_CMD) { led_pulse_range(command[1], command[2], command[3]); } - else if (command[0] == LED_BLINK_CMD) + else if (command[0] == LED_PULSE_CMD) { led_pulse(command[1], command[2], command[3]); } Modified: firmware/tuxdefs/api.h =================================================================== --- firmware/tuxdefs/api.h 2007-12-14 13:34:39 UTC (rev 797) +++ firmware/tuxdefs/api.h 2007-12-14 16:42:38 UTC (rev 798) @@ -197,16 +197,16 @@ * @{ */ /** - * Set the rate and step which determine the speed of the fading effect. + * Set the speed and step which determine the speed of the fading effect. * - * The fading increases or decreases the intensity by 'step' each 'rate' times + * The fading increases or decreases the intensity by 'step' each 'speed' times * 4ms. * * Parameters: * - 1 - LEDs affected by the command, either left, right or both. * The values are defined in LEDS_t. - * - 2 - rate of the fading effect, the time base is 4ms. - * A value from 1 to 255 will change the rate, + * - 2 - speed of the fading effect, the time base is 4ms. + * A value from 1 to 255 will change the speed, * 0 will leave it unaffected. * - 3 - step of the fading effect. * A value from 1 to 255 will change the step, @@ -216,7 +216,7 @@ /** * Set both LEDs to a given intensity with a fading effect controlled by - * 'rate' and 'step'. + * 'speed' and 'step'. * * Parameters: * - 1 - Which LEDs. @@ -226,32 +226,59 @@ #define LED_SET_CMD 0xD1 /** - * Set the intensity boundaries for the blink command. + * Set the intensity boundaries for the pulse command. * * Parameters: * - 1 - Which LEDs. * - 2 - Maximum intensity. * - 3 - Minimum intensity. */ -#define LED_BLINK_RANGE_CMD 0xD2 +#define LED_PULSE_RANGE_CMD 0xD2 /** - * Blink LEDs 'number' times with a frequency determined by 'pulse_width'. + * Pulse LEDs 'number' times with a frequency determined by 'pulse_width'. * * Parameters: * - 1 - Which LEDs * - 2 - Number of toggles the LED should do. - * - 3 - Pulse width of the blinking effect. Affected by the fading effect. + * - 3 - Pulse width of the pulsing effect. 0 is ignored. The value from 1 + * to 255 represents half the delay, in 4ms unit, between 2 pulses. * * The pulse width won't be shorter than what is set for the fading effect, - * even if you set a low value here. + * even if you set a low value here. If the pulse width is larger than the + * fading period, then a pause will occur after fading in order to meet the + * pulse width. */ -#define LED_BLINK_CMD 0xD3 +#define LED_PULSE_CMD 0xD3 /*! @} */ +/** + * \name Status and return values + * These commands are sent by tux to the computer instead of the opposite and + * usually represent tux's status. + * @{ */ + +/** + * LEDs status, both intensities and whether any effect is ongoing. + * + * Parameters: + * - 1 - Intensity of the left LED + * - 2 - Intensity of the right LED + * - 3 - Effects status + * - .0: Left LED fading + * - .1: Left LED pulsing + * - .3: Right LED fading + * - .4: Right LED pulsing + * - .5: LED mask, if set the LEDs are not lit even though the + * intensity is non zero. + */ +#define STATUS_LED_CMD 0xCE + /*! @} */ +/*! @} */ + /** States of the audio recording (flash programming) process */ typedef enum audiorec_status { Modified: firmware/tuxdefs/config.h =================================================================== --- firmware/tuxdefs/config.h 2007-12-14 13:34:39 UTC (rev 797) +++ firmware/tuxdefs/config.h 2007-12-14 16:42:38 UTC (rev 798) @@ -50,28 +50,28 @@ /* Head button event */ #define HEAD_E_SEQ {\ 0, LED_FADE_SPEED_CMD, 3, 1, 10, \ - 0, LED_BLINK_CMD, 3, 2, 30, /* blink led's once */\ + 0, LED_PULSE_CMD, 3, 2, 30, /* Pulse LEDs once */\ END_OF_ACTIONS\ } /* Left flipper button event */ #define LEFT_FLIP_E_SEQ {\ 0, LED_FADE_SPEED_CMD, 3, 1, 10, \ - 0, LED_BLINK_CMD, 3, 2, 30, /* blink led's once */\ + 0, LED_PULSE_CMD, 3, 2, 30, /* Pulse LEDs once */\ END_OF_ACTIONS\ } /* Right flipper event */ #define RIGHT_FLIP_E_SEQ {\ 0, LED_FADE_SPEED_CMD, 3, 1, 10, \ - 0, LED_BLINK_CMD, 3, 2, 30, /* blink led's once */\ + 0, LED_PULSE_CMD, 3, 2, 30, /* Pulse LEDs once */\ END_OF_ACTIONS\ } /* Start charging event */ #define CHARGER_START_E_SEQ {\ 0, MOVE_MOUTH_CMD, 2, 0, 0, /* move the mouth */\ - 0, LED_BLINK_CMD, 3, 4, 50, /* blink led's twice */\ + 0, LED_PULSE_CMD, 3, 4, 50, /* Pulse LEDs twice */\ 0, PLAY_SOUND_CMD, 3, 0, 0, /* play a sound */\ END_OF_ACTIONS\ } |