Class: Phidgets::Encoder
- Inherits:
-
Object
- Object
- Phidgets::Encoder
- Includes:
- Common
- Defined in:
- lib/phidgets-ffi/encoder.rb
Overview
This class represents a PhidgetEncoder
Defined Under Namespace
Classes: EncoderDigitalInputs, EncoderEncoders
Constant Summary collapse
- Klass =
Phidgets::FFI::CPhidgetEncoder
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
The attributes of a PhidgetEncoder.
-
#encoders ⇒ EncoderEncoders
readonly
Collection of encoders.
-
#inputs ⇒ EncoderDigitalInputs
readonly
Collection of digital inputs.
Instance Method Summary collapse
-
#on_input_change(obj = nil, &block) ⇒ Boolean
Sets an input change handler callback function.
-
#on_position_change(obj = nil, &block) ⇒ Boolean
Sets a position change handler callback function.
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 Attribute Details
#attributes ⇒ Object (readonly)
The attributes of a PhidgetEncoder
20 21 22 |
# File 'lib/phidgets-ffi/encoder.rb', line 20 def attributes @attributes end |
#encoders ⇒ EncoderEncoders (readonly)
Collection of encoders
15 16 17 |
# File 'lib/phidgets-ffi/encoder.rb', line 15 def encoders @encoders end |
#inputs ⇒ EncoderDigitalInputs (readonly)
Collection of digital inputs
11 12 13 |
# File 'lib/phidgets-ffi/encoder.rb', line 11 def inputs @inputs end |
Instance Method Details
#on_input_change(obj = nil, &block) ⇒ Boolean
Sets an input change handler callback function. This is called when a digital input on the PhidgetEncoder board has changed.
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.
37 38 39 40 41 42 43 |
# File 'lib/phidgets-ffi/encoder.rb', line 37 def on_input_change(obj=nil, &block) @on_input_change_obj = obj @on_input_change = Proc.new { |device, obj_ptr, index, state| yield self, @inputs[index], (state == 0 ? false : true), object_for(obj_ptr) } Klass.set_OnInputChange_Handler(@handle, @on_input_change, pointer_for(obj)) end |
#on_position_change(obj = nil, &block) ⇒ Boolean
Sets a position change handler callback function. This is called when an encoder position changes.
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.
55 56 57 58 59 60 61 |
# File 'lib/phidgets-ffi/encoder.rb', line 55 def on_position_change(obj=nil, &block) @on_position_change_obj = obj @on_position_change = Proc.new { |device, obj_ptr, index, time, position_change| yield self, @encoders[index], time, position_change, object_for(obj_ptr) } Klass.set_OnPositionChange_Handler(@handle, @on_position_change, pointer_for(obj)) end |