artoo-raspi 0.2.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +23 -24
- data/README.md +32 -6
- data/artoo-raspi.gemspec +8 -7
- data/examples/blink_led.rb +14 -0
- data/examples/blink_led_with_toggle.rb +14 -0
- data/examples/button_and_led.rb +13 -0
- data/examples/led_brightness.rb +22 -0
- data/examples/wiichuck.rb +12 -0
- data/lib/artoo-raspi/version.rb +1 -1
- data/lib/artoo/adaptors/raspi.rb +117 -3
- data/lib/pwm_pin.rb +40 -0
- data/test/adaptors/raspi_adaptor_test.rb +27 -1
- metadata +35 -17
- data/examples/raspi_led.rb +0 -10
- data/examples/raspi_led_and_button.rb +0 -9
- data/lib/artoo/drivers/raspi_pin.rb +0 -68
- data/test/drivers/raspi_pin_driver_test.rb +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f834761fadd08b3676394c8d8e7d98d6001486a
|
4
|
+
data.tar.gz: 69c02de21859c3595e6e590fcd3b01fb0df08130
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d2e259a6937be632bd674c57ce59dcf9d6585488fe9eb6e0e1a8f6ffbae314dcfa5cd8e9f8503e79edb74d5ea7a2fce5d466f76f53a780a12d247abd187080e
|
7
|
+
data.tar.gz: e300afdea903eec06e477a62b5f4b5dcd11f8a41d5a58401eb4c44935cd67c43ab174c6167e00d75e33d91f4008b34075b3bad3b18fdb91b160c9dd2eee87247
|
data/Gemfile.lock
CHANGED
@@ -1,55 +1,54 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
artoo-raspi (0.
|
5
|
-
artoo (
|
6
|
-
|
4
|
+
artoo-raspi (0.4.0)
|
5
|
+
artoo (>= 1.3.0)
|
6
|
+
artoo-gpio
|
7
|
+
artoo-i2c
|
7
8
|
|
8
9
|
GEM
|
9
10
|
remote: http://rubygems.org/
|
10
11
|
specs:
|
11
|
-
artoo (1.
|
12
|
+
artoo (1.3.0)
|
12
13
|
celluloid (~> 0.15.0)
|
13
14
|
celluloid-io (~> 0.15.0)
|
14
15
|
multi_json (~> 1.6)
|
15
16
|
pry (~> 0.9)
|
16
|
-
rake
|
17
|
-
reel (~> 0.4.0
|
17
|
+
rake
|
18
|
+
reel (~> 0.4.0)
|
18
19
|
thor (~> 0.18.1)
|
19
|
-
|
20
|
+
artoo-gpio (0.2.1)
|
21
|
+
artoo (>= 1.2.2)
|
22
|
+
artoo-i2c (0.2.1)
|
23
|
+
artoo (>= 1.2.2)
|
24
|
+
celluloid (0.15.1)
|
20
25
|
timers (~> 1.1.0)
|
21
26
|
celluloid-io (0.15.0)
|
22
27
|
celluloid (>= 0.15.0)
|
23
28
|
nio4r (>= 0.5.0)
|
24
|
-
certified (0.1.1)
|
25
29
|
coderay (1.0.9)
|
26
|
-
|
27
|
-
http (0.4.0)
|
28
|
-
certified
|
30
|
+
http (0.5.0)
|
29
31
|
http_parser.rb
|
30
|
-
http_parser.rb (0.
|
32
|
+
http_parser.rb (0.6.0.beta.2)
|
31
33
|
metaclass (0.0.1)
|
32
34
|
method_source (0.8.2)
|
33
35
|
minitest (5.0.6)
|
34
36
|
minitest-happy (1.0.0)
|
35
37
|
mocha (0.14.0)
|
36
38
|
metaclass (~> 0.0.1)
|
37
|
-
multi_json (1.
|
39
|
+
multi_json (1.8.1)
|
38
40
|
nio4r (0.5.0)
|
39
|
-
pi_piper (1.3.2)
|
40
|
-
ffi
|
41
41
|
pry (0.9.12.2)
|
42
42
|
coderay (~> 1.0.5)
|
43
43
|
method_source (~> 0.8)
|
44
44
|
slop (~> 3.4)
|
45
|
-
rack (1.5.2)
|
46
45
|
rake (10.1.0)
|
47
|
-
reel (0.4.0
|
48
|
-
celluloid
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
websocket_parser (>= 0.1.
|
46
|
+
reel (0.4.0)
|
47
|
+
celluloid (>= 0.15.1)
|
48
|
+
celluloid-io (>= 0.15.0)
|
49
|
+
http (>= 0.5.0)
|
50
|
+
http_parser.rb (>= 0.6.0.beta.2)
|
51
|
+
websocket_parser (>= 0.1.4)
|
53
52
|
slop (3.4.6)
|
54
53
|
thor (0.18.1)
|
55
54
|
timers (1.1.0)
|
@@ -61,6 +60,6 @@ PLATFORMS
|
|
61
60
|
|
62
61
|
DEPENDENCIES
|
63
62
|
artoo-raspi!
|
64
|
-
minitest (
|
63
|
+
minitest (>= 5.0)
|
65
64
|
minitest-happy
|
66
|
-
mocha (
|
65
|
+
mocha (>= 0.14.0)
|
data/README.md
CHANGED
@@ -6,8 +6,6 @@ Artoo is a open source micro-framework for robotics using Ruby.
|
|
6
6
|
|
7
7
|
For more information about Artoo, check out our repo at https://github.com/hybridgroup/artoo
|
8
8
|
|
9
|
-
This gem makes extensive us the the pi_piper gem (https://github.com/jwhitehorn/pi_piper) thanks to [@jwhitehorn](https://github.com/jwhitehorn)
|
10
|
-
|
11
9
|
[![Code Climate](https://codeclimate.com/github/hybridgroup/artoo-raspi.png)](https://codeclimate.com/github/hybridgroup/artoo-raspi) [![Build Status](https://travis-ci.org/hybridgroup/artoo-raspi.png?branch=master)](https://travis-ci.org/hybridgroup/artoo-raspi)
|
12
10
|
|
13
11
|
## Installing On Raspberry Pi
|
@@ -29,17 +27,18 @@ sudo gem install artoo-raspi
|
|
29
27
|
## Using
|
30
28
|
|
31
29
|
```ruby
|
32
|
-
require 'artoo'
|
33
|
-
|
34
30
|
connection :raspi, :adaptor => :raspi
|
35
|
-
device :
|
31
|
+
device :board, :driver => :device_info
|
32
|
+
device :led, :driver => :led, :pin => 17
|
36
33
|
|
37
34
|
work do
|
35
|
+
puts "Firmware name: #{board.firmware_name}"
|
36
|
+
puts "Firmata version: #{board.version}"
|
37
|
+
|
38
38
|
every 1.second do
|
39
39
|
led.toggle
|
40
40
|
end
|
41
41
|
end
|
42
|
-
|
43
42
|
```
|
44
43
|
|
45
44
|
To run the examples, requires sudo access on the Raspberry Pi:
|
@@ -48,6 +47,12 @@ To run the examples, requires sudo access on the Raspberry Pi:
|
|
48
47
|
sudo ruby examples/raspi_led.rb
|
49
48
|
```
|
50
49
|
|
50
|
+
## Devices supported
|
51
|
+
|
52
|
+
The following hardware devices have driver support via the artoo-gpio gem:
|
53
|
+
- Button
|
54
|
+
- LED
|
55
|
+
|
51
56
|
## Connecting to Raspberry Pi GPIO
|
52
57
|
|
53
58
|
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:
|
@@ -58,6 +63,27 @@ To add the button used in the example, add a momentary contact switch to the cir
|
|
58
63
|
|
59
64
|
![GPIO Switch Circuit Example](https://raw.github.com/jwhitehorn/pi_piper/master/examples/simple_switch/circuit.png)
|
60
65
|
|
66
|
+
## Enabling the Raspberry Pi i2c on raspbian
|
67
|
+
|
68
|
+
You must add these two entries in your `/etc/modules`
|
69
|
+
```
|
70
|
+
i2c-bcm2708
|
71
|
+
i2c-dev
|
72
|
+
```
|
73
|
+
You must also ensure that these entries are commented in your `/etc/modprobe.d/raspi-blacklist.conf`
|
74
|
+
```
|
75
|
+
#blacklist spi-bcm2708
|
76
|
+
#blacklist i2c-bcm2708
|
77
|
+
```
|
78
|
+
Now restart your raspberry pi.
|
79
|
+
|
80
|
+
## Enabling PWM output on GPIO pins.
|
81
|
+
|
82
|
+
You need to install and have pi-blaster running in the raspberry-pi,
|
83
|
+
you can follow the instructions for pi-blaster install on our repo here:
|
84
|
+
|
85
|
+
https://github.com/hybridgroup/pi-blaster
|
86
|
+
|
61
87
|
## Contributing
|
62
88
|
|
63
89
|
1. Fork it
|
data/artoo-raspi.gemspec
CHANGED
@@ -6,11 +6,11 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.name = "artoo-raspi"
|
7
7
|
s.version = Artoo::Raspi::VERSION
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
|
-
s.authors = ["Ron Evans"]
|
9
|
+
s.authors = ["Ron Evans", "Edgar Silva", "Adrian Zankich"]
|
10
10
|
s.email = ["artoo@hybridgroup.com"]
|
11
11
|
s.homepage = "https://github.com/hybridgroup/artoo-raspi"
|
12
|
-
s.summary = %q{Artoo adaptor
|
13
|
-
s.description = %q{Artoo adaptor
|
12
|
+
s.summary = %q{Artoo adaptor for Raspberry Pi}
|
13
|
+
s.description = %q{Artoo adaptor for Raspberry Pi}
|
14
14
|
s.license = 'Apache 2.0'
|
15
15
|
|
16
16
|
s.rubyforge_project = "artoo-raspi"
|
@@ -20,9 +20,10 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
21
|
s.require_paths = ["lib"]
|
22
22
|
|
23
|
-
s.add_runtime_dependency 'artoo', '
|
24
|
-
s.add_runtime_dependency '
|
25
|
-
s.
|
23
|
+
s.add_runtime_dependency 'artoo', '>= 1.3.0'
|
24
|
+
s.add_runtime_dependency 'artoo-gpio'
|
25
|
+
s.add_runtime_dependency 'artoo-i2c'
|
26
|
+
s.add_development_dependency 'minitest', '>= 5.0'
|
26
27
|
s.add_development_dependency 'minitest-happy'
|
27
|
-
s.add_development_dependency 'mocha', '
|
28
|
+
s.add_development_dependency 'mocha', '>= 0.14.0'
|
28
29
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'artoo'
|
2
|
+
|
3
|
+
connection :raspi, :adaptor => :raspi
|
4
|
+
device :board, :driver => :device_info
|
5
|
+
device :led, :driver => :led, :pin => 11
|
6
|
+
|
7
|
+
work do
|
8
|
+
puts "Firmware name: #{board.firmware_name}"
|
9
|
+
puts "Firmata version: #{board.version}"
|
10
|
+
|
11
|
+
every 1.second do
|
12
|
+
led.on? ? led.off : led.on
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'artoo'
|
2
|
+
|
3
|
+
connection :raspi, :adaptor => :raspi
|
4
|
+
device :board, :driver => :device_info
|
5
|
+
device :led, :driver => :led, :pin => 11
|
6
|
+
|
7
|
+
work do
|
8
|
+
puts "Firmware name: #{board.firmware_name}"
|
9
|
+
puts "Firmata version: #{board.version}"
|
10
|
+
|
11
|
+
every 1.second do
|
12
|
+
led.toggle
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'artoo'
|
2
|
+
|
3
|
+
connection :raspi, :adaptor => :raspi
|
4
|
+
device :led, :driver => :led, :pin => 11
|
5
|
+
device :button, :driver => :button, :pin => 12, :interval => 0.01
|
6
|
+
|
7
|
+
work do
|
8
|
+
puts
|
9
|
+
puts "Press the button connected on pin #{button.pin}..."
|
10
|
+
|
11
|
+
on button, :push => proc { led.on }
|
12
|
+
on button, :release => proc { led.off }
|
13
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'artoo'
|
2
|
+
|
3
|
+
connection :raspi, :adaptor => :raspi
|
4
|
+
device :board, :driver => :device_info
|
5
|
+
device :led, :driver => :led, :pin => 11
|
6
|
+
|
7
|
+
brightness = 0
|
8
|
+
fade_amount = 5
|
9
|
+
|
10
|
+
|
11
|
+
work do
|
12
|
+
puts "Firmware name: #{board.firmware_name}"
|
13
|
+
puts "Firmata version: #{board.version}"
|
14
|
+
|
15
|
+
every(0.05) do
|
16
|
+
led.brightness(brightness)
|
17
|
+
brightness = brightness + fade_amount
|
18
|
+
if brightness == 0 or brightness == 255
|
19
|
+
fade_amount = -fade_amount
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'artoo'
|
2
|
+
|
3
|
+
connection :raspi, :adaptor => :raspi
|
4
|
+
device :wiichuck, :driver => :wiichuck, :connection => :raspi, :interval => 0.01
|
5
|
+
|
6
|
+
work do
|
7
|
+
on wiichuck, :c_button => proc { puts "c button pressed!" }
|
8
|
+
on wiichuck, :z_button => proc { puts "z button pressed!" }
|
9
|
+
on wiichuck, :joystick => proc { |*value|
|
10
|
+
puts "joystick x: #{value[1][:x]}, y: #{value[1][:y]}"
|
11
|
+
}
|
12
|
+
end
|
data/lib/artoo-raspi/version.rb
CHANGED
data/lib/artoo/adaptors/raspi.rb
CHANGED
@@ -1,12 +1,35 @@
|
|
1
1
|
require 'artoo/adaptors/adaptor'
|
2
|
+
require 'artoo/adaptors/io'
|
3
|
+
require 'pwm_pin'
|
2
4
|
|
3
5
|
module Artoo
|
4
6
|
module Adaptors
|
5
7
|
# Connect to a Raspberry Pi GPIO
|
6
8
|
# @see device documentation for more information
|
7
9
|
class Raspi < Adaptor
|
10
|
+
include Artoo::Adaptors::IO
|
11
|
+
|
12
|
+
PINS = {
|
13
|
+
3 => {:rev1 => 0, :rev2 => 2},
|
14
|
+
5 => {:rev1 => 1, :rev2 => 3},
|
15
|
+
7 => 4,
|
16
|
+
8 => 14,
|
17
|
+
10 => 15,
|
18
|
+
11 => 17,
|
19
|
+
12 => 18,
|
20
|
+
13 => {:rev1 => 21, :rev2 => 27},
|
21
|
+
15 => 22,
|
22
|
+
16 => 23,
|
23
|
+
18 => 24,
|
24
|
+
19 => 10,
|
25
|
+
21 => 9,
|
26
|
+
22 => 25,
|
27
|
+
23 => 11,
|
28
|
+
24 => 8,
|
29
|
+
26 => 7,
|
30
|
+
}
|
8
31
|
finalizer :finalize
|
9
|
-
attr_reader :device
|
32
|
+
attr_reader :device, :pins, :pwm_pins, :i2c, :board_version
|
10
33
|
|
11
34
|
# Closes connection with device if connected
|
12
35
|
# @return [Boolean]
|
@@ -16,22 +39,113 @@ module Artoo
|
|
16
39
|
# Creates a connection with device
|
17
40
|
# @return [Boolean]
|
18
41
|
def connect
|
19
|
-
|
20
|
-
|
42
|
+
@pins = {} if @pins.nil?
|
43
|
+
@pwm_pins = {} if @pwm_pins.nil?
|
44
|
+
@board_version = `cat /proc/cpuinfo | grep Revision`.split.last.unpack("CCCC").last
|
21
45
|
super
|
22
46
|
end
|
23
47
|
|
24
48
|
# Closes connection with device
|
25
49
|
# @return [Boolean]
|
26
50
|
def disconnect
|
51
|
+
release_all_pwm_pins
|
27
52
|
super
|
28
53
|
end
|
29
54
|
|
55
|
+
def firmware_name
|
56
|
+
"Raspberry Pi"
|
57
|
+
end
|
58
|
+
|
59
|
+
def version
|
60
|
+
Artoo::Raspi::VERSION
|
61
|
+
end
|
62
|
+
|
63
|
+
#i2c
|
64
|
+
def i2c_start address
|
65
|
+
if @board_version >= 100
|
66
|
+
i2c_location = "/dev/i2c-1"
|
67
|
+
else
|
68
|
+
i2c_location = "/dev/i2c-0"
|
69
|
+
end
|
70
|
+
@i2c = I2c.new i2c_location, address
|
71
|
+
end
|
72
|
+
|
73
|
+
def i2c_write *data
|
74
|
+
@i2c.write *data
|
75
|
+
end
|
76
|
+
|
77
|
+
def i2c_read len
|
78
|
+
@i2c.read len
|
79
|
+
end
|
80
|
+
|
81
|
+
# GPIO - digital interface
|
82
|
+
def digital_read(pin)
|
83
|
+
release_pwm(pin) if (pwm_used? pin)
|
84
|
+
pin = raspi_pin(pin, "r")
|
85
|
+
pin.digital_read
|
86
|
+
end
|
87
|
+
|
88
|
+
def digital_write(pin, val)
|
89
|
+
release_pwm(pin) if (pwm_used? pin)
|
90
|
+
pin = raspi_pin(pin, "w")
|
91
|
+
pin.digital_write(val)
|
92
|
+
end
|
93
|
+
|
94
|
+
def pwm_write(pin, val)
|
95
|
+
pin = pwm_pin(pin)
|
96
|
+
pin.pwm_write(val)
|
97
|
+
end
|
98
|
+
|
99
|
+
def release_pwm(pin)
|
100
|
+
pin = translate_pin(pin)
|
101
|
+
pwm_pins[pin].release
|
102
|
+
pwm_pins[pin] = nil
|
103
|
+
end
|
104
|
+
|
105
|
+
def release_all_pwm_pins
|
106
|
+
pwm_pins.each_value { |pwm_pin| pwm_pin.release }
|
107
|
+
end
|
108
|
+
|
30
109
|
# Uses method missing to call device actions
|
31
110
|
# @see device documentation
|
32
111
|
def method_missing(method_name, *arguments, &block)
|
33
112
|
device.send(method_name, *arguments, &block)
|
34
113
|
end
|
114
|
+
|
115
|
+
private
|
116
|
+
|
117
|
+
def pwm_used?(pin)
|
118
|
+
(pwm_pins[translate_pin(pin)].nil?) ? false : true
|
119
|
+
end
|
120
|
+
|
121
|
+
def raspi_pin(pin, mode)
|
122
|
+
pin = translate_pin pin
|
123
|
+
pins[pin] = DigitalPin.new(pin, mode) if pins[pin].nil? || pins[pin].mode != mode
|
124
|
+
pins[pin]
|
125
|
+
end
|
126
|
+
|
127
|
+
def pwm_pin(pin)
|
128
|
+
pin = translate_pin(pin)
|
129
|
+
pwm_pins[pin] = PwmPin.new(pin) if pwm_pins[pin].nil?
|
130
|
+
pwm_pins[pin]
|
131
|
+
end
|
132
|
+
|
133
|
+
def translate_pin pin
|
134
|
+
begin
|
135
|
+
p = PINS.fetch(pin.to_i)
|
136
|
+
if p.class == Hash
|
137
|
+
if @board_version >= 54
|
138
|
+
return p[:rev2]
|
139
|
+
else
|
140
|
+
return p[:rev1]
|
141
|
+
end
|
142
|
+
else
|
143
|
+
return p
|
144
|
+
end
|
145
|
+
rescue Exception => e
|
146
|
+
raise "Not a valid pin"
|
147
|
+
end
|
148
|
+
end
|
35
149
|
end
|
36
150
|
end
|
37
151
|
end
|
data/lib/pwm_pin.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
class PwmPin
|
2
|
+
|
3
|
+
attr_reader :pin_num, :pwm_file, :value, :pb_val
|
4
|
+
|
5
|
+
PI_BLASTER_PATH = "/dev/pi-blaster"
|
6
|
+
|
7
|
+
def initialize(pin_num)
|
8
|
+
@pin_num = pin_num
|
9
|
+
@pwm_file = File.open("#{ PI_BLASTER_PATH }", "w")
|
10
|
+
|
11
|
+
pwm_write(0)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Writes PWM value to the specified pin
|
15
|
+
# Param value should be integer from 0 to 255
|
16
|
+
def pwm_write(value)
|
17
|
+
@value = value
|
18
|
+
|
19
|
+
# Calculates the pi-blaster required value between 0 and 1 inclusive
|
20
|
+
@pb_val = pi_blaster_val(value)
|
21
|
+
|
22
|
+
@pwm_file.write("#{ pin_num }=#{ @pb_val }\n")
|
23
|
+
@pwm_file.flush
|
24
|
+
end
|
25
|
+
|
26
|
+
def release
|
27
|
+
@pwm_file.write("release #{ pin_num }\n")
|
28
|
+
@pwm_file.flush
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def pi_blaster_val(value)
|
34
|
+
calc = ((1.0/255.0) * value).round(2)
|
35
|
+
calc = (calc > 1) ? 1 : calc
|
36
|
+
calc = (calc < 0) ? 0 : calc
|
37
|
+
calc
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -1,4 +1,30 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
|
2
2
|
require 'artoo/adaptors/raspi'
|
3
3
|
|
4
|
-
|
4
|
+
describe Artoo::Adaptors::Raspi do
|
5
|
+
before do
|
6
|
+
@adaptor = Artoo::Adaptors::Raspi.new
|
7
|
+
#@adaptor.stubs(:joystick).returns("joy")
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "device info interface" do
|
11
|
+
it "#firmware_name" do
|
12
|
+
@adaptor.firmware_name.must_equal "Raspberry Pi"
|
13
|
+
end
|
14
|
+
|
15
|
+
it "#version" do
|
16
|
+
@adaptor.version.must_equal Artoo::Raspi::VERSION
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "digital GPIO interface" do
|
21
|
+
it "#digital_read"
|
22
|
+
it "#digital_write"
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "i2c interface" do
|
26
|
+
it "#i2c_start"
|
27
|
+
it "#i2c_read"
|
28
|
+
it "#digital_write"
|
29
|
+
end
|
30
|
+
end
|
metadata
CHANGED
@@ -1,31 +1,47 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: artoo-raspi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ron Evans
|
8
|
+
- Edgar Silva
|
9
|
+
- Adrian Zankich
|
8
10
|
autorequire:
|
9
11
|
bindir: bin
|
10
12
|
cert_chain: []
|
11
|
-
date: 2013-
|
13
|
+
date: 2013-10-05 00:00:00.000000000 Z
|
12
14
|
dependencies:
|
13
15
|
- !ruby/object:Gem::Dependency
|
14
16
|
name: artoo
|
15
17
|
requirement: !ruby/object:Gem::Requirement
|
16
18
|
requirements:
|
17
|
-
- -
|
19
|
+
- - '>='
|
18
20
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
21
|
+
version: 1.3.0
|
20
22
|
type: :runtime
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
23
25
|
requirements:
|
24
|
-
- -
|
26
|
+
- - '>='
|
25
27
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.
|
28
|
+
version: 1.3.0
|
27
29
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
30
|
+
name: artoo-gpio
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
type: :runtime
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: artoo-i2c
|
29
45
|
requirement: !ruby/object:Gem::Requirement
|
30
46
|
requirements:
|
31
47
|
- - '>='
|
@@ -42,14 +58,14 @@ dependencies:
|
|
42
58
|
name: minitest
|
43
59
|
requirement: !ruby/object:Gem::Requirement
|
44
60
|
requirements:
|
45
|
-
- -
|
61
|
+
- - '>='
|
46
62
|
- !ruby/object:Gem::Version
|
47
63
|
version: '5.0'
|
48
64
|
type: :development
|
49
65
|
prerelease: false
|
50
66
|
version_requirements: !ruby/object:Gem::Requirement
|
51
67
|
requirements:
|
52
|
-
- -
|
68
|
+
- - '>='
|
53
69
|
- !ruby/object:Gem::Version
|
54
70
|
version: '5.0'
|
55
71
|
- !ruby/object:Gem::Dependency
|
@@ -70,17 +86,17 @@ dependencies:
|
|
70
86
|
name: mocha
|
71
87
|
requirement: !ruby/object:Gem::Requirement
|
72
88
|
requirements:
|
73
|
-
- -
|
89
|
+
- - '>='
|
74
90
|
- !ruby/object:Gem::Version
|
75
91
|
version: 0.14.0
|
76
92
|
type: :development
|
77
93
|
prerelease: false
|
78
94
|
version_requirements: !ruby/object:Gem::Requirement
|
79
95
|
requirements:
|
80
|
-
- -
|
96
|
+
- - '>='
|
81
97
|
- !ruby/object:Gem::Version
|
82
98
|
version: 0.14.0
|
83
|
-
description: Artoo adaptor
|
99
|
+
description: Artoo adaptor for Raspberry Pi
|
84
100
|
email:
|
85
101
|
- artoo@hybridgroup.com
|
86
102
|
executables: []
|
@@ -94,14 +110,16 @@ files:
|
|
94
110
|
- README.md
|
95
111
|
- Rakefile
|
96
112
|
- artoo-raspi.gemspec
|
97
|
-
- examples/
|
98
|
-
- examples/
|
113
|
+
- examples/blink_led.rb
|
114
|
+
- examples/blink_led_with_toggle.rb
|
115
|
+
- examples/button_and_led.rb
|
116
|
+
- examples/led_brightness.rb
|
117
|
+
- examples/wiichuck.rb
|
99
118
|
- lib/artoo-raspi.rb
|
100
119
|
- lib/artoo-raspi/version.rb
|
101
120
|
- lib/artoo/adaptors/raspi.rb
|
102
|
-
- lib/
|
121
|
+
- lib/pwm_pin.rb
|
103
122
|
- test/adaptors/raspi_adaptor_test.rb
|
104
|
-
- test/drivers/raspi_pin_driver_test.rb
|
105
123
|
- test/test_helper.rb
|
106
124
|
homepage: https://github.com/hybridgroup/artoo-raspi
|
107
125
|
licenses:
|
@@ -126,5 +144,5 @@ rubyforge_project: artoo-raspi
|
|
126
144
|
rubygems_version: 2.0.3
|
127
145
|
signing_key:
|
128
146
|
specification_version: 4
|
129
|
-
summary: Artoo adaptor
|
147
|
+
summary: Artoo adaptor for Raspberry Pi
|
130
148
|
test_files: []
|
data/examples/raspi_led.rb
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
require 'artoo/drivers/driver'
|
2
|
-
|
3
|
-
module Artoo
|
4
|
-
module Drivers
|
5
|
-
# Raspberry Pi pin driver behaviors
|
6
|
-
class RaspiPin < Driver
|
7
|
-
COMMANDS = [:is_on?, :on, :is_off?, :off, :toggle].freeze
|
8
|
-
|
9
|
-
attr_reader :raspi_pin, :direction, :value
|
10
|
-
|
11
|
-
def initialize(params={})
|
12
|
-
super
|
13
|
-
|
14
|
-
params[:additional_params] ||= {}
|
15
|
-
@direction = params[:additional_params][:direction] || :out
|
16
|
-
@value = false
|
17
|
-
|
18
|
-
@raspi_pin = ::PiPiper::Pin.new(:pin => pin, :direction => direction)
|
19
|
-
end
|
20
|
-
|
21
|
-
# Start driver and any required connections
|
22
|
-
def start_driver
|
23
|
-
begin
|
24
|
-
every(interval) do
|
25
|
-
handle_message_events
|
26
|
-
end
|
27
|
-
|
28
|
-
super
|
29
|
-
rescue Exception => e
|
30
|
-
Logger.error "Error starting Raspberry Pi pin driver!"
|
31
|
-
Logger.error e.message
|
32
|
-
Logger.error e.backtrace.inspect
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def handle_message_events
|
37
|
-
return if raspi_pin.nil?
|
38
|
-
raspi_pin.read
|
39
|
-
if raspi_pin.changed?
|
40
|
-
publish(event_topic_name(raspi_pin.value == 0 ? "push" : "release"))
|
41
|
-
publish(event_topic_name("update"), "pin", raspi_pin.value)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def toggle
|
46
|
-
is_off? ? on : off
|
47
|
-
end
|
48
|
-
|
49
|
-
def on
|
50
|
-
@value = true
|
51
|
-
raspi_pin.on
|
52
|
-
end
|
53
|
-
|
54
|
-
def is_on?
|
55
|
-
value == true
|
56
|
-
end
|
57
|
-
|
58
|
-
def off
|
59
|
-
@value = false
|
60
|
-
raspi_pin.off
|
61
|
-
end
|
62
|
-
|
63
|
-
def is_off?
|
64
|
-
!is_on?
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
|
2
|
-
require 'artoo/drivers/raspi_pin'
|
3
|
-
|
4
|
-
describe Artoo::Drivers::RaspiPin do
|
5
|
-
before do
|
6
|
-
@device = mock('device')
|
7
|
-
@pin = 17
|
8
|
-
@device.stubs(:pin).returns(@pin)
|
9
|
-
@connection = mock('connection')
|
10
|
-
@device.stubs(:connection).returns(@connection)
|
11
|
-
@pi_pin = mock('pin')
|
12
|
-
::PiPiper::Pin.stubs(:new).returns(@pi_pin)
|
13
|
-
@led = Artoo::Drivers::RaspiPin.new(:parent => @device)
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'RaspiPin#is_on?' do
|
17
|
-
@led.is_on?.must_equal false
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'RaspiPin#is_off?' do
|
21
|
-
@led.is_off?.must_equal true
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'RaspiPin#on' do
|
25
|
-
@pi_pin.expects(:on)
|
26
|
-
@led.on
|
27
|
-
@led.is_on?.must_equal true
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'RaspiPin#off' do
|
31
|
-
@pi_pin.expects(:off)
|
32
|
-
@led.off
|
33
|
-
@led.is_off?.must_equal true
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'RaspiPin#toggle' do
|
37
|
-
@pi_pin.expects(:on)
|
38
|
-
@pi_pin.expects(:off)
|
39
|
-
@led.is_off?.must_equal true
|
40
|
-
@led.toggle
|
41
|
-
@led.is_on?.must_equal true
|
42
|
-
@led.toggle
|
43
|
-
@led.is_off?.must_equal true
|
44
|
-
end
|
45
|
-
end
|