[tuxdroid-svn] r829 - api/python/trunk
Status: Beta
Brought to you by:
ks156
From: jaguarondi <c2m...@c2...> - 2008-01-04 16:48:52
|
Author: jaguarondi Date: 2008-01-04 17:48:54 +0100 (Fri, 04 Jan 2008) New Revision: 829 Modified: api/python/trunk/tuxapi_class.py Log: * Updated the python API to support the pulse effect of the LEDs. Modified: api/python/trunk/tuxapi_class.py =================================================================== --- api/python/trunk/tuxapi_class.py 2008-01-04 16:47:57 UTC (rev 828) +++ api/python/trunk/tuxapi_class.py 2008-01-04 16:48:54 UTC (rev 829) @@ -2321,8 +2321,9 @@ Example: >>> tux.cmd.leds_blink(10,25) """ - self.last_ack=self.structured(TUX_CMD_STRUCT_LEDS, \ - TUX_CMD_STRUCT_SUB_BLINK,count,delay,0) + self.last_ack=self.estructured(TUX_CMD_STRUCT_LEDS, + TUX_CMD_STRUCT_SUB_PULSE, 3, 0, 255, + count, delay, 2, 0, 0) #-------------------------------------------------------------------------- # Send a command to tux for turning the leds off @@ -2523,9 +2524,9 @@ "leds" as enum : Which LEDs are affected by the command (0=LED_NONE, 1=LED_LEFT, 2=LED_RIGHT, 3=LED_BOTH) - intensity as int 8bits : Value of the intensity the LEDs should be + intensity as int : Value of the intensity the LEDs should be set to (0..255). - effect_type : Fading or gradient effect applied when + effect_type as enum : Fading or gradient effect applied when changing the intensity. The values are: - 0=UNAFFECTED Don't update the effect parameters. This can either be the @@ -2561,8 +2562,8 @@ - GRADIENT_DELTA=7 Gradient effect, the intensity changes by a delta value of 'effect_step'. - effect_speed : See above. - effect_step : See above. + effect_speed as int : See above. + effect_step as int : See above. Example: >>> tux.cmd.led_set(3, 0xFF, 4, 0.5, 0) @@ -2573,6 +2574,8 @@ effect_speed = 1.0/16 if effect_step > 255: effect_step = 255 + # workaround to send a float over TCP/IP in the current API: + # effect_speed is multiplied by 16 self.last_ack=self.estructured(TUX_CMD_STRUCT_LEDS, TUX_CMD_STRUCT_SUB_SET, leds, intensity, effect_type, int(effect_speed*16), effect_step) @@ -2580,10 +2583,98 @@ #-------------------------------------------------------------------------- # Mapping of the daemon command to pulse the LEDs. #-------------------------------------------------------------------------- - def led_pulse(self): - # XXX to write - pass + def led_pulse(self, leds, min_intensity, max_intensity, pulse_count, + pulse_period, effect_type, effect_speed, effect_step): + """ + Pulses the LEDs with an effect. This is the raw function provided by + the daemon and is not the easiest to use. See the daemon API + documentation for details. New functions have to be created and this + one probably will have to be removed or kept for debug purposes only. + We don't send floats through TCP/IP (effect_speed and effect_step), we + just multiply by 16 and divide by the same value on the other side. So + the boundaries are 1/16 to 15. + + Parameters: + See the daemon API for details. + "leds" as enum : Which LEDs are affected by the command + (0=LED_NONE, 1=LED_LEFT, 2=LED_RIGHT, + 3=LED_BOTH) + min_intensity as int : Value of the intensity the LEDs should be + set to (0..255). + max_intensity as int : Value of the intensity the LEDs should be + set to (0..255). + pulse_count as int : Number of toggles before pusling stops. + pulse_period as float : Period between 2 pulses, in seconds. + effect_type as enum : Fading or gradient effect applied when + changing the intensity. The values are: + - 0=UNAFFECTED Don't update the effect + parameters. This can either be the + last effect set by software, or by + firmware in the autonomous mode. This + is probably not what you want. + - LAST=1 Last effect requested by + software. + - NONE=2 Don't use effects, equivalent + to on/off mode. + - DEFAULT=3 Default effect which is a + short fading effect. + - FADE_DURATION=4 Fading effect, + 'effect_speed' sets the duration (in + seconds) the effect will last. + - FADE_RATE=5 Fading effect, + 'effect_speed' sets the rate of the + effect. Its value represents the + number of seconds it takes to apply the + effect from off to on. So the actual + effect duration will take less time + than specified if the intensity starts + or ends at intermediate values. + Therefore this parameter guarantees a + constant rate of the effect, not the + duration. + - GRADIENT_NBR=6 Gradient effect, the + intensity changes gradually by a number + of steps given by 'effect_step'. + 'effect_speed' represents the number of + seconds it should take to apply the + effect. + - GRADIENT_DELTA=7 Gradient effect, the + intensity changes by a delta value of + 'effect_step'. + effect_speed as int : See above. + effect_step as int : See above. + + 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. + + Example: + >>> tux.cmd.led_pulse(3, 0x0, 0x80, 6, 0.7, 4, 0.3, 5) + """ + if effect_speed > 15: + effect_speed = 15 + if effect_speed < 1.0/16: + effect_speed = 1.0/16 + if effect_step > 255: + effect_step = 255 + if pulse_count > 255: + pulse_count = 255 + if pulse_period > 1: + pulse_period = 1 + if (pulse_period <= 0): + return + if (max_intensity <= min_intensity): + return + # workaround to send a float over TCP/IP in the current API: + # pulse_period is multiplied by 250 + # effect_speed is multiplied by 16 + self.last_ack=self.estructured(TUX_CMD_STRUCT_LEDS, + TUX_CMD_STRUCT_SUB_PULSE, leds, min_intensity, max_intensity, + pulse_count, int(250 * pulse_period), effect_type, + int(effect_speed*16), effect_step) + #-------------------------------------------------------------------------- # Send a command to tux for playing a sound from the flash memory #-------------------------------------------------------------------------- |