Author: gwadavel
Date: 2008-12-16 22:01:01 +0100 (Tue, 16 Dec 2008)
New Revision: 3136
Added:
software_suite_v2/software/scripts/maxLight/
software_suite_v2/software/scripts/maxLight/tuxMaxLight.py
Log:
Tux search and stop at the maximum light
Added: software_suite_v2/software/scripts/maxLight/tuxMaxLight.py
===================================================================
--- software_suite_v2/software/scripts/maxLight/tuxMaxLight.py
(rev 0)
+++ software_suite_v2/software/scripts/maxLight/tuxMaxLight.py 2008-12-16
21:01:01 UTC (rev 3136)
@@ -0,0 +1,151 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# -----------------------------------------------------------------------------
+# Tux search and stop at the maximum light
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+# 02111-1307, USA.
+# -----------------------------------------------------------------------------
+# $Id: $
+# -----------------------------------------------------------------------------
+
+"""
+CHANGES
+=======
+2008/10/03 - version 0.4.0:
+ - 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
+
+2008/10/02 - version 0.2:
+ - add DEBUG
+
+2008/10/02 - version 0.1:
+ - Initial version
+
+TODO LIST
+=========
+- Add comments
+- Make gadget
+
+"""
+
+__author__ = " Eric Lescaudron AKA Gwadavel irc.freenode.net #tuxdroid"
+__appname__ = "TuxMaxLight"
+__version__ = "0.4"
+__date__ = "2008/16/03"
+__license__ = "GPL"
+
+
+
+from tuxisalive.api import *
+import os
+from time import sleep
+
+tux = TuxAPI('127.1.1.1', 270)
+DEBUG = False
+LANGUAGE = ""
+
+
+
+def lang():
+ """ 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)
+
+def speak(mes):
+ """ Tux talks """
+
+ 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)
+
+def search():
+ """ Search maximum light """
+ l_max = 0 # Light Max
+ speak("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
+
+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")
+
+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.access.release()
+tux.server.disconnect()
+tux.destroy()
Property changes on: software_suite_v2/software/scripts/maxLight/tuxMaxLight.py
___________________________________________________________________
Name: svn:executable
+ *
------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you. Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn