[tuxdroid-user] Python script for remote control
Status: Beta
Brought to you by:
ks156
From: Martin T. <ma...@ma...> - 2007-04-09 02:53:13
|
Here's a little python script to read the key presses from the remote =20 and perform some action. I wrote it a couple of days ago before I dove =20 into the firmware. Push the red button and tux reads a canned weather report. Push the blue button and he offers a number guessing game. Push yellow to quit. //m #!/usr/bin/python # -*- coding: latin-1 -*- ## Borrowed tux.py and added some extra stuff.. import sys import sys sys.path.append('/opt/tuxdroid/api/python') from tuxapi_const import * import tuxapi_class import tuxapi_wav_merger import signal import time global tux run_state=3D1 tux=3Dtuxapi_class.TUXTCPCommunicator(5000, "localhost") tux.print_api_version() wavs=3Dtuxapi_wav_merger.WavMerger(tux) tux.connect_to_daemon() def exit(signum,frame): print "exiting (%d) ..."%(signum) tux.disconnect_from_daemon() sys.exit(signum) signal.signal(signal.SIGTERM, exit) signal.signal(signal.SIGINT, exit) print "Remote control demo" def weather(): weather =3D open('weather.rep').read() tux.tts.speak_free(weather) def my_exit(): print "Leaving now.." tux.disconnect_from_daemon() global run_state run_state=3D0 print "Run state =3D %s"%run_state sys.exit(0) def game(): import random tux.tts.speak("Guess what number I am thinking of ! Press a =20 number key to play or press e sc to quit !") my_number =3D random.randrange(0,9) tux.tts.speak("Here's a clue, it's %s.."%my_number) while(tux.explicit_status()<>'IR code->K_ESCAPE' and =20 tux.explicit_status()<>'IR code->K_%s '%my_number): print "Status: ", tux.explicit_status() pass if tux.explicit_status()<>'IR code->K_ESCAPE': tux.tts.speak('Congratulations! You got the number!') tux.event.set_on_remote_bt(K_RED, weather) tux.event.set_on_remote_bt(K_BLUE, game) tux.event.set_on_remote_bt(K_YELLOW, my_exit) while run_state: time.sleep(0.01) pass |