Class: Phidgets::Bridge
- Inherits:
-
Object
- Object
- Phidgets::Bridge
- Includes:
- Common
- Defined in:
- lib/phidgets-ffi/bridge.rb
Overview
This class represents a PhidgetBridge.
Defined Under Namespace
Classes: BridgeInputs
Constant Summary collapse
- Klass =
Phidgets::FFI::CPhidgetBridge
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
The attributes of a PhidgetBridge.
-
#inputs ⇒ BridgeInputs
readonly
Collection of bridge inputs.
Instance Method Summary collapse
-
#data_rate ⇒ Integer
Returns the data rate of the board, in milliseconds, or raises an error.
-
#data_rate=(new_data_rate) ⇒ Integer
Sets the data rate of the board, or raises an error.
-
#data_rate_max ⇒ Integer
Returns maximum data rate of the board, in milliseconds, or raises an error.
-
#data_rate_min ⇒ Integer
Returns minimum data rate of the board, in milliseconds, or raises an error.
-
#on_bridge_data(obj = nil, &block) ⇒ Boolean
Sets a bridge data 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 PhidgetBridge
16 17 18 |
# File 'lib/phidgets-ffi/bridge.rb', line 16 def attributes @attributes end |
#inputs ⇒ BridgeInputs (readonly)
Collection of bridge inputs
11 12 13 |
# File 'lib/phidgets-ffi/bridge.rb', line 11 def inputs @inputs end |
Instance Method Details
#data_rate ⇒ Integer
Returns the data rate of the board, in milliseconds, or raises an error.
43 44 45 46 47 |
# File 'lib/phidgets-ffi/bridge.rb', line 43 def data_rate ptr = ::FFI::MemoryPointer.new(:int) Klass.getDataRate(@handle, ptr) ptr.get_int(0) end |
#data_rate=(new_data_rate) ⇒ Integer
Sets the data rate of the board, or raises an error.
52 53 54 55 |
# File 'lib/phidgets-ffi/bridge.rb', line 52 def data_rate=(new_data_rate) Klass.setDataRate(@handle, new_data_rate.to_i) new_data_rate.to_i end |
#data_rate_max ⇒ Integer
Returns maximum data rate of the board, in milliseconds, or raises an error.
58 59 60 61 62 |
# File 'lib/phidgets-ffi/bridge.rb', line 58 def data_rate_max ptr = ::FFI::MemoryPointer.new(:int) Klass.getDataRateMax(@handle, ptr) ptr.get_int(0) end |
#data_rate_min ⇒ Integer
Returns minimum data rate of the board, in milliseconds, or raises an error.
65 66 67 68 69 |
# File 'lib/phidgets-ffi/bridge.rb', line 65 def data_rate_min ptr = ::FFI::MemoryPointer.new(:int) Klass.getDataRateMin(@handle, ptr) ptr.get_int(0) end |
#on_bridge_data(obj = nil, &block) ⇒ Boolean
Sets a bridge data handler callback function. This is called at a set rate as defined by #data_rate
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.
32 33 34 35 36 37 38 39 40 |
# File 'lib/phidgets-ffi/bridge.rb', line 32 def on_bridge_data(obj=nil, &block) @on_bridge_data_obj = obj @on_bridge_data = Proc.new { |device, obj_ptr, index, value| yield self, @inputs[index], value, object_for(obj_ptr) } Klass.set_OnBridgeData_Handler(@handle, @on_bridge_data, pointer_for(obj)) end |