[tuxdroid-svn] r869 - api/python/trunk
Status: Beta
Brought to you by:
ks156
From: Paul_R <c2m...@c2...> - 2008-01-23 15:28:41
|
Author: Paul_R Date: 2008-01-23 16:28:39 +0100 (Wed, 23 Jan 2008) New Revision: 869 Modified: api/python/trunk/tuxapi_class.py api/python/trunk/tuxapi_const.py Log: * Changed all the LEDs functions to link them with the two new functions (tux.cmd.led_pulse && tux.cmd.led_set) I must create some new functions to use the LEDs effects Modified: api/python/trunk/tuxapi_class.py =================================================================== --- api/python/trunk/tuxapi_class.py 2008-01-23 11:59:48 UTC (rev 868) +++ api/python/trunk/tuxapi_class.py 2008-01-23 15:28:39 UTC (rev 869) @@ -1788,14 +1788,6 @@ tux.cmd.led_pulse : General command to configure the LEDs effects - tux.cmd.ledl_during - tux.cmd.ledl_during_free - tux.cmd.ledl_off - tux.cmd.ledl_on - tux.cmd.ledr_during - tux.cmd.ledr_during_free - tux.cmd.ledr_off - tux.cmd.ledr_on tux.cmd.leds_blink tux.cmd.leds_during tux.cmd.leds_during_free @@ -1803,7 +1795,7 @@ tux.cmd.leds_on Audio commands : - TTS : + Channel selection : tux.cmd.audio_channel_general tux.cmd.audio_channel_tts @@ -2616,219 +2608,9 @@ TUX_CMD_STRUCT_SUB_SEND,address,command,0) #-------------------------------------------------------------------------- - # Send a command to tux for turning the leds on - #-------------------------------------------------------------------------- - def leds_on(self): - """ - Send a command to tux for turning the leds on - - Example: - >>> tux.cmd.leds_on() - """ - self.last_ack=self.structured(TUX_CMD_STRUCT_LEDS, \ - TUX_CMD_STRUCT_SUB_SET,3,255,3) - - #-------------------------------------------------------------------------- - # Send a command to tux for blinking the leds - #-------------------------------------------------------------------------- - def leds_blink(self,count,delay): - """ - Send a command to tux for blinking the leds - - Parameters: - "count" as integer : number of blink(0..255) - "delay" as integer : delay between 2 states (u=4msec) - - Example: - >>> tux.cmd.leds_blink(10,25) - """ - 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 - #-------------------------------------------------------------------------- - def leds_off(self): - """ - Send a command to tux for turning the leds off - - Example: - >>> tux.cmd.leds_off() - """ - self.last_ack=self.structured(TUX_CMD_STRUCT_LEDS, \ - TUX_CMD_STRUCT_SUB_SET,3,0,3) - - #-------------------------------------------------------------------------- - # Send a command to tux for turning the leds on during a specified time - #-------------------------------------------------------------------------- - def leds_during(self,seconds): - """ - Send a command to tux for turning the leds on during a specified time - - Parameters: - "seconds" as float : time to wait in seconds - - Example: - >>> tux.cmd.leds_during(2.5) - """ - self.leds_on() - time.sleep(seconds) - self.leds_off() - - #-------------------------------------------------------------------------- - # Send a command to tux for turning the leds on during a specified time - # in free mode - #-------------------------------------------------------------------------- - def leds_during_free(self,seconds): - """ - Send a command to tux for turning the leds on during a specified time - in free mode - - Parameters: - "seconds" as float : time to wait in seconds - - Example: - >>> tux.cmd.leds_during_free(2.5) - """ - t=threading.Thread(target=self.leds_during,args=(seconds,)) - t.setName('cmd.leds_during') - t.start() - self.parent.daemon.free_thread_list.append(t) - - #-------------------------------------------------------------------------- - # Send a command to tux for turning the left led on - #-------------------------------------------------------------------------- - def ledl_on(self): - """ - Send a command to tux for turning the left led on - - Example: - >>> tux.cmd.ledl_on() - """ - 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 - #-------------------------------------------------------------------------- - def ledl_off(self): - """ - Send a command to tux for turning the left led off - - Example: - >>> tux.cmd.ledl_off() - """ - 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 - #-------------------------------------------------------------------------- - def ledl_during(self,seconds): - """ - Send a command to tux for turning the left led on during a specified - time - - Parameters: - "seconds" as float : time to wait in seconds - - Example: - >>> tux.cmd.ledl_during(2.5) - """ - self.ledl_on() - time.sleep(seconds) - self.ledl_off() - - #-------------------------------------------------------------------------- - # Send a command to tux for turning the left led on during a specified - # time in free mode - #-------------------------------------------------------------------------- - def ledl_during_free(self,seconds): - """ - Send a command to tux for turning the left led on during a specified - time in free mode - - Parameters: - "seconds" as float : time to wait in seconds - - Example: - >>> tux.cmd.ledl_during_free(2.5) - """ - t=threading.Thread(target=self.ledl_during,args=(seconds,)) - t.setName('cmd.ledl_during') - t.start() - self.parent.daemon.free_thread_list.append(t) - - #-------------------------------------------------------------------------- - # Send a command to tux for turning the right led on - #-------------------------------------------------------------------------- - def ledr_on(self): - """ - Send a command to tux for turning the right led on - - Example: - >>> tux.cmd.ledr_on() - """ - 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 - #-------------------------------------------------------------------------- - def ledr_off(self): - """ - Send a command to tux for turning the right led off - - Example: - >>> tux.cmd.ledr_off() - """ - 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 - # time - #-------------------------------------------------------------------------- - def ledr_during(self,seconds): - """ - Send a command to tux for turning the right led on during a specified - time - - Parameters: - "seconds" as float : time to wait in seconds - - Example: - >>> tux.cmd.ledr_during(2.5) - """ - self.ledr_on() - time.sleep(seconds) - self.ledr_off() - - #-------------------------------------------------------------------------- - # Send a command to tux for turning the right led on during a specified - # time in free mode - #-------------------------------------------------------------------------- - def ledr_during_free(self,seconds): - """ - Send a command to tux for turning the right led on during a specified - time in free mode - - Parameters: - "seconds" as float : time to wait in seconds - - Example: - >>> tux.cmd.ledr_during_free(2.5) - """ - t=threading.Thread(target=self.ledr_during,args=(seconds,)) - t.setName('cmd.ledr_during') - t.start() - 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): + def led_set(self, leds=BOTH, intensity=0xFF, effect_type=NONE, effect_speed=0.2,effect_step=2): """ 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 @@ -2904,8 +2686,9 @@ #-------------------------------------------------------------------------- # Mapping of the daemon command to pulse the LEDs. #-------------------------------------------------------------------------- - def led_pulse(self, leds, min_intensity, max_intensity, pulse_count, - pulse_period, effect_type, effect_speed, effect_step): + def led_pulse(self, leds = BOTH, min_intensity = 0, max_intensity = 255, \ + pulse_count = 1, pulse_period = 0.3, effect_type = NONE, \ + effect_speed = 0.1, effect_step=3): """ 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 @@ -2997,6 +2780,109 @@ int(effect_speed*64), effect_step) #-------------------------------------------------------------------------- + # Send a command to tux for turning the leds on + #-------------------------------------------------------------------------- + def leds_on(self, intensity = 255, leds = BOTH): + """ + Send a command to tux for turning the leds on + + Parameters : + "intensity" as integer : The intensity of the LED. + 0 .. 255 (0x00 .. 0xFF) + + "leds" as enum : 1 - LEFT + 2 - RIGHT + 3 - BOTH + (default = BOTH) + + Examples: + >>> tux.cmd.leds_on() + >>> tux.cmd.leds_on(intensity = 0x80) + >>> tux.cmd.leds_on(leds = LEFT, intensity = 20) + """ + self.led_set(leds = leds, intensity = intensity) + #-------------------------------------------------------------------------- + # Send a command to tux for turning the leds off + #-------------------------------------------------------------------------- + def leds_off(self, leds = BOTH): + """ + Send a command to tux for turning the leds off + + Parameter : + "leds" as enum : 1 - LEFT + 2 - RIGHT + 3 - BOTH + (default = BOTH) + + Example: + >>> tux.cmd.leds_off() + >>> tux.cmd.leds_off(leds = RIGHT) + """ + self.led_set(leds = leds, intensity = 0, effect_type = NONE) + + #-------------------------------------------------------------------------- + # Send a command to tux for blinking the leds + #-------------------------------------------------------------------------- + def leds_blink(self,counter = 1,delay = 4, leds = BOTH): + """ + Send a command to tux for blinking the leds + + Parameters: + "counter" as integer : number of blink(0..255) + + "delay" as integer : delay between 2 states (u=4msec) + + "leds" as enum : 1 - LEFT + 2 - RIGHT + 3 - BOTH + (default = BOTH) + + Example: + >>> tux.cmd.leds_blink(10,25) + >>> tux.cmd.leds_blink(counter = 10, delay = 40, leds = BOTH) + + """ + self.led_pulse(leds = leds, min_intensity = 0, \ + max_intensity = 255, pulse_count = counter, \ + pulse_period = float(delay * 0.004)) + #-------------------------------------------------------------------------- + # Send a command to tux for turning the leds on during a specified time + #-------------------------------------------------------------------------- + def leds_during(self,seconds): + """ + Send a command to tux for turning the leds on during a specified time + + Parameters: + "seconds" as float : time to wait in seconds + + Example: + >>> tux.cmd.leds_during(2.5) + """ + self.leds_on() + time.sleep(seconds) + self.leds_off() + + #-------------------------------------------------------------------------- + # Send a command to tux for turning the leds on during a specified time + # in free mode + #-------------------------------------------------------------------------- + def leds_during_free(self,seconds): + """ + Send a command to tux for turning the leds on during a specified time + in free mode + + Parameters: + "seconds" as float : time to wait in seconds + + Example: + >>> tux.cmd.leds_during_free(2.5) + """ + t=threading.Thread(target=self.leds_during,args=(seconds,)) + t.setName('cmd.leds_during') + t.start() + self.parent.daemon.free_thread_list.append(t) + + #-------------------------------------------------------------------------- # Send a command to tux for playing a sound from the flash memory #-------------------------------------------------------------------------- def sound_play(self,index,volume=0): @@ -3236,6 +3122,97 @@ see tux.cmd.spin_off """ self.move(movement = SPIN_R, final_state = STOP) + + #-------------------------------------------------------------------------- + # Send a command to tux for turning the left led on + #-------------------------------------------------------------------------- + def ledl_on(self): + """ + Deprecated : + see tux.cmd.leds_on + """ + self.led_set(leds = LEFT, intensity = 255, effect_type = NONE) + #-------------------------------------------------------------------------- + # Send a command to tux for turning the left led off + #-------------------------------------------------------------------------- + def ledl_off(self): + """ + Deprecated : + see tux.cmd.leds_off + """ + self.led_set(leds = LEFT, intensity = 0, effect_type = NONE) + #-------------------------------------------------------------------------- + # Send a command to tux for turning the left led on during a specified time + #-------------------------------------------------------------------------- + def ledl_during(self,seconds): + """ + Deprecated : + see tux.cmd.leds_during + """ + self.ledl_on() + time.sleep(seconds) + self.ledl_off() + + #-------------------------------------------------------------------------- + # Send a command to tux for turning the left led on during a specified + # time in free mode + #-------------------------------------------------------------------------- + def ledl_during_free(self,seconds): + """ + Deprecated : + see tux.cmd.leds_during_free + """ + t=threading.Thread(target=self.ledl_during,args=(seconds,)) + t.setName('cmd.ledl_during') + t.start() + self.parent.daemon.free_thread_list.append(t) + + #-------------------------------------------------------------------------- + # Send a command to tux for turning the right led on + #-------------------------------------------------------------------------- + def ledr_on(self): + """ + Deprecated : + see tux.cmd.leds_on + """ + self.led_set(leds = RIGHT, intensity = 255, effect_type = NONE) + + #-------------------------------------------------------------------------- + # Send a command to tux for turning the right led off + #-------------------------------------------------------------------------- + def ledr_off(self): + """ + Deprecated : + see tux.cmd.leds_off + """ + self.led_set(leds = RIGHT, intensity = 0, effect_type = NONE) + + #-------------------------------------------------------------------------- + # Send a command to tux for turning the right led on during a specified + # time + #-------------------------------------------------------------------------- + def ledr_during(self,seconds): + """ + Deprecated : + see tux.cmd.leds_during + """ + self.ledr_on() + time.sleep(seconds) + self.ledr_off() + + #-------------------------------------------------------------------------- + # Send a command to tux for turning the right led on during a specified + # time in free mode + #-------------------------------------------------------------------------- + def ledr_during_free(self,seconds): + """ + Deprecated : + see tux.cmd.leds_during_free + """ + t=threading.Thread(target=self.ledr_during,args=(seconds,)) + t.setName('cmd.ledr_during') + t.start() + self.parent.daemon.free_thread_list.append(t) #============================================================================== # TUXTCPCommunicator - status - class #============================================================================== Modified: api/python/trunk/tuxapi_const.py =================================================================== --- api/python/trunk/tuxapi_const.py 2008-01-23 11:59:48 UTC (rev 868) +++ api/python/trunk/tuxapi_const.py 2008-01-23 15:28:39 UTC (rev 869) @@ -460,7 +460,7 @@ NONE_BT =0 NULL_BT =0xFF -## tux.cmd.move function constant +## tux.cmd.move function constants EYES = 0 MOUTH = 1 FLIPPERS = 2 @@ -480,6 +480,21 @@ MIDHIGH = 4 HIGH = 5 +## tux.cmd.led* constans +NONE = 0 +LEFT = 1 +RIGHT = 2 +BOTH = 3 + +UNAFFECTED = 0 +LAST = 1 +NONE = 2 +DEFAULT = 3 +FADE_DURATION = 4 +FADE_RATE = 5 +GRADIENT_NBR = 6 +GRADIENT_DELTA = 7 + HEAD_BUTTON_PUSHED =1 HEAD_BUTTON_RELEASED =2 LEFT_WING_PUSHED =3 |