[tuxdroid-svn] r825 - api/python/trunk
Status: Beta
Brought to you by:
ks156
From: jaguarondi <c2m...@c2...> - 2008-01-04 13:49:15
|
Author: jaguarondi Date: 2008-01-04 14:49:15 +0100 (Fri, 04 Jan 2008) New Revision: 825 Modified: api/python/trunk/tuxapi_class.py api/python/trunk/tuxapi_const.py Log: * Added a mapping of the daemon command led_set() in order to test the new LED effects. The other LED functions have been updated to use the default effect. Modified: api/python/trunk/tuxapi_class.py =================================================================== --- api/python/trunk/tuxapi_class.py 2008-01-04 13:11:19 UTC (rev 824) +++ api/python/trunk/tuxapi_class.py 2008-01-04 13:49:15 UTC (rev 825) @@ -1851,6 +1851,21 @@ return self.cmd_ack() #-------------------------------------------------------------------------- + # Send an extended structured command to tux + #-------------------------------------------------------------------------- + def estructured(self,fct,cmd,param1,param2,param3, param4=0, param5=0, + param6=0, param7=0, param8=0, param9=0, param10=0): + if not self.parent.daemon.connected: + return 2 + data=(DEST_TUX,SD_DEFAULT,DATA_TP_CMD,SUBDATA_TP_STRUCT, \ + fct,cmd,param1,param2,param3,param4,param5,param6, + param7,param8,param9,param10) + self.parent._sock_send_frame("".join( [chr(x) for x in data] )) + if self.no_ack: + return 2 + else: + return self.cmd_ack() + #-------------------------------------------------------------------------- # Send a raw command to tux #-------------------------------------------------------------------------- def raw(self,cmd,param1,param2,param3): @@ -2290,7 +2305,7 @@ >>> tux.cmd.leds_on() """ self.last_ack=self.structured(TUX_CMD_STRUCT_LEDS, \ - TUX_CMD_STRUCT_SUB_ON,0,0,0) + TUX_CMD_STRUCT_SUB_SET,3,255,3) #-------------------------------------------------------------------------- # Send a command to tux for blinking the leds @@ -2320,7 +2335,7 @@ >>> tux.cmd.leds_off() """ self.last_ack=self.structured(TUX_CMD_STRUCT_LEDS, \ - TUX_CMD_STRUCT_SUB_OFF,0,0,0) + TUX_CMD_STRUCT_SUB_SET,3,0,3) #-------------------------------------------------------------------------- # Send a command to tux for turning the leds on during a specified time @@ -2369,8 +2384,8 @@ Example: >>> tux.cmd.ledl_on() """ - self.last_ack=self.structured(TUX_CMD_STRUCT_LEDL, \ - TUX_CMD_STRUCT_SUB_ON,0,0,0) + self.last_ack=self.structured(TUX_CMD_STRUCT_LEDS, \ + TUX_CMD_STRUCT_SUB_SET, 1, 255, 3) #-------------------------------------------------------------------------- # Send a command to tux for turning the left led off @@ -2382,8 +2397,8 @@ Example: >>> tux.cmd.ledl_off() """ - self.last_ack=self.structured(TUX_CMD_STRUCT_LEDL, \ - TUX_CMD_STRUCT_SUB_OFF,0,0,0) + self.last_ack=self.structured(TUX_CMD_STRUCT_LEDS, \ + TUX_CMD_STRUCT_SUB_SET, 1, 0, 3) #-------------------------------------------------------------------------- # Send a command to tux for turning the left led on during a specified time @@ -2433,8 +2448,8 @@ Example: >>> tux.cmd.ledr_on() """ - self.last_ack=self.structured(TUX_CMD_STRUCT_LEDR, \ - TUX_CMD_STRUCT_SUB_ON,0,0,0) + self.last_ack=self.structured(TUX_CMD_STRUCT_LEDS, \ + TUX_CMD_STRUCT_SUB_SET,2,255,3) #-------------------------------------------------------------------------- # Send a command to tux for turning the right led off @@ -2446,8 +2461,8 @@ Example: >>> tux.cmd.ledr_off() """ - self.last_ack=self.structured(TUX_CMD_STRUCT_LEDR, \ - TUX_CMD_STRUCT_SUB_OFF,0,0,0) + self.last_ack=self.structured(TUX_CMD_STRUCT_LEDS, \ + TUX_CMD_STRUCT_SUB_SET,2,0,3) #-------------------------------------------------------------------------- # Send a command to tux for turning the right led on during a specified @@ -2489,6 +2504,87 @@ self.parent.daemon.free_thread_list.append(t) #-------------------------------------------------------------------------- + # Mapping of the daemon command to set the LEDs. + #-------------------------------------------------------------------------- + def led_set(self, leds, intensity, effect_type, effect_speed, effect_step): + """ + Set the LEDs intensity 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) + intensity as int 8bits : Value of the intensity the LEDs should be + set to (0..255). + effect_type : 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 : See above. + effect_step : See above. + + Example: + >>> tux.cmd.led_set(3, 0xFF, 4, 0.5, 0) + """ + 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 + self.last_ack=self.estructured(TUX_CMD_STRUCT_LEDS, + TUX_CMD_STRUCT_SUB_SET, leds, intensity, effect_type, + int(effect_speed*16), effect_step) + + #-------------------------------------------------------------------------- + # Mapping of the daemon command to pulse the LEDs. + #-------------------------------------------------------------------------- + def led_pulse(self): + # XXX to write + pass + + #-------------------------------------------------------------------------- # Send a command to tux for playing a sound from the flash memory #-------------------------------------------------------------------------- def sound_play(self,index,volume=0): Modified: api/python/trunk/tuxapi_const.py =================================================================== --- api/python/trunk/tuxapi_const.py 2008-01-04 13:11:19 UTC (rev 824) +++ api/python/trunk/tuxapi_const.py 2008-01-04 13:49:15 UTC (rev 825) @@ -314,6 +314,8 @@ TUX_CMD_STRUCT_SUB_CLOSE = 0x0D TUX_CMD_STRUCT_SUB_DOWN = 0x0D TUX_CMD_STRUCT_SUB_ERASE = 0x0E +TUX_CMD_STRUCT_SUB_SET = 0x0F +TUX_CMD_STRUCT_SUB_PULSE = 0x10 # Tux request information TUX_REQ_INFO_VERSION = 0x01 |