Author: gwadavel
Date: 2008-12-23 13:54:24 +0100 (Tue, 23 Dec 2008)
New Revision: 3290
Modified:
software_suite_v2/software/scripts/maxLight/tuxMaxLight.py
Log:
same version as tuxdroid-gadget-maxlight
Modified: software_suite_v2/software/scripts/maxLight/tuxMaxLight.py
===================================================================
--- software_suite_v2/software/scripts/maxLight/tuxMaxLight.py 2008-12-23
12:35:02 UTC (rev 3289)
+++ software_suite_v2/software/scripts/maxLight/tuxMaxLight.py 2008-12-23
12:54:24 UTC (rev 3290)
@@ -25,14 +25,18 @@
"""
CHANGES
=======
-2008/10/03 - version 0.4.0:
+2008/12/19 - version 0.5:
+ - Add says the % of light at the end
+ - Test if tgp_ip and tgp_port exist
+
+2008/10/03 - version 0.4:
- Add TTS + Internalization TTS
-
+
2008/10/03 - version 0.3.1:
- Add charger test
-
+
2008/10/03 - version 0.3:
- - Function stop modified by ks156
+ - Function stop modified by ks156
2008/10/02 - version 0.2:
- add DEBUG
@@ -43,14 +47,14 @@
TODO LIST
=========
- Add comments
-- Make gadget
+
"""
-__author__ = " Eric Lescaudron AKA Gwadavel irc.freenode.net #tuxdroid"
+__author__ = " Eric Lescaudron AKA Gwadavel http://gwadatux.free.fr"
__appname__ = "TuxMaxLight"
-__version__ = "0.4"
-__date__ = "2008/16/03"
+__version__ = "0.5"
+__date__ = "2008/12/19"
__license__ = "GPL"
@@ -59,93 +63,106 @@
import os
from time import sleep
-tux = TuxAPI('127.1.1.1', 270)
-DEBUG = False
LANGUAGE = ""
+FR = {"search": "Je commence la recherche", "stop": "La lumière maximum est
ici",
+"charger": "Déconnectez le chargeur et relancez le programme"}
+EN = {"search": "I began research", "stop": "Light up is here",
+"charger": "Unplugged the charger and restart the program"}
+# Address and port of Tux HTTP Server
+tgp_ip = "127.0.0.1"
+tgp_port = 270
+
def lang():
- """ Search LANGUAGE in os.environ """
+ """ Search LANGUAGE in os.environ """
- global LANGUAGE
- if DEBUG: print os.environ['LANG']
- if "fr_" in os.environ['LANG']: # french
- locutor = "Julie " # Modifiez mettre "Bruno" si vous voulez
- pitch = 105
- LANGUAGE = "FR_"
- else: # english for other, change your language
- locutor = "Ryan" #you can use "Heather"
- pitch = 110
- LANGUAGE = "EN_"
- tux.tts.setLocutor(locutor)
- tux.tts.setPitch(pitch)
+ global LANGUAGE
+
+ if "fr" in os.environ['LANG']:
+ locutor = "Bruno"
+ pitch = 100
+ LANGUAGE = FR
+ elif "en" in os.environ['LANG']:
+ locutor = "Ryan"
+ pitch = 100
+ LANGUAGE = EN
+ else: # for other language
+ locutor = "Ryan"
+ pitch = 100
+ LANGUAGE = EN
+ tux.tts.setLocutor(locutor)
+ tux.tts.setPitch(pitch)
-def speak(mes):
- """ Tux talks """
+def message(mes):
+ """ get message from langage dictionary """
+
+ text = LANGUAGE[mes]
+ speak(text)
+
+def speak(text):
+ """ Tux talks """
+
+ tux.mouth.open()
+ tux.tts.speak(text)
+ tux.mouth.close()
- FR_Search = "Je commence la recherche"
- FR_Stop = "La lumiere maximum est ici "
- FR_Charger = "Débranchez le chargeur et relancez le programme "
- EN_Search = "I began research "
- EN_Stop = "Light up is here "
- EN_Charger = "Unplugged the charger and restart the program "
- text = LANGUAGE + mes
- tux.mouth.open()
- tux.tts.speak(eval(text))
- tux.mouth.close()
-
def tuxConnect():
- """ Wait connected """
- tux.server.autoConnect(CLIENT_LEVEL_RESTRICTED, 'TuxMaxLight', 'NONE')
- tux.server.waitConnected(10.0)
- tux.dongle.waitConnected(10.0)
- tux.radio.waitConnected(10.0)
- return tux.access.waitAcquire(10.0, ACCESS_PRIORITY_NORMAL)
+ """ Wait connected """
+ tux.server.autoConnect(CLIENT_LEVEL_RESTRICTED, 'TuxMaxLight', 'NONE')
+ tux.server.waitConnected(10.0)
+ tux.dongle.waitConnected(10.0)
+ tux.radio.waitConnected(10.0)
+ return tux.access.waitAcquire(10.0, ACCESS_PRIORITY_NORMAL)
+
def search():
""" Search maximum light """
+
l_max = 0 # Light Max
- speak("Search")
- tux.spinning.leftOnAsync((2.0), 4)
+ message("search")
+ tux.spinning.leftOnAsync((2.0), 4)
# Turn on left 2 turns, asynchrone mode
sleep(1) # wait Tux began to turn
- while tux.spinning.getLeftMovingState():
- # While tux spins
- l = float(tux.status.requestOne('light_level')[0]) # Light
- if DEBUG: print("Fonction search, Light : ", l)
- if l > l_max: # Light Max ?
- l_max = l // 1
- if DEBUG: print("Fonction search, Light Max : ", l_max)
- return l_max # Return Light Max
+ while tux.spinning.getLeftMovingState():
+ # While tux spins
+ lum = float(tux.status.requestOne('light_level')[0]) # Light
+ if lum > l_max: # Light Max ?
+ l_max = lum // 1
+ return l_max # Return Light Max
def stop(l_stop):
- """ Tux stop when it finds light up
- Modified by ks156 who wrote light monitor gadget for TuxDroid V1
- Tux turn a little, wait and turn while light < light max """
- tux.spinning.leftOnAsync(0.25, 2)
- sleep(1)
- while 1:
- tux.spinning.leftOnDuring(0.1, 2)
- sleep(0.1)
- l = float(tux.status.requestOne('light_level')[0])
- if DEBUG: print("Fonction stop, Light : ", l)
- if l >= l_stop:
- tux.spinning.off()
- break
- if DEBUG: print("I stop at : ",
tux.status.requestOne('light_level')[0])
- speak("Stop")
-
+ """ Tux stop when it finds light up Modified by ks156 who wrote light
+ monitor gadget for TuxDroid V1 Tux turn a little, wait and turn while
light < light max """
+
+ tux.spinning.leftOnAsync(0.25, 2)
+ sleep(1)
+ while 1:
+ tux.spinning.leftOnDuring(0.1, 2)
+ sleep(0.1)
+ lum = float(tux.status.requestOne('light_level')[0])
+ if lum >= l_stop:
+ tux.spinning.off()
+ break
+ message("stop")
+ speak(str(int(lum)) + "%%")
+
+tux = TuxAPI(tgp_ip, tgp_port)
+
if tuxConnect():
- lang()
- if tux.status.requestOne('charger_state')[0] == 'UNPLUGGED':
- # Test if charger are plugged
- tux.eyes.open()
- light = search() # search light up
- stop(light) # stop
- else:
- if DEBUG: print("Unplugged the charger and restart")
- speak("Charger")
+ tux.tts.setEncoding(encoding='utf-8')
+ lang()
+
+ # Test if charger are plugged
+ if tux.status.requestOne('charger_state')[0] == 'UNPLUGGED':
+ tux.eyes.open()
+ tux.flippers.up()
+ light = search() # search light up
+ stop(light) # stop
+ tux.flippers.down()
+ else:
+ message("charger")
tux.access.release()
tux.server.disconnect()
tux.destroy()
------------------------------------------------------------------------------
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn