tinderfridge 0.1.0 → 0.6.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 +105 -0
- data/lib/tinderfridge/device_collection.rb +101 -4
- data/lib/tinderfridge/device_info.txt +2 -0
- data/lib/tinderfridge/devices/brick_hat/brick_hat.json +10 -0
- data/lib/tinderfridge/devices/brick_hat/brick_hat.rb +18 -0
- data/lib/tinderfridge/devices/brick_hat_zero/brick_hat_zero.json +10 -0
- data/lib/tinderfridge/devices/brick_hat_zero/brick_hat_zero.rb +14 -0
- data/lib/tinderfridge/devices/bricklet_air_quality/bricklet_air_quality.json +3 -0
- data/lib/tinderfridge/devices/bricklet_air_quality/bricklet_air_quality.rb +20 -0
- data/lib/tinderfridge/devices/bricklet_ambient_light_v3/bricklet_ambient_light_v3.json +3 -0
- data/lib/tinderfridge/devices/bricklet_ambient_light_v3/bricklet_ambient_light_v3.rb +19 -0
- data/lib/tinderfridge/devices/bricklet_color_v2/bricklet_color_v2.json +3 -0
- data/lib/tinderfridge/devices/bricklet_color_v2/bricklet_color_v2.rb +31 -0
- data/lib/tinderfridge/devices/bricklet_dmx/bricklet_dmx.json +3 -0
- data/lib/tinderfridge/devices/bricklet_dmx/bricklet_dmx.rb +18 -0
- data/lib/tinderfridge/devices/bricklet_gps_v2/bricklet_gps_v2.json +3 -0
- data/lib/tinderfridge/devices/bricklet_gps_v2/bricklet_gps_v2.rb +31 -0
- data/lib/tinderfridge/devices/bricklet_imu_v3/bricklet_imu_v3.json +3 -0
- data/lib/tinderfridge/devices/bricklet_industrial_dual_relay/bricklet_industrial_dual_relay.json +3 -0
- data/lib/tinderfridge/devices/bricklet_industrial_dual_relay/bricklet_industrial_dual_relay.rb +20 -0
- data/lib/tinderfridge/devices/bricklet_isolator/bricklet_isolator.json +3 -0
- data/lib/tinderfridge/devices/bricklet_isolator/bricklet_isolator.rb +17 -0
- data/lib/tinderfridge/devices/bricklet_joystick_v2/bricklet_joystick_v2.json +3 -0
- data/lib/tinderfridge/devices/bricklet_joystick_v2/bricklet_joystick_v2.rb +15 -0
- data/lib/tinderfridge/devices/bricklet_lcd_128x64/bricklet_lcd_128x64.json +3 -0
- data/lib/tinderfridge/devices/bricklet_lcd_128x64/bricklet_lcd_128x64.rb +31 -0
- data/lib/tinderfridge/devices/bricklet_led_strip_v2/bricklet_led_strip_v2.json +3 -0
- data/lib/tinderfridge/devices/bricklet_led_strip_v2/bricklet_led_strip_v2.rb +55 -0
- data/lib/tinderfridge/devices/bricklet_motion_detector_v2/bricklet_motion_detector_v2.json +3 -0
- data/lib/tinderfridge/devices/bricklet_motion_detector_v2/bricklet_motion_detector_v2.rb +22 -0
- data/lib/tinderfridge/devices/bricklet_motorized_linear_poti/bricklet_motorized_linear_poti.json +3 -0
- data/lib/tinderfridge/devices/bricklet_motorized_linear_poti/bricklet_motorized_linear_poti.rb +42 -0
- data/lib/tinderfridge/devices/bricklet_multi_touch_v2/bricklet_multi_touch_v2.json +3 -0
- data/lib/tinderfridge/devices/bricklet_multi_touch_v2/bricklet_multi_touch_v2.rb +16 -0
- data/lib/tinderfridge/devices/bricklet_nfc/bricklet_nfc.json +3 -0
- data/lib/tinderfridge/devices/bricklet_nfc/bricklet_nfc.rb +16 -0
- data/lib/tinderfridge/devices/bricklet_outdoor_weather/bricklet_outdoor_weather.json +3 -0
- data/lib/tinderfridge/devices/bricklet_outdoor_weather/bricklet_outdoor_weather.rb +19 -0
- data/lib/tinderfridge/devices/bricklet_performance_dc/bricklet_performance_dc.json +3 -0
- data/lib/tinderfridge/devices/bricklet_remote_switch_v2/bricklet_remote_switch_v2.json +3 -0
- data/lib/tinderfridge/devices/bricklet_remote_switch_v2/bricklet_remote_switch_v2.rb +15 -0
- data/lib/tinderfridge/devices/bricklet_rgb_led_button/bricklet_rgb_led_button.json +3 -0
- data/lib/tinderfridge/devices/bricklet_rgb_led_button/bricklet_rgb_led_button.rb +34 -0
- data/lib/tinderfridge/devices/bricklet_rgb_led_v2/bricklet_rgb_led_v2.json +3 -0
- data/lib/tinderfridge/devices/bricklet_rgb_led_v2/bricklet_rgb_led_v2.rb +32 -0
- data/lib/tinderfridge/devices/bricklet_rotary_encoder_v2/bricklet_rotary_encoder_v2.json +3 -0
- data/lib/tinderfridge/devices/bricklet_rotary_encoder_v2/bricklet_rotary_encoder_v2.rb +20 -0
- data/lib/tinderfridge/devices/bricklet_segment_display_4x7_v2/bricklet_segment_display_4x7_v2.json +3 -0
- data/lib/tinderfridge/devices/bricklet_segment_display_4x7_v2/bricklet_segment_display_4x7_v2.rb +128 -0
- data/lib/tinderfridge/devices/bricklet_servo_v2/bricklet_servo_v2.json +3 -0
- data/lib/tinderfridge/devices/bricklet_voltage_current_v2/bricklet_voltage_current_v2.json +3 -0
- data/lib/tinderfridge/devices/bricklet_voltage_current_v2/bricklet_voltage_current_v2.rb +18 -0
- data/lib/tinderfridge/ip_connection.rb +76 -21
- data/lib/tinderfridge/tinkerforge.rb +3 -0
- data/lib/tinderfridge/version.rb +1 -1
- metadata +59 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f93f157ac5afd9dd2b5a6108889f8b00b58df36c16a78faea7fa788ac64ef37d
|
4
|
+
data.tar.gz: b28896b7b8938c3d58a043e0c3ff804f253dbcb8fc5b8605ee6fb2efc4a7b92f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b436ea8162a3d32352a3b5d37a6cd3b5efdebb76cb21f51f9cf6fc393ba4a03eaed7bb0385c9471e80eb5c91ba20d56e89e4d425c02f4f7f3475947bf74fc57
|
7
|
+
data.tar.gz: 24671e0d6c6ff57bfb4bdb4094919c70803cdb7f63cf814c25c879e3c2d9555cbb803dba3c9dff6cc14cac2a4ad339af754993fcb4594ec8309e70ded461d7b1
|
data/lib/tinderfridge/device.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'tinkerforge/ip_connection'
|
2
2
|
|
3
3
|
module Tinkerforge
|
4
|
+
|
4
5
|
class Device
|
5
6
|
|
6
7
|
#----------------------------------------------------------------------#
|
@@ -33,20 +34,97 @@ module Tinkerforge
|
|
33
34
|
end.compact.sort_by { |i| i[0] }
|
34
35
|
end
|
35
36
|
|
37
|
+
private
|
38
|
+
|
39
|
+
# Primitive superhook:
|
40
|
+
# Every time a class inherits from the Device class,
|
41
|
+
# attempts to load an extension for that new class.
|
42
|
+
def inherited(klass)
|
43
|
+
if info = Tinkerforge.device_info(klass)
|
44
|
+
begin
|
45
|
+
require("tinderfridge/devices/#{info[2][1]}/#{info[2][1]}")
|
46
|
+
rescue LoadError
|
47
|
+
# No extension found for this device
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
36
52
|
end
|
37
53
|
|
38
54
|
#----------------------------------------------------------------------#
|
39
55
|
# Instance Methods #
|
40
56
|
#----------------------------------------------------------------------#
|
41
57
|
|
58
|
+
# Returns the device's UID. Not to be confused with #uid, which returns the numeric UID.
|
59
|
+
attr_reader :uid_string
|
60
|
+
|
61
|
+
# Returns the device's numeric Device Identifier.
|
62
|
+
attr_reader :device_identifier
|
63
|
+
|
64
|
+
# Returns the device's Display Name.
|
65
|
+
attr_reader :device_display_name
|
66
|
+
|
42
67
|
# Returns the device's IPConnection object.
|
43
68
|
attr_reader :ipcon
|
44
69
|
|
70
|
+
# Returns device information.
|
71
|
+
#
|
72
|
+
# Device information is an array:
|
73
|
+
# - 0 : Device Identifier
|
74
|
+
# - 1 : Device Display Name
|
75
|
+
# - 2 : Associated class name and source file
|
76
|
+
def device_info
|
77
|
+
Tinkerforge.device_info device_identifier
|
78
|
+
end
|
79
|
+
|
45
80
|
# Returns a programmer-friendly representation of the device.
|
46
81
|
def inspect
|
47
82
|
"%s (%s@%s:%s)" % [self.class, @uid_string, ipcon.host, ipcon.port]
|
48
83
|
end
|
49
84
|
|
85
|
+
# Returns the device's properties.
|
86
|
+
def properties
|
87
|
+
@properties ||= {
|
88
|
+
'device_identifier' => device_identifier,
|
89
|
+
'device_display_name' => device_display_name,
|
90
|
+
}.merge load_properties
|
91
|
+
end
|
92
|
+
|
93
|
+
alias props properties
|
94
|
+
|
95
|
+
# Returns the device's state.
|
96
|
+
def state
|
97
|
+
identity = get_identity
|
98
|
+
|
99
|
+
[
|
100
|
+
[ 'uid' , uid_string ],
|
101
|
+
[ 'update_time' , Time.now.gmtime ],
|
102
|
+
[ 'firmware_version' , identity[4].join('.') ],
|
103
|
+
|
104
|
+
[ 'connected', { 'uid' => identity[1], 'position' => identity[2] } ],
|
105
|
+
[ 'ipcon' , { 'host' => ipcon.host , 'port' => ipcon.port } ],
|
106
|
+
|
107
|
+
respond_to?('get_chip_temperature' ) ? [ 'chip_temperature' , get_chip_temperature ] : nil,
|
108
|
+
respond_to?('get_spitfp_error_count') ? [ 'spitfp_error_count', get_spitfp_error_count ] : nil,
|
109
|
+
respond_to?('get_status_led_config' ) ? [ 'status_led_config' , get_status_led_config ] : nil,
|
110
|
+
|
111
|
+
].compact.to_h
|
112
|
+
end
|
113
|
+
|
114
|
+
# Opens the online documentation for the device (Mac OS only).
|
115
|
+
#
|
116
|
+
# When the URL for the documentation is not known, does nothing.
|
117
|
+
def open_documentation
|
118
|
+
if properties['documentation_en_url'] and ( RUBY_PLATFORM =~ /darwin/ )
|
119
|
+
`open #{properties['documentation_en_url']}`
|
120
|
+
properties['documentation_en_url']
|
121
|
+
else
|
122
|
+
nil
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
alias doc open_documentation
|
127
|
+
|
50
128
|
# Identifies a Tinkerforge device by blinking its status led.
|
51
129
|
#
|
52
130
|
# Supports recent devices. When invoked on older devices, does nothing.
|
@@ -67,5 +145,32 @@ module Tinkerforge
|
|
67
145
|
end
|
68
146
|
end
|
69
147
|
|
148
|
+
private
|
149
|
+
|
150
|
+
def load_properties
|
151
|
+
if device_info
|
152
|
+
properties_file = File.join(
|
153
|
+
File.dirname(__FILE__),
|
154
|
+
'devices',
|
155
|
+
device_info[2][1],
|
156
|
+
device_info[2][1],
|
157
|
+
) + '.json'
|
158
|
+
|
159
|
+
if File.readable? properties_file
|
160
|
+
begin
|
161
|
+
require 'json'
|
162
|
+
JSON.load File.read properties_file
|
163
|
+
rescue
|
164
|
+
{}
|
165
|
+
end
|
166
|
+
else
|
167
|
+
{}
|
168
|
+
end
|
169
|
+
else
|
170
|
+
{}
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
70
174
|
end
|
175
|
+
|
71
176
|
end
|
@@ -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
|
-
|
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
|
-
|
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
|
-
|
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
|
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,88 @@ 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
|
+
# Returns the properties of devices in the collection.
|
67
|
+
def properties
|
68
|
+
smap 'properties'
|
69
|
+
end
|
70
|
+
|
71
|
+
alias props properties
|
72
|
+
|
73
|
+
# Returns the state of devices in the collection.
|
74
|
+
def state
|
75
|
+
smap 'state'
|
76
|
+
end
|
77
|
+
|
78
|
+
# Opens the online documentation for the devices in the collection (Mac OS only).
|
79
|
+
#
|
80
|
+
# When the URL for a device's documentation is not known, does nothing.
|
81
|
+
def open_documentation
|
82
|
+
smap 'open_documentation'
|
83
|
+
end
|
84
|
+
|
85
|
+
alias doc open_documentation
|
86
|
+
|
87
|
+
# Turns off light sources such as screens and RGB LEDs for devices in the collection.
|
88
|
+
#
|
89
|
+
# Ignores devices that do not support the blackout method.
|
90
|
+
def blackout
|
91
|
+
smap 'blackout'
|
92
|
+
end
|
93
|
+
|
94
|
+
# Returns a list of unique IP Connections used by devices in the collection.
|
95
|
+
def ipcons
|
96
|
+
smap('ipcon').values.compact.uniq
|
97
|
+
end
|
98
|
+
|
99
|
+
# Returns an array of devices in the collection matching the selector.
|
100
|
+
#
|
101
|
+
# Selector argument can be:
|
102
|
+
# - Device Identifier
|
103
|
+
# - Class name or Device Display Name (Regexp)
|
104
|
+
# Selection by regular expression is case-insensitive by default.
|
105
|
+
#
|
106
|
+
# @example Select by class name and Device Display Name
|
107
|
+
# # All 'analog' devices
|
108
|
+
# tf = Tinkerforge.connect.discover(1)
|
109
|
+
# tf.find_all /analog/
|
110
|
+
def find_all(selector)
|
111
|
+
case selector
|
112
|
+
when Integer
|
113
|
+
values.select { |v| v.device_identifier == selector}
|
114
|
+
when Regexp
|
115
|
+
r = Regexp.new selector.source, Regexp::IGNORECASE
|
116
|
+
values.select { |v| v.class.to_s.split('::').last =~ r || v.device_display_name =~ r }
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
# Returns the first device in the collection matching the selector.
|
121
|
+
#
|
122
|
+
# Selector argument can be:
|
123
|
+
# - Device Identifier
|
124
|
+
# - Class name or Device Display Name (Regexp)
|
125
|
+
# Selection by regular expression is case-insensitive by default.
|
126
|
+
#
|
127
|
+
# @example Select by Device Identifier
|
128
|
+
# # Remote Switch Bricklet 2.0
|
129
|
+
# tf = Tinkerforge.connect('myhost.local').discover(1)
|
130
|
+
# tf.find 289
|
131
|
+
def find(selector)
|
132
|
+
find_all(selector).first
|
133
|
+
end
|
134
|
+
|
135
|
+
private
|
136
|
+
|
137
|
+
def smap(m)
|
138
|
+
map { |k,d| [ k, d.respond_to?(m) ? d.send(m) : nil ] }.to_h
|
139
|
+
end
|
140
|
+
|
44
141
|
end
|
45
142
|
|
46
143
|
end
|
@@ -135,5 +135,7 @@
|
|
135
135
|
2147 CO2 Bricklet 2.0 Tinkerforge::BrickletCO2V2 bricklet_co2_v2
|
136
136
|
2152 Energy Monitor Bricklet Tinkerforge::BrickletEnergyMonitor bricklet_energy_monitor
|
137
137
|
2153 Compass Bricklet Tinkerforge::BrickletCompass bricklet_compass
|
138
|
+
2156 Performance DC Bricklet Tinkerforge::BrickletPerformanceDC bricklet_performance_dc
|
139
|
+
2157 Servo Bricklet 2.0 Tinkerforge::BrickletServoV2 bricklet_servo_v2
|
138
140
|
2161 IMU Bricklet 3.0 Tinkerforge::BrickletIMUV3 bricklet_imu_v3
|
139
141
|
2162 Industrial Dual AC Relay Bricklet Tinkerforge::BrickletIndustrialDualACRelay bricklet_industrial_dual_ac_relay
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Tinkerforge
|
2
|
+
|
3
|
+
class BrickHAT
|
4
|
+
|
5
|
+
# Returns the device's state.
|
6
|
+
def state
|
7
|
+
volts = get_voltages
|
8
|
+
super.merge(
|
9
|
+
'bricklet_power' => get_bricklet_power,
|
10
|
+
'usb_voltage' => volts[0],
|
11
|
+
'dc_voltage' => volts[1],
|
12
|
+
'sleep_mode' => get_sleep_mode,
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Tinkerforge
|
2
|
+
|
3
|
+
class BrickletAirQuality
|
4
|
+
|
5
|
+
# Returns the device's state.
|
6
|
+
def state
|
7
|
+
av = get_all_values
|
8
|
+
super.merge(
|
9
|
+
'iaq_index' => av[0],
|
10
|
+
'iaq_index_accuracy' => av[1],
|
11
|
+
'temperature' => av[2],
|
12
|
+
'temperature_offset' => get_temperature_offset,
|
13
|
+
'humidity' => av[3],
|
14
|
+
'air_pressure' => av[4],
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Tinkerforge
|
2
|
+
|
3
|
+
class BrickletAmbientLightV3
|
4
|
+
|
5
|
+
ILLUMINANCE_RANGES = [ 64000, 32000, 16000, 8000, 1300, 600, 100000 ]
|
6
|
+
|
7
|
+
# Returns the device's state.
|
8
|
+
def state
|
9
|
+
super.merge(
|
10
|
+
'configuration' => conf = get_configuration,
|
11
|
+
'illuminance_range' => ILLUMINANCE_RANGES[ conf[0] ],
|
12
|
+
'integration_time' => 50 + conf[1] * 50,
|
13
|
+
'illuminance_raw' => get_illuminance,
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Tinkerforge
|
2
|
+
|
3
|
+
class BrickletColorV2
|
4
|
+
|
5
|
+
GAINS = [1, 4, 16, 60]
|
6
|
+
INTEGRATION_TIMES = [2.4, 24, 101, 154, 700]
|
7
|
+
|
8
|
+
# Switches off the Bricklet's white LED.
|
9
|
+
def blackout
|
10
|
+
set_light false
|
11
|
+
true
|
12
|
+
end
|
13
|
+
|
14
|
+
# Returns the device's state.
|
15
|
+
def state
|
16
|
+
super.merge(
|
17
|
+
'configuration' => config = get_configuration,
|
18
|
+
'gain' => GAINS[ config[0] ],
|
19
|
+
'integration_time' => INTEGRATION_TIMES[ config[1] ],
|
20
|
+
'color_rgbc' => color = get_color,
|
21
|
+
'illuminance_raw' => illum = get_illuminance,
|
22
|
+
'illuminance' => illum * 700.0 / GAINS[ config[0] ] / INTEGRATION_TIMES[ config[1] ],
|
23
|
+
'color_temperature' => get_color_temperature,
|
24
|
+
'saturated' => color[0,3].include?(65535),
|
25
|
+
'light' => get_light,
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|