[tuxdroid-svn] r828 - in daemon/trunk: . libs
Status: Beta
Brought to you by:
ks156
From: jaguarondi <c2m...@c2...> - 2008-01-04 16:47:58
|
Author: jaguarondi Date: 2008-01-04 17:47:57 +0100 (Fri, 04 Jan 2008) New Revision: 828 Modified: daemon/trunk/led.c daemon/trunk/led.h daemon/trunk/libs/USBDaemon_command_tux.c Log: * Added functions to pulse the LEDs. Something similar to the blink function but now using effects too, and both eyes are independent. Modified: daemon/trunk/led.c =================================================================== --- daemon/trunk/led.c 2008-01-04 14:12:52 UTC (rev 827) +++ daemon/trunk/led.c 2008-01-04 16:47:57 UTC (rev 828) @@ -114,21 +114,10 @@ return ack; } -/** - * \brief Set the intensity of the LEDs. - * \param leds Which LEDs are affected by the command - * \param intensity Value of the intensity the LEDs should be set to. - * \param effect Fading or gradient effect applied when changing the intensity. - * - * \sa The effect types and parameters are described in the documentation of - * effect_type_t. - */ -int led_set(leds_t leds, int intensity, led_effect_t *effect) +int config_effects(leds_t leds, int left_intensity_delta, + int right_intensity_delta, led_effect_t *effect) { int ack; - /* Preconditions */ - assert(LED_NONE <= leds && leds <= LED_BOTH); - assert(0 <= intensity && intensity <= 255); switch(effect->type) { @@ -176,30 +165,27 @@ * If both leds are not at the same initial level, we can only * have the same duration by assigning different parameters to * each eye. */ - int left_increase, right_increase; /* Flag that indicates if nothing needs to be done. */ bool skip = true; /* We should use effect NONE if we don't want fading. */ assert(effect->speed > 0); - left_increase = abs(intensity - get_led_left_intensity()); - right_increase = abs(intensity - get_led_right_intensity()); /* Don't divide by zero if there's nothing to do ;-). */ - if (leds & LED_LEFT && left_increase) + if (leds & LED_LEFT && left_intensity_delta) { skip = false; ack = config_fading(LED_LEFT, effect->speed / \ - left_increase); + left_intensity_delta); /* XXX Due to bugs lying around in the dongle, RF and daemon, * we can't trust the ack, so disabled for now. */ /*if (ack != ACK_CMD_OK)*/ /*return ack;*/ } - if (leds & LED_RIGHT && right_increase) + if (leds & LED_RIGHT && right_intensity_delta) { skip = false; ack = config_fading(LED_RIGHT, effect->speed / \ - right_increase); + right_intensity_delta); } /* XXX Due to bugs lying around in the dongle, RF and daemon, * we can't trust the ack, so disabled for now. */ @@ -230,7 +216,6 @@ break; case GRADIENT_NBR: { - int left_increase, right_increase; int delta; /* Flag indicating if nothing needs to be done. */ bool skip = true; @@ -241,13 +226,11 @@ /* We should use effect NONE if we don't want gradient. */ assert(effect->speed > 0); - left_increase = abs(intensity - get_led_left_intensity()); - right_increase = abs(intensity - get_led_right_intensity()); /* Don't divide by zero if there's nothing to do ;-). */ - if (leds & LED_LEFT && left_increase) + if (leds & LED_LEFT && left_intensity_delta) { skip = false; - delta = roundf(left_increase / effect->step); + delta = roundf(left_intensity_delta / effect->step); /* If we can't have as many steps as required. */ if (delta == 0) delta = 1; @@ -258,10 +241,10 @@ /*if (ack != ACK_CMD_OK)*/ /*return ack;*/ } - if (leds & LED_RIGHT && right_increase) + if (leds & LED_RIGHT && right_intensity_delta) { skip = false; - delta = roundf(right_increase / effect->step); + delta = roundf(right_intensity_delta / effect->step); /* If we can't have as many steps as required. */ if (delta == 0) delta = 1; @@ -279,7 +262,6 @@ break; case GRADIENT_DELTA: { - int left_increase, right_increase; float gradient_delay; /* Flag indicating if nothing needs to be done. */ bool skip = true; @@ -290,25 +272,23 @@ /* We should use effect NONE if we don't want gradient. */ assert(effect->speed > 0); - left_increase = abs(intensity - get_led_left_intensity()); - right_increase = abs(intensity - get_led_right_intensity()); /* Don't divide by zero if there's nothing to do ;-). */ - if (leds & LED_LEFT && left_increase) + if (leds & LED_LEFT && left_intensity_delta) { skip = false; gradient_delay = effect->speed * effect->step / \ - left_increase; + left_intensity_delta; ack = config_gradient(LED_LEFT, effect->step, gradient_delay); /* XXX Due to bugs lying around in the dongle, RF and daemon, * we can't trust the ack, so disabled for now. */ /*if (ack != ACK_CMD_OK)*/ /*return ack;*/ } - if (leds & LED_RIGHT && right_increase) + if (leds & LED_RIGHT && right_intensity_delta) { skip = false; gradient_delay = effect->speed * effect->step / \ - right_increase; + right_intensity_delta; ack = config_gradient(LED_RIGHT, effect->step, gradient_delay); } /* XXX Due to bugs lying around in the dongle, RF and daemon, @@ -325,11 +305,80 @@ assert(0); break; } + return ack; +} + +/** + * \brief Set the intensity of the LEDs. + * \param leds Which LEDs are affected by the command + * \param intensity Value of the intensity the LEDs should be set to. + * \param effect Fading or gradient effect applied when changing the intensity. + * + * \sa The effect types and parameters are described in the documentation of + * effect_type_t. + */ +int led_set(leds_t leds, int intensity, led_effect_t *effect) +{ + int ack; + int left_intensity_delta, right_intensity_delta; + + /* Preconditions */ + assert(LED_NONE <= leds && leds <= LED_BOTH); + assert(0 <= intensity && intensity <= 255); + + left_intensity_delta = abs(intensity - get_led_left_intensity()); + right_intensity_delta = abs(intensity - get_led_right_intensity()); + ack = config_effects(leds, left_intensity_delta, right_intensity_delta, + effect); + /*if (ack != ACK_CMD_OK)*/ + /*return ack;*/ ack = send_usb_tux_cmd(LED_SET_CMD, leds, intensity, 0); return ack; } -void led_pulse(void) +/** + * \brief Pulse the LEDs. + * \param leds Which LEDs are affected by the command. + * \param min_intensity Value of the minimum intensity when pulsing. + * \param max_intensity Value of the maximum intensity when pulsing. + * \param toggle_count Number of toggles before pusling stops. + * \param pulse_period Period between 2 pulses, in seconds. + * \param effect Fading or gradient effect applied when changing the intensity. + * + * \sa The effect types and parameters are described in the documentation of + * effect_type_t. + * + * The effect duration has priority on the pulse period. If you set the pulse + * period to 0.2s but the fading effect to 0.5s, then you will have 2 effects + * per period (or per pulse) and the pulse period will spend 1s and not 0.2s. + */ +int led_pulse(leds_t leds, int min_intensity, int max_intensity, \ + int toggle_count, float pulse_period, led_effect_t *effect) { - /* XXX add pulsing here. */ + int ack; + /* Pulse width or duration of the pulse, in hardware loops. The pulse + * period is twice that number. */ + int pulse_width; + int delta; + + /* Preconditions */ + assert(LED_NONE <= leds && leds <= LED_BOTH); + assert(0 <= min_intensity && min_intensity <= 255); + assert(0 <= max_intensity && max_intensity <= 255); + assert(max_intensity > min_intensity); + assert(pulse_period > 0); + assert(toggle_count > 0); + + delta = max_intensity - min_intensity; + ack = config_effects(leds, delta, delta, effect); + + pulse_width = roundf(pulse_period/FW_MAIN_LOOP_DELAY/2); + if (pulse_width < 1) + pulse_width = 1; + if (pulse_width > 255) + pulse_width = 255; + ack = send_usb_tux_cmd(LED_PULSE_RANGE_CMD, leds, max_intensity, + min_intensity); + ack = send_usb_tux_cmd(LED_PULSE_CMD, leds, toggle_count, pulse_width); + return ack; } Modified: daemon/trunk/led.h =================================================================== --- daemon/trunk/led.h 2008-01-04 14:12:52 UTC (rev 827) +++ daemon/trunk/led.h 2008-01-04 16:47:57 UTC (rev 828) @@ -90,6 +90,8 @@ * Prototypes. */ extern int led_set(leds_t leds, int intensity, led_effect_t *effect); +extern int led_pulse(leds_t leds, int min_intensity, int max_intensity, \ + int toggle_count, float pulse_period, led_effect_t *effect); /*! @} */ #endif /* _LED_H_ */ Modified: daemon/trunk/libs/USBDaemon_command_tux.c =================================================================== --- daemon/trunk/libs/USBDaemon_command_tux.c 2008-01-04 14:12:52 UTC (rev 827) +++ daemon/trunk/libs/USBDaemon_command_tux.c 2008-01-04 16:47:57 UTC (rev 828) @@ -480,7 +480,17 @@ break; case TUX_CMD_STRUCT_SUB_PULSE: { - /* XXX add pulsing here. */ + led_effect_t effect; + effect.type = data[7]; + /* Workaround to send a float through TCP/IP, just send a + * uint8_t which is the float parameter multiplied by 16, then + * divide it here again. The limitation is of course the range. + * pulse_period is multiplied by 250. + */ + effect.speed = (float)data[8]/16; + effect.step = data[9]; + printf("%x %x %x %x %x %x %x %x \n",data[2], data[3], data[4], data[5], data[6], data[7], data[8], data[9]); + ACK = led_pulse(data[2], data[3], data[4], data[5], (float)data[6]/250, &effect); } break; } |