Personal tools
Document Actions

Remote control game and weather report

Up to Scripts

Remote control game and weather report

Posted by Martin Thomas at April 25. 2007

Here's a little python script to read the key presses from the remote  
and perform some action. I wrote it a couple of days ago before I dove
into the firmware.

Push the red button and tux reads a canned weather report (found in 'weather.rep'.
Push the blue button and he offers a number guessing game.
Push yellow to quit.

I posted this to the tuxdroid-user list but I thought this might be a good place for it as well.

Here's an example weather report I get from the taskbar weather applet..
TONIGHT
MOSTLY CLOUDY WITH A SLIGHT CHANCE OF SPRINKLES.
COLDER. LOWS IN THE UPPER 30S. NORTH WINDS 10 TO 15 MPH. GUSTS UP
TO 25 MPH IN THE EVENING.

SATURDAY
CLOUDY WITH A SLIGHT CHANCE OF LIGHT SNOW. A CHANCE
OF LIGHT RAIN
MAINLY IN THE AFTERNOON. COLDER. HIGHS IN THE
LOWER 40S. NORTHEAST WINDS 10 TO 15 MPH BECOMING NORTH AROUND
5 MPH IN THE AFTERNOON. CHANCE OF PRECIPITATION 40 PERCENT.

//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=1
tux=tuxapi_class.TUXTCPCommunicator(5000, "localhost")
tux.print_api_version()
wavs=tuxapi_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 = open('weather.rep').read()
tux.tts.speak_free(weather)

def my_exit():
print "Leaving now.."
tux.disconnect_from_daemon()
global run_state
run_state=0
print "Run state = %s"%run_state
sys.exit(0)

def game():
import random
tux.tts.speak("Guess what number I am thinking of ! Press a
number key to play or press e
sc to quit !")
my_number = 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
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

Re: Remote control game and weather report

Posted by Alderic at May 07. 2007

hello




How can I get your script ? copy past code into a .py file ?






thanks ! :)


Re: Remote control game and weather report

Posted by Martin Thomas at May 14. 2007

Cut and paste should work..


Re: Remote control game and weather report

Posted by Goren at July 08. 2007
Doesn't work for me. For red button it says
WARNING : Resource text to speech Acapela not found
and doesn't play any sounds.
for blue button i get an error message:
"explicit_status() takes exactly 2 arguments (1 given)"

Re: Remote control game and weather report

Posted by pitux at August 10. 2007

I think is not compatibl with the api 2.0


Powered by Ploneboard
You are here: Home Forum Scripts Remote control game and weather report

Powered by Plone CMS, the Open Source Content Management System