tinkerforge 2.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. data/lib/tinkerforge.rb +5 -0
  2. data/lib/tinkerforge/brick_dc.rb +359 -0
  3. data/lib/tinkerforge/brick_imu.rb +512 -0
  4. data/lib/tinkerforge/brick_master.rb +1120 -0
  5. data/lib/tinkerforge/brick_servo.rb +475 -0
  6. data/lib/tinkerforge/brick_stepper.rb +556 -0
  7. data/lib/tinkerforge/bricklet_ambient_light.rb +246 -0
  8. data/lib/tinkerforge/bricklet_analog_in.rb +273 -0
  9. data/lib/tinkerforge/bricklet_analog_out.rb +90 -0
  10. data/lib/tinkerforge/bricklet_barometer.rb +313 -0
  11. data/lib/tinkerforge/bricklet_current12.rb +274 -0
  12. data/lib/tinkerforge/bricklet_current25.rb +274 -0
  13. data/lib/tinkerforge/bricklet_distance_ir.rb +274 -0
  14. data/lib/tinkerforge/bricklet_dual_relay.rb +127 -0
  15. data/lib/tinkerforge/bricklet_gps.rb +301 -0
  16. data/lib/tinkerforge/bricklet_humidity.rb +245 -0
  17. data/lib/tinkerforge/bricklet_industrial_digital_in_4.rb +165 -0
  18. data/lib/tinkerforge/bricklet_industrial_digital_out_4.rb +177 -0
  19. data/lib/tinkerforge/bricklet_industrial_quad_relay.rb +177 -0
  20. data/lib/tinkerforge/bricklet_io16.rb +237 -0
  21. data/lib/tinkerforge/bricklet_io4.rb +236 -0
  22. data/lib/tinkerforge/bricklet_joystick.rb +274 -0
  23. data/lib/tinkerforge/bricklet_lcd_16x2.rb +175 -0
  24. data/lib/tinkerforge/bricklet_lcd_20x4.rb +231 -0
  25. data/lib/tinkerforge/bricklet_linear_poti.rb +241 -0
  26. data/lib/tinkerforge/bricklet_piezo_buzzer.rb +84 -0
  27. data/lib/tinkerforge/bricklet_ptc.rb +277 -0
  28. data/lib/tinkerforge/bricklet_rotary_poti.rb +241 -0
  29. data/lib/tinkerforge/bricklet_temperature.rb +188 -0
  30. data/lib/tinkerforge/bricklet_temperature_ir.rb +275 -0
  31. data/lib/tinkerforge/bricklet_voltage.rb +241 -0
  32. data/lib/tinkerforge/bricklet_voltage_current.rb +386 -0
  33. data/lib/tinkerforge/ip_connection.rb +1027 -0
  34. data/lib/tinkerforge/version.rb +4 -0
  35. metadata +98 -0
@@ -0,0 +1,246 @@
1
+ # -*- ruby encoding: utf-8 -*-
2
+ #############################################################
3
+ # This file was automatically generated on 2013-05-16. #
4
+ # #
5
+ # Bindings Version 2.0.7 #
6
+ # #
7
+ # If you have a bugfix for this file and want to commit it, #
8
+ # please fix the bug in the generator. You can find a link #
9
+ # to the generator git on tinkerforge.com #
10
+ #############################################################
11
+
12
+ module Tinkerforge
13
+ # Device for sensing Ambient Light
14
+ class BrickletAmbientLight < Device
15
+ DEVICE_IDENTIFIER = 21 # :nodoc:
16
+
17
+ # This callback is triggered periodically with the period that is set by
18
+ # BrickletAmbientLight#set_illuminance_callback_period. The parameter is the illuminance of the
19
+ # ambient light sensor.
20
+ #
21
+ # CALLBACK_ILLUMINANCE is only triggered if the illuminance has changed since the
22
+ # last triggering.
23
+ CALLBACK_ILLUMINANCE = 13
24
+
25
+ # This callback is triggered periodically with the period that is set by
26
+ # BrickletAmbientLight#set_analog_value_callback_period. The parameter is the analog value of the
27
+ # ambient light sensor.
28
+ #
29
+ # CALLBACK_ANALOG_VALUE is only triggered if the analog value has changed since the
30
+ # last triggering.
31
+ CALLBACK_ANALOG_VALUE = 14
32
+
33
+ # This callback is triggered when the threshold as set by
34
+ # BrickletAmbientLight#set_illuminance_callback_threshold is reached.
35
+ # The parameter is the illuminance of the ambient light sensor.
36
+ #
37
+ # If the threshold keeps being reached, the callback is triggered periodically
38
+ # with the period as set by BrickletAmbientLight#set_debounce_period.
39
+ CALLBACK_ILLUMINANCE_REACHED = 15
40
+
41
+ # This callback is triggered when the threshold as set by
42
+ # BrickletAmbientLight#set_analog_value_callback_threshold is reached.
43
+ # The parameter is the analog value of the ambient light sensor.
44
+ #
45
+ # If the threshold keeps being reached, the callback is triggered periodically
46
+ # with the period as set by BrickletAmbientLight#set_debounce_period.
47
+ CALLBACK_ANALOG_VALUE_REACHED = 16
48
+
49
+ FUNCTION_GET_ILLUMINANCE = 1 # :nodoc:
50
+ FUNCTION_GET_ANALOG_VALUE = 2 # :nodoc:
51
+ FUNCTION_SET_ILLUMINANCE_CALLBACK_PERIOD = 3 # :nodoc:
52
+ FUNCTION_GET_ILLUMINANCE_CALLBACK_PERIOD = 4 # :nodoc:
53
+ FUNCTION_SET_ANALOG_VALUE_CALLBACK_PERIOD = 5 # :nodoc:
54
+ FUNCTION_GET_ANALOG_VALUE_CALLBACK_PERIOD = 6 # :nodoc:
55
+ FUNCTION_SET_ILLUMINANCE_CALLBACK_THRESHOLD = 7 # :nodoc:
56
+ FUNCTION_GET_ILLUMINANCE_CALLBACK_THRESHOLD = 8 # :nodoc:
57
+ FUNCTION_SET_ANALOG_VALUE_CALLBACK_THRESHOLD = 9 # :nodoc:
58
+ FUNCTION_GET_ANALOG_VALUE_CALLBACK_THRESHOLD = 10 # :nodoc:
59
+ FUNCTION_SET_DEBOUNCE_PERIOD = 11 # :nodoc:
60
+ FUNCTION_GET_DEBOUNCE_PERIOD = 12 # :nodoc:
61
+ FUNCTION_GET_IDENTITY = 255 # :nodoc:
62
+
63
+ THRESHOLD_OPTION_OFF = 'x' # :nodoc:
64
+ THRESHOLD_OPTION_OUTSIDE = 'o' # :nodoc:
65
+ THRESHOLD_OPTION_INSIDE = 'i' # :nodoc:
66
+ THRESHOLD_OPTION_SMALLER = '<' # :nodoc:
67
+ THRESHOLD_OPTION_GREATER = '>' # :nodoc:
68
+
69
+ # Creates an object with the unique device ID <tt>uid</tt> and adds it to
70
+ # the IP Connection <tt>ipcon</tt>.
71
+ def initialize(uid, ipcon)
72
+ super uid, ipcon
73
+
74
+ @api_version = [2, 0, 0]
75
+
76
+ @response_expected[FUNCTION_GET_ILLUMINANCE] = RESPONSE_EXPECTED_ALWAYS_TRUE
77
+ @response_expected[FUNCTION_GET_ANALOG_VALUE] = RESPONSE_EXPECTED_ALWAYS_TRUE
78
+ @response_expected[FUNCTION_SET_ILLUMINANCE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
79
+ @response_expected[FUNCTION_GET_ILLUMINANCE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
80
+ @response_expected[FUNCTION_SET_ANALOG_VALUE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
81
+ @response_expected[FUNCTION_GET_ANALOG_VALUE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
82
+ @response_expected[FUNCTION_SET_ILLUMINANCE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE
83
+ @response_expected[FUNCTION_GET_ILLUMINANCE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_ALWAYS_TRUE
84
+ @response_expected[FUNCTION_SET_ANALOG_VALUE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE
85
+ @response_expected[FUNCTION_GET_ANALOG_VALUE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_ALWAYS_TRUE
86
+ @response_expected[FUNCTION_SET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_TRUE
87
+ @response_expected[FUNCTION_GET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
88
+ @response_expected[CALLBACK_ILLUMINANCE] = RESPONSE_EXPECTED_ALWAYS_FALSE
89
+ @response_expected[CALLBACK_ANALOG_VALUE] = RESPONSE_EXPECTED_ALWAYS_FALSE
90
+ @response_expected[CALLBACK_ILLUMINANCE_REACHED] = RESPONSE_EXPECTED_ALWAYS_FALSE
91
+ @response_expected[CALLBACK_ANALOG_VALUE_REACHED] = RESPONSE_EXPECTED_ALWAYS_FALSE
92
+ @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
93
+
94
+ @callback_formats[CALLBACK_ILLUMINANCE] = 'S'
95
+ @callback_formats[CALLBACK_ANALOG_VALUE] = 'S'
96
+ @callback_formats[CALLBACK_ILLUMINANCE_REACHED] = 'S'
97
+ @callback_formats[CALLBACK_ANALOG_VALUE_REACHED] = 'S'
98
+ end
99
+
100
+ # Returns the illuminance of the ambient light sensor. The value
101
+ # has a range of 0 to 9000 and is given in Lux/10, i.e. a value
102
+ # of 4500 means that an illuminance of 450 Lux is measured.
103
+ #
104
+ # If you want to get the illuminance periodically, it is recommended to use the
105
+ # callback CALLBACK_ILLUMINANCE and set the period with
106
+ # BrickletAmbientLight#set_illuminance_callback_period.
107
+ def get_illuminance
108
+ send_request(FUNCTION_GET_ILLUMINANCE, [], '', 2, 'S')
109
+ end
110
+
111
+ # Returns the value as read by a 12-bit analog-to-digital converter.
112
+ # The value is between 0 and 4095.
113
+ #
114
+ # .. note::
115
+ # The value returned by BrickletAmbientLight#get_illuminance is averaged over several samples
116
+ # to yield less noise, while BrickletAmbientLight#get_analog_value gives back raw
117
+ # unfiltered analog values. The only reason to use BrickletAmbientLight#get_analog_value is,
118
+ # if you need the full resolution of the analog-to-digital converter.
119
+ #
120
+ # Also, the analog-to-digital converter covers three different ranges that are
121
+ # set dynamically depending on the light intensity. It is impossible to
122
+ # distinguish between these ranges with the analog value.
123
+ #
124
+ # If you want the analog value periodically, it is recommended to use the
125
+ # callback CALLBACK_ANALOG_VALUE and set the period with
126
+ # BrickletAmbientLight#set_analog_value_callback_period.
127
+ def get_analog_value
128
+ send_request(FUNCTION_GET_ANALOG_VALUE, [], '', 2, 'S')
129
+ end
130
+
131
+ # Sets the period in ms with which the CALLBACK_ILLUMINANCE callback is triggered
132
+ # periodically. A value of 0 turns the callback off.
133
+ #
134
+ # CALLBACK_ILLUMINANCE is only triggered if the illuminance has changed since the
135
+ # last triggering.
136
+ #
137
+ # The default value is 0.
138
+ def set_illuminance_callback_period(period)
139
+ send_request(FUNCTION_SET_ILLUMINANCE_CALLBACK_PERIOD, [period], 'L', 0, '')
140
+ end
141
+
142
+ # Returns the period as set by BrickletAmbientLight#set_illuminance_callback_period.
143
+ def get_illuminance_callback_period
144
+ send_request(FUNCTION_GET_ILLUMINANCE_CALLBACK_PERIOD, [], '', 4, 'L')
145
+ end
146
+
147
+ # Sets the period in ms with which the CALLBACK_ANALOG_VALUE callback is triggered
148
+ # periodically. A value of 0 turns the callback off.
149
+ #
150
+ # CALLBACK_ANALOG_VALUE is only triggered if the analog value has changed since the
151
+ # last triggering.
152
+ #
153
+ # The default value is 0.
154
+ def set_analog_value_callback_period(period)
155
+ send_request(FUNCTION_SET_ANALOG_VALUE_CALLBACK_PERIOD, [period], 'L', 0, '')
156
+ end
157
+
158
+ # Returns the period as set by BrickletAmbientLight#set_analog_value_callback_period.
159
+ def get_analog_value_callback_period
160
+ send_request(FUNCTION_GET_ANALOG_VALUE_CALLBACK_PERIOD, [], '', 4, 'L')
161
+ end
162
+
163
+ # Sets the thresholds for the CALLBACK_ILLUMINANCE_REACHED callback.
164
+ #
165
+ # The following options are possible:
166
+ #
167
+ # "Option", "Description"
168
+ #
169
+ # "'x'", "Callback is turned off"
170
+ # "'o'", "Callback is triggered when the illuminance is *outside* the min and max values"
171
+ # "'i'", "Callback is triggered when the illuminance is *inside* the min and max values"
172
+ # "'<'", "Callback is triggered when the illuminance is smaller than the min value (max is ignored)"
173
+ # "'>'", "Callback is triggered when the illuminance is greater than the min value (max is ignored)"
174
+ #
175
+ # The default value is ('x', 0, 0).
176
+ def set_illuminance_callback_threshold(option, min, max)
177
+ send_request(FUNCTION_SET_ILLUMINANCE_CALLBACK_THRESHOLD, [option, min, max], 'k s s', 0, '')
178
+ end
179
+
180
+ # Returns the threshold as set by BrickletAmbientLight#set_illuminance_callback_threshold.
181
+ def get_illuminance_callback_threshold
182
+ send_request(FUNCTION_GET_ILLUMINANCE_CALLBACK_THRESHOLD, [], '', 5, 'k s s')
183
+ end
184
+
185
+ # Sets the thresholds for the CALLBACK_ANALOG_VALUE_REACHED callback.
186
+ #
187
+ # The following options are possible:
188
+ #
189
+ # "Option", "Description"
190
+ #
191
+ # "'x'", "Callback is turned off"
192
+ # "'o'", "Callback is triggered when the analog value is *outside* the min and max values"
193
+ # "'i'", "Callback is triggered when the analog value is *inside* the min and max values"
194
+ # "'<'", "Callback is triggered when the analog value is smaller than the min value (max is ignored)"
195
+ # "'>'", "Callback is triggered when the analog value is greater than the min value (max is ignored)"
196
+ #
197
+ # The default value is ('x', 0, 0).
198
+ def set_analog_value_callback_threshold(option, min, max)
199
+ send_request(FUNCTION_SET_ANALOG_VALUE_CALLBACK_THRESHOLD, [option, min, max], 'k S S', 0, '')
200
+ end
201
+
202
+ # Returns the threshold as set by BrickletAmbientLight#set_analog_value_callback_threshold.
203
+ def get_analog_value_callback_threshold
204
+ send_request(FUNCTION_GET_ANALOG_VALUE_CALLBACK_THRESHOLD, [], '', 5, 'k S S')
205
+ end
206
+
207
+ # Sets the period in ms with which the threshold callbacks
208
+ #
209
+ # CALLBACK_ILLUMINANCE_REACHED, CALLBACK_ANALOG_VALUE_REACHED
210
+ #
211
+ # are triggered, if the thresholds
212
+ #
213
+ # BrickletAmbientLight#set_illuminance_callback_threshold, BrickletAmbientLight#set_analog_value_callback_threshold
214
+ #
215
+ # keep being reached.
216
+ #
217
+ # The default value is 100.
218
+ def set_debounce_period(debounce)
219
+ send_request(FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 0, '')
220
+ end
221
+
222
+ # Returns the debounce period as set by BrickletAmbientLight#set_debounce_period.
223
+ def get_debounce_period
224
+ send_request(FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 4, 'L')
225
+ end
226
+
227
+ # Returns the UID, the UID where the Bricklet is connected to,
228
+ # the position, the hardware and firmware version as well as the
229
+ # device identifier.
230
+ #
231
+ # The position can be 'a', 'b', 'c' or 'd'.
232
+ #
233
+ # The device identifiers can be found :ref:`here <device_identifier>`.
234
+ #
235
+ # .. versionadded:: 2.0.0~(Plugin)
236
+ def get_identity
237
+ send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S')
238
+ end
239
+
240
+ # Registers a callback with ID <tt>id</tt> to the block <tt>block</tt>.
241
+ def register_callback(id, &block)
242
+ callback = block
243
+ @registered_callbacks[id] = callback
244
+ end
245
+ end
246
+ end
@@ -0,0 +1,273 @@
1
+ # -*- ruby encoding: utf-8 -*-
2
+ #############################################################
3
+ # This file was automatically generated on 2013-05-16. #
4
+ # #
5
+ # Bindings Version 2.0.7 #
6
+ # #
7
+ # If you have a bugfix for this file and want to commit it, #
8
+ # please fix the bug in the generator. You can find a link #
9
+ # to the generator git on tinkerforge.com #
10
+ #############################################################
11
+
12
+ module Tinkerforge
13
+ # Device for sensing Voltages between 0 and 45V
14
+ class BrickletAnalogIn < Device
15
+ DEVICE_IDENTIFIER = 219 # :nodoc:
16
+
17
+ # This callback is triggered periodically with the period that is set by
18
+ # BrickletAnalogIn#set_voltage_callback_period. The parameter is the voltage of the
19
+ # sensor.
20
+ #
21
+ # CALLBACK_VOLTAGE is only triggered if the voltage has changed since the
22
+ # last triggering.
23
+ CALLBACK_VOLTAGE = 13
24
+
25
+ # This callback is triggered periodically with the period that is set by
26
+ # BrickletAnalogIn#set_analog_value_callback_period. The parameter is the analog value of the
27
+ # sensor.
28
+ #
29
+ # CALLBACK_ANALOG_VALUE is only triggered if the voltage has changed since the
30
+ # last triggering.
31
+ CALLBACK_ANALOG_VALUE = 14
32
+
33
+ # This callback is triggered when the threshold as set by
34
+ # BrickletAnalogIn#set_voltage_callback_threshold is reached.
35
+ # The parameter is the voltage of the sensor.
36
+ #
37
+ # If the threshold keeps being reached, the callback is triggered periodically
38
+ # with the period as set by BrickletAnalogIn#set_debounce_period.
39
+ CALLBACK_VOLTAGE_REACHED = 15
40
+
41
+ # This callback is triggered when the threshold as set by
42
+ # BrickletAnalogIn#set_analog_value_callback_threshold is reached.
43
+ # The parameter is the analog value of the sensor.
44
+ #
45
+ # If the threshold keeps being reached, the callback is triggered periodically
46
+ # with the period as set by BrickletAnalogIn#set_debounce_period.
47
+ CALLBACK_ANALOG_VALUE_REACHED = 16
48
+
49
+ FUNCTION_GET_VOLTAGE = 1 # :nodoc:
50
+ FUNCTION_GET_ANALOG_VALUE = 2 # :nodoc:
51
+ FUNCTION_SET_VOLTAGE_CALLBACK_PERIOD = 3 # :nodoc:
52
+ FUNCTION_GET_VOLTAGE_CALLBACK_PERIOD = 4 # :nodoc:
53
+ FUNCTION_SET_ANALOG_VALUE_CALLBACK_PERIOD = 5 # :nodoc:
54
+ FUNCTION_GET_ANALOG_VALUE_CALLBACK_PERIOD = 6 # :nodoc:
55
+ FUNCTION_SET_VOLTAGE_CALLBACK_THRESHOLD = 7 # :nodoc:
56
+ FUNCTION_GET_VOLTAGE_CALLBACK_THRESHOLD = 8 # :nodoc:
57
+ FUNCTION_SET_ANALOG_VALUE_CALLBACK_THRESHOLD = 9 # :nodoc:
58
+ FUNCTION_GET_ANALOG_VALUE_CALLBACK_THRESHOLD = 10 # :nodoc:
59
+ FUNCTION_SET_DEBOUNCE_PERIOD = 11 # :nodoc:
60
+ FUNCTION_GET_DEBOUNCE_PERIOD = 12 # :nodoc:
61
+ FUNCTION_SET_RANGE = 17 # :nodoc:
62
+ FUNCTION_GET_RANGE = 18 # :nodoc:
63
+ FUNCTION_GET_IDENTITY = 255 # :nodoc:
64
+
65
+ THRESHOLD_OPTION_OFF = 'x' # :nodoc:
66
+ THRESHOLD_OPTION_OUTSIDE = 'o' # :nodoc:
67
+ THRESHOLD_OPTION_INSIDE = 'i' # :nodoc:
68
+ THRESHOLD_OPTION_SMALLER = '<' # :nodoc:
69
+ THRESHOLD_OPTION_GREATER = '>' # :nodoc:
70
+ RANGE_AUTOMATIC = 0 # :nodoc:
71
+ RANGE_UP_TO_6V = 1 # :nodoc:
72
+ RANGE_UP_TO_10V = 2 # :nodoc:
73
+ RANGE_UP_TO_36V = 3 # :nodoc:
74
+ RANGE_UP_TO_45V = 3 # :nodoc:
75
+
76
+ # Creates an object with the unique device ID <tt>uid</tt> and adds it to
77
+ # the IP Connection <tt>ipcon</tt>.
78
+ def initialize(uid, ipcon)
79
+ super uid, ipcon
80
+
81
+ @api_version = [2, 0, 1]
82
+
83
+ @response_expected[FUNCTION_GET_VOLTAGE] = RESPONSE_EXPECTED_ALWAYS_TRUE
84
+ @response_expected[FUNCTION_GET_ANALOG_VALUE] = RESPONSE_EXPECTED_ALWAYS_TRUE
85
+ @response_expected[FUNCTION_SET_VOLTAGE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
86
+ @response_expected[FUNCTION_GET_VOLTAGE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
87
+ @response_expected[FUNCTION_SET_ANALOG_VALUE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
88
+ @response_expected[FUNCTION_GET_ANALOG_VALUE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
89
+ @response_expected[FUNCTION_SET_VOLTAGE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE
90
+ @response_expected[FUNCTION_GET_VOLTAGE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_ALWAYS_TRUE
91
+ @response_expected[FUNCTION_SET_ANALOG_VALUE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE
92
+ @response_expected[FUNCTION_GET_ANALOG_VALUE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_ALWAYS_TRUE
93
+ @response_expected[FUNCTION_SET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_TRUE
94
+ @response_expected[FUNCTION_GET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
95
+ @response_expected[CALLBACK_VOLTAGE] = RESPONSE_EXPECTED_ALWAYS_FALSE
96
+ @response_expected[CALLBACK_ANALOG_VALUE] = RESPONSE_EXPECTED_ALWAYS_FALSE
97
+ @response_expected[CALLBACK_VOLTAGE_REACHED] = RESPONSE_EXPECTED_ALWAYS_FALSE
98
+ @response_expected[CALLBACK_ANALOG_VALUE_REACHED] = RESPONSE_EXPECTED_ALWAYS_FALSE
99
+ @response_expected[FUNCTION_SET_RANGE] = RESPONSE_EXPECTED_FALSE
100
+ @response_expected[FUNCTION_GET_RANGE] = RESPONSE_EXPECTED_ALWAYS_TRUE
101
+ @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
102
+
103
+ @callback_formats[CALLBACK_VOLTAGE] = 'S'
104
+ @callback_formats[CALLBACK_ANALOG_VALUE] = 'S'
105
+ @callback_formats[CALLBACK_VOLTAGE_REACHED] = 'S'
106
+ @callback_formats[CALLBACK_ANALOG_VALUE_REACHED] = 'S'
107
+ end
108
+
109
+ # Returns the voltage of the sensor. The value is in mV and
110
+ # between 0V and 45V. The resolution between 0 and 6V is about 2mV.
111
+ # Between 6 and 45V the resolution is about 10mV.
112
+ #
113
+ # If you want to get the voltage periodically, it is recommended to use the
114
+ # callback CALLBACK_VOLTAGE and set the period with
115
+ # BrickletAnalogIn#set_voltage_callback_period.
116
+ def get_voltage
117
+ send_request(FUNCTION_GET_VOLTAGE, [], '', 2, 'S')
118
+ end
119
+
120
+ # Returns the value as read by a 12-bit analog-to-digital converter.
121
+ # The value is between 0 and 4095.
122
+ #
123
+ # .. note::
124
+ # The value returned by BrickletAnalogIn#get_voltage is averaged over several samples
125
+ # to yield less noise, while BrickletAnalogIn#get_analog_value gives back raw
126
+ # unfiltered analog values. The only reason to use BrickletAnalogIn#get_analog_value is,
127
+ # if you need the full resolution of the analog-to-digital converter.
128
+ #
129
+ # If you want the analog value periodically, it is recommended to use the
130
+ # callback CALLBACK_ANALOG_VALUE and set the period with
131
+ # BrickletAnalogIn#set_analog_value_callback_period.
132
+ def get_analog_value
133
+ send_request(FUNCTION_GET_ANALOG_VALUE, [], '', 2, 'S')
134
+ end
135
+
136
+ # Sets the period in ms with which the CALLBACK_VOLTAGE callback is triggered
137
+ # periodically. A value of 0 turns the callback off.
138
+ #
139
+ # CALLBACK_VOLTAGE is only triggered if the voltage has changed since the
140
+ # last triggering.
141
+ #
142
+ # The default value is 0.
143
+ def set_voltage_callback_period(period)
144
+ send_request(FUNCTION_SET_VOLTAGE_CALLBACK_PERIOD, [period], 'L', 0, '')
145
+ end
146
+
147
+ # Returns the period as set by BrickletAnalogIn#set_voltage_callback_period.
148
+ def get_voltage_callback_period
149
+ send_request(FUNCTION_GET_VOLTAGE_CALLBACK_PERIOD, [], '', 4, 'L')
150
+ end
151
+
152
+ # Sets the period in ms with which the CALLBACK_ANALOG_VALUE callback is triggered
153
+ # periodically. A value of 0 turns the callback off.
154
+ #
155
+ # CALLBACK_ANALOG_VALUE is only triggered if the analog value has changed since the
156
+ # last triggering.
157
+ #
158
+ # The default value is 0.
159
+ def set_analog_value_callback_period(period)
160
+ send_request(FUNCTION_SET_ANALOG_VALUE_CALLBACK_PERIOD, [period], 'L', 0, '')
161
+ end
162
+
163
+ # Returns the period as set by BrickletAnalogIn#set_analog_value_callback_period.
164
+ def get_analog_value_callback_period
165
+ send_request(FUNCTION_GET_ANALOG_VALUE_CALLBACK_PERIOD, [], '', 4, 'L')
166
+ end
167
+
168
+ # Sets the thresholds for the CALLBACK_VOLTAGE_REACHED callback.
169
+ #
170
+ # The following options are possible:
171
+ #
172
+ # "Option", "Description"
173
+ #
174
+ # "'x'", "Callback is turned off"
175
+ # "'o'", "Callback is triggered when the voltage is *outside* the min and max values"
176
+ # "'i'", "Callback is triggered when the voltage is *inside* the min and max values"
177
+ # "'<'", "Callback is triggered when the voltage is smaller than the min value (max is ignored)"
178
+ # "'>'", "Callback is triggered when the voltage is greater than the min value (max is ignored)"
179
+ #
180
+ # The default value is ('x', 0, 0).
181
+ def set_voltage_callback_threshold(option, min, max)
182
+ send_request(FUNCTION_SET_VOLTAGE_CALLBACK_THRESHOLD, [option, min, max], 'k s s', 0, '')
183
+ end
184
+
185
+ # Returns the threshold as set by BrickletAnalogIn#set_voltage_callback_threshold.
186
+ def get_voltage_callback_threshold
187
+ send_request(FUNCTION_GET_VOLTAGE_CALLBACK_THRESHOLD, [], '', 5, 'k s s')
188
+ end
189
+
190
+ # Sets the thresholds for the CALLBACK_ANALOG_VALUE_REACHED callback.
191
+ #
192
+ # The following options are possible:
193
+ #
194
+ # "Option", "Description"
195
+ #
196
+ # "'x'", "Callback is turned off"
197
+ # "'o'", "Callback is triggered when the analog value is *outside* the min and max values"
198
+ # "'i'", "Callback is triggered when the analog value is *inside* the min and max values"
199
+ # "'<'", "Callback is triggered when the analog value is smaller than the min value (max is ignored)"
200
+ # "'>'", "Callback is triggered when the analog value is greater than the min value (max is ignored)"
201
+ #
202
+ # The default value is ('x', 0, 0).
203
+ def set_analog_value_callback_threshold(option, min, max)
204
+ send_request(FUNCTION_SET_ANALOG_VALUE_CALLBACK_THRESHOLD, [option, min, max], 'k S S', 0, '')
205
+ end
206
+
207
+ # Returns the threshold as set by BrickletAnalogIn#set_analog_value_callback_threshold.
208
+ def get_analog_value_callback_threshold
209
+ send_request(FUNCTION_GET_ANALOG_VALUE_CALLBACK_THRESHOLD, [], '', 5, 'k S S')
210
+ end
211
+
212
+ # Sets the period in ms with which the threshold callbacks
213
+ #
214
+ # CALLBACK_VOLTAGE_REACHED, CALLBACK_ANALOG_VALUE_REACHED
215
+ #
216
+ # are triggered, if the thresholds
217
+ #
218
+ # BrickletAnalogIn#set_voltage_callback_threshold, BrickletAnalogIn#set_analog_value_callback_threshold
219
+ #
220
+ # keep being reached.
221
+ #
222
+ # The default value is 100.
223
+ def set_debounce_period(debounce)
224
+ send_request(FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 0, '')
225
+ end
226
+
227
+ # Returns the debounce period as set by BrickletAnalogIn#set_debounce_period.
228
+ def get_debounce_period
229
+ send_request(FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 4, 'L')
230
+ end
231
+
232
+ # Sets the measurement range. Possible ranges:
233
+ #
234
+ # * 0: Automatically switched
235
+ # * 1: 0V - 6.05V, ~1.48mV resolution
236
+ # * 2: 0V - 10.32V, ~2.52mV resolution
237
+ # * 3: 0V - 36.30V, ~8.86mV resolution
238
+ # * 3: 0V - 45.00V, ~11.25mV resolution
239
+ #
240
+ # The default measurement range is 0.
241
+ #
242
+ # .. versionadded:: 2.0.1~(Plugin)
243
+ def set_range(range)
244
+ send_request(FUNCTION_SET_RANGE, [range], 'C', 0, '')
245
+ end
246
+
247
+ # Returns the measurement range as set by BrickletAnalogIn#set_range.
248
+ #
249
+ # .. versionadded:: 2.0.1~(Plugin)
250
+ def get_range
251
+ send_request(FUNCTION_GET_RANGE, [], '', 1, 'C')
252
+ end
253
+
254
+ # Returns the UID, the UID where the Bricklet is connected to,
255
+ # the position, the hardware and firmware version as well as the
256
+ # device identifier.
257
+ #
258
+ # The position can be 'a', 'b', 'c' or 'd'.
259
+ #
260
+ # The device identifiers can be found :ref:`here <device_identifier>`.
261
+ #
262
+ # .. versionadded:: 2.0.0~(Plugin)
263
+ def get_identity
264
+ send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S')
265
+ end
266
+
267
+ # Registers a callback with ID <tt>id</tt> to the block <tt>block</tt>.
268
+ def register_callback(id, &block)
269
+ callback = block
270
+ @registered_callbacks[id] = callback
271
+ end
272
+ end
273
+ end