rpi_led_simulator 0.1.0 → 0.1.1
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 +0 -0
- data/lib/rpi_led_simulator.rb +25 -18
- data.tar.gz.sig +0 -0
- metadata +1 -1
- 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: dec19e62c83fbcbf8550b6e6de4b43cd581634a1
|
4
|
+
data.tar.gz: a5aeb34e64e16acee4cb6eabbf68ca9267c6b9f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80f7b73bc6081ea69cfcb25402bc0c8342f0e695b71313eb65319a651c08520746195cbde7a2b98bab858dcc036a07c311a0acc6307bdcbe99d92e628cb7b4b1
|
7
|
+
data.tar.gz: 5739813cc42165180768bffa327bf0bd3b690882e1a4693e8777b41c5bffdbdd6a0a696963b45324db7cd35aea5c5b9f2d34edc825d484c55a53c9f9b65ce388
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/rpi_led_simulator.rb
CHANGED
@@ -10,32 +10,36 @@ class RPiLedSimulator
|
|
10
10
|
|
11
11
|
class PinX
|
12
12
|
|
13
|
-
HIGH = 1
|
14
|
-
LOW = 0
|
15
13
|
|
16
14
|
def initialize(id, color: :red, parent: nil)
|
17
15
|
@id = id
|
18
16
|
@on, @blinking = false, false
|
19
17
|
@color = color
|
20
18
|
@parent = parent
|
19
|
+
|
21
20
|
end
|
22
21
|
|
23
22
|
def color()
|
24
23
|
@on ? @color : :black
|
25
24
|
end
|
26
25
|
|
27
|
-
def on(
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
def on(durationx=nil, duration: nil)
|
27
|
+
|
28
|
+
@on = true
|
29
|
+
duration ||= durationx
|
30
|
+
|
31
|
+
@off_thread.exit if @off_thread
|
32
|
+
@on_thread = Thread.new {(sleep duration; off()) } if duration
|
31
33
|
|
32
34
|
end
|
33
35
|
|
34
|
-
def off(
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
def off(durationx=nil, duration: nil)
|
37
|
+
|
38
|
+
@on, @blinking = false, false
|
39
|
+
duration ||= durationx
|
40
|
+
|
41
|
+
@on_thread.exit if @on_thread
|
42
|
+
@off_thread = Thread.new { (sleep duration; on()) } if duration
|
39
43
|
|
40
44
|
end
|
41
45
|
|
@@ -71,9 +75,9 @@ class RPiLedSimulator
|
|
71
75
|
alias stop off
|
72
76
|
end
|
73
77
|
|
74
|
-
def initialize(x=[], color: :red, symbol: '▋')
|
78
|
+
def initialize(x=[], color: :red, symbol: '▋', spacer: 0, colors: [])
|
75
79
|
|
76
|
-
@color, @symbol = color, symbol
|
80
|
+
@color, @symbol, @spacer, @colors = color, symbol, spacer, colors
|
77
81
|
|
78
82
|
a = case x
|
79
83
|
when Fixnum
|
@@ -84,8 +88,11 @@ class RPiLedSimulator
|
|
84
88
|
x
|
85
89
|
end
|
86
90
|
|
87
|
-
|
88
|
-
|
91
|
+
@pins = a.map.with_index do |pin, i|
|
92
|
+
|
93
|
+
PinX.new pin, color: colors[i] || color, parent: self
|
94
|
+
|
95
|
+
end
|
89
96
|
|
90
97
|
def @pins.[](i)
|
91
98
|
|
@@ -110,7 +117,7 @@ class RPiLedSimulator
|
|
110
117
|
a = [" ".on_white]
|
111
118
|
a.concat colors.map{|c| @symbol.method((c.to_s + '_on_white').to_sym).call }
|
112
119
|
|
113
|
-
print "\r " + a.join + " ".on_white
|
120
|
+
print "\r " + a.join(" ".on_white * @spacer.to_i) + " ".on_white + " "
|
114
121
|
|
115
122
|
return if n < 1
|
116
123
|
|
@@ -121,7 +128,7 @@ class RPiLedSimulator
|
|
121
128
|
|
122
129
|
def watch(n=2.8)
|
123
130
|
refresh n * 100
|
131
|
+
puts
|
124
132
|
end
|
125
133
|
|
126
|
-
end
|
127
|
-
|
134
|
+
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|