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,25 +1,37 @@
|
|
|
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
|
# HAT for Raspberry Pi with 8 Bricklets ports and real-time clock
|
|
14
16
|
class BrickHAT < Device
|
|
15
17
|
DEVICE_IDENTIFIER = 111 # :nodoc:
|
|
16
18
|
DEVICE_DISPLAY_NAME = 'HAT Brick' # :nodoc:
|
|
17
19
|
|
|
20
|
+
# This callback is triggered periodically according to the configuration set by
|
|
21
|
+
# BrickHAT#set_voltages_callback_configuration.
|
|
22
|
+
#
|
|
23
|
+
# The parameters are the same as BrickHAT#get_voltages.
|
|
24
|
+
#
|
|
25
|
+
# .. versionadded:: 2.0.1$nbsp;(Firmware)
|
|
26
|
+
CALLBACK_VOLTAGES = 8
|
|
27
|
+
|
|
18
28
|
FUNCTION_SET_SLEEP_MODE = 1 # :nodoc:
|
|
19
29
|
FUNCTION_GET_SLEEP_MODE = 2 # :nodoc:
|
|
20
30
|
FUNCTION_SET_BRICKLET_POWER = 3 # :nodoc:
|
|
21
31
|
FUNCTION_GET_BRICKLET_POWER = 4 # :nodoc:
|
|
22
32
|
FUNCTION_GET_VOLTAGES = 5 # :nodoc:
|
|
33
|
+
FUNCTION_SET_VOLTAGES_CALLBACK_CONFIGURATION = 6 # :nodoc:
|
|
34
|
+
FUNCTION_GET_VOLTAGES_CALLBACK_CONFIGURATION = 7 # :nodoc:
|
|
23
35
|
FUNCTION_GET_SPITFP_ERROR_COUNT = 234 # :nodoc:
|
|
24
36
|
FUNCTION_SET_BOOTLOADER_MODE = 235 # :nodoc:
|
|
25
37
|
FUNCTION_GET_BOOTLOADER_MODE = 236 # :nodoc:
|
|
@@ -52,15 +64,17 @@ module Tinkerforge
|
|
|
52
64
|
# Creates an object with the unique device ID <tt>uid</tt> and adds it to
|
|
53
65
|
# the IP Connection <tt>ipcon</tt>.
|
|
54
66
|
def initialize(uid, ipcon)
|
|
55
|
-
super uid, ipcon
|
|
67
|
+
super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME
|
|
56
68
|
|
|
57
|
-
@api_version = [2, 0,
|
|
69
|
+
@api_version = [2, 0, 1]
|
|
58
70
|
|
|
59
71
|
@response_expected[FUNCTION_SET_SLEEP_MODE] = RESPONSE_EXPECTED_FALSE
|
|
60
72
|
@response_expected[FUNCTION_GET_SLEEP_MODE] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
|
61
73
|
@response_expected[FUNCTION_SET_BRICKLET_POWER] = RESPONSE_EXPECTED_FALSE
|
|
62
74
|
@response_expected[FUNCTION_GET_BRICKLET_POWER] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
|
63
75
|
@response_expected[FUNCTION_GET_VOLTAGES] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
|
76
|
+
@response_expected[FUNCTION_SET_VOLTAGES_CALLBACK_CONFIGURATION] = RESPONSE_EXPECTED_TRUE
|
|
77
|
+
@response_expected[FUNCTION_GET_VOLTAGES_CALLBACK_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
|
64
78
|
@response_expected[FUNCTION_GET_SPITFP_ERROR_COUNT] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
|
65
79
|
@response_expected[FUNCTION_SET_BOOTLOADER_MODE] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
|
66
80
|
@response_expected[FUNCTION_GET_BOOTLOADER_MODE] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
|
@@ -74,49 +88,61 @@ module Tinkerforge
|
|
|
74
88
|
@response_expected[FUNCTION_READ_UID] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
|
75
89
|
@response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
|
76
90
|
|
|
91
|
+
@callback_formats[CALLBACK_VOLTAGES] = [12, 'S S']
|
|
77
92
|
|
|
93
|
+
@ipcon.add_device self
|
|
78
94
|
end
|
|
79
95
|
|
|
80
96
|
# Sets the sleep mode.
|
|
81
97
|
#
|
|
98
|
+
# .. note::
|
|
99
|
+
# Calling this function will cut the Raspberry Pi's power after Power Off Delay seconds.
|
|
100
|
+
# You have to shut down the operating system yourself, e.g. by calling 'sudo shutdown -h now'.
|
|
101
|
+
#
|
|
82
102
|
# Parameters:
|
|
83
103
|
#
|
|
84
|
-
# * Power Off Delay: Time before the RPi/Bricklets are powered off
|
|
85
|
-
# * Power Off Duration: Duration that the RPi/Bricklets stay powered off
|
|
86
|
-
# * Raspberry Pi Off: RPi
|
|
104
|
+
# * Power Off Delay: Time before the RPi/Bricklets are powered off.
|
|
105
|
+
# * Power Off Duration: Duration that the RPi/Bricklets stay powered off.
|
|
106
|
+
# * Raspberry Pi Off: RPi is powered off if set to true.
|
|
87
107
|
# * Bricklets Off: Bricklets are powered off if set to true.
|
|
88
108
|
# * Enable Sleep Indicator: If set to true, the status LED will blink in a 1s interval
|
|
89
|
-
# during the whole power off duration. This will draw
|
|
109
|
+
# during the whole power off duration. This will draw additional 0.3mA.
|
|
90
110
|
#
|
|
91
111
|
# Example: To turn RPi and Bricklets off in 5 seconds for 10 minutes with sleep
|
|
92
|
-
# indicator enabled call (5, 60*10, true, true, true).
|
|
112
|
+
# indicator enabled, call (5, 60*10, true, true, true).
|
|
93
113
|
#
|
|
94
114
|
# This function can also be used to implement a watchdog. To do this you can
|
|
95
115
|
# write a program that calls this function once per second in a loop with
|
|
96
116
|
# (10, 2, true, false, false). If the RPi crashes or gets stuck
|
|
97
117
|
# the HAT will reset the RPi after 10 seconds.
|
|
98
118
|
def set_sleep_mode(power_off_delay, power_off_duration, raspberry_pi_off, bricklets_off, enable_sleep_indicator)
|
|
99
|
-
|
|
119
|
+
check_validity
|
|
120
|
+
|
|
121
|
+
send_request FUNCTION_SET_SLEEP_MODE, [power_off_delay, power_off_duration, raspberry_pi_off, bricklets_off, enable_sleep_indicator], 'L L ? ? ?', 8, ''
|
|
100
122
|
end
|
|
101
123
|
|
|
102
124
|
# Returns the sleep mode settings as set by BrickHAT#set_sleep_mode.
|
|
103
125
|
def get_sleep_mode
|
|
104
|
-
|
|
126
|
+
check_validity
|
|
127
|
+
|
|
128
|
+
send_request FUNCTION_GET_SLEEP_MODE, [], '', 19, 'L L ? ? ?'
|
|
105
129
|
end
|
|
106
130
|
|
|
107
131
|
# Set to true/false to turn the power supply of the connected Bricklets on/off.
|
|
108
|
-
#
|
|
109
|
-
# By default the Bricklets are on.
|
|
110
132
|
def set_bricklet_power(bricklet_power)
|
|
111
|
-
|
|
133
|
+
check_validity
|
|
134
|
+
|
|
135
|
+
send_request FUNCTION_SET_BRICKLET_POWER, [bricklet_power], '?', 8, ''
|
|
112
136
|
end
|
|
113
137
|
|
|
114
138
|
# Returns the power status of the connected Bricklets as set by BrickHAT#set_bricklet_power.
|
|
115
139
|
def get_bricklet_power
|
|
116
|
-
|
|
140
|
+
check_validity
|
|
141
|
+
|
|
142
|
+
send_request FUNCTION_GET_BRICKLET_POWER, [], '', 9, '?'
|
|
117
143
|
end
|
|
118
144
|
|
|
119
|
-
# Returns the USB supply voltage and the DC input supply voltage
|
|
145
|
+
# Returns the USB supply voltage and the DC input supply voltage.
|
|
120
146
|
#
|
|
121
147
|
# There are three possible combinations:
|
|
122
148
|
#
|
|
@@ -131,7 +157,36 @@ module Tinkerforge
|
|
|
131
157
|
# disconnect the DC input (or if the DC input voltage falls below the
|
|
132
158
|
# USB voltage).
|
|
133
159
|
def get_voltages
|
|
134
|
-
|
|
160
|
+
check_validity
|
|
161
|
+
|
|
162
|
+
send_request FUNCTION_GET_VOLTAGES, [], '', 12, 'S S'
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
# The period is the period with which the CALLBACK_VOLTAGES
|
|
166
|
+
# callback is triggered periodically. A value of 0 turns the callback off.
|
|
167
|
+
#
|
|
168
|
+
# If the `value has to change`-parameter is set to true, the callback is only
|
|
169
|
+
# triggered after the value has changed. If the value didn't change within the
|
|
170
|
+
# period, the callback is triggered immediately on change.
|
|
171
|
+
#
|
|
172
|
+
# If it is set to false, the callback is continuously triggered with the period,
|
|
173
|
+
# independent of the value.
|
|
174
|
+
#
|
|
175
|
+
# .. versionadded:: 2.0.1$nbsp;(Firmware)
|
|
176
|
+
def set_voltages_callback_configuration(period, value_has_to_change)
|
|
177
|
+
check_validity
|
|
178
|
+
|
|
179
|
+
send_request FUNCTION_SET_VOLTAGES_CALLBACK_CONFIGURATION, [period, value_has_to_change], 'L ?', 8, ''
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
# Returns the callback configuration as set by
|
|
183
|
+
# BrickHAT#set_voltages_callback_configuration.
|
|
184
|
+
#
|
|
185
|
+
# .. versionadded:: 2.0.1$nbsp;(Firmware)
|
|
186
|
+
def get_voltages_callback_configuration
|
|
187
|
+
check_validity
|
|
188
|
+
|
|
189
|
+
send_request FUNCTION_GET_VOLTAGES_CALLBACK_CONFIGURATION, [], '', 13, 'L ?'
|
|
135
190
|
end
|
|
136
191
|
|
|
137
192
|
# Returns the error count for the communication between Brick and Bricklet.
|
|
@@ -146,7 +201,9 @@ module Tinkerforge
|
|
|
146
201
|
# The errors counts are for errors that occur on the Bricklet side. All
|
|
147
202
|
# Bricks have a similar function that returns the errors on the Brick side.
|
|
148
203
|
def get_spitfp_error_count
|
|
149
|
-
|
|
204
|
+
check_validity
|
|
205
|
+
|
|
206
|
+
send_request FUNCTION_GET_SPITFP_ERROR_COUNT, [], '', 24, 'L L L L'
|
|
150
207
|
end
|
|
151
208
|
|
|
152
209
|
# Sets the bootloader mode and returns the status after the requested
|
|
@@ -159,12 +216,16 @@ module Tinkerforge
|
|
|
159
216
|
# This function is used by Brick Viewer during flashing. It should not be
|
|
160
217
|
# necessary to call it in a normal user program.
|
|
161
218
|
def set_bootloader_mode(mode)
|
|
162
|
-
|
|
219
|
+
check_validity
|
|
220
|
+
|
|
221
|
+
send_request FUNCTION_SET_BOOTLOADER_MODE, [mode], 'C', 9, 'C'
|
|
163
222
|
end
|
|
164
223
|
|
|
165
224
|
# Returns the current bootloader mode, see BrickHAT#set_bootloader_mode.
|
|
166
225
|
def get_bootloader_mode
|
|
167
|
-
|
|
226
|
+
check_validity
|
|
227
|
+
|
|
228
|
+
send_request FUNCTION_GET_BOOTLOADER_MODE, [], '', 9, 'C'
|
|
168
229
|
end
|
|
169
230
|
|
|
170
231
|
# Sets the firmware pointer for BrickHAT#write_firmware. The pointer has
|
|
@@ -174,7 +235,9 @@ module Tinkerforge
|
|
|
174
235
|
# This function is used by Brick Viewer during flashing. It should not be
|
|
175
236
|
# necessary to call it in a normal user program.
|
|
176
237
|
def set_write_firmware_pointer(pointer)
|
|
177
|
-
|
|
238
|
+
check_validity
|
|
239
|
+
|
|
240
|
+
send_request FUNCTION_SET_WRITE_FIRMWARE_POINTER, [pointer], 'L', 8, ''
|
|
178
241
|
end
|
|
179
242
|
|
|
180
243
|
# Writes 64 Bytes of firmware at the position as written by
|
|
@@ -186,7 +249,9 @@ module Tinkerforge
|
|
|
186
249
|
# This function is used by Brick Viewer during flashing. It should not be
|
|
187
250
|
# necessary to call it in a normal user program.
|
|
188
251
|
def write_firmware(data)
|
|
189
|
-
|
|
252
|
+
check_validity
|
|
253
|
+
|
|
254
|
+
send_request FUNCTION_WRITE_FIRMWARE, [data], 'C64', 9, 'C'
|
|
190
255
|
end
|
|
191
256
|
|
|
192
257
|
# Sets the status LED configuration. By default the LED shows
|
|
@@ -197,22 +262,28 @@ module Tinkerforge
|
|
|
197
262
|
#
|
|
198
263
|
# If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
|
|
199
264
|
def set_status_led_config(config)
|
|
200
|
-
|
|
265
|
+
check_validity
|
|
266
|
+
|
|
267
|
+
send_request FUNCTION_SET_STATUS_LED_CONFIG, [config], 'C', 8, ''
|
|
201
268
|
end
|
|
202
269
|
|
|
203
270
|
# Returns the configuration as set by BrickHAT#set_status_led_config
|
|
204
271
|
def get_status_led_config
|
|
205
|
-
|
|
272
|
+
check_validity
|
|
273
|
+
|
|
274
|
+
send_request FUNCTION_GET_STATUS_LED_CONFIG, [], '', 9, 'C'
|
|
206
275
|
end
|
|
207
276
|
|
|
208
|
-
# Returns the temperature
|
|
277
|
+
# Returns the temperature as measured inside the microcontroller. The
|
|
209
278
|
# value returned is not the ambient temperature!
|
|
210
279
|
#
|
|
211
280
|
# The temperature is only proportional to the real temperature and it has bad
|
|
212
281
|
# accuracy. Practically it is only useful as an indicator for
|
|
213
282
|
# temperature changes.
|
|
214
283
|
def get_chip_temperature
|
|
215
|
-
|
|
284
|
+
check_validity
|
|
285
|
+
|
|
286
|
+
send_request FUNCTION_GET_CHIP_TEMPERATURE, [], '', 10, 's'
|
|
216
287
|
end
|
|
217
288
|
|
|
218
289
|
# Calling this function will reset the Bricklet. All configurations
|
|
@@ -222,7 +293,9 @@ module Tinkerforge
|
|
|
222
293
|
# calling functions on the existing ones will result in
|
|
223
294
|
# undefined behavior!
|
|
224
295
|
def reset
|
|
225
|
-
|
|
296
|
+
check_validity
|
|
297
|
+
|
|
298
|
+
send_request FUNCTION_RESET, [], '', 8, ''
|
|
226
299
|
end
|
|
227
300
|
|
|
228
301
|
# Writes a new UID into flash. If you want to set a new UID
|
|
@@ -231,26 +304,36 @@ module Tinkerforge
|
|
|
231
304
|
#
|
|
232
305
|
# We recommend that you use Brick Viewer to change the UID.
|
|
233
306
|
def write_uid(uid)
|
|
234
|
-
|
|
307
|
+
check_validity
|
|
308
|
+
|
|
309
|
+
send_request FUNCTION_WRITE_UID, [uid], 'L', 8, ''
|
|
235
310
|
end
|
|
236
311
|
|
|
237
312
|
# Returns the current UID as an integer. Encode as
|
|
238
313
|
# Base58 to get the usual string version.
|
|
239
314
|
def read_uid
|
|
240
|
-
|
|
315
|
+
check_validity
|
|
316
|
+
|
|
317
|
+
send_request FUNCTION_READ_UID, [], '', 12, 'L'
|
|
241
318
|
end
|
|
242
319
|
|
|
243
|
-
# Returns the UID, the UID where the
|
|
320
|
+
# Returns the UID, the UID where the HAT is connected to
|
|
321
|
+
# (typically '0' as the HAT is the root device in the topology),
|
|
244
322
|
# the position, the hardware and firmware version as well as the
|
|
245
323
|
# device identifier.
|
|
246
324
|
#
|
|
247
|
-
# The
|
|
325
|
+
# The HAT (Zero) Brick is always at position 'i'.
|
|
248
326
|
#
|
|
249
327
|
# The device identifier numbers can be found :ref:`here <device_identifier>`.
|
|
250
328
|
# |device_identifier_constant|
|
|
251
329
|
def get_identity
|
|
252
|
-
send_request FUNCTION_GET_IDENTITY, [], '',
|
|
330
|
+
send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S'
|
|
253
331
|
end
|
|
254
332
|
|
|
333
|
+
# Registers a callback with ID <tt>id</tt> to the block <tt>block</tt>.
|
|
334
|
+
def register_callback(id, &block)
|
|
335
|
+
callback = block
|
|
336
|
+
@registered_callbacks[id] = callback
|
|
337
|
+
end
|
|
255
338
|
end
|
|
256
339
|
end
|
|
@@ -1,21 +1,33 @@
|
|
|
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
|
# HAT for Raspberry Pi Zero with 4 Bricklets ports
|
|
14
16
|
class BrickHATZero < Device
|
|
15
17
|
DEVICE_IDENTIFIER = 112 # :nodoc:
|
|
16
18
|
DEVICE_DISPLAY_NAME = 'HAT Zero Brick' # :nodoc:
|
|
17
19
|
|
|
20
|
+
# This callback is triggered periodically according to the configuration set by
|
|
21
|
+
# BrickHATZero#set_usb_voltage_callback_configuration.
|
|
22
|
+
#
|
|
23
|
+
# The parameter is the same as BrickHATZero#get_usb_voltage.
|
|
24
|
+
#
|
|
25
|
+
# .. versionadded:: 2.0.1$nbsp;(Firmware)
|
|
26
|
+
CALLBACK_USB_VOLTAGE = 4
|
|
27
|
+
|
|
18
28
|
FUNCTION_GET_USB_VOLTAGE = 1 # :nodoc:
|
|
29
|
+
FUNCTION_SET_USB_VOLTAGE_CALLBACK_CONFIGURATION = 2 # :nodoc:
|
|
30
|
+
FUNCTION_GET_USB_VOLTAGE_CALLBACK_CONFIGURATION = 3 # :nodoc:
|
|
19
31
|
FUNCTION_GET_SPITFP_ERROR_COUNT = 234 # :nodoc:
|
|
20
32
|
FUNCTION_SET_BOOTLOADER_MODE = 235 # :nodoc:
|
|
21
33
|
FUNCTION_GET_BOOTLOADER_MODE = 236 # :nodoc:
|
|
@@ -29,6 +41,11 @@ module Tinkerforge
|
|
|
29
41
|
FUNCTION_READ_UID = 249 # :nodoc:
|
|
30
42
|
FUNCTION_GET_IDENTITY = 255 # :nodoc:
|
|
31
43
|
|
|
44
|
+
THRESHOLD_OPTION_OFF = 'x' # :nodoc:
|
|
45
|
+
THRESHOLD_OPTION_OUTSIDE = 'o' # :nodoc:
|
|
46
|
+
THRESHOLD_OPTION_INSIDE = 'i' # :nodoc:
|
|
47
|
+
THRESHOLD_OPTION_SMALLER = '<' # :nodoc:
|
|
48
|
+
THRESHOLD_OPTION_GREATER = '>' # :nodoc:
|
|
32
49
|
BOOTLOADER_MODE_BOOTLOADER = 0 # :nodoc:
|
|
33
50
|
BOOTLOADER_MODE_FIRMWARE = 1 # :nodoc:
|
|
34
51
|
BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT = 2 # :nodoc:
|
|
@@ -48,11 +65,13 @@ module Tinkerforge
|
|
|
48
65
|
# Creates an object with the unique device ID <tt>uid</tt> and adds it to
|
|
49
66
|
# the IP Connection <tt>ipcon</tt>.
|
|
50
67
|
def initialize(uid, ipcon)
|
|
51
|
-
super uid, ipcon
|
|
68
|
+
super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME
|
|
52
69
|
|
|
53
|
-
@api_version = [2, 0,
|
|
70
|
+
@api_version = [2, 0, 1]
|
|
54
71
|
|
|
55
72
|
@response_expected[FUNCTION_GET_USB_VOLTAGE] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
|
73
|
+
@response_expected[FUNCTION_SET_USB_VOLTAGE_CALLBACK_CONFIGURATION] = RESPONSE_EXPECTED_TRUE
|
|
74
|
+
@response_expected[FUNCTION_GET_USB_VOLTAGE_CALLBACK_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
|
56
75
|
@response_expected[FUNCTION_GET_SPITFP_ERROR_COUNT] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
|
57
76
|
@response_expected[FUNCTION_SET_BOOTLOADER_MODE] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
|
58
77
|
@response_expected[FUNCTION_GET_BOOTLOADER_MODE] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
|
@@ -66,12 +85,63 @@ module Tinkerforge
|
|
|
66
85
|
@response_expected[FUNCTION_READ_UID] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
|
67
86
|
@response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
|
|
68
87
|
|
|
88
|
+
@callback_formats[CALLBACK_USB_VOLTAGE] = [10, 'S']
|
|
69
89
|
|
|
90
|
+
@ipcon.add_device self
|
|
70
91
|
end
|
|
71
92
|
|
|
72
|
-
# Returns the USB supply voltage of the Raspberry Pi
|
|
93
|
+
# Returns the USB supply voltage of the Raspberry Pi.
|
|
94
|
+
#
|
|
95
|
+
#
|
|
96
|
+
# If you want to get the value periodically, it is recommended to use the
|
|
97
|
+
# CALLBACK_USB_VOLTAGE callback. You can set the callback configuration
|
|
98
|
+
# with BrickHATZero#set_usb_voltage_callback_configuration.
|
|
73
99
|
def get_usb_voltage
|
|
74
|
-
|
|
100
|
+
check_validity
|
|
101
|
+
|
|
102
|
+
send_request FUNCTION_GET_USB_VOLTAGE, [], '', 10, 'S'
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# The period is the period with which the CALLBACK_USB_VOLTAGE callback is triggered
|
|
106
|
+
# periodically. A value of 0 turns the callback off.
|
|
107
|
+
#
|
|
108
|
+
# If the `value has to change`-parameter is set to true, the callback is only
|
|
109
|
+
# triggered after the value has changed. If the value didn't change
|
|
110
|
+
# within the period, the callback is triggered immediately on change.
|
|
111
|
+
#
|
|
112
|
+
# If it is set to false, the callback is continuously triggered with the period,
|
|
113
|
+
# independent of the value.
|
|
114
|
+
#
|
|
115
|
+
# It is furthermore possible to constrain the callback with thresholds.
|
|
116
|
+
#
|
|
117
|
+
# The `option`-parameter together with min/max sets a threshold for the CALLBACK_USB_VOLTAGE callback.
|
|
118
|
+
#
|
|
119
|
+
# The following options are possible:
|
|
120
|
+
#
|
|
121
|
+
# "Option", "Description"
|
|
122
|
+
#
|
|
123
|
+
# "'x'", "Threshold is turned off"
|
|
124
|
+
# "'o'", "Threshold is triggered when the value is *outside* the min and max values"
|
|
125
|
+
# "'i'", "Threshold is triggered when the value is *inside* or equal to the min and max values"
|
|
126
|
+
# "'<'", "Threshold is triggered when the value is smaller than the min value (max is ignored)"
|
|
127
|
+
# "'>'", "Threshold is triggered when the value is greater than the min value (max is ignored)"
|
|
128
|
+
#
|
|
129
|
+
# If the option is set to 'x' (threshold turned off) the callback is triggered with the fixed period.
|
|
130
|
+
#
|
|
131
|
+
# .. versionadded:: 2.0.1$nbsp;(Firmware)
|
|
132
|
+
def set_usb_voltage_callback_configuration(period, value_has_to_change, option, min, max)
|
|
133
|
+
check_validity
|
|
134
|
+
|
|
135
|
+
send_request FUNCTION_SET_USB_VOLTAGE_CALLBACK_CONFIGURATION, [period, value_has_to_change, option, min, max], 'L ? k S S', 8, ''
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# Returns the callback configuration as set by BrickHATZero#set_usb_voltage_callback_configuration.
|
|
139
|
+
#
|
|
140
|
+
# .. versionadded:: 2.0.1$nbsp;(Firmware)
|
|
141
|
+
def get_usb_voltage_callback_configuration
|
|
142
|
+
check_validity
|
|
143
|
+
|
|
144
|
+
send_request FUNCTION_GET_USB_VOLTAGE_CALLBACK_CONFIGURATION, [], '', 18, 'L ? k S S'
|
|
75
145
|
end
|
|
76
146
|
|
|
77
147
|
# Returns the error count for the communication between Brick and Bricklet.
|
|
@@ -86,7 +156,9 @@ module Tinkerforge
|
|
|
86
156
|
# The errors counts are for errors that occur on the Bricklet side. All
|
|
87
157
|
# Bricks have a similar function that returns the errors on the Brick side.
|
|
88
158
|
def get_spitfp_error_count
|
|
89
|
-
|
|
159
|
+
check_validity
|
|
160
|
+
|
|
161
|
+
send_request FUNCTION_GET_SPITFP_ERROR_COUNT, [], '', 24, 'L L L L'
|
|
90
162
|
end
|
|
91
163
|
|
|
92
164
|
# Sets the bootloader mode and returns the status after the requested
|
|
@@ -99,12 +171,16 @@ module Tinkerforge
|
|
|
99
171
|
# This function is used by Brick Viewer during flashing. It should not be
|
|
100
172
|
# necessary to call it in a normal user program.
|
|
101
173
|
def set_bootloader_mode(mode)
|
|
102
|
-
|
|
174
|
+
check_validity
|
|
175
|
+
|
|
176
|
+
send_request FUNCTION_SET_BOOTLOADER_MODE, [mode], 'C', 9, 'C'
|
|
103
177
|
end
|
|
104
178
|
|
|
105
179
|
# Returns the current bootloader mode, see BrickHATZero#set_bootloader_mode.
|
|
106
180
|
def get_bootloader_mode
|
|
107
|
-
|
|
181
|
+
check_validity
|
|
182
|
+
|
|
183
|
+
send_request FUNCTION_GET_BOOTLOADER_MODE, [], '', 9, 'C'
|
|
108
184
|
end
|
|
109
185
|
|
|
110
186
|
# Sets the firmware pointer for BrickHATZero#write_firmware. The pointer has
|
|
@@ -114,7 +190,9 @@ module Tinkerforge
|
|
|
114
190
|
# This function is used by Brick Viewer during flashing. It should not be
|
|
115
191
|
# necessary to call it in a normal user program.
|
|
116
192
|
def set_write_firmware_pointer(pointer)
|
|
117
|
-
|
|
193
|
+
check_validity
|
|
194
|
+
|
|
195
|
+
send_request FUNCTION_SET_WRITE_FIRMWARE_POINTER, [pointer], 'L', 8, ''
|
|
118
196
|
end
|
|
119
197
|
|
|
120
198
|
# Writes 64 Bytes of firmware at the position as written by
|
|
@@ -126,7 +204,9 @@ module Tinkerforge
|
|
|
126
204
|
# This function is used by Brick Viewer during flashing. It should not be
|
|
127
205
|
# necessary to call it in a normal user program.
|
|
128
206
|
def write_firmware(data)
|
|
129
|
-
|
|
207
|
+
check_validity
|
|
208
|
+
|
|
209
|
+
send_request FUNCTION_WRITE_FIRMWARE, [data], 'C64', 9, 'C'
|
|
130
210
|
end
|
|
131
211
|
|
|
132
212
|
# Sets the status LED configuration. By default the LED shows
|
|
@@ -137,22 +217,28 @@ module Tinkerforge
|
|
|
137
217
|
#
|
|
138
218
|
# If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
|
|
139
219
|
def set_status_led_config(config)
|
|
140
|
-
|
|
220
|
+
check_validity
|
|
221
|
+
|
|
222
|
+
send_request FUNCTION_SET_STATUS_LED_CONFIG, [config], 'C', 8, ''
|
|
141
223
|
end
|
|
142
224
|
|
|
143
225
|
# Returns the configuration as set by BrickHATZero#set_status_led_config
|
|
144
226
|
def get_status_led_config
|
|
145
|
-
|
|
227
|
+
check_validity
|
|
228
|
+
|
|
229
|
+
send_request FUNCTION_GET_STATUS_LED_CONFIG, [], '', 9, 'C'
|
|
146
230
|
end
|
|
147
231
|
|
|
148
|
-
# Returns the temperature
|
|
232
|
+
# Returns the temperature as measured inside the microcontroller. The
|
|
149
233
|
# value returned is not the ambient temperature!
|
|
150
234
|
#
|
|
151
235
|
# The temperature is only proportional to the real temperature and it has bad
|
|
152
236
|
# accuracy. Practically it is only useful as an indicator for
|
|
153
237
|
# temperature changes.
|
|
154
238
|
def get_chip_temperature
|
|
155
|
-
|
|
239
|
+
check_validity
|
|
240
|
+
|
|
241
|
+
send_request FUNCTION_GET_CHIP_TEMPERATURE, [], '', 10, 's'
|
|
156
242
|
end
|
|
157
243
|
|
|
158
244
|
# Calling this function will reset the Bricklet. All configurations
|
|
@@ -162,7 +248,9 @@ module Tinkerforge
|
|
|
162
248
|
# calling functions on the existing ones will result in
|
|
163
249
|
# undefined behavior!
|
|
164
250
|
def reset
|
|
165
|
-
|
|
251
|
+
check_validity
|
|
252
|
+
|
|
253
|
+
send_request FUNCTION_RESET, [], '', 8, ''
|
|
166
254
|
end
|
|
167
255
|
|
|
168
256
|
# Writes a new UID into flash. If you want to set a new UID
|
|
@@ -171,26 +259,36 @@ module Tinkerforge
|
|
|
171
259
|
#
|
|
172
260
|
# We recommend that you use Brick Viewer to change the UID.
|
|
173
261
|
def write_uid(uid)
|
|
174
|
-
|
|
262
|
+
check_validity
|
|
263
|
+
|
|
264
|
+
send_request FUNCTION_WRITE_UID, [uid], 'L', 8, ''
|
|
175
265
|
end
|
|
176
266
|
|
|
177
267
|
# Returns the current UID as an integer. Encode as
|
|
178
268
|
# Base58 to get the usual string version.
|
|
179
269
|
def read_uid
|
|
180
|
-
|
|
270
|
+
check_validity
|
|
271
|
+
|
|
272
|
+
send_request FUNCTION_READ_UID, [], '', 12, 'L'
|
|
181
273
|
end
|
|
182
274
|
|
|
183
|
-
# Returns the UID, the UID where the
|
|
275
|
+
# Returns the UID, the UID where the HAT is connected to
|
|
276
|
+
# (typically '0' as the HAT is the root device in the topology),
|
|
184
277
|
# the position, the hardware and firmware version as well as the
|
|
185
278
|
# device identifier.
|
|
186
279
|
#
|
|
187
|
-
# The
|
|
280
|
+
# The HAT (Zero) Brick is always at position 'i'.
|
|
188
281
|
#
|
|
189
282
|
# The device identifier numbers can be found :ref:`here <device_identifier>`.
|
|
190
283
|
# |device_identifier_constant|
|
|
191
284
|
def get_identity
|
|
192
|
-
send_request FUNCTION_GET_IDENTITY, [], '',
|
|
285
|
+
send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S'
|
|
193
286
|
end
|
|
194
287
|
|
|
288
|
+
# Registers a callback with ID <tt>id</tt> to the block <tt>block</tt>.
|
|
289
|
+
def register_callback(id, &block)
|
|
290
|
+
callback = block
|
|
291
|
+
@registered_callbacks[id] = callback
|
|
292
|
+
end
|
|
195
293
|
end
|
|
196
294
|
end
|