Class: FingerPoken::Target::Tivo
- Inherits:
-
FingerPoken::Target
- Object
- FingerPoken::Target
- FingerPoken::Target::Tivo
- Defined in:
- lib/fingerpoken/tivo.rb
Defined Under Namespace
Classes: TivoClient
Instance Method Summary collapse
- #click(button) ⇒ Object
-
#initialize(config) ⇒ Tivo
constructor
A new instance of Tivo.
-
#keypress(key) ⇒ Object
Hack for now.
- #mousemove_relative(x, y) ⇒ Object
- #move_end ⇒ Object
Constructor Details
#initialize(config) ⇒ Tivo
Returns a new instance of Tivo.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/fingerpoken/tivo.rb', line 15 def initialize(config) super(config) # TODO(sissel): Make this a config @host = config[:host] @port = (config[:port] or 31339) @tivo = EventMachine::connect(@host, @port, TivoClient, self) @state = OpenStruct.new # TODO(sissel): Make this not an open struct... @state.speed = 0 end |
Instance Method Details
#click(button) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/fingerpoken/tivo.rb', line 65 def click() case .to_i when 1 @tivo.send_data("IRCODE PAUSE\r\n") return { "action" => "status", "status" => "Pause" } when 2 # 'middle' click (three fingers) @tivo.send_data("IRCODE SELECT\r\n") return { "action" => "status", "status" => "Select" } #when 2 # 'middle' click (three fingers) #@tivo.send_data("IRCODE TIVO\r\n") when 4 # scroll up @tivo.send_data("IRCODE UP\r\n") return { "action" => "status", "status" => "Up" } when 5 # scroll down @tivo.send_data("IRCODE DOWN\r\n") return { "action" => "status", "status" => "Down" } end end |
#keypress(key) ⇒ Object
Hack for now
85 86 87 88 89 90 91 92 93 |
# File 'lib/fingerpoken/tivo.rb', line 85 def keypress(key) case key when "Home" @tivo.send_data("IRCODE TIVO\r\n") when "Return" @tivo.send_data("IRCODE SELECT\r\n") end return nil end |
#mousemove_relative(x, y) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/fingerpoken/tivo.rb', line 27 def mousemove_relative(x, y) direction = x < 0 ? -1 : 1 want_speed = [(x.abs / 30).to_i, 3].min want_speed *= direction if want_speed != @state.speed p [want_speed] end if want_speed > @state.speed # increase to it 1.upto(want_speed - @state.speed).each do puts "UP" @tivo.send_data("IRCODE FORWARD\r\n") end elsif (want_speed < @state.speed) 1.upto( (want_speed - @state.speed).abs ).each do @tivo.send_data("IRCODE REVERSE\r\n") puts "DOWN" end # decrease to it end @state.speed = want_speed if @state.speed > 0 char = "\\u23E9" * @state.speed else char = "\\u23EA" * @state.speed.abs end return { "action" => "status", "status" => char } end |
#move_end ⇒ Object
59 60 61 62 63 |
# File 'lib/fingerpoken/tivo.rb', line 59 def move_end @tivo.send_data("IRCODE PLAY\r\n") @state.speed = 0 return { "action" => "status", "status" => "\\u25b6" } end |