Class: Phidgets::InterfaceKit
- Inherits:
-
Object
- Object
- Phidgets::InterfaceKit
- Includes:
- Common
- Defined in:
- lib/phidgets-ffi/interface_kit.rb
Overview
This class represents a PhidgetInterfaceKit.
Defined Under Namespace
Classes: InterfaceKitInputs, InterfaceKitOutputs, InterfaceKitSensors
Constant Summary collapse
- Klass =
Phidgets::FFI::CPhidgetInterfaceKit
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
The attributes of a PhidgetInterfaceKit.
-
#inputs ⇒ InterfaceKitInputs
readonly
Collection of digital inputs.
-
#outputs ⇒ InterfaceKitOutputs
readonly
Collection of digital outputs.
-
#sensors ⇒ InterfaceKitSensors
readonly
Collection of analog sensor inputs.
Instance Method Summary collapse
-
#on_input_change(obj = nil, &block) ⇒ Boolean
Sets an input change handler callback function.
-
#on_output_change(obj = nil, &block) ⇒ Boolean
Sets an output change handler callback function.
-
#on_sensor_change(obj = nil, &block) ⇒ Boolean
Sets a sensor change handler callback function.
-
#ratiometric ⇒ Boolean
(also: #ratiometric?)
Returns the ratiometric state of the Phidget.
-
#ratiometric=(new_state) ⇒ Boolean
Sets the ratiometric state of the Phidget.
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 PhidgetInterfaceKit
24 25 26 |
# File 'lib/phidgets-ffi/interface_kit.rb', line 24 def attributes @attributes end |
#inputs ⇒ InterfaceKitInputs (readonly)
Collection of digital inputs
11 12 13 |
# File 'lib/phidgets-ffi/interface_kit.rb', line 11 def inputs @inputs end |
#outputs ⇒ InterfaceKitOutputs (readonly)
Collection of digital outputs
15 16 17 |
# File 'lib/phidgets-ffi/interface_kit.rb', line 15 def outputs @outputs end |
#sensors ⇒ InterfaceKitSensors (readonly)
Collection of analog sensor inputs
19 20 21 |
# File 'lib/phidgets-ffi/interface_kit.rb', line 19 def sensors @sensors 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 PhidgetInterfaceKit 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.
43 44 45 46 47 48 49 |
# File 'lib/phidgets-ffi/interface_kit.rb', line 43 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_output_change(obj = nil, &block) ⇒ Boolean
Sets an output change handler callback function. This is called when a digital output on the PhidgetInterfaceKit 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.
61 62 63 64 65 66 67 |
# File 'lib/phidgets-ffi/interface_kit.rb', line 61 def on_output_change(obj=nil, &block) @on_output_change_obj = obj @on_output_change = Proc.new { |device, obj_ptr, index, state| yield self, @outputs[index], (state == 0 ? false : true), object_for(obj_ptr) } Klass.set_OnOutputChange_Handler(@handle, @on_output_change, pointer_for(obj)) end |
#on_sensor_change(obj = nil, &block) ⇒ Boolean
Sets a sensor change handler callback function. This is called when a sensor on the PhidgetInterfaceKit has changed by at least the sensitivity value that has been set for this input.
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.
79 80 81 82 83 84 85 |
# File 'lib/phidgets-ffi/interface_kit.rb', line 79 def on_sensor_change(obj=nil, &block) @on_sensor_change_obj = obj @on_sensor_change = Proc.new { |device, obj_ptr, index, value| yield self, @sensors[index], value, object_for(obj_ptr) } Klass.set_OnSensorChange_Handler(@handle, @on_sensor_change, pointer_for(obj)) end |
#ratiometric ⇒ Boolean Also known as: ratiometric?
Returns the ratiometric state of the Phidget.
90 91 92 93 94 |
# File 'lib/phidgets-ffi/interface_kit.rb', line 90 def ratiometric ptr = ::FFI::MemoryPointer.new(:int) Klass.getRatiometric(@handle, ptr) (ptr.get_int(0) == 0) ? false : true end |
#ratiometric=(new_state) ⇒ Boolean
Sets the ratiometric state of the Phidget.
100 101 102 103 104 |
# File 'lib/phidgets-ffi/interface_kit.rb', line 100 def ratiometric=(new_state) tmp = new_state ? 1 : 0 Klass.setRatiometric(@handle, tmp) new_state end |