Class: Phidgets::Bridge

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#attributesObject (readonly)

The attributes of a PhidgetBridge



16
17
18
# File 'lib/phidgets-ffi/bridge.rb', line 16

def attributes
  @attributes
end

#inputsBridgeInputs (readonly)

Collection of bridge inputs

Returns:



11
12
13
# File 'lib/phidgets-ffi/bridge.rb', line 11

def inputs
  @inputs
end

Instance Method Details

#data_rateInteger

Returns the data rate of the board, in milliseconds, or raises an error.

Returns:

  • (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.

Parameters:

  • new_data_rate (Integer)

    data rate, in millilseconds

Returns:

  • (Integer)

    returns 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_maxInteger

Returns maximum data rate of the board, in milliseconds, or raises an error.

Returns:

  • (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_minInteger

Returns minimum data rate of the board, in milliseconds, or raises an error.

Returns:

  • (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.

Examples:

bridge.on_bridge_data do |device, input, value, obj|
  puts "Bridge Index  #{input.index}, value: #{value}"
end

Parameters:

  • obj (String) (defaults to: nil)

    Object to pass to the callback function. This is optional.

  • Block (Proc)

    When the callback is executed, the device and object are yielded to this block.

Returns:

  • (Boolean)

    returns true or raises an error



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