tinkerforge 2.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,241 @@
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 Linear Potentiometer input
14
+ class BrickletLinearPoti < Device
15
+ DEVICE_IDENTIFIER = 213 # :nodoc:
16
+
17
+ # This callback is triggered periodically with the period that is set by
18
+ # BrickletLinearPoti#set_position_callback_period. The parameter is the position of the
19
+ # Linear Potentiometer.
20
+ #
21
+ # CALLBACK_POSITION is only triggered if the position has changed since the
22
+ # last triggering.
23
+ CALLBACK_POSITION = 13
24
+
25
+ # This callback is triggered periodically with the period that is set by
26
+ # BrickletLinearPoti#set_analog_value_callback_period. The parameter is the analog value of the
27
+ # Linear Potentiometer.
28
+ #
29
+ # CALLBACK_ANALOG_VALUE is only triggered if the position 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
+ # BrickletLinearPoti#set_position_callback_threshold is reached.
35
+ # The parameter is the position of the Linear Potentiometer.
36
+ #
37
+ # If the threshold keeps being reached, the callback is triggered periodically
38
+ # with the period as set by BrickletLinearPoti#set_debounce_period.
39
+ CALLBACK_POSITION_REACHED = 15
40
+
41
+ # This callback is triggered when the threshold as set by
42
+ # BrickletLinearPoti#set_analog_value_callback_threshold is reached.
43
+ # The parameter is the analog value of the Linear Potentiometer.
44
+ #
45
+ # If the threshold keeps being reached, the callback is triggered periodically
46
+ # with the period as set by BrickletLinearPoti#set_debounce_period.
47
+ CALLBACK_ANALOG_VALUE_REACHED = 16
48
+
49
+ FUNCTION_GET_POSITION = 1 # :nodoc:
50
+ FUNCTION_GET_ANALOG_VALUE = 2 # :nodoc:
51
+ FUNCTION_SET_POSITION_CALLBACK_PERIOD = 3 # :nodoc:
52
+ FUNCTION_GET_POSITION_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_POSITION_CALLBACK_THRESHOLD = 7 # :nodoc:
56
+ FUNCTION_GET_POSITION_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_POSITION] = RESPONSE_EXPECTED_ALWAYS_TRUE
77
+ @response_expected[FUNCTION_GET_ANALOG_VALUE] = RESPONSE_EXPECTED_ALWAYS_TRUE
78
+ @response_expected[FUNCTION_SET_POSITION_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
79
+ @response_expected[FUNCTION_GET_POSITION_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_POSITION_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE
83
+ @response_expected[FUNCTION_GET_POSITION_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_POSITION] = RESPONSE_EXPECTED_ALWAYS_FALSE
89
+ @response_expected[CALLBACK_ANALOG_VALUE] = RESPONSE_EXPECTED_ALWAYS_FALSE
90
+ @response_expected[CALLBACK_POSITION_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_POSITION] = 'S'
95
+ @callback_formats[CALLBACK_ANALOG_VALUE] = 'S'
96
+ @callback_formats[CALLBACK_POSITION_REACHED] = 'S'
97
+ @callback_formats[CALLBACK_ANALOG_VALUE_REACHED] = 'S'
98
+ end
99
+
100
+ # Returns the position of the Linear Potentiometer. The value is
101
+ # between 0 (slider down) and 100 (slider up).
102
+ #
103
+ # If you want to get the position periodically, it is recommended to use the
104
+ # callback CALLBACK_POSITION and set the period with
105
+ # BrickletLinearPoti#set_position_callback_period.
106
+ def get_position
107
+ send_request(FUNCTION_GET_POSITION, [], '', 2, 'S')
108
+ end
109
+
110
+ # Returns the value as read by a 12-bit analog-to-digital converter.
111
+ # The value is between 0 and 4095.
112
+ #
113
+ # .. note::
114
+ # The value returned by BrickletLinearPoti#get_position is averaged over several samples
115
+ # to yield less noise, while BrickletLinearPoti#get_analog_value gives back raw
116
+ # unfiltered analog values. The only reason to use BrickletLinearPoti#get_analog_value is,
117
+ # if you need the full resolution of the analog-to-digital converter.
118
+ #
119
+ # If you want the analog value periodically, it is recommended to use the
120
+ # callback CALLBACK_ANALOG_VALUE and set the period with
121
+ # BrickletLinearPoti#set_analog_value_callback_period.
122
+ def get_analog_value
123
+ send_request(FUNCTION_GET_ANALOG_VALUE, [], '', 2, 'S')
124
+ end
125
+
126
+ # Sets the period in ms with which the CALLBACK_POSITION callback is triggered
127
+ # periodically. A value of 0 turns the callback off.
128
+ #
129
+ # CALLBACK_POSITION is only triggered if the position has changed since the
130
+ # last triggering.
131
+ #
132
+ # The default value is 0.
133
+ def set_position_callback_period(period)
134
+ send_request(FUNCTION_SET_POSITION_CALLBACK_PERIOD, [period], 'L', 0, '')
135
+ end
136
+
137
+ # Returns the period as set by BrickletLinearPoti#set_position_callback_period.
138
+ def get_position_callback_period
139
+ send_request(FUNCTION_GET_POSITION_CALLBACK_PERIOD, [], '', 4, 'L')
140
+ end
141
+
142
+ # Sets the period in ms with which the CALLBACK_ANALOG_VALUE callback is triggered
143
+ # periodically. A value of 0 turns the callback off.
144
+ #
145
+ # CALLBACK_ANALOG_VALUE is only triggered if the analog value has changed since the
146
+ # last triggering.
147
+ #
148
+ # The default value is 0.
149
+ def set_analog_value_callback_period(period)
150
+ send_request(FUNCTION_SET_ANALOG_VALUE_CALLBACK_PERIOD, [period], 'L', 0, '')
151
+ end
152
+
153
+ # Returns the period as set by BrickletLinearPoti#set_analog_value_callback_period.
154
+ def get_analog_value_callback_period
155
+ send_request(FUNCTION_GET_ANALOG_VALUE_CALLBACK_PERIOD, [], '', 4, 'L')
156
+ end
157
+
158
+ # Sets the thresholds for the CALLBACK_POSITION_REACHED callback.
159
+ #
160
+ # The following options are possible:
161
+ #
162
+ # "Option", "Description"
163
+ #
164
+ # "'x'", "Callback is turned off"
165
+ # "'o'", "Callback is triggered when the position is *outside* the min and max values"
166
+ # "'i'", "Callback is triggered when the position is *inside* the min and max values"
167
+ # "'<'", "Callback is triggered when the position is smaller than the min value (max is ignored)"
168
+ # "'>'", "Callback is triggered when the position is greater than the min value (max is ignored)"
169
+ #
170
+ # The default value is ('x', 0, 0).
171
+ def set_position_callback_threshold(option, min, max)
172
+ send_request(FUNCTION_SET_POSITION_CALLBACK_THRESHOLD, [option, min, max], 'k s s', 0, '')
173
+ end
174
+
175
+ # Returns the threshold as set by BrickletLinearPoti#set_position_callback_threshold.
176
+ def get_position_callback_threshold
177
+ send_request(FUNCTION_GET_POSITION_CALLBACK_THRESHOLD, [], '', 5, 'k s s')
178
+ end
179
+
180
+ # Sets the thresholds for the CALLBACK_ANALOG_VALUE_REACHED callback.
181
+ #
182
+ # The following options are possible:
183
+ #
184
+ # "Option", "Description"
185
+ #
186
+ # "'x'", "Callback is turned off"
187
+ # "'o'", "Callback is triggered when the analog value is *outside* the min and max values"
188
+ # "'i'", "Callback is triggered when the analog value is *inside* the min and max values"
189
+ # "'<'", "Callback is triggered when the analog value is smaller than the min value (max is ignored)"
190
+ # "'>'", "Callback is triggered when the analog value is greater than the min value (max is ignored)"
191
+ #
192
+ # The default value is ('x', 0, 0).
193
+ def set_analog_value_callback_threshold(option, min, max)
194
+ send_request(FUNCTION_SET_ANALOG_VALUE_CALLBACK_THRESHOLD, [option, min, max], 'k S S', 0, '')
195
+ end
196
+
197
+ # Returns the threshold as set by BrickletLinearPoti#set_analog_value_callback_threshold.
198
+ def get_analog_value_callback_threshold
199
+ send_request(FUNCTION_GET_ANALOG_VALUE_CALLBACK_THRESHOLD, [], '', 5, 'k S S')
200
+ end
201
+
202
+ # Sets the period in ms with which the threshold callbacks
203
+ #
204
+ # CALLBACK_POSITION_REACHED, CALLBACK_ANALOG_VALUE_REACHED
205
+ #
206
+ # are triggered, if the thresholds
207
+ #
208
+ # BrickletLinearPoti#set_position_callback_threshold, BrickletLinearPoti#set_analog_value_callback_threshold
209
+ #
210
+ # keep being reached.
211
+ #
212
+ # The default value is 100.
213
+ def set_debounce_period(debounce)
214
+ send_request(FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 0, '')
215
+ end
216
+
217
+ # Returns the debounce period as set by BrickletLinearPoti#set_debounce_period.
218
+ def get_debounce_period
219
+ send_request(FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 4, 'L')
220
+ end
221
+
222
+ # Returns the UID, the UID where the Bricklet is connected to,
223
+ # the position, the hardware and firmware version as well as the
224
+ # device identifier.
225
+ #
226
+ # The position can be 'a', 'b', 'c' or 'd'.
227
+ #
228
+ # The device identifiers can be found :ref:`here <device_identifier>`.
229
+ #
230
+ # .. versionadded:: 2.0.0~(Plugin)
231
+ def get_identity
232
+ send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S')
233
+ end
234
+
235
+ # Registers a callback with ID <tt>id</tt> to the block <tt>block</tt>.
236
+ def register_callback(id, &block)
237
+ callback = block
238
+ @registered_callbacks[id] = callback
239
+ end
240
+ end
241
+ end
@@ -0,0 +1,84 @@
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 controlling a piezo buzzer
14
+ class BrickletPiezoBuzzer < Device
15
+ DEVICE_IDENTIFIER = 214 # :nodoc:
16
+
17
+ # This callback is triggered if a beep set by BrickletPiezoBuzzer#beep is finished
18
+ CALLBACK_BEEP_FINISHED = 3
19
+
20
+ # This callback is triggered if the playback of the morse code set by
21
+ # BrickletPiezoBuzzer#morse_code is finished.
22
+ CALLBACK_MORSE_CODE_FINISHED = 4
23
+
24
+ FUNCTION_BEEP = 1 # :nodoc:
25
+ FUNCTION_MORSE_CODE = 2 # :nodoc:
26
+ FUNCTION_GET_IDENTITY = 255 # :nodoc:
27
+
28
+
29
+ # Creates an object with the unique device ID <tt>uid</tt> and adds it to
30
+ # the IP Connection <tt>ipcon</tt>.
31
+ def initialize(uid, ipcon)
32
+ super uid, ipcon
33
+
34
+ @api_version = [2, 0, 0]
35
+
36
+ @response_expected[FUNCTION_BEEP] = RESPONSE_EXPECTED_FALSE
37
+ @response_expected[FUNCTION_MORSE_CODE] = RESPONSE_EXPECTED_FALSE
38
+ @response_expected[CALLBACK_BEEP_FINISHED] = RESPONSE_EXPECTED_ALWAYS_FALSE
39
+ @response_expected[CALLBACK_MORSE_CODE_FINISHED] = RESPONSE_EXPECTED_ALWAYS_FALSE
40
+ @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
41
+
42
+ @callback_formats[CALLBACK_BEEP_FINISHED] = ''
43
+ @callback_formats[CALLBACK_MORSE_CODE_FINISHED] = ''
44
+ end
45
+
46
+ # Beeps with the duration in ms. For example: If you set a value of 1000,
47
+ # the piezo buzzer will beep for one second.
48
+ def beep(duration)
49
+ send_request(FUNCTION_BEEP, [duration], 'L', 0, '')
50
+ end
51
+
52
+ # Sets morse code that will be played by the piezo buzzer. The morse code
53
+ # is given as a string consisting of "." (dot), "-" (minus) and " " (space)
54
+ # for *dits*, *dahs* and *pauses*. Every other character is ignored.
55
+ #
56
+ # For example: If you set the string "...---...", the piezo buzzer will beep
57
+ # nine times with the durations "short short short long long long short
58
+ # short short".
59
+ #
60
+ # The maximum string size is 60.
61
+ def morse_code(morse)
62
+ send_request(FUNCTION_MORSE_CODE, [morse], 'Z60', 0, '')
63
+ end
64
+
65
+ # Returns the UID, the UID where the Bricklet is connected to,
66
+ # the position, the hardware and firmware version as well as the
67
+ # device identifier.
68
+ #
69
+ # The position can be 'a', 'b', 'c' or 'd'.
70
+ #
71
+ # The device identifiers can be found :ref:`here <device_identifier>`.
72
+ #
73
+ # .. versionadded:: 2.0.0~(Plugin)
74
+ def get_identity
75
+ send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S')
76
+ end
77
+
78
+ # Registers a callback with ID <tt>id</tt> to the block <tt>block</tt>.
79
+ def register_callback(id, &block)
80
+ callback = block
81
+ @registered_callbacks[id] = callback
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,277 @@
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 reading temperatures from Pt100 or Pt1000 sensors
14
+ class BrickletPTC < Device
15
+ DEVICE_IDENTIFIER = 226 # :nodoc:
16
+
17
+ # This callback is triggered periodically with the period that is set by
18
+ # BrickletPTC#set_temperature_callback_period. The parameter is the temperature
19
+ # of the sensor.
20
+ #
21
+ # CALLBACK_TEMPERATURE is only triggered if the temperature has changed since the
22
+ # last triggering.
23
+ CALLBACK_TEMPERATURE = 13
24
+
25
+ # This callback is triggered when the threshold as set by
26
+ # BrickletPTC#set_temperature_callback_threshold is reached.
27
+ # The parameter is the temperature of the sensor.
28
+ #
29
+ # If the threshold keeps being reached, the callback is triggered periodically
30
+ # with the period as set by BrickletPTC#set_debounce_period.
31
+ CALLBACK_TEMPERATURE_REACHED = 14
32
+
33
+ # This callback is triggered periodically with the period that is set by
34
+ # BrickletPTC#set_resistance_callback_period. The parameter is the resistance
35
+ # of the sensor.
36
+ #
37
+ # CALLBACK_RESISTANCE is only triggered if the resistance has changed since the
38
+ # last triggering.
39
+ CALLBACK_RESISTANCE = 15
40
+
41
+ # This callback is triggered when the threshold as set by
42
+ # BrickletPTC#set_resistance_callback_threshold is reached.
43
+ # The parameter is the resistance of the sensor.
44
+ #
45
+ # If the threshold keeps being reached, the callback is triggered periodically
46
+ # with the period as set by BrickletPTC#set_debounce_period.
47
+ CALLBACK_RESISTANCE_REACHED = 16
48
+
49
+ FUNCTION_GET_TEMPERATURE = 1 # :nodoc:
50
+ FUNCTION_GET_RESISTANCE = 2 # :nodoc:
51
+ FUNCTION_SET_TEMPERATURE_CALLBACK_PERIOD = 3 # :nodoc:
52
+ FUNCTION_GET_TEMPERATURE_CALLBACK_PERIOD = 4 # :nodoc:
53
+ FUNCTION_SET_RESISTANCE_CALLBACK_PERIOD = 5 # :nodoc:
54
+ FUNCTION_GET_RESISTANCE_CALLBACK_PERIOD = 6 # :nodoc:
55
+ FUNCTION_SET_TEMPERATURE_CALLBACK_THRESHOLD = 7 # :nodoc:
56
+ FUNCTION_GET_TEMPERATURE_CALLBACK_THRESHOLD = 8 # :nodoc:
57
+ FUNCTION_SET_RESISTANCE_CALLBACK_THRESHOLD = 9 # :nodoc:
58
+ FUNCTION_GET_RESISTANCE_CALLBACK_THRESHOLD = 10 # :nodoc:
59
+ FUNCTION_SET_DEBOUNCE_PERIOD = 11 # :nodoc:
60
+ FUNCTION_GET_DEBOUNCE_PERIOD = 12 # :nodoc:
61
+ FUNCTION_SET_NOISE_REJECTION_FILTER = 17 # :nodoc:
62
+ FUNCTION_GET_NOISE_REJECTION_FILTER = 18 # :nodoc:
63
+ FUNCTION_IS_SENSOR_CONNECTED = 19 # :nodoc:
64
+ FUNCTION_SET_WIRE_MODE = 20 # :nodoc:
65
+ FUNCTION_GET_WIRE_MODE = 21 # :nodoc:
66
+ FUNCTION_GET_IDENTITY = 255 # :nodoc:
67
+
68
+ THRESHOLD_OPTION_OFF = 'x' # :nodoc:
69
+ THRESHOLD_OPTION_OUTSIDE = 'o' # :nodoc:
70
+ THRESHOLD_OPTION_INSIDE = 'i' # :nodoc:
71
+ THRESHOLD_OPTION_SMALLER = '<' # :nodoc:
72
+ THRESHOLD_OPTION_GREATER = '>' # :nodoc:
73
+ FILTER_OPTION_50HZ = 0 # :nodoc:
74
+ FILTER_OPTION_60HZ = 1 # :nodoc:
75
+ WIRE_MODE_2OR4 = 0 # :nodoc:
76
+ WIRE_MODE_3 = 1 # :nodoc:
77
+
78
+ # Creates an object with the unique device ID <tt>uid</tt> and adds it to
79
+ # the IP Connection <tt>ipcon</tt>.
80
+ def initialize(uid, ipcon)
81
+ super uid, ipcon
82
+
83
+ @api_version = [2, 0, 0]
84
+
85
+ @response_expected[FUNCTION_GET_TEMPERATURE] = RESPONSE_EXPECTED_ALWAYS_TRUE
86
+ @response_expected[FUNCTION_GET_RESISTANCE] = RESPONSE_EXPECTED_ALWAYS_TRUE
87
+ @response_expected[FUNCTION_SET_TEMPERATURE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
88
+ @response_expected[FUNCTION_GET_TEMPERATURE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
89
+ @response_expected[FUNCTION_SET_RESISTANCE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
90
+ @response_expected[FUNCTION_GET_RESISTANCE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
91
+ @response_expected[FUNCTION_SET_TEMPERATURE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE
92
+ @response_expected[FUNCTION_GET_TEMPERATURE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_ALWAYS_TRUE
93
+ @response_expected[FUNCTION_SET_RESISTANCE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE
94
+ @response_expected[FUNCTION_GET_RESISTANCE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_ALWAYS_TRUE
95
+ @response_expected[FUNCTION_SET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_TRUE
96
+ @response_expected[FUNCTION_GET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
97
+ @response_expected[CALLBACK_TEMPERATURE] = RESPONSE_EXPECTED_ALWAYS_FALSE
98
+ @response_expected[CALLBACK_TEMPERATURE_REACHED] = RESPONSE_EXPECTED_ALWAYS_FALSE
99
+ @response_expected[CALLBACK_RESISTANCE] = RESPONSE_EXPECTED_ALWAYS_FALSE
100
+ @response_expected[CALLBACK_RESISTANCE_REACHED] = RESPONSE_EXPECTED_ALWAYS_FALSE
101
+ @response_expected[FUNCTION_SET_NOISE_REJECTION_FILTER] = RESPONSE_EXPECTED_FALSE
102
+ @response_expected[FUNCTION_GET_NOISE_REJECTION_FILTER] = RESPONSE_EXPECTED_ALWAYS_TRUE
103
+ @response_expected[FUNCTION_IS_SENSOR_CONNECTED] = RESPONSE_EXPECTED_ALWAYS_TRUE
104
+ @response_expected[FUNCTION_SET_WIRE_MODE] = RESPONSE_EXPECTED_FALSE
105
+ @response_expected[FUNCTION_GET_WIRE_MODE] = RESPONSE_EXPECTED_ALWAYS_TRUE
106
+ @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
107
+
108
+ @callback_formats[CALLBACK_TEMPERATURE] = 'l'
109
+ @callback_formats[CALLBACK_TEMPERATURE_REACHED] = 'l'
110
+ @callback_formats[CALLBACK_RESISTANCE] = 'S'
111
+ @callback_formats[CALLBACK_RESISTANCE_REACHED] = 'S'
112
+ end
113
+
114
+ # TODO
115
+ #
116
+ # If you want to get the temperature periodically, it is recommended
117
+ # to use the callback CALLBACK_TEMPERATURE and set the period with
118
+ # BrickletPTC#set_temperature_callback_period.
119
+ def get_temperature
120
+ send_request(FUNCTION_GET_TEMPERATURE, [], '', 4, 'l')
121
+ end
122
+
123
+ # TODO
124
+ #
125
+ # If you want to get the resistance periodically, it is recommended
126
+ # to use the callback CALLBACK_RESISTANCE and set the period with
127
+ # BrickletPTC#set_resistance_callback_period.
128
+ def get_resistance
129
+ send_request(FUNCTION_GET_RESISTANCE, [], '', 2, 'S')
130
+ end
131
+
132
+ # Sets the period in ms with which the CALLBACK_TEMPERATURE callback is triggered
133
+ # periodically. A value of 0 turns the callback off.
134
+ #
135
+ # CALLBACK_TEMPERATURE is only triggered if the temperature has changed since the
136
+ # last triggering.
137
+ #
138
+ # The default value is 0.
139
+ def set_temperature_callback_period(period)
140
+ send_request(FUNCTION_SET_TEMPERATURE_CALLBACK_PERIOD, [period], 'L', 0, '')
141
+ end
142
+
143
+ # Returns the period as set by BrickletPTC#set_temperature_callback_period.
144
+ def get_temperature_callback_period
145
+ send_request(FUNCTION_GET_TEMPERATURE_CALLBACK_PERIOD, [], '', 4, 'L')
146
+ end
147
+
148
+ # Sets the period in ms with which the CALLBACK_RESISTANCE callback is triggered
149
+ # periodically. A value of 0 turns the callback off.
150
+ #
151
+ # CALLBACK_RESISTANCE is only triggered if the resistance has changed since the
152
+ # last triggering.
153
+ #
154
+ # The default value is 0.
155
+ def set_resistance_callback_period(period)
156
+ send_request(FUNCTION_SET_RESISTANCE_CALLBACK_PERIOD, [period], 'L', 0, '')
157
+ end
158
+
159
+ # Returns the period as set by BrickletPTC#set_resistance_callback_period.
160
+ def get_resistance_callback_period
161
+ send_request(FUNCTION_GET_RESISTANCE_CALLBACK_PERIOD, [], '', 4, 'L')
162
+ end
163
+
164
+ # Sets the thresholds for the CALLBACK_TEMPERATURE_REACHED callback.
165
+ #
166
+ # The following options are possible:
167
+ #
168
+ # "Option", "Description"
169
+ #
170
+ # "'x'", "Callback is turned off"
171
+ # "'o'", "Callback is triggered when the temperature is *outside* the min and max values"
172
+ # "'i'", "Callback is triggered when the temperature is *inside* the min and max values"
173
+ # "'<'", "Callback is triggered when the temperature is smaller than the min value (max is ignored)"
174
+ # "'>'", "Callback is triggered when the temperature is greater than the min value (max is ignored)"
175
+ #
176
+ # The default value is ('x', 0, 0).
177
+ def set_temperature_callback_threshold(option, min, max)
178
+ send_request(FUNCTION_SET_TEMPERATURE_CALLBACK_THRESHOLD, [option, min, max], 'k l l', 0, '')
179
+ end
180
+
181
+ # Returns the threshold as set by BrickletPTC#set_temperature_callback_threshold.
182
+ def get_temperature_callback_threshold
183
+ send_request(FUNCTION_GET_TEMPERATURE_CALLBACK_THRESHOLD, [], '', 9, 'k l l')
184
+ end
185
+
186
+ # Sets the thresholds for the CALLBACK_RESISTANCE_REACHED callback.
187
+ #
188
+ # The following options are possible:
189
+ #
190
+ # "Option", "Description"
191
+ #
192
+ # "'x'", "Callback is turned off"
193
+ # "'o'", "Callback is triggered when the temperature is *outside* the min and max values"
194
+ # "'i'", "Callback is triggered when the temperature is *inside* the min and max values"
195
+ # "'<'", "Callback is triggered when the temperature is smaller than the min value (max is ignored)"
196
+ # "'>'", "Callback is triggered when the temperature is greater than the min value (max is ignored)"
197
+ #
198
+ # The default value is ('x', 0, 0).
199
+ def set_resistance_callback_threshold(option, min, max)
200
+ send_request(FUNCTION_SET_RESISTANCE_CALLBACK_THRESHOLD, [option, min, max], 'k S S', 0, '')
201
+ end
202
+
203
+ # Returns the threshold as set by BrickletPTC#set_resistance_callback_threshold.
204
+ def get_resistance_callback_threshold
205
+ send_request(FUNCTION_GET_RESISTANCE_CALLBACK_THRESHOLD, [], '', 5, 'k S S')
206
+ end
207
+
208
+ # Sets the period in ms with which the threshold callback
209
+ #
210
+ # CALLBACK_TEMPERATURE_REACHED, CALLBACK_RESISTANCE_REACHED
211
+ #
212
+ # is triggered, if the threshold
213
+ #
214
+ # BrickletPTC#set_temperature_callback_threshold, BrickletPTC#set_resistance_callback_threshold
215
+ #
216
+ # keeps being reached.
217
+ #
218
+ # The default value is 100.
219
+ def set_debounce_period(debounce)
220
+ send_request(FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 0, '')
221
+ end
222
+
223
+ # Returns the debounce period as set by BrickletPTC#set_debounce_period.
224
+ def get_debounce_period
225
+ send_request(FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 4, 'L')
226
+ end
227
+
228
+ # TODO: Setting noise rejection filter frequency (50 or 60hz), default 50hz).
229
+ def set_noise_rejection_filter(filter)
230
+ send_request(FUNCTION_SET_NOISE_REJECTION_FILTER, [filter], 'C', 0, '')
231
+ end
232
+
233
+ # Returns the noise rejection filter option as set by
234
+ # BrickletPTC#set_noise_rejection_filter
235
+ def get_noise_rejection_filter
236
+ send_request(FUNCTION_GET_NOISE_REJECTION_FILTER, [], '', 1, 'C')
237
+ end
238
+
239
+ # Returns *true* if the sensor is connected correctly.
240
+ #
241
+ # If this function
242
+ # returns *false*, there is either no pt100 or pt1000 sensor connected,
243
+ # the sensor is connect incorrectly or the sensor itself is faulty.
244
+ def is_sensor_connected
245
+ send_request(FUNCTION_IS_SENSOR_CONNECTED, [], '', 1, '?')
246
+ end
247
+
248
+ # TODO: Default: 1 (3 wire)
249
+ def set_wire_mode(mode)
250
+ send_request(FUNCTION_SET_WIRE_MODE, [mode], 'C', 0, '')
251
+ end
252
+
253
+ # Returns the wire mode as set by BrickletPTC#set_wire_mode
254
+ def get_wire_mode
255
+ send_request(FUNCTION_GET_WIRE_MODE, [], '', 1, 'C')
256
+ end
257
+
258
+ # Returns the UID, the UID where the Bricklet is connected to,
259
+ # the position, the hardware and firmware version as well as the
260
+ # device identifier.
261
+ #
262
+ # The position can be 'a', 'b', 'c' or 'd'.
263
+ #
264
+ # The device identifiers can be found :ref:`here <device_identifier>`.
265
+ #
266
+ # .. versionadded:: 2.0.0~(Plugin)
267
+ def get_identity
268
+ send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S')
269
+ end
270
+
271
+ # Registers a callback with ID <tt>id</tt> to the block <tt>block</tt>.
272
+ def register_callback(id, &block)
273
+ callback = block
274
+ @registered_callbacks[id] = callback
275
+ end
276
+ end
277
+ end