traffic_light_pi_server 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/Guardfile +13 -0
- data/LICENSE.txt +22 -0
- data/README.md +68 -0
- data/Rakefile +1 -0
- data/example_server.rb +30 -0
- data/lib/public/images/green-0.png +0 -0
- data/lib/public/images/green-1.png +0 -0
- data/lib/public/images/orange-0.png +0 -0
- data/lib/public/images/orange-1.png +0 -0
- data/lib/public/images/red-0.png +0 -0
- data/lib/public/images/red-1.png +0 -0
- data/lib/public/images/traffic-lights-ko.jpg +0 -0
- data/lib/public/images/traffic-lights-lost.jpg +0 -0
- data/lib/public/onepcssgrid.css +121 -0
- data/lib/public/style.css +17 -0
- data/lib/public/traffic-light.js +34 -0
- data/lib/sounds/clic.mp3 +0 -0
- data/lib/sounds/siren.mp3 +0 -0
- data/lib/traffic_light_pi_server.rb +95 -0
- data/lib/views/404.haml +12 -0
- data/lib/views/500.haml +12 -0
- data/lib/views/index.haml +19 -0
- data/spec/lib/traffic_light_pi_server_spec.rb +93 -0
- data/spec/mpg123-mock +1 -0
- data/spec/spec_helper.rb +23 -0
- data/traffic_light_pi_server.gemspec +37 -0
- metadata +224 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard 'rspec' do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
guard 'bundler' do
|
12
|
+
watch('Gemfile')
|
13
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Nicolas Ledez
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# TrafficLightPiServer
|
2
|
+
|
3
|
+
A traffic light serveur for Raspberry π
|
4
|
+
|
5
|
+
Current build:
|
6
|
+
[![Build Status](https://travis-ci.org/nledez/traffic_light_pi_server.png)](https://travis-ci.org/nledez/traffic_light_pi_server)
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'traffic_light_pi_server'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install traffic_light_pi_server
|
21
|
+
|
22
|
+
Need to install mpg123 before if you want play sound:
|
23
|
+
|
24
|
+
OSX:
|
25
|
+
|
26
|
+
```brew install mpg123```
|
27
|
+
|
28
|
+
Debian like:
|
29
|
+
|
30
|
+
```apt-get install mpg123```
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
Launch example in production
|
35
|
+
|
36
|
+
If you missing this part server listen only on localhost:4567
|
37
|
+
|
38
|
+
Launch as root on π server:
|
39
|
+
|
40
|
+
```# RACK_ENV=production ./example_server.rb```
|
41
|
+
|
42
|
+
Open a browser:
|
43
|
+
|
44
|
+
http://<π address>:4567/
|
45
|
+
|
46
|
+
Enjoy.
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
1. Fork it (https://github.com/nledez/traffic_light_pi_server)
|
51
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
52
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
53
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
54
|
+
5. Create new Pull Request
|
55
|
+
|
56
|
+
## Credits
|
57
|
+
|
58
|
+
Thanks to msaling for lights:
|
59
|
+
|
60
|
+
http://www.vectoropenstock.com/1358-Vector-Traffic-Light-vector
|
61
|
+
|
62
|
+
Thanks to Per aspera ad Astra for london traffic lights:
|
63
|
+
|
64
|
+
http://commons.wikimedia.org/wiki/File:London_traffic-lights.JPG
|
65
|
+
|
66
|
+
Thanks to jenniferboyer for broken traffic lights:
|
67
|
+
|
68
|
+
http://www.flickr.com/photos/jenniferboyer/5252129732/
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/example_server.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require File.join(File.dirname(__FILE__), 'lib', 'traffic_light_pi_server.rb')
|
3
|
+
|
4
|
+
class TrafficLightPiServer < Sinatra::Base
|
5
|
+
configure do
|
6
|
+
@@line_map = {
|
7
|
+
:devant => {
|
8
|
+
:red => 12,
|
9
|
+
:orange => 13,
|
10
|
+
:green => 14,
|
11
|
+
},
|
12
|
+
:gauche => {
|
13
|
+
:red => 4,
|
14
|
+
:green => 5,
|
15
|
+
},
|
16
|
+
:fond => {
|
17
|
+
:red => 6,
|
18
|
+
:orange => 10,
|
19
|
+
:green => 11,
|
20
|
+
},
|
21
|
+
:droite => {
|
22
|
+
:red => 0,
|
23
|
+
:green => 3,
|
24
|
+
},
|
25
|
+
}
|
26
|
+
init_lights
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
TrafficLightPiServer.run!
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,121 @@
|
|
1
|
+
/* *********************************************************************************************************************
|
2
|
+
One% CSS Grid - 12 Columns Fluid CSS Grid System
|
3
|
+
|
4
|
+
Why One% ? Let’s count ...
|
5
|
+
we have 12 columns (magic number divided by 2, 3, 4, 6)
|
6
|
+
|
7
|
+
for 12 columns we need 11 margins
|
8
|
+
|
9
|
+
so if we count margin 3%, then 3% * 11 margins = 33%
|
10
|
+
|
11
|
+
and if we count width of 1 column 5.5%, than 5.5% * 12 columns = 66%
|
12
|
+
|
13
|
+
in the end we have 33% + 66% = 99% aaand ???
|
14
|
+
|
15
|
+
1% is still here so that's the name - One%
|
16
|
+
|
17
|
+
2 starting options ? Let’s count a bit more ...
|
18
|
+
1200px - perfectly fits 1280 screens
|
19
|
+
12 columns
|
20
|
+
margin 3% / 36px (full-width)
|
21
|
+
col1 5.5% / 66px (full-width)
|
22
|
+
|
23
|
+
1000px - perfectly fits 1024 screens
|
24
|
+
12 columns
|
25
|
+
margin 3% / 30px (full-width)
|
26
|
+
col1 5.5% / 55px (full-width)
|
27
|
+
*/
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
/* *********************************************************************************************************************
|
34
|
+
* Main container for all
|
35
|
+
*/
|
36
|
+
.onepcssgrid-1000, .onepcssgrid-1200 {
|
37
|
+
margin: 0 auto;
|
38
|
+
padding: 0 0 0 1%; /* THAT'S THE NAME ;) */
|
39
|
+
}
|
40
|
+
|
41
|
+
.onepcssgrid-1200 {
|
42
|
+
max-width: 1220px;
|
43
|
+
}
|
44
|
+
|
45
|
+
.onepcssgrid-1000 {
|
46
|
+
max-width: 1020px;
|
47
|
+
}
|
48
|
+
|
49
|
+
.onerow {
|
50
|
+
clear: both;
|
51
|
+
padding: 0 10px;
|
52
|
+
}
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
/* *********************************************************************************************************************
|
59
|
+
* Common columns definitions
|
60
|
+
*/
|
61
|
+
.col1, .col2, .col3, .col4, .col5, .col6, .col7, .col8, .col9, .col10, .col11, .col12 {
|
62
|
+
float: left;
|
63
|
+
margin: 0 3% 0 0;
|
64
|
+
}
|
65
|
+
|
66
|
+
.col1.last, .col2.last, .col3.last, .col4.last, .col5.last, .col6.last, .col7.last, .col8.last, .col9.last, .col10.last, .col11.last, .col12 {
|
67
|
+
margin: 0;
|
68
|
+
}
|
69
|
+
|
70
|
+
.col1 { width: 5.5%; }
|
71
|
+
.col2 { width: 14%; }
|
72
|
+
.col3 { width: 22.5%; }
|
73
|
+
.col4 { width: 31%; }
|
74
|
+
.col5 { width: 39.5%; }
|
75
|
+
.col6 { width: 48%; }
|
76
|
+
.col7 { width: 56.5%; }
|
77
|
+
.col8 { width: 65%; }
|
78
|
+
.col9 { width: 73.5%; }
|
79
|
+
.col10 { width: 82%; }
|
80
|
+
.col11 { width: 90.5%; }
|
81
|
+
.col12 { width: 99%; margin: 0; }
|
82
|
+
|
83
|
+
.col1 img, .col2 img, .col3 img, .col4 img, .col5 img, .col6 img, .col7 img, .col8 img, .col9 img, .col10 img, .col11 img, .col12 img {
|
84
|
+
width: 100%;
|
85
|
+
height: auto;
|
86
|
+
display: block;
|
87
|
+
}
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
/* *********************************************************************************************************************
|
94
|
+
* Disable padding left/right 10px if I'm 1024 or gibber - correct percentage math
|
95
|
+
*/
|
96
|
+
@media all and (min-width: 1024px) {
|
97
|
+
.onepcssgrid-1000 {
|
98
|
+
max-width: 1000px;
|
99
|
+
}
|
100
|
+
|
101
|
+
.onepcssgrid-1000 .onerow {
|
102
|
+
padding: 0;
|
103
|
+
}
|
104
|
+
}
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
/* *********************************************************************************************************************
|
111
|
+
* Small devices
|
112
|
+
*/
|
113
|
+
@media all and (max-width: 768px) {
|
114
|
+
.onerow {
|
115
|
+
}
|
116
|
+
|
117
|
+
.col1, .col2, .col3, .col4, .col5, .col6, .col7, .col8, .col9, .col10, .col11 {
|
118
|
+
float: none;
|
119
|
+
width: 99%;
|
120
|
+
}
|
121
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
body {
|
2
|
+
margin-top: 20px;
|
3
|
+
}
|
4
|
+
|
5
|
+
.col1, .col2, .col3, .col4, .col5, .col6, .col7, .col8, .col9, .col10, .col11, .col12 {
|
6
|
+
background-color: black;
|
7
|
+
color: white;
|
8
|
+
margin-bottom: 20px;
|
9
|
+
text-align: center;
|
10
|
+
padding: 20px 0;
|
11
|
+
}
|
12
|
+
|
13
|
+
@media all and (max-width: 768px) {
|
14
|
+
.onerow {
|
15
|
+
margin:100px;
|
16
|
+
}
|
17
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
$(".light").click(function () {
|
2
|
+
// Get current image
|
3
|
+
$image = $(this);
|
4
|
+
|
5
|
+
// Extract parameters from id
|
6
|
+
$parameters = $image.attr("id").split('-');
|
7
|
+
$line = $parameters[0];
|
8
|
+
$light = $parameters[1];
|
9
|
+
$old_state = $parameters[2];
|
10
|
+
|
11
|
+
// Swicht status
|
12
|
+
if ($old_state == '0') {
|
13
|
+
$state = '1';
|
14
|
+
} else {
|
15
|
+
$state = '0';
|
16
|
+
}
|
17
|
+
|
18
|
+
// Make url to change status
|
19
|
+
$url = $line + '/' + $light + '/' + $state;
|
20
|
+
|
21
|
+
// And call it
|
22
|
+
$.get($url, function(data) {
|
23
|
+
// Get page resut & extract new state
|
24
|
+
$newstate = data.split(':')[1];
|
25
|
+
|
26
|
+
// Make new src & id
|
27
|
+
$src = "images/" + $light + "-" + $newstate + ".png";
|
28
|
+
$id = $line + '-' + $light + '-' + $newstate;
|
29
|
+
|
30
|
+
// And update it
|
31
|
+
$image.attr('src', $src);
|
32
|
+
$image.attr('id', $id);
|
33
|
+
});
|
34
|
+
});
|
data/lib/sounds/clic.mp3
ADDED
Binary file
|
Binary file
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'sinatra'
|
2
|
+
require 'haml'
|
3
|
+
if RUBY_PLATFORM == 'arm-linux-eabihf'
|
4
|
+
require "wiringpi"
|
5
|
+
end
|
6
|
+
|
7
|
+
class TrafficLightPiServer < Sinatra::Base
|
8
|
+
def self.init_lights
|
9
|
+
unless defined? @@mp3player
|
10
|
+
@@mp3player = "mpg123"
|
11
|
+
end
|
12
|
+
|
13
|
+
unless defined? @@sound_dir
|
14
|
+
@@sound_dir = "#{File.dirname(__FILE__)}/sounds"
|
15
|
+
end
|
16
|
+
|
17
|
+
@@pi_enabled = nil
|
18
|
+
if RUBY_PLATFORM == 'arm-linux-eabihf'
|
19
|
+
@@io = WiringPi::GPIO.new
|
20
|
+
@@pi_enabled = true
|
21
|
+
end
|
22
|
+
|
23
|
+
@@lines = Hash.new
|
24
|
+
@@line_map.each_key do |line|
|
25
|
+
@@lines[line] = Hash.new
|
26
|
+
@@line_map[line].each_key do |light|
|
27
|
+
if @@pi_enabled
|
28
|
+
pin = @@line_map[line][light]
|
29
|
+
@@io.mode(pin, OUTPUT)
|
30
|
+
@@lines[line][light] = @@io.read(pin)
|
31
|
+
else
|
32
|
+
@@lines[line][light] = 0
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# A custom 500
|
39
|
+
error do
|
40
|
+
haml :'500'
|
41
|
+
end
|
42
|
+
|
43
|
+
# A custom 404
|
44
|
+
not_found do
|
45
|
+
haml :'404'
|
46
|
+
end
|
47
|
+
|
48
|
+
# Put a default page
|
49
|
+
get '/' do
|
50
|
+
@lines = @@lines
|
51
|
+
@line_map = @@line_map
|
52
|
+
haml :index, :format => :html5
|
53
|
+
end
|
54
|
+
|
55
|
+
get '/play/:sound' do
|
56
|
+
sound = params[:sound]
|
57
|
+
mp3 = "#{@@sound_dir}/#{sound}.mp3"
|
58
|
+
if File.exist? mp3
|
59
|
+
pid = fork{ exec @@mp3player, '-q', mp3 }
|
60
|
+
"Played with pid: #{pid}"
|
61
|
+
else
|
62
|
+
status 404
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Get current status for one light/color in one line
|
67
|
+
get '/:line/:light' do
|
68
|
+
line = params[:line].to_sym
|
69
|
+
light = params[:light].to_sym
|
70
|
+
|
71
|
+
pin = @@line_map[line][light]
|
72
|
+
state = @@lines[line][light.to_sym]
|
73
|
+
"#{pin}:#{state}"
|
74
|
+
end
|
75
|
+
|
76
|
+
# Set status of one light/light in one line
|
77
|
+
get '/:line/:light/:state' do
|
78
|
+
line = params[:line].to_sym
|
79
|
+
light = params[:light].to_sym
|
80
|
+
state = params[:state].to_i
|
81
|
+
|
82
|
+
if state != 0 && state != 1
|
83
|
+
raise "Bad state value (must be 0 or 1)"
|
84
|
+
end
|
85
|
+
|
86
|
+
pin = @@line_map[line][light.to_sym].to_i
|
87
|
+
if @@pi_enabled
|
88
|
+
@@io.write(pin, state)
|
89
|
+
state = @@lines[line][light] = @@io.read(pin)
|
90
|
+
else
|
91
|
+
@@lines[line][light] = state
|
92
|
+
end
|
93
|
+
"#{pin}:#{state}"
|
94
|
+
end
|
95
|
+
end
|
data/lib/views/404.haml
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
!!!
|
2
|
+
%html
|
3
|
+
%head
|
4
|
+
%meta{:content => "text/html; charset=utf-8", "http-equiv" => "Content-Type"}/
|
5
|
+
%title Traffic light server - Lost ?
|
6
|
+
%meta{:content => "width=device-width", :name => "viewport"}/
|
7
|
+
%link{:href => "onepcssgrid.css", :rel => "stylesheet"}/
|
8
|
+
%link{:href => "style.css", :media => "all", :rel => "stylesheet", :type => "text/css"}/
|
9
|
+
%body
|
10
|
+
Lost ?
|
11
|
+
%br
|
12
|
+
%img{ :src => "/images/traffic-lights-lost.jpg" }
|
data/lib/views/500.haml
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
!!!
|
2
|
+
%html
|
3
|
+
%head
|
4
|
+
%meta{:content => "text/html; charset=utf-8", "http-equiv" => "Content-Type"}/
|
5
|
+
%title Traffic light server - Oups :(
|
6
|
+
%meta{:content => "width=device-width", :name => "viewport"}/
|
7
|
+
%link{:href => "onepcssgrid.css", :rel => "stylesheet"}/
|
8
|
+
%link{:href => "style.css", :media => "all", :rel => "stylesheet", :type => "text/css"}/
|
9
|
+
%body
|
10
|
+
Oups :(
|
11
|
+
%br
|
12
|
+
%img{ :src => "/images/traffic-lights-ko.jpg" }
|
@@ -0,0 +1,19 @@
|
|
1
|
+
!!!
|
2
|
+
%html
|
3
|
+
%head
|
4
|
+
%meta{:content => "text/html; charset=utf-8", "http-equiv" => "Content-Type"}/
|
5
|
+
%title Traffic light server
|
6
|
+
%meta{:content => "width=device-width", :name => "viewport"}/
|
7
|
+
%link{:href => "onepcssgrid.css", :rel => "stylesheet"}/
|
8
|
+
%link{:href => "style.css", :media => "all", :rel => "stylesheet", :type => "text/css"}/
|
9
|
+
%script{ :src => 'http://code.jquery.com/jquery-1.9.1.js' }
|
10
|
+
%body
|
11
|
+
.onepcssgrid-1200
|
12
|
+
- (@line_map).each_key do |line|
|
13
|
+
.col2
|
14
|
+
= line.capitalize
|
15
|
+
- (@line_map[line]).each_key do |light|
|
16
|
+
- state = @lines[line][light]
|
17
|
+
%div
|
18
|
+
%img{ :src => "images/#{light}-#{state}.png", :id => "#{line}-#{light}-#{state}", :class => "light" }
|
19
|
+
%script{ :src => 'traffic-light.js' }
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require File.dirname(__FILE__) + '../../spec_helper'
|
2
|
+
set :environment, :test
|
3
|
+
|
4
|
+
describe "My Traffic light server" do
|
5
|
+
include Rack::Test::Methods
|
6
|
+
|
7
|
+
class TrafficLightPiServer < Sinatra::Base
|
8
|
+
@@mp3player = "#{File.dirname(__FILE__)}/../mpg123-mock"
|
9
|
+
configure do
|
10
|
+
@@line_map = {
|
11
|
+
:front => {
|
12
|
+
:green => 12,
|
13
|
+
:orange => 13,
|
14
|
+
:red => 14
|
15
|
+
},
|
16
|
+
:left => {
|
17
|
+
:green => 4,
|
18
|
+
:red => 5
|
19
|
+
}
|
20
|
+
}
|
21
|
+
init_lights
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def app
|
26
|
+
@app || TrafficLightPiServer
|
27
|
+
end
|
28
|
+
|
29
|
+
# Do a root test
|
30
|
+
it "should respond to /" do
|
31
|
+
get '/'
|
32
|
+
last_response.should be_ok
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should change status for different line & light" do
|
36
|
+
get '/front/green/0'
|
37
|
+
get '/front/red/0'
|
38
|
+
get '/left/red/0'
|
39
|
+
|
40
|
+
get '/front/green'
|
41
|
+
last_response.body.should == "12:0"
|
42
|
+
|
43
|
+
get '/front/green/1'
|
44
|
+
last_response.body.should == "12:1"
|
45
|
+
|
46
|
+
get '/front/green'
|
47
|
+
last_response.body.should == "12:1"
|
48
|
+
|
49
|
+
get '/front/green/0'
|
50
|
+
last_response.body.should == "12:0"
|
51
|
+
|
52
|
+
get '/front/green'
|
53
|
+
last_response.body.should == "12:0"
|
54
|
+
|
55
|
+
get '/front/red'
|
56
|
+
last_response.body.should == "14:0"
|
57
|
+
|
58
|
+
get '/front/red/1'
|
59
|
+
last_response.body.should == "14:1"
|
60
|
+
|
61
|
+
get '/front/red'
|
62
|
+
last_response.body.should == "14:1"
|
63
|
+
|
64
|
+
get '/front/green'
|
65
|
+
last_response.body.should == "12:0"
|
66
|
+
|
67
|
+
get '/left/red'
|
68
|
+
last_response.body.should == "5:0"
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should play mp3" do
|
72
|
+
get '/play/clic'
|
73
|
+
last_response.should be_ok
|
74
|
+
last_response.body.should =~ /Played with pid: \d+/
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should return 404 if try to play a missing file" do
|
78
|
+
get '/play/missing-file'
|
79
|
+
last_response.status.should == 404
|
80
|
+
end
|
81
|
+
|
82
|
+
unless ENV.has_key? 'TRAVIS'
|
83
|
+
it "should return a custom 404 & 500 error pages" do
|
84
|
+
get '/left/red/bad/url'
|
85
|
+
last_response.status.should == 404
|
86
|
+
last_response.body.should =~ /traffic-lights-lost/
|
87
|
+
|
88
|
+
get '/left/red/4'
|
89
|
+
last_response.status.should == 500
|
90
|
+
last_response.body.should =~ /traffic-lights-ko/
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
data/spec/mpg123-mock
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
#!/bin/sh
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../lib', 'traffic_light_pi_server.rb')
|
2
|
+
|
3
|
+
require 'rack/test'
|
4
|
+
require 'rspec'
|
5
|
+
|
6
|
+
# set test environment
|
7
|
+
set :environment, :test
|
8
|
+
set :run, false
|
9
|
+
set :raise_errors, true
|
10
|
+
set :logging, false
|
11
|
+
|
12
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
15
|
+
config.run_all_when_everything_filtered = true
|
16
|
+
config.filter_run :focus
|
17
|
+
|
18
|
+
# Run specs in random order to surface order dependencies. If you find an
|
19
|
+
# order dependency and want to debug it, you can fix the order by providing
|
20
|
+
# the seed, which is printed after each run.
|
21
|
+
# --seed 1234
|
22
|
+
#config.order = 'random'
|
23
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "traffic_light_pi_server"
|
7
|
+
spec.version = "0.0.1"
|
8
|
+
spec.authors = ["Nicolas Ledez"]
|
9
|
+
spec.email = ["rubygems@ledez.net"]
|
10
|
+
spec.description = %q{A traffic light serveur for Raspberry π}
|
11
|
+
spec.summary = %q{Get a Raspberry π & traffic light install this app on π & enjoy}
|
12
|
+
spec.homepage = "https://github.com/nledez/traffic_light_pi_server"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_dependency "sinatra"
|
20
|
+
spec.add_dependency "haml"
|
21
|
+
spec.add_dependency "wiringpi" if spec.platform.to_s == 'arm-linux-eabihf'
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
|
26
|
+
spec.add_development_dependency "rspec"
|
27
|
+
spec.add_development_dependency "rack-test"
|
28
|
+
|
29
|
+
spec.add_development_dependency "guard"
|
30
|
+
spec.add_development_dependency "guard-rspec"
|
31
|
+
spec.add_development_dependency "guard-bundler"
|
32
|
+
|
33
|
+
if spec.platform.to_s == 'arm-linux-eabihf'
|
34
|
+
spec.add_development_dependency "rb-fsevent"
|
35
|
+
spec.add_development_dependency "growl"
|
36
|
+
end
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,224 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: traffic_light_pi_server
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Nicolas Ledez
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-05-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: sinatra
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: haml
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: bundler
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.3'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.3'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rspec
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: rack-test
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: guard
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: guard-rspec
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
- !ruby/object:Gem::Dependency
|
143
|
+
name: guard-bundler
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ! '>='
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
type: :development
|
151
|
+
prerelease: false
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ! '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
description: A traffic light serveur for Raspberry π
|
159
|
+
email:
|
160
|
+
- rubygems@ledez.net
|
161
|
+
executables: []
|
162
|
+
extensions: []
|
163
|
+
extra_rdoc_files: []
|
164
|
+
files:
|
165
|
+
- .gitignore
|
166
|
+
- .rspec
|
167
|
+
- .travis.yml
|
168
|
+
- Gemfile
|
169
|
+
- Guardfile
|
170
|
+
- LICENSE.txt
|
171
|
+
- README.md
|
172
|
+
- Rakefile
|
173
|
+
- example_server.rb
|
174
|
+
- lib/public/images/green-0.png
|
175
|
+
- lib/public/images/green-1.png
|
176
|
+
- lib/public/images/orange-0.png
|
177
|
+
- lib/public/images/orange-1.png
|
178
|
+
- lib/public/images/red-0.png
|
179
|
+
- lib/public/images/red-1.png
|
180
|
+
- lib/public/images/traffic-lights-ko.jpg
|
181
|
+
- lib/public/images/traffic-lights-lost.jpg
|
182
|
+
- lib/public/onepcssgrid.css
|
183
|
+
- lib/public/style.css
|
184
|
+
- lib/public/traffic-light.js
|
185
|
+
- lib/sounds/clic.mp3
|
186
|
+
- lib/sounds/siren.mp3
|
187
|
+
- lib/traffic_light_pi_server.rb
|
188
|
+
- lib/views/404.haml
|
189
|
+
- lib/views/500.haml
|
190
|
+
- lib/views/index.haml
|
191
|
+
- spec/lib/traffic_light_pi_server_spec.rb
|
192
|
+
- spec/mpg123-mock
|
193
|
+
- spec/spec_helper.rb
|
194
|
+
- traffic_light_pi_server.gemspec
|
195
|
+
homepage: https://github.com/nledez/traffic_light_pi_server
|
196
|
+
licenses:
|
197
|
+
- MIT
|
198
|
+
post_install_message:
|
199
|
+
rdoc_options: []
|
200
|
+
require_paths:
|
201
|
+
- lib
|
202
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
203
|
+
none: false
|
204
|
+
requirements:
|
205
|
+
- - ! '>='
|
206
|
+
- !ruby/object:Gem::Version
|
207
|
+
version: '0'
|
208
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
209
|
+
none: false
|
210
|
+
requirements:
|
211
|
+
- - ! '>='
|
212
|
+
- !ruby/object:Gem::Version
|
213
|
+
version: '0'
|
214
|
+
requirements: []
|
215
|
+
rubyforge_project:
|
216
|
+
rubygems_version: 1.8.23
|
217
|
+
signing_key:
|
218
|
+
specification_version: 3
|
219
|
+
summary: Get a Raspberry π & traffic light install this app on π & enjoy
|
220
|
+
test_files:
|
221
|
+
- spec/lib/traffic_light_pi_server_spec.rb
|
222
|
+
- spec/mpg123-mock
|
223
|
+
- spec/spec_helper.rb
|
224
|
+
has_rdoc:
|