#!/usr/bin/env ruby require 'rubygems' #Include the FireWatir file. require 'firewatir' #include the FireWatir Module. include FireWatir require 'joystick' require "festivaltts4r" require 'optparse' class CatArguments < Hash def initialize(args) super() self[:joystick] = '/dev/input/js0' self[:site]= 'skid.org.in/' self[:yes_button]='0' self[:no_button]='1' self[:modules]='modules' self[:tauto]='3' opts = OptionParser.new do |opts| opts.banner = "Usage: #$0 [options]" opts.on('-j', '--joystick [STRING]', 'default is /dev/input/js0') do |s| self[:joystick] = s end opts.on('-m', '--modules [STRING]', 'modules') do |s| self[:modules] = s end opts.on('-l', '--local', 'to use localhost:3000') do self[:site] = 'localhost:3000/' end opts.on('-t','--tinterval', 'how long the software waits at each choice') do |s| self[:tauto]=s end opts.on('-y','--yesbutton [STRING]', 'the yes button no., default 0') do |s| self[:yes_button]=s.to_i end opts.on('-n','--nobutton [STRING]', 'the no button no., default 1') do |s| self[:no_button]=s.to_i end opts.on_tail('-h', '--help', 'display this help and exit') do puts opts exit end end opts.parse!(args) end end arguments = CatArguments.new(ARGV) site=arguments[:site] yes_button=arguments[:yes_button].to_i no_button=arguments[:no_button].to_i tAutoRefresh=arguments[:tauto].to_i t_bounce=1 junk=[] $apps=arguments[:modules].split('+') $cap=$apps[0] aindex=0 def go_to (f,st) begin # puts "current app: #{$cap} going to #{st}" f.goto(st) page_text=f.text if page_text =~ /say:"(.+)"/ speak=$1 speak.to_speech end rescue end [Time.now,$apps] end open('jlog.txt','w') do |wf| if !Joystick::Device::open(arguments[:joystick]){ |joy| puts "Joystick: #{joy.name}", "Axes / Buttons : #{joy.axes} / #{joy.buttons}", begin if $apps.empty? $apps=['modules'] end puts "running applications: #{$apps.join(";")}" aindex=0 #the index for $apps $cap=$apps[aindex] #currently running app p ff=Firefox.new lastupdate,$apps= go_to(ff,"http://#{site}#{$cap}/index/"+ "stopscroll+nobuttons+nomodules") lastupdate=Time.now # ignore joystick till noise settles while Time.now - lastupdate < t_bounce if joy.pending? ev=joy.ev lastupdate=Time.now end end yes_processed=false #for bounce suppression no_processed=false #do loop { if joy.pending? ev = joy.ev wf.puts "n#{ev.num} val #{ev.val} #{lastupdate}" if (yes_button==ev.num) and !yes_processed yes_processed=true lastupdate,$apps= go_to(ff,"http://#{site}#{$cap}/select") wf.puts "selected #{$cap} from #{$apps}" elsif (no_button==ev.num) and !no_processed no_processed=true aindex=(aindex+1) % $apps.size $cap=$apps[aindex] lastupdate,$apps=go_to(ff, "http://#{site}#{$cap}/first_time") wf.puts "switch to #{$cap}" end # puts "last update #{lastupdate}" end if ((Time.now-lastupdate)>t_bounce) then # allow fresh yes/no input no_processed=false yes_processed=false if ((Time.now-lastupdate)>tAutoRefresh) then lastupdate,junk= go_to(ff, "http://#{site}#{$cap}/down") end end } ensure ff.close unless ff.nil? end } then puts "cannot find joystick at #{arguments[:joystick]}" end end