open_lighting 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,20 +8,20 @@ module OpenLighting
8
8
  options[:points] ||= {}
9
9
  options[:points][:center] ||= {:pan => 127, :tilt => 127}
10
10
 
11
- options[:points][:strobe_slow] ||= {:strobe => 16}
12
- options[:points][:strobe_fast] ||= {:strobe => 131}
11
+ options[:points][:strobe_slow] ||= {:strobe => 16}
12
+ options[:points][:strobe_fast] ||= {:strobe => 131}
13
13
  options[:points][:strobe_slow_fast] ||= {:strobe => 140}
14
14
  options[:points][:strobe_fast_slow] ||= {:strobe => 190}
15
- options[:points][:strobe_random] ||= {:strobe => 247}
15
+ options[:points][:strobe_random] ||= {:strobe => 247}
16
16
 
17
- options[:points][:yellow] ||= {:gobo => 8}
18
- options[:points][:red] ||= {:gobo => 15}
19
- options[:points][:green] ||= {:gobo => 22}
20
- options[:points][:blue] ||= {:gobo => 29}
17
+ options[:points][:yellow] ||= {:gobo => 8}
18
+ options[:points][:red] ||= {:gobo => 15}
19
+ options[:points][:green] ||= {:gobo => 22}
20
+ options[:points][:blue] ||= {:gobo => 29}
21
21
  options[:points][:teardrop] ||= {:gobo => 36}
22
- options[:points][:polka] ||= {:gobo => 43}
23
- options[:points][:teal] ||= {:gobo => 50}
24
- options[:points][:rings] ||= {:gobo => 57}
22
+ options[:points][:polka] ||= {:gobo => 43}
23
+ options[:points][:teal] ||= {:gobo => 50}
24
+ options[:points][:rings] ||= {:gobo => 57}
25
25
 
26
26
  options[:capabilities] ||= [:pan, :tilt, :strobe, :gobo, :dimmer]
27
27
 
@@ -0,0 +1 @@
1
+ require 'open_lighting/devices/comscan_led'
@@ -26,12 +26,13 @@ module OpenLighting
26
26
  end
27
27
 
28
28
  def <<(val)
29
+ val.start_address ||= current_values.count + 1
29
30
  val.controller = self
30
31
  @devices << val
31
32
  end
32
33
 
33
34
  def set(options = {})
34
- @devices.each {|device| device.set(options)}
35
+ @devices.each {|device| device.set(options.dup)}
35
36
  end
36
37
 
37
38
  def write!(values=current_values)
@@ -44,6 +45,11 @@ module OpenLighting
44
45
  self.write_pipe.flush
45
46
  end
46
47
 
48
+ def close!
49
+ self.write_pipe.close if self.write_pipe
50
+ self.read_pipe.close if self.read_pipe
51
+ end
52
+
47
53
  def instant!(options = {})
48
54
  set(options)
49
55
  write!
@@ -90,5 +96,19 @@ module OpenLighting
90
96
  end
91
97
  results
92
98
  end
99
+
100
+ def capabilities
101
+ @devices.map{|device| device.capabilities + device.points.keys}.flatten.uniq
102
+ end
103
+
104
+ def method_missing(meth, *args, &block)
105
+ if capabilities.include? meth.to_sym
106
+ set :point => meth.to_sym
107
+ else
108
+ super # You *must* call super if you don't handle the
109
+ # method, otherwise you'll mess up Ruby's method
110
+ # lookup.
111
+ end
112
+ end
93
113
  end
94
114
  end
@@ -24,7 +24,7 @@ module OpenLighting
24
24
 
25
25
  capabilities.each_with_index do |c, i|
26
26
  unless options[c].nil?
27
- current_values[i] = options[c]
27
+ current_values[i] = options.delete(c)
28
28
  end
29
29
  end
30
30
  end
@@ -39,5 +39,15 @@ module OpenLighting
39
39
  def to_dmx
40
40
  current_values.join ","
41
41
  end
42
+
43
+ def method_missing(meth, *args, &block)
44
+ if points[meth.to_sym]
45
+ set points[meth.to_sym]
46
+ else
47
+ super # You *must* call super if you don't handle the
48
+ # method, otherwise you'll mess up Ruby's method
49
+ # lookup.
50
+ end
51
+ end
42
52
  end
43
53
  end
@@ -1,3 +1,3 @@
1
1
  module OpenLighting
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/open_lighting.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  require "open_lighting/version"
2
2
  require "open_lighting/dmx_controller"
3
3
  require "open_lighting/dmx_device"
4
+ require "open_lighting/devices"
@@ -1,5 +1,4 @@
1
1
  require 'spec_helper'
2
- require "open_lighting/devices/comscan_led"
3
2
 
4
3
  module OpenLighting
5
4
  module Devices
@@ -1,6 +1,4 @@
1
1
  require 'spec_helper'
2
- require "open_lighting/dmx_controller"
3
- require "open_lighting/dmx_device"
4
2
 
5
3
  module OpenLighting
6
4
  describe DmxController do
@@ -33,20 +31,37 @@ module OpenLighting
33
31
  end
34
32
 
35
33
  context 'when adding devices' do
36
- before(:each) do
37
- @controller << DmxDevice.new(:start_address => 1)
38
- @controller << DmxDevice.new(:start_address => 6)
39
- end
40
-
41
- it 'should return devices in the same order as added' do
42
- @controller.devices.count.should == 2
43
- @controller.devices.first.start_address.should == 1
44
- @controller.devices.last.start_address.should == 6
34
+ context 'when :start_address is specified' do
35
+ before(:each) do
36
+ @controller << DmxDevice.new(:start_address => 1)
37
+ @controller << DmxDevice.new(:start_address => 6)
38
+ end
39
+
40
+ it 'should return devices in the same order as added' do
41
+ @controller.devices.count.should == 2
42
+ @controller.devices.first.start_address.should == 1
43
+ @controller.devices.last.start_address.should == 6
44
+ end
45
+
46
+ it 'should attach controller to devices' do
47
+ @controller.devices.first.controller.should == @controller
48
+ @controller.devices.last.controller.should == @controller
49
+ end
45
50
  end
46
51
 
47
- it 'should attach controller to devices' do
48
- @controller.devices.first.controller.should == @controller
49
- @controller.devices.last.controller.should == @controller
52
+ context 'when :start_address is not specified' do
53
+ before(:each) do
54
+ options = {:capabilities => [:pan, :tilt]}
55
+ @controller << DmxDevice.new(options)
56
+ @controller << DmxDevice.new(options)
57
+ @controller << DmxDevice.new(options)
58
+ end
59
+
60
+ it 'should add default :start_address' do
61
+ @controller.devices.count.should == 3
62
+ @controller.devices.first.start_address.should == 1
63
+ @controller.devices.last.start_address.should == 5
64
+ end
50
65
  end
51
66
  end
52
67
  end
@@ -54,12 +69,30 @@ module OpenLighting
54
69
  describe ".to_dmx" do
55
70
  before(:each) do
56
71
  @controller = DmxController.new
57
- @controller << DmxDevice.new(:start_address => 1, :capabilities => [:pan, :tilt, :dimmer])
58
- @controller << DmxDevice.new(:start_address => 4, :capabilities => [:pan, :tilt, :dimmer])
72
+ @controller << DmxDevice.new(:start_address => 1, :capabilities => [:pan, :tilt, :dimmer], :points => {:center => {:pan => 127, :tilt => 127}})
73
+ @controller << DmxDevice.new(:start_address => 4, :capabilities => [:pan, :tilt, :dimmer], :points => {:center => {:pan => 127, :tilt => 127}})
74
+ end
75
+
76
+ it "should report correct capabilities" do
77
+ @controller.capabilities.should == [:pan, :tilt, :dimmer, :center]
59
78
  end
60
79
 
61
80
  it "should serialize all DmxDevices" do
62
81
  @controller.to_dmx.should == "0,0,0,0,0,0"
82
+ @controller.set(:pan => 255)
83
+ @controller.to_dmx.should == "255,0,0,255,0,0"
84
+ @controller.set(:point => :center)
85
+ @controller.to_dmx.should == "127,127,0,127,127,0"
86
+ end
87
+
88
+ it "should do method_missing magics" do
89
+ @controller.to_dmx.should == "0,0,0,0,0,0"
90
+ @controller.center
91
+ @controller.to_dmx.should == "127,127,0,127,127,0"
92
+ end
93
+
94
+ it "but not for incorrect names" do
95
+ lambda { @controller.offcenter }.should raise_error NoMethodError
63
96
  end
64
97
 
65
98
  it "should honor overlapping start_address" do
@@ -1,6 +1,4 @@
1
1
  require 'spec_helper'
2
- require "open_lighting/dmx_controller"
3
- require "open_lighting/dmx_device"
4
2
 
5
3
  module OpenLighting
6
4
  describe DmxDevice do
@@ -97,6 +95,15 @@ module OpenLighting
97
95
  @device.set(:point => :center)
98
96
  @device.current_values.should == [127, 127, 0]
99
97
  end
98
+
99
+ it "should do method_missing magics" do
100
+ @device.center
101
+ @device.current_values.should == [127, 127, 0]
102
+ end
103
+
104
+ it "but not for incorrect names" do
105
+ lambda {@device.offcenter}.should raise_error NoMethodError
106
+ end
100
107
  end
101
108
 
102
109
  context "when setting multiple points" do
data/spec/spec_helper.rb CHANGED
@@ -5,3 +5,5 @@ if RUBY_VERSION.to_f == 1.9
5
5
  require 'simplecov'
6
6
  SimpleCov.start
7
7
  end
8
+
9
+ require "open_lighting"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: open_lighting
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-25 00:00:00.000000000 Z
12
+ date: 2012-07-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: simplecov
@@ -122,6 +122,7 @@ files:
122
122
  - README.md
123
123
  - Rakefile
124
124
  - lib/open_lighting.rb
125
+ - lib/open_lighting/devices.rb
125
126
  - lib/open_lighting/devices/comscan_led.rb
126
127
  - lib/open_lighting/dmx_controller.rb
127
128
  - lib/open_lighting/dmx_device.rb