Class: OpenLighting::DmxDevice

Inherits:
Object
  • Object
show all
Defined in:
lib/open_lighting/dmx_device.rb

Overview

A DmxDevice represents a single controllable piece of physical hardware that can be controlled via DMX signals.

DmxDevice can be subclassed with sensible defaults for various pieces of hardware.

Direct Known Subclasses

OpenLighting::Devices::ComscanLed

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ DmxDevice

Returns a new instance of DmxDevice.



10
11
12
13
14
15
16
# File 'lib/open_lighting/dmx_device.rb', line 10

def initialize(options = {})
  self.start_address = options[:start_address]
  self.capabilities = (options[:capabilities]  || []).map{|i| i.to_sym}
  self.defaults = options[:defaults] || {}
  self.current_values = capabilities.map{|c| defaults[c] || 0 }
  self.points = options[:points] || {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/open_lighting/dmx_device.rb', line 49

def method_missing(meth, *args, &block)
  if points[meth]
    buffer points[meth]
  elsif capabilities.include? meth
    buffer meth => args.first
  else
    super # You *must* call super if you don't handle the
          # method, otherwise you'll mess up Ruby's method
          # lookup.
  end
end

Instance Attribute Details

#capabilitiesObject

Returns the value of attribute capabilities.



9
10
11
# File 'lib/open_lighting/dmx_device.rb', line 9

def capabilities
  @capabilities
end

#controllerObject

Returns the value of attribute controller.



9
10
11
# File 'lib/open_lighting/dmx_device.rb', line 9

def controller
  @controller
end

#current_valuesObject

Returns the value of attribute current_values.



9
10
11
# File 'lib/open_lighting/dmx_device.rb', line 9

def current_values
  @current_values
end

#defaultsObject

Returns the value of attribute defaults.



9
10
11
# File 'lib/open_lighting/dmx_device.rb', line 9

def defaults
  @defaults
end

#pointsObject

Returns the value of attribute points.



9
10
11
# File 'lib/open_lighting/dmx_device.rb', line 9

def points
  @points
end

#start_addressObject

Returns the value of attribute start_address.



9
10
11
# File 'lib/open_lighting/dmx_device.rb', line 9

def start_address
  @start_address
end

Instance Method Details

#buffer(opt) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/open_lighting/dmx_device.rb', line 23

def buffer(opt)
  options = opt.dup if opt
  return if options.nil?

  if pt = options.delete(:point)
    buffer points[pt]
  end

  capabilities.each_with_index do |c, i|
    unless options[c].nil?
      current_values[i] = options.delete(c)
    end
  end
end

#point(key) ⇒ Object



38
39
40
41
42
43
# File 'lib/open_lighting/dmx_device.rb', line 38

def point(key)
  # d { key }
  # d { self.points }

  self.points[key]
end

#set(options) ⇒ Object



18
19
20
21
# File 'lib/open_lighting/dmx_device.rb', line 18

def set(options)
  warn "[DEPRECATION] `set` is deprecated. Use `buffer` instead."
  buffer(options)
end

#to_dmxObject



45
46
47
# File 'lib/open_lighting/dmx_device.rb', line 45

def to_dmx
  current_values.join ","
end