module Tinkerforge

Constants

ALL_VERSIONS_URL
LATEST_VERSIONS_URL
TINDERFRIDGE_VERSION

Tinderfridge version.

Public Class Methods

about() click to toggle source

About Tinkerforge & Tinderfridge.

# File lib/tinderfridge/version.rb, line 9
def self.about
  "Tinkerforge #{VERSION} (with Tinderfridge #{TINDERFRIDGE_VERSION})"
end
connect(host=nil, port=nil) click to toggle source

Creates an IP Connection object connected to the given host and port.

If no host and port are specified, uses the TINKERFORGE_HOST and TINKERFORGE_PORT environment variables, when defined. Otherwise defaults to 'localhost' and port 4223.

# File lib/tinderfridge/ip_connection.rb, line 124
def self.connect(host=nil, port=nil)
  ipcon = IPConnection.new
  ipcon.connect(
    ( host || ENV['TINKERFORGE_HOST'] || 'localhost' ),
    ( port || ENV['TINKERFORGE_PORT'] ||  4223       )
  )
  ipcon
end
device_info(selector=nil) click to toggle source

Returns information about device types.

Device information is returned as array:

  • 0 : Device Identifier

  • 1 : Device Display Name

  • 2 : Associated class name and source file

Optional selector argument can be:

Selection by regular expression is case-insensitive by default, and returns an array of matches.

@example Select by Device Identifier

Tinkerforge.device_info 2103

@example Select by class

Tinkerforge.device_info Tinkerforge::BrickletLEDStripV2

@example Select by class name and Device Display Name

# All 'analog' devices
Tinkerforge.device_info /analog/

# Relays and switches
Tinkerforge.device_info /relay|switch/

@example No Selector

# All devices
Tinkerforge.device_info
# File lib/tinderfridge/device_info.rb, line 35
def device_info(selector=nil)
  @@device_info ||= load_device_info
  case selector
    when NilClass
      @@device_info
    when Integer
      @@device_info.select { |i| i[0] == selector }.first
    when Class
      klass = selector.to_s
      @@device_info.select { |i| i[2][0] == klass }.first
    when Regexp
      r = Regexp.new selector.source, Regexp::IGNORECASE
      @@device_info.select { |i| ( i[1] =~ r ) || ( i[2][0] =~ r ) }
    else
      if selector.class.ancestors.include? Tinkerforge::Device
        klass = selector.class.to_s
        @@device_info.select { |i| i[2][0] == klass }.first
      else
        raise ArgumentError, 'Unsupported selector'
      end
  end
end
lib_dir() click to toggle source

Returns the directory where Tinkerforge bindings appear to be installed.

# File lib/tinderfridge/tinkerforge.rb, line 9
def self.lib_dir
  File.dirname File.dirname Device.instance_method('uid').source_location.first
end
require_everything() click to toggle source

Attempts to load all files that are part of Tinkerforge. Returns a list of files loaded.

# File lib/tinderfridge/tinkerforge.rb, line 14
def self.require_everything
  Dir.glob(File.join lib_dir, 'tinkerforge', '*.rb').map do |file|
    require(file) ? file : nil
  end.compact
end

Private Class Methods

load_device_info() click to toggle source

Load device info from file.

# File lib/tinderfridge/device_info.rb, line 61
def load_device_info
  File.readlines( File.join( File.dirname(__FILE__), 'device_info.txt' ) ).map do |l|
    a = l.chomp.split("\t")
    a[0]   = a[0].to_i
    a[2,2] = a[2,2], nil
    a.compact
  end
end