monome_serial 1.0.0 → 1.1.0

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.
data/.gitignore CHANGED
@@ -2,5 +2,5 @@ tmp
2
2
  *.DS_Store
3
3
  \#*#
4
4
  *.#*
5
+ *.rbc
5
6
  pkg
6
-
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.1.0
data/lib/monome_serial.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #require external libraries
2
- require 'activesupport'
2
+ require 'active_support'
3
3
  require 'fcntl'
4
4
 
5
5
  require 'monome_serial/serial_communicator'
@@ -9,10 +9,11 @@ module MonomeSerial
9
9
 
10
10
  attr_reader :communicator, :serial, :protocol
11
11
 
12
- def initialize(tty_path, protocol="series")
13
- raise ArgumentError, "Unexpected protocol type: #{protocol}. Expected 40h or series" unless protocol == "40h" || protocol == "series"
12
+ def initialize(tty_path, opts = {})
13
+ opts.reverse_merge! :brightness => 10, :ignore_intro => false, :protocol => 'series'
14
+ raise ArgumentError, "Unexpected protocol type: #{opts[:protocol]}. Expected 40h or series" unless ['40h', 'series'].include?(opts[:protocol])
14
15
 
15
- @protocol = protocol
16
+ @protocol = opts[:protocol]
16
17
 
17
18
  #try to pull out serial for the monome represented by
18
19
  #this tty_path
@@ -29,6 +30,11 @@ module MonomeSerial
29
30
  else
30
31
  extend SerialCommunicator::BinaryPatterns::Series
31
32
  end
33
+
34
+ if is_real?
35
+ run_intromation unless opts[:ignore_intro]
36
+ self.brightness = opts[:brightness]
37
+ end
32
38
  end
33
39
 
34
40
  def illuminate_lamp(x,y)
@@ -86,5 +92,29 @@ module MonomeSerial
86
92
  def is_real?
87
93
  @communicator && @communicator.class != MonomeSerial::SerialCommunicator::DummyCommunicator
88
94
  end
95
+
96
+ private
97
+
98
+ def run_intromation
99
+ extinguish_all
100
+
101
+ brightness = 1
102
+ illuminate_all
103
+
104
+ sleep_times = [ 0, 0.072, 0.1030, 0.1159, 0.1236, 0.1287, 0.1324, 0.1352, 0.1373, 0.1390, 0.1404, 0.1416, 0.1426, 0.1435, 0.1442, 0.1448, 0.1278 ]
105
+
106
+ (1..16).each do |brightness|
107
+ self.brightness = brightness
108
+ sleep_time = (sleep_times[16 - brightness]) / 4.0
109
+ sleep sleep_time
110
+ end
111
+
112
+ (1..16).to_a.reverse.each do |brightness|
113
+ self.brightness = brightness
114
+ sleep_time = (sleep_times[brightness]) / 10.0
115
+ sleep sleep_time
116
+ end
117
+ extinguish_all
118
+ end
89
119
  end
90
120
  end
@@ -272,9 +272,10 @@ module MonomeSerial
272
272
 
273
273
 
274
274
  def brightness_pattern(brightness)
275
- raise ArgumentError, "Expecting a brightness between 0 and 15 inclusively, got #{brightness}" unless brightness >= 0 && brightness <= 15
275
+ raise ArgumentError, "Expecting brightness to be a Fixnum. You gave me a #{brightness.class}." unless Fixnum === brightness
276
+ raise ArgumentError, "Expecting a brightness between 1 and 16 inclusively, got #{brightness}" unless brightness >= 1 && brightness <= 16
276
277
 
277
- "1010" + INT_TO_BIN_STRING[brightness]
278
+ "1010" + INT_TO_BIN_STRING[brightness - 1]
278
279
  end
279
280
 
280
281
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{monome_serial}
8
- s.version = "1.0.0"
8
+ s.version = "1.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Sam Aaron"]
12
- s.date = %q{2009-12-02}
12
+ s.date = %q{2010-01-21}
13
13
  s.description = %q{Communicate directly with your monome with this handy Ruby library.}
14
14
  s.email = %q{samaaron@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -20,9 +20,12 @@ Gem::Specification.new do |s|
20
20
  "README",
21
21
  "Rakefile",
22
22
  "VERSION",
23
+ "assets/monome_serial_final.png",
24
+ "assets/monome_serial_logo.graffle",
23
25
  "docs/CONTRIBUTORS",
24
26
  "docs/LICENSE",
25
27
  "docs/TODO",
28
+ "examples/toggler.rb",
26
29
  "lib/monome_serial.rb",
27
30
  "lib/monome_serial/examples/toggle.rb",
28
31
  "lib/monome_serial/monome_communicator.rb",
@@ -7,7 +7,7 @@ describe MonomeCommunicator do
7
7
  end
8
8
 
9
9
  it "should raise an error when not initializing with a correct protocol name" do
10
- lambda{MonomeCommunicator.new('/blah', "phonycol" )}.should raise_error(ArgumentError)
10
+ lambda{MonomeCommunicator.new('/blah', :protocol => "phonycol" )}.should raise_error(ArgumentError)
11
11
  end
12
12
 
13
13
  describe "A default monome with an unusual tty_path" do
@@ -30,7 +30,7 @@ describe MonomeCommunicator do
30
30
 
31
31
  describe "A default monome with the 40h protocol" do
32
32
  before(:each) do
33
- @monome = MonomeCommunicator.new('/foo/tty.usbserial-m256-203', '40h')
33
+ @monome = MonomeCommunicator.new('/foo/tty.usbserial-m256-203', :protocol => '40h')
34
34
  end
35
35
 
36
36
  it "should raise an exception when a communicating method is used" do
@@ -57,27 +57,27 @@ describe MonomeCommunicator do
57
57
  @monome.extinguish_all
58
58
  end
59
59
 
60
- it "should send the correct binary string to set the brightness to 0" do
60
+ it "should send the correct binary string to set the brightness to 1" do
61
61
  @comm.should_receive(:write).with(["10100000"])
62
- @monome.brightness = 0
62
+ @monome.brightness = 1
63
63
  end
64
64
 
65
- it "should send the correct binary string to set the brightness to 5" do
65
+ it "should send the correct binary string to set the brightness to 6" do
66
66
  @comm.should_receive(:write).with(["10100101"])
67
- @monome.brightness = 5
67
+ @monome.brightness = 6
68
68
  end
69
69
 
70
- it "should send the correct binary string to set the brightness to 15" do
70
+ it "should send the correct binary string to set the brightness to 16" do
71
71
  @comm.should_receive(:write).with(["10101111"])
72
- @monome.brightness = 15
72
+ @monome.brightness = 16
73
73
  end
74
74
 
75
75
  it "should raise an error if a negative brightness is set" do
76
- lambda{@monome.brightness = -1}.should raise_error(ArgumentError)
76
+ lambda{@monome.brightness = 0}.should raise_error(ArgumentError)
77
77
  end
78
78
 
79
79
  it "should raise an error if a brightness is set to an integer greater than 15" do
80
- lambda{@monome.brightness = 16}.should raise_error(ArgumentError)
80
+ lambda{@monome.brightness = 17}.should raise_error(ArgumentError)
81
81
  end
82
82
  end
83
83
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monome_serial
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Aaron
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-07 00:00:00 +01:00
12
+ date: 2010-01-21 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency