#!/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' 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('-l', '--local', 'to use localhost:3000') do self[:site] = 'localhost:3000/' end opts.on('-y','--yesbutton [STRING]', 'to define the yes button') do |s| self[:yes_button]=s.to_i end opts.on('-n','--nobutton [STRING]', 'to define the no button') 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 # p arguments tAutoRefresh=5 junk=[] apps=[] aindex=0 def go_to (f,st) apps ||= ['modules'] cap ||= apps[0] puts "current app: #{cap} going to #{st}" f.goto(st) page_text=f.text if page_text =~ /say:"(.+)"/ speak=$1 speak.to_speech end t=f.table(:id,/content/) p t r=t.rows.first apps=[] r.each do |cell| m=cell.to_s apps << m unless m.empty? end aindex=apps.index(cap) || 0 p apps # p "aindex at loading #{aindex}" [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 # t_release=Time.now # t_clicking=Time.now # long_counter=1 apps=ARGV if apps.empty? # apps=["easypic","abcd","words"] apps=['modules'] end puts "running applications: #{apps.join(";")}" aindex=0 #the index for apps cap=apps[aindex] #currently running app # th=Thread.new{system('script/server')} # sleep(3) scrolling_modules=false p ff=Firefox.new lastupdate,apps= go_to(ff, "http://#{site}#{cap}/index/stopscroll+nobuttons") # selapps=['abcd','easypic','modules'] # loop forever lastupdate=Time.now # ignore joystick for the first few secs: noise while Time.now - lastupdate < tAutoRefresh if joy.pending? ev=joy.ev end end loop { while joy.pending? ev = joy.ev wf.puts "n#{ev.num} val #{ev.val} #{lastupdate}" if (yes_button==ev.num) and (ev.val==0) if scrolling_modules scrolling_modules=false else lastupdate,apps= go_to(ff,"http://#{site}#{cap}/select") wf.puts "selected #{cap} from #{apps}" end elsif (no_button==ev.num) and (ev.val==0) scrolling_modules= !scrolling_modules if scrolling_modules aindex=(aindex+1) % apps.size cap=apps[aindex] lastupdate,apps=go_to(ff, "http://#{site}#{cap}/first_time") end end puts "last update #{lastupdate}" end if ((Time.now-lastupdate)>tAutoRefresh) then if scrolling_modules aindex=(aindex+1) % apps.size cap=apps[aindex] lastupdate,junk=go_to(ff, "http://#{site}#{cap}/first_time") else lastupdate,junk= go_to(ff, "http://#{site}#{cap}/down") end end } ensure ff.close unless ff.nil? # th.terminate end } then puts 'cannot find joystick at /dev/input/js0' end end