class Tinkerforge::DeviceCollection
Public Instance Methods
Turns off light sources such as screens and RGB LEDs for devices in the collection.
Ignores devices that do not support the blackout method.
# File lib/tinderfridge/device_collection.rb, line 90 def blackout smap 'blackout' end
Returns the first device in the collection matching the selector.
Selector argument can be:
Selection by regular expression is case-insensitive by default.
@example Select by Device
Identifier
# Remote Switch Bricklet 2.0 tf = Tinkerforge.connect('myhost.local').discover(1) tf.find 289
# File lib/tinderfridge/device_collection.rb, line 131 def find(selector) find_all(selector).first end
Returns an array of devices in the collection matching the selector.
Selector argument can be:
Selection by regular expression is case-insensitive by default.
@example Select by class name and Device
Display Name
# All 'analog' devices tf = Tinkerforge.connect.discover(1) tf.find_all /analog/
# File lib/tinderfridge/device_collection.rb, line 110 def find_all(selector) case selector when Integer values.select { |v| v.device_identifier == selector} when Regexp r = Regexp.new selector.source, Regexp::IGNORECASE values.select { |v| v.class.to_s.split('::').last =~ r || v.device_display_name =~ r } end end
Returns the temperatures as measured inside the microcontrollers of devices in the collection.
Nil for devices that do not support the get_chip_temperature
method.
# File lib/tinderfridge/device_collection.rb, line 8 def get_chip_temperature smap 'get_chip_temperature' end
Returns identity information for devices in the collection.
Identity information is returned as an array:
-
0 : UID
-
1 : Connected UID
-
2 : Connected port (position)
-
3 : Hardware version
-
4 : Firmware version
-
5 :
Device
Identifier
Nil for devices that do not support the get_identity
method.
# File lib/tinderfridge/device_collection.rb, line 23 def get_identity smap 'get_identity' end
Returns the error counts for devices in the collection.
Nil for devices that do not support the get_spitfp_error_count
method.
# File lib/tinderfridge/device_collection.rb, line 30 def get_spitfp_error_count smap 'get_spitfp_error_count' end
Returns the status LED configuration for devices in the collection.
Nil for devices that do not support the get_status_led_config
method.
# File lib/tinderfridge/device_collection.rb, line 37 def get_status_led_config smap 'get_status_led_config' end
Returns a list of unique IP Connections used by devices in the collection.
# File lib/tinderfridge/device_collection.rb, line 95 def ipcons smap('ipcon').values.compact.uniq end
Prints a list of devices in the collection.
# File lib/tinderfridge/device_collection.rb, line 60 def ls keys.sort_by(&:downcase).each do |k| puts "%-8s %.40s" % [k, Tinkerforge.device_info(self[k])[1]] end.size end
Opens the online documentation for the devices in the collection (Mac OS only).
When the URL for a device's documentation is not known, does nothing.
# File lib/tinderfridge/device_collection.rb, line 81 def open_documentation smap 'open_documentation' end
Returns the properties of devices in the collection.
# File lib/tinderfridge/device_collection.rb, line 67 def properties smap 'properties' end
Sets the status LED configuration for devices in the collection.
Ignores devices that do not support the set_status_led_config
method.
Argument can be an integer (e.g. 0=off, 1=on), or a hash (as returned by get_status_led_config
).
# File lib/tinderfridge/device_collection.rb, line 46 def set_status_led_config(state) case state when Integer map { |k,d| d.respond_to?('set_status_led_config') ? d : nil}.compact.each { |d| d.set_status_led_config(state) }.size when Hash state.keys.select { |k| self[k].respond_to?('set_status_led_config') }.each do |k| self[k].set_status_led_config(state[k]) end.size else raise ArgumentError, 'Unknown state' end end
Returns the state of devices in the collection.
# File lib/tinderfridge/device_collection.rb, line 74 def state smap 'state' end
Private Instance Methods
# File lib/tinderfridge/device_collection.rb, line 137 def smap(m) map { |k,d| [ k, d.respond_to?(m) ? d.send(m) : nil ] }.to_h end