tinderfridge 0.16.0 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8269237b83fcfd5a052cdcc9cb9f702bbca2f8e093a918dca330418679cf0496
4
- data.tar.gz: ff1e59646d0b04205e1f5151d6710c2f0834e2822dab3e842fd627c5a1878140
3
+ metadata.gz: d72a23621805a4527cf80a4e35d0ad49fff4cb362a94fe1e916a36130f5fe844
4
+ data.tar.gz: 8e5422de11c1e78dcedfe354fbd35829bf2f09254c33363040091e83d595cc6c
5
5
  SHA512:
6
- metadata.gz: fb2db92d210948ce317538ef9826ec34e2171061f91f01ea4aa6964edd5379f8274e624cdfa5078618d7ebff4029f8c776c404324587c3344fb08ce9d58d9449
7
- data.tar.gz: 2944c853d896630f99b2d305a8b76782fb67158199bfa108ca3ff7432e2c5381710bfdecca993d398bd60b26a0bf1eaefb81d8ef7afc1ba49c8574d255d37915
6
+ metadata.gz: 576e9b5d51bc93fee968f6a0788dd5bb71c451b0b5e4860f789e1603b1d2ce98cf48e0e8d7825ede45ae4510b3b15c54920f18eb153d21fc1d3424e6f5f1f06a
7
+ data.tar.gz: 908a10df2b8722fad35b5caf3e243c4d202658f2fe9a53575a59b905cb6e61962dcf1a46b8b5a6b0995f9decb7ad7606fff5ab1b7442ad747d46010500a72189
@@ -1,15 +1,43 @@
1
1
  module Tinkerforge
2
2
  class Device
3
3
 
4
- # Returns configuration data for the device (a mutable Hash).
5
- def config
6
- @config ||= {}
4
+ # Returns settings for the device (a mutable Hash).
5
+ def settings
6
+ @settings ||= {}
7
7
  end
8
8
 
9
- # Sets configuration data (a Hash) for the device.
10
- def config=(configuration)
11
- raise(ArgumentError, 'Invalid configuration') unless configuration.class == Hash
12
- @config = configuration
9
+ alias config settings
10
+
11
+ # Defines settings for the device (a Hash).
12
+ def settings=(settings_hash)
13
+ raise(ArgumentError, 'Invalid settings') unless settings_hash.class == Hash
14
+ @settings = settings_hash
15
+ end
16
+
17
+ alias config= settings=
18
+
19
+ # Configures the device by applying settings.
20
+ def configure
21
+ if settings.any?
22
+ logger_debug "Configuring #{settings.keys.map(&:to_s).join(', ')}"
23
+ case status_led_api_variety
24
+ when 2
25
+ if settings.has_key? 'status_led_config'
26
+ set_status_led_config settings['status_led_config'].to_i
27
+ end
28
+ when 1
29
+ if settings.has_key? 'status_led_enabled'
30
+ if !!settings['status_led_enabled']
31
+ enable_status_led
32
+ else
33
+ disable_status_led
34
+ end
35
+ end
36
+ end
37
+ if respond_to?(:custom_configure, true)
38
+ custom_configure
39
+ end
40
+ end
13
41
  end
14
42
 
15
43
  end
@@ -79,21 +79,30 @@ module Tinkerforge
79
79
  smap 'state'
80
80
  end
81
81
 
82
- # Returns configuration data of devices in the collection.
83
- def config
84
- smap 'config'
82
+ # Returns settings for the devices in the collection.
83
+ def settings
84
+ smap 'settings'
85
85
  end
86
86
 
87
- # Sets configuration data of devices in the collection.
88
- def config=(configuration)
89
- raise ArgumentError, 'invalid configuration' unless (configuration.class == Hash)
87
+ alias config settings
88
+
89
+ # Defines settings for the devices in the collection.
90
+ def settings=(settings_hash)
91
+ raise ArgumentError, 'invalid settings' unless (settings_hash.class == Hash)
90
92
  each do |k,v|
91
- if configuration[k]
92
- v.config = configuration[k]
93
+ if settings_hash[k]
94
+ v.settings = settings_hash[k]
93
95
  end
94
96
  end
95
97
  end
96
98
 
99
+ alias config= settings=
100
+
101
+ # Configures the devices in the collection by applying settings.
102
+ def configure
103
+ smap 'configure'
104
+ end
105
+
97
106
  # Opens the online documentation for the devices in the collection (Mac OS only).
98
107
  #
99
108
  # When the URL for a device's documentation is not known, does nothing.
@@ -16,6 +16,12 @@ module Tinkerforge
16
16
 
17
17
  private
18
18
 
19
+ def custom_configure
20
+ if settings.has_key? 'configuration'
21
+ set_configuration *settings['configuration']
22
+ end
23
+ end
24
+
19
25
  def _view_21x8
20
26
  s = state
21
27
  "AmbiLightV3 #{uid_string.rjust 8}\n\n\n" +
@@ -17,6 +17,12 @@ module Tinkerforge
17
17
 
18
18
  private
19
19
 
20
+ def custom_configure
21
+ if settings.has_key? 'sensor_configuration'
22
+ set_sensor_configuration *settings['sensor_configuration']
23
+ end
24
+ end
25
+
20
26
  def _view_21x8
21
27
  "BaroV2 #{uid_string.rjust 8}\n\n\n" +
22
28
  ('%.2f hPa' % [get_air_pressure*0.001]).center(21)
@@ -1,58 +1,9 @@
1
- module Tinkerforge
1
+ require 'tinderfridge/shared/gps'
2
2
 
3
+ module Tinkerforge
3
4
  class BrickletGPSV2
4
5
 
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
- "GPSV2 #{uid_string.rjust 8}\n\n" +
53
- ((c = coordinates) ? (" Lat %10.5f\n Lon %10.5f" % c) : ' no fix')
54
- end
6
+ include Tinkerforge::Shared::GPS
55
7
 
56
8
  end
57
-
58
9
  end
@@ -1,58 +1,9 @@
1
- module Tinkerforge
1
+ require 'tinderfridge/shared/gps'
2
2
 
3
+ module Tinkerforge
3
4
  class BrickletGPSV3
4
5
 
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
6
+ include Tinkerforge::Shared::GPS
55
7
 
56
8
  end
57
-
58
9
  end
@@ -15,6 +15,14 @@ module Tinkerforge
15
15
  )
16
16
  end
17
17
 
18
+ private
19
+
20
+ def custom_configure
21
+ if settings.has_key? 'value'
22
+ set_value *settings['value']
23
+ end
24
+ end
25
+
18
26
  end
19
27
 
20
28
  end
@@ -34,6 +34,28 @@ module Tinkerforge
34
34
 
35
35
  private
36
36
 
37
+ def custom_configure
38
+ if settings.has_key? 'chip_type'
39
+ if settings['chip_type'].to_i != get_chip_type
40
+ set_chip_type settings['chip_type'].to_i
41
+ end
42
+ end
43
+
44
+ if settings.has_key? 'channel_mapping'
45
+ set_channel_mapping settings['channel_mapping'].to_i
46
+ end
47
+
48
+ if settings.has_key? 'frame_duration'
49
+ set_frame_duration settings['frame_duration'].to_i
50
+ end
51
+
52
+ if settings.has_key? 'clock_frequency'
53
+ if settings['clock_frequency'].to_i != get_clock_frequency
54
+ set_clock_frequency settings['clock_frequency'].to_i
55
+ end
56
+ end
57
+ end
58
+
37
59
  def lookup_channel_mapping(selector=nil)
38
60
  @@channel_mapping_table ||= self.class.constants.map do |c|
39
61
  (c.to_s =~ /^CHANNEL_MAPPING_(\w{3,4})$/ ) ? [self.class.const_get(c), $1] : nil
@@ -17,6 +17,14 @@ module Tinkerforge
17
17
  )
18
18
  end
19
19
 
20
+ private
21
+
22
+ def custom_configure
23
+ if settings.has_key? 'sensitivity'
24
+ set_sensitivity settings['sensitivity'].to_i
25
+ end
26
+ end
27
+
20
28
  end
21
29
 
22
30
  end
@@ -18,9 +18,9 @@ module Tinkerforge
18
18
  #
19
19
  # Sensor identifiers can be mapped to descriptive strings or other values:
20
20
  # @example
21
- # my_weather_bricklet.config['sensormap'] = { 202 => 'outdoors' }
21
+ # my_weather_bricklet.settings['sensormap'] = { 202 => 'outdoors' }
22
22
  def sensors
23
- sensormap = (config['sensormap'].class == Hash) ? config['sensormap'] : {}
23
+ sensormap = (settings['sensormap'].class == Hash) ? settings['sensormap'] : {}
24
24
  get_sensor_identifiers.map do |id|
25
25
  [ (sensormap[id] || id), get_sensor_data(id).each_with_index.map { |v,i| i == 0 ? v/10.0 : v } ]
26
26
  end.to_h
@@ -24,6 +24,12 @@ module Tinkerforge
24
24
 
25
25
  private
26
26
 
27
+ def custom_configure
28
+ if settings.has_key? 'enable'
29
+ set_enable( !! settings['enable'] )
30
+ end
31
+ end
32
+
27
33
  def _view_21x8
28
34
  "PM #{uid_string.rjust 8}\n\n" +
29
35
  if get_enable
@@ -29,6 +29,14 @@ module Tinkerforge
29
29
  )
30
30
  end
31
31
 
32
+ private
33
+
34
+ def custom_configure
35
+ if settings.has_key? 'color'
36
+ set_color *settings['color']
37
+ end
38
+ end
39
+
32
40
  end
33
41
 
34
42
  end
@@ -190,6 +190,14 @@ module Tinkerforge
190
190
  end
191
191
  end
192
192
 
193
+ private
194
+
195
+ def custom_configure
196
+ if settings.has_key? 'brightness'
197
+ set_brightness settings['brightness'].to_i
198
+ end
199
+ end
200
+
193
201
  end
194
202
 
195
203
  end
@@ -0,0 +1,68 @@
1
+ module Tinkerforge
2
+ module Shared
3
+
4
+ # Mixin for GPS Bricklet versions 2 & 3.
5
+ module GPS
6
+
7
+ # Returns the device's state.
8
+ def state
9
+ super.merge(
10
+ 'fix_led_config' => get_fix_led_config,
11
+ 'fix' => fix?,
12
+ )
13
+ end
14
+
15
+ # Returns true if a fix is available.
16
+ def fix?
17
+ get_status[0]
18
+ end
19
+
20
+ # Returns latitude and longitude as reported by the GPS Bricklet.
21
+ #
22
+ # Nil when there is no fix (position not determined).
23
+ def coordinates
24
+ if fix?
25
+ c = get_coordinates
26
+ [
27
+ c[0] / (c[1] == 'N' ? 1000000.0 : -1000000.0),
28
+ c[2] / (c[3] == 'E' ? 1000000.0 : -1000000.0)
29
+ ]
30
+ else
31
+ nil
32
+ end
33
+ end
34
+
35
+ # Returns a Time object representing the time as reported by the GPS Bricklet.
36
+ def time
37
+ # FIXME: This will not work after 31-Dec-2099.
38
+ dt = get_date_time.map &:to_s
39
+ dt = dt[0].rjust(6,'0').unpack('a2a2a2').reverse + dt[1].rjust(9,'0').concat('000').unpack('a2a2a2a6')
40
+ dt[0].prepend '20'
41
+ Time.gm *dt.map(&:to_i)
42
+ end
43
+
44
+ # Returns a URL for viewing the current coordinates on OpenStreetMap.
45
+ def openstreetmap_marker_url(zoom=12)
46
+ if c = coordinates
47
+ "https://www.openstreetmap.org/?mlat=%f&mlon=%f&zoom=%d" % [c, zoom].flatten
48
+ end
49
+ end
50
+
51
+ private
52
+
53
+ def custom_configure
54
+ if settings.has_key? 'fix_led_config'
55
+ set_fix_led_config settings['fix_led_config'].to_i
56
+ end
57
+ end
58
+
59
+ def _view_21x8
60
+ @label21x8 ||= self.class.to_s[-5,5]
61
+ "#{@label21x8} #{uid_string.rjust 8}\n\n" +
62
+ ((c = coordinates) ? (" Lat %10.5f\n Lon %10.5f" % c) : ' no fix')
63
+ end
64
+
65
+ end
66
+
67
+ end
68
+ end
@@ -3,7 +3,7 @@ require 'tinkerforge/version'
3
3
  module Tinkerforge
4
4
 
5
5
  # Tinderfridge version.
6
- TINDERFRIDGE_VERSION = '0.16.0'
6
+ TINDERFRIDGE_VERSION = '0.17.0'
7
7
 
8
8
  # About Tinkerforge & Tinderfridge.
9
9
  def self.about
data/lib/tinderfridge.rb CHANGED
@@ -2,18 +2,9 @@ if defined? Tinkerforge
2
2
  raise 'Tinkerforge was already loaded, so Tinderfridge can not reliably extend it!'
3
3
  end
4
4
 
5
- %w(
6
-
7
- version
8
-
9
- ip_connection
10
-
11
- device
12
-
13
- tinkerforge
14
-
15
- device_info
16
-
17
- device_collection
18
-
19
- ).each { |m| require "tinderfridge/#{m}" }
5
+ require 'tinderfridge/version'
6
+ require 'tinderfridge/ip_connection'
7
+ require 'tinderfridge/device'
8
+ require 'tinderfridge/tinkerforge'
9
+ require 'tinderfridge/device_info'
10
+ require 'tinderfridge/device_collection'
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.16.0
4
+ version: 0.17.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: 2024-04-14 00:00:00.000000000 Z
11
+ date: 2026-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tinkerforge
@@ -159,15 +159,16 @@ files:
159
159
  - lib/tinderfridge/devices/bricklet_xmc1400_breakout/bricklet_xmc1400_breakout.json
160
160
  - lib/tinderfridge/ip_connection.rb
161
161
  - lib/tinderfridge/shared/display_ibm437_encoding.rb
162
+ - lib/tinderfridge/shared/gps.rb
162
163
  - lib/tinderfridge/shared/logger.rb
163
164
  - lib/tinderfridge/tinkerforge.rb
164
165
  - lib/tinderfridge/version.rb
165
- homepage: https://github.com/lllisteu/tinderfridge
166
+ homepage: https://codeberg.org/lllisteu/tinderfridge
166
167
  licenses:
167
168
  - CC0-1.0
168
169
  metadata:
169
- homepage_uri: https://github.com/lllisteu/tinderfridge
170
- changelog_uri: https://github.com/lllisteu/tinderfridge/blob/master/History.md
170
+ homepage_uri: https://codeberg.org/lllisteu/tinderfridge
171
+ changelog_uri: https://codeberg.org/lllisteu/tinderfridge/src/branch/master/History.md
171
172
  documentation_uri: https://www.rubydoc.info/gems/tinderfridge
172
173
  post_install_message:
173
174
  rdoc_options: []