tinderfridge 0.11.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (22) hide show
  1. checksums.yaml +4 -4
  2. data/lib/tinderfridge/device.rb +6 -0
  3. data/lib/tinderfridge/device_collection.rb +18 -1
  4. data/lib/tinderfridge/devices/brick_esp32_ethernet/brick_esp32_ethernet.rb +1 -1
  5. data/lib/tinderfridge/devices/bricklet_ambient_light_v3/bricklet_ambient_light_v3.rb +9 -0
  6. data/lib/tinderfridge/devices/bricklet_barometer_v2/bricklet_barometer_v2.rb +2 -5
  7. data/lib/tinderfridge/devices/bricklet_co2_v2/bricklet_co2_v2.rb +2 -5
  8. data/lib/tinderfridge/devices/bricklet_gps_v2/bricklet_gps_v2.json +1 -1
  9. data/lib/tinderfridge/devices/bricklet_gps_v2/bricklet_gps_v2.rb +1 -1
  10. data/lib/tinderfridge/devices/bricklet_gps_v3/bricklet_gps_v3.json +7 -0
  11. data/lib/tinderfridge/devices/bricklet_gps_v3/bricklet_gps_v3.rb +58 -0
  12. data/lib/tinderfridge/devices/bricklet_lcd_128x64/bricklet_lcd_128x64.rb +1 -1
  13. data/lib/tinderfridge/devices/bricklet_oled_128x64_v2/bricklet_oled_128x64_v2.rb +1 -1
  14. data/lib/tinderfridge/devices/bricklet_outdoor_weather/bricklet_outdoor_weather.rb +15 -3
  15. data/lib/tinderfridge/devices/bricklet_piezo_speaker_v2/bricklet_piezo_speaker_v2.rb +14 -0
  16. data/lib/tinderfridge/devices/bricklet_segment_display_4x7_v2/bricklet_segment_display_4x7_v2.rb +31 -0
  17. data/lib/tinderfridge/devices/bricklet_solid_state_relay_v2/bricklet_solid_state_relay_v2.rb +22 -0
  18. data/lib/tinderfridge/devices/bricklet_temperature_v2/bricklet_temperature_v2.rb +3 -7
  19. data/lib/tinderfridge/ip_connection.rb +15 -0
  20. data/lib/tinderfridge/tinkerforge.rb +13 -0
  21. data/lib/tinderfridge/version.rb +1 -1
  22. metadata +5 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f1c28bf9d30fc0a07640bc0455e0c79625d9c83891eff91d8e6e4227780c57d3
4
- data.tar.gz: cb7039e16d274378b77af9c065e74ff0ad2ebd07450df034893d04144c5b5302
3
+ metadata.gz: 2805da1fbb45d1938cde253637d7a66119718191692caf44ceb22f5d684ed58a
4
+ data.tar.gz: 5e3dbb8a81b3a5f59975a0b4ef4f1c5cbaa76e97d1fc6d9034cd14edc0f0371b
5
5
  SHA512:
6
- metadata.gz: 3311ac8e16a9233ae652ae8caf50aca8ebe6fa48ba8f0079764da55a8234542d57044ab52c2d7a6358fe22fb57e771c4cef8777e772dff3ad78da1e0e86ba989
7
- data.tar.gz: 466bc1054d70689af056866a5d784050d6731d71fc711937a59e8a053bc7f17335eee594034f241282f918d773237d401486f62cef209d173e37eb95b559e105
6
+ metadata.gz: e5d86b78c3c4351b63d9bcbad1032a661d6fdd9b00457a59deaed677d358577781fdc2809ebe7f8a7c762c77638685d601349bb2065930e9f5dad8232ae61a2f
7
+ data.tar.gz: bc3e28b83f1704169827b0a4650e1f5a360714d70e5f153e62e4428f33360821e2514e31a10ff089cdfa4955225656106b26e314b03d6b24cdf91fe7190014a9
@@ -15,6 +15,7 @@ module Tinkerforge
15
15
  # With help from:
16
16
  # - https://stackoverflow.com/questions/2393697
17
17
  def descendants
18
+ # NOTE: Ruby 3.1 has Class#subclasses
18
19
  ObjectSpace.each_object(Class).select { |klass| klass < self }
19
20
  end
20
21
 
@@ -121,6 +122,11 @@ module Tinkerforge
121
122
  ].compact.to_h
122
123
  end
123
124
 
125
+ # Returns configuration data for the device (a mutable Hash).
126
+ def config
127
+ @config ||= {}
128
+ end
129
+
124
130
  # Opens the online documentation for the device (Mac OS only).
125
131
  #
126
132
  # When the URL for the documentation is not known, does nothing.
@@ -61,7 +61,7 @@ module Tinkerforge
61
61
  # Prints a list of devices in the collection.
62
62
  def ls
63
63
  keys.sort_by(&:downcase).each do |k|
64
- puts "%-8s %.40s" % [k, Tinkerforge.device_info(self[k])[1]]
64
+ puts "%-8s %.40s" % [k, self[k].device_display_name]
65
65
  end.size
66
66
  end
67
67
 
@@ -77,6 +77,11 @@ module Tinkerforge
77
77
  smap 'state'
78
78
  end
79
79
 
80
+ # Returns configuration data of devices in the collection.
81
+ def config
82
+ smap 'config'
83
+ end
84
+
80
85
  # Opens the online documentation for the devices in the collection (Mac OS only).
81
86
  #
82
87
  # When the URL for a device's documentation is not known, does nothing.
@@ -86,6 +91,18 @@ module Tinkerforge
86
91
 
87
92
  alias doc open_documentation
88
93
 
94
+ # On Mac OS, opens a new Brick Viewer for each unique
95
+ # IP Connection used by devices in the collection.
96
+ #
97
+ # Not supported on other platforms.
98
+ #
99
+ # Requires Brick Viewer version 2.4.23 or later.
100
+ def open_brick_viewer
101
+ ipcons.map { |i| i.open_brick_viewer }
102
+ end
103
+
104
+ alias brickv open_brick_viewer
105
+
89
106
  # Turns off light sources such as screens and RGB LEDs for devices in the collection.
90
107
  #
91
108
  # Ignores devices that do not support the blackout method.
@@ -5,7 +5,7 @@ module Tinkerforge
5
5
  private
6
6
 
7
7
  def _view_21x8
8
- "ESP32 Eth #{uid_string.rjust 8}"
8
+ "ESP32Eth #{uid_string.rjust 8}"
9
9
  end
10
10
 
11
11
  end
@@ -14,6 +14,15 @@ module Tinkerforge
14
14
  )
15
15
  end
16
16
 
17
+ private
18
+
19
+ def _view_21x8
20
+ s = state
21
+ "AmbiLightV3 #{uid_string.rjust 8}\n\n\n" +
22
+ ("%.2f Lux" % [0.01 * s['illuminance_raw']]).center(21) + "\n\n\n\n" +
23
+ ("max %d / %d ms" % [ s['illuminance_range'], s['integration_time'] ]).center(21)
24
+ end
25
+
17
26
  end
18
27
 
19
28
  end
@@ -18,11 +18,8 @@ module Tinkerforge
18
18
  private
19
19
 
20
20
  def _view_21x8
21
- <<~ET
22
- Baro #{uid_string.rjust 8}
23
-
24
- #{'%7.2f hPa' % [get_air_pressure*0.001]}
25
- ET
21
+ "BaroV2 #{uid_string.rjust 8}\n\n\n" +
22
+ ('%.2f hPa' % [get_air_pressure*0.001]).center(21)
26
23
  end
27
24
 
28
25
  end
@@ -17,11 +17,8 @@ module Tinkerforge
17
17
  private
18
18
 
19
19
  def _view_21x8
20
- <<~ET
21
- CO2 #{uid_string.rjust 8}
22
-
23
- #{'%5d PPM' % get_co2_concentration}
24
- ET
20
+ "CO2V2 #{uid_string.rjust 8}\n\n\n" +
21
+ ('%d PPM' % get_co2_concentration).center(21)
25
22
  end
26
23
 
27
24
  end
@@ -4,7 +4,7 @@
4
4
  35,
5
5
  12
6
6
  ],
7
- "weight": 20,
7
+ "weight": 16,
8
8
  "documentation_en_url": "https://www.tinkerforge.com/en/doc/Hardware/Bricklets/GPS_V2.html",
9
9
  "versions_identifier": "bricklets:gps_v2",
10
10
  "released": "2017-05-11"
@@ -49,7 +49,7 @@ module Tinkerforge
49
49
  private
50
50
 
51
51
  def _view_21x8
52
- "GPS #{uid_string.rjust 8}\n\n" +
52
+ "GPSV2 #{uid_string.rjust 8}\n\n" +
53
53
  ((c = coordinates) ? (" Lat %10.5f\n Lon %10.5f" % c) : ' no fix')
54
54
  end
55
55
 
@@ -1,4 +1,11 @@
1
1
  {
2
+ "dimensions": [
3
+ 40,
4
+ 40,
5
+ 12
6
+ ],
7
+ "weight": 12,
2
8
  "documentation_en_url": "https://www.tinkerforge.com/en/doc/Hardware/Bricklets/GPS_V3.html",
9
+ "versions_identifier": "bricklets:gps_v3",
3
10
  "released": "2022-05-09"
4
11
  }
@@ -0,0 +1,58 @@
1
+ module Tinkerforge
2
+
3
+ class BrickletGPSV3
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
+
18
+ # Returns latitude and longitude as reported by the GPS Bricklet.
19
+ #
20
+ # Nil when there is no fix (position not determined).
21
+ def coordinates
22
+ if fix?
23
+ c = get_coordinates
24
+ [
25
+ c[0] / (c[1] == 'N' ? 1000000.0 : -1000000.0),
26
+ c[2] / (c[3] == 'E' ? 1000000.0 : -1000000.0)
27
+ ]
28
+ else
29
+ nil
30
+ end
31
+ end
32
+
33
+ # Returns a Time object representing the time as reported by the GPS Bricklet.
34
+ def time
35
+ # FIXME: This will not work after 31-Dec-2099.
36
+ dt = get_date_time.map &:to_s
37
+ dt = dt[0].rjust(6,'0').unpack('a2a2a2').reverse + dt[1].rjust(9,'0').concat('000').unpack('a2a2a2a6')
38
+ dt[0].prepend '20'
39
+ Time.gm *dt.map(&:to_i)
40
+ end
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
+ "GPSV3 #{uid_string.rjust 8}\n\n" +
53
+ ((c = coordinates) ? (" Lat %10.5f\n Lon %10.5f" % c) : ' no fix')
54
+ end
55
+
56
+ end
57
+
58
+ end
@@ -106,7 +106,7 @@ module Tinkerforge
106
106
  private
107
107
 
108
108
  def _view_21x8
109
- "LCD #{uid_string.rjust 8}"
109
+ "LCD128x64 #{uid_string.rjust 8}"
110
110
  end
111
111
 
112
112
  end
@@ -86,7 +86,7 @@ module Tinkerforge
86
86
  private
87
87
 
88
88
  def _view_21x8
89
- "OLED #{uid_string.rjust 8}"
89
+ "OLED128x64V2 #{uid_string.rjust 8}"
90
90
  end
91
91
 
92
92
  end
@@ -2,15 +2,27 @@ module Tinkerforge
2
2
 
3
3
  class BrickletOutdoorWeather
4
4
 
5
+ # Returns the device's state.
6
+ def state
7
+ super.merge(
8
+ 'sensor_data' => sensors,
9
+ )
10
+ end
11
+
5
12
  # Returns the last measured data for all sensors.
6
13
  #
7
- # The result is a Hash, with sensor identifiers as the keys. Values per sensor are:
14
+ # The result is a Hash, with sensor identifiers (or their mapped values) as the keys. Values per sensor are:
8
15
  # - 0: Temperature (°C)
9
16
  # - 1: Relative humidity (%RH)
10
17
  # - 2: Last change (seconds)
18
+ #
19
+ # Sensor identifiers can be mapped to descriptive strings or other values:
20
+ # @example
21
+ # my_weather_bricklet.config['sensormap'] = { 202 => 'outdoors' }
11
22
  def sensors
23
+ sensormap = (config['sensormap'].class == Hash) ? config['sensormap'] : {}
12
24
  get_sensor_identifiers.map do |id|
13
- [ id, get_sensor_data(id).each_with_index.map { |v,i| i == 0 ? v/10.0 : v } ]
25
+ [ (sensormap[id] || id), get_sensor_data(id).each_with_index.map { |v,i| i == 0 ? v/10.0 : v } ]
14
26
  end.to_h
15
27
  end
16
28
 
@@ -19,7 +31,7 @@ module Tinkerforge
19
31
  def _view_21x8
20
32
  "Weather #{uid_string.rjust 8}\n\n" +
21
33
  sensors.first(6).map do |k,v|
22
- %Q(#{v[2] > 100 ? '?' : ' '} %3d %4.1f °C %2d %%\n) % [k,v].flatten
34
+ %Q(#{v[2] > 100 ? '!' : ' '}%-8.8s %5.1f°C%3d%%\n) % [k,v].flatten
23
35
  end.join
24
36
  end
25
37
 
@@ -0,0 +1,14 @@
1
+ module Tinkerforge
2
+
3
+ class BrickletPiezoSpeakerV2
4
+
5
+ # Beeps briefly.
6
+ #
7
+ # Volume (0..10) defaults to 0.
8
+ def blip(volume=0)
9
+ set_beep(600, volume, 80)
10
+ end
11
+
12
+ end
13
+
14
+ end
@@ -112,7 +112,9 @@ module Tinkerforge
112
112
 
113
113
  '_' => '0001000',
114
114
  '-' => '0000001',
115
+ '¯' => '1000000',
115
116
  '=' => '0001001',
117
+ '≡' => '1001001',
116
118
 
117
119
  '(' => '1001110',
118
120
  ')' => '1111000',
@@ -147,6 +149,35 @@ module Tinkerforge
147
149
  [value1, value2]
148
150
  end
149
151
 
152
+ # Returns the current thread automatically updating the display.
153
+ def thread
154
+ @thread
155
+ end
156
+
157
+ # Stops automatic updating of the display.
158
+ def stop
159
+ if thread
160
+ thread.exit
161
+ @thread = nil
162
+ end
163
+ end
164
+
165
+ # Continuously displays the current time, in 24-hour format.
166
+ #
167
+ # Starts a new thread automatically updating the display. Use the stop method to end.
168
+ #
169
+ # By default uses local time, or optionally UTC.
170
+ def clock(utc=false)
171
+ stop
172
+ @thread = Thread.new do
173
+ while true
174
+ t = utc ? Time.now.getutc : Time.now
175
+ print t.strftime("%H#{t.sec.even? ? ':' : ''}%M")
176
+ sleep 0.5
177
+ end
178
+ end
179
+ end
180
+
150
181
  end
151
182
 
152
183
  end
@@ -0,0 +1,22 @@
1
+ module Tinkerforge
2
+
3
+ class BrickletSolidStateRelayV2
4
+
5
+ # Returns the device's state.
6
+ def state
7
+ super.merge(
8
+ 'value' => get_state,
9
+ 'monoflop' => get_monoflop,
10
+ )
11
+ end
12
+
13
+ private
14
+
15
+ def _view_21x8
16
+ "SSRelayV2 #{uid_string.rjust 8}\n\n\n" +
17
+ (get_state ? 'ON' : 'Off').center(21)
18
+ end
19
+
20
+ end
21
+
22
+ end
@@ -13,13 +13,9 @@ module Tinkerforge
13
13
  private
14
14
 
15
15
  def _view_21x8
16
- <<~ET
17
- Temp #{uid_string.rjust 8}
18
-
19
- #{'%6.2f °C' % [get_temperature*0.01]}
20
-
21
- #{get_heater_configuration == 1 ? 'HEATER' : ''}
22
- ET
16
+ "TempV2 #{uid_string.rjust 8}\n\n\n" +
17
+ ('%.2f °C' % [get_temperature*0.01]).center(21) +
18
+ (get_heater_configuration == 1 ? "\n\n\n HEATER" : '')
23
19
  end
24
20
 
25
21
  end
@@ -105,6 +105,21 @@ module Tinkerforge
105
105
  list
106
106
  end
107
107
 
108
+ # On Mac OS, opens a new Brick Viewer,
109
+ # connected to the IP Connection's host and port.
110
+ #
111
+ # Not supported on other platforms.
112
+ #
113
+ # Requires Brick Viewer version 2.4.23 or later.
114
+ def open_brick_viewer
115
+ if RUBY_PLATFORM =~ /darwin/
116
+ `open -n -a Brickv --args #{host} --port #{port}`
117
+ "#{host}:#{port}"
118
+ end
119
+ end
120
+
121
+ alias brickv open_brick_viewer
122
+
108
123
  private
109
124
 
110
125
  # Takes the args supplied by an enumeration callback, and returns a device instance.
@@ -30,6 +30,19 @@ module Tinkerforge
30
30
  connect('localhost', port).discover(0.25)
31
31
  end
32
32
 
33
+ private
34
+
35
+ def _view_21x8
36
+ "\n" +
37
+ 'Tinkerforge'.center(21) +
38
+ "\n" +
39
+ VERSION.center(21) +
40
+ "\n\n\n\n" +
41
+ "Tinderfridge #{TINDERFRIDGE_VERSION}".center(21) +
42
+ "\n" +
43
+ "Ruby #{RUBY_VERSION}".center(21)
44
+ end
45
+
33
46
  end
34
47
 
35
48
  end
@@ -3,7 +3,7 @@ require 'tinkerforge/version'
3
3
  module Tinkerforge
4
4
 
5
5
  # Tinderfridge version.
6
- TINDERFRIDGE_VERSION = '0.11.0'
6
+ TINDERFRIDGE_VERSION = '0.13.0'
7
7
 
8
8
  # About Tinkerforge & Tinderfridge.
9
9
  def self.about
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tinderfridge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - lllist.eu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-24 00:00:00.000000000 Z
11
+ date: 2022-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tinkerforge
@@ -77,6 +77,7 @@ files:
77
77
  - lib/tinderfridge/devices/bricklet_gps_v2/bricklet_gps_v2.json
78
78
  - lib/tinderfridge/devices/bricklet_gps_v2/bricklet_gps_v2.rb
79
79
  - lib/tinderfridge/devices/bricklet_gps_v3/bricklet_gps_v3.json
80
+ - lib/tinderfridge/devices/bricklet_gps_v3/bricklet_gps_v3.rb
80
81
  - lib/tinderfridge/devices/bricklet_hall_effect_v2/bricklet_hall_effect_v2.json
81
82
  - lib/tinderfridge/devices/bricklet_hall_effect_v2/bricklet_hall_effect_v2.rb
82
83
  - lib/tinderfridge/devices/bricklet_humidity_v2/bricklet_humidity_v2.json
@@ -121,6 +122,7 @@ files:
121
122
  - lib/tinderfridge/devices/bricklet_particulate_matter/bricklet_particulate_matter.json
122
123
  - lib/tinderfridge/devices/bricklet_performance_dc/bricklet_performance_dc.json
123
124
  - lib/tinderfridge/devices/bricklet_piezo_speaker_v2/bricklet_piezo_speaker_v2.json
125
+ - lib/tinderfridge/devices/bricklet_piezo_speaker_v2/bricklet_piezo_speaker_v2.rb
124
126
  - lib/tinderfridge/devices/bricklet_ptc_v2/bricklet_ptc_v2.json
125
127
  - lib/tinderfridge/devices/bricklet_real_time_clock_v2/bricklet_real_time_clock_v2.json
126
128
  - lib/tinderfridge/devices/bricklet_remote_switch_v2/bricklet_remote_switch_v2.json
@@ -139,6 +141,7 @@ files:
139
141
  - lib/tinderfridge/devices/bricklet_servo_v2/bricklet_servo_v2.json
140
142
  - lib/tinderfridge/devices/bricklet_silent_stepper_v2/bricklet_silent_stepper_v2.json
141
143
  - lib/tinderfridge/devices/bricklet_solid_state_relay_v2/bricklet_solid_state_relay_v2.json
144
+ - lib/tinderfridge/devices/bricklet_solid_state_relay_v2/bricklet_solid_state_relay_v2.rb
142
145
  - lib/tinderfridge/devices/bricklet_sound_pressure_level/bricklet_sound_pressure_level.json
143
146
  - lib/tinderfridge/devices/bricklet_sound_pressure_level/bricklet_sound_pressure_level.rb
144
147
  - lib/tinderfridge/devices/bricklet_temperature_ir_v2/bricklet_temperature_ir_v2.json