ledstrip 0.0.1
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 +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +40 -0
- data/Rakefile +2 -0
- data/ledstrip.gemspec +25 -0
- data/lib/ledstrip/led.rb +11 -0
- data/lib/ledstrip/strip.rb +23 -0
- data/lib/ledstrip/type/lpd6803.rb +49 -0
- data/lib/ledstrip/version.rb +3 -0
- data/lib/ledstrip.rb +7 -0
- data/spec/ledstrip/strip_spec.rb +28 -0
- data/spec/ledstrip/type/lpd6803_spec.rb +17 -0
- data/spec/spec_helper.rb +8 -0
- metadata +118 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e52ad039dec4cb3437fb70c44b21c6e30b3d7047
|
4
|
+
data.tar.gz: 8d1d03c956dcc245a54aec6b7d964c48b810b803
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6b0f68c804a2083d9e9a738f36f953c1f6143cc6b708a03be63a8f4bb48bc70143d60133b6e12a939313aedcb2e6a25ba100036b0d84e7ef68e2e16c1ca657b6
|
7
|
+
data.tar.gz: a7e1292e9857a558fe4dc4021afbeb94b7ab6def553d1c0c4db05042e39c88ad6283bcdf885ad10d702a541a3f1d92623d0097d6a64df044ccf2beb4f30d0e22
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Roy van der Meij
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# Ledstrip
|
2
|
+
|
3
|
+
So you have a ledstrip? And you have a Raspberry Pi?
|
4
|
+
Let's combine the two and have some fun with ruby.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'ledstrip'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install ledstrip
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
strip = Ledstrip::Strip.new(30, Ledstrip::Type::LPD6803.new)
|
23
|
+
loop do
|
24
|
+
30.times do |x|
|
25
|
+
strip.leds[x].r = rand(255)
|
26
|
+
strip.leds[x].g = rand(255)
|
27
|
+
strip.leds[x].b = rand(255)
|
28
|
+
end
|
29
|
+
|
30
|
+
strip.draw
|
31
|
+
sleep .5
|
32
|
+
end
|
33
|
+
|
34
|
+
## Contributing
|
35
|
+
|
36
|
+
1. Fork it ( https://github.com/[my-github-username]/ledstrip/fork )
|
37
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
38
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
39
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
40
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/ledstrip.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ledstrip/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ledstrip"
|
8
|
+
spec.version = Ledstrip::VERSION
|
9
|
+
spec.authors = ["Roy van der Meij"]
|
10
|
+
spec.email = ["roy@royapps.nl"]
|
11
|
+
spec.summary = "Control your ledstrips with ruby"
|
12
|
+
spec.description = %q{This gems led you control your ledstrips connected to a raspberry pi with Ruby}
|
13
|
+
spec.homepage = "http://github.com/roy/ledstrip"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "pi_piper", "1.3.2"
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
spec.add_development_dependency "rspec"
|
25
|
+
end
|
data/lib/ledstrip/led.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module Ledstrip
|
2
|
+
class Strip
|
3
|
+
|
4
|
+
attr_accessor :leds
|
5
|
+
|
6
|
+
def initialize(led_count, type)
|
7
|
+
@leds = []
|
8
|
+
@type = type
|
9
|
+
|
10
|
+
init_leds(led_count)
|
11
|
+
end
|
12
|
+
|
13
|
+
def draw
|
14
|
+
@type.draw(@leds)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
def init_leds(led_count)
|
19
|
+
led_count.times { |x| @leds << Led.new(r: 255, g: 255, b: 255) }
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Ledstrip
|
2
|
+
module Type
|
3
|
+
class LPD6803
|
4
|
+
def initialize
|
5
|
+
end
|
6
|
+
|
7
|
+
def draw(leds)
|
8
|
+
write_start_bytes
|
9
|
+
write_leds(leds)
|
10
|
+
write_end_bytes(leds.size)
|
11
|
+
end
|
12
|
+
|
13
|
+
def write(array)
|
14
|
+
PiPiper::Spi.spidev_out(array)
|
15
|
+
# File.open('/dev/spidev0.0', 'wb'){|f| f.write(array.pack('C*')) }
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
def write_start_bytes
|
20
|
+
# 32 bits start frame
|
21
|
+
write([0,0,0,0])
|
22
|
+
end
|
23
|
+
|
24
|
+
def write_leds(leds)
|
25
|
+
leds.each do |led|
|
26
|
+
write_led(led)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def write_led(led)
|
31
|
+
bits = 0b1000000000000000
|
32
|
+
bits |= ((led.r / 255) * 31) << 10
|
33
|
+
bits |= ((led.g / 255) * 31) << 5
|
34
|
+
bits |= ((led.b / 255) * 31)
|
35
|
+
|
36
|
+
output = []
|
37
|
+
output[0] = (bits & 0xff00) >> 8
|
38
|
+
output[1] = (bits & 0x00ff) >> 0
|
39
|
+
write(output)
|
40
|
+
end
|
41
|
+
|
42
|
+
def write_end_bytes(size)
|
43
|
+
# two versions found online, one is to use bits per led other is bytes per led
|
44
|
+
write(Array.new(size / 8 + 1, 0))
|
45
|
+
# write(Array.new(size, 0))
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/ledstrip.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "ledstrip/strip"
|
3
|
+
|
4
|
+
describe Ledstrip::Strip do
|
5
|
+
|
6
|
+
context "#initialize" do
|
7
|
+
|
8
|
+
it "accepts a type" do
|
9
|
+
type = double
|
10
|
+
expect{ Ledstrip::Strip.new(30, type) }.to_not raise_error
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
context "#draw" do
|
16
|
+
|
17
|
+
it "delegates to type" do
|
18
|
+
type = double("type")
|
19
|
+
allow(type).to receive(:draw)
|
20
|
+
|
21
|
+
subject = Ledstrip::Strip.new(1, type)
|
22
|
+
subject.draw
|
23
|
+
|
24
|
+
expect(type).to have_received(:draw).with(subject.leds)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "ledstrip/type/lpd6803"
|
3
|
+
|
4
|
+
include Ledstrip::Type
|
5
|
+
|
6
|
+
describe LPD6803 do
|
7
|
+
|
8
|
+
describe "#draw" do
|
9
|
+
|
10
|
+
xit "draws a red led" do
|
11
|
+
subject = LPD6803.new
|
12
|
+
red_led = Led.new(r: 255, g: 0, b: 0)
|
13
|
+
subject.draw([red_led])
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ledstrip
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Roy van der Meij
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pi_piper
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.3.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.3.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: This gems led you control your ledstrips connected to a raspberry pi
|
70
|
+
with Ruby
|
71
|
+
email:
|
72
|
+
- roy@royapps.nl
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- ledstrip.gemspec
|
83
|
+
- lib/ledstrip.rb
|
84
|
+
- lib/ledstrip/led.rb
|
85
|
+
- lib/ledstrip/strip.rb
|
86
|
+
- lib/ledstrip/type/lpd6803.rb
|
87
|
+
- lib/ledstrip/version.rb
|
88
|
+
- spec/ledstrip/strip_spec.rb
|
89
|
+
- spec/ledstrip/type/lpd6803_spec.rb
|
90
|
+
- spec/spec_helper.rb
|
91
|
+
homepage: http://github.com/roy/ledstrip
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.2.2
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Control your ledstrips with ruby
|
115
|
+
test_files:
|
116
|
+
- spec/ledstrip/strip_spec.rb
|
117
|
+
- spec/ledstrip/type/lpd6803_spec.rb
|
118
|
+
- spec/spec_helper.rb
|