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.
- data/lib/tinkerforge.rb +5 -0
- data/lib/tinkerforge/brick_dc.rb +359 -0
- data/lib/tinkerforge/brick_imu.rb +512 -0
- data/lib/tinkerforge/brick_master.rb +1120 -0
- data/lib/tinkerforge/brick_servo.rb +475 -0
- data/lib/tinkerforge/brick_stepper.rb +556 -0
- data/lib/tinkerforge/bricklet_ambient_light.rb +246 -0
- data/lib/tinkerforge/bricklet_analog_in.rb +273 -0
- data/lib/tinkerforge/bricklet_analog_out.rb +90 -0
- data/lib/tinkerforge/bricklet_barometer.rb +313 -0
- data/lib/tinkerforge/bricklet_current12.rb +274 -0
- data/lib/tinkerforge/bricklet_current25.rb +274 -0
- data/lib/tinkerforge/bricklet_distance_ir.rb +274 -0
- data/lib/tinkerforge/bricklet_dual_relay.rb +127 -0
- data/lib/tinkerforge/bricklet_gps.rb +301 -0
- data/lib/tinkerforge/bricklet_humidity.rb +245 -0
- data/lib/tinkerforge/bricklet_industrial_digital_in_4.rb +165 -0
- data/lib/tinkerforge/bricklet_industrial_digital_out_4.rb +177 -0
- data/lib/tinkerforge/bricklet_industrial_quad_relay.rb +177 -0
- data/lib/tinkerforge/bricklet_io16.rb +237 -0
- data/lib/tinkerforge/bricklet_io4.rb +236 -0
- data/lib/tinkerforge/bricklet_joystick.rb +274 -0
- data/lib/tinkerforge/bricklet_lcd_16x2.rb +175 -0
- data/lib/tinkerforge/bricklet_lcd_20x4.rb +231 -0
- data/lib/tinkerforge/bricklet_linear_poti.rb +241 -0
- data/lib/tinkerforge/bricklet_piezo_buzzer.rb +84 -0
- data/lib/tinkerforge/bricklet_ptc.rb +277 -0
- data/lib/tinkerforge/bricklet_rotary_poti.rb +241 -0
- data/lib/tinkerforge/bricklet_temperature.rb +188 -0
- data/lib/tinkerforge/bricklet_temperature_ir.rb +275 -0
- data/lib/tinkerforge/bricklet_voltage.rb +241 -0
- data/lib/tinkerforge/bricklet_voltage_current.rb +386 -0
- data/lib/tinkerforge/ip_connection.rb +1027 -0
- data/lib/tinkerforge/version.rb +4 -0
- 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 Voltages between 0 and 50V
|
14
|
+
class BrickletVoltage < Device
|
15
|
+
DEVICE_IDENTIFIER = 218 # :nodoc:
|
16
|
+
|
17
|
+
# This callback is triggered periodically with the period that is set by
|
18
|
+
# BrickletVoltage#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
|
+
# BrickletVoltage#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
|
+
# BrickletVoltage#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 BrickletVoltage#set_debounce_period.
|
39
|
+
CALLBACK_VOLTAGE_REACHED = 15
|
40
|
+
|
41
|
+
# This callback is triggered when the threshold as set by
|
42
|
+
# BrickletVoltage#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 BrickletVoltage#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_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_VOLTAGE] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
77
|
+
@response_expected[FUNCTION_GET_ANALOG_VALUE] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
78
|
+
@response_expected[FUNCTION_SET_VOLTAGE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
|
79
|
+
@response_expected[FUNCTION_GET_VOLTAGE_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_VOLTAGE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE
|
83
|
+
@response_expected[FUNCTION_GET_VOLTAGE_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_VOLTAGE] = RESPONSE_EXPECTED_ALWAYS_FALSE
|
89
|
+
@response_expected[CALLBACK_ANALOG_VALUE] = RESPONSE_EXPECTED_ALWAYS_FALSE
|
90
|
+
@response_expected[CALLBACK_VOLTAGE_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_VOLTAGE] = 'S'
|
95
|
+
@callback_formats[CALLBACK_ANALOG_VALUE] = 'S'
|
96
|
+
@callback_formats[CALLBACK_VOLTAGE_REACHED] = 'S'
|
97
|
+
@callback_formats[CALLBACK_ANALOG_VALUE_REACHED] = 'S'
|
98
|
+
end
|
99
|
+
|
100
|
+
# Returns the voltage of the sensor. The value is in mV and
|
101
|
+
# between 0mV and 50000mV.
|
102
|
+
#
|
103
|
+
# If you want to get the voltage periodically, it is recommended to use the
|
104
|
+
# callback CALLBACK_VOLTAGE and set the period with
|
105
|
+
# BrickletVoltage#set_voltage_callback_period.
|
106
|
+
def get_voltage
|
107
|
+
send_request(FUNCTION_GET_VOLTAGE, [], '', 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 BrickletVoltage#get_voltage is averaged over several samples
|
115
|
+
# to yield less noise, while BrickletVoltage#get_analog_value gives back raw
|
116
|
+
# unfiltered analog values. The only reason to use BrickletVoltage#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
|
+
# BrickletVoltage#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_VOLTAGE callback is triggered
|
127
|
+
# periodically. A value of 0 turns the callback off.
|
128
|
+
#
|
129
|
+
# CALLBACK_VOLTAGE is only triggered if the voltage has changed since the
|
130
|
+
# last triggering.
|
131
|
+
#
|
132
|
+
# The default value is 0.
|
133
|
+
def set_voltage_callback_period(period)
|
134
|
+
send_request(FUNCTION_SET_VOLTAGE_CALLBACK_PERIOD, [period], 'L', 0, '')
|
135
|
+
end
|
136
|
+
|
137
|
+
# Returns the period as set by BrickletVoltage#set_voltage_callback_period.
|
138
|
+
def get_voltage_callback_period
|
139
|
+
send_request(FUNCTION_GET_VOLTAGE_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 BrickletVoltage#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_VOLTAGE_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 voltage is *outside* the min and max values"
|
166
|
+
# "'i'", "Callback is triggered when the voltage is *inside* the min and max values"
|
167
|
+
# "'<'", "Callback is triggered when the voltage is smaller than the min value (max is ignored)"
|
168
|
+
# "'>'", "Callback is triggered when the voltage is greater than the min value (max is ignored)"
|
169
|
+
#
|
170
|
+
# The default value is ('x', 0, 0).
|
171
|
+
def set_voltage_callback_threshold(option, min, max)
|
172
|
+
send_request(FUNCTION_SET_VOLTAGE_CALLBACK_THRESHOLD, [option, min, max], 'k s s', 0, '')
|
173
|
+
end
|
174
|
+
|
175
|
+
# Returns the threshold as set by BrickletVoltage#set_voltage_callback_threshold.
|
176
|
+
def get_voltage_callback_threshold
|
177
|
+
send_request(FUNCTION_GET_VOLTAGE_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 BrickletVoltage#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_VOLTAGE_REACHED, CALLBACK_ANALOG_VALUE_REACHED
|
205
|
+
#
|
206
|
+
# are triggered, if the thresholds
|
207
|
+
#
|
208
|
+
# BrickletVoltage#set_voltage_callback_threshold, BrickletVoltage#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 BrickletVoltage#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,386 @@
|
|
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 high precision sensing of voltage and current
|
14
|
+
class BrickletVoltageCurrent < Device
|
15
|
+
DEVICE_IDENTIFIER = 227 # :nodoc:
|
16
|
+
|
17
|
+
# This callback is triggered periodically with the period that is set by
|
18
|
+
# BrickletVoltageCurrent#set_current_callback_period. The parameter is the current of the
|
19
|
+
# sensor.
|
20
|
+
#
|
21
|
+
# CALLBACK_CURRENT is only triggered if the current has changed since the
|
22
|
+
# last triggering.
|
23
|
+
CALLBACK_CURRENT = 22
|
24
|
+
|
25
|
+
# This callback is triggered periodically with the period that is set by
|
26
|
+
# BrickletVoltageCurrent#set_voltage_callback_period. The parameter is the voltage of the
|
27
|
+
# sensor.
|
28
|
+
#
|
29
|
+
# CALLBACK_VOLTAGE is only triggered if the voltage has changed since the
|
30
|
+
# last triggering.
|
31
|
+
CALLBACK_VOLTAGE = 23
|
32
|
+
|
33
|
+
# This callback is triggered periodically with the period that is set by
|
34
|
+
# BrickletVoltageCurrent#set_power_callback_period. The parameter is the power of the
|
35
|
+
# sensor.
|
36
|
+
#
|
37
|
+
# CALLBACK_POWER is only triggered if the power has changed since the
|
38
|
+
# last triggering.
|
39
|
+
CALLBACK_POWER = 24
|
40
|
+
|
41
|
+
# This callback is triggered when the threshold as set by
|
42
|
+
# BrickletVoltageCurrent#set_current_callback_threshold is reached.
|
43
|
+
# The parameter is the current of the sensor.
|
44
|
+
#
|
45
|
+
# If the threshold keeps being reached, the callback is triggered periodically
|
46
|
+
# with the period as set by BrickletVoltageCurrent#set_debounce_period.
|
47
|
+
CALLBACK_CURRENT_REACHED = 25
|
48
|
+
|
49
|
+
# This callback is triggered when the threshold as set by
|
50
|
+
# BrickletVoltageCurrent#set_voltage_callback_threshold is reached.
|
51
|
+
# The parameter is the voltage of the sensor.
|
52
|
+
#
|
53
|
+
# If the threshold keeps being reached, the callback is triggered periodically
|
54
|
+
# with the period as set by BrickletVoltageCurrent#set_debounce_period.
|
55
|
+
CALLBACK_VOLTAGE_REACHED = 26
|
56
|
+
|
57
|
+
# This callback is triggered when the threshold as set by
|
58
|
+
# BrickletVoltageCurrent#set_power_callback_threshold is reached.
|
59
|
+
# The parameter is the power of the sensor.
|
60
|
+
#
|
61
|
+
# If the threshold keeps being reached, the callback is triggered periodically
|
62
|
+
# with the period as set by BrickletVoltageCurrent#set_debounce_period.
|
63
|
+
CALLBACK_POWER_REACHED = 27
|
64
|
+
|
65
|
+
FUNCTION_GET_CURRENT = 1 # :nodoc:
|
66
|
+
FUNCTION_GET_VOLTAGE = 2 # :nodoc:
|
67
|
+
FUNCTION_GET_POWER = 3 # :nodoc:
|
68
|
+
FUNCTION_SET_CONFIGURATION = 4 # :nodoc:
|
69
|
+
FUNCTION_GET_CONFIGURATION = 5 # :nodoc:
|
70
|
+
FUNCTION_SET_CALIBRATION = 6 # :nodoc:
|
71
|
+
FUNCTION_GET_CALIBRATION = 7 # :nodoc:
|
72
|
+
FUNCTION_SET_CURRENT_CALLBACK_PERIOD = 8 # :nodoc:
|
73
|
+
FUNCTION_GET_CURRENT_CALLBACK_PERIOD = 9 # :nodoc:
|
74
|
+
FUNCTION_SET_VOLTAGE_CALLBACK_PERIOD = 10 # :nodoc:
|
75
|
+
FUNCTION_GET_VOLTAGE_CALLBACK_PERIOD = 11 # :nodoc:
|
76
|
+
FUNCTION_SET_POWER_CALLBACK_PERIOD = 12 # :nodoc:
|
77
|
+
FUNCTION_GET_POWER_CALLBACK_PERIOD = 13 # :nodoc:
|
78
|
+
FUNCTION_SET_CURRENT_CALLBACK_THRESHOLD = 14 # :nodoc:
|
79
|
+
FUNCTION_GET_CURRENT_CALLBACK_THRESHOLD = 15 # :nodoc:
|
80
|
+
FUNCTION_SET_VOLTAGE_CALLBACK_THRESHOLD = 16 # :nodoc:
|
81
|
+
FUNCTION_GET_VOLTAGE_CALLBACK_THRESHOLD = 17 # :nodoc:
|
82
|
+
FUNCTION_SET_POWER_CALLBACK_THRESHOLD = 18 # :nodoc:
|
83
|
+
FUNCTION_GET_POWER_CALLBACK_THRESHOLD = 19 # :nodoc:
|
84
|
+
FUNCTION_SET_DEBOUNCE_PERIOD = 20 # :nodoc:
|
85
|
+
FUNCTION_GET_DEBOUNCE_PERIOD = 21 # :nodoc:
|
86
|
+
FUNCTION_GET_IDENTITY = 255 # :nodoc:
|
87
|
+
|
88
|
+
AVERAGING_1 = 0 # :nodoc:
|
89
|
+
AVERAGING_4 = 1 # :nodoc:
|
90
|
+
AVERAGING_16 = 2 # :nodoc:
|
91
|
+
AVERAGING_64 = 3 # :nodoc:
|
92
|
+
AVERAGING_128 = 4 # :nodoc:
|
93
|
+
AVERAGING_256 = 5 # :nodoc:
|
94
|
+
AVERAGING_512 = 6 # :nodoc:
|
95
|
+
AVERAGING_1024 = 7 # :nodoc:
|
96
|
+
THRESHOLD_OPTION_OFF = 'x' # :nodoc:
|
97
|
+
THRESHOLD_OPTION_OUTSIDE = 'o' # :nodoc:
|
98
|
+
THRESHOLD_OPTION_INSIDE = 'i' # :nodoc:
|
99
|
+
THRESHOLD_OPTION_SMALLER = '<' # :nodoc:
|
100
|
+
THRESHOLD_OPTION_GREATER = '>' # :nodoc:
|
101
|
+
|
102
|
+
# Creates an object with the unique device ID <tt>uid</tt> and adds it to
|
103
|
+
# the IP Connection <tt>ipcon</tt>.
|
104
|
+
def initialize(uid, ipcon)
|
105
|
+
super uid, ipcon
|
106
|
+
|
107
|
+
@api_version = [2, 0, 0]
|
108
|
+
|
109
|
+
@response_expected[FUNCTION_GET_CURRENT] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
110
|
+
@response_expected[FUNCTION_GET_VOLTAGE] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
111
|
+
@response_expected[FUNCTION_GET_POWER] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
112
|
+
@response_expected[FUNCTION_SET_CONFIGURATION] = RESPONSE_EXPECTED_FALSE
|
113
|
+
@response_expected[FUNCTION_GET_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
114
|
+
@response_expected[FUNCTION_SET_CALIBRATION] = RESPONSE_EXPECTED_FALSE
|
115
|
+
@response_expected[FUNCTION_GET_CALIBRATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
116
|
+
@response_expected[FUNCTION_SET_CURRENT_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
|
117
|
+
@response_expected[FUNCTION_GET_CURRENT_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
118
|
+
@response_expected[FUNCTION_SET_VOLTAGE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
|
119
|
+
@response_expected[FUNCTION_GET_VOLTAGE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
120
|
+
@response_expected[FUNCTION_SET_POWER_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
|
121
|
+
@response_expected[FUNCTION_GET_POWER_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
122
|
+
@response_expected[FUNCTION_SET_CURRENT_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE
|
123
|
+
@response_expected[FUNCTION_GET_CURRENT_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
124
|
+
@response_expected[FUNCTION_SET_VOLTAGE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE
|
125
|
+
@response_expected[FUNCTION_GET_VOLTAGE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
126
|
+
@response_expected[FUNCTION_SET_POWER_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE
|
127
|
+
@response_expected[FUNCTION_GET_POWER_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
128
|
+
@response_expected[FUNCTION_SET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_TRUE
|
129
|
+
@response_expected[FUNCTION_GET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
130
|
+
@response_expected[CALLBACK_CURRENT] = RESPONSE_EXPECTED_ALWAYS_FALSE
|
131
|
+
@response_expected[CALLBACK_VOLTAGE] = RESPONSE_EXPECTED_ALWAYS_FALSE
|
132
|
+
@response_expected[CALLBACK_POWER] = RESPONSE_EXPECTED_ALWAYS_FALSE
|
133
|
+
@response_expected[CALLBACK_CURRENT_REACHED] = RESPONSE_EXPECTED_ALWAYS_FALSE
|
134
|
+
@response_expected[CALLBACK_VOLTAGE_REACHED] = RESPONSE_EXPECTED_ALWAYS_FALSE
|
135
|
+
@response_expected[CALLBACK_POWER_REACHED] = RESPONSE_EXPECTED_ALWAYS_FALSE
|
136
|
+
@response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
137
|
+
|
138
|
+
@callback_formats[CALLBACK_CURRENT] = 'l'
|
139
|
+
@callback_formats[CALLBACK_VOLTAGE] = 'l'
|
140
|
+
@callback_formats[CALLBACK_POWER] = 'l'
|
141
|
+
@callback_formats[CALLBACK_CURRENT_REACHED] = 'l'
|
142
|
+
@callback_formats[CALLBACK_VOLTAGE_REACHED] = 'l'
|
143
|
+
@callback_formats[CALLBACK_POWER_REACHED] = 'l'
|
144
|
+
end
|
145
|
+
|
146
|
+
# Returns the current. The value is in mA
|
147
|
+
# and between 0mA and 20000mA.
|
148
|
+
#
|
149
|
+
# If you want to get the current periodically, it is recommended to use the
|
150
|
+
# callback CALLBACK_CURRENT and set the period with
|
151
|
+
# BrickletVoltageCurrent#set_current_callback_period.
|
152
|
+
def get_current
|
153
|
+
send_request(FUNCTION_GET_CURRENT, [], '', 4, 'l')
|
154
|
+
end
|
155
|
+
|
156
|
+
# Returns the voltage. The value is in mV
|
157
|
+
# and between 0mV and 36000mV.
|
158
|
+
#
|
159
|
+
# If you want to get the voltage periodically, it is recommended to use the
|
160
|
+
# callback CALLBACK_VOLTAGE and set the period with
|
161
|
+
# BrickletVoltageCurrent#set_voltage_callback_period.
|
162
|
+
def get_voltage
|
163
|
+
send_request(FUNCTION_GET_VOLTAGE, [], '', 4, 'l')
|
164
|
+
end
|
165
|
+
|
166
|
+
# Returns the power. The value is in mW
|
167
|
+
# and between 0mV and 720000mW.
|
168
|
+
#
|
169
|
+
# If you want to get the power periodically, it is recommended to use the
|
170
|
+
# callback CALLBACK_POWER and set the period with
|
171
|
+
# BrickletVoltageCurrent#set_power_callback_period.
|
172
|
+
def get_power
|
173
|
+
send_request(FUNCTION_GET_POWER, [], '', 4, 'l')
|
174
|
+
end
|
175
|
+
|
176
|
+
# Sets the configuration of the Voltage/Current Bricklet. It is
|
177
|
+
# possible to configure number of averages as well as
|
178
|
+
# voltage and current conversion time.
|
179
|
+
#
|
180
|
+
# Averaging:
|
181
|
+
#
|
182
|
+
# "Value", "Number of Averages"
|
183
|
+
#
|
184
|
+
# "0", "1"
|
185
|
+
# "1", "4"
|
186
|
+
# "2", "16"
|
187
|
+
# "3", "64"
|
188
|
+
# "4", "128"
|
189
|
+
# "5", "256"
|
190
|
+
# "6", "512"
|
191
|
+
# ">=7", "1024"
|
192
|
+
#
|
193
|
+
# Voltage/Current conversion:
|
194
|
+
#
|
195
|
+
# "Value", "Conversion time"
|
196
|
+
#
|
197
|
+
# "0", "140µs"
|
198
|
+
# "1", "204µs"
|
199
|
+
# "2", "332µs"
|
200
|
+
# "3", "588µs"
|
201
|
+
# "4", "1.1ms"
|
202
|
+
# "5", "2.116ms"
|
203
|
+
# "6", "4.156ms"
|
204
|
+
# ">=7", "8.244ms"
|
205
|
+
#
|
206
|
+
# The default values are 3, 4 and 4 (64, 1.1ms, 1.1ms) for averaging, voltage
|
207
|
+
# conversion and current conversion.
|
208
|
+
def set_configuration(averaging, voltage_conversion_time, current_conversion_time)
|
209
|
+
send_request(FUNCTION_SET_CONFIGURATION, [averaging, voltage_conversion_time, current_conversion_time], 'C C C', 0, '')
|
210
|
+
end
|
211
|
+
|
212
|
+
# Returns the configuration as set by BrickletVoltageCurrent#set_configuration.
|
213
|
+
def get_configuration
|
214
|
+
send_request(FUNCTION_GET_CONFIGURATION, [], '', 3, 'C C C')
|
215
|
+
end
|
216
|
+
|
217
|
+
# Since the shunt resistor that is used to measure the current is not
|
218
|
+
# perfectly precise, it needs to be calibrated by a multiplier and
|
219
|
+
# divisor if a very precise reading is needed.
|
220
|
+
#
|
221
|
+
# For example, if you are expecting a measurement of 1000mA and you
|
222
|
+
# are measuring 1023mA, you can calibrate the Voltage/Current Bricklet
|
223
|
+
# by setting the multiplier to 1000 and the divisor to 1023.
|
224
|
+
def set_calibration(gain_multiplier, gain_divisor)
|
225
|
+
send_request(FUNCTION_SET_CALIBRATION, [gain_multiplier, gain_divisor], 'S S', 0, '')
|
226
|
+
end
|
227
|
+
|
228
|
+
# Returns the calibration as set by BrickletVoltageCurrent#set_calibration.
|
229
|
+
def get_calibration
|
230
|
+
send_request(FUNCTION_GET_CALIBRATION, [], '', 4, 'S S')
|
231
|
+
end
|
232
|
+
|
233
|
+
# Sets the period in ms with which the CALLBACK_CURRENT callback is triggered
|
234
|
+
# periodically. A value of 0 turns the callback off.
|
235
|
+
#
|
236
|
+
# CALLBACK_CURRENT is only triggered if the current has changed since the
|
237
|
+
# last triggering.
|
238
|
+
#
|
239
|
+
# The default value is 0.
|
240
|
+
def set_current_callback_period(period)
|
241
|
+
send_request(FUNCTION_SET_CURRENT_CALLBACK_PERIOD, [period], 'L', 0, '')
|
242
|
+
end
|
243
|
+
|
244
|
+
# Returns the period as set by BrickletVoltageCurrent#set_current_callback_period.
|
245
|
+
def get_current_callback_period
|
246
|
+
send_request(FUNCTION_GET_CURRENT_CALLBACK_PERIOD, [], '', 4, 'L')
|
247
|
+
end
|
248
|
+
|
249
|
+
# Sets the period in ms with which the CALLBACK_VOLTAGE callback is triggered
|
250
|
+
# periodically. A value of 0 turns the callback off.
|
251
|
+
#
|
252
|
+
# CALLBACK_VOLTAGE is only triggered if the voltage has changed since the
|
253
|
+
# last triggering.
|
254
|
+
#
|
255
|
+
# The default value is 0.
|
256
|
+
def set_voltage_callback_period(period)
|
257
|
+
send_request(FUNCTION_SET_VOLTAGE_CALLBACK_PERIOD, [period], 'L', 0, '')
|
258
|
+
end
|
259
|
+
|
260
|
+
# Returns the period as set by BrickletVoltageCurrent#set_voltage_callback_period.
|
261
|
+
def get_voltage_callback_period
|
262
|
+
send_request(FUNCTION_GET_VOLTAGE_CALLBACK_PERIOD, [], '', 4, 'L')
|
263
|
+
end
|
264
|
+
|
265
|
+
# Sets the period in ms with which the CALLBACK_POWER callback is triggered
|
266
|
+
# periodically. A value of 0 turns the callback off.
|
267
|
+
#
|
268
|
+
# CALLBACK_POWER is only triggered if the power has changed since the
|
269
|
+
# last triggering.
|
270
|
+
#
|
271
|
+
# The default value is 0.
|
272
|
+
def set_power_callback_period(period)
|
273
|
+
send_request(FUNCTION_SET_POWER_CALLBACK_PERIOD, [period], 'L', 0, '')
|
274
|
+
end
|
275
|
+
|
276
|
+
# Returns the period as set by BrickletVoltageCurrent#get_power_callback_period.
|
277
|
+
def get_power_callback_period
|
278
|
+
send_request(FUNCTION_GET_POWER_CALLBACK_PERIOD, [], '', 4, 'L')
|
279
|
+
end
|
280
|
+
|
281
|
+
# Sets the thresholds for the CALLBACK_CURRENT_REACHED callback.
|
282
|
+
#
|
283
|
+
# The following options are possible:
|
284
|
+
#
|
285
|
+
# "Option", "Description"
|
286
|
+
#
|
287
|
+
# "'x'", "Callback is turned off"
|
288
|
+
# "'o'", "Callback is triggered when the current is *outside* the min and max values"
|
289
|
+
# "'i'", "Callback is triggered when the current is *inside* the min and max values"
|
290
|
+
# "'<'", "Callback is triggered when the current is smaller than the min value (max is ignored)"
|
291
|
+
# "'>'", "Callback is triggered when the current is greater than the min value (max is ignored)"
|
292
|
+
#
|
293
|
+
# The default value is ('x', 0, 0).
|
294
|
+
def set_current_callback_threshold(option, min, max)
|
295
|
+
send_request(FUNCTION_SET_CURRENT_CALLBACK_THRESHOLD, [option, min, max], 'k l l', 0, '')
|
296
|
+
end
|
297
|
+
|
298
|
+
# Returns the threshold as set by BrickletVoltageCurrent#set_current_callback_threshold.
|
299
|
+
def get_current_callback_threshold
|
300
|
+
send_request(FUNCTION_GET_CURRENT_CALLBACK_THRESHOLD, [], '', 9, 'k l l')
|
301
|
+
end
|
302
|
+
|
303
|
+
# Sets the thresholds for the CALLBACK_VOLTAGE_REACHED callback.
|
304
|
+
#
|
305
|
+
# The following options are possible:
|
306
|
+
#
|
307
|
+
# "Option", "Description"
|
308
|
+
#
|
309
|
+
# "'x'", "Callback is turned off"
|
310
|
+
# "'o'", "Callback is triggered when the voltage is *outside* the min and max values"
|
311
|
+
# "'i'", "Callback is triggered when the voltage is *inside* the min and max values"
|
312
|
+
# "'<'", "Callback is triggered when the voltage is smaller than the min value (max is ignored)"
|
313
|
+
# "'>'", "Callback is triggered when the voltage is greater than the min value (max is ignored)"
|
314
|
+
#
|
315
|
+
# The default value is ('x', 0, 0).
|
316
|
+
def set_voltage_callback_threshold(option, min, max)
|
317
|
+
send_request(FUNCTION_SET_VOLTAGE_CALLBACK_THRESHOLD, [option, min, max], 'k l l', 0, '')
|
318
|
+
end
|
319
|
+
|
320
|
+
# Returns the threshold as set by BrickletVoltageCurrent#set_voltage_callback_threshold.
|
321
|
+
def get_voltage_callback_threshold
|
322
|
+
send_request(FUNCTION_GET_VOLTAGE_CALLBACK_THRESHOLD, [], '', 9, 'k l l')
|
323
|
+
end
|
324
|
+
|
325
|
+
# Sets the thresholds for the CALLBACK_POWER_REACHED callback.
|
326
|
+
#
|
327
|
+
# The following options are possible:
|
328
|
+
#
|
329
|
+
# "Option", "Description"
|
330
|
+
#
|
331
|
+
# "'x'", "Callback is turned off"
|
332
|
+
# "'o'", "Callback is triggered when the power is *outside* the min and max values"
|
333
|
+
# "'i'", "Callback is triggered when the power is *inside* the min and max values"
|
334
|
+
# "'<'", "Callback is triggered when the power is smaller than the min value (max is ignored)"
|
335
|
+
# "'>'", "Callback is triggered when the power is greater than the min value (max is ignored)"
|
336
|
+
#
|
337
|
+
# The default value is ('x', 0, 0).
|
338
|
+
def set_power_callback_threshold(option, min, max)
|
339
|
+
send_request(FUNCTION_SET_POWER_CALLBACK_THRESHOLD, [option, min, max], 'k l l', 0, '')
|
340
|
+
end
|
341
|
+
|
342
|
+
# Returns the threshold as set by BrickletVoltageCurrent#set_power_callback_threshold.
|
343
|
+
def get_power_callback_threshold
|
344
|
+
send_request(FUNCTION_GET_POWER_CALLBACK_THRESHOLD, [], '', 9, 'k l l')
|
345
|
+
end
|
346
|
+
|
347
|
+
# Sets the period in ms with which the threshold callbacks
|
348
|
+
#
|
349
|
+
# CALLBACK_CURRENT_REACHED, CALLBACK_VOLTAGE_REACHED, CALLBACK_POWER_REACHED
|
350
|
+
#
|
351
|
+
# are triggered, if the thresholds
|
352
|
+
#
|
353
|
+
# BrickletVoltageCurrent#set_current_callback_threshold, BrickletVoltageCurrent#set_voltage_callback_threshold, BrickletVoltageCurrent#set_power_callback_threshold
|
354
|
+
#
|
355
|
+
# keep being reached.
|
356
|
+
#
|
357
|
+
# The default value is 100.
|
358
|
+
def set_debounce_period(debounce)
|
359
|
+
send_request(FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 0, '')
|
360
|
+
end
|
361
|
+
|
362
|
+
# Returns the debounce period as set by BrickletVoltageCurrent#set_debounce_period.
|
363
|
+
def get_debounce_period
|
364
|
+
send_request(FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 4, 'L')
|
365
|
+
end
|
366
|
+
|
367
|
+
# Returns the UID, the UID where the Bricklet is connected to,
|
368
|
+
# the position, the hardware and firmware version as well as the
|
369
|
+
# device identifier.
|
370
|
+
#
|
371
|
+
# The position can be 'a', 'b', 'c' or 'd'.
|
372
|
+
#
|
373
|
+
# The device identifiers can be found :ref:`here <device_identifier>`.
|
374
|
+
#
|
375
|
+
# .. versionadded:: 2.0.0~(Plugin)
|
376
|
+
def get_identity
|
377
|
+
send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S')
|
378
|
+
end
|
379
|
+
|
380
|
+
# Registers a callback with ID <tt>id</tt> to the block <tt>block</tt>.
|
381
|
+
def register_callback(id, &block)
|
382
|
+
callback = block
|
383
|
+
@registered_callbacks[id] = callback
|
384
|
+
end
|
385
|
+
end
|
386
|
+
end
|