rpi_led_simulator 0.1.0 → 0.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: adb8c11a2870cecb4ee0b30ac76c1c95596f1d1a
4
- data.tar.gz: a170de743d0d2e108640b9739a7fccd57e7c835b
3
+ metadata.gz: dec19e62c83fbcbf8550b6e6de4b43cd581634a1
4
+ data.tar.gz: a5aeb34e64e16acee4cb6eabbf68ca9267c6b9f1
5
5
  SHA512:
6
- metadata.gz: 35d5f803a2bf67c96746217d3696dc2041bce846176567203764db3f730af062fbb30a0f619050f56158902eb98ebd98f1cfa15a772a35a3f52beb2128ca8db8
7
- data.tar.gz: aeea97b09943fd674ba9e44ec4452cd5eaa6f279413cff144305678398198c7b1c9f0254cbb0b7aa1a6f4deebc23cbd5cddde4b612b7637bf464aee0e45db982
6
+ metadata.gz: 80f7b73bc6081ea69cfcb25402bc0c8342f0e695b71313eb65319a651c08520746195cbde7a2b98bab858dcc036a07c311a0acc6307bdcbe99d92e628cb7b4b1
7
+ data.tar.gz: 5739813cc42165180768bffa327bf0bd3b690882e1a4693e8777b41c5bffdbdd6a0a696963b45324db7cd35aea5c5b9f2d34edc825d484c55a53c9f9b65ce388
checksums.yaml.gz.sig CHANGED
Binary file
@@ -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(duration=nil)
28
- @on = true
29
-
30
- (sleep duration; self.off) if duration
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(duration=nil)
35
-
36
- return if self.off?
37
- @on, @blinking = false, false
38
- (sleep duration; self.on) if duration
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
- @pins = a.map {|pin| PinX.new pin, color: color, parent: self }
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
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rpi_led_simulator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file