humble_rpi-plugin-led 0.2.4 → 0.3.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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +3 -1
- data.tar.gz.sig +0 -0
- data/lib/humble_rpi-plugin-led.rb +87 -14
- metadata +7 -7
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f0db3a3d669a825cda9e65e2dce717fa81f5f28
|
4
|
+
data.tar.gz: 144a7ca9b84650124bf5e7c1657933cc4360b928
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c09a5861e1307e2a858d23382c3b8e79fe52bcd53797f0533004de958bf326e81d79fa43ea5e98be9ef388baba02d8a4389b6dcbeda22bb38297f3a9f4a331b
|
7
|
+
data.tar.gz: aeb3e751796ce623c0fe81e0e20fd146ccc7efecd20511ce8ef1fe110870c7c53e75ec36aa02d76d385d4c9144a3381bc04c08ee6d0fd60390ef6930cb5a67ad
|
checksums.yaml.gz.sig
CHANGED
@@ -1 +1,3 @@
|
|
1
|
-
|
1
|
+
<�����������n0z���u�����9TF�Z>��i��Z��!ӵ*!��5j~I%�<��9�2>�
|
2
|
+
�t����8�ezb>YewD��z�G(vE;�Uu�kя�{�;Rd�W�?u.�� �R+� �M�n����I�����>~E������8��^�T�]�Z��83��:�2N�TC3���e�o�1�.Q��6
|
3
|
+
O2f�� �������&�L�����&�Y�|���ũo?�h)���=
|
data.tar.gz.sig
CHANGED
Binary file
|
@@ -2,15 +2,17 @@
|
|
2
2
|
|
3
3
|
# file: humble_rpi-plugin-led.rb
|
4
4
|
|
5
|
-
require '
|
5
|
+
require 'rpi_rgb'
|
6
6
|
|
7
7
|
|
8
8
|
|
9
9
|
class HumbleRPiPluginLed
|
10
|
+
|
10
11
|
|
11
12
|
def initialize(settings: {}, variables: {})
|
12
13
|
|
13
|
-
x = settings[:pins]
|
14
|
+
x = settings[:pins] || []
|
15
|
+
rgb = settings[:rgb]
|
14
16
|
|
15
17
|
pins = case x
|
16
18
|
when Fixnum
|
@@ -25,16 +27,54 @@ class HumbleRPiPluginLed
|
|
25
27
|
|
26
28
|
@lookup = {}
|
27
29
|
@gpio_pins = []
|
30
|
+
@led = []
|
28
31
|
|
29
32
|
# each pin can contain an identifier e.g. pins = [{'4': 'record'}, 17]
|
30
33
|
# an LED can be identified by the identifier instead of the numberic index
|
31
34
|
|
35
|
+
initialize_leds(pins) {|pin| RPiLed.new pin} if pins.any?
|
36
|
+
|
37
|
+
if rgb then
|
38
|
+
|
39
|
+
|
40
|
+
colours = %i(red green blue)
|
41
|
+
|
42
|
+
named_pins = rgb[:pins].zip(colours).map do |pin, colour|
|
43
|
+
{pin.to_s.to_sym => colour.to_s}
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
presets = {
|
48
|
+
purple: '#800080',
|
49
|
+
yellow: '#FFFF00',
|
50
|
+
orange: '#FFA500',
|
51
|
+
turquoise: '#40E0D0',
|
52
|
+
steelblue: '#4682B4'
|
53
|
+
}
|
54
|
+
|
55
|
+
rgb_led = RPiRGB.new(rgb[:pins], presets: presets)
|
56
|
+
index = @led.length
|
57
|
+
@lookup[:red] = @lookup[index.to_s.to_sym] = index
|
58
|
+
@lookup[:green] = @lookup[(index+1).to_s.to_sym]= index
|
59
|
+
@lookup[:blue] = @lookup[(index+2).to_s.to_sym]= index
|
60
|
+
|
61
|
+
presets.each {|preset| @lookup[preset] = index}
|
62
|
+
|
63
|
+
|
64
|
+
@led << rgb_led
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
def initialize_leds(pins)
|
71
|
+
|
32
72
|
pins.each.with_index do |x, i|
|
33
73
|
|
34
|
-
if x.is_a? String or x.is_a? Integer then
|
74
|
+
pin = if x.is_a? String or x.is_a? Integer then
|
35
75
|
|
36
|
-
@lookup.merge!(
|
37
|
-
|
76
|
+
@lookup.merge!(i.to_s.to_sym => i )
|
77
|
+
x
|
38
78
|
|
39
79
|
elsif x.is_a? Hash
|
40
80
|
|
@@ -43,11 +83,14 @@ class HumbleRPiPluginLed
|
|
43
83
|
led_name = x[n.to_sym]
|
44
84
|
@lookup.merge!(i.to_s.to_sym => i )
|
45
85
|
@lookup.merge!(led_name.to_sym => i )
|
46
|
-
|
86
|
+
n
|
87
|
+
|
47
88
|
end
|
89
|
+
|
90
|
+
@gpio_pins << pin.to_i
|
91
|
+
@led << yield(pin.to_i) if block_given?
|
48
92
|
|
49
93
|
end
|
50
|
-
|
51
94
|
end
|
52
95
|
|
53
96
|
def on_led_message(message)
|
@@ -55,8 +98,11 @@ class HumbleRPiPluginLed
|
|
55
98
|
r = message.match(/(\w+)\s*(on|off|blink)\s*([\d\.]+)?(?:\s*duration\s)?([\d\.]+)?/)
|
56
99
|
|
57
100
|
if r then
|
58
|
-
|
101
|
+
|
102
|
+
identifier, state, seconds, raw_duration = r.captures
|
59
103
|
duration = raw_duration ? raw_duration.to_f : nil
|
104
|
+
|
105
|
+
seconds = seconds ? seconds.to_f : 0.5
|
60
106
|
|
61
107
|
a = case state
|
62
108
|
|
@@ -67,19 +113,46 @@ class HumbleRPiPluginLed
|
|
67
113
|
[:off]
|
68
114
|
|
69
115
|
when 'blink'
|
70
|
-
|
116
|
+
|
71
117
|
[:blink, seconds, duration: duration]
|
72
118
|
end
|
73
119
|
|
74
|
-
|
120
|
+
|
121
|
+
led = @led[@lookup[identifier.to_sym].to_i]
|
122
|
+
|
123
|
+
if led.is_a? RPiLed then
|
124
|
+
|
125
|
+
led.send(*a)
|
126
|
+
|
127
|
+
elsif led.is_a? RPiRGB
|
128
|
+
|
129
|
+
if state == 'on' then
|
130
|
+
|
131
|
+
a = ((@led.length-1)..@led.length+1).map{|x| x.to_s.to_sym}
|
132
|
+
h = a.zip(%w(red green blue)).to_h
|
133
|
+
#puts 'h: ' + h.inspect
|
134
|
+
colour = h[identifier.to_sym]
|
135
|
+
|
136
|
+
|
137
|
+
led.colour = colour || identifier
|
138
|
+
led.on duration
|
139
|
+
|
140
|
+
elsif state == 'off'
|
141
|
+
|
142
|
+
led.off
|
143
|
+
|
144
|
+
elsif state == 'blink'
|
145
|
+
|
146
|
+
led.blink seconds, duration: duration
|
147
|
+
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
75
151
|
end
|
76
152
|
end
|
77
153
|
|
78
154
|
def start()
|
79
|
-
|
80
|
-
if @gpio_pins.any? then
|
81
|
-
@led = @gpio_pins.map{|x| RPiLed.new x}
|
82
|
-
end
|
155
|
+
|
83
156
|
|
84
157
|
end
|
85
158
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: humble_rpi-plugin-led
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -31,28 +31,28 @@ cert_chain:
|
|
31
31
|
kuXWaEX0BC/yqishnYeDqOuqzvI1C4/7lvY+i4RJn3y13EP8RbXUlRa2A+PcKx0e
|
32
32
|
pi5a3T8Qg0ZT5A==
|
33
33
|
-----END CERTIFICATE-----
|
34
|
-
date: 2017-07-
|
34
|
+
date: 2017-07-28 00:00:00.000000000 Z
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
|
-
name:
|
37
|
+
name: rpi_rgb
|
38
38
|
requirement: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
40
|
- - "~>"
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: '0.
|
42
|
+
version: '0.2'
|
43
43
|
- - ">="
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 0.
|
45
|
+
version: 0.2.0
|
46
46
|
type: :runtime
|
47
47
|
prerelease: false
|
48
48
|
version_requirements: !ruby/object:Gem::Requirement
|
49
49
|
requirements:
|
50
50
|
- - "~>"
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version: '0.
|
52
|
+
version: '0.2'
|
53
53
|
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: 0.
|
55
|
+
version: 0.2.0
|
56
56
|
description:
|
57
57
|
email: james@jamesrobertson.eu
|
58
58
|
executables: []
|
metadata.gz.sig
CHANGED
Binary file
|