tinderfridge 0.8.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/lib/tinderfridge/device.rb +45 -4
  3. data/lib/tinderfridge/device_collection.rb +3 -1
  4. data/lib/tinderfridge/device_info.txt +3 -0
  5. data/lib/tinderfridge/devices/brick_esp32/brick_esp32.json +11 -0
  6. data/lib/tinderfridge/devices/brick_esp32/brick_esp32.rb +13 -0
  7. data/lib/tinderfridge/devices/brick_esp32_ethernet/brick_esp32_ethernet.json +11 -0
  8. data/lib/tinderfridge/devices/brick_esp32_ethernet/brick_esp32_ethernet.rb +13 -0
  9. data/lib/tinderfridge/devices/brick_hat/brick_hat.rb +12 -0
  10. data/lib/tinderfridge/devices/brick_hat_zero/brick_hat_zero.rb +10 -0
  11. data/lib/tinderfridge/devices/brick_master/brick_master.json +11 -0
  12. data/lib/tinderfridge/devices/brick_master/brick_master.rb +11 -0
  13. data/lib/tinderfridge/devices/bricklet_air_quality/bricklet_air_quality.rb +15 -0
  14. data/lib/tinderfridge/devices/bricklet_ambient_light_v3/bricklet_ambient_light_v3.json +2 -1
  15. data/lib/tinderfridge/devices/bricklet_analog_in_v3/bricklet_analog_in_v3.json +2 -1
  16. data/lib/tinderfridge/devices/bricklet_barometer_v2/bricklet_barometer_v2.rb +30 -0
  17. data/lib/tinderfridge/devices/bricklet_co2_v2/bricklet_co2_v2.json +2 -1
  18. data/lib/tinderfridge/devices/bricklet_co2_v2/bricklet_co2_v2.rb +29 -0
  19. data/lib/tinderfridge/devices/bricklet_color_v2/bricklet_color_v2.json +2 -1
  20. data/lib/tinderfridge/devices/bricklet_compass/bricklet_compass.json +2 -1
  21. data/lib/tinderfridge/devices/bricklet_distance_us_v2/bricklet_distance_us_v2.json +2 -1
  22. data/lib/tinderfridge/devices/bricklet_dmx/bricklet_dmx.json +2 -1
  23. data/lib/tinderfridge/devices/bricklet_e_paper_296x128/bricklet_e_paper_296x128.json +2 -1
  24. data/lib/tinderfridge/devices/bricklet_energy_monitor/bricklet_energy_monitor.json +2 -1
  25. data/lib/tinderfridge/devices/bricklet_gps_v2/bricklet_gps_v2.json +2 -1
  26. data/lib/tinderfridge/devices/bricklet_gps_v2/bricklet_gps_v2.rb +28 -1
  27. data/lib/tinderfridge/devices/bricklet_gps_v3/bricklet_gps_v3.json +4 -0
  28. data/lib/tinderfridge/devices/bricklet_hall_effect_v2/bricklet_hall_effect_v2.json +2 -1
  29. data/lib/tinderfridge/devices/bricklet_hall_effect_v2/bricklet_hall_effect_v2.rb +16 -0
  30. data/lib/tinderfridge/devices/bricklet_humidity_v2/bricklet_humidity_v2.json +2 -1
  31. data/lib/tinderfridge/devices/bricklet_imu_v3/bricklet_imu_v3.json +2 -1
  32. data/lib/tinderfridge/devices/bricklet_industrial_dual_relay/bricklet_industrial_dual_relay.json +2 -1
  33. data/lib/tinderfridge/devices/bricklet_isolator/bricklet_isolator.json +2 -1
  34. data/lib/tinderfridge/devices/bricklet_joystick_v2/bricklet_joystick_v2.json +2 -1
  35. data/lib/tinderfridge/devices/bricklet_laser_range_finder_v2/bricklet_laser_range_finder_v2.json +2 -1
  36. data/lib/tinderfridge/devices/bricklet_lcd_128x64/bricklet_lcd_128x64.json +2 -1
  37. data/lib/tinderfridge/devices/bricklet_lcd_128x64/bricklet_lcd_128x64.rb +83 -0
  38. data/lib/tinderfridge/devices/bricklet_linear_poti_v2/bricklet_linear_poti_v2.json +2 -1
  39. data/lib/tinderfridge/devices/bricklet_motion_detector_v2/bricklet_motion_detector_v2.json +2 -1
  40. data/lib/tinderfridge/devices/bricklet_motorized_linear_poti/bricklet_motorized_linear_poti.json +2 -1
  41. data/lib/tinderfridge/devices/bricklet_multi_touch_v2/bricklet_multi_touch_v2.json +2 -1
  42. data/lib/tinderfridge/devices/bricklet_nfc/bricklet_nfc.json +2 -1
  43. data/lib/tinderfridge/devices/bricklet_oled_128x64_v2/bricklet_oled_128x64_v2.rb +94 -0
  44. data/lib/tinderfridge/devices/bricklet_outdoor_weather/bricklet_outdoor_weather.json +2 -1
  45. data/lib/tinderfridge/devices/bricklet_outdoor_weather/bricklet_outdoor_weather.rb +9 -0
  46. data/lib/tinderfridge/devices/bricklet_piezo_speaker_v2/bricklet_piezo_speaker_v2.json +2 -1
  47. data/lib/tinderfridge/devices/bricklet_real_time_clock_v2/bricklet_real_time_clock_v2.json +2 -1
  48. data/lib/tinderfridge/devices/bricklet_remote_switch_v2/bricklet_remote_switch_v2.json +2 -1
  49. data/lib/tinderfridge/devices/bricklet_rgb_led_button/bricklet_rgb_led_button.json +2 -1
  50. data/lib/tinderfridge/devices/bricklet_rgb_led_v2/bricklet_rgb_led_v2.json +2 -1
  51. data/lib/tinderfridge/devices/bricklet_rotary_encoder_v2/bricklet_rotary_encoder_v2.json +2 -1
  52. data/lib/tinderfridge/devices/bricklet_rotary_poti_v2/bricklet_rotary_poti_v2.json +2 -1
  53. data/lib/tinderfridge/devices/bricklet_segment_display_4x7_v2/bricklet_segment_display_4x7_v2.rb +2 -0
  54. data/lib/tinderfridge/devices/bricklet_sound_pressure_level/bricklet_sound_pressure_level.json +2 -1
  55. data/lib/tinderfridge/devices/bricklet_sound_pressure_level/bricklet_sound_pressure_level.rb +20 -0
  56. data/lib/tinderfridge/devices/bricklet_temperature_ir_v2/bricklet_temperature_ir_v2.json +2 -1
  57. data/lib/tinderfridge/devices/bricklet_temperature_ir_v2/bricklet_temperature_ir_v2.rb +14 -0
  58. data/lib/tinderfridge/devices/bricklet_temperature_v2/bricklet_temperature_v2.json +2 -1
  59. data/lib/tinderfridge/devices/bricklet_temperature_v2/bricklet_temperature_v2.rb +27 -0
  60. data/lib/tinderfridge/devices/bricklet_thermal_imaging/bricklet_thermal_imaging.json +2 -1
  61. data/lib/tinderfridge/devices/bricklet_thermocouple_v2/bricklet_thermocouple_v2.json +2 -1
  62. data/lib/tinderfridge/devices/bricklet_uv_light_v2/bricklet_uv_light_v2.json +2 -1
  63. data/lib/tinderfridge/devices/bricklet_voltage_current_v2/bricklet_voltage_current_v2.json +2 -1
  64. data/lib/tinderfridge/devices/bricklet_xmc1400_breakout/bricklet_xmc1400_breakout.json +2 -1
  65. data/lib/tinderfridge/ip_connection.rb +19 -11
  66. data/lib/tinderfridge/shared/display_ibm437_encoding.rb +41 -0
  67. data/lib/tinderfridge/tinkerforge.rb +24 -9
  68. data/lib/tinderfridge/version.rb +1 -1
  69. metadata +18 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c1f848437f1877596a58521fdbe213042f6561b42a91c91b60eca2fd3ab1a690
4
- data.tar.gz: '09c7adcf40fabf6eae5ca89316428aeb6cabfa5f4abccbaaf27bd3901535afca'
3
+ metadata.gz: f1c28bf9d30fc0a07640bc0455e0c79625d9c83891eff91d8e6e4227780c57d3
4
+ data.tar.gz: cb7039e16d274378b77af9c065e74ff0ad2ebd07450df034893d04144c5b5302
5
5
  SHA512:
6
- metadata.gz: a84bc2687015ef1c65dd61cac031a7b6e6ff57e22a811784e6160dd5b002badf5f55f11c3883ffa754a6f42d0b5a6e5a085a4c930700c899956d06ec8f533d98
7
- data.tar.gz: c12dcf3ef70b1111f665a3098ab213a75819c2953b3c7cb2ebc020bd00b016588ec70ca0bebbdf72666a84edcc4be345f7aaa67c8ee4f8841262c1fc4afb80a7
6
+ metadata.gz: 3311ac8e16a9233ae652ae8caf50aca8ebe6fa48ba8f0079764da55a8234542d57044ab52c2d7a6358fe22fb57e771c4cef8777e772dff3ad78da1e0e86ba989
7
+ data.tar.gz: 466bc1054d70689af056866a5d784050d6731d71fc711937a59e8a053bc7f17335eee594034f241282f918d773237d401486f62cef209d173e37eb95b559e105
@@ -79,7 +79,7 @@ module Tinkerforge
79
79
 
80
80
  # Returns a programmer-friendly representation of the device.
81
81
  def inspect
82
- "%s (%s@%s:%s)" % [self.class, @uid_string, ipcon.host, ipcon.port]
82
+ "%s (%s@%s:%s)" % [self.class, uid_string, ipcon.host, ipcon.port]
83
83
  end
84
84
 
85
85
  # Returns the device's properties.
@@ -109,7 +109,13 @@ module Tinkerforge
109
109
  [ 'ipcon' , { 'host' => ipcon.host , 'port' => ipcon.port } ],
110
110
 
111
111
  respond_to?('get_chip_temperature' ) ? [ 'chip_temperature' , get_chip_temperature ] : nil,
112
- respond_to?('get_spitfp_error_count') ? [ 'spitfp_error_count', get_spitfp_error_count ] : nil,
112
+
113
+ if respond_to?('get_spitfp_error_count') and (method(:get_spitfp_error_count).arity == 0)
114
+ [ 'spitfp_error_count', get_spitfp_error_count ]
115
+ else
116
+ nil
117
+ end,
118
+
113
119
  respond_to?('get_status_led_config' ) ? [ 'status_led_config' , get_status_led_config ] : nil,
114
120
 
115
121
  ].compact.to_h
@@ -131,9 +137,30 @@ module Tinkerforge
131
137
 
132
138
  # Identifies a Tinkerforge device by blinking its status led.
133
139
  #
134
- # Supports recent devices. When invoked on older devices, does nothing.
140
+ # Supports recent devices. When invoked on some older devices, does nothing.
135
141
  def identify(seconds=10)
136
- if (respond_to? 'get_status_led_config') and (respond_to? 'set_status_led_config')
142
+ case status_led_api_variety
143
+ when 1
144
+ seconds = seconds.to_i
145
+ state = is_status_led_enabled
146
+
147
+ (seconds*2).times do |n|
148
+ if n.even?
149
+ disable_status_led
150
+ else
151
+ enable_status_led
152
+ end
153
+ sleep 0.5
154
+ end
155
+
156
+ if state
157
+ enable_status_led
158
+ else
159
+ disable_status_led
160
+ end
161
+
162
+ seconds
163
+ when 2
137
164
  seconds = seconds.to_i
138
165
  state = get_status_led_config
139
166
 
@@ -175,6 +202,20 @@ module Tinkerforge
175
202
  end
176
203
  end
177
204
 
205
+ def status_led_api_variety
206
+ @status_led_api_variety ||=
207
+ if ( respond_to?('get_status_led_config') &&
208
+ respond_to?('set_status_led_config') )
209
+ 2
210
+ elsif ( respond_to?('is_status_led_enabled') &&
211
+ respond_to?('enable_status_led') &&
212
+ respond_to?('disable_status_led') )
213
+ 1
214
+ else
215
+ nil
216
+ end
217
+ end
218
+
178
219
  end
179
220
 
180
221
  end
@@ -5,6 +5,8 @@ module Tinkerforge
5
5
  # Returns the temperatures as measured inside the microcontrollers of devices in the collection.
6
6
  #
7
7
  # Nil for devices that do not support the get_chip_temperature method.
8
+ #
9
+ # Note: most devices return temperature in °C, but a few return temperature in 1/10 °C.
8
10
  def get_chip_temperature
9
11
  smap 'get_chip_temperature'
10
12
  end
@@ -135,7 +137,7 @@ module Tinkerforge
135
137
  private
136
138
 
137
139
  def smap(m)
138
- map { |k,d| [ k, d.respond_to?(m) ? d.send(m) : nil ] }.to_h
140
+ map { |k,d| [ k, ( d.respond_to?(m) and (d.method(m).arity == 0) ) ? d.send(m) : nil ] }.to_h
139
141
  end
140
142
 
141
143
  end
@@ -16,6 +16,8 @@
16
16
  29 IO-4 Bricklet Tinkerforge::BrickletIO4 bricklet_io4
17
17
  111 HAT Brick Tinkerforge::BrickHAT brick_hat
18
18
  112 HAT Zero Brick Tinkerforge::BrickHATZero brick_hat_zero
19
+ 113 ESP32 Brick Tinkerforge::BrickESP32 brick_esp32
20
+ 115 ESP32 Ethernet Brick Tinkerforge::BrickESP32Ethernet brick_esp32_ethernet
19
21
  210 Joystick Bricklet Tinkerforge::BrickletJoystick bricklet_joystick
20
22
  211 LCD 16x2 Bricklet Tinkerforge::BrickletLCD16x2 bricklet_lcd_16x2
21
23
  212 LCD 20x4 Bricklet Tinkerforge::BrickletLCD20x4 bricklet_lcd_20x4
@@ -142,3 +144,4 @@
142
144
  2164 Industrial PTC Bricklet Tinkerforge::BrickletIndustrialPTC bricklet_industrial_ptc
143
145
  2165 DC Bricklet 2.0 Tinkerforge::BrickletDCV2 bricklet_dc_v2
144
146
  2166 Silent Stepper Bricklet 2.0 Tinkerforge::BrickletSilentStepperV2 bricklet_silent_stepper_v2
147
+ 2171 GPS Bricklet 3.0 Tinkerforge::BrickletGPSV3 bricklet_gps_v3
@@ -0,0 +1,11 @@
1
+ {
2
+ "dimensions": [
3
+ 66,
4
+ 40,
5
+ 9
6
+ ],
7
+ "weight": 14,
8
+ "documentation_en_url": "https://www.tinkerforge.com/en/doc/Hardware/Bricks/ESP32_Brick.html",
9
+ "versions_identifier": "bricks:esp32",
10
+ "released": "2022-04-29"
11
+ }
@@ -0,0 +1,13 @@
1
+ module Tinkerforge
2
+
3
+ class BrickESP32
4
+
5
+ private
6
+
7
+ def _view_21x8
8
+ "ESP32 #{uid_string.rjust 8}"
9
+ end
10
+
11
+ end
12
+
13
+ end
@@ -0,0 +1,11 @@
1
+ {
2
+ "dimensions": [
3
+ 88,
4
+ 45,
5
+ 12
6
+ ],
7
+ "weight": 20,
8
+ "documentation_en_url": "https://www.tinkerforge.com/en/doc/Hardware/Bricks/ESP32_Ethernet_Brick.html",
9
+ "versions_identifier": "bricks:esp32_ethernet",
10
+ "released": "2022-04-29"
11
+ }
@@ -0,0 +1,13 @@
1
+ module Tinkerforge
2
+
3
+ class BrickESP32Ethernet
4
+
5
+ private
6
+
7
+ def _view_21x8
8
+ "ESP32 Eth #{uid_string.rjust 8}"
9
+ end
10
+
11
+ end
12
+
13
+ end
@@ -13,6 +13,18 @@ module Tinkerforge
13
13
  )
14
14
  end
15
15
 
16
+ private
17
+
18
+ def _view_21x8
19
+ volts = get_voltages
20
+ <<~ET
21
+ HAT #{uid_string.rjust 8}
22
+
23
+ USB #{'%5.2f V' % [volts[0]*0.001]}
24
+ DC #{'%5.2f V' % [volts[1]*0.001]}
25
+ ET
26
+ end
27
+
16
28
  end
17
29
 
18
30
  end
@@ -9,6 +9,16 @@ module Tinkerforge
9
9
  )
10
10
  end
11
11
 
12
+ private
13
+
14
+ def _view_21x8
15
+ <<~ET
16
+ HAT Zero #{uid_string.rjust 8}
17
+
18
+ USB #{'%5.2f V' % [get_usb_voltage*0.001]}
19
+ ET
20
+ end
21
+
12
22
  end
13
23
 
14
24
  end
@@ -0,0 +1,11 @@
1
+ {
2
+ "dimensions": [
3
+ 40,
4
+ 40,
5
+ 16
6
+ ],
7
+ "weight": 12,
8
+ "documentation_en_url": "https://www.tinkerforge.com/en/doc/Hardware/Bricks/Master_Brick.html",
9
+ "versions_identifier": "bricks:master",
10
+ "released": ""
11
+ }
@@ -0,0 +1,11 @@
1
+ module Tinkerforge
2
+
3
+ class BrickMaster
4
+
5
+ # Unit returned by #get_chip_temperature. Master Bricks return temperature as 1/10 °C.
6
+ CHIP_TEMPERATURE_UNIT = 0.1
7
+ # REVIEW: This should ideally be part of base Tinkerforge.
8
+
9
+ end
10
+
11
+ end
@@ -15,6 +15,21 @@ module Tinkerforge
15
15
  )
16
16
  end
17
17
 
18
+ # Returns the derived air pressure at sea level.
19
+ #
20
+ # Air pressure is derived from:
21
+ # - air pressure as measured by the Bricklet itself
22
+ # - temperature as measured by the Bricklet itself
23
+ # - altitude of the Bricklet's location (meter)
24
+ #
25
+ # With help from:
26
+ # - https://www.tinkerforge.com/en/doc/Hardware/Bricklets/Barometer_V2.html
27
+ # - https://keisan.casio.com/exec/system/1224575267
28
+ def qff(altitude)
29
+ # QFE / [1 - Tg * H / (273.15 + Tfe + Tg * H)] ^ (0.034163 / Tg)
30
+ (get_air_pressure / (1 - 0.0065 * altitude / (273.15 + (get_temperature * 0.01) + 0.0065 * altitude)) ** (0.034163 / 0.0065)).round
31
+ end
32
+
18
33
  end
19
34
 
20
35
  end
@@ -6,5 +6,6 @@
6
6
  ],
7
7
  "weight": 2,
8
8
  "documentation_en_url": "https://www.tinkerforge.com/en/doc/Hardware/Bricklets/Ambient_Light_V3.html",
9
- "versions_identifier": "bricklets:ambient_light_v3"
9
+ "versions_identifier": "bricklets:ambient_light_v3",
10
+ "released": "2019-01-29"
10
11
  }
@@ -6,5 +6,6 @@
6
6
  ],
7
7
  "weight": 8,
8
8
  "documentation_en_url": "https://www.tinkerforge.com/en/doc/Hardware/Bricklets/Analog_In_V3.html",
9
- "versions_identifier": "bricklets:analog_in_v3"
9
+ "versions_identifier": "bricklets:analog_in_v3",
10
+ "released": "2018-02-26"
10
11
  }
@@ -0,0 +1,30 @@
1
+ module Tinkerforge
2
+
3
+ class BrickletBarometerV2
4
+
5
+ # Returns the device's state.
6
+ def state
7
+ super.merge(
8
+ 'air_pressure' => get_air_pressure,
9
+ 'calibration' => get_calibration,
10
+ 'altitude' => get_altitude,
11
+ 'reference_air_pressure' => get_reference_air_pressure,
12
+ 'temperature' => get_temperature,
13
+ 'moving_average_configuration' => get_moving_average_configuration,
14
+ 'sensor_configuration' => get_sensor_configuration,
15
+ )
16
+ end
17
+
18
+ private
19
+
20
+ def _view_21x8
21
+ <<~ET
22
+ Baro #{uid_string.rjust 8}
23
+
24
+ #{'%7.2f hPa' % [get_air_pressure*0.001]}
25
+ ET
26
+ end
27
+
28
+ end
29
+
30
+ end
@@ -6,5 +6,6 @@
6
6
  ],
7
7
  "weight": 9,
8
8
  "documentation_en_url": "https://www.tinkerforge.com/en/doc/Hardware/Bricklets/CO2_V2.html",
9
- "versions_identifier": "bricklets:co2_v2"
9
+ "versions_identifier": "bricklets:co2_v2",
10
+ "released": "2019-05-20"
10
11
  }
@@ -0,0 +1,29 @@
1
+ module Tinkerforge
2
+
3
+ class BrickletCO2V2
4
+
5
+ # Returns the device's state.
6
+ def state
7
+ av = get_all_values
8
+ super.merge(
9
+ 'co2_concentration' => av[0],
10
+ 'temperature' => av[1],
11
+ 'temperature_offset' => get_temperature_offset,
12
+ 'humidity' => av[2],
13
+ 'air_pressure' => get_air_pressure,
14
+ )
15
+ end
16
+
17
+ private
18
+
19
+ def _view_21x8
20
+ <<~ET
21
+ CO2 #{uid_string.rjust 8}
22
+
23
+ #{'%5d PPM' % get_co2_concentration}
24
+ ET
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -6,5 +6,6 @@
6
6
  ],
7
7
  "weight": 2,
8
8
  "documentation_en_url": "https://www.tinkerforge.com/en/doc/Hardware/Bricklets/Color_V2.html",
9
- "versions_identifier": "bricklets:color_v2"
9
+ "versions_identifier": "bricklets:color_v2",
10
+ "released": "2019-08-22"
10
11
  }
@@ -6,5 +6,6 @@
6
6
  ],
7
7
  "weight": 2,
8
8
  "documentation_en_url": "https://www.tinkerforge.com/en/doc/Hardware/Bricklets/Compass.html",
9
- "versions_identifier": "bricklets:compass"
9
+ "versions_identifier": "bricklets:compass",
10
+ "released": "2019-08-22"
10
11
  }
@@ -6,5 +6,6 @@
6
6
  ],
7
7
  "weight": 9,
8
8
  "documentation_en_url": "https://www.tinkerforge.com/en/doc/Hardware/Bricklets/Distance_US_V2.html",
9
- "versions_identifier": "bricklets:distance_us_v2"
9
+ "versions_identifier": "bricklets:distance_us_v2",
10
+ "released": "2019-08-22"
10
11
  }
@@ -6,5 +6,6 @@
6
6
  ],
7
7
  "weight": 30,
8
8
  "documentation_en_url": "https://www.tinkerforge.com/en/doc/Hardware/Bricklets/DMX.html",
9
- "versions_identifier": "bricklets:dmx"
9
+ "versions_identifier": "bricklets:dmx",
10
+ "released": "2017-11-17"
10
11
  }
@@ -6,5 +6,6 @@
6
6
  ],
7
7
  "weight": 20,
8
8
  "documentation_en_url": "https://www.tinkerforge.com/en/doc/Hardware/Bricklets/EPaper_296x128.html",
9
- "versions_identifier": "bricklets:e_paper_296x128"
9
+ "versions_identifier": "bricklets:e_paper_296x128",
10
+ "released": "2019-05-20"
10
11
  }
@@ -6,5 +6,6 @@
6
6
  ],
7
7
  "weight": 7,
8
8
  "documentation_en_url": "https://www.tinkerforge.com/en/doc/Hardware/Bricklets/Energy_Monitor.html",
9
- "versions_identifier": "bricklets:energy_monitor"
9
+ "versions_identifier": "bricklets:energy_monitor",
10
+ "released": "2019-08-22"
10
11
  }
@@ -6,5 +6,6 @@
6
6
  ],
7
7
  "weight": 20,
8
8
  "documentation_en_url": "https://www.tinkerforge.com/en/doc/Hardware/Bricklets/GPS_V2.html",
9
- "versions_identifier": "bricklets:gps_v2"
9
+ "versions_identifier": "bricklets:gps_v2",
10
+ "released": "2017-05-11"
10
11
  }
@@ -2,11 +2,24 @@ module Tinkerforge
2
2
 
3
3
  class BrickletGPSV2
4
4
 
5
+ # Returns the device's state.
6
+ def state
7
+ super.merge(
8
+ 'fix_led_config' => get_fix_led_config,
9
+ 'fix' => fix?,
10
+ )
11
+ end
12
+
13
+ # Returns true if a fix is available.
14
+ def fix?
15
+ get_status[0]
16
+ end
17
+
5
18
  # Returns latitude and longitude as reported by the GPS Bricklet.
6
19
  #
7
20
  # Nil when there is no fix (position not determined).
8
21
  def coordinates
9
- if get_status[0]
22
+ if fix?
10
23
  c = get_coordinates
11
24
  [
12
25
  c[0] / (c[1] == 'N' ? 1000000.0 : -1000000.0),
@@ -26,6 +39,20 @@ module Tinkerforge
26
39
  Time.gm *dt.map(&:to_i)
27
40
  end
28
41
 
42
+ # Returns a URL for viewing the current coordinates on OpenStreetMap.
43
+ def openstreetmap_marker_url(zoom=12)
44
+ if c = coordinates
45
+ "https://www.openstreetmap.org/?mlat=%f&mlon=%f&zoom=%d" % [c, zoom].flatten
46
+ end
47
+ end
48
+
49
+ private
50
+
51
+ def _view_21x8
52
+ "GPS #{uid_string.rjust 8}\n\n" +
53
+ ((c = coordinates) ? (" Lat %10.5f\n Lon %10.5f" % c) : ' no fix')
54
+ end
55
+
29
56
  end
30
57
 
31
58
  end
@@ -0,0 +1,4 @@
1
+ {
2
+ "documentation_en_url": "https://www.tinkerforge.com/en/doc/Hardware/Bricklets/GPS_V3.html",
3
+ "released": "2022-05-09"
4
+ }
@@ -6,5 +6,6 @@
6
6
  ],
7
7
  "weight": 2,
8
8
  "documentation_en_url": "https://www.tinkerforge.com/en/doc/Hardware/Bricklets/Hall_Effect_V2.html",
9
- "versions_identifier": "bricklets:hall_effect_v2"
9
+ "versions_identifier": "bricklets:hall_effect_v2",
10
+ "released": "2019-05-20"
10
11
  }
@@ -0,0 +1,16 @@
1
+ module Tinkerforge
2
+
3
+ class BrickletHallEffectV2
4
+
5
+ # Returns the device's state.
6
+ def state
7
+ super.merge(
8
+ 'magnetic_flux_density' => get_magnetic_flux_density,
9
+ 'counter' => get_counter(false),
10
+ 'counter_config' => get_counter_config,
11
+ )
12
+ end
13
+
14
+ end
15
+
16
+ end
@@ -6,5 +6,6 @@
6
6
  ],
7
7
  "weight": 3,
8
8
  "documentation_en_url": "https://www.tinkerforge.com/en/doc/Hardware/Bricklets/Humidity_V2.html",
9
- "versions_identifier": "bricklets:humidity_v2"
9
+ "versions_identifier": "bricklets:humidity_v2",
10
+ "released": "2017-11-17"
10
11
  }
@@ -6,5 +6,6 @@
6
6
  ],
7
7
  "weight": 3,
8
8
  "documentation_en_url": "https://www.tinkerforge.com/en/doc/Hardware/Bricklets/IMU_V3.html",
9
- "versions_identifier": "bricklets:imu_v3"
9
+ "versions_identifier": "bricklets:imu_v3",
10
+ "released": "2020-10-27"
10
11
  }
@@ -6,5 +6,6 @@
6
6
  ],
7
7
  "weight": 29.4,
8
8
  "documentation_en_url": "https://www.tinkerforge.com/en/doc/Hardware/Bricklets/Industrial_Dual_Relay.html",
9
- "versions_identifier": "bricklets:industrial_dual_relay"
9
+ "versions_identifier": "bricklets:industrial_dual_relay",
10
+ "released": "2018-06-07"
10
11
  }
@@ -6,5 +6,6 @@
6
6
  ],
7
7
  "weight": 7.1,
8
8
  "documentation_en_url": "https://www.tinkerforge.com/en/doc/Hardware/Bricklets/Isolator.html",
9
- "versions_identifier": "bricklets:isolator"
9
+ "versions_identifier": "bricklets:isolator",
10
+ "released": "2018-09-10"
10
11
  }
@@ -6,5 +6,6 @@
6
6
  ],
7
7
  "weight": 15,
8
8
  "documentation_en_url": "https://www.tinkerforge.com/en/doc/Hardware/Bricklets/Joystick_V2.html",
9
- "versions_identifier": "bricklets:joystick_v2"
9
+ "versions_identifier": "bricklets:joystick_v2",
10
+ "released": "2019-05-20"
10
11
  }
@@ -6,5 +6,6 @@
6
6
  ],
7
7
  "weight": 30,
8
8
  "documentation_en_url": "https://www.tinkerforge.com/en/doc/Hardware/Bricklets/Laser_Range_Finder_V2.html",
9
- "versions_identifier": "bricklets:laser_range_finder_v2"
9
+ "versions_identifier": "bricklets:laser_range_finder_v2",
10
+ "released": "2019-05-20"
10
11
  }
@@ -6,5 +6,6 @@
6
6
  ],
7
7
  "weight": 55,
8
8
  "documentation_en_url": "https://www.tinkerforge.com/en/doc/Hardware/Bricklets/LCD_128x64.html",
9
- "versions_identifier": "bricklets:lcd_128x64"
9
+ "versions_identifier": "bricklets:lcd_128x64",
10
+ "released": "2018-09-27"
10
11
  }
@@ -1,7 +1,21 @@
1
+ require 'tinderfridge/shared/display_ibm437_encoding'
2
+
1
3
  module Tinkerforge
2
4
 
3
5
  class BrickletLCD128x64
4
6
 
7
+ include Tinkerforge::Shared::IBM437_encoding
8
+
9
+ # Encodes a string in the IBM437 character set used by some displays.
10
+ #
11
+ # Characters that can not be encoded are replaced with '?'.
12
+ #
13
+ # See:
14
+ # - https://en.wikipedia.org/wiki/Code_page_437
15
+ def encode(string)
16
+ ibm437_encode(string)
17
+ end
18
+
5
19
  # Returns the current setting for the backlight (0..100).
6
20
  def backlight
7
21
  get_display_configuration[1]
@@ -20,12 +34,81 @@ module Tinkerforge
20
34
  true
21
35
  end
22
36
 
37
+ # Returns the current contrast setting (0..63).
38
+ def contrast
39
+ get_display_configuration[0]
40
+ end
41
+
42
+ # Sets the contrast (0..63).
43
+ def contrast=(value)
44
+ state = get_display_configuration
45
+ state[0] = value.to_i
46
+ set_display_configuration *state
47
+ end
48
+
23
49
  # Clears the display, including the GUI.
24
50
  def clear
25
51
  clear_display
26
52
  remove_all_gui
27
53
  end
28
54
 
55
+ # Returns true if automatic draw is set to false.
56
+ def buffered?
57
+ ! get_display_configuration[3]
58
+ end
59
+
60
+ # Draws the currently buffered frame.
61
+ def redraw(force_complete_redraw=false)
62
+ draw_buffered_frame force_complete_redraw
63
+ end
64
+
65
+ alias flush redraw
66
+
67
+ # Returns the device's state.
68
+ def state
69
+ super.merge(
70
+ 'touch_led_config' => get_touch_led_config,
71
+ 'display_configuration' => get_display_configuration,
72
+ )
73
+ end
74
+
75
+ # Clears the display and prints upto 8 lines of text.
76
+ #
77
+ # Text may contain newline characters to separate lines.
78
+ # Lines longer than 21 characters will be wrapped.
79
+ #
80
+ # Text is automatically encoded in the IBM437 character set.
81
+ # @example
82
+ # my_lcd.put_screen "Hello, World!\n\nRuby #{RUBY_VERSION}"
83
+ def put_screen(text='', test: false)
84
+ lines = text.split("\n")
85
+ lines = lines.map { |s| s.empty? ? '' : s.scan(/.{1,21}/) }.flatten
86
+ lines = lines[0,8].map { |l| encode l }
87
+
88
+ return lines if test
89
+
90
+ clear
91
+ lines.each_with_index do |s,l|
92
+ write_line l, 0, s
93
+ end
94
+ nil
95
+ end
96
+
97
+ # Shows an object.
98
+ def show(object)
99
+ if object.respond_to?( :_view_21x8, true)
100
+ put_screen ( object.send(:_view_21x8) rescue "21x8 view error\n\n#{object.class.to_s}" )
101
+ elsif
102
+ put_screen object.inspect[0,168]
103
+ end
104
+ end
105
+
106
+ private
107
+
108
+ def _view_21x8
109
+ "LCD #{uid_string.rjust 8}"
110
+ end
111
+
29
112
  end
30
113
 
31
114
  end