whipped-cream 0.0.1pre4 → 0.0.1pre5
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.
@@ -2,13 +2,15 @@
|
|
2
2
|
module PiPiper
|
3
3
|
# Just enough to imitate a pin
|
4
4
|
class Pin
|
5
|
-
attr_reader :pin, :direction
|
5
|
+
attr_reader :pin, :direction
|
6
6
|
|
7
7
|
def initialize(options)
|
8
8
|
@pin = options[:pin]
|
9
9
|
@direction = options[:direction]
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
+
def read
|
13
|
+
@value ||= 0
|
12
14
|
end
|
13
15
|
|
14
16
|
def on
|
@@ -23,6 +25,8 @@ module PiPiper
|
|
23
25
|
log "Pin #{pin} off"
|
24
26
|
end
|
25
27
|
|
28
|
+
private
|
29
|
+
|
26
30
|
def log(message)
|
27
31
|
puts message unless ENV['RUBY_ENV'] == 'test'
|
28
32
|
end
|
data/lib/whipped-cream/runner.rb
CHANGED
@@ -69,7 +69,7 @@ module WhippedCream
|
|
69
69
|
define_singleton_method sensor.id do
|
70
70
|
pin = pins[sensor.id]
|
71
71
|
|
72
|
-
pin.
|
72
|
+
pin.read == 1 ? sensor.high : sensor.low
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
@@ -86,7 +86,7 @@ module WhippedCream
|
|
86
86
|
define_singleton_method switch.id do
|
87
87
|
pin = pins[switch.id]
|
88
88
|
|
89
|
-
pin.
|
89
|
+
pin.read == 1 ? pin.off : pin.on
|
90
90
|
end
|
91
91
|
end
|
92
92
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<div class="item">
|
2
2
|
<h2><%= control.name %></h2>
|
3
|
-
<p><%= runner.pins[control.id].
|
3
|
+
<p><%= runner.pins[control.id].read.nonzero? ? "On" : "Off" %></p>
|
4
4
|
<form action="/<%= control.id %>" method="get">
|
5
|
-
<input type="submit" value="<%= runner.pins[control.id].
|
5
|
+
<input type="submit" value="<%= runner.pins[control.id].read.nonzero? ? "Off" : "On" %>">
|
6
6
|
</form>
|
7
7
|
</div>
|
@@ -54,7 +54,7 @@ describe WhippedCream::Runner do
|
|
54
54
|
|
55
55
|
it "defines a method that reads and converts the pin's value" do
|
56
56
|
pin = runner.pins[:door]
|
57
|
-
pin.stub
|
57
|
+
pin.stub read: 1
|
58
58
|
|
59
59
|
expect(runner.door).to eq("Closed")
|
60
60
|
end
|
@@ -96,13 +96,13 @@ describe WhippedCream::Runner do
|
|
96
96
|
it "defines a light method that switches the pin on and off" do
|
97
97
|
pin = runner.pins[:light]
|
98
98
|
|
99
|
-
expect(pin.
|
99
|
+
expect(pin.read).to eq(0)
|
100
100
|
runner.light
|
101
|
-
expect(pin.
|
101
|
+
expect(pin.read).to eq(1)
|
102
102
|
runner.light
|
103
|
-
expect(pin.
|
103
|
+
expect(pin.read).to eq(0)
|
104
104
|
runner.light
|
105
|
-
expect(pin.
|
105
|
+
expect(pin.read).to eq(1)
|
106
106
|
end
|
107
107
|
end
|
108
108
|
end
|