ledstrip 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.
- checksums.yaml +4 -4
- data/README.md +8 -1
- data/lib/ledstrip/effects/base.rb +43 -0
- data/lib/ledstrip/effects/full_color.rb +17 -0
- data/lib/ledstrip/effects/rainbow.rb +29 -0
- data/lib/ledstrip/effects/random.rb +21 -0
- data/lib/ledstrip/effects.rb +8 -0
- data/lib/ledstrip/led.rb +5 -2
- data/lib/ledstrip/strip.rb +12 -2
- data/lib/ledstrip/type/terminal.rb +42 -0
- data/lib/ledstrip/version.rb +1 -1
- data/lib/ledstrip.rb +7 -0
- data/spec/ledstrip/effects/random_spec.rb +19 -0
- data/spec/ledstrip/strip_spec.rb +2 -2
- metadata +10 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c3c2addaeb10f7c40f7d53f44fcc041f2698d8d
|
4
|
+
data.tar.gz: db5f945f884e07d17cef527038c78883c5f7269a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e56ba7800d8c8148a9a40f139efcf2d8605fe75f389572477e27d60c7a920d116bc69a5fbca6656561f644d259c228eedb979df85005c1ddc07133d8c7afee17
|
7
|
+
data.tar.gz: 059825e116095ad49585767af720071051f835a94dafec6c55831f04d3955d26c7965642b40e19d4eaba7478a5604f9423a5fef06abf1ec770aafe0e3fcd6301
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Ledstrip
|
2
2
|
|
3
3
|
So you have a ledstrip? And you have a Raspberry Pi?
|
4
|
+
|
4
5
|
Let's combine the two and have some fun with ruby.
|
5
6
|
|
6
7
|
## Installation
|
@@ -18,8 +19,9 @@ Or install it yourself as:
|
|
18
19
|
$ gem install ledstrip
|
19
20
|
|
20
21
|
## Usage
|
21
|
-
|
22
|
+
``` ruby
|
22
23
|
strip = Ledstrip::Strip.new(30, Ledstrip::Type::LPD6803.new)
|
24
|
+
|
23
25
|
loop do
|
24
26
|
30.times do |x|
|
25
27
|
strip.leds[x].r = rand(255)
|
@@ -30,6 +32,11 @@ loop do
|
|
30
32
|
strip.draw
|
31
33
|
sleep .5
|
32
34
|
end
|
35
|
+
```
|
36
|
+
|
37
|
+
## Current Status
|
38
|
+
|
39
|
+
Very much a work in progress, I haven't even tested it on the raspi yet as my strip is currently being shipped to me.
|
33
40
|
|
34
41
|
## Contributing
|
35
42
|
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Ledstrip
|
2
|
+
module Effects
|
3
|
+
class Base
|
4
|
+
|
5
|
+
attr_accessor :running
|
6
|
+
|
7
|
+
def initialize(strip, options = {})
|
8
|
+
@strip = strip
|
9
|
+
@options = options
|
10
|
+
@running = false
|
11
|
+
@frame = 1
|
12
|
+
end
|
13
|
+
|
14
|
+
def sleep_time
|
15
|
+
1
|
16
|
+
end
|
17
|
+
|
18
|
+
def start
|
19
|
+
@running = true
|
20
|
+
run
|
21
|
+
end
|
22
|
+
|
23
|
+
def stop
|
24
|
+
@running = false
|
25
|
+
end
|
26
|
+
|
27
|
+
def tick
|
28
|
+
@strip.leds = step(@strip.leds)
|
29
|
+
@strip.draw
|
30
|
+
@frame += 1
|
31
|
+
end
|
32
|
+
|
33
|
+
def run
|
34
|
+
Thread.new do
|
35
|
+
while(running) do
|
36
|
+
tick
|
37
|
+
sleep sleep_time
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Ledstrip
|
2
|
+
module Effects
|
3
|
+
class Rainbow < Base
|
4
|
+
|
5
|
+
def step(leds)
|
6
|
+
i = @frame
|
7
|
+
frequency = 0.3
|
8
|
+
|
9
|
+
leds.collect do |led|
|
10
|
+
red = Math.sin(frequency*i + 0) * 127 + 128
|
11
|
+
green = Math.sin(frequency*i + 2) * 127 + 128
|
12
|
+
blue = Math.sin(frequency*i + 4) * 127 + 128
|
13
|
+
|
14
|
+
led.red = red
|
15
|
+
led.green = green
|
16
|
+
led.blue = blue
|
17
|
+
|
18
|
+
i += 1
|
19
|
+
led
|
20
|
+
end.reverse
|
21
|
+
end
|
22
|
+
|
23
|
+
def sleep_time
|
24
|
+
0.1
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Ledstrip
|
2
|
+
module Effects
|
3
|
+
class Random < Base
|
4
|
+
|
5
|
+
def step(leds)
|
6
|
+
next_state(leds)
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
def next_state(leds)
|
11
|
+
leds.collect do |led|
|
12
|
+
led.red = rand(255)
|
13
|
+
led.green = rand(255)
|
14
|
+
led.blue = rand(255)
|
15
|
+
led
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/ledstrip/led.rb
CHANGED
@@ -3,9 +3,12 @@ module Ledstrip
|
|
3
3
|
|
4
4
|
attr_accessor :r, :g, :b
|
5
5
|
|
6
|
-
def initialize(:
|
7
|
-
@r, @g, @b =
|
6
|
+
def initialize(r: 0, g: 0, b: 0)
|
7
|
+
@r, @g, @b = r, g, b
|
8
8
|
end
|
9
9
|
|
10
|
+
def red=(value); @r = value; end
|
11
|
+
def green=(value); @g = value; end
|
12
|
+
def blue=(value); @b = value; end
|
10
13
|
end
|
11
14
|
end
|
data/lib/ledstrip/strip.rb
CHANGED
@@ -1,19 +1,29 @@
|
|
1
1
|
module Ledstrip
|
2
2
|
class Strip
|
3
3
|
|
4
|
-
attr_accessor :leds
|
4
|
+
attr_accessor :leds, :effect
|
5
5
|
|
6
|
-
def initialize(led_count, type)
|
6
|
+
def initialize(led_count, type:)
|
7
7
|
@leds = []
|
8
8
|
@type = type
|
9
9
|
|
10
10
|
init_leds(led_count)
|
11
11
|
end
|
12
12
|
|
13
|
+
def set_effect(name, options={})
|
14
|
+
@effect.stop if @effect
|
15
|
+
@effect = Ledstrip::Effects.instantiate(self, name, options)
|
16
|
+
@effect.start
|
17
|
+
end
|
18
|
+
|
13
19
|
def draw
|
14
20
|
@type.draw(@leds)
|
15
21
|
end
|
16
22
|
|
23
|
+
def sleep_time
|
24
|
+
@effect.sleep_time
|
25
|
+
end
|
26
|
+
|
17
27
|
private
|
18
28
|
def init_leds(led_count)
|
19
29
|
led_count.times { |x| @leds << Led.new(r: 255, g: 255, b: 255) }
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Ledstrip
|
2
|
+
module Type
|
3
|
+
class Terminal
|
4
|
+
|
5
|
+
def draw(leds)
|
6
|
+
clear_screen
|
7
|
+
write_leds(leds)
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
def clear_screen
|
12
|
+
system("clear")
|
13
|
+
end
|
14
|
+
|
15
|
+
def write_leds(leds)
|
16
|
+
leds.each_with_index do |led, x|
|
17
|
+
print_color(x + 1, rgb(led.r, led.g, led.b))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def print_color(pos, color)
|
22
|
+
print "\x1b[48;5;#{color}m"
|
23
|
+
print "\x1b[38;5;235m"
|
24
|
+
print " #{pos % 10} "
|
25
|
+
reset_color
|
26
|
+
end
|
27
|
+
|
28
|
+
def reset_color
|
29
|
+
print "\x1b[0m"
|
30
|
+
end
|
31
|
+
|
32
|
+
def rgb(red, green, blue)
|
33
|
+
16 + (to_ansi_domain(red) * 36) + (to_ansi_domain(green) * 6) + to_ansi_domain(blue)
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_ansi_domain(value)
|
37
|
+
(6 * (value / 256.0)).to_i
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/ledstrip/version.rb
CHANGED
data/lib/ledstrip.rb
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
require "ledstrip/version"
|
2
2
|
require "ledstrip/led"
|
3
|
+
require "ledstrip/type/lpd6803"
|
4
|
+
require "ledstrip/effects"
|
5
|
+
require "ledstrip/effects/base"
|
6
|
+
require "ledstrip/effects/random"
|
7
|
+
require "ledstrip/effects/full_color"
|
8
|
+
require "ledstrip/effects/rainbow"
|
9
|
+
require "ledstrip/type/terminal"
|
3
10
|
require "ledstrip/strip"
|
4
11
|
|
5
12
|
module Ledstrip
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "ledstrip/effects/random"
|
3
|
+
|
4
|
+
describe Ledstrip::Effects::Random do
|
5
|
+
context "#initialze" do
|
6
|
+
it "accepts a strip" do
|
7
|
+
strip = double("strip")
|
8
|
+
effect = Ledstrip::Effects::Random.new(strip)
|
9
|
+
|
10
|
+
expect(effect.strip).to eq(strip)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context "#tick" do
|
15
|
+
xit "generates random colors" do
|
16
|
+
# how to test randomness
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/spec/ledstrip/strip_spec.rb
CHANGED
@@ -7,7 +7,7 @@ describe Ledstrip::Strip do
|
|
7
7
|
|
8
8
|
it "accepts a type" do
|
9
9
|
type = double
|
10
|
-
expect{ Ledstrip::Strip.new(30, type) }.to_not raise_error
|
10
|
+
expect{ Ledstrip::Strip.new(30, type: type) }.to_not raise_error
|
11
11
|
end
|
12
12
|
|
13
13
|
end
|
@@ -18,7 +18,7 @@ describe Ledstrip::Strip do
|
|
18
18
|
type = double("type")
|
19
19
|
allow(type).to receive(:draw)
|
20
20
|
|
21
|
-
subject = Ledstrip::Strip.new(1, type)
|
21
|
+
subject = Ledstrip::Strip.new(1, type: type)
|
22
22
|
subject.draw
|
23
23
|
|
24
24
|
expect(type).to have_received(:draw).with(subject.leds)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ledstrip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roy van der Meij
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pi_piper
|
@@ -81,10 +81,17 @@ files:
|
|
81
81
|
- Rakefile
|
82
82
|
- ledstrip.gemspec
|
83
83
|
- lib/ledstrip.rb
|
84
|
+
- lib/ledstrip/effects.rb
|
85
|
+
- lib/ledstrip/effects/base.rb
|
86
|
+
- lib/ledstrip/effects/full_color.rb
|
87
|
+
- lib/ledstrip/effects/rainbow.rb
|
88
|
+
- lib/ledstrip/effects/random.rb
|
84
89
|
- lib/ledstrip/led.rb
|
85
90
|
- lib/ledstrip/strip.rb
|
86
91
|
- lib/ledstrip/type/lpd6803.rb
|
92
|
+
- lib/ledstrip/type/terminal.rb
|
87
93
|
- lib/ledstrip/version.rb
|
94
|
+
- spec/ledstrip/effects/random_spec.rb
|
88
95
|
- spec/ledstrip/strip_spec.rb
|
89
96
|
- spec/ledstrip/type/lpd6803_spec.rb
|
90
97
|
- spec/spec_helper.rb
|
@@ -113,6 +120,7 @@ signing_key:
|
|
113
120
|
specification_version: 4
|
114
121
|
summary: Control your ledstrips with ruby
|
115
122
|
test_files:
|
123
|
+
- spec/ledstrip/effects/random_spec.rb
|
116
124
|
- spec/ledstrip/strip_spec.rb
|
117
125
|
- spec/ledstrip/type/lpd6803_spec.rb
|
118
126
|
- spec/spec_helper.rb
|