Class: Tinkerforge::BrickletDustDetector

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

Overview

Measures dust density

Constant Summary collapse

DEVICE_IDENTIFIER =

:nodoc:

260
DEVICE_DISPLAY_NAME =

:nodoc:

'Dust Detector Bricklet'
CALLBACK_DUST_DENSITY =

This callback is triggered periodically with the period that is set by BrickletDustDetector#set_dust_density_callback_period. The parameter is the dust density of the sensor.

CALLBACK_DUST_DENSITY is only triggered if the dust density value has changed since the last triggering.

8
CALLBACK_DUST_DENSITY_REACHED =

This callback is triggered when the threshold as set by BrickletDustDetector#set_dust_density_callback_threshold is reached. The parameter is the dust density of the sensor.

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

9
FUNCTION_GET_DUST_DENSITY =

:nodoc:

1
FUNCTION_SET_DUST_DENSITY_CALLBACK_PERIOD =

:nodoc:

2
FUNCTION_GET_DUST_DENSITY_CALLBACK_PERIOD =

:nodoc:

3
FUNCTION_SET_DUST_DENSITY_CALLBACK_THRESHOLD =

:nodoc:

4
FUNCTION_GET_DUST_DENSITY_CALLBACK_THRESHOLD =

:nodoc:

5
FUNCTION_SET_DEBOUNCE_PERIOD =

:nodoc:

6
FUNCTION_GET_DEBOUNCE_PERIOD =

:nodoc:

7
FUNCTION_SET_MOVING_AVERAGE =

:nodoc:

10
FUNCTION_GET_MOVING_AVERAGE =

:nodoc:

11
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) ⇒ BrickletDustDetector

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



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/tinkerforge/bricklet_dust_detector.rb', line 53

def initialize(uid, ipcon)
  super uid, ipcon

  @api_version = [2, 0, 0]

  @response_expected[FUNCTION_GET_DUST_DENSITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_DUST_DENSITY_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_DUST_DENSITY_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_DUST_DENSITY_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_DUST_DENSITY_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_DUST_DENSITY] = RESPONSE_EXPECTED_ALWAYS_FALSE
  @response_expected[CALLBACK_DUST_DENSITY_REACHED] = RESPONSE_EXPECTED_ALWAYS_FALSE
  @response_expected[FUNCTION_SET_MOVING_AVERAGE] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_MOVING_AVERAGE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE

  @callback_formats[CALLBACK_DUST_DENSITY] = 'S'
  @callback_formats[CALLBACK_DUST_DENSITY_REACHED] = 'S'
end

Instance Method Details

#get_debounce_periodObject

Returns the debounce period as set by BrickletDustDetector#set_debounce_period.



138
139
140
# File 'lib/tinkerforge/bricklet_dust_detector.rb', line 138

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

#get_dust_densityObject

Returns the dust density in µg/m³.

If you want to get the dust density periodically, it is recommended to use the callback CALLBACK_DUST_DENSITY and set the period with BrickletDustDetector#set_dust_density_callback_period.



80
81
82
# File 'lib/tinkerforge/bricklet_dust_detector.rb', line 80

def get_dust_density
  send_request(FUNCTION_GET_DUST_DENSITY, [], '', 2, 'S')
end

#get_dust_density_callback_periodObject

Returns the period as set by BrickletDustDetector#set_dust_density_callback_period.



96
97
98
# File 'lib/tinkerforge/bricklet_dust_detector.rb', line 96

def get_dust_density_callback_period
  send_request(FUNCTION_GET_DUST_DENSITY_CALLBACK_PERIOD, [], '', 4, 'L')
end

#get_dust_density_callback_thresholdObject

Returns the threshold as set by BrickletDustDetector#set_dust_density_callback_threshold.



118
119
120
# File 'lib/tinkerforge/bricklet_dust_detector.rb', line 118

def get_dust_density_callback_threshold
  send_request(FUNCTION_GET_DUST_DENSITY_CALLBACK_THRESHOLD, [], '', 5, 'k S 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|



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

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

#get_moving_averageObject

Returns the length moving average as set by BrickletDustDetector#set_moving_average.



156
157
158
# File 'lib/tinkerforge/bricklet_dust_detector.rb', line 156

def get_moving_average
  send_request(FUNCTION_GET_MOVING_AVERAGE, [], '', 1, 'C')
end

#register_callback(id, &block) ⇒ Object

Registers a callback with ID id to the block block.



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

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

#set_debounce_period(debounce) ⇒ Object

Sets the period in ms with which the threshold callback

  • CALLBACK_DUST_DENSITY_REACHED

is triggered, if the threshold

  • BrickletDustDetector#set_dust_density_callback_threshold

keeps being reached.

The default value is 100.



133
134
135
# File 'lib/tinkerforge/bricklet_dust_detector.rb', line 133

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

#set_dust_density_callback_period(period) ⇒ Object

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

CALLBACK_DUST_DENSITY is only triggered if the dust density has changed since the last triggering.

The default value is 0.



91
92
93
# File 'lib/tinkerforge/bricklet_dust_detector.rb', line 91

def set_dust_density_callback_period(period)
  send_request(FUNCTION_SET_DUST_DENSITY_CALLBACK_PERIOD, [period], 'L', 0, '')
end

#set_dust_density_callback_threshold(option, min, max) ⇒ Object

Sets the thresholds for the CALLBACK_DUST_DENSITY_REACHED callback.

The following options are possible:

"Option", "Description"

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

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



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

def set_dust_density_callback_threshold(option, min, max)
  send_request(FUNCTION_SET_DUST_DENSITY_CALLBACK_THRESHOLD, [option, min, max], 'k S S', 0, '')
end

#set_moving_average(average) ⇒ Object

Sets the length of a ‘moving averaging <en.wikipedia.org/wiki/Moving_average>`__ for the dust_density.

Setting the length to 0 will turn the averaging completely off. With less averaging, there is more noise on the data.

The range for the averaging is 0-100.

The default value is 100.



151
152
153
# File 'lib/tinkerforge/bricklet_dust_detector.rb', line 151

def set_moving_average(average)
  send_request(FUNCTION_SET_MOVING_AVERAGE, [average], 'C', 0, '')
end