Class: Denko::LED::APA102
Instance Attribute Summary collapse
#spi_bit_order, #spi_frequency, #spi_mode
#address
#board
#callback_mutex
#mode, #pin
Instance Method Summary
collapse
#spi_listen, #spi_read, #spi_stop, #spi_transfer, #spi_write
#atomically
#initialize, #micro_delay
#initialize, #state
#add_callback, #callbacks, #initialize, #pre_callback_filter, #remove_callback, #update
Instance Attribute Details
#bpp ⇒ Object
Returns the value of attribute bpp.
6
7
8
|
# File 'lib/denko/led/apa102.rb', line 6
def bpp
@bpp
end
|
#brightness ⇒ Object
Returns the value of attribute brightness.
6
7
8
|
# File 'lib/denko/led/apa102.rb', line 6
def brightness
@brightness
end
|
#length ⇒ Object
Returns the value of attribute length.
6
7
8
|
# File 'lib/denko/led/apa102.rb', line 6
def length
@length
end
|
Instance Method Details
#[]=(index, array) ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/denko/led/apa102.rb', line 55
def []=(index, array)
if array[3]
@buffer[index*bpp+0] = 0b11100000 | array[3]
end
@buffer[index*bpp+1] = array[2]
@buffer[index*bpp+2] = array[1]
@buffer[index*bpp+3] = array[0]
end
|
#after_initialize(options = {}) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/denko/led/apa102.rb', line 13
def after_initialize(options={})
super(options)
raise ArgumentError, "no length given for APA102 array" unless options[:length]
@length = options[:length]
@start_frame = Array.new(4) { 0 }
end_frame_bytes = (@length / 16.0).ceil
end_frame_bytes = 4 if end_frame_bytes < 4
@end_frame = Array.new(end_frame_bytes) { 0 }
@bpp = 4
@buffer = Array.new(length * bpp) { 0 }
self.brightness = 31
off
end
|
#all_on ⇒ Object
67
68
69
70
71
|
# File 'lib/denko/led/apa102.rb', line 67
def all_on
self.brightness = 31
@buffer = @buffer.each_slice(bpp).map { [@masked_brightness,255,255,255] }.flatten
show
end
|
#before_initialize(options = {}) ⇒ Object
8
9
10
11
|
# File 'lib/denko/led/apa102.rb', line 8
def before_initialize(options={})
options[:pin] = 255
super(options)
end
|
#clear ⇒ Object
78
79
80
|
# File 'lib/denko/led/apa102.rb', line 78
def clear
@buffer = @buffer.each_slice(bpp).map { [@masked_brightness,0,0,0] }.flatten
end
|
#off ⇒ Object
73
74
75
76
|
# File 'lib/denko/led/apa102.rb', line 73
def off
clear
show
end
|
#show ⇒ Object
82
83
84
|
# File 'lib/denko/led/apa102.rb', line 82
def show
spi_write(@start_frame + @buffer + @end_frame)
end
|