Class: Tinkerforge::BrickletTemperatureIR

Inherits:
Device
  • Object
show all
Defined in:
lib/tinkerforge/bricklet_temperature_ir.rb

Overview

Measures contactless object temperature between -70°C and +380°C

Constant Summary collapse

DEVICE_IDENTIFIER =

:nodoc:

217
DEVICE_DISPLAY_NAME =

:nodoc:

'Temperature IR Bricklet'
CALLBACK_AMBIENT_TEMPERATURE =

This callback is triggered periodically with the period that is set by BrickletTemperatureIR#set_ambient_temperature_callback_period. The parameter is the ambient temperature of the sensor.

CALLBACK_AMBIENT_TEMPERATURE is only triggered if the ambient temperature has changed since the last triggering.

15
CALLBACK_OBJECT_TEMPERATURE =

This callback is triggered periodically with the period that is set by BrickletTemperatureIR#set_object_temperature_callback_period. The parameter is the object temperature of the sensor.

CALLBACK_OBJECT_TEMPERATURE is only triggered if the object temperature has changed since the last triggering.

16
CALLBACK_AMBIENT_TEMPERATURE_REACHED =

This callback is triggered when the threshold as set by BrickletTemperatureIR#set_ambient_temperature_callback_threshold is reached. The parameter is the ambient temperature of the sensor.

If the threshold keeps being reached, the callback is triggered periodically with the period as set by BrickletTemperatureIR#set_debounce_period.

17
CALLBACK_OBJECT_TEMPERATURE_REACHED =

This callback is triggered when the threshold as set by BrickletTemperatureIR#set_object_temperature_callback_threshold is reached. The parameter is the object temperature of the sensor.

If the threshold keeps being reached, the callback is triggered periodically with the period as set by BrickletTemperatureIR#set_debounce_period.

18
FUNCTION_GET_AMBIENT_TEMPERATURE =

:nodoc:

1
FUNCTION_GET_OBJECT_TEMPERATURE =

:nodoc:

2
FUNCTION_SET_EMISSIVITY =

:nodoc:

3
FUNCTION_GET_EMISSIVITY =

:nodoc:

4
FUNCTION_SET_AMBIENT_TEMPERATURE_CALLBACK_PERIOD =

:nodoc:

5
FUNCTION_GET_AMBIENT_TEMPERATURE_CALLBACK_PERIOD =

:nodoc:

6
FUNCTION_SET_OBJECT_TEMPERATURE_CALLBACK_PERIOD =

:nodoc:

7
FUNCTION_GET_OBJECT_TEMPERATURE_CALLBACK_PERIOD =

:nodoc:

8
FUNCTION_SET_AMBIENT_TEMPERATURE_CALLBACK_THRESHOLD =

:nodoc:

9
FUNCTION_GET_AMBIENT_TEMPERATURE_CALLBACK_THRESHOLD =

:nodoc:

10
FUNCTION_SET_OBJECT_TEMPERATURE_CALLBACK_THRESHOLD =

:nodoc:

11
FUNCTION_GET_OBJECT_TEMPERATURE_CALLBACK_THRESHOLD =

:nodoc:

12
FUNCTION_SET_DEBOUNCE_PERIOD =

:nodoc:

13
FUNCTION_GET_DEBOUNCE_PERIOD =

:nodoc:

14
FUNCTION_GET_IDENTITY =

:nodoc:

255
THRESHOLD_OPTION_OFF =

:nodoc:

'x'
THRESHOLD_OPTION_OUTSIDE =

:nodoc:

'o'
THRESHOLD_OPTION_INSIDE =

:nodoc:

'i'
THRESHOLD_OPTION_SMALLER =

:nodoc:

'<'
THRESHOLD_OPTION_GREATER =

:nodoc:

'>'

Constants inherited from Device

Device::RESPONSE_EXPECTED_ALWAYS_FALSE, Device::RESPONSE_EXPECTED_ALWAYS_TRUE, Device::RESPONSE_EXPECTED_FALSE, Device::RESPONSE_EXPECTED_INVALID_FUNCTION_ID, Device::RESPONSE_EXPECTED_TRUE

Instance Attribute Summary

Attributes inherited from Device

#callback_formats, #expected_response_function_id, #expected_response_sequence_number, #registered_callbacks, #uid

Instance Method Summary collapse

Methods inherited from Device

#dequeue_response, #enqueue_response, #get_api_version, #get_response_expected, #send_request, #set_response_expected, #set_response_expected_all

Constructor Details

#initialize(uid, ipcon) ⇒ BrickletTemperatureIR

Creates an object with the unique device ID uid and adds it to the IP Connection ipcon.



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/tinkerforge/bricklet_temperature_ir.rb', line 74

def initialize(uid, ipcon)
  super uid, ipcon

  @api_version = [2, 0, 0]

  @response_expected[FUNCTION_GET_AMBIENT_TEMPERATURE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_OBJECT_TEMPERATURE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_EMISSIVITY] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_EMISSIVITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_AMBIENT_TEMPERATURE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_AMBIENT_TEMPERATURE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_OBJECT_TEMPERATURE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_OBJECT_TEMPERATURE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_AMBIENT_TEMPERATURE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_AMBIENT_TEMPERATURE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_OBJECT_TEMPERATURE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_OBJECT_TEMPERATURE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[CALLBACK_AMBIENT_TEMPERATURE] = RESPONSE_EXPECTED_ALWAYS_FALSE
  @response_expected[CALLBACK_OBJECT_TEMPERATURE] = RESPONSE_EXPECTED_ALWAYS_FALSE
  @response_expected[CALLBACK_AMBIENT_TEMPERATURE_REACHED] = RESPONSE_EXPECTED_ALWAYS_FALSE
  @response_expected[CALLBACK_OBJECT_TEMPERATURE_REACHED] = RESPONSE_EXPECTED_ALWAYS_FALSE
  @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE

  @callback_formats[CALLBACK_AMBIENT_TEMPERATURE] = 's'
  @callback_formats[CALLBACK_OBJECT_TEMPERATURE] = 's'
  @callback_formats[CALLBACK_AMBIENT_TEMPERATURE_REACHED] = 's'
  @callback_formats[CALLBACK_OBJECT_TEMPERATURE_REACHED] = 's'
end

Instance Method Details

#get_ambient_temperatureObject

Returns the ambient temperature of the sensor. The value has a range of -400 to 1250 and is given in °C/10, e.g. a value of 423 means that an ambient temperature of 42.3 °C is measured.

If you want to get the ambient temperature periodically, it is recommended to use the callback CALLBACK_AMBIENT_TEMPERATURE and set the period with BrickletTemperatureIR#set_ambient_temperature_callback_period.



113
114
115
# File 'lib/tinkerforge/bricklet_temperature_ir.rb', line 113

def get_ambient_temperature
  send_request(FUNCTION_GET_AMBIENT_TEMPERATURE, [], '', 2, 's')
end

#get_ambient_temperature_callback_periodObject

Returns the period as set by BrickletTemperatureIR#set_ambient_temperature_callback_period.



173
174
175
# File 'lib/tinkerforge/bricklet_temperature_ir.rb', line 173

def get_ambient_temperature_callback_period
  send_request(FUNCTION_GET_AMBIENT_TEMPERATURE_CALLBACK_PERIOD, [], '', 4, 'L')
end

#get_ambient_temperature_callback_thresholdObject

Returns the threshold as set by BrickletTemperatureIR#set_ambient_temperature_callback_threshold.



211
212
213
# File 'lib/tinkerforge/bricklet_temperature_ir.rb', line 211

def get_ambient_temperature_callback_threshold
  send_request(FUNCTION_GET_AMBIENT_TEMPERATURE_CALLBACK_THRESHOLD, [], '', 5, 'k s s')
end

#get_debounce_periodObject

Returns the debounce period as set by BrickletTemperatureIR#set_debounce_period.



255
256
257
# File 'lib/tinkerforge/bricklet_temperature_ir.rb', line 255

def get_debounce_period
  send_request(FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 4, 'L')
end

#get_emissivityObject

Returns the emissivity as set by BrickletTemperatureIR#set_emissivity.



157
158
159
# File 'lib/tinkerforge/bricklet_temperature_ir.rb', line 157

def get_emissivity
  send_request(FUNCTION_GET_EMISSIVITY, [], '', 2, 'S')
end

#get_identityObject

Returns the UID, the UID where the Bricklet is connected to, the position, the hardware and firmware version as well as the device identifier.

The position can be ‘a’, ‘b’, ‘c’ or ‘d’.

The device identifier numbers can be found :ref:‘here <device_identifier>`. |device_identifier_constant|



267
268
269
# File 'lib/tinkerforge/bricklet_temperature_ir.rb', line 267

def get_identity
  send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S')
end

#get_object_temperatureObject

Returns the object temperature of the sensor, i.e. the temperature of the surface of the object the sensor is aimed at. The value has a range of -700 to 3800 and is given in °C/10, e.g. a value of 3001 means that a temperature of 300.1 °C is measured on the surface of the object.

The temperature of different materials is dependent on their ‘emissivity <en.wikipedia.org/wiki/Emissivity>`__. The emissivity of the material can be set with BrickletTemperatureIR#set_emissivity.

If you want to get the object temperature periodically, it is recommended to use the callback CALLBACK_OBJECT_TEMPERATURE and set the period with BrickletTemperatureIR#set_object_temperature_callback_period.



130
131
132
# File 'lib/tinkerforge/bricklet_temperature_ir.rb', line 130

def get_object_temperature
  send_request(FUNCTION_GET_OBJECT_TEMPERATURE, [], '', 2, 's')
end

#get_object_temperature_callback_periodObject

Returns the period as set by BrickletTemperatureIR#set_object_temperature_callback_period.



189
190
191
# File 'lib/tinkerforge/bricklet_temperature_ir.rb', line 189

def get_object_temperature_callback_period
  send_request(FUNCTION_GET_OBJECT_TEMPERATURE_CALLBACK_PERIOD, [], '', 4, 'L')
end

#get_object_temperature_callback_thresholdObject

Returns the threshold as set by BrickletTemperatureIR#set_object_temperature_callback_threshold.



233
234
235
# File 'lib/tinkerforge/bricklet_temperature_ir.rb', line 233

def get_object_temperature_callback_threshold
  send_request(FUNCTION_GET_OBJECT_TEMPERATURE_CALLBACK_THRESHOLD, [], '', 5, 'k s s')
end

#register_callback(id, &block) ⇒ Object

Registers a callback with ID id to the block block.



272
273
274
275
# File 'lib/tinkerforge/bricklet_temperature_ir.rb', line 272

def register_callback(id, &block)
  callback = block
  @registered_callbacks[id] = callback
end

#set_ambient_temperature_callback_period(period) ⇒ Object

Sets the period in ms with which the CALLBACK_AMBIENT_TEMPERATURE callback is triggered periodically. A value of 0 turns the callback off.

CALLBACK_AMBIENT_TEMPERATURE is only triggered if the temperature has changed since the last triggering.

The default value is 0.



168
169
170
# File 'lib/tinkerforge/bricklet_temperature_ir.rb', line 168

def set_ambient_temperature_callback_period(period)
  send_request(FUNCTION_SET_AMBIENT_TEMPERATURE_CALLBACK_PERIOD, [period], 'L', 0, '')
end

#set_ambient_temperature_callback_threshold(option, min, max) ⇒ Object

Sets the thresholds for the CALLBACK_AMBIENT_TEMPERATURE_REACHED callback.

The following options are possible:

"Option", "Description"

"'x'",    "Callback is turned off"
"'o'",    "Callback is triggered when the ambient temperature is *outside* the min and max values"
"'i'",    "Callback is triggered when the ambient temperature is *inside* the min and max values"
"'<'",    "Callback is triggered when the ambient temperature is smaller than the min value (max is ignored)"
"'>'",    "Callback is triggered when the ambient temperature is greater than the min value (max is ignored)"

The default value is (‘x’, 0, 0).



206
207
208
# File 'lib/tinkerforge/bricklet_temperature_ir.rb', line 206

def set_ambient_temperature_callback_threshold(option, min, max)
  send_request(FUNCTION_SET_AMBIENT_TEMPERATURE_CALLBACK_THRESHOLD, [option, min, max], 'k s s', 0, '')
end

#set_debounce_period(debounce) ⇒ Object

Sets the period in ms with which the threshold callbacks

  • CALLBACK_AMBIENT_TEMPERATURE_REACHED,

  • CALLBACK_OBJECT_TEMPERATURE_REACHED

are triggered, if the thresholds

  • BrickletTemperatureIR#set_ambient_temperature_callback_threshold,

  • BrickletTemperatureIR#set_object_temperature_callback_threshold

keep being reached.

The default value is 100.



250
251
252
# File 'lib/tinkerforge/bricklet_temperature_ir.rb', line 250

def set_debounce_period(debounce)
  send_request(FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 0, '')
end

#set_emissivity(emissivity) ⇒ Object

Sets the ‘emissivity <en.wikipedia.org/wiki/Emissivity>`__ that is used to calculate the surface temperature as returned by BrickletTemperatureIR#get_object_temperature.

The emissivity is usually given as a value between 0.0 and 1.0. A list of emissivities of different materials can be found ‘here <www.infrared-thermography.com/material.htm>`__.

The parameter of BrickletTemperatureIR#set_emissivity has to be given with a factor of 65535 (16-bit). For example: An emissivity of 0.1 can be set with the value 6553, an emissivity of 0.5 with the value 32767 and so on.

.. note

If you need a precise measurement for the object temperature, it is absolutely crucial that you also provide a precise emissivity.

The default emissivity is 1.0 (value of 65535) and the minimum emissivity the sensor can handle is 0.1 (value of 6553).



152
153
154
# File 'lib/tinkerforge/bricklet_temperature_ir.rb', line 152

def set_emissivity(emissivity)
  send_request(FUNCTION_SET_EMISSIVITY, [emissivity], 'S', 0, '')
end

#set_object_temperature_callback_period(period) ⇒ Object

Sets the period in ms with which the CALLBACK_OBJECT_TEMPERATURE callback is triggered periodically. A value of 0 turns the callback off.

CALLBACK_OBJECT_TEMPERATURE is only triggered if the temperature has changed since the last triggering.

The default value is 0.



184
185
186
# File 'lib/tinkerforge/bricklet_temperature_ir.rb', line 184

def set_object_temperature_callback_period(period)
  send_request(FUNCTION_SET_OBJECT_TEMPERATURE_CALLBACK_PERIOD, [period], 'L', 0, '')
end

#set_object_temperature_callback_threshold(option, min, max) ⇒ Object

Sets the thresholds for the CALLBACK_OBJECT_TEMPERATURE_REACHED callback.

The following options are possible:

"Option", "Description"

"'x'",    "Callback is turned off"
"'o'",    "Callback is triggered when the object temperature is *outside* the min and max values"
"'i'",    "Callback is triggered when the object temperature is *inside* the min and max values"
"'<'",    "Callback is triggered when the object temperature is smaller than the min value (max is ignored)"
"'>'",    "Callback is triggered when the object temperature is greater than the min value (max is ignored)"

The default value is (‘x’, 0, 0).



228
229
230
# File 'lib/tinkerforge/bricklet_temperature_ir.rb', line 228

def set_object_temperature_callback_threshold(option, min, max)
  send_request(FUNCTION_SET_OBJECT_TEMPERATURE_CALLBACK_THRESHOLD, [option, min, max], 'k s s', 0, '')
end