Class: Phidgets::IR
Overview
This class represents a PhidgetIR.
Defined Under Namespace
Classes: IR_code_info
Constant Summary collapse
- Klass =
Phidgets::FFI::CPhidgetIR
Instance Attribute Summary
Attributes included from Common
Instance Method Summary collapse
-
#last_code ⇒ Array<String>, ...
Gets the last code that was received.
-
#last_learned_code ⇒ Array<String>, ...
Gets the last code that was learned.
-
#on_code(obj = nil, &block) ⇒ Boolean
Sets a code handler callback function.
-
#on_learn(obj = nil, &block) ⇒ Boolean
Sets a learn handler callback function.
-
#on_raw_data(obj = nil, &block) ⇒ Boolean
Sets a raw data handler callback function.
-
#read_raw_data ⇒ Array<Integer>, Integer
Reads any available raw data.
-
#transmit(data, code_info) ⇒ Boolean
Transmits a code.
-
#transmit_raw(data, length, carrier_frequency, duty_cycle, gap) ⇒ Boolean
Transmits raw data as a series of pulses and spaces.
-
#transmit_repeat ⇒ Boolean
Transmits a repeat of a previously transmitted code, or raises an error.
Methods included from Common
#attached?, #attached_to_server?, attributes, #close, #detached?, #detached_to_server?, device_class, #device_class, device_id, #id, #initialize, #label, #label=, #name, #on_attach, #on_detach, #on_error, #on_server_connect, #on_server_disconnect, #on_sleep, #on_wake, #serial_number, #server_address, server_address, #server_id, server_id, server_status, #type, #version, #wait_for_attachment
Instance Method Details
#last_code ⇒ Array<String>, ...
Gets the last code that was received.
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/phidgets-ffi/ir.rb', line 230 def last_code data_ffi = ::FFI::MemoryPointer.new(:uchar, 16) data_length = ::FFI::MemoryPointer.new(:int) data_length.write_int(16) bit_count = ::FFI::MemoryPointer.new(:int) Klass.getLastCode(@handle, data_ffi, data_length, bit_count) data = [] data_length.get_int(0).times { |i| data << data_ffi[i].get_uchar(0).to_s(16) } [data, data_length.get_int(0), bit_count.get_int(0)] end |
#last_learned_code ⇒ Array<String>, ...
Gets the last code that was learned.
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/phidgets-ffi/ir.rb', line 254 def last_learned_code data_ffi = ::FFI::MemoryPointer.new(:uchar, 16) data_length = ::FFI::MemoryPointer.new(:int) data_length.write_int(16) code_info = ::FFI::MemoryPointer.new(IR_code_info) Klass.getLastLearnedCode(@handle, data_ffi, data_length, code_info) data = [] data_length.get_int(0).times { |i| data << data_ffi[i].get_uchar(0).to_s(16) } code_info_struct = IR_code_info.new(code_info) [data, data_length.get_int(0), code_info_struct] end |
#on_code(obj = nil, &block) ⇒ Boolean
Sets a code handler callback function. This is called whenever a new code is recognized.
As this runs in it’s own thread, be sure that all errors are properly handled or the thread will halt and not fire any more.
129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/phidgets-ffi/ir.rb', line 129 def on_code(obj=nil, &block) @on_code_obj = obj @on_code = Proc.new { |device, obj_ptr, data, data_length, bit_count, repeat| data_string = [] data_length.times { |i| data_string[i] = data[i].get_uchar(0).to_s(16) } yield self, data_string, data_length, bit_count, repeat, object_for(obj_ptr) } Klass.set_OnCode_Handler(@handle, @on_code, pointer_for(obj)) end |
#on_learn(obj = nil, &block) ⇒ Boolean
Sets a learn handler callback function. This is called when a new code has been learned. This generally requires the button to be held down for a second or two.
As this runs in it’s own thread, be sure that all errors are properly handled or the thread will halt and not fire any more.
152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/phidgets-ffi/ir.rb', line 152 def on_learn(obj=nil, &block) @on_learn_obj = obj @on_learn = Proc.new { |device, obj_ptr, int_data, data_length, code_info| data = [] data_length.times { |i| data[i] = int_data[i].get_uchar(0).to_s(16) } code_info_struct = IR_code_info.new(code_info) yield self, data, data_length, code_info_struct, object_for(obj_ptr) } Klass.set_OnLearn_Handler(@handle, @on_learn, pointer_for(obj)) end |
#on_raw_data(obj = nil, &block) ⇒ Boolean
Sets a raw data handler callback function. This is called whenever a new IR data is available. Data is in the form of an array of microsecond pulse values. This can be used if the user wishes to do their own data decoding, or for codes that the PhidgetIR cannot automatically recognize.
As this runs in it’s own thread, be sure that all errors are properly handled or the thread will halt and not fire any more.
106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/phidgets-ffi/ir.rb', line 106 def on_raw_data(obj=nil, &block) @on_raw_data_obj = obj @on_raw_data = Proc.new { |device, obj_ptr, raw_data, data_length| data = [] data_length.times { |i| data << raw_data[i].get_int(0) } yield self, data, data_length, object_for(obj_ptr) } Klass.set_OnRawData_Handler(@handle, @on_raw_data, pointer_for(obj)) end |
#read_raw_data ⇒ Array<Integer>, Integer
Reads any available raw data. This should be polled continuously(every 20ms) to avoid missing data. Read data always starts with a space and ends with a pulse.
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/phidgets-ffi/ir.rb', line 209 def read_raw_data data_ffi = ::FFI::MemoryPointer.new(:int, 16) data_length = ::FFI::MemoryPointer.new(:int) data_length.write_int(16) Klass.getRawData(@handle, data_ffi, data_length) data = [] data_length.get_int(0).times { |i| data << data_ffi[i].get_int(0) } [data, data_length.get_int(0)] end |
#transmit(data, code_info) ⇒ Boolean
Transmits a code
171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/phidgets-ffi/ir.rb', line 171 def transmit(data, code_info) pdata = ::FFI::MemoryPointer.new(:uchar, 16) data_ffi = [] data.size.times { |i| data_ffi[i] = data[i].to_i(16) } data_ffi = ::FFI::MemoryPointer.new(:uchar, 16).write_array_of_uchar(data_ffi) Klass.Transmit(@handle, data_ffi, code_info) true end |
#transmit_raw(data, length, carrier_frequency, duty_cycle, gap) ⇒ Boolean
Transmits raw data as a series of pulses and spaces.
200 201 202 203 204 |
# File 'lib/phidgets-ffi/ir.rb', line 200 def transmit_raw(data, length, carrier_frequency, duty_cycle, gap) c_data = ::FFI::MemoryPointer.new(:int, data.size).write_array_of_int(data) Klass.TransmitRaw(@handle, c_data, length.to_i, carrier_frequency.to_i, duty_cycle.to_i, gap.to_i) true end |
#transmit_repeat ⇒ Boolean
Transmits a repeat of a previously transmitted code, or raises an error.
188 189 190 191 |
# File 'lib/phidgets-ffi/ir.rb', line 188 def transmit_repeat Klass.TransmitRepeat(@handle) true end |