tinkerforge 2.1.16 → 2.1.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/lib/tinkerforge/brick_dc.rb +3 -3
  3. data/lib/tinkerforge/brick_imu.rb +3 -3
  4. data/lib/tinkerforge/brick_imu_v2.rb +3 -3
  5. data/lib/tinkerforge/brick_master.rb +3 -3
  6. data/lib/tinkerforge/brick_red.rb +2 -2
  7. data/lib/tinkerforge/brick_servo.rb +3 -3
  8. data/lib/tinkerforge/brick_silent_stepper.rb +3 -3
  9. data/lib/tinkerforge/brick_stepper.rb +3 -3
  10. data/lib/tinkerforge/bricklet_accelerometer.rb +2 -2
  11. data/lib/tinkerforge/bricklet_ambient_light.rb +2 -2
  12. data/lib/tinkerforge/bricklet_ambient_light_v2.rb +2 -2
  13. data/lib/tinkerforge/bricklet_analog_in.rb +2 -2
  14. data/lib/tinkerforge/bricklet_analog_in_v2.rb +2 -2
  15. data/lib/tinkerforge/bricklet_analog_in_v3.rb +5 -6
  16. data/lib/tinkerforge/bricklet_analog_out.rb +2 -2
  17. data/lib/tinkerforge/bricklet_analog_out_v2.rb +2 -2
  18. data/lib/tinkerforge/bricklet_barometer.rb +2 -2
  19. data/lib/tinkerforge/bricklet_can.rb +3 -3
  20. data/lib/tinkerforge/bricklet_can_v2.rb +770 -0
  21. data/lib/tinkerforge/bricklet_co2.rb +2 -2
  22. data/lib/tinkerforge/bricklet_color.rb +2 -2
  23. data/lib/tinkerforge/bricklet_current12.rb +2 -2
  24. data/lib/tinkerforge/bricklet_current25.rb +2 -2
  25. data/lib/tinkerforge/bricklet_distance_ir.rb +2 -2
  26. data/lib/tinkerforge/bricklet_distance_us.rb +2 -2
  27. data/lib/tinkerforge/bricklet_dmx.rb +3 -3
  28. data/lib/tinkerforge/bricklet_dual_button.rb +2 -2
  29. data/lib/tinkerforge/bricklet_dual_relay.rb +2 -2
  30. data/lib/tinkerforge/bricklet_dust_detector.rb +2 -2
  31. data/lib/tinkerforge/bricklet_gps.rb +2 -2
  32. data/lib/tinkerforge/bricklet_gps_v2.rb +3 -3
  33. data/lib/tinkerforge/bricklet_hall_effect.rb +2 -2
  34. data/lib/tinkerforge/bricklet_humidity.rb +2 -2
  35. data/lib/tinkerforge/bricklet_humidity_v2.rb +11 -13
  36. data/lib/tinkerforge/bricklet_industrial_analog_out.rb +2 -2
  37. data/lib/tinkerforge/bricklet_industrial_counter.rb +445 -0
  38. data/lib/tinkerforge/bricklet_industrial_digital_in_4.rb +2 -2
  39. data/lib/tinkerforge/bricklet_industrial_digital_in_4_v2.rb +342 -0
  40. data/lib/tinkerforge/bricklet_industrial_digital_out_4.rb +2 -2
  41. data/lib/tinkerforge/bricklet_industrial_dual_0_20ma.rb +2 -2
  42. data/lib/tinkerforge/bricklet_industrial_dual_analog_in.rb +2 -2
  43. data/lib/tinkerforge/bricklet_industrial_dual_relay.rb +263 -0
  44. data/lib/tinkerforge/bricklet_industrial_quad_relay.rb +2 -2
  45. data/lib/tinkerforge/bricklet_industrial_quad_relay_v2.rb +281 -0
  46. data/lib/tinkerforge/bricklet_io16.rb +2 -2
  47. data/lib/tinkerforge/bricklet_io4.rb +2 -2
  48. data/lib/tinkerforge/bricklet_io4_v2.rb +437 -0
  49. data/lib/tinkerforge/bricklet_joystick.rb +2 -2
  50. data/lib/tinkerforge/bricklet_laser_range_finder.rb +2 -2
  51. data/lib/tinkerforge/bricklet_lcd_16x2.rb +3 -3
  52. data/lib/tinkerforge/bricklet_lcd_20x4.rb +3 -3
  53. data/lib/tinkerforge/bricklet_led_strip.rb +2 -2
  54. data/lib/tinkerforge/bricklet_led_strip_v2.rb +493 -0
  55. data/lib/tinkerforge/bricklet_line.rb +2 -2
  56. data/lib/tinkerforge/bricklet_linear_poti.rb +2 -2
  57. data/lib/tinkerforge/bricklet_load_cell.rb +2 -2
  58. data/lib/tinkerforge/bricklet_load_cell_v2.rb +354 -0
  59. data/lib/tinkerforge/bricklet_moisture.rb +2 -2
  60. data/lib/tinkerforge/bricklet_motion_detector.rb +3 -3
  61. data/lib/tinkerforge/bricklet_motion_detector_v2.rb +2 -2
  62. data/lib/tinkerforge/bricklet_motorized_linear_poti.rb +5 -6
  63. data/lib/tinkerforge/bricklet_multi_touch.rb +2 -2
  64. data/lib/tinkerforge/bricklet_nfc.rb +39 -3
  65. data/lib/tinkerforge/bricklet_nfc_rfid.rb +2 -2
  66. data/lib/tinkerforge/bricklet_oled_128x64.rb +2 -2
  67. data/lib/tinkerforge/bricklet_oled_64x48.rb +2 -2
  68. data/lib/tinkerforge/bricklet_outdoor_weather.rb +2 -2
  69. data/lib/tinkerforge/bricklet_particulate_matter.rb +320 -0
  70. data/lib/tinkerforge/bricklet_piezo_buzzer.rb +2 -2
  71. data/lib/tinkerforge/bricklet_piezo_speaker.rb +2 -2
  72. data/lib/tinkerforge/bricklet_ptc.rb +33 -3
  73. data/lib/tinkerforge/bricklet_ptc_v2.rb +433 -0
  74. data/lib/tinkerforge/bricklet_real_time_clock.rb +2 -2
  75. data/lib/tinkerforge/bricklet_real_time_clock_v2.rb +353 -0
  76. data/lib/tinkerforge/bricklet_remote_switch.rb +2 -2
  77. data/lib/tinkerforge/bricklet_remote_switch_v2.rb +2 -2
  78. data/lib/tinkerforge/bricklet_rgb_led.rb +2 -2
  79. data/lib/tinkerforge/bricklet_rgb_led_button.rb +2 -2
  80. data/lib/tinkerforge/bricklet_rgb_led_matrix.rb +2 -2
  81. data/lib/tinkerforge/bricklet_rotary_encoder.rb +2 -2
  82. data/lib/tinkerforge/bricklet_rotary_encoder_v2.rb +8 -9
  83. data/lib/tinkerforge/bricklet_rotary_poti.rb +2 -2
  84. data/lib/tinkerforge/bricklet_rs232.rb +3 -3
  85. data/lib/tinkerforge/bricklet_rs232_v2.rb +421 -0
  86. data/lib/tinkerforge/bricklet_rs485.rb +6 -6
  87. data/lib/tinkerforge/bricklet_segment_display_4x7.rb +2 -2
  88. data/lib/tinkerforge/bricklet_solid_state_relay.rb +2 -2
  89. data/lib/tinkerforge/bricklet_solid_state_relay_v2.rb +3 -3
  90. data/lib/tinkerforge/bricklet_sound_intensity.rb +2 -2
  91. data/lib/tinkerforge/bricklet_sound_pressure_level.rb +420 -0
  92. data/lib/tinkerforge/bricklet_temperature.rb +3 -3
  93. data/lib/tinkerforge/bricklet_temperature_ir.rb +2 -2
  94. data/lib/tinkerforge/bricklet_temperature_ir_v2.rb +13 -15
  95. data/lib/tinkerforge/bricklet_thermal_imaging.rb +2 -2
  96. data/lib/tinkerforge/bricklet_thermocouple.rb +4 -4
  97. data/lib/tinkerforge/bricklet_thermocouple_v2.rb +340 -0
  98. data/lib/tinkerforge/bricklet_tilt.rb +2 -2
  99. data/lib/tinkerforge/bricklet_uv_light.rb +2 -2
  100. data/lib/tinkerforge/bricklet_voltage.rb +2 -2
  101. data/lib/tinkerforge/bricklet_voltage_current.rb +2 -2
  102. data/lib/tinkerforge/bricklet_voltage_current_v2.rb +453 -0
  103. data/lib/tinkerforge/ip_connection.rb +4 -4
  104. data/lib/tinkerforge/version.rb +1 -1
  105. metadata +17 -2
@@ -1,8 +1,8 @@
1
1
  # -*- ruby encoding: utf-8 -*-
2
2
  #############################################################
3
- # This file was automatically generated on 2018-02-28. #
3
+ # This file was automatically generated on 2018-06-08. #
4
4
  # #
5
- # Ruby Bindings Version 2.1.16 #
5
+ # Ruby Bindings Version 2.1.17 #
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 #
@@ -565,8 +565,8 @@ module Tinkerforge
565
565
  send_request FUNCTION_GET_MODE, [], '', 1, 'C'
566
566
  end
567
567
 
568
- # Sets the communication LED configuration. By default the LED shows
569
- # communication traffic, it flickers once for every 10 received data packets.
568
+ # Sets the communication LED configuration. By default the LED shows RS485
569
+ # communication traffic by flickering.
570
570
  #
571
571
  # You can also turn the LED permanently on/off or show a heartbeat.
572
572
  #
@@ -604,8 +604,8 @@ module Tinkerforge
604
604
  #
605
605
  # The current buffer content is lost if this function is called.
606
606
  #
607
- # The send buffer holds data that is given by BrickletRS485#write and
608
- # can not be written yet. The receive buffer holds data that is
607
+ # The send buffer holds data that was given by BrickletRS485#write and
608
+ # could not be written yet. The receive buffer holds data that is
609
609
  # received through RS485 but could not yet be send to the
610
610
  # user, either by BrickletRS485#read or through CALLBACK_READ callback.
611
611
  #
@@ -1,8 +1,8 @@
1
1
  # -*- ruby encoding: utf-8 -*-
2
2
  #############################################################
3
- # This file was automatically generated on 2018-02-28. #
3
+ # This file was automatically generated on 2018-06-08. #
4
4
  # #
5
- # Ruby Bindings Version 2.1.16 #
5
+ # Ruby Bindings Version 2.1.17 #
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 #
@@ -1,8 +1,8 @@
1
1
  # -*- ruby encoding: utf-8 -*-
2
2
  #############################################################
3
- # This file was automatically generated on 2018-02-28. #
3
+ # This file was automatically generated on 2018-06-08. #
4
4
  # #
5
- # Ruby Bindings Version 2.1.16 #
5
+ # Ruby Bindings Version 2.1.17 #
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 #
@@ -1,8 +1,8 @@
1
1
  # -*- ruby encoding: utf-8 -*-
2
2
  #############################################################
3
- # This file was automatically generated on 2018-02-28. #
3
+ # This file was automatically generated on 2018-06-08. #
4
4
  # #
5
- # Ruby Bindings Version 2.1.16 #
5
+ # Ruby Bindings Version 2.1.17 #
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 #
@@ -10,7 +10,7 @@
10
10
  #############################################################
11
11
 
12
12
  module Tinkerforge
13
- #
13
+ # Controls AC and DC Solid State Relays
14
14
  class BrickletSolidStateRelayV2 < Device
15
15
  DEVICE_IDENTIFIER = 296 # :nodoc:
16
16
  DEVICE_DISPLAY_NAME = 'Solid State Relay Bricklet 2.0' # :nodoc:
@@ -1,8 +1,8 @@
1
1
  # -*- ruby encoding: utf-8 -*-
2
2
  #############################################################
3
- # This file was automatically generated on 2018-02-28. #
3
+ # This file was automatically generated on 2018-06-08. #
4
4
  # #
5
- # Ruby Bindings Version 2.1.16 #
5
+ # Ruby Bindings Version 2.1.17 #
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 #
@@ -0,0 +1,420 @@
1
+ # -*- ruby encoding: utf-8 -*-
2
+ #############################################################
3
+ # This file was automatically generated on 2018-06-08. #
4
+ # #
5
+ # Ruby Bindings Version 2.1.17 #
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
+ module Tinkerforge
13
+ # Measures Sound Pressure Level in dB(A/B/C/D/Z)
14
+ class BrickletSoundPressureLevel < Device
15
+ DEVICE_IDENTIFIER = 290 # :nodoc:
16
+ DEVICE_DISPLAY_NAME = 'Sound Pressure Level Bricklet' # :nodoc:
17
+
18
+ # This callback is triggered periodically according to the configuration set by
19
+ # BrickletSoundPressureLevel#set_decibel_callback_configuration.
20
+ #
21
+ # The parameter is the same as BrickletSoundPressureLevel#get_decibel.
22
+ CALLBACK_DECIBEL = 4
23
+
24
+ # This callback is triggered periodically according to the configuration set by
25
+ # BrickletSoundPressureLevel#set_spectrum_callback_configuration.
26
+ #
27
+ # The parameter is the same as BrickletSoundPressureLevel#get_spectrum.
28
+ CALLBACK_SPECTRUM_LOW_LEVEL = 8
29
+
30
+ # This callback is triggered periodically according to the configuration set by
31
+ # BrickletSoundPressureLevel#set_spectrum_callback_configuration.
32
+ #
33
+ # The parameter is the same as BrickletSoundPressureLevel#get_spectrum.
34
+ CALLBACK_SPECTRUM = -8
35
+
36
+ FUNCTION_GET_DECIBEL = 1 # :nodoc:
37
+ FUNCTION_SET_DECIBEL_CALLBACK_CONFIGURATION = 2 # :nodoc:
38
+ FUNCTION_GET_DECIBEL_CALLBACK_CONFIGURATION = 3 # :nodoc:
39
+ FUNCTION_GET_SPECTRUM_LOW_LEVEL = 5 # :nodoc:
40
+ FUNCTION_SET_SPECTRUM_CALLBACK_CONFIGURATION = 6 # :nodoc:
41
+ FUNCTION_GET_SPECTRUM_CALLBACK_CONFIGURATION = 7 # :nodoc:
42
+ FUNCTION_SET_CONFIGURATION = 9 # :nodoc:
43
+ FUNCTION_GET_CONFIGURATION = 10 # :nodoc:
44
+ FUNCTION_GET_SPITFP_ERROR_COUNT = 234 # :nodoc:
45
+ FUNCTION_SET_BOOTLOADER_MODE = 235 # :nodoc:
46
+ FUNCTION_GET_BOOTLOADER_MODE = 236 # :nodoc:
47
+ FUNCTION_SET_WRITE_FIRMWARE_POINTER = 237 # :nodoc:
48
+ FUNCTION_WRITE_FIRMWARE = 238 # :nodoc:
49
+ FUNCTION_SET_STATUS_LED_CONFIG = 239 # :nodoc:
50
+ FUNCTION_GET_STATUS_LED_CONFIG = 240 # :nodoc:
51
+ FUNCTION_GET_CHIP_TEMPERATURE = 242 # :nodoc:
52
+ FUNCTION_RESET = 243 # :nodoc:
53
+ FUNCTION_WRITE_UID = 248 # :nodoc:
54
+ FUNCTION_READ_UID = 249 # :nodoc:
55
+ FUNCTION_GET_IDENTITY = 255 # :nodoc:
56
+
57
+ THRESHOLD_OPTION_OFF = 'x' # :nodoc:
58
+ THRESHOLD_OPTION_OUTSIDE = 'o' # :nodoc:
59
+ THRESHOLD_OPTION_INSIDE = 'i' # :nodoc:
60
+ THRESHOLD_OPTION_SMALLER = '<' # :nodoc:
61
+ THRESHOLD_OPTION_GREATER = '>' # :nodoc:
62
+ FFT_SIZE_128 = 0 # :nodoc:
63
+ FFT_SIZE_256 = 1 # :nodoc:
64
+ FFT_SIZE_512 = 2 # :nodoc:
65
+ FFT_SIZE_1024 = 3 # :nodoc:
66
+ WEIGHTING_A = 0 # :nodoc:
67
+ WEIGHTING_B = 1 # :nodoc:
68
+ WEIGHTING_C = 2 # :nodoc:
69
+ WEIGHTING_D = 3 # :nodoc:
70
+ WEIGHTING_Z = 4 # :nodoc:
71
+ WEIGHTING_ITU_R_468 = 5 # :nodoc:
72
+ BOOTLOADER_MODE_BOOTLOADER = 0 # :nodoc:
73
+ BOOTLOADER_MODE_FIRMWARE = 1 # :nodoc:
74
+ BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT = 2 # :nodoc:
75
+ BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT = 3 # :nodoc:
76
+ BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT = 4 # :nodoc:
77
+ BOOTLOADER_STATUS_OK = 0 # :nodoc:
78
+ BOOTLOADER_STATUS_INVALID_MODE = 1 # :nodoc:
79
+ BOOTLOADER_STATUS_NO_CHANGE = 2 # :nodoc:
80
+ BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT = 3 # :nodoc:
81
+ BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT = 4 # :nodoc:
82
+ BOOTLOADER_STATUS_CRC_MISMATCH = 5 # :nodoc:
83
+ STATUS_LED_CONFIG_OFF = 0 # :nodoc:
84
+ STATUS_LED_CONFIG_ON = 1 # :nodoc:
85
+ STATUS_LED_CONFIG_SHOW_HEARTBEAT = 2 # :nodoc:
86
+ STATUS_LED_CONFIG_SHOW_STATUS = 3 # :nodoc:
87
+
88
+ # Creates an object with the unique device ID <tt>uid</tt> and adds it to
89
+ # the IP Connection <tt>ipcon</tt>.
90
+ def initialize(uid, ipcon)
91
+ super uid, ipcon
92
+
93
+ @api_version = [2, 0, 0]
94
+
95
+ @response_expected[FUNCTION_GET_DECIBEL] = RESPONSE_EXPECTED_ALWAYS_TRUE
96
+ @response_expected[FUNCTION_SET_DECIBEL_CALLBACK_CONFIGURATION] = RESPONSE_EXPECTED_TRUE
97
+ @response_expected[FUNCTION_GET_DECIBEL_CALLBACK_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
98
+ @response_expected[FUNCTION_GET_SPECTRUM_LOW_LEVEL] = RESPONSE_EXPECTED_ALWAYS_TRUE
99
+ @response_expected[FUNCTION_SET_SPECTRUM_CALLBACK_CONFIGURATION] = RESPONSE_EXPECTED_TRUE
100
+ @response_expected[FUNCTION_GET_SPECTRUM_CALLBACK_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
101
+ @response_expected[FUNCTION_SET_CONFIGURATION] = RESPONSE_EXPECTED_FALSE
102
+ @response_expected[FUNCTION_GET_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
103
+ @response_expected[FUNCTION_GET_SPITFP_ERROR_COUNT] = RESPONSE_EXPECTED_ALWAYS_TRUE
104
+ @response_expected[FUNCTION_SET_BOOTLOADER_MODE] = RESPONSE_EXPECTED_ALWAYS_TRUE
105
+ @response_expected[FUNCTION_GET_BOOTLOADER_MODE] = RESPONSE_EXPECTED_ALWAYS_TRUE
106
+ @response_expected[FUNCTION_SET_WRITE_FIRMWARE_POINTER] = RESPONSE_EXPECTED_FALSE
107
+ @response_expected[FUNCTION_WRITE_FIRMWARE] = RESPONSE_EXPECTED_ALWAYS_TRUE
108
+ @response_expected[FUNCTION_SET_STATUS_LED_CONFIG] = RESPONSE_EXPECTED_FALSE
109
+ @response_expected[FUNCTION_GET_STATUS_LED_CONFIG] = RESPONSE_EXPECTED_ALWAYS_TRUE
110
+ @response_expected[FUNCTION_GET_CHIP_TEMPERATURE] = RESPONSE_EXPECTED_ALWAYS_TRUE
111
+ @response_expected[FUNCTION_RESET] = RESPONSE_EXPECTED_FALSE
112
+ @response_expected[FUNCTION_WRITE_UID] = RESPONSE_EXPECTED_FALSE
113
+ @response_expected[FUNCTION_READ_UID] = RESPONSE_EXPECTED_ALWAYS_TRUE
114
+ @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
115
+
116
+ @callback_formats[CALLBACK_DECIBEL] = 'S'
117
+ @callback_formats[CALLBACK_SPECTRUM_LOW_LEVEL] = 'S S S30'
118
+
119
+ @high_level_callbacks[CALLBACK_SPECTRUM] = [['stream_length', 'stream_chunk_offset', 'stream_chunk_data'], {'fixed_length' => nil, 'single_chunk' => false}, nil]
120
+ end
121
+
122
+ # Returns the measured sound pressure in decibels. The values are given in
123
+ # dB/10 (tenths dB).
124
+ #
125
+ # The Bricklet supports the weighting standards dB(A), dB(B), dB(C), dB(D),
126
+ # dB(Z) and ITU-R 468. You can configure the weighting with BrickletSoundPressureLevel#set_configuration.
127
+ #
128
+ # By default dB(A) will be used.
129
+ #
130
+ #
131
+ # If you want to get the value periodically, it is recommended to use the
132
+ # CALLBACK_DECIBEL callback. You can set the callback configuration
133
+ # with BrickletSoundPressureLevel#set_decibel_callback_configuration.
134
+ def get_decibel
135
+ send_request FUNCTION_GET_DECIBEL, [], '', 2, 'S'
136
+ end
137
+
138
+ # The period in ms is the period with which the CALLBACK_DECIBEL callback is triggered
139
+ # periodically. A value of 0 turns the callback off.
140
+ #
141
+ # If the `value has to change`-parameter is set to true, the callback is only
142
+ # triggered after the value has changed. If the value didn't change
143
+ # within the period, the callback is triggered immediately on change.
144
+ #
145
+ # If it is set to false, the callback is continuously triggered with the period,
146
+ # independent of the value.
147
+ #
148
+ # It is furthermore possible to constrain the callback with thresholds.
149
+ #
150
+ # The `option`-parameter together with min/max sets a threshold for the CALLBACK_DECIBEL callback.
151
+ #
152
+ # The following options are possible:
153
+ #
154
+ # "Option", "Description"
155
+ #
156
+ # "'x'", "Threshold is turned off"
157
+ # "'o'", "Threshold is triggered when the value is *outside* the min and max values"
158
+ # "'i'", "Threshold is triggered when the value is *inside* or equal to the min and max values"
159
+ # "'<'", "Threshold is triggered when the value is smaller than the min value (max is ignored)"
160
+ # "'>'", "Threshold is triggered when the value is greater than the min value (max is ignored)"
161
+ #
162
+ # If the option is set to 'x' (threshold turned off) the callback is triggered with the fixed period.
163
+ #
164
+ # The default value is (0, false, 'x', 0, 0).
165
+ def set_decibel_callback_configuration(period, value_has_to_change, option, min, max)
166
+ send_request FUNCTION_SET_DECIBEL_CALLBACK_CONFIGURATION, [period, value_has_to_change, option, min, max], 'L ? k S S', 0, ''
167
+ end
168
+
169
+ # Returns the callback configuration as set by BrickletSoundPressureLevel#set_decibel_callback_configuration.
170
+ def get_decibel_callback_configuration
171
+ send_request FUNCTION_GET_DECIBEL_CALLBACK_CONFIGURATION, [], '', 10, 'L ? k S S'
172
+ end
173
+
174
+ # Returns the frequency spectrum. The length of the spectrum is between
175
+ # 512 (FFT size 1024) and 64 (FFT size 128). See BrickletSoundPressureLevel#set_configuration.
176
+ #
177
+ # Each array element is one bin of the FFT. The first bin is always the
178
+ # DC offset and the other bins have a size between 40Hz (FFT size 1024) and
179
+ # 320Hz (FFT size 128).
180
+ #
181
+ # In sum the frequency of the spectrum always has a range from 0 to
182
+ # 20480Hz (the FFT is applied to samples with a frequency of 40960Hz).
183
+ #
184
+ # The returned data is already equalized, which means that the microphone
185
+ # frequency response is compensated and the weighting function is applied
186
+ # (see BrickletSoundPressureLevel#set_configuration for the available weighting standards). Use
187
+ # dB(Z) if you need the unaltered spectrum.
188
+ #
189
+ # The values are not in dB form yet. If you want a proper dB scale of the
190
+ # spectrum you have to apply the formula f(x) = 20*log10(max(1, x/sqrt(2)))
191
+ # on each value.
192
+ def get_spectrum_low_level
193
+ send_request FUNCTION_GET_SPECTRUM_LOW_LEVEL, [], '', 64, 'S S S30'
194
+ end
195
+
196
+ # The period in ms is the period with which the CALLBACK_SPECTRUM callback is
197
+ # triggered periodically. A value of 0 turns the callback off.
198
+ #
199
+ # Every new measured spectrum will be send at most once. Set the period to 1 to
200
+ # make sure that you get every spectrum.
201
+ #
202
+ # The default value is 0.
203
+ def set_spectrum_callback_configuration(period)
204
+ send_request FUNCTION_SET_SPECTRUM_CALLBACK_CONFIGURATION, [period], 'L', 0, ''
205
+ end
206
+
207
+ # Returns the callback configuration as set by
208
+ # BrickletSoundPressureLevel#get_spectrum_callback_configuration.
209
+ def get_spectrum_callback_configuration
210
+ send_request FUNCTION_GET_SPECTRUM_CALLBACK_CONFIGURATION, [], '', 4, 'L'
211
+ end
212
+
213
+ # Sets the Sound Pressure Level Bricklet configuration.
214
+ #
215
+ # With different FFT sizes the Bricklet has a different
216
+ # amount of samples per second and the size of the FFT bins
217
+ # changes. The higher the FFT size the more precise is the result
218
+ # of the dB(X) calculation.
219
+ #
220
+ # Available FFT sizes are:
221
+ #
222
+ # * 1024: 512 bins, 10 samples per second, each bin has size 40Hz
223
+ # * 512: 256 bins, 20 samples per second, each bin has size 80Hz
224
+ # * 256: 128 bins, 40 samples per second, each bin has size 160Hz
225
+ # * 128: 64 bins, 80 samples per second, each bin has size 320Hz
226
+ #
227
+ # The Bricklet supports different weighting functions. You can choose
228
+ # between dB(A), dB(B), dB(C), dB(D), dB(Z) and ITU-R 468.
229
+ #
230
+ # dB(A/B/C/D) are the standard dB weighting curves. dB(A) is
231
+ # often used to measure volumes at concerts etc. dB(Z) has a
232
+ # flat response, no weighting is applied. ITU-R 468 is an ITU
233
+ # weighting standard mostly used in the UK and Europe.
234
+ #
235
+ # The defaults are FFT size 1024 and weighting standard dB(A).
236
+ def set_configuration(fft_size, weighting)
237
+ send_request FUNCTION_SET_CONFIGURATION, [fft_size, weighting], 'C C', 0, ''
238
+ end
239
+
240
+ # Returns the configuration as set by BrickletSoundPressureLevel#set_configuration.
241
+ def get_configuration
242
+ send_request FUNCTION_GET_CONFIGURATION, [], '', 2, 'C C'
243
+ end
244
+
245
+ # Returns the error count for the communication between Brick and Bricklet.
246
+ #
247
+ # The errors are divided into
248
+ #
249
+ # * ack checksum errors,
250
+ # * message checksum errors,
251
+ # * frameing errors and
252
+ # * overflow errors.
253
+ #
254
+ # The errors counts are for errors that occur on the Bricklet side. All
255
+ # Bricks have a similar function that returns the errors on the Brick side.
256
+ def get_spitfp_error_count
257
+ send_request FUNCTION_GET_SPITFP_ERROR_COUNT, [], '', 16, 'L L L L'
258
+ end
259
+
260
+ # Sets the bootloader mode and returns the status after the requested
261
+ # mode change was instigated.
262
+ #
263
+ # You can change from bootloader mode to firmware mode and vice versa. A change
264
+ # from bootloader mode to firmware mode will only take place if the entry function,
265
+ # device identifier und crc are present and correct.
266
+ #
267
+ # This function is used by Brick Viewer during flashing. It should not be
268
+ # necessary to call it in a normal user program.
269
+ def set_bootloader_mode(mode)
270
+ send_request FUNCTION_SET_BOOTLOADER_MODE, [mode], 'C', 1, 'C'
271
+ end
272
+
273
+ # Returns the current bootloader mode, see BrickletSoundPressureLevel#set_bootloader_mode.
274
+ def get_bootloader_mode
275
+ send_request FUNCTION_GET_BOOTLOADER_MODE, [], '', 1, 'C'
276
+ end
277
+
278
+ # Sets the firmware pointer for BrickletSoundPressureLevel#write_firmware. The pointer has
279
+ # to be increased by chunks of size 64. The data is written to flash
280
+ # every 4 chunks (which equals to one page of size 256).
281
+ #
282
+ # This function is used by Brick Viewer during flashing. It should not be
283
+ # necessary to call it in a normal user program.
284
+ def set_write_firmware_pointer(pointer)
285
+ send_request FUNCTION_SET_WRITE_FIRMWARE_POINTER, [pointer], 'L', 0, ''
286
+ end
287
+
288
+ # Writes 64 Bytes of firmware at the position as written by
289
+ # BrickletSoundPressureLevel#set_write_firmware_pointer before. The firmware is written
290
+ # to flash every 4 chunks.
291
+ #
292
+ # You can only write firmware in bootloader mode.
293
+ #
294
+ # This function is used by Brick Viewer during flashing. It should not be
295
+ # necessary to call it in a normal user program.
296
+ def write_firmware(data)
297
+ send_request FUNCTION_WRITE_FIRMWARE, [data], 'C64', 1, 'C'
298
+ end
299
+
300
+ # Sets the status LED configuration. By default the LED shows
301
+ # communication traffic between Brick and Bricklet, it flickers once
302
+ # for every 10 received data packets.
303
+ #
304
+ # You can also turn the LED permanently on/off or show a heartbeat.
305
+ #
306
+ # If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
307
+ def set_status_led_config(config)
308
+ send_request FUNCTION_SET_STATUS_LED_CONFIG, [config], 'C', 0, ''
309
+ end
310
+
311
+ # Returns the configuration as set by BrickletSoundPressureLevel#set_status_led_config
312
+ def get_status_led_config
313
+ send_request FUNCTION_GET_STATUS_LED_CONFIG, [], '', 1, 'C'
314
+ end
315
+
316
+ # Returns the temperature in °C as measured inside the microcontroller. The
317
+ # value returned is not the ambient temperature!
318
+ #
319
+ # The temperature is only proportional to the real temperature and it has bad
320
+ # accuracy. Practically it is only useful as an indicator for
321
+ # temperature changes.
322
+ def get_chip_temperature
323
+ send_request FUNCTION_GET_CHIP_TEMPERATURE, [], '', 2, 's'
324
+ end
325
+
326
+ # Calling this function will reset the Bricklet. All configurations
327
+ # will be lost.
328
+ #
329
+ # After a reset you have to create new device objects,
330
+ # calling functions on the existing ones will result in
331
+ # undefined behavior!
332
+ def reset
333
+ send_request FUNCTION_RESET, [], '', 0, ''
334
+ end
335
+
336
+ # Writes a new UID into flash. If you want to set a new UID
337
+ # you have to decode the Base58 encoded UID string into an
338
+ # integer first.
339
+ #
340
+ # We recommend that you use Brick Viewer to change the UID.
341
+ def write_uid(uid)
342
+ send_request FUNCTION_WRITE_UID, [uid], 'L', 0, ''
343
+ end
344
+
345
+ # Returns the current UID as an integer. Encode as
346
+ # Base58 to get the usual string version.
347
+ def read_uid
348
+ send_request FUNCTION_READ_UID, [], '', 4, 'L'
349
+ end
350
+
351
+ # Returns the UID, the UID where the Bricklet is connected to,
352
+ # the position, the hardware and firmware version as well as the
353
+ # device identifier.
354
+ #
355
+ # The position can be 'a', 'b', 'c' or 'd'.
356
+ #
357
+ # The device identifier numbers can be found :ref:`here <device_identifier>`.
358
+ # |device_identifier_constant|
359
+ def get_identity
360
+ send_request FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S'
361
+ end
362
+
363
+ # Returns the frequency spectrum. The length of the spectrum is between
364
+ # 512 (FFT size 1024) and 64 (FFT size 128). See BrickletSoundPressureLevel#set_configuration.
365
+ #
366
+ # Each array element is one bin of the FFT. The first bin is always the
367
+ # DC offset and the other bins have a size between 40Hz (FFT size 1024) and
368
+ # 320Hz (FFT size 128).
369
+ #
370
+ # In sum the frequency of the spectrum always has a range from 0 to
371
+ # 20480Hz (the FFT is applied to samples with a frequency of 40960Hz).
372
+ #
373
+ # The returned data is already equalized, which means that the microphone
374
+ # frequency response is compensated and the weighting function is applied
375
+ # (see BrickletSoundPressureLevel#set_configuration for the available weighting standards). Use
376
+ # dB(Z) if you need the unaltered spectrum.
377
+ #
378
+ # The values are not in dB form yet. If you want a proper dB scale of the
379
+ # spectrum you have to apply the formula f(x) = 20*log10(max(1, x/sqrt(2)))
380
+ # on each value.
381
+ def get_spectrum
382
+ spectrum_length = nil # assigned in block
383
+ spectrum_data = nil # assigned in block
384
+
385
+ @stream_mutex.synchronize {
386
+ ret = get_spectrum_low_level
387
+ spectrum_length = ret[0]
388
+ spectrum_chunk_offset = ret[1]
389
+ spectrum_out_of_sync = spectrum_chunk_offset != 0
390
+ spectrum_data = ret[2]
391
+
392
+ while not spectrum_out_of_sync and spectrum_data.length < spectrum_length
393
+ ret = get_spectrum_low_level
394
+ spectrum_length = ret[0]
395
+ spectrum_chunk_offset = ret[1]
396
+ spectrum_out_of_sync = spectrum_chunk_offset != spectrum_data.length
397
+ spectrum_data += ret[2]
398
+ end
399
+
400
+ if spectrum_out_of_sync # discard remaining stream to bring it back in-sync
401
+ while spectrum_chunk_offset + 30 < spectrum_length
402
+ ret = get_spectrum_low_level
403
+ spectrum_length = ret[0]
404
+ spectrum_chunk_offset = ret[1]
405
+ end
406
+
407
+ raise StreamOutOfSyncException, 'Spectrum stream is out-of-sync'
408
+ end
409
+ }
410
+
411
+ spectrum_data[0, spectrum_length]
412
+ end
413
+
414
+ # Registers a callback with ID <tt>id</tt> to the block <tt>block</tt>.
415
+ def register_callback(id, &block)
416
+ callback = block
417
+ @registered_callbacks[id] = callback
418
+ end
419
+ end
420
+ end