traffic_light_pi_server 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/traffic_light_pi_server.rb +20 -29
- data/traffic_light_pi_server.gemspec +1 -1
- metadata +2 -2
@@ -25,7 +25,7 @@ class TrafficLightPiServer < Sinatra::Base
|
|
25
25
|
@@lines[line] = Hash.new
|
26
26
|
@@line_map[line].each_key do |light|
|
27
27
|
if @@pi_enabled
|
28
|
-
pin =
|
28
|
+
pin = get_pin(line, light)
|
29
29
|
@@io.mode(pin, OUTPUT)
|
30
30
|
@@lines[line][light] = @@io.read(pin)
|
31
31
|
else
|
@@ -66,19 +66,7 @@ class TrafficLightPiServer < Sinatra::Base
|
|
66
66
|
# Reset all lines
|
67
67
|
get '/reset' do
|
68
68
|
@@line_map.each do |line, lights|
|
69
|
-
|
70
|
-
if light == :green
|
71
|
-
state = 1
|
72
|
-
else
|
73
|
-
state = 0
|
74
|
-
end
|
75
|
-
if @@pi_enabled
|
76
|
-
@@io.write(pin, state)
|
77
|
-
state = @@lines[line][light] = @@io.read(pin)
|
78
|
-
else
|
79
|
-
@@lines[line][light] = state
|
80
|
-
end
|
81
|
-
end
|
69
|
+
reset_line(line)
|
82
70
|
end
|
83
71
|
"Reseted"
|
84
72
|
end
|
@@ -86,20 +74,8 @@ class TrafficLightPiServer < Sinatra::Base
|
|
86
74
|
# Reset one line
|
87
75
|
get '/:line/reset' do
|
88
76
|
line = params[:line].to_sym
|
77
|
+
reset_line(line)
|
89
78
|
|
90
|
-
@@line_map[line].each do |light, pin|
|
91
|
-
if light == :green
|
92
|
-
state = 1
|
93
|
-
else
|
94
|
-
state = 0
|
95
|
-
end
|
96
|
-
if @@pi_enabled
|
97
|
-
@@io.write(pin, state)
|
98
|
-
state = @@lines[line][light] = @@io.read(pin)
|
99
|
-
else
|
100
|
-
@@lines[line][light] = state
|
101
|
-
end
|
102
|
-
end
|
103
79
|
"Reseted"
|
104
80
|
end
|
105
81
|
|
@@ -108,7 +84,7 @@ class TrafficLightPiServer < Sinatra::Base
|
|
108
84
|
line = params[:line].to_sym
|
109
85
|
light = params[:light].to_sym
|
110
86
|
|
111
|
-
pin =
|
87
|
+
pin = get_pin(line, light)
|
112
88
|
state = @@lines[line][light.to_sym]
|
113
89
|
"#{pin}:#{state}"
|
114
90
|
end
|
@@ -123,7 +99,15 @@ class TrafficLightPiServer < Sinatra::Base
|
|
123
99
|
raise "Bad state value (must be 0 or 1)"
|
124
100
|
end
|
125
101
|
|
126
|
-
|
102
|
+
write_light(line, light, state)
|
103
|
+
end
|
104
|
+
|
105
|
+
def get_pin(line, light)
|
106
|
+
@@line_map[line][light]
|
107
|
+
end
|
108
|
+
|
109
|
+
def write_light(line, light, state)
|
110
|
+
pin = get_pin(line, light)
|
127
111
|
if @@pi_enabled
|
128
112
|
@@io.write(pin, state)
|
129
113
|
state = @@lines[line][light] = @@io.read(pin)
|
@@ -132,4 +116,11 @@ class TrafficLightPiServer < Sinatra::Base
|
|
132
116
|
end
|
133
117
|
"#{pin}:#{state}"
|
134
118
|
end
|
119
|
+
|
120
|
+
def reset_line(line)
|
121
|
+
@@line_map[line].each do |light, pin|
|
122
|
+
write_light(line, light, 0)
|
123
|
+
end
|
124
|
+
write_light(line, :green, 1)
|
125
|
+
end
|
135
126
|
end
|
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "traffic_light_pi_server"
|
7
|
-
spec.version = "0.0.
|
7
|
+
spec.version = "0.0.3"
|
8
8
|
spec.authors = ["Nicolas Ledez"]
|
9
9
|
spec.email = ["rubygems@ledez.net"]
|
10
10
|
spec.description = %q{A traffic light serveur for Raspberry π}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: traffic_light_pi_server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sinatra
|