rpi 0.4.6 → 0.4.7
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.tar.gz.sig +0 -0
- data/lib/rpi.rb +38 -16
- 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: 76b839fcf54da81b0e89dbde7baf90c7fe3f8d3f
|
4
|
+
data.tar.gz: 686e899dde81c9007a913ac984deabafa08ba997
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5ac67b4d436d205192703250c64d22d6a73d46f6525827e0202ade519ab8d04bb880d41db8c9caae13f7b086d6cdfa9a502809e709beef9d9e28edc2f0539b9
|
7
|
+
data.tar.gz: 9fe559f58641b5c42cdfb80b195f3dfca4e03b05debfda27d1c2ed1c0266b96b6fb9564efaef7d16202c3989ee20bc7923943f87eeb9b6c385bb6ad4af638901
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/rpi.rb
CHANGED
@@ -18,21 +18,30 @@ class RPi
|
|
18
18
|
def initialize(id)
|
19
19
|
@id = id
|
20
20
|
super(pin: id, direction: :out)
|
21
|
-
@
|
21
|
+
@on, @blinking = false, false
|
22
22
|
end
|
23
23
|
|
24
|
-
def on(
|
24
|
+
def on(durationx=nil, duration: nil)
|
25
25
|
super();
|
26
|
-
@
|
27
|
-
|
26
|
+
@on = true
|
27
|
+
duration ||= durationx
|
28
|
+
|
29
|
+
@off_thread.exit if @off_thread
|
30
|
+
@on_thread = Thread.new {(sleep duration; self.off()) } if duration
|
31
|
+
|
28
32
|
end
|
29
33
|
|
30
|
-
def off(
|
34
|
+
def off(durationx=nil, duration: nil)
|
35
|
+
|
36
|
+
super();
|
37
|
+
return if @internal_call
|
38
|
+
|
39
|
+
@on, @blinking = false, false
|
40
|
+
duration ||= durationx
|
41
|
+
|
42
|
+
@on_thread.exit if @on_thread
|
43
|
+
@off_thread = Thread.new { (sleep duration; self.on()) } if duration
|
31
44
|
|
32
|
-
return if self.off?
|
33
|
-
super()
|
34
|
-
@state = :off
|
35
|
-
(sleep duration; self.on) if duration
|
36
45
|
end
|
37
46
|
|
38
47
|
alias high on # opposite of low
|
@@ -46,12 +55,25 @@ class RPi
|
|
46
55
|
|
47
56
|
def blink(seconds=0.5, duration: nil)
|
48
57
|
|
49
|
-
@
|
58
|
+
@blinking = true
|
50
59
|
t2 = Time.now + duration if duration
|
51
60
|
|
52
61
|
Thread.new do
|
53
|
-
while @
|
54
|
-
|
62
|
+
while @blinking do
|
63
|
+
|
64
|
+
set_pin HIGH
|
65
|
+
sleep seconds / 2.0
|
66
|
+
break if !@blinking
|
67
|
+
sleep seconds / 2.0
|
68
|
+
break if !@blinking
|
69
|
+
|
70
|
+
set_pin LOW;
|
71
|
+
sleep seconds / 2.0
|
72
|
+
break if !@blinking
|
73
|
+
sleep seconds / 2.0
|
74
|
+
|
75
|
+
break if !@blinking
|
76
|
+
|
55
77
|
self.off if duration and Time.now >= t2
|
56
78
|
end
|
57
79
|
|
@@ -60,16 +82,16 @@ class RPi
|
|
60
82
|
|
61
83
|
alias oscillate blink
|
62
84
|
|
63
|
-
def on?() @
|
64
|
-
def off?()
|
85
|
+
def on?() @on end
|
86
|
+
def off?() !@on end
|
65
87
|
|
66
88
|
# set val with 0 (off) or 1 (on)
|
67
89
|
#
|
68
90
|
def set_pin(val)
|
69
91
|
|
70
|
-
|
92
|
+
@internal_call = true
|
71
93
|
self.update_value val
|
72
|
-
@
|
94
|
+
@internal_call = false
|
73
95
|
end
|
74
96
|
|
75
97
|
def to_s()
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|