Class: Phidgets::TemperatureSensor

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/phidgets-ffi/temperature_sensor.rb

Overview

This class represents a PhidgetTemperatureSensor.

Defined Under Namespace

Classes: TemperatureSensorSensors

Constant Summary collapse

Klass =
Phidgets::FFI::CPhidgetTemperatureSensor

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 PhidgetTemperatureSensor



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

def attributes
  @attributes
end

#thermocouplesTemperatureSensorSensors (readonly)

Collection of temperature sensor sensors



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

def thermocouples
  @thermocouples
end

Instance Method Details

#on_temperature_change(obj = nil, &block) ⇒ Boolean

Sets a temperature change handler callback function. This is called when when the temperature has changed atleast by the sensitivity value that has been set.

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:

temp.on_temperature_change do |device, input, temperature, obj|
  puts "Input #{input.index}'s temperature changed to #{temperature}"
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
# File 'lib/phidgets-ffi/temperature_sensor.rb', line 32

def on_temperature_change(obj=nil, &block)
  @on_temperature_change_obj = obj
  @on_temperature_change = Proc.new { |device, obj_ptr, index, temperature|
 yield self, @thermocouples[index], temperature, object_for(obj_ptr)
	}
  Klass.set_OnTemperatureChange_Handler(@handle, @on_temperature_change, pointer_for(obj))
end