Class: Phidgets::IR
- Defined in:
- lib/phidgets/ir.rb,
ext/phidgets/phidgets_ir.c
Constant Summary collapse
- ENCODING_UNKNOWN =
INT2NUM(IR_ENCODING_UNKNOWN)
- ENCODING_SPACE =
INT2NUM(IR_ENCODING_SPACE)
- ENCODING_PULSE =
INT2NUM(IR_ENCODING_PULSE)
- ENCODING_BIPHASE =
INT2NUM(IR_ENCODING_BIPHASE)
- ENCODING_RC5 =
INT2NUM(IR_ENCODING_RC5)
- ENCODING_RC6 =
INT2NUM(IR_ENCODING_RC6)
- LENGTH_UNKNOWN =
INT2NUM(IR_LENGTH_UNKNOWN)
- LENGTH_CONSTANT =
INT2NUM(IR_LENGTH_CONSTANT)
- LENGTH_VARIABLE =
INT2NUM(IR_LENGTH_VARIABLE)
Instance Method Summary collapse
-
#getLastCode ⇒ Object
(also: #last_code)
The last code the channel has received.
-
#getLastLearnedCode ⇒ Object
(also: #last_learned_code)
The last code the channel has learned.
-
#new ⇒ Object
constructor
Creates a Phidget IR object.
-
#setOnCodeHandler(cb_proc = nil, &cb_block) ⇒ Object
(also: #on_code)
call-seq: setOnCodeHandler(proc=nil, &block).
-
#setOnLearnHandler(cb_proc = nil, &cb_block) ⇒ Object
(also: #on_learn)
call-seq: setOnLearnHandler(proc=nil, &block).
-
#setOnRawDataHandler(cb_proc = nil, &cb_block) ⇒ Object
(also: #on_raw_data)
call-seq: setOnRawDataHandler(proc=nil, &block).
-
#transmit(code, code_info) ⇒ Object
Transmits a code code data is transmitted MSBit first.
-
#transmitRaw(data, carrier_frequency, duty_cycle, gap) ⇒ Object
(also: #transmit_raw)
Transmits raw data as a series of pulses and spaces.
-
#transmitRepeat ⇒ Object
(also: #transmit_repeat)
Transmits a repeat of the last transmited code.
Methods inherited from Common
#close, #getAttached, #getChannel, #getChannelClass, #getChannelClassName, #getChannelName, #getChannelSubclass, #getDataInterval, #getDeviceChannelCount, #getDeviceClass, #getDeviceClassName, #getDeviceID, #getDeviceLabel, #getDeviceName, #getDeviceSKU, #getDeviceSerialNumber, #getDeviceVersion, #getHubPort, #getHubPortCount, #getIsChannel, #getIsHubPortDevice, #getIsLocal, #getIsRemote, #getServerHostname, #getServerName, #getServerPeerName, #getServerUniqueName, #open, #openWaitForAttachment, #setChannel, #setDataInterval, #setDeviceLabel, #setDeviceSerialNumber, #setHubPort, #setIsHubPortDevice, #setIsLocal, #setIsRemote, #setOnAttachHandler, #setOnDetachHandler, #setOnErrorHandler, #setOnPropertyChangeHandler, #setServerName, #writeDeviceLabel
Constructor Details
#new ⇒ Object
Creates a Phidget IR object.
10 11 12 13 14 |
# File 'ext/phidgets/phidgets_ir.c', line 10
VALUE ph_ir_init(VALUE self) {
ph_data_t *ph = get_ph_data(self);
ph_raise(PhidgetIR_create((PhidgetIRHandle *)(&(ph->handle))));
return self;
}
|
Instance Method Details
#getLastCode ⇒ Object Also known as: last_code
The last code the channel has received. The code is represented by a hexadecimal string (array of bytes)
62 63 64 65 66 67 68 69 70 71 72 |
# File 'ext/phidgets/phidgets_ir.c', line 62
VALUE ph_ir_get_last_code(VALUE self) {
PhidgetIRHandle handle = (PhidgetIRHandle)get_ph_handle(self);
char code[IR_MAX_CODE_STR_LENGTH];
uint32_t bitCount;
VALUE rb_code_data = rb_hash_new();
ph_raise(PhidgetIR_getLastCode(handle, code, IR_MAX_CODE_STR_LENGTH, &bitCount));
rb_hash_aset(rb_code_data, rb_str_new2("code"), rb_str_new2(code));
rb_hash_aset(rb_code_data, rb_str_new2("bitCount"), UINT2NUM(bitCount));
return rb_code_data;
}
|
#getLastLearnedCode ⇒ Object Also known as: last_learned_code
The last code the channel has learned. The code is represented by a hexadecimal string (array of bytes). The codeInfo structure holds data that describes the learned code
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'ext/phidgets/phidgets_ir.c', line 75
VALUE ph_ir_get_last_learned_code(VALUE self) {
PhidgetIRHandle handle = (PhidgetIRHandle)get_ph_handle(self);
char code[IR_MAX_CODE_STR_LENGTH];
PhidgetIR_CodeInfo info;
VALUE rb_code_data = rb_hash_new();
VALUE rb_code_info = rb_hash_new();
VALUE rb_info_header = rb_ary_new();
VALUE rb_info_one = rb_ary_new();
VALUE rb_info_zero = rb_ary_new();
VALUE rb_info_repeat = rb_ary_new();
VALUE rb_info_toggle_mask = rb_ary_new();
int i;
ph_raise(PhidgetIR_getLastLearnedCode(handle, code, IR_MAX_CODE_STR_LENGTH, &info));
rb_hash_aset(rb_code_info, rb_str_new2("bitCount"), UINT2NUM(info.bitCount));
rb_hash_aset(rb_code_info, rb_str_new2("encoding"), INT2NUM(info.encoding));
rb_hash_aset(rb_code_info, rb_str_new2("length"), INT2NUM(info.length));
rb_hash_aset(rb_code_info, rb_str_new2("gap"), UINT2NUM(info.gap));
rb_hash_aset(rb_code_info, rb_str_new2("trail"), UINT2NUM(info.trail));
for(i=0; i<2; i++) { rb_ary_push(rb_info_header, UINT2NUM(info.header[i])); }
rb_hash_aset(rb_code_info, rb_str_new2("header"), rb_info_header);
for(i=0; i<2; i++) { rb_ary_push(rb_info_one, UINT2NUM(info.one[i])); }
rb_hash_aset(rb_code_info, rb_str_new2("one"), rb_info_one);
for(i=0; i<2; i++) { rb_ary_push(rb_info_zero, UINT2NUM(info.zero[i])); }
rb_hash_aset(rb_code_info, rb_str_new2("zero"), rb_info_zero);
for(i=0; i<26; i++) { rb_ary_push(rb_info_repeat, UINT2NUM(info.repeat[i])); }
rb_hash_aset(rb_code_info, rb_str_new2("repeat"), rb_info_repeat);
rb_hash_aset(rb_code_info, rb_str_new2("minRepeat"), UINT2NUM(info.minRepeat));
rb_hash_aset(rb_code_info, rb_str_new2("dutyCycle"), DBL2NUM(info.dutyCycle));
rb_hash_aset(rb_code_info, rb_str_new2("carrierFrequency"), UINT2NUM(info.carrierFrequency));
for(i=0; i<33; i++) { rb_ary_push(rb_info_toggle_mask, INT2NUM(info.toggleMask[i])); }
rb_hash_aset(rb_code_info, rb_str_new2("toggleMask"), rb_info_toggle_mask);
rb_hash_aset(rb_code_data, rb_str_new2("code"), rb_str_new2(code));
rb_hash_aset(rb_code_data, rb_str_new2("codeInfo"), rb_code_info);
return rb_code_data;
}
|
#setOnCodeHandler(cb_proc = nil, &cb_block) ⇒ Object Also known as: on_code
call-seq:
setOnCodeHandler(proc=nil, &block)
Assigns a handler that will be called when the Code event occurs.
11 12 13 14 15 |
# File 'lib/phidgets/ir.rb', line 11 def setOnCodeHandler(cb_proc = nil, &cb_block) @on_code_thread.kill if defined? @on_code_thread and @on_code_thread.alive? callback = cb_proc || cb_block @on_code_thread = Thread.new {ext_setOnCodeHandler(callback)} end |
#setOnLearnHandler(cb_proc = nil, &cb_block) ⇒ Object Also known as: on_learn
call-seq:
setOnLearnHandler(proc=nil, &block)
Assigns a handler that will be called when the Learn event occurs.
22 23 24 25 26 |
# File 'lib/phidgets/ir.rb', line 22 def setOnLearnHandler(cb_proc = nil, &cb_block) @on_learn_thread.kill if defined? @on_learn_thread and @on_learn_thread.alive? callback = cb_proc || cb_block @on_learn_thread = Thread.new {ext_setOnLearnHandler(callback)} end |
#setOnRawDataHandler(cb_proc = nil, &cb_block) ⇒ Object Also known as: on_raw_data
call-seq:
setOnRawDataHandler(proc=nil, &block)
Assigns a handler that will be called when the RawData event occurs.
33 34 35 36 37 |
# File 'lib/phidgets/ir.rb', line 33 def setOnRawDataHandler(cb_proc = nil, &cb_block) @on_raw_data_thread.kill if defined? @on_raw_data_thread and @on_raw_data_thread.alive? callback = cb_proc || cb_block @on_raw_data_thread = Thread.new {ext_setOnRawDataHandler(callback)} end |
#transmit(code, code_info) ⇒ Object
Transmits a code code data is transmitted MSBit first. MSByte is in array index 0 of code LSBit is right justified, therefore, MSBit may be in bit position 0-7 (of array index 0) depending on the bit count
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'ext/phidgets/phidgets_ir.c', line 17
VALUE ph_ir_transmit(VALUE self, VALUE code, VALUE code_info) {
PhidgetIRHandle handle = (PhidgetIRHandle)get_ph_handle(self);
PhidgetIR_CodeInfo info;
int i;
if(! RB_TYPE_P(code, T_STRING)) ph_raise(EPHIDGET_INVALIDARG);
if(! RB_TYPE_P(code_info, T_HASH)) ph_raise(EPHIDGET_INVALIDARG);
info.bitCount = NUM2UINT(rb_hash_aref(code_info, rb_str_new2("bitCount")));
info.encoding = NUM2INT(rb_hash_aref(code_info, rb_str_new2("encoding")));
info.length = NUM2INT(rb_hash_aref(code_info, rb_str_new2("length")));
info.gap = NUM2UINT(rb_hash_aref(code_info, rb_str_new2("gap")));
info.trail = NUM2UINT(rb_hash_aref(code_info, rb_str_new2("trail")));
for(i=0; i<2; i++) { info.header[i] = NUM2UINT(rb_ary_entry(rb_hash_aref(code_info, rb_str_new2("header")), i)); }
for(i=0; i<2; i++) { info.one[i] = NUM2UINT(rb_ary_entry(rb_hash_aref(code_info, rb_str_new2("one")), i)); }
for(i=0; i<2; i++) { info.zero[i] = NUM2UINT(rb_ary_entry(rb_hash_aref(code_info, rb_str_new2("zero")), i)); }
for(i=0; i<26; i++) { info.repeat[i] = NUM2UINT(rb_ary_entry(rb_hash_aref(code_info, rb_str_new2("repeat")), i)); }
info.minRepeat = NUM2UINT(rb_hash_aref(code_info, rb_str_new2("minRepeat")));
info.dutyCycle = NUM2DBL(rb_hash_aref(code_info, rb_str_new2("dutyCycle")));
info.carrierFrequency = NUM2UINT(rb_hash_aref(code_info, rb_str_new2("carrierFrequency")));
for(i=0; i<33; i++) { info.toggleMask[i] = NUM2CHR(rb_ary_entry(rb_hash_aref(code_info, rb_str_new2("toggleMask")), i)); }
ph_raise(PhidgetIR_transmit(handle, StringValuePtr(code), &info));
return Qnil;
}
|
#transmitRaw(data, carrier_frequency, duty_cycle, gap) ⇒ Object Also known as: transmit_raw
Transmits raw data as a series of pulses and spaces. data must start and end with a pulse.
Each element is a positive time in μs
dataLength has a maximum length of 200, however, streams should be kept must shorter than this (less than 100ms between gaps).
dataLength must be an odd number
Leave carrierFrequency as 0 for default.
carrierFrequency has a range of 10kHz - 1MHz
Leave dutyCycle as 0 for default
dutyCycle can have a value between 0.1 and 0.5
Specifying a gap will guarantee a gap time (no transmitting) after data is sent.
gap time is in μs
gap time can be set to 0
50 51 52 53 54 55 56 57 58 59 |
# File 'ext/phidgets/phidgets_ir.c', line 50
VALUE ph_ir_transmit_raw(VALUE self, VALUE data, VALUE carrier_freq, VALUE duty_cycle, VALUE gap) {
PhidgetIRHandle handle = (PhidgetIRHandle)get_ph_handle(self);
size_t data_length = RARRAY_LEN(data);
uint32_t raw_data[200];
size_t i;
for(i=0; i<data_length; i++) { raw_data[i] = NUM2UINT(rb_ary_entry(data, i)); }
ph_raise(PhidgetIR_transmitRaw(handle, raw_data, data_length, NUM2UINT(carrier_freq), NUM2DBL(duty_cycle), NUM2UINT(gap)));
return Qnil;
}
|
#transmitRepeat ⇒ Object Also known as: transmit_repeat
Transmits a repeat of the last transmited code. Depending on the CodeInfo structure, this may be a retransmission of the code itself, or there may be a special repeat code.
44 45 46 47 |
# File 'ext/phidgets/phidgets_ir.c', line 44
VALUE ph_ir_transmit_repeat(VALUE self) {
ph_raise(PhidgetIR_transmitRepeat((PhidgetIRHandle)get_ph_handle(self)));
return Qnil;
}
|