tinkerforge 2.1.22 → 2.1.27
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.
- checksums.yaml +5 -5
- data/lib/tinkerforge/brick_dc.rb +157 -76
- data/lib/tinkerforge/brick_hat.rb +115 -32
- data/lib/tinkerforge/brick_hat_zero.rb +119 -21
- data/lib/tinkerforge/brick_imu.rb +192 -87
- data/lib/tinkerforge/brick_imu_v2.rb +220 -119
- data/lib/tinkerforge/brick_master.rb +498 -198
- data/lib/tinkerforge/brick_red.rb +197 -74
- data/lib/tinkerforge/brick_servo.rb +187 -103
- data/lib/tinkerforge/brick_silent_stepper.rb +249 -169
- data/lib/tinkerforge/brick_stepper.rb +214 -102
- data/lib/tinkerforge/bricklet_accelerometer.rb +61 -36
- data/lib/tinkerforge/bricklet_accelerometer_v2.rb +167 -48
- data/lib/tinkerforge/bricklet_air_quality.rb +123 -76
- data/lib/tinkerforge/bricklet_ambient_light.rb +62 -46
- data/lib/tinkerforge/bricklet_ambient_light_v2.rb +41 -28
- data/lib/tinkerforge/bricklet_ambient_light_v3.rb +61 -28
- data/lib/tinkerforge/bricklet_analog_in.rb +66 -45
- data/lib/tinkerforge/bricklet_analog_in_v2.rb +60 -43
- data/lib/tinkerforge/bricklet_analog_in_v3.rb +68 -32
- data/lib/tinkerforge/bricklet_analog_out.rb +25 -16
- data/lib/tinkerforge/bricklet_analog_out_v2.rb +21 -10
- data/lib/tinkerforge/bricklet_analog_out_v3.rb +55 -22
- data/lib/tinkerforge/bricklet_barometer.rb +108 -58
- data/lib/tinkerforge/bricklet_barometer_v2.rb +109 -67
- data/lib/tinkerforge/bricklet_can.rb +84 -24
- data/lib/tinkerforge/bricklet_can_v2.rb +173 -72
- data/lib/tinkerforge/bricklet_co2.rb +36 -25
- data/lib/tinkerforge/bricklet_co2_v2.rb +119 -60
- data/lib/tinkerforge/bricklet_color.rb +77 -49
- data/lib/tinkerforge/bricklet_color_v2.rb +493 -0
- data/lib/tinkerforge/bricklet_compass.rb +397 -0
- data/lib/tinkerforge/bricklet_current12.rb +61 -40
- data/lib/tinkerforge/bricklet_current25.rb +61 -40
- data/lib/tinkerforge/bricklet_distance_ir.rb +60 -38
- data/lib/tinkerforge/bricklet_distance_ir_v2.rb +85 -45
- data/lib/tinkerforge/bricklet_distance_us.rb +43 -30
- data/lib/tinkerforge/bricklet_distance_us_v2.rb +335 -0
- data/lib/tinkerforge/bricklet_dmx.rb +92 -48
- data/lib/tinkerforge/bricklet_dual_button.rb +23 -12
- data/lib/tinkerforge/bricklet_dual_button_v2.rb +64 -29
- data/lib/tinkerforge/bricklet_dual_relay.rb +27 -14
- data/lib/tinkerforge/bricklet_dust_detector.rb +43 -30
- data/lib/tinkerforge/bricklet_e_paper_296x128.rb +115 -63
- data/lib/tinkerforge/bricklet_energy_monitor.rb +416 -0
- data/lib/tinkerforge/bricklet_gps.rb +72 -48
- data/lib/tinkerforge/bricklet_gps_v2.rb +124 -73
- data/lib/tinkerforge/bricklet_hall_effect.rb +43 -28
- data/lib/tinkerforge/bricklet_hall_effect_v2.rb +76 -44
- data/lib/tinkerforge/bricklet_humidity.rb +54 -38
- data/lib/tinkerforge/bricklet_humidity_v2.rb +86 -49
- data/lib/tinkerforge/bricklet_imu_v3.rb +784 -0
- data/lib/tinkerforge/bricklet_industrial_analog_out.rb +41 -18
- data/lib/tinkerforge/bricklet_industrial_analog_out_v2.rb +84 -40
- data/lib/tinkerforge/bricklet_industrial_counter.rb +102 -59
- data/lib/tinkerforge/bricklet_industrial_digital_in_4.rb +51 -24
- data/lib/tinkerforge/bricklet_industrial_digital_in_4_v2.rb +79 -40
- data/lib/tinkerforge/bricklet_industrial_digital_out_4.rb +36 -15
- data/lib/tinkerforge/bricklet_industrial_digital_out_4_v2.rb +75 -33
- data/lib/tinkerforge/bricklet_industrial_dual_0_20ma.rb +43 -29
- data/lib/tinkerforge/bricklet_industrial_dual_0_20ma_v2.rb +81 -44
- data/lib/tinkerforge/bricklet_industrial_dual_ac_relay.rb +325 -0
- data/lib/tinkerforge/bricklet_industrial_dual_analog_in.rb +51 -30
- data/lib/tinkerforge/bricklet_industrial_dual_analog_in_v2.rb +139 -40
- data/lib/tinkerforge/bricklet_industrial_dual_relay.rb +63 -28
- data/lib/tinkerforge/bricklet_industrial_quad_relay.rb +36 -15
- data/lib/tinkerforge/bricklet_industrial_quad_relay_v2.rb +67 -28
- data/lib/tinkerforge/bricklet_io16.rb +57 -32
- data/lib/tinkerforge/bricklet_io16_v2.rb +93 -48
- data/lib/tinkerforge/bricklet_io4.rb +56 -31
- data/lib/tinkerforge/bricklet_io4_v2.rb +109 -57
- data/lib/tinkerforge/bricklet_isolator.rb +111 -35
- data/lib/tinkerforge/bricklet_joystick.rb +63 -42
- data/lib/tinkerforge/bricklet_joystick_v2.rb +71 -35
- data/lib/tinkerforge/bricklet_laser_range_finder.rb +87 -59
- data/lib/tinkerforge/bricklet_laser_range_finder_v2.rb +101 -53
- data/lib/tinkerforge/bricklet_lcd_128x64.rb +241 -131
- data/lib/tinkerforge/bricklet_lcd_16x2.rb +49 -25
- data/lib/tinkerforge/bricklet_lcd_20x4.rb +59 -29
- data/lib/tinkerforge/bricklet_led_strip.rb +69 -47
- data/lib/tinkerforge/bricklet_led_strip_v2.rb +105 -48
- data/lib/tinkerforge/bricklet_line.rb +35 -22
- data/lib/tinkerforge/bricklet_linear_poti.rb +53 -35
- data/lib/tinkerforge/bricklet_linear_poti_v2.rb +55 -24
- data/lib/tinkerforge/bricklet_load_cell.rb +64 -40
- data/lib/tinkerforge/bricklet_load_cell_v2.rb +81 -41
- data/lib/tinkerforge/bricklet_moisture.rb +43 -30
- data/lib/tinkerforge/bricklet_motion_detector.rb +21 -10
- data/lib/tinkerforge/bricklet_motion_detector_v2.rb +62 -29
- data/lib/tinkerforge/bricklet_motorized_linear_poti.rb +71 -32
- data/lib/tinkerforge/bricklet_multi_touch.rb +30 -17
- data/lib/tinkerforge/bricklet_multi_touch_v2.rb +371 -0
- data/lib/tinkerforge/bricklet_nfc.rb +130 -80
- data/lib/tinkerforge/bricklet_nfc_rfid.rb +32 -13
- data/lib/tinkerforge/bricklet_oled_128x64.rb +30 -17
- data/lib/tinkerforge/bricklet_oled_128x64_v2.rb +97 -40
- data/lib/tinkerforge/bricklet_oled_64x48.rb +30 -17
- data/lib/tinkerforge/bricklet_one_wire.rb +65 -24
- data/lib/tinkerforge/bricklet_outdoor_weather.rb +84 -41
- data/lib/tinkerforge/bricklet_particulate_matter.rb +85 -37
- data/lib/tinkerforge/bricklet_piezo_buzzer.rb +19 -13
- data/lib/tinkerforge/bricklet_piezo_speaker.rb +22 -19
- data/lib/tinkerforge/bricklet_piezo_speaker_v2.rb +84 -57
- data/lib/tinkerforge/bricklet_ptc.rb +76 -51
- data/lib/tinkerforge/bricklet_ptc_v2.rb +96 -54
- data/lib/tinkerforge/bricklet_real_time_clock.rb +45 -36
- data/lib/tinkerforge/bricklet_real_time_clock_v2.rb +78 -47
- data/lib/tinkerforge/bricklet_remote_switch.rb +38 -29
- data/lib/tinkerforge/bricklet_remote_switch_v2.rb +86 -49
- data/lib/tinkerforge/bricklet_rgb_led.rb +17 -8
- data/lib/tinkerforge/bricklet_rgb_led_button.rb +61 -30
- data/lib/tinkerforge/bricklet_rgb_led_matrix.rb +78 -33
- data/lib/tinkerforge/bricklet_rgb_led_v2.rb +51 -20
- data/lib/tinkerforge/bricklet_rotary_encoder.rb +40 -25
- data/lib/tinkerforge/bricklet_rotary_encoder_v2.rb +60 -27
- data/lib/tinkerforge/bricklet_rotary_poti.rb +55 -37
- data/lib/tinkerforge/bricklet_rotary_poti_v2.rb +290 -0
- data/lib/tinkerforge/bricklet_rs232.rb +89 -28
- data/lib/tinkerforge/bricklet_rs232_v2.rb +121 -47
- data/lib/tinkerforge/bricklet_rs485.rb +303 -207
- data/lib/tinkerforge/bricklet_segment_display_4x7.rb +24 -14
- data/lib/tinkerforge/bricklet_segment_display_4x7_v2.rb +75 -36
- data/lib/tinkerforge/bricklet_solid_state_relay.rb +24 -13
- data/lib/tinkerforge/bricklet_solid_state_relay_v2.rb +58 -25
- data/lib/tinkerforge/bricklet_sound_intensity.rb +36 -24
- data/lib/tinkerforge/bricklet_sound_pressure_level.rb +77 -41
- data/lib/tinkerforge/bricklet_temperature.rb +43 -28
- data/lib/tinkerforge/bricklet_temperature_ir.rb +63 -47
- data/lib/tinkerforge/bricklet_temperature_ir_v2.rb +75 -53
- data/lib/tinkerforge/bricklet_temperature_v2.rb +62 -31
- data/lib/tinkerforge/bricklet_thermal_imaging.rb +118 -68
- data/lib/tinkerforge/bricklet_thermocouple.rb +46 -30
- data/lib/tinkerforge/bricklet_thermocouple_v2.rb +65 -30
- data/lib/tinkerforge/bricklet_tilt.rb +23 -10
- data/lib/tinkerforge/bricklet_uv_light.rb +37 -24
- data/lib/tinkerforge/bricklet_uv_light_v2.rb +87 -46
- data/lib/tinkerforge/bricklet_voltage.rb +54 -37
- data/lib/tinkerforge/bricklet_voltage_current.rb +94 -85
- data/lib/tinkerforge/bricklet_voltage_current_v2.rb +103 -77
- data/lib/tinkerforge/bricklet_xmc1400_breakout.rb +410 -0
- data/lib/tinkerforge/device_display_names.rb +165 -0
- data/lib/tinkerforge/ip_connection.rb +155 -33
- data/lib/tinkerforge/version.rb +1 -1
- metadata +14 -4
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
# -*- ruby encoding: utf-8 -*-
|
|
2
2
|
#############################################################
|
|
3
|
-
# This file was automatically generated on
|
|
3
|
+
# This file was automatically generated on 2020-11-02. #
|
|
4
4
|
# #
|
|
5
|
-
# Ruby Bindings Version 2.1.
|
|
5
|
+
# Ruby Bindings Version 2.1.27 #
|
|
6
6
|
# #
|
|
7
7
|
# If you have a bugfix for this file and want to commit it, #
|
|
8
8
|
# please fix the bug in the generator. You can find a link #
|
|
9
9
|
# to the generators git repository on tinkerforge.com #
|
|
10
10
|
#############################################################
|
|
11
11
|
|
|
12
|
+
require_relative './ip_connection'
|
|
13
|
+
|
|
12
14
|
module Tinkerforge
|
|
13
15
|
# Measures distance between 2cm and 400cm with ultrasound
|
|
14
16
|
class BrickletDistanceUS < Device
|
|
@@ -51,7 +53,7 @@ module Tinkerforge
|
|
|
51
53
|
# Creates an object with the unique device ID <tt>uid</tt> and adds it to
|
|
52
54
|
# the IP Connection <tt>ipcon</tt>.
|
|
53
55
|
def initialize(uid, ipcon)
|
|
54
|
-
super uid, ipcon
|
|
56
|
+
super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME
|
|
55
57
|
|
|
56
58
|
@api_version = [2, 0, 1]
|
|
57
59
|
|
|
@@ -66,13 +68,14 @@ module Tinkerforge
|
|
|
66
68
|
@response_expected[FUNCTION_GET_MOVING_AVERAGE] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
|
67
69
|
@response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
|
68
70
|
|
|
69
|
-
@callback_formats[CALLBACK_DISTANCE] = 'S'
|
|
70
|
-
@callback_formats[CALLBACK_DISTANCE_REACHED] = 'S'
|
|
71
|
+
@callback_formats[CALLBACK_DISTANCE] = [10, 'S']
|
|
72
|
+
@callback_formats[CALLBACK_DISTANCE_REACHED] = [10, 'S']
|
|
71
73
|
|
|
74
|
+
@ipcon.add_device self
|
|
72
75
|
end
|
|
73
76
|
|
|
74
|
-
# Returns the current distance value measured by the sensor.
|
|
75
|
-
#
|
|
77
|
+
# Returns the current distance value measured by the sensor.
|
|
78
|
+
# A small value corresponds to a small distance, a big
|
|
76
79
|
# value corresponds to a big distance. The relation between the measured distance
|
|
77
80
|
# value and the actual distance is affected by the 5V supply voltage (deviations
|
|
78
81
|
# in the supply voltage result in deviations in the distance values) and is
|
|
@@ -82,23 +85,27 @@ module Tinkerforge
|
|
|
82
85
|
# use the CALLBACK_DISTANCE callback and set the period with
|
|
83
86
|
# BrickletDistanceUS#set_distance_callback_period.
|
|
84
87
|
def get_distance_value
|
|
85
|
-
|
|
88
|
+
check_validity
|
|
89
|
+
|
|
90
|
+
send_request FUNCTION_GET_DISTANCE_VALUE, [], '', 10, 'S'
|
|
86
91
|
end
|
|
87
92
|
|
|
88
|
-
# Sets the period
|
|
93
|
+
# Sets the period with which the CALLBACK_DISTANCE callback is triggered
|
|
89
94
|
# periodically. A value of 0 turns the callback off.
|
|
90
95
|
#
|
|
91
96
|
# Der CALLBACK_DISTANCE callback is only triggered if the distance value has changed
|
|
92
97
|
# since the last triggering.
|
|
93
|
-
#
|
|
94
|
-
# The default value is 0.
|
|
95
98
|
def set_distance_callback_period(period)
|
|
96
|
-
|
|
99
|
+
check_validity
|
|
100
|
+
|
|
101
|
+
send_request FUNCTION_SET_DISTANCE_CALLBACK_PERIOD, [period], 'L', 8, ''
|
|
97
102
|
end
|
|
98
103
|
|
|
99
104
|
# Returns the period as set by BrickletDistanceUS#set_distance_callback_period.
|
|
100
105
|
def get_distance_callback_period
|
|
101
|
-
|
|
106
|
+
check_validity
|
|
107
|
+
|
|
108
|
+
send_request FUNCTION_GET_DISTANCE_CALLBACK_PERIOD, [], '', 12, 'L'
|
|
102
109
|
end
|
|
103
110
|
|
|
104
111
|
# Sets the thresholds for the CALLBACK_DISTANCE_REACHED callback.
|
|
@@ -112,18 +119,20 @@ module Tinkerforge
|
|
|
112
119
|
# "'i'", "Callback is triggered when the distance value is *inside* the min and max values"
|
|
113
120
|
# "'<'", "Callback is triggered when the distance value is smaller than the min value (max is ignored)"
|
|
114
121
|
# "'>'", "Callback is triggered when the distance value is greater than the min value (max is ignored)"
|
|
115
|
-
#
|
|
116
|
-
# The default value is ('x', 0, 0).
|
|
117
122
|
def set_distance_callback_threshold(option, min, max)
|
|
118
|
-
|
|
123
|
+
check_validity
|
|
124
|
+
|
|
125
|
+
send_request FUNCTION_SET_DISTANCE_CALLBACK_THRESHOLD, [option, min, max], 'k S S', 8, ''
|
|
119
126
|
end
|
|
120
127
|
|
|
121
128
|
# Returns the threshold as set by BrickletDistanceUS#set_distance_callback_threshold.
|
|
122
129
|
def get_distance_callback_threshold
|
|
123
|
-
|
|
130
|
+
check_validity
|
|
131
|
+
|
|
132
|
+
send_request FUNCTION_GET_DISTANCE_CALLBACK_THRESHOLD, [], '', 13, 'k S S'
|
|
124
133
|
end
|
|
125
134
|
|
|
126
|
-
# Sets the period
|
|
135
|
+
# Sets the period with which the threshold callbacks
|
|
127
136
|
#
|
|
128
137
|
# * CALLBACK_DISTANCE_REACHED,
|
|
129
138
|
#
|
|
@@ -132,15 +141,17 @@ module Tinkerforge
|
|
|
132
141
|
# * BrickletDistanceUS#set_distance_callback_threshold,
|
|
133
142
|
#
|
|
134
143
|
# keep being reached.
|
|
135
|
-
#
|
|
136
|
-
# The default value is 100.
|
|
137
144
|
def set_debounce_period(debounce)
|
|
138
|
-
|
|
145
|
+
check_validity
|
|
146
|
+
|
|
147
|
+
send_request FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 8, ''
|
|
139
148
|
end
|
|
140
149
|
|
|
141
150
|
# Returns the debounce period as set by BrickletDistanceUS#set_debounce_period.
|
|
142
151
|
def get_debounce_period
|
|
143
|
-
|
|
152
|
+
check_validity
|
|
153
|
+
|
|
154
|
+
send_request FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 12, 'L'
|
|
144
155
|
end
|
|
145
156
|
|
|
146
157
|
# Sets the length of a `moving averaging <https://en.wikipedia.org/wiki/Moving_average>`__
|
|
@@ -148,29 +159,31 @@ module Tinkerforge
|
|
|
148
159
|
#
|
|
149
160
|
# Setting the length to 0 will turn the averaging completely off. With less
|
|
150
161
|
# averaging, there is more noise on the data.
|
|
151
|
-
#
|
|
152
|
-
# The range for the averaging is 0-100.
|
|
153
|
-
#
|
|
154
|
-
# The default value is 20.
|
|
155
162
|
def set_moving_average(average)
|
|
156
|
-
|
|
163
|
+
check_validity
|
|
164
|
+
|
|
165
|
+
send_request FUNCTION_SET_MOVING_AVERAGE, [average], 'C', 8, ''
|
|
157
166
|
end
|
|
158
167
|
|
|
159
168
|
# Returns the length moving average as set by BrickletDistanceUS#set_moving_average.
|
|
160
169
|
def get_moving_average
|
|
161
|
-
|
|
170
|
+
check_validity
|
|
171
|
+
|
|
172
|
+
send_request FUNCTION_GET_MOVING_AVERAGE, [], '', 9, 'C'
|
|
162
173
|
end
|
|
163
174
|
|
|
164
175
|
# Returns the UID, the UID where the Bricklet is connected to,
|
|
165
176
|
# the position, the hardware and firmware version as well as the
|
|
166
177
|
# device identifier.
|
|
167
178
|
#
|
|
168
|
-
# The position can be 'a', 'b', 'c' or '
|
|
179
|
+
# The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
|
|
180
|
+
# A Bricklet connected to an :ref:`Isolator Bricklet <isolator_bricklet>` is always at
|
|
181
|
+
# position 'z'.
|
|
169
182
|
#
|
|
170
183
|
# The device identifier numbers can be found :ref:`here <device_identifier>`.
|
|
171
184
|
# |device_identifier_constant|
|
|
172
185
|
def get_identity
|
|
173
|
-
send_request FUNCTION_GET_IDENTITY, [], '',
|
|
186
|
+
send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S'
|
|
174
187
|
end
|
|
175
188
|
|
|
176
189
|
# Registers a callback with ID <tt>id</tt> to the block <tt>block</tt>.
|
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
# -*- ruby encoding: utf-8 -*-
|
|
2
|
+
#############################################################
|
|
3
|
+
# This file was automatically generated on 2020-11-02. #
|
|
4
|
+
# #
|
|
5
|
+
# Ruby Bindings Version 2.1.27 #
|
|
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 generators git repository on tinkerforge.com #
|
|
10
|
+
#############################################################
|
|
11
|
+
|
|
12
|
+
require_relative './ip_connection'
|
|
13
|
+
|
|
14
|
+
module Tinkerforge
|
|
15
|
+
# Measures distance between 30cm and 500cm with ultrasound
|
|
16
|
+
class BrickletDistanceUSV2 < Device
|
|
17
|
+
DEVICE_IDENTIFIER = 299 # :nodoc:
|
|
18
|
+
DEVICE_DISPLAY_NAME = 'Distance US Bricklet 2.0' # :nodoc:
|
|
19
|
+
|
|
20
|
+
# This callback is triggered periodically according to the configuration set by
|
|
21
|
+
# BrickletDistanceUSV2#set_distance_callback_configuration.
|
|
22
|
+
#
|
|
23
|
+
# The parameter is the same as BrickletDistanceUSV2#get_distance.
|
|
24
|
+
CALLBACK_DISTANCE = 4
|
|
25
|
+
|
|
26
|
+
FUNCTION_GET_DISTANCE = 1 # :nodoc:
|
|
27
|
+
FUNCTION_SET_DISTANCE_CALLBACK_CONFIGURATION = 2 # :nodoc:
|
|
28
|
+
FUNCTION_GET_DISTANCE_CALLBACK_CONFIGURATION = 3 # :nodoc:
|
|
29
|
+
FUNCTION_SET_UPDATE_RATE = 5 # :nodoc:
|
|
30
|
+
FUNCTION_GET_UPDATE_RATE = 6 # :nodoc:
|
|
31
|
+
FUNCTION_SET_DISTANCE_LED_CONFIG = 7 # :nodoc:
|
|
32
|
+
FUNCTION_GET_DISTANCE_LED_CONFIG = 8 # :nodoc:
|
|
33
|
+
FUNCTION_GET_SPITFP_ERROR_COUNT = 234 # :nodoc:
|
|
34
|
+
FUNCTION_SET_BOOTLOADER_MODE = 235 # :nodoc:
|
|
35
|
+
FUNCTION_GET_BOOTLOADER_MODE = 236 # :nodoc:
|
|
36
|
+
FUNCTION_SET_WRITE_FIRMWARE_POINTER = 237 # :nodoc:
|
|
37
|
+
FUNCTION_WRITE_FIRMWARE = 238 # :nodoc:
|
|
38
|
+
FUNCTION_SET_STATUS_LED_CONFIG = 239 # :nodoc:
|
|
39
|
+
FUNCTION_GET_STATUS_LED_CONFIG = 240 # :nodoc:
|
|
40
|
+
FUNCTION_GET_CHIP_TEMPERATURE = 242 # :nodoc:
|
|
41
|
+
FUNCTION_RESET = 243 # :nodoc:
|
|
42
|
+
FUNCTION_WRITE_UID = 248 # :nodoc:
|
|
43
|
+
FUNCTION_READ_UID = 249 # :nodoc:
|
|
44
|
+
FUNCTION_GET_IDENTITY = 255 # :nodoc:
|
|
45
|
+
|
|
46
|
+
THRESHOLD_OPTION_OFF = 'x' # :nodoc:
|
|
47
|
+
THRESHOLD_OPTION_OUTSIDE = 'o' # :nodoc:
|
|
48
|
+
THRESHOLD_OPTION_INSIDE = 'i' # :nodoc:
|
|
49
|
+
THRESHOLD_OPTION_SMALLER = '<' # :nodoc:
|
|
50
|
+
THRESHOLD_OPTION_GREATER = '>' # :nodoc:
|
|
51
|
+
UPDATE_RATE_2_HZ = 0 # :nodoc:
|
|
52
|
+
UPDATE_RATE_10_HZ = 1 # :nodoc:
|
|
53
|
+
DISTANCE_LED_CONFIG_OFF = 0 # :nodoc:
|
|
54
|
+
DISTANCE_LED_CONFIG_ON = 1 # :nodoc:
|
|
55
|
+
DISTANCE_LED_CONFIG_SHOW_HEARTBEAT = 2 # :nodoc:
|
|
56
|
+
DISTANCE_LED_CONFIG_SHOW_DISTANCE = 3 # :nodoc:
|
|
57
|
+
BOOTLOADER_MODE_BOOTLOADER = 0 # :nodoc:
|
|
58
|
+
BOOTLOADER_MODE_FIRMWARE = 1 # :nodoc:
|
|
59
|
+
BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT = 2 # :nodoc:
|
|
60
|
+
BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT = 3 # :nodoc:
|
|
61
|
+
BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT = 4 # :nodoc:
|
|
62
|
+
BOOTLOADER_STATUS_OK = 0 # :nodoc:
|
|
63
|
+
BOOTLOADER_STATUS_INVALID_MODE = 1 # :nodoc:
|
|
64
|
+
BOOTLOADER_STATUS_NO_CHANGE = 2 # :nodoc:
|
|
65
|
+
BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT = 3 # :nodoc:
|
|
66
|
+
BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT = 4 # :nodoc:
|
|
67
|
+
BOOTLOADER_STATUS_CRC_MISMATCH = 5 # :nodoc:
|
|
68
|
+
STATUS_LED_CONFIG_OFF = 0 # :nodoc:
|
|
69
|
+
STATUS_LED_CONFIG_ON = 1 # :nodoc:
|
|
70
|
+
STATUS_LED_CONFIG_SHOW_HEARTBEAT = 2 # :nodoc:
|
|
71
|
+
STATUS_LED_CONFIG_SHOW_STATUS = 3 # :nodoc:
|
|
72
|
+
|
|
73
|
+
# Creates an object with the unique device ID <tt>uid</tt> and adds it to
|
|
74
|
+
# the IP Connection <tt>ipcon</tt>.
|
|
75
|
+
def initialize(uid, ipcon)
|
|
76
|
+
super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME
|
|
77
|
+
|
|
78
|
+
@api_version = [2, 0, 0]
|
|
79
|
+
|
|
80
|
+
@response_expected[FUNCTION_GET_DISTANCE] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
|
81
|
+
@response_expected[FUNCTION_SET_DISTANCE_CALLBACK_CONFIGURATION] = RESPONSE_EXPECTED_TRUE
|
|
82
|
+
@response_expected[FUNCTION_GET_DISTANCE_CALLBACK_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
|
83
|
+
@response_expected[FUNCTION_SET_UPDATE_RATE] = RESPONSE_EXPECTED_FALSE
|
|
84
|
+
@response_expected[FUNCTION_GET_UPDATE_RATE] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
|
85
|
+
@response_expected[FUNCTION_SET_DISTANCE_LED_CONFIG] = RESPONSE_EXPECTED_FALSE
|
|
86
|
+
@response_expected[FUNCTION_GET_DISTANCE_LED_CONFIG] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
|
87
|
+
@response_expected[FUNCTION_GET_SPITFP_ERROR_COUNT] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
|
88
|
+
@response_expected[FUNCTION_SET_BOOTLOADER_MODE] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
|
89
|
+
@response_expected[FUNCTION_GET_BOOTLOADER_MODE] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
|
90
|
+
@response_expected[FUNCTION_SET_WRITE_FIRMWARE_POINTER] = RESPONSE_EXPECTED_FALSE
|
|
91
|
+
@response_expected[FUNCTION_WRITE_FIRMWARE] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
|
92
|
+
@response_expected[FUNCTION_SET_STATUS_LED_CONFIG] = RESPONSE_EXPECTED_FALSE
|
|
93
|
+
@response_expected[FUNCTION_GET_STATUS_LED_CONFIG] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
|
94
|
+
@response_expected[FUNCTION_GET_CHIP_TEMPERATURE] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
|
95
|
+
@response_expected[FUNCTION_RESET] = RESPONSE_EXPECTED_FALSE
|
|
96
|
+
@response_expected[FUNCTION_WRITE_UID] = RESPONSE_EXPECTED_FALSE
|
|
97
|
+
@response_expected[FUNCTION_READ_UID] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
|
98
|
+
@response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
|
99
|
+
|
|
100
|
+
@callback_formats[CALLBACK_DISTANCE] = [10, 'S']
|
|
101
|
+
|
|
102
|
+
@ipcon.add_device self
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# Returns the distance.
|
|
106
|
+
#
|
|
107
|
+
#
|
|
108
|
+
# If you want to get the value periodically, it is recommended to use the
|
|
109
|
+
# CALLBACK_DISTANCE callback. You can set the callback configuration
|
|
110
|
+
# with BrickletDistanceUSV2#set_distance_callback_configuration.
|
|
111
|
+
def get_distance
|
|
112
|
+
check_validity
|
|
113
|
+
|
|
114
|
+
send_request FUNCTION_GET_DISTANCE, [], '', 10, 'S'
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# The period is the period with which the CALLBACK_DISTANCE callback is triggered
|
|
118
|
+
# periodically. A value of 0 turns the callback off.
|
|
119
|
+
#
|
|
120
|
+
# If the `value has to change`-parameter is set to true, the callback is only
|
|
121
|
+
# triggered after the value has changed. If the value didn't change
|
|
122
|
+
# within the period, the callback is triggered immediately on change.
|
|
123
|
+
#
|
|
124
|
+
# If it is set to false, the callback is continuously triggered with the period,
|
|
125
|
+
# independent of the value.
|
|
126
|
+
#
|
|
127
|
+
# It is furthermore possible to constrain the callback with thresholds.
|
|
128
|
+
#
|
|
129
|
+
# The `option`-parameter together with min/max sets a threshold for the CALLBACK_DISTANCE callback.
|
|
130
|
+
#
|
|
131
|
+
# The following options are possible:
|
|
132
|
+
#
|
|
133
|
+
# "Option", "Description"
|
|
134
|
+
#
|
|
135
|
+
# "'x'", "Threshold is turned off"
|
|
136
|
+
# "'o'", "Threshold is triggered when the value is *outside* the min and max values"
|
|
137
|
+
# "'i'", "Threshold is triggered when the value is *inside* or equal to the min and max values"
|
|
138
|
+
# "'<'", "Threshold is triggered when the value is smaller than the min value (max is ignored)"
|
|
139
|
+
# "'>'", "Threshold is triggered when the value is greater than the min value (max is ignored)"
|
|
140
|
+
#
|
|
141
|
+
# If the option is set to 'x' (threshold turned off) the callback is triggered with the fixed period.
|
|
142
|
+
def set_distance_callback_configuration(period, value_has_to_change, option, min, max)
|
|
143
|
+
check_validity
|
|
144
|
+
|
|
145
|
+
send_request FUNCTION_SET_DISTANCE_CALLBACK_CONFIGURATION, [period, value_has_to_change, option, min, max], 'L ? k S S', 8, ''
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
# Returns the callback configuration as set by BrickletDistanceUSV2#set_distance_callback_configuration.
|
|
149
|
+
def get_distance_callback_configuration
|
|
150
|
+
check_validity
|
|
151
|
+
|
|
152
|
+
send_request FUNCTION_GET_DISTANCE_CALLBACK_CONFIGURATION, [], '', 18, 'L ? k S S'
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
# Sets the update rate to 2 Hz or 10 Hz.
|
|
156
|
+
#
|
|
157
|
+
# With 2 Hz update rate the noise is about ±1mm, while with 10 Hz update rate the noise
|
|
158
|
+
# increases to about ±5mm.
|
|
159
|
+
def set_update_rate(update_rate)
|
|
160
|
+
check_validity
|
|
161
|
+
|
|
162
|
+
send_request FUNCTION_SET_UPDATE_RATE, [update_rate], 'C', 8, ''
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
# Returns the update rate as set by BrickletDistanceUSV2#set_update_rate.
|
|
166
|
+
def get_update_rate
|
|
167
|
+
check_validity
|
|
168
|
+
|
|
169
|
+
send_request FUNCTION_GET_UPDATE_RATE, [], '', 9, 'C'
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
# Configures the distance LED to be either turned off, turned on, blink in
|
|
173
|
+
# heartbeat mode or show the distance (brighter = object is nearer).
|
|
174
|
+
def set_distance_led_config(config)
|
|
175
|
+
check_validity
|
|
176
|
+
|
|
177
|
+
send_request FUNCTION_SET_DISTANCE_LED_CONFIG, [config], 'C', 8, ''
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
# Returns the LED configuration as set by BrickletDistanceUSV2#set_distance_led_config
|
|
181
|
+
def get_distance_led_config
|
|
182
|
+
check_validity
|
|
183
|
+
|
|
184
|
+
send_request FUNCTION_GET_DISTANCE_LED_CONFIG, [], '', 9, 'C'
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
# Returns the error count for the communication between Brick and Bricklet.
|
|
188
|
+
#
|
|
189
|
+
# The errors are divided into
|
|
190
|
+
#
|
|
191
|
+
# * ACK checksum errors,
|
|
192
|
+
# * message checksum errors,
|
|
193
|
+
# * framing errors and
|
|
194
|
+
# * overflow errors.
|
|
195
|
+
#
|
|
196
|
+
# The errors counts are for errors that occur on the Bricklet side. All
|
|
197
|
+
# Bricks have a similar function that returns the errors on the Brick side.
|
|
198
|
+
def get_spitfp_error_count
|
|
199
|
+
check_validity
|
|
200
|
+
|
|
201
|
+
send_request FUNCTION_GET_SPITFP_ERROR_COUNT, [], '', 24, 'L L L L'
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
# Sets the bootloader mode and returns the status after the requested
|
|
205
|
+
# mode change was instigated.
|
|
206
|
+
#
|
|
207
|
+
# You can change from bootloader mode to firmware mode and vice versa. A change
|
|
208
|
+
# from bootloader mode to firmware mode will only take place if the entry function,
|
|
209
|
+
# device identifier and CRC are present and correct.
|
|
210
|
+
#
|
|
211
|
+
# This function is used by Brick Viewer during flashing. It should not be
|
|
212
|
+
# necessary to call it in a normal user program.
|
|
213
|
+
def set_bootloader_mode(mode)
|
|
214
|
+
check_validity
|
|
215
|
+
|
|
216
|
+
send_request FUNCTION_SET_BOOTLOADER_MODE, [mode], 'C', 9, 'C'
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
# Returns the current bootloader mode, see BrickletDistanceUSV2#set_bootloader_mode.
|
|
220
|
+
def get_bootloader_mode
|
|
221
|
+
check_validity
|
|
222
|
+
|
|
223
|
+
send_request FUNCTION_GET_BOOTLOADER_MODE, [], '', 9, 'C'
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
# Sets the firmware pointer for BrickletDistanceUSV2#write_firmware. The pointer has
|
|
227
|
+
# to be increased by chunks of size 64. The data is written to flash
|
|
228
|
+
# every 4 chunks (which equals to one page of size 256).
|
|
229
|
+
#
|
|
230
|
+
# This function is used by Brick Viewer during flashing. It should not be
|
|
231
|
+
# necessary to call it in a normal user program.
|
|
232
|
+
def set_write_firmware_pointer(pointer)
|
|
233
|
+
check_validity
|
|
234
|
+
|
|
235
|
+
send_request FUNCTION_SET_WRITE_FIRMWARE_POINTER, [pointer], 'L', 8, ''
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
# Writes 64 Bytes of firmware at the position as written by
|
|
239
|
+
# BrickletDistanceUSV2#set_write_firmware_pointer before. The firmware is written
|
|
240
|
+
# to flash every 4 chunks.
|
|
241
|
+
#
|
|
242
|
+
# You can only write firmware in bootloader mode.
|
|
243
|
+
#
|
|
244
|
+
# This function is used by Brick Viewer during flashing. It should not be
|
|
245
|
+
# necessary to call it in a normal user program.
|
|
246
|
+
def write_firmware(data)
|
|
247
|
+
check_validity
|
|
248
|
+
|
|
249
|
+
send_request FUNCTION_WRITE_FIRMWARE, [data], 'C64', 9, 'C'
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
# Sets the status LED configuration. By default the LED shows
|
|
253
|
+
# communication traffic between Brick and Bricklet, it flickers once
|
|
254
|
+
# for every 10 received data packets.
|
|
255
|
+
#
|
|
256
|
+
# You can also turn the LED permanently on/off or show a heartbeat.
|
|
257
|
+
#
|
|
258
|
+
# If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
|
|
259
|
+
def set_status_led_config(config)
|
|
260
|
+
check_validity
|
|
261
|
+
|
|
262
|
+
send_request FUNCTION_SET_STATUS_LED_CONFIG, [config], 'C', 8, ''
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
# Returns the configuration as set by BrickletDistanceUSV2#set_status_led_config
|
|
266
|
+
def get_status_led_config
|
|
267
|
+
check_validity
|
|
268
|
+
|
|
269
|
+
send_request FUNCTION_GET_STATUS_LED_CONFIG, [], '', 9, 'C'
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
# Returns the temperature as measured inside the microcontroller. The
|
|
273
|
+
# value returned is not the ambient temperature!
|
|
274
|
+
#
|
|
275
|
+
# The temperature is only proportional to the real temperature and it has bad
|
|
276
|
+
# accuracy. Practically it is only useful as an indicator for
|
|
277
|
+
# temperature changes.
|
|
278
|
+
def get_chip_temperature
|
|
279
|
+
check_validity
|
|
280
|
+
|
|
281
|
+
send_request FUNCTION_GET_CHIP_TEMPERATURE, [], '', 10, 's'
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
# Calling this function will reset the Bricklet. All configurations
|
|
285
|
+
# will be lost.
|
|
286
|
+
#
|
|
287
|
+
# After a reset you have to create new device objects,
|
|
288
|
+
# calling functions on the existing ones will result in
|
|
289
|
+
# undefined behavior!
|
|
290
|
+
def reset
|
|
291
|
+
check_validity
|
|
292
|
+
|
|
293
|
+
send_request FUNCTION_RESET, [], '', 8, ''
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
# Writes a new UID into flash. If you want to set a new UID
|
|
297
|
+
# you have to decode the Base58 encoded UID string into an
|
|
298
|
+
# integer first.
|
|
299
|
+
#
|
|
300
|
+
# We recommend that you use Brick Viewer to change the UID.
|
|
301
|
+
def write_uid(uid)
|
|
302
|
+
check_validity
|
|
303
|
+
|
|
304
|
+
send_request FUNCTION_WRITE_UID, [uid], 'L', 8, ''
|
|
305
|
+
end
|
|
306
|
+
|
|
307
|
+
# Returns the current UID as an integer. Encode as
|
|
308
|
+
# Base58 to get the usual string version.
|
|
309
|
+
def read_uid
|
|
310
|
+
check_validity
|
|
311
|
+
|
|
312
|
+
send_request FUNCTION_READ_UID, [], '', 12, 'L'
|
|
313
|
+
end
|
|
314
|
+
|
|
315
|
+
# Returns the UID, the UID where the Bricklet is connected to,
|
|
316
|
+
# the position, the hardware and firmware version as well as the
|
|
317
|
+
# device identifier.
|
|
318
|
+
#
|
|
319
|
+
# The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
|
|
320
|
+
# A Bricklet connected to an :ref:`Isolator Bricklet <isolator_bricklet>` is always at
|
|
321
|
+
# position 'z'.
|
|
322
|
+
#
|
|
323
|
+
# The device identifier numbers can be found :ref:`here <device_identifier>`.
|
|
324
|
+
# |device_identifier_constant|
|
|
325
|
+
def get_identity
|
|
326
|
+
send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S'
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
# Registers a callback with ID <tt>id</tt> to the block <tt>block</tt>.
|
|
330
|
+
def register_callback(id, &block)
|
|
331
|
+
callback = block
|
|
332
|
+
@registered_callbacks[id] = callback
|
|
333
|
+
end
|
|
334
|
+
end
|
|
335
|
+
end
|