apa102_rbpi 1.1.pre → 1.1

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: d61bbbb496c64346da43a00d15ab618651ea5e11
4
- data.tar.gz: 0b49de24035db3478f263fad0e4b6c72c79d5207
3
+ metadata.gz: 84c6e4842fcb0b1d796bd492e6661754fab72cfd
4
+ data.tar.gz: 9db2f05ceef04b434cb0204b6d8b806868fd24bc
5
5
  SHA512:
6
- metadata.gz: 6728f8fc5c1dcca3ce6251ca443c4e98e9208b8b5af689a3a764b90164330da67d062a4689a194a734fa55bd90166dea1547c5cc180bab2c9ab39d82e5489539
7
- data.tar.gz: ea8fa336f80abbd940a18b36365366fcc9974e1f637f09462a551d1331d50effada96ad5efa312aee5292d2b0c755c437d39a1b86f7a6a49e4a562683f1d9843
6
+ metadata.gz: d2140ca25427e8c847d551eb3b66025b07d44c98d2f45ed6b03e74699b38073292ee2ec19b9c50805dc36a4ea419b3e0be4ec4577b52b68e137df747ab29ff92
7
+ data.tar.gz: d736a1bfba1f89f943c670b9e9e9d897c901c6d7c422c0c4356ce0a2711ff0ed891b4c01e044b127e002310375780a1a7ca217db58678dd402f77aa68ef14107
data/CHANGELOG.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # Changelog
2
2
 
3
3
  ## 1.1
4
- - Improve non-mirrored strip performance
4
+ - Improve set_pixel performance
5
5
  - Add a benchmark script
6
+ - `strip.mirrors` no longer writable
7
+ - Added `strip.clear_mirrors` method used to unmirror a strip.
6
8
 
7
9
  ## 1.0.1
8
10
  - Fix bug with `set` not being required
@@ -18,7 +18,7 @@ module Apa102Rbpi
18
18
  red: 3,
19
19
  green: 2,
20
20
  blue: 1
21
- }
21
+ }
22
22
  @spi_hz = 8000000
23
23
  @simulate = false
24
24
 
@@ -26,10 +26,7 @@ module Apa102Rbpi
26
26
  @start_frame = [0x00] * 4
27
27
  @end_frame = calculate_end_frame
28
28
 
29
-
30
29
  @led_frames = []
31
- @substrips = {}
32
- @mirrors = {}
33
30
  end
34
31
 
35
32
  def simulate=(bool)
@@ -46,12 +43,8 @@ module Apa102Rbpi
46
43
  @end_frame = calculate_end_frame
47
44
  end
48
45
 
49
- def calculate_end_frame
50
- [0x00] * (@num_leds / 2.0).ceil
51
- end
52
-
53
46
  def show!
54
- interface.begin do |s|
47
+ @interface.begin do |s|
55
48
  s.clock(@spi_hz)
56
49
  s.write(@start_frame + @led_frames + @end_frame)
57
50
  end
@@ -60,6 +53,12 @@ module Apa102Rbpi
60
53
  def print
61
54
  ::Apa102Rbpi::SpiSimulator.display(@led_frames)
62
55
  end
56
+
57
+ private
58
+
59
+ def calculate_end_frame
60
+ [0x00] * (@num_leds / 2.0).ceil
61
+ end
63
62
  end
64
63
  end
65
64
 
@@ -1,9 +1,6 @@
1
1
  module Apa102Rbpi
2
2
  class Strip
3
-
4
- require 'set'
5
-
6
- attr_reader :mirrors, :head, :tail, :num_leds, :base
3
+ attr_reader :head, :tail, :num_leds, :base, :mirrors
7
4
  attr_accessor :led_frame_rgb_offsets, :brightness
8
5
 
9
6
  def initialize(len = Apa102Rbpi.base.num_leds, opts = {})
@@ -36,15 +33,21 @@ module Apa102Rbpi
36
33
  @reverse
37
34
  end
38
35
 
39
- def mirror(strip)
40
- if strip.num_leds == @num_leds
41
- @mirrors.add(strip)
42
- strip.mirrors.add(self)
43
- else
44
- raise 'Strips must be of same length to be mirrored!'
36
+ def mirror(other_strip)
37
+ new_mirrors = @mirrors + other_strip.mirrors + Set.new([self, other_strip])
38
+ new_mirrors.each do |m|
39
+ m.mirrors += (new_mirrors - [m])
45
40
  end
46
41
  end
47
42
 
43
+ def clear_mirrors
44
+ @mirrors.each do |m|
45
+ m.mirrors -= [self]
46
+ end
47
+
48
+ @mirrors.clear
49
+ end
50
+
48
51
  def show!
49
52
  @base.show!
50
53
  end
@@ -57,24 +60,16 @@ module Apa102Rbpi
57
60
  else
58
61
  raise 'Invalid color'
59
62
  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)
72
- end
63
+
64
+ set_pixel_helper(pos, color, is_hex, brightness || @brightness)
65
+ unless @mirrors.empty?
66
+ @mirrors.each do |strip|
67
+ strip.set_pixel_helper(pos, color, is_hex, brightness || strip.brightness)
73
68
  end
74
69
  end
75
70
  end
76
71
 
77
- def set_color_helper(pos, color, is_hex, brightness)
72
+ def set_pixel_helper(pos, color, is_hex, brightness)
78
73
  led_frame_hdr = (brightness & 0b00011111) | 0b11100000
79
74
  idx = if @reverse
80
75
  4 * ((@tail - pos) % @base.num_leds)
@@ -121,5 +116,11 @@ module Apa102Rbpi
121
116
  clear
122
117
  show!
123
118
  end
119
+
120
+ protected
121
+
122
+ def mirrors=(m)
123
+ @mirrors = m
124
+ end
124
125
  end
125
126
  end
@@ -1,3 +1,3 @@
1
1
  module Apa102Rbpi
2
- VERSION = '1.1.pre'
2
+ VERSION = '1.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apa102_rbpi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.pre
4
+ version: '1.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - matl33t
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-07-24 00:00:00.000000000 Z
11
+ date: 2016-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -135,9 +135,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
135
135
  version: '0'
136
136
  required_rubygems_version: !ruby/object:Gem::Requirement
137
137
  requirements:
138
- - - ">"
138
+ - - ">="
139
139
  - !ruby/object:Gem::Version
140
- version: 1.3.1
140
+ version: '0'
141
141
  requirements: []
142
142
  rubyforge_project:
143
143
  rubygems_version: 2.2.3