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.
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=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
#!/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 esc 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


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 AFTE NOON. 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. 

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
tux-droid-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-user

Reply via email to