Class: ITACH::Remote
- Inherits:
-
Object
- Object
- ITACH::Remote
- Defined in:
- lib/itach/remote.rb
Instance Method Summary collapse
- #address ⇒ Object
- #combo_exists?(combo) ⇒ Boolean
- #command_exists?(command) ⇒ Boolean
- #connected? ⇒ Boolean
- #get_learning_responses(&block) ⇒ Object
-
#initialize(options = {}) ⇒ Remote
constructor
A new instance of Remote.
- #learn(state) ⇒ Object
- #port ⇒ Object
- #remote_exists?(remote) ⇒ Boolean
- #send_combo(combo) ⇒ Object
- #send_command(command, repeat = 1) ⇒ Object
- #socket ⇒ Object
Constructor Details
Instance Method Details
#address ⇒ Object
9 10 11 |
# File 'lib/itach/remote.rb', line 9 def address @config['RECEIVER']['ip'] end |
#combo_exists?(combo) ⇒ Boolean
29 30 31 |
# File 'lib/itach/remote.rb', line 29 def combo_exists? combo @config['COMBOS'].keys.include?(combo.split("_").last) end |
#command_exists?(command) ⇒ Boolean
33 34 35 36 37 38 39 |
# File 'lib/itach/remote.rb', line 33 def command_exists? command remote, command, *action = command.split("_") command = [command, action].join('_') unless action.empty? raise RuntimeError, "No remote defined for #{remote}" unless remote_exists? remote return true if @config['REMOTES'][remote].keys.include? command raise RuntimeError, "No command #{command} defined for #{remote}" end |
#connected? ⇒ Boolean
17 18 19 |
# File 'lib/itach/remote.rb', line 17 def connected? !!socket end |
#get_learning_responses(&block) ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/itach/remote.rb', line 68 def get_learning_responses(&block) while connected? str = "" until str[-2..-1] == "\r\n" str << read_block(1) end yield str end end |
#learn(state) ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/itach/remote.rb', line 57 def learn(state) load_config if state socket.puts ("get_IRL\r") puts "IR Learner Enabled\r" else socket.puts("stop_IRL\r") puts "IR Learner Disabled\r" end end |
#port ⇒ Object
13 14 15 |
# File 'lib/itach/remote.rb', line 13 def port @config['RECEIVER']['port'] end |
#remote_exists?(remote) ⇒ Boolean
25 26 27 |
# File 'lib/itach/remote.rb', line 25 def remote_exists? remote @config['REMOTES'].keys.include?(remote) end |
#send_combo(combo) ⇒ Object
52 53 54 55 |
# File 'lib/itach/remote.rb', line 52 def send_combo combo raise RuntimeError, "No combo #{combo} defined." unless combo_exists? combo @config['COMBOS'][combo.split("_").last].map { |c| send_command c } end |
#send_command(command, repeat = 1) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/itach/remote.rb', line 41 def send_command command, repeat = 1 if command_exists? command remote, command, *action = command.split("_") command = [command, action].join('_') unless action.empty? repeat.times do socket.puts "sendir,#{@config['REMOTES'][remote][command]}\r" puts read_from_unblock_to_block end end end |
#socket ⇒ Object
21 22 23 |
# File 'lib/itach/remote.rb', line 21 def socket @socket ||= TCPSocket.new address, port end |