apa102_rbpi 1.0.1 → 1.1.pre

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: c45c70969c9ca54e9ea97767122830cd10e63608
4
- data.tar.gz: fcad57631c27c9b9bbbb0523bc39a5c847cd5175
3
+ metadata.gz: d61bbbb496c64346da43a00d15ab618651ea5e11
4
+ data.tar.gz: 0b49de24035db3478f263fad0e4b6c72c79d5207
5
5
  SHA512:
6
- metadata.gz: d333ca8227c94a6254571ebc8f3e94b3e268882d66fd8e8298494885f4179adc645f1565c752b56b37767a1f9a8e151227821144fe8932f7b306993450fb3145
7
- data.tar.gz: 8dffec1f2cfd910843233e8bebba50569c429aa307c5bd8f72cb60eeda98bffedd4298823d46e4d5f2d9897733084abc281a01e656813990f187accabeb6cca4
6
+ metadata.gz: 6728f8fc5c1dcca3ce6251ca443c4e98e9208b8b5af689a3a764b90164330da67d062a4689a194a734fa55bd90166dea1547c5cc180bab2c9ab39d82e5489539
7
+ data.tar.gz: ea8fa336f80abbd940a18b36365366fcc9974e1f637f09462a551d1331d50effada96ad5efa312aee5292d2b0c755c437d39a1b86f7a6a49e4a562683f1d9843
data/.gitignore CHANGED
@@ -5,3 +5,6 @@ pkg/
5
5
  .env
6
6
  *.gem
7
7
  .DS_Store
8
+
9
+ *.gem
10
+ Gemfile.lock
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.0
5
+ cache: bundler
6
+ before_install:
7
+ - gem install bundler -v 1.9
8
+ script:
9
+ - bundle exec rspec
10
+ notifications:
11
+ email: false
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.1
4
+ - Improve non-mirrored strip performance
5
+ - Add a benchmark script
6
+
3
7
  ## 1.0.1
4
8
  - Fix bug with `set` not being required
5
9
  - Add `set_all_pixels` functionality to strip
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Apa102Rbpi
1
+ # Apa102Rbpi [![Build Status](https://travis-ci.org/matl33t/apa102_rbpi.svg?branch=master)](https://travis-ci.org/matl33t/apa102_rbpi)
2
2
  Simple library to drive APA102/Dotstar LEDs using a Raspberry Pi
3
3
 
4
4
  ## Setup
data/apa102_rbpi.gemspec CHANGED
@@ -25,8 +25,10 @@ Gem::Specification.new do |spec|
25
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
26
  spec.require_paths = ['lib']
27
27
 
28
+ spec.add_development_dependency 'rspec', '~> 3.3.0'
28
29
  spec.add_development_dependency 'bundler', '~> 1.9'
29
30
  spec.add_development_dependency 'rake', '~> 10.0'
31
+ spec.add_development_dependency 'benchmark-perf', '~> 0.1.0'
30
32
  spec.add_dependency 'pi_piper', '~> 1.9'
31
33
  spec.add_dependency 'paint'
32
34
  end
@@ -35,7 +35,7 @@ module Apa102Rbpi
35
35
  def simulate=(bool)
36
36
  @simulate = bool
37
37
  if @simulate
38
- @interface = ::Apa102Rbpi::SpiSimulator #TODO
38
+ @interface = ::Apa102Rbpi::SpiSimulator
39
39
  else
40
40
  @interface = PiPiper::Spi
41
41
  end
@@ -3,10 +3,11 @@ module Apa102Rbpi
3
3
 
4
4
  require 'set'
5
5
 
6
- attr_reader :mirrors, :head, :tail, :num_leds
6
+ attr_reader :mirrors, :head, :tail, :num_leds, :base
7
7
  attr_accessor :led_frame_rgb_offsets, :brightness
8
8
 
9
- def initialize(len = base.num_leds, opts = {})
9
+ def initialize(len = Apa102Rbpi.base.num_leds, opts = {})
10
+ @base = Apa102Rbpi.base
10
11
  if len.is_a?(Array)
11
12
  @head = len[0]
12
13
  @tail = len[1]
@@ -22,8 +23,8 @@ module Apa102Rbpi
22
23
 
23
24
  @reverse = false
24
25
 
25
- @led_frame_rgb_offsets = opts[:led_frame_rgb_offsets] || base.led_frame_rgb_offsets
26
- @brightness = opts[:brightness] || base.brightness
26
+ @led_frame_rgb_offsets = opts[:led_frame_rgb_offsets] || @base.led_frame_rgb_offsets
27
+ @brightness = opts[:brightness] || @base.brightness
27
28
  @mirrors = Set.new
28
29
  end
29
30
 
@@ -45,40 +46,52 @@ module Apa102Rbpi
45
46
  end
46
47
 
47
48
  def show!
48
- base.show!
49
+ @base.show!
49
50
  end
50
51
 
51
- def set_pixel(pos, color, brightness = @brightness)
52
- q = [self]
53
- seen = Set.new([self])
54
- frames = base.led_frames
55
- while(substrip = q.pop)
56
- substrip.mirrors.each do |mirror|
57
- unless seen.include?(mirror)
58
- q.push(mirror)
59
- seen.add(mirror)
52
+ def set_pixel(pos, color, brightness = nil)
53
+ is_hex = if color.is_a?(Integer)
54
+ true
55
+ elsif color.is_a?(Array)
56
+ false
57
+ else
58
+ raise 'Invalid color'
59
+ end
60
+ if @mirrors.empty?
61
+ set_color_helper(pos, color, is_hex, brightness || @brightness)
62
+ else
63
+ q = [self]
64
+ seen = Set.new([self])
65
+ while(substrip = q.pop)
66
+ substrip.mirrors.each do |mirror|
67
+ unless seen.include?(mirror)
68
+ q.push(mirror)
69
+ seen.add(mirror)
70
+ end
71
+ substrip.set_color_helper(pos, color, is_hex, brightness || substrip.brightness)
60
72
  end
61
73
  end
74
+ end
75
+ end
62
76
 
63
- idx = if substrip.reversed?
64
- 4 * ((substrip.tail - pos) % base.num_leds)
65
- else
66
- 4 * ((pos + substrip.head) % base.num_leds)
67
- end
68
-
69
- if color.is_a?(Integer)
70
- frames[idx] = substrip.led_frame_hdr(brightness)
71
- frames[idx + substrip.led_frame_rgb_offsets[:red]] = (color & 0xFF0000) >> 16
72
- frames[idx + substrip.led_frame_rgb_offsets[:green]] = (color & 0x00FF00) >> 8
73
- frames[idx + substrip.led_frame_rgb_offsets[:blue]] = (color & 0x0000FF)
74
- elsif color.is_a?(Array)
75
- frames[idx] = substrip.led_frame_hdr(brightness)
76
- frames[idx + substrip.led_frame_rgb_offsets[:red]] = color[0]
77
- frames[idx + substrip.led_frame_rgb_offsets[:green]] = color[1]
78
- frames[idx + substrip.led_frame_rgb_offsets[:blue]] = color[2]
79
- else
80
- raise 'Invalid color'
81
- end
77
+ def set_color_helper(pos, color, is_hex, brightness)
78
+ led_frame_hdr = (brightness & 0b00011111) | 0b11100000
79
+ idx = if @reverse
80
+ 4 * ((@tail - pos) % @base.num_leds)
81
+ else
82
+ 4 * ((pos + @head) % @base.num_leds)
83
+ end
84
+
85
+ if is_hex
86
+ @base.led_frames[idx] = led_frame_hdr
87
+ @base.led_frames[idx + @led_frame_rgb_offsets[:red]] = (color & 0xFF0000) >> 16
88
+ @base.led_frames[idx + @led_frame_rgb_offsets[:green]] = (color & 0x00FF00) >> 8
89
+ @base.led_frames[idx + @led_frame_rgb_offsets[:blue]] = (color & 0x0000FF)
90
+ else
91
+ @base.led_frames[idx] = led_frame_hdr
92
+ @base.led_frames[idx + @led_frame_rgb_offsets[:red]] = color[0]
93
+ @base.led_frames[idx + @led_frame_rgb_offsets[:green]] = color[1]
94
+ @base.led_frames[idx + @led_frame_rgb_offsets[:blue]] = color[2]
82
95
  end
83
96
  end
84
97
 
@@ -108,15 +121,5 @@ module Apa102Rbpi
108
121
  clear
109
122
  show!
110
123
  end
111
-
112
- def led_frame_hdr(brightness = @brightness)
113
- (brightness & 0b00011111) | 0b11100000
114
- end
115
-
116
- private
117
-
118
- def base
119
- Apa102Rbpi.base
120
- end
121
124
  end
122
125
  end
@@ -1,3 +1,3 @@
1
1
  module Apa102Rbpi
2
- VERSION = '1.0.1'
2
+ VERSION = '1.1.pre'
3
3
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apa102_rbpi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - matl33t
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-10 00:00:00.000000000 Z
11
+ date: 2016-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 3.3.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 3.3.0
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +52,20 @@ dependencies:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
54
  version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: benchmark-perf
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.1.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.1.0
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: pi_piper
43
71
  requirement: !ruby/object:Gem::Requirement
@@ -75,6 +103,7 @@ extra_rdoc_files: []
75
103
  files:
76
104
  - ".gitignore"
77
105
  - ".rspec"
106
+ - ".travis.yml"
78
107
  - AUTHORS
79
108
  - CHANGELOG.md
80
109
  - Gemfile
@@ -106,9 +135,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
135
  version: '0'
107
136
  required_rubygems_version: !ruby/object:Gem::Requirement
108
137
  requirements:
109
- - - ">="
138
+ - - ">"
110
139
  - !ruby/object:Gem::Version
111
- version: '0'
140
+ version: 1.3.1
112
141
  requirements: []
113
142
  rubyforge_project:
114
143
  rubygems_version: 2.2.3