class Tinkerforge::BrickletCO2

Measures CO2 concentration in ppm

Constants

CALLBACK_CO2_CONCENTRATION

This callback is triggered periodically with the period that is set by BrickletCO2#set_co2_concentration_callback_period. The parameter is the CO2 concentration of the sensor.

The CALLBACK_CO2_CONCENTRATION callback is only triggered if the CO2 concentration has changed since the last triggering.

CALLBACK_CO2_CONCENTRATION_REACHED

This callback is triggered when the threshold as set by BrickletCO2#set_co2_concentration_callback_threshold is reached. The parameter is the CO2 concentration.

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

Public Class Methods

new(uid, ipcon) click to toggle source

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

Calls superclass method
# File lib/tinkerforge/bricklet_co2.rb, line 52
def initialize(uid, ipcon)
  super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME

  @api_version = [2, 0, 0]

  @response_expected[FUNCTION_GET_CO2_CONCENTRATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_CO2_CONCENTRATION_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_CO2_CONCENTRATION_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_CO2_CONCENTRATION_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_CO2_CONCENTRATION_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[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE

  @callback_formats[CALLBACK_CO2_CONCENTRATION] = [10, 'S']
  @callback_formats[CALLBACK_CO2_CONCENTRATION_REACHED] = [10, 'S']

  @ipcon.add_device self
end

Public Instance Methods

get_co2_concentration() click to toggle source

Returns the measured CO2 concentration.

If you want to get the CO2 concentration periodically, it is recommended to use the CALLBACK_CO2_CONCENTRATION callback and set the period with BrickletCO2#set_co2_concentration_callback_period.

# File lib/tinkerforge/bricklet_co2.rb, line 77
def get_co2_concentration
  check_validity

  send_request FUNCTION_GET_CO2_CONCENTRATION, [], '', 10, 'S'
end
get_co2_concentration_callback_period() click to toggle source

Returns the period as set by BrickletCO2#set_co2_concentration_callback_period.

# File lib/tinkerforge/bricklet_co2.rb, line 95
def get_co2_concentration_callback_period
  check_validity

  send_request FUNCTION_GET_CO2_CONCENTRATION_CALLBACK_PERIOD, [], '', 12, 'L'
end
get_co2_concentration_callback_threshold() click to toggle source

Returns the threshold as set by BrickletCO2#set_co2_concentration_callback_threshold.

# File lib/tinkerforge/bricklet_co2.rb, line 119
def get_co2_concentration_callback_threshold
  check_validity

  send_request FUNCTION_GET_CO2_CONCENTRATION_CALLBACK_THRESHOLD, [], '', 13, 'k S S'
end
get_debounce_period() click to toggle source

Returns the debounce period as set by BrickletCO2#set_debounce_period.

# File lib/tinkerforge/bricklet_co2.rb, line 141
def get_debounce_period
  check_validity

  send_request FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 12, 'L'
end
get_identity() click to toggle source

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', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port). A Bricklet connected to an :ref:`Isolator Bricklet <isolator_bricklet>` is always at position 'z'.

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

# File lib/tinkerforge/bricklet_co2.rb, line 157
def get_identity
  send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S'
end
register_callback(id, &block) click to toggle source

Registers a callback with ID id to the block block.

# File lib/tinkerforge/bricklet_co2.rb, line 162
def register_callback(id, &block)
  callback = block
  @registered_callbacks[id] = callback
end
set_co2_concentration_callback_period(period) click to toggle source

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

The CALLBACK_CO2_CONCENTRATION callback is only triggered if the CO2 concentration has changed since the last triggering.

# File lib/tinkerforge/bricklet_co2.rb, line 88
def set_co2_concentration_callback_period(period)
  check_validity

  send_request FUNCTION_SET_CO2_CONCENTRATION_CALLBACK_PERIOD, [period], 'L', 8, ''
end
set_co2_concentration_callback_threshold(option, min, max) click to toggle source

Sets the thresholds for the CALLBACK_CO2_CONCENTRATION_REACHED callback.

The following options are possible:

"Option", "Description"

"'x'",    "Callback is turned off"
"'o'",    "Callback is triggered when the CO2 concentration is *outside* the min and max values"
"'i'",    "Callback is triggered when the CO2 concentration is *inside* the min and max values"
"'<'",    "Callback is triggered when the CO2 concentration is smaller than the min value (max is ignored)"
"'>'",    "Callback is triggered when the CO2 concentration is greater than the min value (max is ignored)"
# File lib/tinkerforge/bricklet_co2.rb, line 112
def set_co2_concentration_callback_threshold(option, min, max)
  check_validity

  send_request FUNCTION_SET_CO2_CONCENTRATION_CALLBACK_THRESHOLD, [option, min, max], 'k S S', 8, ''
end
set_debounce_period(debounce) click to toggle source

Sets the period with which the threshold callbacks

are triggered, if the thresholds

keep being reached.

# File lib/tinkerforge/bricklet_co2.rb, line 134
def set_debounce_period(debounce)
  check_validity

  send_request FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 8, ''
end