Class: Phidgets::InterfaceKit

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

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 PhidgetInterfaceKit



24
25
26
# File 'lib/phidgets-ffi/interface_kit.rb', line 24

def attributes
  @attributes
end

#inputsInterfaceKitInputs (readonly)

Collection of digital inputs

Returns:



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

def inputs
  @inputs
end

#outputsInterfaceKitOutputs (readonly)

Collection of digital outputs

Returns:



15
16
17
# File 'lib/phidgets-ffi/interface_kit.rb', line 15

def outputs
  @outputs
end

#sensorsInterfaceKitSensors (readonly)

Collection of analog sensor inputs

Returns:



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.

Examples:

ifkit.on_input_change do |device, input, state, obj|
  print "Digital Input  #{input.index}, changed to #{state}\n"
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



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.

Examples:

ifkit.on_output_change do |device, output, state, obj|
  print "Digital Output  #{output.index}, changed to #{state}\n"
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



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.

Examples:

ifkit.on_sensor_change do |device, input, value, obj|
  print "Analog Input  #{input.index}, changed to #{value}\n"
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



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

#ratiometricBoolean Also known as: ratiometric?

Returns the ratiometric state of the Phidget.

Returns:

  • (Boolean)

    returns the ratiometric state or raises an error



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.

Parameters:

  • new_state (Boolean)

    new ratiometric state

Returns:

  • (Boolean)

    returns the ratiometric state or raises an error



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