tinderfridge 0.12.0 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tinderfridge/device.rb +24 -1
- data/lib/tinderfridge/device_collection.rb +33 -1
- data/lib/tinderfridge/devices/brick_esp32_ethernet/brick_esp32_ethernet.rb +1 -1
- data/lib/tinderfridge/devices/bricklet_ambient_light_v3/bricklet_ambient_light_v3.rb +9 -0
- data/lib/tinderfridge/devices/bricklet_barometer_v2/bricklet_barometer_v2.rb +2 -5
- data/lib/tinderfridge/devices/bricklet_co2_v2/bricklet_co2_v2.rb +2 -5
- data/lib/tinderfridge/devices/bricklet_gps_v2/bricklet_gps_v2.rb +1 -1
- data/lib/tinderfridge/devices/bricklet_gps_v3/bricklet_gps_v3.rb +1 -1
- data/lib/tinderfridge/devices/bricklet_lcd_128x64/bricklet_lcd_128x64.rb +1 -1
- data/lib/tinderfridge/devices/bricklet_oled_128x64_v2/bricklet_oled_128x64_v2.rb +1 -1
- data/lib/tinderfridge/devices/bricklet_outdoor_weather/bricklet_outdoor_weather.rb +8 -3
- data/lib/tinderfridge/devices/bricklet_segment_display_4x7_v2/bricklet_segment_display_4x7_v2.rb +31 -0
- data/lib/tinderfridge/devices/bricklet_solid_state_relay_v2/bricklet_solid_state_relay_v2.rb +22 -0
- data/lib/tinderfridge/devices/bricklet_temperature_v2/bricklet_temperature_v2.rb +3 -7
- data/lib/tinderfridge/ip_connection.rb +29 -4
- data/lib/tinderfridge/shared/logger.rb +51 -0
- data/lib/tinderfridge/tinkerforge.rb +34 -0
- data/lib/tinderfridge/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5370c2b6210bbb986208ce2afc7f6ce9573592b7707bf14a8bc371ffb47050c
|
4
|
+
data.tar.gz: 79338d5081d87b1aff9402eaf656be89ed5a50c52f59f597c68a84e9462ccdd4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0077e242170d67d5c8ffdc63efd702183865d2e475c4be0c0f93bc4bf33aff1c313838a96ade44255245c320057e5369133d860fd5755b585f0fa92f1ae823c
|
7
|
+
data.tar.gz: 3a98205cf201dd8df8ca95378ad1bb82fa41af517f2f8b87a910f4f43b7753344ea0538d90aab6015fd3b8d16d2627b3ef24167380457601cf20f7aae19addfe
|
data/lib/tinderfridge/device.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'tinkerforge/ip_connection'
|
2
|
+
require 'tinderfridge/shared/logger'
|
2
3
|
|
3
4
|
module Tinkerforge
|
4
5
|
|
@@ -56,6 +57,8 @@ module Tinkerforge
|
|
56
57
|
# Instance Methods #
|
57
58
|
#----------------------------------------------------------------------#
|
58
59
|
|
60
|
+
include Tinkerforge::Shared::Logger
|
61
|
+
|
59
62
|
# Returns the device's UID. Not to be confused with #uid, which returns the numeric UID.
|
60
63
|
attr_reader :uid_string
|
61
64
|
|
@@ -68,6 +71,15 @@ module Tinkerforge
|
|
68
71
|
# Returns the device's IPConnection object.
|
69
72
|
attr_reader :ipcon
|
70
73
|
|
74
|
+
alias original_initialize initialize
|
75
|
+
|
76
|
+
def initialize(uid, ipcon, device_identifier, device_display_name)
|
77
|
+
original_initialize(uid, ipcon, device_identifier, device_display_name)
|
78
|
+
if respond_to? 'get_identity'
|
79
|
+
logger_debug "Created %s '%s'" % [self.class, uid_string]
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
71
83
|
# Returns device information.
|
72
84
|
#
|
73
85
|
# Device information is an array:
|
@@ -80,7 +92,7 @@ module Tinkerforge
|
|
80
92
|
|
81
93
|
# Returns a programmer-friendly representation of the device.
|
82
94
|
def inspect
|
83
|
-
"
|
95
|
+
"#{self.class} (#{uid_string}" + ( ipcon.host ? "@#{ipcon.host}:#{ipcon.port})" : ')' )
|
84
96
|
end
|
85
97
|
|
86
98
|
# Returns the device's properties.
|
@@ -122,6 +134,17 @@ module Tinkerforge
|
|
122
134
|
].compact.to_h
|
123
135
|
end
|
124
136
|
|
137
|
+
# Returns configuration data for the device (a mutable Hash).
|
138
|
+
def config
|
139
|
+
@config ||= {}
|
140
|
+
end
|
141
|
+
|
142
|
+
# Sets configuration data (a Hash) for the device.
|
143
|
+
def config=(configuration)
|
144
|
+
raise(ArgumentError, 'Invalid configuration') unless configuration.class == Hash
|
145
|
+
@config = configuration
|
146
|
+
end
|
147
|
+
|
125
148
|
# Opens the online documentation for the device (Mac OS only).
|
126
149
|
#
|
127
150
|
# 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,
|
64
|
+
puts "%-8s %.40s" % [k, self[k].device_display_name]
|
65
65
|
end.size
|
66
66
|
end
|
67
67
|
|
@@ -77,6 +77,21 @@ 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
|
+
|
85
|
+
# Sets configuration data of devices in the collection.
|
86
|
+
def config=(configuration)
|
87
|
+
raise ArgumentError, 'invalid configuration' unless (configuration.class == Hash)
|
88
|
+
each do |k,v|
|
89
|
+
if configuration[k]
|
90
|
+
v.config = configuration[k]
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
80
95
|
# Opens the online documentation for the devices in the collection (Mac OS only).
|
81
96
|
#
|
82
97
|
# When the URL for a device's documentation is not known, does nothing.
|
@@ -86,6 +101,18 @@ module Tinkerforge
|
|
86
101
|
|
87
102
|
alias doc open_documentation
|
88
103
|
|
104
|
+
# On Mac OS, opens a new Brick Viewer for each unique
|
105
|
+
# IP Connection used by devices in the collection.
|
106
|
+
#
|
107
|
+
# Not supported on other platforms.
|
108
|
+
#
|
109
|
+
# Requires Brick Viewer version 2.4.23 or later.
|
110
|
+
def open_brick_viewer
|
111
|
+
ipcons.map { |i| i.open_brick_viewer }
|
112
|
+
end
|
113
|
+
|
114
|
+
alias brickv open_brick_viewer
|
115
|
+
|
89
116
|
# Turns off light sources such as screens and RGB LEDs for devices in the collection.
|
90
117
|
#
|
91
118
|
# Ignores devices that do not support the blackout method.
|
@@ -98,6 +125,11 @@ module Tinkerforge
|
|
98
125
|
smap('ipcon').values.compact.uniq
|
99
126
|
end
|
100
127
|
|
128
|
+
# Disconnects IP Connections used by devices in the collection.
|
129
|
+
def disconnect
|
130
|
+
ipcons.map { |i| [i, (i.get_connection_state == 0 ? nil : i.disconnect) ] }.to_h
|
131
|
+
end
|
132
|
+
|
101
133
|
# Returns an array of devices in the collection matching the selector.
|
102
134
|
#
|
103
135
|
# Selector argument can be:
|
@@ -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
|
-
|
22
|
-
|
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
|
@@ -11,13 +11,18 @@ module Tinkerforge
|
|
11
11
|
|
12
12
|
# Returns the last measured data for all sensors.
|
13
13
|
#
|
14
|
-
# 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:
|
15
15
|
# - 0: Temperature (°C)
|
16
16
|
# - 1: Relative humidity (%RH)
|
17
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' }
|
18
22
|
def sensors
|
23
|
+
sensormap = (config['sensormap'].class == Hash) ? config['sensormap'] : {}
|
19
24
|
get_sensor_identifiers.map do |id|
|
20
|
-
[ 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 } ]
|
21
26
|
end.to_h
|
22
27
|
end
|
23
28
|
|
@@ -26,7 +31,7 @@ module Tinkerforge
|
|
26
31
|
def _view_21x8
|
27
32
|
"Weather #{uid_string.rjust 8}\n\n" +
|
28
33
|
sensors.first(6).map do |k,v|
|
29
|
-
%Q(#{v[2] > 100 ? '
|
34
|
+
%Q(#{v[2] > 100 ? '!' : ' '}%-8.8s %5.1f°C%3d%%\n) % [k,v].flatten
|
30
35
|
end.join
|
31
36
|
end
|
32
37
|
|
data/lib/tinderfridge/devices/bricklet_segment_display_4x7_v2/bricklet_segment_display_4x7_v2.rb
CHANGED
@@ -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
|
-
|
17
|
-
|
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
|
@@ -1,9 +1,12 @@
|
|
1
1
|
require 'tinkerforge/ip_connection'
|
2
|
+
require 'tinderfridge/shared/logger'
|
2
3
|
|
3
4
|
module Tinkerforge
|
4
5
|
|
5
6
|
class IPConnection
|
6
7
|
|
8
|
+
include Tinkerforge::Shared::Logger
|
9
|
+
|
7
10
|
# Returns the host for the IP Connection.
|
8
11
|
attr_reader :host
|
9
12
|
|
@@ -15,7 +18,7 @@ module Tinkerforge
|
|
15
18
|
|
16
19
|
# Returns a programmer-friendly representation of the object.
|
17
20
|
def inspect
|
18
|
-
"
|
21
|
+
"#{self.class} (%s:%s)" % (host ? [host, port] : ['-', '-'] )
|
19
22
|
end
|
20
23
|
|
21
24
|
# Returns the state of the IP Connection.
|
@@ -86,6 +89,7 @@ module Tinkerforge
|
|
86
89
|
list = Tinkerforge::DeviceCollection.new
|
87
90
|
|
88
91
|
self.register_callback(CALLBACK_ENUMERATE) do |*args|
|
92
|
+
logger_log_enum(args)
|
89
93
|
case args[6]
|
90
94
|
when 0, 1
|
91
95
|
unless list.key?(args[0])
|
@@ -95,8 +99,6 @@ module Tinkerforge
|
|
95
99
|
end
|
96
100
|
when 2
|
97
101
|
list.delete args[0]
|
98
|
-
else
|
99
|
-
raise "Unknown Enumeration Type: #{args[6]}"
|
100
102
|
end
|
101
103
|
end
|
102
104
|
|
@@ -105,6 +107,21 @@ module Tinkerforge
|
|
105
107
|
list
|
106
108
|
end
|
107
109
|
|
110
|
+
# On Mac OS, opens a new Brick Viewer,
|
111
|
+
# connected to the IP Connection's host and port.
|
112
|
+
#
|
113
|
+
# Not supported on other platforms.
|
114
|
+
#
|
115
|
+
# Requires Brick Viewer version 2.4.23 or later.
|
116
|
+
def open_brick_viewer
|
117
|
+
if host and (RUBY_PLATFORM =~ /darwin/)
|
118
|
+
`open -n -a Brickv --args #{host} --port #{port}`
|
119
|
+
"#{host}:#{port}"
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
alias brickv open_brick_viewer
|
124
|
+
|
108
125
|
private
|
109
126
|
|
110
127
|
# Takes the args supplied by an enumeration callback, and returns a device instance.
|
@@ -113,11 +130,19 @@ module Tinkerforge
|
|
113
130
|
require "tinkerforge/#{dev_info[2][1]}"
|
114
131
|
Tinkerforge.const_get(dev_info[2][0]).new enum_data[0], self
|
115
132
|
else
|
116
|
-
|
133
|
+
logger_warn "Unknown Device Identifier: #{enum_data[5]} (UID: #{enum_data[0]})"
|
117
134
|
nil
|
118
135
|
end
|
119
136
|
end
|
120
137
|
|
138
|
+
def logger_log_enum(enum_data)
|
139
|
+
logger_debug(
|
140
|
+
"Device '#{enum_data[0]}' " +
|
141
|
+
['available', 'connected', 'disconnected'][enum_data[6]] +
|
142
|
+
( enum_data[6] == 2 ? '' : " (Device Identifier: #{enum_data[5]})" )
|
143
|
+
)
|
144
|
+
end
|
145
|
+
|
121
146
|
end
|
122
147
|
|
123
148
|
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Tinkerforge
|
2
|
+
|
3
|
+
module Shared
|
4
|
+
|
5
|
+
# Mixin for event logging to a Logger instance.
|
6
|
+
#
|
7
|
+
# Logger is part of the Ruby Standard Library:
|
8
|
+
# - https://docs.ruby-lang.org/en/master/Logger.html
|
9
|
+
module Logger
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def logger
|
14
|
+
Tinkerforge.logger
|
15
|
+
end
|
16
|
+
|
17
|
+
def logger_debug(msg)
|
18
|
+
if logger
|
19
|
+
logger.debug(msg)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def logger_info(msg)
|
24
|
+
if logger
|
25
|
+
logger.info(msg)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def logger_warn(msg)
|
30
|
+
if logger
|
31
|
+
logger.warn(msg)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def logger_error(msg)
|
36
|
+
if logger
|
37
|
+
logger.error(msg)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def logger_fatal(msg)
|
42
|
+
if logger
|
43
|
+
logger.fatal(msg)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -7,6 +7,8 @@ module Tinkerforge
|
|
7
7
|
|
8
8
|
class << self
|
9
9
|
|
10
|
+
@@logger = nil
|
11
|
+
|
10
12
|
# Returns the directory where Tinkerforge bindings appear to be installed.
|
11
13
|
def lib_dir
|
12
14
|
File.dirname File.dirname Device.instance_method('uid').source_location.first
|
@@ -30,6 +32,38 @@ module Tinkerforge
|
|
30
32
|
connect('localhost', port).discover(0.25)
|
31
33
|
end
|
32
34
|
|
35
|
+
# Assign a Logger object to enable logging of Tinkerforge events.
|
36
|
+
def logger=(logger)
|
37
|
+
if logger
|
38
|
+
if logger.respond_to? :debug
|
39
|
+
@@logger = logger
|
40
|
+
logger.debug(about)
|
41
|
+
else
|
42
|
+
raise ArgumentError, 'Invalid Logger'
|
43
|
+
end
|
44
|
+
else
|
45
|
+
@@logger = nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Returns the Logger, or nil
|
50
|
+
def logger
|
51
|
+
@@logger
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def _view_21x8
|
57
|
+
"\n" +
|
58
|
+
'Tinkerforge'.center(21) +
|
59
|
+
"\n" +
|
60
|
+
VERSION.center(21) +
|
61
|
+
"\n\n\n\n" +
|
62
|
+
"Tinderfridge #{TINDERFRIDGE_VERSION}".center(21) +
|
63
|
+
"\n" +
|
64
|
+
"Ruby #{RUBY_VERSION}".center(21)
|
65
|
+
end
|
66
|
+
|
33
67
|
end
|
34
68
|
|
35
69
|
end
|
data/lib/tinderfridge/version.rb
CHANGED
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.
|
4
|
+
version: 0.14.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:
|
11
|
+
date: 2023-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tinkerforge
|
@@ -141,6 +141,7 @@ files:
|
|
141
141
|
- lib/tinderfridge/devices/bricklet_servo_v2/bricklet_servo_v2.json
|
142
142
|
- lib/tinderfridge/devices/bricklet_silent_stepper_v2/bricklet_silent_stepper_v2.json
|
143
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
|
144
145
|
- lib/tinderfridge/devices/bricklet_sound_pressure_level/bricklet_sound_pressure_level.json
|
145
146
|
- lib/tinderfridge/devices/bricklet_sound_pressure_level/bricklet_sound_pressure_level.rb
|
146
147
|
- lib/tinderfridge/devices/bricklet_temperature_ir_v2/bricklet_temperature_ir_v2.json
|
@@ -155,6 +156,7 @@ files:
|
|
155
156
|
- lib/tinderfridge/devices/bricklet_xmc1400_breakout/bricklet_xmc1400_breakout.json
|
156
157
|
- lib/tinderfridge/ip_connection.rb
|
157
158
|
- lib/tinderfridge/shared/display_ibm437_encoding.rb
|
159
|
+
- lib/tinderfridge/shared/logger.rb
|
158
160
|
- lib/tinderfridge/tinkerforge.rb
|
159
161
|
- lib/tinderfridge/version.rb
|
160
162
|
homepage: https://github.com/lllisteu/tinderfridge
|