tinderfridge 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 92034339759c82954498219a57e8070f6859b907e135a8d9a8df936abd58a01f
4
- data.tar.gz: a222affea211a17b0e6b9fd0087ddb53830f5e2a0de7a63258ebc566d5e6bd7d
3
+ metadata.gz: 2a1a23e33e307a89386dbf4d61f3a9852e000e3382ec3c61de5b1c45c0335f11
4
+ data.tar.gz: 4261d085ad57d3205da9b27fcd38d74bd3bb47e482f0fbcfb391918e4abac268
5
5
  SHA512:
6
- metadata.gz: a450530444bcaeeed475e6476d12d7cfeedda25f02cb2619b4ccdd62951f9f16f9a1f03f874c6807fef6efddbe7fe3b06825c5ca120ca6828ef1e332844cceb3
7
- data.tar.gz: a7c84f3fd084e655a81f79d58a3bbf1173f31ca0b0fafd5a66041c3aefd689f5a04d18045599a645073ccae693b13a07c6af0f51d668eb0ab8bd0954dbf6f1e9
6
+ metadata.gz: 12677e84815ddad014bf40df64798fbb05c46be764106143e16d2964a73d71a402bfb9d66bbc6f1422ec83766628ec0f6e2ddf9817fb64e38988523f9b4c3479
7
+ data.tar.gz: '0749d1e2bf1b022313bbe807c08836df740d223d1b5d81efd5bb388693c84c707d436e5dc35f9fe827518dcf6ce97db70e9f8c948a5d3b0e64f75b4780f722f5'
@@ -33,6 +33,21 @@ module Tinkerforge
33
33
  end.compact.sort_by { |i| i[0] }
34
34
  end
35
35
 
36
+ private
37
+
38
+ # Primitive superhook:
39
+ # Every time a class inherits from the Device class,
40
+ # attempts to load an extension for that new class.
41
+ def inherited(klass)
42
+ if info = Tinkerforge.device_info(klass)
43
+ begin
44
+ require("tinderfridge/devices/#{info[2][1]}")
45
+ rescue LoadError
46
+ # No extension found for this device
47
+ end
48
+ end
49
+ end
50
+
36
51
  end
37
52
 
38
53
  #----------------------------------------------------------------------#
@@ -6,28 +6,43 @@ module Tinkerforge
6
6
  #
7
7
  # Nil for devices that do not support the get_chip_temperature method.
8
8
  def get_chip_temperature
9
- map { |k,d| [ k, d.respond_to?('get_chip_temperature' ) ? d.get_chip_temperature : nil ] }.to_h
9
+ smap 'get_chip_temperature'
10
+ end
11
+
12
+ # Returns identity information for devices in the collection.
13
+ #
14
+ # Identity information is returned as an array:
15
+ # - 0 : UID
16
+ # - 1 : Connected UID
17
+ # - 2 : Connected port (position)
18
+ # - 3 : Hardware version
19
+ # - 4 : Firmware version
20
+ # - 5 : Device Identifier
21
+ #
22
+ # Nil for devices that do not support the get_identity method.
23
+ def get_identity
24
+ smap 'get_identity'
10
25
  end
11
26
 
12
27
  # Returns the error counts for devices in the collection.
13
28
  #
14
29
  # Nil for devices that do not support the get_spitfp_error_count method.
15
30
  def get_spitfp_error_count
16
- map { |k,d| [ k, d.respond_to?('get_spitfp_error_count' ) ? d.get_spitfp_error_count : nil ] }.to_h
31
+ smap 'get_spitfp_error_count'
17
32
  end
18
33
 
19
34
  # Returns the status LED configuration for devices in the collection.
20
35
  #
21
36
  # Nil for devices that do not support the get_status_led_config method.
22
37
  def get_status_led_config
23
- map { |k,d| [ k, d.respond_to?('get_status_led_config') ? d.get_status_led_config : nil ] }.to_h
38
+ smap 'get_status_led_config'
24
39
  end
25
40
 
26
41
  # Sets the status LED configuration for devices in the collection.
27
42
  #
28
43
  # Ignores devices that do not support the set_status_led_config method.
29
44
  #
30
- # Argument can be an Integer (e.g. 0=off, 1=on), or a Hash (as returned by #get_status_led_config).
45
+ # Argument can be an integer (e.g. 0=off, 1=on), or a hash (as returned by #get_status_led_config).
31
46
  def set_status_led_config(state)
32
47
  case state
33
48
  when Integer
@@ -41,6 +56,19 @@ module Tinkerforge
41
56
  end
42
57
  end
43
58
 
59
+ # Prints a list of devices in the collection.
60
+ def ls
61
+ keys.sort_by(&:downcase).each do |k|
62
+ puts "%-8s %.40s" % [k, Tinkerforge.device_info(self[k])[1]]
63
+ end.size
64
+ end
65
+
66
+ private
67
+
68
+ def smap(m)
69
+ map { |k,d| [ k, d.respond_to?(m) ? d.send(m) : nil ] }.to_h
70
+ end
71
+
44
72
  end
45
73
 
46
74
  end
@@ -0,0 +1,31 @@
1
+ module Tinkerforge
2
+
3
+ class BrickletGPSV2
4
+
5
+ # Returns latitude and longitude as reported by the GPS Bricklet.
6
+ #
7
+ # Nil when there is no fix (position not determined).
8
+ def coordinates
9
+ if get_status[0]
10
+ c = get_coordinates
11
+ [
12
+ c[0] / (c[1] == 'N' ? 1000000.0 : -1000000.0),
13
+ c[2] / (c[3] == 'E' ? 1000000.0 : -1000000.0)
14
+ ]
15
+ else
16
+ nil
17
+ end
18
+ end
19
+
20
+ # Returns a Time object representing the time as reported by the GPS Bricklet.
21
+ def time
22
+ # FIXME: This will not work after 31-Dec-2099.
23
+ dt = get_date_time.map &:to_s
24
+ dt = dt[0].rjust(6,'0').unpack('a2a2a2').reverse + dt[1].rjust(9,'0').concat('000').unpack('a2a2a2a6')
25
+ dt[0].prepend '20'
26
+ Time.gm *dt.map(&:to_i)
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,31 @@
1
+ module Tinkerforge
2
+
3
+ class BrickletLCD128x64
4
+
5
+ # Returns the current setting for the backlight (0..100).
6
+ def backlight
7
+ get_display_configuration[1]
8
+ end
9
+
10
+ # Sets the brightness of the backlight (0..100).
11
+ def backlight=(brightness)
12
+ state = get_display_configuration
13
+ state[1] = brightness.to_i
14
+ set_display_configuration *state
15
+ end
16
+
17
+ # Switches off the backlight.
18
+ def blackout
19
+ self.backlight = 0
20
+ true
21
+ end
22
+
23
+ # Clears the display, including the GUI.
24
+ def clear
25
+ clear_display
26
+ remove_all_gui
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,43 @@
1
+ module Tinkerforge
2
+
3
+ class BrickletLEDStripV2
4
+
5
+ # Switches off all connected LEDs. Use in case of misconfiguration or other trouble.
6
+ #
7
+ # Sends the connected LEDs 6144 zeros (2048 RGB values or 1536 RGBW values).
8
+ def blackout
9
+ a = Array.new(1024,0)
10
+ 6.times { |n| set_led_values( n*1024, a ) }
11
+ true
12
+ end
13
+
14
+ # Returns the channels as defined by the channel mapping.
15
+ def channels
16
+ if ch = lookup_channel_mapping(get_channel_mapping)
17
+ ch[1].chars
18
+ else
19
+ ch
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def lookup_channel_mapping(selector=nil)
26
+ @@channel_mapping_table ||= self.class.constants.map do |c|
27
+ (c.to_s =~ /^CHANNEL_MAPPING_(\w{3,4})$/ ) ? [self.class.const_get(c), $1] : nil
28
+ end.compact.sort_by { |l| l[0] }
29
+ case selector
30
+ when NilClass
31
+ @@channel_mapping_table
32
+ when Integer
33
+ @@channel_mapping_table.select { |n,s| n == selector }.first
34
+ when String
35
+ @@channel_mapping_table.select { |n,s| s == selector }.first
36
+ else
37
+ raise ArgumentError, 'Unknown selector'
38
+ end
39
+ end
40
+
41
+ end
42
+
43
+ end
@@ -0,0 +1,19 @@
1
+ module Tinkerforge
2
+
3
+ class BrickletOutdoorWeather
4
+
5
+ # Returns the last measured data for all sensors.
6
+ #
7
+ # The result is a Hash, with sensor identifiers as the keys. Values per sensor are:
8
+ # - 0: Temperature (°C)
9
+ # - 1: Relative humidity (%RH)
10
+ # - 2: Last change (seconds)
11
+ def sensors
12
+ get_sensor_identifiers.map do |id|
13
+ [ id, get_sensor_data(id).each_with_index.map { |v,i| i == 0 ? v/10.0 : v } ]
14
+ end.to_h
15
+ end
16
+
17
+ end
18
+
19
+ end
@@ -0,0 +1,25 @@
1
+ module Tinkerforge
2
+
3
+ class BrickletRGBLEDButton
4
+
5
+ # Returns the button's current color as three values for red, green, and blue (integers in the range 0..255).
6
+ def rgb
7
+ get_color
8
+ end
9
+
10
+ # Sets the button's color using three values for red, green, and blue (integers in the range 0..255).
11
+ #
12
+ # Values can be supplied as an array or as three separate values.
13
+ def rgb=(*rgb)
14
+ set_color *rgb.flatten
15
+ end
16
+
17
+ # Switches off the button's LED.
18
+ def blackout
19
+ self.rgb = 0, 0, 0
20
+ true
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,25 @@
1
+ module Tinkerforge
2
+
3
+ class BrickletRGBLEDV2
4
+
5
+ # Returns the LED's current color as three values for red, green, and blue (integers in the range 0..255).
6
+ def rgb
7
+ get_rgb_value
8
+ end
9
+
10
+ # Sets the LED's color using three values for red, green, and blue (integers in the range 0..255).
11
+ #
12
+ # Values can be supplied as an array or as three separate values.
13
+ def rgb=(*rgb)
14
+ set_rgb_value *rgb.flatten
15
+ end
16
+
17
+ # Switches off the LED.
18
+ def blackout
19
+ self.rgb = 0, 0, 0
20
+ true
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,20 @@
1
+ module Tinkerforge
2
+
3
+ class BrickletSegmentDisplay4x7V2
4
+
5
+ # Clears the display.
6
+ def clear
7
+ set_segments [false]*8, [false]*8, [false]*8, [false]*8, [false]*2, false
8
+ true
9
+ end
10
+
11
+ alias blackout clear
12
+
13
+ # Returns the state of all 35 segments.
14
+ def segments
15
+ send_request FUNCTION_GET_SEGMENTS, [], '', 14, '?35'
16
+ end
17
+
18
+ end
19
+
20
+ end
@@ -33,28 +33,32 @@ module Tinkerforge
33
33
  list = Tinkerforge::DeviceCollection.new
34
34
  self.register_callback(CALLBACK_ENUMERATE) do |*args|
35
35
  case args[6]
36
-
37
- when 0, 1 # Available or Connected
38
- info = Tinkerforge.device_info args[5]
39
- if info
40
- require File.join('tinkerforge', info[2][1] )
41
- list[args.first] = Tinkerforge.const_get( info[2][0] ).new args.first, self
42
- else # Device not in device_info
43
- list[args.first] = nil
36
+ when 0, 1
37
+ unless list.key?(args[0])
38
+ list[args[0]] = device_instance_from_enum_data(args)
44
39
  end
45
-
46
- when 2 # Disconnected
47
- list[args.first] = nil
48
-
40
+ when 2
41
+ list.delete args[0]
49
42
  else
50
43
  raise "Unknown Enumeration Type: #{args[6]}"
51
-
52
44
  end
53
45
  end
54
46
  self.enumerate
55
47
  list
56
48
  end
57
49
 
50
+ private
51
+
52
+ # Takes the args supplied by an enumeration callback, and returns a device instance.
53
+ def device_instance_from_enum_data(enum_data)
54
+ if dev_info = Tinkerforge.device_info(enum_data[5])
55
+ require "tinkerforge/#{dev_info[2][1]}"
56
+ Tinkerforge.const_get(dev_info[2][0]).new enum_data[0], self
57
+ else
58
+ raise "Unknown device type #{enum_data[5]} (#{enum_data[0]})"
59
+ end
60
+ end
61
+
58
62
  end
59
63
 
60
64
  # Creates an IP Connection object connected to the given host and port.
@@ -3,7 +3,7 @@ require 'tinkerforge/version'
3
3
  module Tinkerforge
4
4
 
5
5
  # Tinderfridge version.
6
- TINDERFRIDGE_VERSION = '0.1.0'
6
+ TINDERFRIDGE_VERSION = '0.2.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.1.0
4
+ version: 0.2.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: 2020-12-09 00:00:00.000000000 Z
11
+ date: 2020-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tinkerforge
@@ -35,6 +35,13 @@ files:
35
35
  - lib/tinderfridge/device_collection.rb
36
36
  - lib/tinderfridge/device_info.rb
37
37
  - lib/tinderfridge/device_info.txt
38
+ - lib/tinderfridge/devices/bricklet_gps_v2.rb
39
+ - lib/tinderfridge/devices/bricklet_lcd_128x64.rb
40
+ - lib/tinderfridge/devices/bricklet_led_strip_v2.rb
41
+ - lib/tinderfridge/devices/bricklet_outdoor_weather.rb
42
+ - lib/tinderfridge/devices/bricklet_rgb_led_button.rb
43
+ - lib/tinderfridge/devices/bricklet_rgb_led_v2.rb
44
+ - lib/tinderfridge/devices/bricklet_segment_display_4x7_v2.rb
38
45
  - lib/tinderfridge/ip_connection.rb
39
46
  - lib/tinderfridge/tinkerforge.rb
40
47
  - lib/tinderfridge/version.rb