apa102_rbpi 0.1.0.alpha

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1ef695016b994bed42b8d1e6750cd8b598328694
4
+ data.tar.gz: f4c8698b02a13b9221a9fa0c3e8c4b057c3606c0
5
+ SHA512:
6
+ metadata.gz: 0285047463da4b007bce7947332e1d33b9feb04f554f13b15b343e618c1b3690ffc24b13e32de7f72b2f37e35645ba28be00c340d7944075c8e5eac23c1a8a8b
7
+ data.tar.gz: b702e223e8a816ecbcdd356ff9f5a6cfff8b1879dba59a7afb9aa8f0f0eaca78780f2d538eba617334bdff0934d9e1860468ff576e5090189f8876a51b9dcadc
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ .bundle/
2
+ *.log
3
+ pkg/
4
+ *~
5
+ .env
6
+ *.gem
7
+ .DS_Store
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0
4
+
5
+ Initial Release.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 matl33t
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # Apa102Rbpi
2
+
3
+ Simple library to drive APA102/Dotstar LEDs using a Raspberry Pi
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'apa102_rbpi'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install apa102_rbpi
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it ( https://github.com/matl33t/apa102_rbpi/fork )
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'apa102_rbpi/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'apa102_rbpi'
8
+ spec.version = Apa102Rbpi::VERSION
9
+ spec.authors = ['matl33t']
10
+ spec.email = ['leung.mattp@gmail.com']
11
+
12
+ spec.summary = 'Simple library to drive APA102/Dotstar LEDs using a Raspberry Pi.'
13
+ spec.license = 'MIT'
14
+
15
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
16
+ # delete this section to allow pushing this gem to any host.
17
+ if spec.respond_to?(:metadata)
18
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
19
+ else
20
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
21
+ end
22
+
23
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ spec.bindir = 'exe'
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ['lib']
27
+
28
+ spec.add_development_dependency 'bundler', '~> 1.9'
29
+ spec.add_development_dependency 'rake', '~> 10.0'
30
+ spec.add_development_dependency 'pi_piper', '~> 1.9'
31
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "apa102_rbpi"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,67 @@
1
+ require 'pi_piper'
2
+
3
+ module Apa102Rbpi
4
+ include PiPiper
5
+
6
+ class Apa102
7
+ START_FRAME = [0x00] * 4
8
+
9
+ attr_accessor :brightness
10
+
11
+ def initialize(opts)
12
+ @num_leds = opts[:num_leds] || 1
13
+ @brightness = opts[:brightness] || 31
14
+ @spi_hz = opts[:spi_hz] || 8000000
15
+
16
+ # some strips may have different led frame specs
17
+ # set offsets if using a non-default strip
18
+ # offset: 0 1 2 3
19
+ # frame = [header|blue|green|red],
20
+ @led_frame_blue_offset = opts[:led_frame_blue_offset] || 1
21
+ @led_frame_green_offset = opts[:led_frame_green_offset] || 2
22
+ @led_frame_red_offset = opts[:led_frame_red_offset] || 3
23
+
24
+ @led_frames = []
25
+ @end_frame = [0x00] * (@num_leds / 2.0).ceil
26
+
27
+ (0..@num_leds).each do |l|
28
+ self.set_pixel_color(l, 0x00)
29
+ end
30
+ self.show!
31
+ end
32
+
33
+ # Sets color of a single pixel at specified position in the strip
34
+ # accepts an array of [r,g,b] values or a single 3 byte value
35
+ def set_pixel_color(pos, color)
36
+ idx = pos * 4
37
+ if color.is_a?(Integer)
38
+ @led_frames[idx] = led_frame_hdr
39
+ @led_frames[idx + @led_frame_red_offset] = (color & 0xFF0000)
40
+ @led_frames[idx + @led_frame_green_offset] = (color & 0x00FF00) >> 8
41
+ @led_frames[idx + @led_frame_blue_offset] = (color & 0x0000FF) >> 16
42
+ elsif color.is_a?(Array)
43
+ @led_frames[idx] = led_frame_hdr
44
+ @led_frames[idx + @led_frame_red_offset] = color[0]
45
+ @led_frames[idx + @led_frame_green_offset] = color[1]
46
+ @led_frames[idx + @led_frame_blue_offset] = color[2]
47
+ else
48
+ raise 'Invalid color'
49
+ end
50
+ end
51
+
52
+ # Writes out the led frames to the strip
53
+ def show!
54
+ Spi.begin do |s|
55
+ s.clock(@spi_hz)
56
+ s.write(START_FRAME + @led_frames + @end_frame)
57
+ end
58
+ end
59
+
60
+ private
61
+
62
+ # First 3 bits high, then 5 bits for brightness
63
+ def led_frame_hdr
64
+ (@brightness & 0b00011111) | 0b11100000
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,3 @@
1
+ module Apa102Rbpi
2
+ VERSION = '0.1.0.alpha'
3
+ end
@@ -0,0 +1,5 @@
1
+ require 'apa102_rbpi/apa102'
2
+ require 'apa102_rbpi/version'
3
+
4
+ module Apa102Rbpi
5
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: apa102_rbpi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.alpha
5
+ platform: ruby
6
+ authors:
7
+ - matl33t
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-02-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pi_piper
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.9'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.9'
55
+ description:
56
+ email:
57
+ - leung.mattp@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - CHANGELOG.md
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - apa102_rbpi.gemspec
69
+ - bin/console
70
+ - bin/setup
71
+ - lib/apa102_rbpi.rb
72
+ - lib/apa102_rbpi/apa102.rb
73
+ - lib/apa102_rbpi/version.rb
74
+ homepage:
75
+ licenses:
76
+ - MIT
77
+ metadata:
78
+ allowed_push_host: https://rubygems.org
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">"
91
+ - !ruby/object:Gem::Version
92
+ version: 1.3.1
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.2.3
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Simple library to drive APA102/Dotstar LEDs using a Raspberry Pi.
99
+ test_files: []
100
+ has_rdoc: