Author: ks156 Date: 2009-02-20 21:36:01 +0100 (Fri, 20 Feb 2009) New Revision: 3724
Added: software_suite_v2/software/scripts/tuxshellplus/ software_suite_v2/software/scripts/tuxshellplus/branches/ software_suite_v2/software/scripts/tuxshellplus/tags/ software_suite_v2/software/scripts/tuxshellplus/trunk/ software_suite_v2/software/scripts/tuxshellplus/trunk/README software_suite_v2/software/scripts/tuxshellplus/trunk/tuxshellplus.py Log: * Imported tuxshellplus from the git The git repository is maintained by the community, and is available at http://github.com/gitsean/tuxdroid/tree/master Added: software_suite_v2/software/scripts/tuxshellplus/trunk/README =================================================================== --- software_suite_v2/software/scripts/tuxshellplus/trunk/README (rev 0) +++ software_suite_v2/software/scripts/tuxshellplus/trunk/README 2009-02-20 20:36:01 UTC (rev 3724) @@ -0,0 +1,5 @@ +This script has been imported from the tuxdroid-git repo. +This repository is maintained by the community, and is accessible at : +http://github.com/gitsean/tuxdroid/tree/master + + Added: software_suite_v2/software/scripts/tuxshellplus/trunk/tuxshellplus.py =================================================================== --- software_suite_v2/software/scripts/tuxshellplus/trunk/tuxshellplus.py (rev 0) +++ software_suite_v2/software/scripts/tuxshellplus/trunk/tuxshellplus.py 2009-02-20 20:36:01 UTC (rev 3724) @@ -0,0 +1,313 @@ +#!/usr/bin/python -i +#THIS CODE IS NOT PART OF NESTOR! See the nestor folder for that code. +# TuxShell+ v0.4a! +#Copyright (C) 2009 Sean <[email protected]> +#This program is designed to make controlling tux via python easy! +# +# 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 3 of the License, 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, see <http://www.gnu.org/licenses/>. + +#=============CHANGELOG=================== +#Format +#Version DD/MM/YYYY Dev Name +# Commit message + +#V0.4a 20/2/2009 Sean +# Added a check for interactive mode. + +#V0.4 06/2/2009 Sean +# Connect to the local tux if no address is entered. Fixed many more typos (hopefully all of them.) + +#V0.3b 06/2/2009 Sean +# Fixed alert message on the last line. Thanks Gwadavel! + +#V0.3a 25/1/2009 Sean +# Fixed some typos. + +#V0.3 25/1/2009 Sean +# New methods and added documentation. + +#V0.2 6/1/2009 Sean +# First commit + + +#==========TODO=========== +#Nothing for now ;) +#========================= +#sys module is required +import sys + +#import tuxisalive.api +from tuxisalive.api import * + +#extra modules in case the end user wants to play :) +import math +import threading +import thread +import os +import time + +#Check for interactive mode +if not 'readline' in sys.modules: + print "For interctive use, run: python -i tuxshellplus.py" + print + quit() + +#Display welcome message +print("Welcome to TuxShell+ v0.4a!") +print ("Copyright (C) 2009 Sean <[email protected]>") +print("This program is designed to make controlling tux via python easy!") +print +print("For more details on the Tux Droid, visit http://www.kysoh.com") +print +print(" This program is free software: you can redistribute it and/or modify") +print(" it under the terms of the GNU General Public License as published by") +print(" the Free Software Foundation, either version 3 of the License, or") +print(" (at your option) any later version.") +print +print(" This program is distributed in the hope that it will be useful,") +print(" but WITHOUT ANY WARRANTY; without even the implied warranty of") +print(" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the") +print(" GNU General Public License for more details.") +print +print(" You should have received a copy of the GNU General Public License") +print(" along with this program. If not, see <http://www.gnu.org/licenses/>.") +print + +#Ask user for address of server +def connect(): + #make tux global so that it can be used elsewhere in the script + global tux + print("Note: Use http://www.whatsmyip.org/more for details on your internal and external addresses.") + print + print("Please be sure that port 720 is accessible on the remote host.") + #print a blank line + print + try: + address = input('Please enter the address of the server (Press enter for the local Tux): ') + print + except: + print ('Your input was invalid! Defaulting to local Tux.') + print + #use the local tux + address = "127.0.0.1" + #Connect to Tux Droid server + + #Define the tux object tux by using the address and port of the Tux Droid + try: + tux = TuxAPI(address, 270) + + #Gain access to tux + tux.server.autoConnect(CLIENT_LEVEL_RESTRICTED, 'TuxGuestUser', 'TuxPass') + except: + print("ERROR: Could not connect to the server! Please try again.") + print + #exit the python console + quit() + + #Define say() +def say(message): +#open the mouth + try: + tux.mouth.open() + + #Speak the message passed, use voice x and y % pitch + tux.tts.speak(message,"Ryan", 120) + + #close the mouth...er...beak + tux.mouth.close() + except: + print ("ERROR: TTS FAILED") + tux.mouth.close() + + +#define getLight() +def getLight(): + #Get ammount of light + light = float(tux.status.requestOne('light_level')[0]) + +#define closeEyes() +def closeEyes(): + tux.eyes.close() + +#define openEyes() +def openEyes(): + tux.eyes.open() + +#define blink(n) +def blink(n): + tux.eyes.open() + tux.eyes.on(n) + tux.eyes.open() + +#define flap(n) +def flap(n): + while n > 0: + tux.flippers.on(n, finalState='DOWN', speed=5) + n=n-1 + +#define flashLedsSlow(n) +def flashLedsSlow(n): + tux.led.both.blink(1,n,0) + +#define flashLedsFast(n) +def flashLedsFast(n): + tux.led.both.blink(5,n,0) + +#define ledsOff() +def ledsOff(): + tux.led.both.off() + +#define ledsOn() +def ledsOn(): + tux.led.both.on() + +#define rLedOff() +def rLedOff(): + tux.led.right.off() + +#define rLedOn() +def rLedOn(): + tux.led.right.on() + +#define rLedOff() +def lLedOff(): + tux.led.left.off() + +#define lLedsOn() +def lLedOn(): + tux.led.left.on() + +#define spinR(n) +def spinR(n): + tux.spinning.rightOn(n,5) + +#define spinL(n) +def spinL(n): + tux.spinning.leftOn(n,5) + +#define finish +def finish(): +#alert the parties + + say("The Tux Shell Plus user has disconnected.") + print("Control released.") + + #Release control of the server + tux.access.release() + + #Disconnect from server + tux.server.disconnect() + + #Destroy the tux object (clean up) + tux.destroy() + + #exit the python console + quit() + +#desplay help documentation +def help(): + print("The fallowing commands (methods) are built into TuxShell+:") + print(" say(message)") + print(" Opens the beak, says the massage, and closes the beak.") + print(' Example: say("Hello world!")') + print + print(" help()") + print(" Displays this message.") + print(' Example: help()') + print + print(" getLight()") + print(" Gets one sample of the level of light and sets it as the float light. ") + print(' Example: finish()') + print + print(" closeEyes()") + print(" Close Tux's eyes.") + print(' Example: closeEyes()') + print + print(" openEyes()") + print(" Open Tux's eyes.") + print(' Example: openEyes()') + print + print(" blink(n)") + print(" Blink Tux's eyes n times.") + print(' Example: blink(2)') + print + print(" flashLedsSlow(n)") + print(" Flashes Tux's eyes (LEDs) slowly n times.") + print(' Example: FlashLedsSlow(4)') + print + print(" flashLedsFast(n)") + print(" Flashes Tux's eyes (LEDs) quickly n times.") + print(' Example: FlashLedsFast(5)') + print + print(" ledsOff()") + print(" Turn Tux's eyes (LEDs) off.") + print(' Example: ledsOff()') + print + print(" ledsOn()") + print(" Turn Tux's eyes (LEDs) on.") + print(' Example: ledsOn()') + print + print(" lLedOff()") + print(" Turn Tux's left eye (LED) off.") + print(' Example: lLedOff()') + print + print(" lLedOn()") + print(" Turn Tux's left eye (LED) on.") + print(' Example: lLedOn()') + print + print(" rLedOff()") + print(" Turn Tux's right eye (LED) off.") + print(' Example: rLedOff()') + print + print(" rLedOn()") + print(" Turn Tux's right eye (LED) on.") + print(' Example: rLedOn()') + print + print(" spinL(n)") + print(" Make tux spin left where n is the degree of the turn.") + print(' Example: spinL(.25) .25= 90 degrees, 50.0=180 1.0=360, etc') + print + print(" spinR(n)") + print(" Make tux spin right where n is the degree of the turn.") + print(' Example: SpinR(.25) .25= 90 degrees, 50.0=180 1.0=360, etc') + print + print(" flap(n)") + print(" Flap Tux's flappers n times.") + print(' Example: flap(3)') + print + print(" finish()") + print(" Closes all connections the right way and ends this script.") + print(' Example: finish()') + print + print(" DO NOT CLOSE THE TERMINAL WINDOW! USE finish()") + print + print(" You can also use all of the things from tuxisalive.api.") + print + print(" Lastly, have fun!") + #main +connect() + +#Display welcome +print("Woo hoo! Everything is running smoothly.") +#display help +help() +print +#let the user know to press enter +print ("PRESS ENTER TO ENTER THE PROMPT") + +#Give Tux time to say the line below +time.sleep(1.0) + +#Alert the remote party +say("Alert! Someone has connected using Tux Shell Plus.") ------------------------------------------------------------------------------ Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise -Strategies to boost innovation and cut costs with open source participation -Receive a $600 discount off the registration fee with the source code: SFAD http://p.sf.net/sfu/XcvMzF8H _______________________________________________ Tux-droid-svn mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/tux-droid-svn
