tinkerforge 2.1.4 → 2.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/lib/tinkerforge/brick_dc.rb +42 -4
  2. data/lib/tinkerforge/brick_imu.rb +49 -11
  3. data/lib/tinkerforge/brick_imu_v2.rb +506 -0
  4. data/lib/tinkerforge/brick_master.rb +86 -46
  5. data/lib/tinkerforge/brick_red.rb +36 -5
  6. data/lib/tinkerforge/brick_servo.rb +53 -15
  7. data/lib/tinkerforge/brick_stepper.rb +43 -14
  8. data/lib/tinkerforge/bricklet_accelerometer.rb +229 -0
  9. data/lib/tinkerforge/bricklet_ambient_light.rb +10 -9
  10. data/lib/tinkerforge/bricklet_ambient_light_v2.rb +216 -0
  11. data/lib/tinkerforge/bricklet_analog_in.rb +13 -12
  12. data/lib/tinkerforge/bricklet_analog_in_v2.rb +259 -0
  13. data/lib/tinkerforge/bricklet_analog_out.rb +5 -4
  14. data/lib/tinkerforge/bricklet_analog_out_v2.rb +66 -0
  15. data/lib/tinkerforge/bricklet_barometer.rb +11 -9
  16. data/lib/tinkerforge/bricklet_color.rb +11 -9
  17. data/lib/tinkerforge/bricklet_current12.rb +5 -4
  18. data/lib/tinkerforge/bricklet_current25.rb +5 -4
  19. data/lib/tinkerforge/bricklet_distance_ir.rb +8 -7
  20. data/lib/tinkerforge/bricklet_distance_us.rb +9 -8
  21. data/lib/tinkerforge/bricklet_dual_button.rb +5 -4
  22. data/lib/tinkerforge/bricklet_dual_relay.rb +5 -4
  23. data/lib/tinkerforge/bricklet_dust_detector.rb +178 -0
  24. data/lib/tinkerforge/bricklet_gps.rb +6 -5
  25. data/lib/tinkerforge/bricklet_hall_effect.rb +5 -4
  26. data/lib/tinkerforge/bricklet_humidity.rb +8 -7
  27. data/lib/tinkerforge/bricklet_industrial_analog_out.rb +137 -0
  28. data/lib/tinkerforge/bricklet_industrial_digital_in_4.rb +8 -7
  29. data/lib/tinkerforge/bricklet_industrial_digital_out_4.rb +5 -4
  30. data/lib/tinkerforge/bricklet_industrial_dual_0_20ma.rb +6 -5
  31. data/lib/tinkerforge/bricklet_industrial_dual_analog_in.rb +209 -0
  32. data/lib/tinkerforge/bricklet_industrial_quad_relay.rb +5 -4
  33. data/lib/tinkerforge/bricklet_io16.rb +8 -7
  34. data/lib/tinkerforge/bricklet_io4.rb +8 -7
  35. data/lib/tinkerforge/bricklet_joystick.rb +5 -4
  36. data/lib/tinkerforge/bricklet_laser_range_finder.rb +324 -0
  37. data/lib/tinkerforge/bricklet_lcd_16x2.rb +7 -6
  38. data/lib/tinkerforge/bricklet_lcd_20x4.rb +11 -10
  39. data/lib/tinkerforge/bricklet_led_strip.rb +12 -10
  40. data/lib/tinkerforge/bricklet_line.rb +5 -4
  41. data/lib/tinkerforge/bricklet_linear_poti.rb +8 -7
  42. data/lib/tinkerforge/bricklet_load_cell.rb +261 -0
  43. data/lib/tinkerforge/bricklet_moisture.rb +6 -5
  44. data/lib/tinkerforge/bricklet_motion_detector.rb +5 -4
  45. data/lib/tinkerforge/bricklet_multi_touch.rb +5 -4
  46. data/lib/tinkerforge/bricklet_nfc_rfid.rb +38 -46
  47. data/lib/tinkerforge/bricklet_piezo_buzzer.rb +5 -4
  48. data/lib/tinkerforge/bricklet_piezo_speaker.rb +6 -5
  49. data/lib/tinkerforge/bricklet_ptc.rb +5 -4
  50. data/lib/tinkerforge/bricklet_remote_switch.rb +9 -8
  51. data/lib/tinkerforge/bricklet_rotary_encoder.rb +5 -4
  52. data/lib/tinkerforge/bricklet_rotary_poti.rb +5 -4
  53. data/lib/tinkerforge/bricklet_rs232.rb +183 -0
  54. data/lib/tinkerforge/bricklet_segment_display_4x7.rb +8 -5
  55. data/lib/tinkerforge/bricklet_solid_state_relay.rb +5 -4
  56. data/lib/tinkerforge/bricklet_sound_intensity.rb +6 -5
  57. data/lib/tinkerforge/bricklet_temperature.rb +7 -6
  58. data/lib/tinkerforge/bricklet_temperature_ir.rb +7 -6
  59. data/lib/tinkerforge/bricklet_tilt.rb +5 -4
  60. data/lib/tinkerforge/bricklet_voltage.rb +8 -7
  61. data/lib/tinkerforge/bricklet_voltage_current.rb +5 -4
  62. data/lib/tinkerforge/version.rb +1 -1
  63. metadata +13 -2
@@ -1,18 +1,19 @@
1
1
  # -*- ruby encoding: utf-8 -*-
2
2
  #############################################################
3
- # This file was automatically generated on 2014-12-10. #
3
+ # This file was automatically generated on 2015-11-17. #
4
4
  # #
5
- # Bindings Version 2.1.4 #
5
+ # Bindings Version 2.1.6 #
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
- # to the generator git on tinkerforge.com #
9
+ # to the generators git repository on tinkerforge.com #
10
10
  #############################################################
11
11
 
12
12
  module Tinkerforge
13
- # Device for controlling a LCD with 2 lines a 16 characters
13
+ # 16x2 character alphanumeric display with blue backlight
14
14
  class BrickletLCD16x2 < Device
15
15
  DEVICE_IDENTIFIER = 211 # :nodoc:
16
+ DEVICE_DISPLAY_NAME = 'LCD 16x2 Bricklet' # :nodoc:
16
17
 
17
18
  # This callback is triggered when a button is pressed. The parameter is
18
19
  # the number of the button (0 to 2).
@@ -140,7 +141,7 @@ module Tinkerforge
140
141
  # Custom characters are stored by the LCD in RAM, so they have to be set
141
142
  # after each startup.
142
143
  #
143
- # .. versionadded:: 2.0.1~(Plugin)
144
+ # .. versionadded:: 2.0.1$nbsp;(Plugin)
144
145
  def set_custom_character(index, character)
145
146
  send_request(FUNCTION_SET_CUSTOM_CHARACTER, [index, character], 'C C8', 0, '')
146
147
  end
@@ -148,7 +149,7 @@ module Tinkerforge
148
149
  # Returns the custom character for a given index, as set with
149
150
  # BrickletLCD16x2#set_custom_character.
150
151
  #
151
- # .. versionadded:: 2.0.1~(Plugin)
152
+ # .. versionadded:: 2.0.1$nbsp;(Plugin)
152
153
  def get_custom_character(index)
153
154
  send_request(FUNCTION_GET_CUSTOM_CHARACTER, [index], 'C', 8, 'C8')
154
155
  end
@@ -1,18 +1,19 @@
1
1
  # -*- ruby encoding: utf-8 -*-
2
2
  #############################################################
3
- # This file was automatically generated on 2014-12-10. #
3
+ # This file was automatically generated on 2015-11-17. #
4
4
  # #
5
- # Bindings Version 2.1.4 #
5
+ # Bindings Version 2.1.6 #
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
- # to the generator git on tinkerforge.com #
9
+ # to the generators git repository on tinkerforge.com #
10
10
  #############################################################
11
11
 
12
12
  module Tinkerforge
13
- # Device for controlling a LCD with 4 lines a 20 characters
13
+ # 20x4 character alphanumeric display with blue backlight
14
14
  class BrickletLCD20x4 < Device
15
15
  DEVICE_IDENTIFIER = 212 # :nodoc:
16
+ DEVICE_DISPLAY_NAME = 'LCD 20x4 Bricklet' # :nodoc:
16
17
 
17
18
  # This callback is triggered when a button is pressed. The parameter is
18
19
  # the number of the button (0 to 2 or 0 to 3 since hardware version 1.2).
@@ -149,7 +150,7 @@ module Tinkerforge
149
150
  # Custom characters are stored by the LCD in RAM, so they have to be set
150
151
  # after each startup.
151
152
  #
152
- # .. versionadded:: 2.0.1~(Plugin)
153
+ # .. versionadded:: 2.0.1$nbsp;(Plugin)
153
154
  def set_custom_character(index, character)
154
155
  send_request(FUNCTION_SET_CUSTOM_CHARACTER, [index, character], 'C C8', 0, '')
155
156
  end
@@ -157,7 +158,7 @@ module Tinkerforge
157
158
  # Returns the custom character for a given index, as set with
158
159
  # BrickletLCD20x4#set_custom_character.
159
160
  #
160
- # .. versionadded:: 2.0.1~(Plugin)
161
+ # .. versionadded:: 2.0.1$nbsp;(Plugin)
161
162
  def get_custom_character(index)
162
163
  send_request(FUNCTION_GET_CUSTOM_CHARACTER, [index], 'C', 8, 'C8')
163
164
  end
@@ -168,7 +169,7 @@ module Tinkerforge
168
169
  # The default text is shown on the LCD, if the default text counter
169
170
  # expires, see BrickletLCD20x4#set_default_text_counter.
170
171
  #
171
- # .. versionadded:: 2.0.2~(Plugin)
172
+ # .. versionadded:: 2.0.2$nbsp;(Plugin)
172
173
  def set_default_text(line, text)
173
174
  send_request(FUNCTION_SET_DEFAULT_TEXT, [line, text], 'C Z20', 0, '')
174
175
  end
@@ -176,7 +177,7 @@ module Tinkerforge
176
177
  # Returns the default text for a given line (0-3) as set by
177
178
  # BrickletLCD20x4#set_default_text.
178
179
  #
179
- # .. versionadded:: 2.0.2~(Plugin)
180
+ # .. versionadded:: 2.0.2$nbsp;(Plugin)
180
181
  def get_default_text(line)
181
182
  send_request(FUNCTION_GET_DEFAULT_TEXT, [line], 'C', 20, 'Z20')
182
183
  end
@@ -197,14 +198,14 @@ module Tinkerforge
197
198
  #
198
199
  # The default is -1.
199
200
  #
200
- # .. versionadded:: 2.0.2~(Plugin)
201
+ # .. versionadded:: 2.0.2$nbsp;(Plugin)
201
202
  def set_default_text_counter(counter)
202
203
  send_request(FUNCTION_SET_DEFAULT_TEXT_COUNTER, [counter], 'l', 0, '')
203
204
  end
204
205
 
205
206
  # Returns the current value of the default text counter.
206
207
  #
207
- # .. versionadded:: 2.0.2~(Plugin)
208
+ # .. versionadded:: 2.0.2$nbsp;(Plugin)
208
209
  def get_default_text_counter
209
210
  send_request(FUNCTION_GET_DEFAULT_TEXT_COUNTER, [], '', 4, 'l')
210
211
  end
@@ -1,20 +1,22 @@
1
1
  # -*- ruby encoding: utf-8 -*-
2
2
  #############################################################
3
- # This file was automatically generated on 2014-12-10. #
3
+ # This file was automatically generated on 2015-11-17. #
4
4
  # #
5
- # Bindings Version 2.1.4 #
5
+ # Bindings Version 2.1.6 #
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
- # to the generator git on tinkerforge.com #
9
+ # to the generators git repository on tinkerforge.com #
10
10
  #############################################################
11
11
 
12
12
  module Tinkerforge
13
- # Device to control up to 320 RGB LEDs
13
+ # Controls up to 320 RGB LEDs
14
14
  class BrickletLEDStrip < Device
15
15
  DEVICE_IDENTIFIER = 231 # :nodoc:
16
+ DEVICE_DISPLAY_NAME = 'LED Strip Bricklet' # :nodoc:
16
17
 
17
- # This callback is triggered directly after a new frame is rendered.
18
+ # This callback is triggered directly after a new frame is rendered. The
19
+ # parameter is the number of LEDs in that frame.
18
20
  #
19
21
  # You should send the data for the next frame directly after this callback
20
22
  # was triggered.
@@ -121,7 +123,7 @@ module Tinkerforge
121
123
  send_request(FUNCTION_SET_FRAME_DURATION, [duration], 'S', 0, '')
122
124
  end
123
125
 
124
- # Returns the frame duration as set by BrickletLEDStrip#set_frame_duration.
126
+ # Returns the frame duration in ms as set by BrickletLEDStrip#set_frame_duration.
125
127
  def get_frame_duration
126
128
  send_request(FUNCTION_GET_FRAME_DURATION, [], '', 2, 'S')
127
129
  end
@@ -150,14 +152,14 @@ module Tinkerforge
150
152
  # .. note::
151
153
  # The frequency in firmware version 2.0.0 is fixed at 2MHz.
152
154
  #
153
- # .. versionadded:: 2.0.1~(Plugin)
155
+ # .. versionadded:: 2.0.1$nbsp;(Plugin)
154
156
  def set_clock_frequency(frequency)
155
157
  send_request(FUNCTION_SET_CLOCK_FREQUENCY, [frequency], 'L', 0, '')
156
158
  end
157
159
 
158
160
  # Returns the currently used clock frequency as set by BrickletLEDStrip#set_clock_frequency.
159
161
  #
160
- # .. versionadded:: 2.0.1~(Plugin)
162
+ # .. versionadded:: 2.0.1$nbsp;(Plugin)
161
163
  def get_clock_frequency
162
164
  send_request(FUNCTION_GET_CLOCK_FREQUENCY, [], '', 4, 'L')
163
165
  end
@@ -174,14 +176,14 @@ module Tinkerforge
174
176
  #
175
177
  # The default value is WS2801 (``chip`` = 2801).
176
178
  #
177
- # .. versionadded:: 2.0.2~(Plugin)
179
+ # .. versionadded:: 2.0.2$nbsp;(Plugin)
178
180
  def set_chip_type(chip)
179
181
  send_request(FUNCTION_SET_CHIP_TYPE, [chip], 'S', 0, '')
180
182
  end
181
183
 
182
184
  # Returns the currently used chip type as set by BrickletLEDStrip#set_chip_type.
183
185
  #
184
- # .. versionadded:: 2.0.2~(Plugin)
186
+ # .. versionadded:: 2.0.2$nbsp;(Plugin)
185
187
  def get_chip_type
186
188
  send_request(FUNCTION_GET_CHIP_TYPE, [], '', 2, 'S')
187
189
  end
@@ -1,18 +1,19 @@
1
1
  # -*- ruby encoding: utf-8 -*-
2
2
  #############################################################
3
- # This file was automatically generated on 2014-12-10. #
3
+ # This file was automatically generated on 2015-11-17. #
4
4
  # #
5
- # Bindings Version 2.1.4 #
5
+ # Bindings Version 2.1.6 #
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
- # to the generator git on tinkerforge.com #
9
+ # to the generators git repository on tinkerforge.com #
10
10
  #############################################################
11
11
 
12
12
  module Tinkerforge
13
- # Device that measures reflectivity to allow following a line
13
+ # Measures reflectivity of a surface
14
14
  class BrickletLine < Device
15
15
  DEVICE_IDENTIFIER = 241 # :nodoc:
16
+ DEVICE_DISPLAY_NAME = 'Line Bricklet' # :nodoc:
16
17
 
17
18
  # This callback is triggered periodically with the period that is set by
18
19
  # BrickletLine#set_reflectivity_callback_period. The parameter is the reflectivity
@@ -1,18 +1,19 @@
1
1
  # -*- ruby encoding: utf-8 -*-
2
2
  #############################################################
3
- # This file was automatically generated on 2014-12-10. #
3
+ # This file was automatically generated on 2015-11-17. #
4
4
  # #
5
- # Bindings Version 2.1.4 #
5
+ # Bindings Version 2.1.6 #
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
- # to the generator git on tinkerforge.com #
9
+ # to the generators git repository on tinkerforge.com #
10
10
  #############################################################
11
11
 
12
12
  module Tinkerforge
13
- # Device for sensing Linear Potentiometer input
13
+ # 59mm linear potentiometer
14
14
  class BrickletLinearPoti < Device
15
15
  DEVICE_IDENTIFIER = 213 # :nodoc:
16
+ DEVICE_DISPLAY_NAME = 'Linear Poti Bricklet' # :nodoc:
16
17
 
17
18
  # This callback is triggered periodically with the period that is set by
18
19
  # BrickletLinearPoti#set_position_callback_period. The parameter is the position of the
@@ -71,7 +72,7 @@ module Tinkerforge
71
72
  def initialize(uid, ipcon)
72
73
  super uid, ipcon
73
74
 
74
- @api_version = [2, 0, 0]
75
+ @api_version = [2, 0, 1]
75
76
 
76
77
  @response_expected[FUNCTION_GET_POSITION] = RESPONSE_EXPECTED_ALWAYS_TRUE
77
78
  @response_expected[FUNCTION_GET_ANALOG_VALUE] = RESPONSE_EXPECTED_ALWAYS_TRUE
@@ -169,12 +170,12 @@ module Tinkerforge
169
170
  #
170
171
  # The default value is ('x', 0, 0).
171
172
  def set_position_callback_threshold(option, min, max)
172
- send_request(FUNCTION_SET_POSITION_CALLBACK_THRESHOLD, [option, min, max], 'k s s', 0, '')
173
+ send_request(FUNCTION_SET_POSITION_CALLBACK_THRESHOLD, [option, min, max], 'k S S', 0, '')
173
174
  end
174
175
 
175
176
  # Returns the threshold as set by BrickletLinearPoti#set_position_callback_threshold.
176
177
  def get_position_callback_threshold
177
- send_request(FUNCTION_GET_POSITION_CALLBACK_THRESHOLD, [], '', 5, 'k s s')
178
+ send_request(FUNCTION_GET_POSITION_CALLBACK_THRESHOLD, [], '', 5, 'k S S')
178
179
  end
179
180
 
180
181
  # Sets the thresholds for the CALLBACK_ANALOG_VALUE_REACHED callback.
@@ -0,0 +1,261 @@
1
+ # -*- ruby encoding: utf-8 -*-
2
+ #############################################################
3
+ # This file was automatically generated on 2015-11-17. #
4
+ # #
5
+ # Bindings Version 2.1.6 #
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 weight with a load cell
14
+ class BrickletLoadCell < Device
15
+ DEVICE_IDENTIFIER = 253 # :nodoc:
16
+ DEVICE_DISPLAY_NAME = 'Load Cell Bricklet' # :nodoc:
17
+
18
+ # This callback is triggered periodically with the period that is set by
19
+ # BrickletLoadCell#set_weight_callback_period. The parameter is the weight
20
+ # as measured by the load cell.
21
+ #
22
+ # CALLBACK_WEIGHT is only triggered if the weight has changed since the
23
+ # last triggering.
24
+ CALLBACK_WEIGHT = 17
25
+
26
+ # This callback is triggered when the threshold as set by
27
+ # BrickletLoadCell#set_weight_callback_threshold is reached.
28
+ # The parameter is the weight as measured by the load cell.
29
+ #
30
+ # If the threshold keeps being reached, the callback is triggered periodically
31
+ # with the period as set by BrickletLoadCell#set_debounce_period.
32
+ CALLBACK_WEIGHT_REACHED = 18
33
+
34
+ FUNCTION_GET_WEIGHT = 1 # :nodoc:
35
+ FUNCTION_SET_WEIGHT_CALLBACK_PERIOD = 2 # :nodoc:
36
+ FUNCTION_GET_WEIGHT_CALLBACK_PERIOD = 3 # :nodoc:
37
+ FUNCTION_SET_WEIGHT_CALLBACK_THRESHOLD = 4 # :nodoc:
38
+ FUNCTION_GET_WEIGHT_CALLBACK_THRESHOLD = 5 # :nodoc:
39
+ FUNCTION_SET_DEBOUNCE_PERIOD = 6 # :nodoc:
40
+ FUNCTION_GET_DEBOUNCE_PERIOD = 7 # :nodoc:
41
+ FUNCTION_SET_MOVING_AVERAGE = 8 # :nodoc:
42
+ FUNCTION_GET_MOVING_AVERAGE = 9 # :nodoc:
43
+ FUNCTION_LED_ON = 10 # :nodoc:
44
+ FUNCTION_LED_OFF = 11 # :nodoc:
45
+ FUNCTION_IS_LED_ON = 12 # :nodoc:
46
+ FUNCTION_CALIBRATE = 13 # :nodoc:
47
+ FUNCTION_TARE = 14 # :nodoc:
48
+ FUNCTION_SET_CONFIGURATION = 15 # :nodoc:
49
+ FUNCTION_GET_CONFIGURATION = 16 # :nodoc:
50
+ FUNCTION_GET_IDENTITY = 255 # :nodoc:
51
+
52
+ THRESHOLD_OPTION_OFF = 'x' # :nodoc:
53
+ THRESHOLD_OPTION_OUTSIDE = 'o' # :nodoc:
54
+ THRESHOLD_OPTION_INSIDE = 'i' # :nodoc:
55
+ THRESHOLD_OPTION_SMALLER = '<' # :nodoc:
56
+ THRESHOLD_OPTION_GREATER = '>' # :nodoc:
57
+ RATE_10HZ = 0 # :nodoc:
58
+ RATE_80HZ = 1 # :nodoc:
59
+ GAIN_128X = 0 # :nodoc:
60
+ GAIN_64X = 1 # :nodoc:
61
+ GAIN_32X = 2 # :nodoc:
62
+
63
+ # Creates an object with the unique device ID <tt>uid</tt> and adds it to
64
+ # the IP Connection <tt>ipcon</tt>.
65
+ def initialize(uid, ipcon)
66
+ super uid, ipcon
67
+
68
+ @api_version = [2, 0, 0]
69
+
70
+ @response_expected[FUNCTION_GET_WEIGHT] = RESPONSE_EXPECTED_ALWAYS_TRUE
71
+ @response_expected[FUNCTION_SET_WEIGHT_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE
72
+ @response_expected[FUNCTION_GET_WEIGHT_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
73
+ @response_expected[FUNCTION_SET_WEIGHT_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE
74
+ @response_expected[FUNCTION_GET_WEIGHT_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_ALWAYS_TRUE
75
+ @response_expected[FUNCTION_SET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_TRUE
76
+ @response_expected[FUNCTION_GET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
77
+ @response_expected[FUNCTION_SET_MOVING_AVERAGE] = RESPONSE_EXPECTED_FALSE
78
+ @response_expected[FUNCTION_GET_MOVING_AVERAGE] = RESPONSE_EXPECTED_ALWAYS_TRUE
79
+ @response_expected[FUNCTION_LED_ON] = RESPONSE_EXPECTED_FALSE
80
+ @response_expected[FUNCTION_LED_OFF] = RESPONSE_EXPECTED_FALSE
81
+ @response_expected[FUNCTION_IS_LED_ON] = RESPONSE_EXPECTED_ALWAYS_TRUE
82
+ @response_expected[FUNCTION_CALIBRATE] = RESPONSE_EXPECTED_FALSE
83
+ @response_expected[FUNCTION_TARE] = RESPONSE_EXPECTED_FALSE
84
+ @response_expected[FUNCTION_SET_CONFIGURATION] = RESPONSE_EXPECTED_FALSE
85
+ @response_expected[FUNCTION_GET_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
86
+ @response_expected[CALLBACK_WEIGHT] = RESPONSE_EXPECTED_ALWAYS_FALSE
87
+ @response_expected[CALLBACK_WEIGHT_REACHED] = RESPONSE_EXPECTED_ALWAYS_FALSE
88
+ @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
89
+
90
+ @callback_formats[CALLBACK_WEIGHT] = 'l'
91
+ @callback_formats[CALLBACK_WEIGHT_REACHED] = 'l'
92
+ end
93
+
94
+ # Returns the currently measured weight in grams.
95
+ #
96
+ # If you want to get the weight periodically, it is recommended
97
+ # to use the callback CALLBACK_WEIGHT and set the period with
98
+ # BrickletLoadCell#set_weight_callback_period.
99
+ def get_weight
100
+ send_request(FUNCTION_GET_WEIGHT, [], '', 4, 'l')
101
+ end
102
+
103
+ # Sets the period in ms with which the CALLBACK_WEIGHT callback is triggered
104
+ # periodically. A value of 0 turns the callback off.
105
+ #
106
+ # CALLBACK_WEIGHT is only triggered if the weight has changed since the
107
+ # last triggering.
108
+ #
109
+ # The default value is 0.
110
+ def set_weight_callback_period(period)
111
+ send_request(FUNCTION_SET_WEIGHT_CALLBACK_PERIOD, [period], 'L', 0, '')
112
+ end
113
+
114
+ # Returns the period as set by BrickletLoadCell#set_weight_callback_period.
115
+ def get_weight_callback_period
116
+ send_request(FUNCTION_GET_WEIGHT_CALLBACK_PERIOD, [], '', 4, 'L')
117
+ end
118
+
119
+ # Sets the thresholds for the CALLBACK_WEIGHT_REACHED callback.
120
+ #
121
+ # The following options are possible:
122
+ #
123
+ # "Option", "Description"
124
+ #
125
+ # "'x'", "Callback is turned off"
126
+ # "'o'", "Callback is triggered when the weight is *outside* the min and max values"
127
+ # "'i'", "Callback is triggered when the weight is *inside* the min and max values"
128
+ # "'<'", "Callback is triggered when the weight is smaller than the min value (max is ignored)"
129
+ # "'>'", "Callback is triggered when the weight is greater than the min value (max is ignored)"
130
+ #
131
+ # The default value is ('x', 0, 0).
132
+ def set_weight_callback_threshold(option, min, max)
133
+ send_request(FUNCTION_SET_WEIGHT_CALLBACK_THRESHOLD, [option, min, max], 'k l l', 0, '')
134
+ end
135
+
136
+ # Returns the threshold as set by BrickletLoadCell#set_weight_callback_threshold.
137
+ def get_weight_callback_threshold
138
+ send_request(FUNCTION_GET_WEIGHT_CALLBACK_THRESHOLD, [], '', 9, 'k l l')
139
+ end
140
+
141
+ # Sets the period in ms with which the threshold callback
142
+ #
143
+ # * CALLBACK_WEIGHT_REACHED
144
+ #
145
+ # is triggered, if the threshold
146
+ #
147
+ # * BrickletLoadCell#set_weight_callback_threshold
148
+ #
149
+ # keeps being reached.
150
+ #
151
+ # The default value is 100.
152
+ def set_debounce_period(debounce)
153
+ send_request(FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 0, '')
154
+ end
155
+
156
+ # Returns the debounce period as set by BrickletLoadCell#set_debounce_period.
157
+ def get_debounce_period
158
+ send_request(FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 4, 'L')
159
+ end
160
+
161
+ # Sets the length of a `moving averaging <https://en.wikipedia.org/wiki/Moving_average>`__
162
+ # for the weight value.
163
+ #
164
+ # Setting the length to 1 will turn the averaging off. With less
165
+ # averaging, there is more noise on the data.
166
+ #
167
+ # The range for the averaging is 1-40.
168
+ #
169
+ # The default value is 4.
170
+ def set_moving_average(average)
171
+ send_request(FUNCTION_SET_MOVING_AVERAGE, [average], 'C', 0, '')
172
+ end
173
+
174
+ # Returns the length moving average as set by BrickletLoadCell#set_moving_average.
175
+ def get_moving_average
176
+ send_request(FUNCTION_GET_MOVING_AVERAGE, [], '', 1, 'C')
177
+ end
178
+
179
+ # Turns the LED on.
180
+ def led_on
181
+ send_request(FUNCTION_LED_ON, [], '', 0, '')
182
+ end
183
+
184
+ # Turns the LED off.
185
+ def led_off
186
+ send_request(FUNCTION_LED_OFF, [], '', 0, '')
187
+ end
188
+
189
+ # Returns *true* if the led is on, *false* otherwise.
190
+ def is_led_on
191
+ send_request(FUNCTION_IS_LED_ON, [], '', 1, '?')
192
+ end
193
+
194
+ # To calibrate your Load Cell Bricklet you have to
195
+ #
196
+ # * empty the scale and call this function with 0 and
197
+ # * add a known weight to the scale and call this function with the weight in
198
+ # grams.
199
+ #
200
+ # The calibration is saved in the EEPROM of the Bricklet and only
201
+ # needs to be done once.
202
+ #
203
+ # We recommend to use the Brick Viewer for calibration, you don't need
204
+ # to call this function in your source code.
205
+ def calibrate(weight)
206
+ send_request(FUNCTION_CALIBRATE, [weight], 'L', 0, '')
207
+ end
208
+
209
+ # Sets the currently measured weight as tare weight.
210
+ def tare
211
+ send_request(FUNCTION_TARE, [], '', 0, '')
212
+ end
213
+
214
+ # The measurement rate and gain are configurable.
215
+ #
216
+ # The rate can be either 10Hz or 80Hz. A faster rate will produce more noise.
217
+ # It is additionally possible to add a moving average
218
+ # (see BrickletLoadCell#set_moving_average) to the measurements.
219
+ #
220
+ # The gain can be 128x, 64x or 32x. It represents a measurement range of
221
+ # ±20mV, ±40mV and ±80mV respectively. The Load Cell Bricklet uses an
222
+ # excitation voltage of 5V and most load cells use an output of 2mV/V. That
223
+ # means the voltage range is ±15mV for most load cells (i.e. gain of 128x
224
+ # is best). If you don't know what all of this means you should keep it at
225
+ # 128x, it will most likely be correct.
226
+ #
227
+ # The configuration is saved in the EEPROM of the Bricklet and only
228
+ # needs to be done once.
229
+ #
230
+ # We recommend to use the Brick Viewer for configuration, you don't need
231
+ # to call this function in your source code.
232
+ #
233
+ # The default rate is 10Hz and the default gain is 128x.
234
+ def set_configuration(rate, gain)
235
+ send_request(FUNCTION_SET_CONFIGURATION, [rate, gain], 'C C', 0, '')
236
+ end
237
+
238
+ # Returns the configuration as set by BrickletLoadCell#set_configuration.
239
+ def get_configuration
240
+ send_request(FUNCTION_GET_CONFIGURATION, [], '', 2, 'C C')
241
+ end
242
+
243
+ # Returns the UID, the UID where the Bricklet is connected to,
244
+ # the position, the hardware and firmware version as well as the
245
+ # device identifier.
246
+ #
247
+ # The position can be 'a', 'b', 'c' or 'd'.
248
+ #
249
+ # The device identifier numbers can be found :ref:`here <device_identifier>`.
250
+ # |device_identifier_constant|
251
+ def get_identity
252
+ send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S')
253
+ end
254
+
255
+ # Registers a callback with ID <tt>id</tt> to the block <tt>block</tt>.
256
+ def register_callback(id, &block)
257
+ callback = block
258
+ @registered_callbacks[id] = callback
259
+ end
260
+ end
261
+ end