#!/usr/bin/env ruby require 'rubygems' #Include the FireWatir file. require 'firewatir' #include the FireWatir Module. include FireWatir require 'joystick' require "festivaltts4r" site='localhost:3000/' #site='rubypython.railsplayground.net/' def go_to (f,st) p st f.goto(st) end if !Joystick::Device::open('/dev/input/js0') { |joy| puts "Joystick: #{joy.name}", "Axes / Buttons : #{joy.axes} / #{joy.buttons}", begin apps=ARGV if apps.empty? # apps=["easypic","abcd","words"] apps=['modules'] end puts "running applications: #{apps.join(";")}" aindex=0 cap=apps[aindex] # th=Thread.new{system('script/server')} # sleep(3) p ff=Firefox.new ff.goto("http://#{site}#{cap}/index/norefresh") lastupdate=Time.now # loop forever loop { ev = joy.ev p ev.type case ev.type when Joystick::Event::INIT puts 'init' when Joystick::Event::BUTTON if (ev.val==1) puts "button #{ev.num}" if ev.num % 2 == 0 then ff.goto("http://#{site}#{cap}/select") else ff.goto("http://#{site}#{cap}/backspace") end page_text=ff.text if page_text =~ /say:"(.+)"/ speak=$1 speak.to_speech end # if ff.text =~ /say:"(.+)"/ # ($1).to_speech # end page_text=page_text.split('~')[0] p page_text if page_text=~/modules/ apps=page_text.scan(%r{\w+}) p apps #apps.collect!{|s| s[0]} aindex=apps.index(cap) || 0 #page_text=page_text[0..(page_text=~/modules/)+7] # apps=page_text.scan(%r{\w+}) end p 'running modules: '+apps.join(';') p "index #{aindex}" end when Joystick::Event::AXIS if ((Time.now-lastupdate)>0.5) then if (ev.val != 0) then if (ev.val < 0) then if (ev.num%2==1) then go_to(ff,"http://#{site}#{cap}/up") else aindex=(aindex-1)%apps.size cap=apps[aindex] go_to(ff,"http://#{site}#{cap}/first_time") puts cap+ev.val.to_s end else if ev.num%2==1 then go_to(ff,"http://#{site}#{cap}/down") else aindex=(aindex+1)%apps.size cap=apps[aindex] go_to(ff,"http://#{site}#{cap}/first_time") puts cap+ev.val.to_s end end if ff.text =~ /say:"(.+)"/ ($1).to_speech end lastupdate=Time.now end end end } ensure ff.close unless ff.nil? # th.terminate end } then puts 'cannot find joystick at /dev/input/js0' end