[tuxdroid-svn] r782 - firmware/tuxcore/trunk
Status: Beta
Brought to you by:
ks156
From: jaguarondi <c2m...@c2...> - 2007-12-12 13:29:39
|
Author: jaguarondi Date: 2007-12-12 14:01:00 +0100 (Wed, 12 Dec 2007) New Revision: 782 Modified: firmware/tuxcore/trunk/led.c firmware/tuxcore/trunk/led.h firmware/tuxcore/trunk/parser.c firmware/tuxcore/trunk/standalone.c Log: * Renamed a couple of variables. Modified: firmware/tuxcore/trunk/led.c =================================================================== --- firmware/tuxcore/trunk/led.c 2007-12-12 11:46:24 UTC (rev 781) +++ firmware/tuxcore/trunk/led.c 2007-12-12 13:01:00 UTC (rev 782) @@ -36,16 +36,16 @@ led_t left_led = { .command.step=2, - .command.rate=1, - .blink.max_intensity = 0xFF, + .command.delay=1, + .pulse.max_intensity = 0xFF, }; /** Right LED status structure. */ led_t right_led = { .command.step=2, - .command.rate=1, - .blink.max_intensity = 0xFF, + .command.delay=1, + .pulse.max_intensity = 0xFF, }; /** @@ -152,19 +152,19 @@ } /** - \brief Blink LEDs + \brief Pulse LEDs \ingroup led \param leds Which LEDs are affected by the command - \param cnt Number of blinks. 0 is ignored, 255 (0xFF) means infinite. - \param pulse_width Blinking pulse width. 0 is ignored. + \param cnt Number of pulses. 0 is ignored, 255 (0xFF) means infinite. + \param pulse_width Pulse width. 0 is ignored. The LEDs will be toggled 'cnt' times. The pulse width can be used to change the toggle frequency. If 'cnt' or 'pulse_width' are set to 0, the register is not updated so the old value is kept. - 'cnt' can be set to 255 to trigger an infinite blinking effect. + 'cnt' can be set to 255 to trigger an infinite pulsing effect. */ -void led_blink(LEDS_t leds, uint8_t const cnt, uint8_t const pulse_width) +void led_pulse(LEDS_t leds, uint8_t const cnt, uint8_t const pulse_width) { /* XXX we should really find a way to optimize this loop for the 2 leds. * We don't want to add a new function call, bu don't want to have the code @@ -184,27 +184,27 @@ leds &= ~LED_RIGHT; led = &right_led; } - led->status.blinking = true; - led->blink.pulse_width = pulse_width; + led->status.pulsing = true; + led->pulse.pulse_width = pulse_width; if (cnt) { - led->blink.count = cnt; + led->pulse.count = cnt; /* We can't simply set the flag here otherwise we alter the ongoing - * blinking. So we need to check for blinking first. */ - if (!led->var.blink_tmr) - led->var.blink_flag = true; + * pulsing. So we need to check for pulsing first. */ + if (!led->var.pulse_tmr) + led->var.pulse_flag = true; } } } /** - \brief Set the intensity boundaries for the blink command. + \brief Set the intensity boundaries for the pulse command. \ingroup led \param leds Which LEDs are affected by the command \param max Maximum intensity \param min Minimum intensity */ -void led_blink_range(LEDS_t leds, uint8_t const max, uint8_t const min) +void led_pulse_range(LEDS_t leds, uint8_t const max, uint8_t const min) { led_t *led = &left_led; @@ -220,19 +220,20 @@ leds &= ~LED_RIGHT; led = &right_led; } - led->blink.max_intensity = max; - led->blink.min_intensity = min; + led->pulse.max_intensity = max; + led->pulse.min_intensity = min; } } /** - \brief Set the rate and step which determine the speed of the fading effect. + \brief Set the delay and step which determine the speed of the fading effect. \ingroup led \param leds Which LEDs are affected by the command - \param rate Rate at which the intensity is changed. See struct led_comand. + \param delay Number of 4ms loops before the intensity is changed. See struct + led_command. \param step Intenisty step applied when fading. */ -void led_set_fade_speed(LEDS_t leds, uint8_t const rate, uint8_t const step) +void led_set_fade_speed(LEDS_t leds, uint8_t const delay, uint8_t const step) { led_t *led = &left_led; @@ -248,8 +249,8 @@ leds &= ~LED_RIGHT; led = &right_led; } - if (rate) - led->command.rate = rate; + if (delay) + led->command.delay = delay; if (step) led->command.step = step; } @@ -291,7 +292,7 @@ */ static void fading(led_t *led) { - if (!led->var.rate_cnt) + if (!led->var.speed_cnt) { if (led->command.setpoint > led->status.intensity) { @@ -318,54 +319,61 @@ else led->status.intensity -= led->command.step; } - led->var.rate_cnt = led->command.rate; + led->var.speed_cnt = led->command.delay; } - /* we decrease in all cases, i.e. if rate == 1, cnt will be set to 0 when + /* we decrease in all cases, i.e. if delay == 1, cnt will be set to 0 when * leaving the function and so will only loop one time */ - led->var.rate_cnt--; + led->var.speed_cnt--; } /** - \brief Handles the blinking effect. + \brief Handles the pulsing effect. \param led Pointer to the led structure - Set the new fading settings if more blinking has to be done. + Set the new fading settings if more pulsing has to be done. */ -static void blinking(led_t *led) +static void pulsing(led_t *led) { - /* Infinite blinking or next blink. */ - if ((led->blink.count == 0xFF) || --led->blink.count) - led->var.blink_tmr = led->blink.pulse_width; + /* Infinite pulsing or next pulse. */ + if ((led->pulse.count == 0xFF) || --led->pulse.count) + led->var.pulse_tmr = led->pulse.pulse_width; else - led->status.blinking = false; - if (led->status.intensity <= led->blink.min_intensity) - led->command.setpoint = led->blink.max_intensity; + led->status.pulsing = false; + if (led->status.intensity <= led->pulse.min_intensity) + led->command.setpoint = led->pulse.max_intensity; else - (led->command.setpoint = led->blink.min_intensity); + (led->command.setpoint = led->pulse.min_intensity); led->status.fading = true; /* Add the intermediate delay between 2 fades. */ - led->var.rate_cnt = led->command.rate; + led->var.speed_cnt = led->command.delay; } +/** + \brief Check when fading or pulsing need to be done. + \param led Pointer to the led structure + + 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) { /* Do we need fading? */ if (led->status.fading) fading(led); - /* Check the blinking pulse width. */ - if (led->var.blink_tmr) + /* Check the pulse width. */ + if (led->var.pulse_tmr) { - led->var.blink_tmr--; - if (!led->var.blink_tmr) - led->var.blink_flag = true; + led->var.pulse_tmr--; + if (!led->var.pulse_tmr) + led->var.pulse_flag = true; } if (!led->status.fading) - /* When fading is done, check if we need to blink again. */ - if (led->var.blink_flag) + /* When fading is done, check if we need to pulse again. */ + if (led->var.pulse_flag) { - blinking(led); - led->var.blink_flag = false; + pulsing(led); + led->var.pulse_flag = false; } } @@ -375,8 +383,8 @@ \param mask If set, masking is applied on the LEDs so they don't light. Used when the eyes are closed, it's neater. - This function should be called regularly as it controls the blinking. The - period this function is called will be the unit period of the led blinking. + This function should be called regularly as it controls the pulsing. The + period this function is called will be the unit period of the led pulsing. */ void led_control(bool mask) { Modified: firmware/tuxcore/trunk/led.h =================================================================== --- firmware/tuxcore/trunk/led.h 2007-12-12 11:46:24 UTC (rev 781) +++ firmware/tuxcore/trunk/led.h 2007-12-12 13:01:00 UTC (rev 782) @@ -38,7 +38,7 @@ /** \ingroup led LED status structure holding all information necessary to handle intensity, - fading and blinking effects. + fading and pulsing effects. */ typedef struct led_t { @@ -46,29 +46,29 @@ { uint8_t intensity; bool fading; - bool blinking; + bool pulsing; } status; struct led_command { uint8_t setpoint; - uint8_t rate; + uint8_t delay; uint8_t step; } command; - struct led_blink + struct led_pulse { uint8_t min_intensity; uint8_t max_intensity; - /** Number of times the LEDs should be toggled when blinking. */ + /** Number of times the LEDs should be toggled when pulsing. */ uint8_t count; - /** Delay between 2 toggles of the LEDs when blinking them. */ + /** Delay between 2 toggles of the LEDs when pulsing them. */ uint8_t pulse_width; - } blink; + } pulse; struct led_var { - uint8_t rate_cnt; + uint8_t speed_cnt; /** Timer for the delay between 2 toggles of the LEDs. */ - uint8_t blink_tmr; - bool blink_flag; + uint8_t pulse_tmr; + bool pulse_flag; } var; } led_t; @@ -77,11 +77,11 @@ void led_init(void); void led_shutdown(void); -void led_set_fade_speed(LEDS_t leds, uint8_t const rate, uint8_t const step); +void led_set_fade_speed(LEDS_t leds, uint8_t const delay, uint8_t const step); void led_set_intensity(LEDS_t leds, uint8_t const intensity); -void led_blink_range(LEDS_t leds, uint8_t const max, uint8_t const min); -void blink_led(led_t *const led, uint8_t const cnt, uint8_t const pulse_width); -void led_blink(LEDS_t led, uint8_t const cnt, uint8_t const pulse_width); +void led_pulse_range(LEDS_t leds, uint8_t const max, uint8_t const min); +void pulse_led(led_t *const led, uint8_t const cnt, uint8_t const pulse_width); +void led_pulse(LEDS_t led, uint8_t const cnt, uint8_t const pulse_width); void led_control(bool mask); #endif /* _LED_H_ */ Modified: firmware/tuxcore/trunk/parser.c =================================================================== --- firmware/tuxcore/trunk/parser.c 2007-12-12 11:46:24 UTC (rev 781) +++ firmware/tuxcore/trunk/parser.c 2007-12-12 13:01:00 UTC (rev 782) @@ -135,11 +135,11 @@ /* Leds */ else if (command[0] == LED_BLINK_RANGE_CMD) { - led_blink_range(command[1], command[2], command[3]); + led_pulse_range(command[1], command[2], command[3]); } else if (command[0] == LED_BLINK_CMD) { - led_blink(command[1], command[2], command[3]); + led_pulse(command[1], command[2], command[3]); } else if (command[0] == LED_FADE_SPEED_CMD) { @@ -232,9 +232,9 @@ { led_set_intensity(LED_RIGHT, 0x0); } - else if (command[0] == 0x9A) /* old blink function */ + else if (command[0] == 0x9A) /* old pulse function */ { - led_blink(3, command[1], command[2]); + led_pulse(3, command[1], command[2]); } /* Undefined commands */ Modified: firmware/tuxcore/trunk/standalone.c =================================================================== --- firmware/tuxcore/trunk/standalone.c 2007-12-12 11:46:24 UTC (rev 781) +++ firmware/tuxcore/trunk/standalone.c 2007-12-12 13:01:00 UTC (rev 782) @@ -231,7 +231,7 @@ /* IR feedback signal */ if (tux_config.ir_feedback) - led_blink(LED_BOTH, 2, 4); + led_pulse(LED_BOTH, 2, 4); /* ALT KEYS */ if (alt_mode) @@ -296,10 +296,10 @@ tux_config.ir_feedback = !tux_config.ir_feedback; break; case K_CHANNELPLUS: - led_blink(LED_RIGHT, 1, 0); + led_pulse(LED_RIGHT, 1, 0); break; case K_VOLUMEPLUS: - led_blink(LED_LEFT, 1, 0); + led_pulse(LED_LEFT, 1, 0); break; case K_FASTREWIND: if (spin_PWM) |