ws2801 1.0.2 → 1.1.0
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.
- data/lib/ws2801.rb +12 -14
- data/lib/ws2801/effects.rb +116 -0
- metadata +2 -1
data/lib/ws2801.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
#
|
3
2
|
# Controller for: RGB Pixel with WS2801 Chip
|
4
3
|
# build for Diffused Digital RGB LED Pixels from Adafruits on Raspberry Pi
|
@@ -102,15 +101,15 @@ module WS2801
|
|
102
101
|
# :g => (Integer)
|
103
102
|
# :b => (Integer)
|
104
103
|
def self.set options = {}
|
105
|
-
|
106
|
-
options[:pixel] = (0..(
|
104
|
+
WS2801.generate if @@options[:strip].length == 0
|
105
|
+
options[:pixel] = (0..(WS2801.length-1)).to_a if options[:pixel].nil? or options[:pixel] == :all
|
107
106
|
options[:pixel] = [options[:pixel]] if options[:pixel].is_a? Numeric
|
108
107
|
options[:pixel].each do |i|
|
109
|
-
@@options[:strip][(i*3)]
|
108
|
+
@@options[:strip][(i*3)] = options[:r] || 0
|
110
109
|
@@options[:strip][(i*3)+1] = options[:g] || 0
|
111
110
|
@@options[:strip][(i*3)+2] = options[:b] || 0
|
112
111
|
end
|
113
|
-
|
112
|
+
WS2801.write if @@options[:autowrite]
|
114
113
|
end
|
115
114
|
|
116
115
|
# Fade pixel to color
|
@@ -127,14 +126,13 @@ module WS2801
|
|
127
126
|
# :g => (Integer)
|
128
127
|
# :b => (Integer)
|
129
128
|
def self.fade options = {}
|
130
|
-
|
131
|
-
options[:pixel] = (0..(
|
129
|
+
WS2801.generate if @@options[:strip].length == 0
|
130
|
+
options[:pixel] = (0..(WS2801.length-1)).to_a if options[:pixel].nil? or options[:pixel] == :all
|
132
131
|
options[:pixel] = [options[:pixel]] if options[:pixel].is_a? Numeric
|
133
132
|
options[:r] = 0 if options[:r].nil?
|
134
133
|
options[:g] = 0 if options[:g].nil?
|
135
134
|
options[:b] = 0 if options[:b].nil?
|
136
135
|
|
137
|
-
breakme = 0
|
138
136
|
while true
|
139
137
|
options[:pixel].each do |i|
|
140
138
|
#next if @@options[:strip][(i*3+2)] == options[:b] and @@options[:strip][(i*3+1)] == options[:g] and @@options[:strip][(i*3)] == options[:r]
|
@@ -153,12 +151,12 @@ module WS2801
|
|
153
151
|
elsif @@options[:strip][(i*3+2)] < options[:b]
|
154
152
|
@@options[:strip][(i*3+2)] -= 1
|
155
153
|
end
|
156
|
-
|
154
|
+
end
|
155
|
+
(breakme = true; break) if @@options[:strip][(i*3+2)] == options[:b] and @@options[:strip][(i*3+1)] == options[:g] and
|
157
156
|
@@options[:strip][(i*3)] ==
|
158
157
|
options[:r]
|
159
|
-
|
160
|
-
|
161
|
-
break if breakme >= @@options[:len]
|
158
|
+
WS2801.write if @@options[:autowrite]
|
159
|
+
break if breakme
|
162
160
|
|
163
161
|
sleep(options[:timeout] || 0.01)
|
164
162
|
end
|
@@ -181,7 +179,7 @@ options[:r]
|
|
181
179
|
# Example:
|
182
180
|
# >> WS2801.off
|
183
181
|
def self.off
|
184
|
-
|
185
|
-
|
182
|
+
WS2801.generate
|
183
|
+
WS2801.write if @@options[:autowrite]
|
186
184
|
end
|
187
185
|
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
#
|
2
|
+
# Controller for: RGB Pixel with WS2801 Chip (Effects)
|
3
|
+
# build for Diffused Digital RGB LED Pixels from Adafruits on Raspberry Pi
|
4
|
+
# but should work on any device and the same led chip
|
5
|
+
# (c) 2013 Roman Pramberger (roman@pramberger.ch)
|
6
|
+
#
|
7
|
+
# WS2801 user-space driver (effects)
|
8
|
+
#
|
9
|
+
#
|
10
|
+
module WS2801::Effects
|
11
|
+
#
|
12
|
+
# Stroboscope effect
|
13
|
+
#
|
14
|
+
# Example:
|
15
|
+
# >> WS2801E.stroboscope({ :timeout => 0.25, :times => 22, :r => 255 })
|
16
|
+
# >> WS2801E.stroboscope({ :b => 255, :g => 255 })
|
17
|
+
#
|
18
|
+
# Arguments (or nil):
|
19
|
+
# pixel: (Number-Array|Integer|:all)
|
20
|
+
# r: (Integer) 0-255 red
|
21
|
+
# g: (Integer) 0-255 green
|
22
|
+
# b: (Integer) 0-255 blue
|
23
|
+
# timeout: (Float)
|
24
|
+
# times: (Integer)
|
25
|
+
#
|
26
|
+
def self.stroboscope options = {}
|
27
|
+
options[:pixel] = (0..(WS2801.length-1)).to_a if options[:pixel].nil? or options[:pixel] == :all
|
28
|
+
options[:pixel] = [options[:pixel]] if options[:pixel].is_a? Numeric
|
29
|
+
options[:r] = 0 if options[:r].nil?
|
30
|
+
options[:g] = 0 if options[:g].nil?
|
31
|
+
options[:b] = 0 if options[:b].nil?
|
32
|
+
options[:times] = options[:times].to_i if !options[:times].is_a? Numeric
|
33
|
+
options[:times] = 40 if options[:times] == 0
|
34
|
+
options[:timeout] = options[:timeout].to_f
|
35
|
+
options[:timeout] = 0.03 if options[:timeout] == 0.0
|
36
|
+
|
37
|
+
breakme = 0
|
38
|
+
options[:times].times do |c|
|
39
|
+
if c % 2 == 0
|
40
|
+
r = 0
|
41
|
+
g = 0
|
42
|
+
b = 0
|
43
|
+
else
|
44
|
+
r = options[:r]
|
45
|
+
g = options[:g]
|
46
|
+
b = options[:b]
|
47
|
+
end
|
48
|
+
WS2801.set({
|
49
|
+
:pixel => options[:pixel],
|
50
|
+
:r => r,
|
51
|
+
:g => g,
|
52
|
+
:b => b
|
53
|
+
})
|
54
|
+
sleep( options[:timeout] )
|
55
|
+
end
|
56
|
+
end
|
57
|
+
#
|
58
|
+
# Pulse Effect
|
59
|
+
#
|
60
|
+
# Example:
|
61
|
+
# >> WS2801E.pulse({ :direction => :outer, :r => 255 })
|
62
|
+
# >> WS2801E.pulse({ :b => 255, :g => 255 })
|
63
|
+
#
|
64
|
+
# Arguments (or nil):
|
65
|
+
# pixel: (Number-Array|Integer|:all) [default: :all]
|
66
|
+
# r: (Integer) 0-255 red [default: 0]
|
67
|
+
# g: (Integer) 0-255 green [default: 0]
|
68
|
+
# b: (Integer) 0-255 blue [default: 0]
|
69
|
+
# direction: (Symbol) :start | :end | :inner | :outer [default: :start]
|
70
|
+
# timeout: (Float) [default: 0.1]
|
71
|
+
# keep: (Boolean) if pixels get blacked out [default: true]
|
72
|
+
#
|
73
|
+
def self.pulse options = {}
|
74
|
+
options[:pixel] = (0..(WS2801.length-1)).to_a if options[:pixel].nil? or options[:pixel] == :all
|
75
|
+
options[:pixel] = [options[:pixel]] if options[:pixel].is_a? Numeric
|
76
|
+
options[:r] = 0 if options[:r].nil?
|
77
|
+
options[:g] = 0 if options[:g].nil?
|
78
|
+
options[:b] = 0 if options[:b].nil?
|
79
|
+
options[:direction] = :start if options[:direction].nil?
|
80
|
+
options[:timeout] = 0.1 if options[:timeout].to_f == 0.0
|
81
|
+
options[:keep] = true if options[:keep].nil?
|
82
|
+
|
83
|
+
WS2801.generate if !options[:keep]
|
84
|
+
if options[:direction] == :start
|
85
|
+
WS2801.length.times do |i|
|
86
|
+
WS2801.generate if !options[:keep]
|
87
|
+
WS2801.set({ :r => options[:r], :g => options[:g], :b => options[:b], :pixel => i })
|
88
|
+
sleep(options[:timeout])
|
89
|
+
end
|
90
|
+
elsif options[:direction] == :end
|
91
|
+
WS2801.length.times do |i|
|
92
|
+
WS2801.generate if !options[:keep]
|
93
|
+
WS2801.set({ :r => options[:r], :g => options[:g], :b => options[:b], :pixel => WS2801.length-i })
|
94
|
+
sleep(options[:timeout])
|
95
|
+
end
|
96
|
+
elsif options[:direction] == :inner
|
97
|
+
first = WS2801.length/2.0
|
98
|
+
if first % 1 != 0
|
99
|
+
first = first.to_i + 1
|
100
|
+
end
|
101
|
+
WS2801.generate if !options[:keep]
|
102
|
+
((WS2801.length/2)+1).times do |i|
|
103
|
+
WS2801.generate if !options[:keep]
|
104
|
+
WS2801.set({ :pixel => [first-i, first+i], :r => options[:r], :g => options[:g], :b => options[:b] })
|
105
|
+
sleep(options[:timeout])
|
106
|
+
end
|
107
|
+
elsif options[:direction] == :outer
|
108
|
+
WS2801.generate if !options[:keep]
|
109
|
+
((WS2801.length/2)+1).times do |i|
|
110
|
+
WS2801.generate if !options[:keep]
|
111
|
+
WS2801.set({ :pixel => [0+i, WS2801.length-i], :r => options[:r], :g => options[:g], :b => options[:b] })
|
112
|
+
sleep(options[:timeout])
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ws2801
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -19,6 +19,7 @@ extensions: []
|
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
21
|
- lib/ws2801.rb
|
22
|
+
- lib/ws2801/effects.rb
|
22
23
|
homepage: https://github.com/b1nary/ws2801
|
23
24
|
licenses: []
|
24
25
|
post_install_message:
|