artoo-raspi 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -0
- data/Gemfile.lock +58 -0
- data/LICENSE +13 -0
- data/README.md +60 -0
- data/Rakefile +10 -0
- data/artoo-raspi.gemspec +30 -0
- data/examples/raspi_led.rb +10 -0
- data/examples/raspi_led_and_button.rb +9 -0
- data/lib/artoo-raspi.rb +3 -0
- data/lib/artoo-raspi/version.rb +5 -0
- data/lib/artoo/adaptors/raspi.rb +37 -0
- data/lib/artoo/drivers/raspi_pin.rb +67 -0
- data/test/adaptors/raspi_adaptor_test.rb +4 -0
- data/test/drivers/raspi_pin_driver_test.rb +4 -0
- data/test/test_helper.rb +5 -0
- metadata +99 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
artoo-raspi (0.1.0)
|
5
|
+
artoo (~> 1.0.0.rc4)
|
6
|
+
pi_piper
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
artoo (1.0.0.rc4)
|
12
|
+
celluloid (~> 0.14.1)
|
13
|
+
celluloid-io (~> 0.14.1)
|
14
|
+
multi_json (~> 1.6)
|
15
|
+
pry (~> 0.9)
|
16
|
+
rake (~> 10.0)
|
17
|
+
reel (~> 0.4.0.pre)
|
18
|
+
thor (~> 0.18.1)
|
19
|
+
celluloid (0.14.1)
|
20
|
+
timers (>= 1.0.0)
|
21
|
+
celluloid-io (0.14.1)
|
22
|
+
celluloid (>= 0.14.1)
|
23
|
+
nio4r (>= 0.4.5)
|
24
|
+
certified (0.1.1)
|
25
|
+
coderay (1.0.9)
|
26
|
+
ffi (1.9.0)
|
27
|
+
http (0.4.0)
|
28
|
+
certified
|
29
|
+
http_parser.rb
|
30
|
+
http_parser.rb (0.5.3)
|
31
|
+
method_source (0.8.2)
|
32
|
+
multi_json (1.7.9)
|
33
|
+
nio4r (0.5.0)
|
34
|
+
pi_piper (1.3.1)
|
35
|
+
ffi
|
36
|
+
pry (0.9.12.2)
|
37
|
+
coderay (~> 1.0.5)
|
38
|
+
method_source (~> 0.8)
|
39
|
+
slop (~> 3.4)
|
40
|
+
rack (1.5.2)
|
41
|
+
rake (10.1.0)
|
42
|
+
reel (0.4.0.pre)
|
43
|
+
celluloid-io (>= 0.8.0)
|
44
|
+
http (>= 0.2.0)
|
45
|
+
http_parser.rb (>= 0.5.3)
|
46
|
+
rack (>= 1.4.0)
|
47
|
+
websocket_parser (>= 0.1.2)
|
48
|
+
slop (3.4.6)
|
49
|
+
thor (0.18.1)
|
50
|
+
timers (1.1.0)
|
51
|
+
websocket_parser (0.1.4)
|
52
|
+
http
|
53
|
+
|
54
|
+
PLATFORMS
|
55
|
+
ruby
|
56
|
+
|
57
|
+
DEPENDENCIES
|
58
|
+
artoo-raspi!
|
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2013 The Hybrid Group
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Artoo Adaptor For Raspberry Pi
|
2
|
+
|
3
|
+
This repository contains the Artoo (http://artoo.io/) adaptor for the Raspberry Pi (http://www.raspberrypi.org/) tiny Linux computer's General Purpose Input/Output (GPIO).
|
4
|
+
|
5
|
+
Artoo is a open source micro-framework for robotics using Ruby.
|
6
|
+
|
7
|
+
For more information about Artoo, check out our repo at https://github.com/hybridgroup/artoo
|
8
|
+
|
9
|
+
This gem makes extensive us the the pi_piper gem (https://github.com/jwhitehorn/pi_piper) thanks to @jwhitehorn
|
10
|
+
|
11
|
+
## Installing On Raspberry Pi
|
12
|
+
|
13
|
+
If you do not already have Ruby installed, first you'll need to:
|
14
|
+
|
15
|
+
```
|
16
|
+
sudo apt-get install ruby ruby1.9.1-dev
|
17
|
+
```
|
18
|
+
|
19
|
+
Despite one of the packages being titled "ruby1.9.1-dev", the above command will install Ruby 1.9.3 (as of January 2013) and the Ruby dev tools.
|
20
|
+
|
21
|
+
Then install the artoo-raspi gem:
|
22
|
+
|
23
|
+
```
|
24
|
+
sudo gem install artoo-raspi
|
25
|
+
```
|
26
|
+
|
27
|
+
## Using
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
require 'artoo'
|
31
|
+
|
32
|
+
connection :raspi, :adaptor => :raspi
|
33
|
+
device :led, :driver => :raspi_pin, :pin => 17, :direction => :out
|
34
|
+
|
35
|
+
work do
|
36
|
+
every 1.second do
|
37
|
+
led.toggle
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
```
|
42
|
+
|
43
|
+
To run the examples, requires sudo access on the Raspberry Pi:
|
44
|
+
|
45
|
+
```
|
46
|
+
sudo ruby examples/raspi_led.rb
|
47
|
+
```
|
48
|
+
|
49
|
+
## Connecting to Raspberry Pi GPIO
|
50
|
+
|
51
|
+
This gem only works on a real Raspberry Pi. Do not bother trying on any other kind of computer it will not work. Also note you will need to connect actual circuits to the Raspberry Pi's GPIO pins. Here is an example of wiring the circuits for the GPIO to connect a single LED:
|
52
|
+
|
53
|
+
![GPIO LED Circuit Example](https://github.com/jwhitehorn/pi_piper/blob/master/examples/morse_code/circuit.png)
|
54
|
+
|
55
|
+
To add the button used in the example, add a momentary contact switch to the circuit.
|
56
|
+
|
57
|
+
![GPIO Switch Circuit Example](https://github.com/jwhitehorn/pi_piper/blob/master/examples/simple_switch/circuit.png)
|
58
|
+
|
59
|
+
|
60
|
+
|
data/Rakefile
ADDED
data/artoo-raspi.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "artoo-raspi/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "artoo-raspi"
|
7
|
+
s.version = Artoo::Raspi::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Ron Evans"]
|
10
|
+
s.email = ["artoo@hybridgroup.com"]
|
11
|
+
s.homepage = "https://github.com/hybridgroup/artoo-raspi"
|
12
|
+
s.summary = %q{Artoo adaptor and driver for Raspberry Pi}
|
13
|
+
s.description = %q{Artoo adaptor and driver for Raspberry Pi GPIO}
|
14
|
+
s.license = 'Apache 2.0'
|
15
|
+
|
16
|
+
s.rubyforge_project = "artoo-raspi"
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
+
s.require_paths = ["lib"]
|
22
|
+
|
23
|
+
s.add_runtime_dependency 'artoo', '~> 1.0.0.rc4'
|
24
|
+
s.add_runtime_dependency 'pi_piper'
|
25
|
+
# TODO: add your development dependencies here
|
26
|
+
# EXAMPLE:
|
27
|
+
# s.add_development_dependency 'minitest', '~> 5.0'
|
28
|
+
# s.add_development_dependency 'minitest-happy'
|
29
|
+
# s.add_development_dependency 'mocha', '~> 0.14.0'
|
30
|
+
end
|
data/lib/artoo-raspi.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'artoo/adaptors/adaptor'
|
2
|
+
|
3
|
+
module Artoo
|
4
|
+
module Adaptors
|
5
|
+
# Connect to a Raspberry Pi GPIO
|
6
|
+
# @see device documentation for more information
|
7
|
+
class Raspi < Adaptor
|
8
|
+
finalizer :finalize
|
9
|
+
attr_reader :device
|
10
|
+
|
11
|
+
# Closes connection with device if connected
|
12
|
+
# @return [Boolean]
|
13
|
+
def finalize
|
14
|
+
end
|
15
|
+
|
16
|
+
# Creates a connection with device
|
17
|
+
# @return [Boolean]
|
18
|
+
def connect
|
19
|
+
require 'pi_piper' unless defined?(::PiPiper)
|
20
|
+
|
21
|
+
super
|
22
|
+
end
|
23
|
+
|
24
|
+
# Closes connection with device
|
25
|
+
# @return [Boolean]
|
26
|
+
def disconnect
|
27
|
+
super
|
28
|
+
end
|
29
|
+
|
30
|
+
# Uses method missing to call device actions
|
31
|
+
# @see device documentation
|
32
|
+
def method_missing(method_name, *arguments, &block)
|
33
|
+
device.send(method_name, *arguments, &block)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'artoo/drivers/driver'
|
2
|
+
|
3
|
+
module Artoo
|
4
|
+
module Drivers
|
5
|
+
# Raspberry Pi pin driver behaviors
|
6
|
+
class RaspiPin < Driver
|
7
|
+
COMMANDS = [:on?, :on, :off?, :off, :toggle].freeze
|
8
|
+
|
9
|
+
attr_reader :raspi_pin, :direction, :value
|
10
|
+
|
11
|
+
def initialize(params)
|
12
|
+
super
|
13
|
+
|
14
|
+
@direction = params[:additional_params][:direction]
|
15
|
+
@value = false
|
16
|
+
end
|
17
|
+
|
18
|
+
# Start driver and any required connections
|
19
|
+
def start_driver
|
20
|
+
begin
|
21
|
+
every(interval) do
|
22
|
+
handle_message_events
|
23
|
+
end
|
24
|
+
|
25
|
+
@raspi_pin = PiPiper::Pin.new(:pin => pin, :direction => direction)
|
26
|
+
|
27
|
+
super
|
28
|
+
rescue Exception => e
|
29
|
+
Logger.error "Error starting Raspberry Pi pin driver!"
|
30
|
+
Logger.error e.message
|
31
|
+
Logger.error e.backtrace.inspect
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def handle_message_events
|
36
|
+
return if raspi_pin.nil?
|
37
|
+
raspi_pin.read
|
38
|
+
if raspi_pin.changed?
|
39
|
+
publish(event_topic_name(raspi_pin.value == 0 ? "push" : "release"))
|
40
|
+
publish(event_topic_name("update"), "pin", raspi_pin.value)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def toggle
|
45
|
+
off? ? on : off
|
46
|
+
end
|
47
|
+
|
48
|
+
def on
|
49
|
+
@value = true
|
50
|
+
raspi_pin.on
|
51
|
+
end
|
52
|
+
|
53
|
+
def on?
|
54
|
+
value == true
|
55
|
+
end
|
56
|
+
|
57
|
+
def off
|
58
|
+
@value = false
|
59
|
+
raspi_pin.off
|
60
|
+
end
|
61
|
+
|
62
|
+
def off?
|
63
|
+
!on?
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: artoo-raspi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ron Evans
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-08-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: artoo
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.0.0.rc4
|
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: 1.0.0.rc4
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: pi_piper
|
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
|
+
description: Artoo adaptor and driver for Raspberry Pi GPIO
|
47
|
+
email:
|
48
|
+
- artoo@hybridgroup.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- Gemfile
|
54
|
+
- Gemfile.lock
|
55
|
+
- LICENSE
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- artoo-raspi.gemspec
|
59
|
+
- examples/raspi_led.rb
|
60
|
+
- examples/raspi_led_and_button.rb
|
61
|
+
- lib/artoo-raspi.rb
|
62
|
+
- lib/artoo-raspi/version.rb
|
63
|
+
- lib/artoo/adaptors/raspi.rb
|
64
|
+
- lib/artoo/drivers/raspi_pin.rb
|
65
|
+
- test/adaptors/raspi_adaptor_test.rb
|
66
|
+
- test/drivers/raspi_pin_driver_test.rb
|
67
|
+
- test/test_helper.rb
|
68
|
+
homepage: https://github.com/hybridgroup/artoo-raspi
|
69
|
+
licenses:
|
70
|
+
- Apache 2.0
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
segments:
|
82
|
+
- 0
|
83
|
+
hash: 3220213707000459885
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
segments:
|
91
|
+
- 0
|
92
|
+
hash: 3220213707000459885
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project: artoo-raspi
|
95
|
+
rubygems_version: 1.8.24
|
96
|
+
signing_key:
|
97
|
+
specification_version: 3
|
98
|
+
summary: Artoo adaptor and driver for Raspberry Pi
|
99
|
+
test_files: []
|