l8 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 88b84aac9e164d3a2574231a4faec8a90477f0a3
4
- data.tar.gz: d273d1937fc4a2fe49acfec4b6f27399f42fd36d
3
+ metadata.gz: 552b313bea0a79a81b188d377ac2fabbfdc4cbfe
4
+ data.tar.gz: 3c1d0312e81a4fd772d080075043ba7acfe72f66
5
5
  SHA512:
6
- metadata.gz: e48676e30685b59040d1a096a351c2d8c566e378685ef816b9daa9cd4653826c7ef949a7cf32689d6c306175552de39243afe88357fee0a88dd0342af74d0d46
7
- data.tar.gz: cc6d2d306537f5f9c57e54eae75267f43d4996c1f2d45615e069d09ee85778f9f720d60fce3314eab6a4742928109dd641f4a8ad06d24430a1ab659e25e23c79
6
+ metadata.gz: fbd1ee91b43f246b3375bedfffb6eea00c90cda1d3e9180fe89f7c4680c64aa87652f15cda52f6432eee2f3bba1174d3c05ab4414e92c7a70ef8dea30e140ae6
7
+ data.tar.gz: a76b1e1b2ff62c76c0c7b215c1d3cccb42e65f28670d503a740b0e3b847b7b265080290eec0af2fa383c7fd43b2efd85071617a9d8859497e7334c0b8e82615a
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # L8
4
4
 
5
- A gem for communicating with an [L8 SmartLight](http://l8smartlight.com) over USB.
5
+ A Ruby Gem for communicating with an [L8 SmartLight](http://l8smartlight.com) over USB.
6
6
 
7
7
  ## Installation
8
8
 
@@ -22,12 +22,12 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- To connect to your L8 Smartlight, determine the serial port it's on:
25
+ To connect to your L8 Smartlight, determine the serial port it's on and then create a new L8::Smartlight:
26
26
 
27
27
  require 'l8'
28
28
  l8 = L8::Smartlight.new('/dev/tty.usbmodem1421')
29
29
 
30
- ### Changing LEDs
30
+ ### Change LEDs
31
31
 
32
32
  Use `set_led` to set one of the LEDs to a color. The arguments are:
33
33
 
@@ -41,21 +41,69 @@ For example, to set the 5th LED in the 3rd row to orange:
41
41
 
42
42
  l8.set_led(2, 4, 15, 7, 0)
43
43
 
44
- ### Clearing the LEDs
44
+ ### Clear the LEDs
45
45
 
46
46
  Use the `clear_matrix` method:
47
47
 
48
48
  l8.clear_matrix
49
49
 
50
- ### Changing the Super (Back) LED
50
+ ### Change the Super (Back) LED
51
51
 
52
52
  Use the `set_superled` method and pass 3 color values (0..15):
53
53
 
54
54
  l8.set_superled(0, 0, 15)
55
+
56
+ ### Set L8 Brightness
57
+
58
+ You can control the overall brightness of the L8 using the `set_brightness` method with one of the following values: `:high`, `:medium` or `:low`.
59
+
60
+ l8.set_brightness(:low)
61
+
62
+ ### Disable/Enable Status LEDs
63
+
64
+ The status LEDs on the top of the L8 can leak light into the LED matrix or just detract from the main LEDs in general, so you can turn them off with the `disable_status_leds` method. There is a `enable_status_leds` method to turn them back on.
65
+
66
+ l8.disable_status_leds
67
+
68
+ ### Force L8 Orientation
69
+
70
+ If you lay the L8 flat or move it around a lot it may lose your preferred orienation in reference to the status lights at the top of the L8.
71
+
72
+ You can force the orientation using the `set_orientation` method and passing one of the following: `:up`, `:down`, `:left` or `:right`.
73
+
74
+ l8.set_orientation(:down)
75
+
76
+ ### Display Character
77
+
78
+ To display an alpha-numeric character on the L8, use the `display_character` method and send a single Ascii character.
79
+
80
+ l8.display_character('')
81
+
82
+ ### Power Off
83
+
84
+ You can turn the L8s off using the `power_off` method.
85
+
86
+ l8.power_off
87
+
88
+ ### Controlling Groups of L8s
89
+
90
+ You can control a group of L8s as either a Stack or Row of them. This will give you a `set_led` method that treats them as one big matrix of LEDs.
91
+
92
+ stack = L8::Stack.new('/dev/tty.usbmodem1421', '/dev/tty.usbmodem1422')
93
+ stack.set_led(7, 15, 0, 15, 0)
94
+
95
+ The following methods are also available on groups of L8s and affect all L8s in the group.
96
+
97
+ - `clear_matrix`
98
+ - `disable_status_lights`
99
+
100
+ #### Identify L8s in a Group
101
+
102
+ When using a group of L8s you might get your USB ports/wires crossed and need to figure out the correct order to put the L8s in. The `identify` method will put a number on each L8 letting you know how to arrange them - left to right or top to bottom, start at 1.
55
103
 
56
104
  ## Resources
57
105
 
58
- - [SLCP Specification 1.0](http://www.l8smartlight.com/dev/slcp/1.0/#_Toc380755772)
106
+ - [SLCP Specification 1.0](http://www.l8smartlight.com/dev/slcp/1.0/)
59
107
 
60
108
  ## Contributing
61
109
 
@@ -39,7 +39,7 @@ def get_statuses(url)
39
39
  JSON.parse(response)
40
40
  end
41
41
 
42
- @l8 = L8::Smartlight.new('/dev/tty.usbmodem1411')
42
+ @l8 = L8::Smartlight.new('/dev/tty.usbmodem1a1211')
43
43
 
44
44
  @projects = %w(
45
45
  https://api.travis-ci.org/repos/spilth/l8/builds
@@ -0,0 +1,46 @@
1
+ require 'l8'
2
+
3
+ stack = L8::Stack.new('/dev/tty.usbmodem1a1211', '/dev/tty.usbmodem1a1221')
4
+ stack.clear_matrix
5
+
6
+ sleep 2
7
+
8
+ # ground
9
+
10
+ (0..7).each do |y|
11
+ stack.set_led(15, y, 0, 7, 0)
12
+ end
13
+
14
+ # ship
15
+
16
+ stack.set_led(14, 0, 15, 15, 15)
17
+ stack.set_led(14, 1, 15, 15, 15)
18
+ stack.set_led(14, 2, 15, 15, 15)
19
+ stack.set_led(13, 1, 15, 15, 15)
20
+
21
+ # stars
22
+
23
+ stack.set_led(1, 6, 1, 1, 1)
24
+ stack.set_led(3, 2, 1, 1, 1)
25
+ stack.set_led(6, 5, 1, 1, 1)
26
+ stack.set_led(8, 2, 1, 1, 1)
27
+ stack.set_led(10, 6, 1, 1, 1)
28
+
29
+ # asteroids
30
+
31
+ stack.set_led(1,1, 15, 7, 0)
32
+ stack.set_led(1,2, 15, 7, 0)
33
+ stack.set_led(2,1, 15, 7, 0)
34
+ stack.set_led(2,2, 15, 7, 0)
35
+
36
+ stack.set_led(4,6, 15, 0, 15)
37
+ stack.set_led(4,7, 15, 0, 15)
38
+ stack.set_led(5,6, 15, 0, 15)
39
+ stack.set_led(5,7, 15, 0, 15)
40
+
41
+ stack.set_led(9, 4, 15, 15, 0)
42
+ stack.set_led(9, 5, 15, 15, 0)
43
+ stack.set_led(10, 4, 15, 15, 0)
44
+ stack.set_led(10, 5, 15, 15, 0)
45
+
46
+ sleep 2
@@ -0,0 +1,63 @@
1
+ require 'l8'
2
+ require 'sdl'
3
+
4
+ SDL.init(SDL::INIT_JOYSTICK)
5
+ @joystick = SDL::Joystick.open(0)
6
+
7
+ @x = 0
8
+ @y = 0
9
+
10
+ @l8 = L8::Row.new('/dev/tty.usbmodem1a1211', '/dev/tty.usbmodem1a1221')
11
+ @l8.clear_matrix
12
+ @l8.disable_status_leds
13
+ # @l8.set_brightness(:low)
14
+ # @l8.set_superled(0,0,0)
15
+ @l8.set_led(@x,@y, 15, 15, 15)
16
+ @l8.identify
17
+
18
+ @colors = [
19
+ [14,0,0],
20
+ [0,14,0],
21
+ [0,0,14],
22
+ [14,14,14],
23
+ [0,0,0]
24
+ ]
25
+ @color_index = 0
26
+
27
+ while(true) do
28
+ SDL::Joystick.update_all
29
+ break if @joystick.button(9)
30
+ sleep 0.1
31
+ end
32
+
33
+ def read_joystick
34
+ SDL::Joystick.update_all
35
+
36
+ @color_index = @color_index + 1 if @joystick.button(1)
37
+ @color_index = @color_index - 1 if @joystick.button(2)
38
+
39
+ @color_index = 0 if @color_index > 4
40
+ @color_index = 4 if @color_index < 0
41
+
42
+ color = @colors[@color_index]
43
+ @l8.set_led(@y,@x, color[0], color[1], color[2])
44
+
45
+ # @l8.set_superled(color[0], color[1], color[2]) if @joystick.button(8)
46
+
47
+ @x = @x - 1 if @joystick.axis(3) < -16384
48
+ @x = @x + 1 if @joystick.axis(3) > 16384
49
+ @y = @y - 1 if @joystick.axis(4) < -16384
50
+ @y = @y + 1 if @joystick.axis(4) > 16384
51
+
52
+ @x = 0 if @x < 0
53
+ @y = 0 if @y < 0
54
+ @x = 15 if @x > 15
55
+ @y = 7 if @y > 7
56
+
57
+ @l8.set_led(@y,@x, color[0] + 1, color[1] + 1, color[2] + 1)
58
+
59
+ @l8.clear_matrix if @joystick.button(9)
60
+ sleep 0.2
61
+ end
62
+
63
+ read_joystick while(true)
@@ -0,0 +1,44 @@
1
+ require 'l8'
2
+
3
+ row = L8::Row.new('/dev/tty.usbmodem1a1211', '/dev/tty.usbmodem1a1221')
4
+ row.clear_matrix
5
+ row.disable_status_leds
6
+
7
+ sleep 1
8
+
9
+ # red paddle
10
+
11
+ (2..4).each do |x|
12
+ row.set_led(x, 0, 15, 0, 0)
13
+ end
14
+
15
+ # blue paddle
16
+
17
+ (3..5).each do |x|
18
+ row.set_led(x, 15, 0, 0, 15)
19
+ end
20
+
21
+ # ball
22
+
23
+ row.set_led(3, 4, 15, 15, 15)
24
+
25
+ # red score
26
+
27
+ (4..6).each do |x|
28
+ row.set_led(0, x, 1, 0, 0)
29
+ end
30
+
31
+ # blue score
32
+
33
+ (9..13).each do |x|
34
+ row.set_led(0, x, 0, 0, 1)
35
+ end
36
+
37
+ # divider
38
+
39
+ (0..7).step(2) do |x|
40
+ row.set_led(x, 7, 1, 1, 1)
41
+ row.set_led(x + 1, 8, 1, 1, 1)
42
+ end
43
+
44
+ sleep 2
data/lib/l8.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'l8/version'
2
2
  require 'l8/smartlight'
3
+ require 'l8/group'
3
4
  require 'l8/stack'
5
+ require 'l8/row'
4
6
  require 'l8/util'
5
7
 
6
8
  module L8
@@ -0,0 +1,30 @@
1
+ module L8
2
+ class Group
3
+ def initialize(*ports)
4
+ @l8s = []
5
+
6
+ ports.each do |port|
7
+ @l8s << L8::Smartlight.new(port)
8
+ end
9
+ end
10
+
11
+ def disable_status_leds
12
+ @l8s.each do |l8|
13
+ l8.disable_status_leds
14
+ end
15
+ end
16
+
17
+ def clear_matrix
18
+ @l8s.each do |l8|
19
+ l8.clear_matrix
20
+ end
21
+ end
22
+
23
+ def identify
24
+ @l8s.each_with_index do |l8, index|
25
+ l8.display_character((index + 1).to_s)
26
+ end
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,9 @@
1
+ module L8
2
+ class Row < Group
3
+ def set_led(x,y,r,g,b)
4
+ l8index = y / 8
5
+ y = y - (l8index * 8)
6
+ @l8s[l8index].set_led(x,y,r,g,b)
7
+ end
8
+ end
9
+ end
@@ -2,14 +2,15 @@ require 'rubyserial'
2
2
 
3
3
  module L8
4
4
  class Smartlight
5
+ CMD_L8_DISP_CHAR = 0x7f
5
6
  CMD_L8_LED_SET = 0x43
6
7
  CMD_L8_MATRIX_OFF = 0x45
7
- CMD_L8_SUPERLED_SET = 0x4b
8
- CMD_L8_STATUSLEDS_ENABLE = 0x9e
9
- CMD_L8_SET_LOW_BRIGHTNESS = 0x9a
10
- CMD_L8_POWEROFF = 0x9d
11
8
  CMD_L8_MATRIX_SET = 0x44
9
+ CMD_L8_POWEROFF = 0x9d
10
+ CMD_L8_SET_LOW_BRIGHTNESS = 0x9a
12
11
  CMD_L8_SET_ORIENTATION = 0x80
12
+ CMD_L8_STATUSLEDS_ENABLE = 0x9e
13
+ CMD_L8_SUPERLED_SET = 0x4b
13
14
 
14
15
  def initialize(serial_port)
15
16
  @serial_port = Serial.new(serial_port)
@@ -18,66 +19,59 @@ module L8
18
19
  end
19
20
 
20
21
  def clear_matrix
21
- @serial_port.write Util.frame([CMD_L8_MATRIX_OFF])
22
+ send_command [CMD_L8_MATRIX_OFF]
22
23
  end
23
24
 
24
25
  def set_led(x, y, r, g, b)
25
- payload = [CMD_L8_LED_SET, x, y, b, g, r, 0x00]
26
-
27
- @serial_port.write Util.frame(payload)
26
+ send_command [CMD_L8_LED_SET, x, y, b, g, r, 0x00]
28
27
  end
29
28
 
30
29
  def set_superled(r,g,b)
31
- payload = [CMD_L8_SUPERLED_SET, b, g, r]
30
+ send_command [CMD_L8_SUPERLED_SET, b, g, r]
31
+ end
32
32
 
33
- @serial_port.write Util.frame(payload)
33
+ def display_character(character)
34
+ send_command [CMD_L8_DISP_CHAR, character.bytes[0], 0]
34
35
  end
35
36
 
36
37
  def enable_status_leds
37
- payload = [CMD_L8_STATUSLEDS_ENABLE, 1]
38
-
39
- @serial_port.write Util.frame(payload)
38
+ send_command [CMD_L8_STATUSLEDS_ENABLE, 1]
40
39
  end
41
40
 
42
41
  def disable_status_leds
43
- payload = [CMD_L8_STATUSLEDS_ENABLE, 0]
44
-
45
- @serial_port.write Util.frame(payload)
42
+ send_command [CMD_L8_STATUSLEDS_ENABLE, 0]
46
43
  end
47
44
 
48
45
  def set_brightness(level)
49
46
  brightness = 0
47
+ brightness = 2 if level == :low
48
+ brightness = 1 if level == :medium
50
49
 
51
- if level == :low
52
- brightness = 2
53
- elsif level == :medium
54
- brightness = 1
55
- end
56
-
57
- payload = [CMD_L8_SET_LOW_BRIGHTNESS, brightness]
58
-
59
- @serial_port.write Util.frame(payload)
50
+ send_command [CMD_L8_SET_LOW_BRIGHTNESS, brightness]
60
51
  end
61
52
 
62
53
  def power_off
63
- @serial_port.write Util.frame([CMD_L8_POWEROFF])
54
+ send_command [CMD_L8_POWEROFF]
64
55
  end
65
56
 
66
57
  def set_matrix(pixels)
67
58
  data = Util.pixels_to_two_byte_array(pixels)
68
59
 
69
- payload = [CMD_L8_MATRIX_SET] + data
70
-
71
- @serial_port.write Util.frame(payload)
60
+ send_command [CMD_L8_MATRIX_SET] + data
72
61
  end
73
62
 
74
63
  def set_orientation(orientation)
75
- value = 1 if orientation == :up
64
+ value = 1
76
65
  value = 2 if orientation == :down
77
66
  value = 5 if orientation == :right
78
67
  value = 6 if orientation == :left
79
68
 
80
- payload = [CMD_L8_SET_ORIENTATION, value]
69
+ send_command [CMD_L8_SET_ORIENTATION, value]
70
+ end
71
+
72
+ private
73
+
74
+ def send_command payload
81
75
  @serial_port.write Util.frame(payload)
82
76
  end
83
77
  end
@@ -1,23 +1,9 @@
1
1
  module L8
2
- class Stack
3
- def initialize(*ports)
4
- @l8s = []
5
-
6
- ports.each do |port|
7
- @l8s << L8::Smartlight.new(port)
8
- end
9
- end
10
-
2
+ class Stack < Group
11
3
  def set_led(x,y,r,g,b)
12
4
  l8index = x / 8
13
5
  x = x - (l8index * 8)
14
6
  @l8s[l8index].set_led(x,y,r,g,b)
15
7
  end
16
-
17
- def clear_matrix
18
- @l8s.each do |l8|
19
- l8.clear_matrix
20
- end
21
- end
22
8
  end
23
9
  end
@@ -1,3 +1,3 @@
1
1
  module L8
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ module L8
4
+ describe Group do
5
+ describe 'constructor' do
6
+ it 'creates a Smartlight instance on each supplied serial port' do
7
+ expect(L8::Smartlight).to receive(:new).with('/dev/foo') { 'foo' }
8
+ expect(L8::Smartlight).to receive(:new).with('/dev/bar') { 'bar' }
9
+
10
+ L8::Group.new('/dev/foo', '/dev/bar')
11
+ end
12
+ end
13
+
14
+ describe '#clear_matrix' do
15
+ describe 'when there are three L8s in the Group' do
16
+ let(:light1) { double(:l8one) }
17
+ let(:light2) { double(:l8two) }
18
+ let(:light3) { double(:l8three) }
19
+
20
+ before(:each) do
21
+ allow(L8::Smartlight).to receive(:new).with('/dev/foo') { light1 }
22
+ allow(L8::Smartlight).to receive(:new).with('/dev/bar') { light2 }
23
+ allow(L8::Smartlight).to receive(:new).with('/dev/baz') { light3 }
24
+ end
25
+
26
+ it 'calls clear_matrix on each light' do
27
+ expect(light1).to receive(:clear_matrix)
28
+ expect(light2).to receive(:clear_matrix)
29
+ expect(light3).to receive(:clear_matrix)
30
+
31
+ l8Group = L8::Group.new('/dev/foo', '/dev/bar', '/dev/baz')
32
+ l8Group.clear_matrix
33
+ end
34
+ end
35
+ end
36
+
37
+ describe '#disable_status_lights' do
38
+ describe 'when there are three L8s in the Group' do
39
+ let(:light1) { double(:l8one) }
40
+ let(:light2) { double(:l8two) }
41
+ let(:light3) { double(:l8three) }
42
+
43
+ before(:each) do
44
+ allow(L8::Smartlight).to receive(:new).with('/dev/foo') { light1 }
45
+ allow(L8::Smartlight).to receive(:new).with('/dev/bar') { light2 }
46
+ allow(L8::Smartlight).to receive(:new).with('/dev/baz') { light3 }
47
+ end
48
+
49
+ it 'calls disable_status_lights on each light' do
50
+ expect(light1).to receive(:disable_status_leds)
51
+ expect(light2).to receive(:disable_status_leds)
52
+ expect(light3).to receive(:disable_status_leds)
53
+
54
+ l8Group = L8::Group.new('/dev/foo', '/dev/bar', '/dev/baz')
55
+ l8Group.disable_status_leds
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ module L8
4
+ describe Row do
5
+ describe '#set_led' do
6
+ describe 'when there are three L8s in the stack' do
7
+ let(:light1) { double(:l8one) }
8
+ let(:light2) { double(:l8two) }
9
+ let(:light3) { double(:l8three) }
10
+
11
+ before(:each) do
12
+ allow(L8::Smartlight).to receive(:new).with('/dev/foo') { light1 }
13
+ allow(L8::Smartlight).to receive(:new).with('/dev/bar') { light2 }
14
+ allow(L8::Smartlight).to receive(:new).with('/dev/baz') { light3 }
15
+ end
16
+
17
+ describe 'when the pixel is within the range of the first L8' do
18
+ it 'turns on an led on the first L8' do
19
+ expect(light1).to receive(:set_led).with(7,7,15,15,15)
20
+
21
+ l8stack = L8::Row.new('/dev/foo', '/dev/bar')
22
+ l8stack.set_led(7,7,15,15,15)
23
+ end
24
+ end
25
+
26
+ describe 'when the pixel is outside the range of the first L8' do
27
+ it 'turns on an LED on the second L8' do
28
+ expect(light2).to receive(:set_led).with(0,0,15,15,15)
29
+
30
+ l8stack = L8::Row.new('/dev/foo', '/dev/bar')
31
+ l8stack.set_led(0,8,15,15,15)
32
+ end
33
+ end
34
+
35
+ describe 'when the pixel is outside the range of the first and second L8' do
36
+ it 'turns on an LED on the third L8' do
37
+ expect(light3).to receive(:set_led).with(0,0,15,15,15)
38
+
39
+ l8stack = L8::Row.new('/dev/foo', '/dev/bar', '/dev/baz')
40
+ l8stack.set_led(0,16,15,15,15)
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -21,6 +21,15 @@ module L8
21
21
  end
22
22
  end
23
23
 
24
+ describe '#clear_matrix' do
25
+ it 'sends a command to clear the matrix' do
26
+ expect(Util).to receive(:frame).with([Smartlight::CMD_L8_MATRIX_OFF]) { 'foo'}
27
+
28
+ l8 = L8::Smartlight.new('serial_port')
29
+ l8.clear_matrix
30
+ end
31
+ end
32
+
24
33
  describe '#set_led' do
25
34
  it 'sets the color of the LED at given location' do
26
35
  expect(Util).to receive(:frame).with([Smartlight::CMD_L8_LED_SET, 3, 0, 15, 15, 15, 0]) { 'foo'}
@@ -30,6 +39,80 @@ module L8
30
39
  end
31
40
  end
32
41
 
42
+ describe '#set_superled' do
43
+ it 'sets the color of the superled' do
44
+ expect(Util).to receive(:frame).with([Smartlight::CMD_L8_SUPERLED_SET, 15, 14, 13]) { 'foo'}
45
+
46
+ l8 = L8::Smartlight.new('serial_port')
47
+ l8.set_superled(13, 14, 15)
48
+ end
49
+ end
50
+
51
+ describe '#display_character' do
52
+ it 'display a single character on the L8' do
53
+ expect(Util).to receive(:frame).with([Smartlight::CMD_L8_DISP_CHAR, 66, 0]) { 'foo' }
54
+
55
+ l8 = L8::Smartlight.new('serial_port')
56
+ l8.display_character('B')
57
+ end
58
+ end
59
+
60
+ describe '#enable_status_leds' do
61
+ it 'enables the status LEDs' do
62
+ expect(Util).to receive(:frame).with([Smartlight::CMD_L8_STATUSLEDS_ENABLE, 1]) { 'foo'}
63
+
64
+ l8 = L8::Smartlight.new('serial_port')
65
+ l8.enable_status_leds
66
+ end
67
+ end
68
+
69
+ describe '#disable_status_leds' do
70
+ it 'disables the status LEDs' do
71
+ expect(Util).to receive(:frame).with([Smartlight::CMD_L8_STATUSLEDS_ENABLE, 0]) { 'foo'}
72
+
73
+ l8 = L8::Smartlight.new('serial_port')
74
+ l8.disable_status_leds
75
+ end
76
+ end
77
+
78
+ describe '#set_brightness' do
79
+ describe 'to low' do
80
+ it 'sets it to low' do
81
+ expect(Util).to receive(:frame).with([Smartlight::CMD_L8_SET_LOW_BRIGHTNESS, 2]) { 'foo'}
82
+
83
+ l8 = L8::Smartlight.new('serial_port')
84
+ l8.set_brightness(:low)
85
+ end
86
+ end
87
+
88
+ describe 'to medium' do
89
+ it 'sets it to medium' do
90
+ expect(Util).to receive(:frame).with([Smartlight::CMD_L8_SET_LOW_BRIGHTNESS, 1]) { 'foo'}
91
+
92
+ l8 = L8::Smartlight.new('serial_port')
93
+ l8.set_brightness(:medium)
94
+ end
95
+ end
96
+
97
+ describe 'to high' do
98
+ it 'sets it to high' do
99
+ expect(Util).to receive(:frame).with([Smartlight::CMD_L8_SET_LOW_BRIGHTNESS, 0]) { 'foo'}
100
+
101
+ l8 = L8::Smartlight.new('serial_port')
102
+ l8.set_brightness(:high)
103
+ end
104
+ end
105
+ end
106
+
107
+ describe '#power_off' do
108
+ it 'sends the poweroff message' do
109
+ expect(Util).to receive(:frame).with([Smartlight::CMD_L8_POWEROFF]) { 'foo'}
110
+
111
+ l8 = L8::Smartlight.new('serial_port')
112
+ l8.power_off
113
+ end
114
+ end
115
+
33
116
  describe '#set_orientation' do
34
117
  before(:each) do
35
118
  allow(serial_port).to receive(:write).with('foo')
@@ -2,38 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  module L8
4
4
  describe Stack do
5
- describe 'constructor' do
6
- it 'creates a Smartlight instance on each supplied serial port' do
7
- expect(L8::Smartlight).to receive(:new).with('/dev/foo') { 'foo' }
8
- expect(L8::Smartlight).to receive(:new).with('/dev/bar') { 'bar' }
9
-
10
- L8::Stack.new('/dev/foo', '/dev/bar')
11
- end
12
- end
13
-
14
- describe '#clear_matrix' do
15
- describe 'when there are three L8s in the stack' do
16
- let(:light1) { double(:l8one) }
17
- let(:light2) { double(:l8two) }
18
- let(:light3) { double(:l8three) }
19
-
20
- before(:each) do
21
- allow(L8::Smartlight).to receive(:new).with('/dev/foo') { light1 }
22
- allow(L8::Smartlight).to receive(:new).with('/dev/bar') { light2 }
23
- allow(L8::Smartlight).to receive(:new).with('/dev/baz') { light3 }
24
- end
25
-
26
- it 'calls clear_matrix on each light' do
27
- expect(light1).to receive(:clear_matrix)
28
- expect(light2).to receive(:clear_matrix)
29
- expect(light3).to receive(:clear_matrix)
30
-
31
- l8stack = L8::Stack.new('/dev/foo', '/dev/bar', '/dev/baz')
32
- l8stack.clear_matrix
33
- end
34
- end
35
- end
36
-
37
5
  describe '#set_led' do
38
6
  describe 'when there are three L8s in the stack' do
39
7
  let(:light1) { double(:l8one) }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: l8
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Kelly
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-11 00:00:00.000000000 Z
11
+ date: 2015-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyserial
@@ -96,12 +96,19 @@ files:
96
96
  - Rakefile
97
97
  - examples/build_status.rb
98
98
  - examples/draw.rb
99
+ - examples/l8strosmash.rb
100
+ - examples/nes_draw.rb
101
+ - examples/pong.rb
99
102
  - l8.gemspec
100
103
  - lib/l8.rb
104
+ - lib/l8/group.rb
105
+ - lib/l8/row.rb
101
106
  - lib/l8/smartlight.rb
102
107
  - lib/l8/stack.rb
103
108
  - lib/l8/util.rb
104
109
  - lib/l8/version.rb
110
+ - spec/lib/group_spec.rb
111
+ - spec/lib/row_spec.rb
105
112
  - spec/lib/smartlight_spec.rb
106
113
  - spec/lib/stack_spec.rb
107
114
  - spec/lib/util_spec.rb
@@ -131,6 +138,8 @@ signing_key:
131
138
  specification_version: 4
132
139
  summary: Gem for communicating with an L8 SmartLight
133
140
  test_files:
141
+ - spec/lib/group_spec.rb
142
+ - spec/lib/row_spec.rb
134
143
  - spec/lib/smartlight_spec.rb
135
144
  - spec/lib/stack_spec.rb
136
145
  - spec/lib/util_spec.rb