blinkytape-orb 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NmMxYTllNTkyNTllOTk2ZTgwMWQxYTgzZGEwODFkNGI0NjRhMGFiYw==
4
+ YjQxZWMwMDhjNTA2NzQ0ZmMxM2IzMTA3ZGE3OWY5OWM5NDZmN2RiYw==
5
5
  data.tar.gz: !binary |-
6
- MTg3NDhlZGFiZGM4NzBlNzgyN2MyOTU0ODYwOTlkMjAwNmFjMTlkMA==
6
+ NjE5ZDU0MDcyYWRiYWMzOTBhYTRhOTMyYzJjY2NlYzMzZTA1ZWNkYw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZTUyNDAwYjJiNjI1OWNjYjllYThlMTNmMWVhMGY5NDQwOGJkYTU1MzEyMzg3
10
- YTFkNGY1OTAyYmU4MmEyYjc1ODcxY2U1Yzc4NjFkZWFhYmE0MzAwZGMxYjUz
11
- MDdlOTAxNGE1Y2JiMDc0MjE4NGIzYzdiZjEzODZjNzlhOTQ3NWU=
9
+ MmViNWViMmNkN2E2N2E2MmI5MjA0M2Y1NWVkY2UxOWYzODVlOTIxMWRjM2Fm
10
+ NGVmZjQ3MjBhNDI3ZmI1NjU2MzU4N2E3OGFiNTkwOGY2ZTNmYmVmZDgyODc4
11
+ MWIxYWQxN2Y0NGVhMWQ3YzZjZDUzOTQ0ZjcyMWVkNTEwNDVmZWQ=
12
12
  data.tar.gz: !binary |-
13
- ZDM2NTlhMTg4YjQ3YWUxODhiMmFkZDU4MTQ4ZWI1NTdkM2M5OGM5MDI2NGJk
14
- ZjE2ZjYzMmUxMmUyMjZjMDhmNTNiNzE5MjQ0NzUzOTI3MGViZmUxNjY5NTYy
15
- NTIzYzI2MjljOWMzOTM2ZGMwY2NiNWM1NGQ4YjIxMDFkNmRkMjM=
13
+ ZTg4ZjZmY2FkMDg0YTY0ZTViZDEyOWE1YjY4ODViZDRhODI4ZWE0NzY2YWFh
14
+ NDM5OWE4N2M2NGQwMDVkMDUzYjgyNjk4MWVjZGM4MjI4ZTZmOTMxNmY1NWNk
15
+ ODc3MDBjNjQzZWI4Zjc3YmNjZWZmZmUzZjQ0YzM1Y2Y4ZDJhMzU=
data/LICENSE.md CHANGED
@@ -1,4 +1,4 @@
1
- The MIT License (MIT)
1
+ ## The MIT License (MIT)
2
2
 
3
3
  Copyright (c) 2016 Jon Tai
4
4
 
@@ -20,13 +20,13 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
22
22
 
23
-
23
+ ---
24
24
 
25
25
  Hardware initialization and interrupt handling arduino code was copied from
26
26
  https://github.com/Blinkinlabs/BlinkyTape_Arduino, which has the following
27
27
  license:
28
28
 
29
- The MIT License (MIT)
29
+ ## The MIT License (MIT)
30
30
 
31
31
  Copyright (c) 2013 Blinkinlabs, LLC
32
32
 
data/README.md CHANGED
@@ -19,7 +19,7 @@ display everything. This protocol is required for compatibility with BlinkyTape
19
19
  software such as [PatternPaint](http://blinkinlabs.com/blinkytape/patternpaint/).
20
20
 
21
21
  On the other hand, the Ambient Orb accepts a color and animation, encoded as
22
- ASCII. After recieving an update, the Orb continues to animate (pulse) on its
22
+ ASCII. After recieving a command, the Orb continues to animate (pulse) on its
23
23
  own. Like on the BlinkyTape, the button is used to cycle through several
24
24
  brightness levels.
25
25
 
@@ -30,7 +30,7 @@ differences:
30
30
  * Only 6 colors and 4 pulse speeds are accepted (vs. 37 and 10,
31
31
  respectively)
32
32
  * As a result, the serial protocol is simplified to 1 ASCII character per
33
- update
33
+ command
34
34
  * Brightness can be controlled via the serial protocol as well as via the
35
35
  hardware button (it's unclear if the Orb allowed this as well)
36
36
  * Animations were recreated from memory without comparing them side by side
@@ -79,19 +79,19 @@ sleep(3)
79
79
  [ BlinkyTapeOrb::COLOR_YELLOW, BlinkyTapeOrb::PULSE_MED ],
80
80
  [ BlinkyTapeOrb::COLOR_ORANGE, BlinkyTapeOrb::PULSE_MED ],
81
81
  [ BlinkyTapeOrb::COLOR_RED, BlinkyTapeOrb::PULSE_FAST ],
82
- ].each do |(color, animation)|
83
- orb.update(color, animation)
82
+ ].each do |(color, pulse)|
83
+ orb.setColorAndPulse(color, pulse)
84
84
  sleep(10)
85
85
  end
86
86
  ```
87
87
 
88
- # Serial Protocol
88
+ ## Serial Protocol
89
89
 
90
- The custom firmware accepts a single ASCII character per update. Regular
91
- updates encode both a color and pulse speed. Some characters are set aside to
92
- allow controlling brightness.
90
+ The custom firmware accepts a single ASCII character per command. Color and
91
+ pulse speed commands encode both attributes in a single character. In
92
+ brightness commands, a single character corresponds to a single brightness.
93
93
 
94
- ## Regular Updates (Color and Pulse Speed)
94
+ ### Color and Pulse Speed
95
95
 
96
96
  The two lowest bits encode the pulse speed:
97
97
 
@@ -123,7 +123,7 @@ In other words, "A" is red with no pulsing, followed by "B" for slow pulsing,
123
123
  "C" for medium pulsing, and "D" for fast pulsing. "E" is orange with no
124
124
  pulsing, "F" is orange with slow pulsing, etc.
125
125
 
126
- ## Brightness Updates
126
+ ### Brightness
127
127
 
128
128
  There are three settings encoded in two bits:
129
129
 
@@ -131,14 +131,14 @@ There are three settings encoded in two bits:
131
131
  * `01` - Medium
132
132
  * `10` - Bright
133
133
 
134
- These are "shifted up" by 97 (ASCII "a"). So "a" is dim, "b" is medium, and "c"
134
+ These are "shifted up" by 60 (ASCII "<"). So "<" is dim, "=" is medium, and ">"
135
135
  is bright. The Ruby one-liner for encoding is:
136
136
 
137
137
  ```ruby
138
- ('a'.ord + brightness).chr
138
+ ('<'.ord + brightness).chr
139
139
  ```
140
140
 
141
- # Hardware Setup
141
+ ## Hardware Setup
142
142
 
143
143
  I stuck the [BlinkyTape controller board](http://blinkinlabs.myshopify.com/collections/frontpage/products/blinkytape-control-board)
144
144
  on the plastic base of the Orb with a small styrofoam riser (poor man's 3D
@@ -45,30 +45,27 @@ void checkSerial() {
45
45
  command = Serial.read();
46
46
  }
47
47
 
48
- // handle brightness changes immediately
49
- // if command was a brightness change or an invalid command,
50
- // swallow it to prevent rushing through the next fade
51
- switch (command) {
52
- case 97:
53
- brightness = BRIGHTNESS_MIN;
54
- FastLED.setBrightness(brightness);
55
- command = prev_command;
56
- break;
57
- case 98:
58
- brightness = BRIGHTNESS_MED;
59
- FastLED.setBrightness(brightness);
60
- command = prev_command;
61
- break;
62
- case 99:
63
- brightness = BRIGHTNESS_MAX;
64
- FastLED.setBrightness(brightness);
65
- command = prev_command;
66
- break;
67
- default:
68
- if (command - 65 >= 24) { // swallow garbage values
69
- command = prev_command;
70
- }
71
- break;
48
+ // handle certain commands immediately, then swallow the
49
+ // handled commands to prevent rushing through the next fade
50
+ if (command >= 60 && command < 63) { // brightness
51
+ switch (command - 60) { // align to ASCII "<"
52
+ case 0:
53
+ brightness = BRIGHTNESS_MIN;
54
+ break;
55
+ case 1:
56
+ brightness = BRIGHTNESS_MED;
57
+ break;
58
+ case 2:
59
+ brightness = BRIGHTNESS_MAX;
60
+ break;
61
+ }
62
+
63
+ FastLED.setBrightness(brightness);
64
+ command = prev_command;
65
+ } else if (command >= 65 && command < 89) { // color and pulse
66
+ // handled later at low point in fade for a nice smooth transition
67
+ } else { // invalid command
68
+ command = prev_command;
72
69
  }
73
70
  }
74
71
 
@@ -46,7 +46,7 @@ class BlinkyTapeOrb
46
46
  end
47
47
  end
48
48
 
49
- def update(color, pulse)
49
+ def setColorAndPulse(color, pulse)
50
50
  if (color < 0 || color > 5)
51
51
  raise ArgumentError, 'color must be between 0 and 5'
52
52
  end
@@ -67,7 +67,7 @@ class BlinkyTapeOrb
67
67
 
68
68
  logger.info("setting brightness=#{brightness}")
69
69
 
70
- send(('a'.ord + brightness).chr)
70
+ send(('<'.ord + brightness).chr)
71
71
  end
72
72
 
73
73
  private
@@ -1,3 +1,3 @@
1
1
  class BlinkyTapeOrb
2
- VERSION = '0.0.2'
2
+ VERSION = '0.1.0'
3
3
  end
@@ -44,7 +44,7 @@ describe BlinkyTapeOrb do
44
44
 
45
45
  end
46
46
 
47
- describe '#update' do
47
+ describe '#setColorAndPulse' do
48
48
 
49
49
  let (:color) { BlinkyTapeOrb::COLOR_RED }
50
50
  let (:pulse) { BlinkyTapeOrb::PULSE_NONE }
@@ -54,7 +54,7 @@ describe BlinkyTapeOrb do
54
54
 
55
55
  it 'raises ArgumentError' do
56
56
  expect {
57
- orb.update(color, pulse)
57
+ orb.setColorAndPulse(color, pulse)
58
58
  }.to raise_error(ArgumentError)
59
59
  end
60
60
  end
@@ -64,33 +64,33 @@ describe BlinkyTapeOrb do
64
64
 
65
65
  it 'raises ArgumentError' do
66
66
  expect {
67
- orb.update(color, pulse)
67
+ orb.setColorAndPulse(color, pulse)
68
68
  }.to raise_error(ArgumentError)
69
69
  end
70
70
  end
71
71
 
72
72
  context 'with valid arguments' do
73
- it 'sends correct update' do
73
+ it 'sends correct command' do
74
74
  expect(orb).to receive(:send).with('A')
75
- orb.update(color, pulse)
75
+ orb.setColorAndPulse(color, pulse)
76
76
  end
77
77
  end
78
78
 
79
79
  context 'with purple color' do
80
80
  let (:color) { BlinkyTapeOrb::COLOR_PURPLE }
81
81
 
82
- it 'sends correct update' do
82
+ it 'sends correct command' do
83
83
  expect(orb).to receive(:send).with('U')
84
- orb.update(color, pulse)
84
+ orb.setColorAndPulse(color, pulse)
85
85
  end
86
86
  end
87
87
 
88
88
  context 'with fast pulse' do
89
89
  let (:pulse) { BlinkyTapeOrb::PULSE_FAST }
90
90
 
91
- it 'sends correct update' do
91
+ it 'sends correct command' do
92
92
  expect(orb).to receive(:send).with('D')
93
- orb.update(color, pulse)
93
+ orb.setColorAndPulse(color, pulse)
94
94
  end
95
95
  end
96
96
 
@@ -111,8 +111,8 @@ describe BlinkyTapeOrb do
111
111
  end
112
112
 
113
113
  context 'with valid arguments' do
114
- it 'sends correct update' do
115
- expect(orb).to receive(:send).with('c')
114
+ it 'sends correct command' do
115
+ expect(orb).to receive(:send).with('>')
116
116
  orb.setBrightness(brightness)
117
117
  end
118
118
  end
@@ -120,8 +120,8 @@ describe BlinkyTapeOrb do
120
120
  context 'with min brightness' do
121
121
  let (:brightness) { BlinkyTapeOrb::BRIGHTNESS_MIN }
122
122
 
123
- it 'sends correct update' do
124
- expect(orb).to receive(:send).with('a')
123
+ it 'sends correct command' do
124
+ expect(orb).to receive(:send).with('<')
125
125
  orb.setBrightness(brightness)
126
126
  end
127
127
  end
@@ -137,7 +137,7 @@ describe BlinkyTapeOrb do
137
137
  io = double('serial_port')
138
138
  expect(io).to receive(:write).with('A')
139
139
  expect(SerialPort).to receive(:open).and_yield(io)
140
- orb.update(BlinkyTapeOrb::COLOR_RED, BlinkyTapeOrb::PULSE_NONE)
140
+ orb.setColorAndPulse(BlinkyTapeOrb::COLOR_RED, BlinkyTapeOrb::PULSE_NONE)
141
141
  end
142
142
 
143
143
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blinkytape-orb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Tai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-24 00:00:00.000000000 Z
11
+ date: 2016-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: serialport