class Tinkerforge::DeviceCollection

Public Instance Methods

blackout() click to toggle source

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
doc()
Alias for: open_documentation
find(selector) click to toggle source

Returns the first device in the collection matching the selector.

Selector argument can be:

  • Device Identifier

  • Class name or Device Display Name (Regexp)

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
find_all(selector) click to toggle source

Returns an array of devices in the collection matching the selector.

Selector argument can be:

  • Device Identifier

  • Class name or Device Display Name (Regexp)

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
get_chip_temperature() click to toggle source

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
get_identity() click to toggle source

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
get_spitfp_error_count() click to toggle source

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
get_status_led_config() click to toggle source

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
ipcons() click to toggle source

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
ls() click to toggle source

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
open_documentation() click to toggle source

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
Also aliased as: doc
properties() click to toggle source

Returns the properties of devices in the collection.

# File lib/tinderfridge/device_collection.rb, line 67
def properties
  smap 'properties'
end
Also aliased as: props
props()
Alias for: properties
set_status_led_config(state) click to toggle source

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
state() click to toggle source

Returns the state of devices in the collection.

# File lib/tinderfridge/device_collection.rb, line 74
def state
  smap 'state'
end

Private Instance Methods

smap(m) click to toggle source
# 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