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.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/lib/rpi.rb +38 -16
  5. metadata +1 -1
  6. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3c9dc28e91ead4d24acb32becc2760c8651169e2
4
- data.tar.gz: d63a47fbaba95fb2346451ecf4f7e5280c77a70f
3
+ metadata.gz: 76b839fcf54da81b0e89dbde7baf90c7fe3f8d3f
4
+ data.tar.gz: 686e899dde81c9007a913ac984deabafa08ba997
5
5
  SHA512:
6
- metadata.gz: a8a0e58408996d34cbaff0dd5da980c4eb196c233209e2e33b0d10c0f4ce115ed4758f764547d14840d393c837a2124571fb88cf56c9d230846c3e949881e9f1
7
- data.tar.gz: d6da6f1c50c8b81411bbd3ad9b121335144a7a35238abf761d6bbb44495975444d69aa8fd06257d89c91ff508ac9826f23c20f72cdd1296ea2984432e64ca3a9
6
+ metadata.gz: c5ac67b4d436d205192703250c64d22d6a73d46f6525827e0202ade519ab8d04bb880d41db8c9caae13f7b086d6cdfa9a502809e709beef9d9e28edc2f0539b9
7
+ data.tar.gz: 9fe559f58641b5c42cdfb80b195f3dfca4e03b05debfda27d1c2ed1c0266b96b6fb9564efaef7d16202c3989ee20bc7923943f87eeb9b6c385bb6ad4af638901
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
- @state = self.value
21
+ @on, @blinking = false, false
22
22
  end
23
23
 
24
- def on(duration=nil)
24
+ def on(durationx=nil, duration: nil)
25
25
  super();
26
- @state = :on
27
- (sleep duration; self.off) if duration
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(duration=nil)
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
- @state = :blink
58
+ @blinking = true
50
59
  t2 = Time.now + duration if duration
51
60
 
52
61
  Thread.new do
53
- while @state == :blink do
54
- (set_pin HIGH; sleep seconds; set_pin LOW; sleep seconds)
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?() @state == :on end
64
- def off?() @state == :off end
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
- state = @state
92
+ @internal_call = true
71
93
  self.update_value val
72
- @state = state
94
+ @internal_call = false
73
95
  end
74
96
 
75
97
  def to_s()
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rpi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
4
+ version: 0.4.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file