ruby_pins 0.1.1 → 0.1.2
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.
- checksums.yaml +4 -4
- data/.byebug_history +4 -0
- data/README.md +49 -5
- data/lib/.byebug_history +12 -0
- data/lib/ruby_pins/host.rb +12 -0
- data/lib/ruby_pins/pin.rb +79 -0
- data/lib/ruby_pins/version.rb +1 -1
- data/lib/ruby_pins.rb +5 -66
- data/ruby_pins.gemspec +10 -9
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7e272be6fcee3162904989970bb34925ddd8d83
|
4
|
+
data.tar.gz: eba0917f3a811475a6661c6b82480abdf24b9080
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76eba6e2779cf371d9aa1e5f49558071fac48ef61296a25e340455496611acf16bb0a6aae728b6a825c5912f45d460e68cdb020db7f12715e1e62d3c9cda426d
|
7
|
+
data.tar.gz: 72e5cd4d2486f81d804c1f55feeca07071d945f61fd9a7575061b7e44cb92a52ca0283a6b64528a6198d8d0b83d2232a58e586a232f88a807f14be5e326d8c7b
|
data/.byebug_history
ADDED
data/README.md
CHANGED
@@ -22,14 +22,48 @@ to your Gemfile, and run
|
|
22
22
|
bundle
|
23
23
|
```
|
24
24
|
|
25
|
-
|
25
|
+
# Usage
|
26
|
+
|
27
|
+
## Basic pin
|
26
28
|
|
27
29
|
Create a new pin:
|
28
30
|
|
29
31
|
```ruby
|
30
|
-
#
|
31
|
-
#
|
32
|
-
|
32
|
+
# Pins accept a pin #, a state (:on, :off), a name, and a host.
|
33
|
+
# If you running the code on the PI itself, the pin just needs a pin number!
|
34
|
+
# The default state is off
|
35
|
+
pin = RubyPins::Pin.new pin: 17
|
36
|
+
```
|
37
|
+
|
38
|
+
Turn the pin on:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
pin.on
|
42
|
+
```
|
43
|
+
|
44
|
+
Turn the pin off:
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
pin.off
|
48
|
+
```
|
49
|
+
|
50
|
+
## Remote pin
|
51
|
+
|
52
|
+
Say what? You wanna control a Pi on your network, but run the code from a different computer?
|
53
|
+
ruby_pins has you covered!
|
54
|
+
|
55
|
+
Create a host:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
pi_host = RubyPins::Host.new address: <ip_address>,
|
59
|
+
user: <unix_user(probably 'pi')>,
|
60
|
+
password: <unix password>
|
61
|
+
```
|
62
|
+
|
63
|
+
Add this host to your pin
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
pin.host = pi_host
|
33
67
|
```
|
34
68
|
|
35
69
|
Turn the pin on:
|
@@ -46,6 +80,17 @@ pin.off
|
|
46
80
|
|
47
81
|
Now rewire your whole house to be interfaced from your Ruby app!
|
48
82
|
|
83
|
+
## Note about pin numbers
|
84
|
+
|
85
|
+
ruby_pins expects the pin number to be the pin's GPIO number.
|
86
|
+
For example, when looking at the following pinout chart, if you wanted to
|
87
|
+
set your pin number to the 11th pin, or GPIO17, you would pass in
|
88
|
+
```ruby
|
89
|
+
pin: 17
|
90
|
+
```
|
91
|
+
Pinout chart:
|
92
|
+
https://www.element14.com/community/servlet/JiveServlet/previewBody/73950-102-10-339300/pi3_gpio.png
|
93
|
+
|
49
94
|
## Installing Ruby (and Rails)
|
50
95
|
|
51
96
|
This is the guide I use to install Ruby and Ruby on Rails on my Pis:
|
@@ -61,4 +106,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERN
|
|
61
106
|
## License
|
62
107
|
|
63
108
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
64
|
-
|
data/lib/.byebug_history
CHANGED
@@ -0,0 +1,79 @@
|
|
1
|
+
module RubyPins
|
2
|
+
|
3
|
+
class Pin
|
4
|
+
attr_accessor :pin, :name, :state, :pinset, :host
|
5
|
+
|
6
|
+
def initialize args
|
7
|
+
args.each {|k, v| self.send "#{k}=", v}
|
8
|
+
self.state= :off unless self.state
|
9
|
+
self.host ||= :local
|
10
|
+
end
|
11
|
+
|
12
|
+
def state= state
|
13
|
+
self.send state
|
14
|
+
end
|
15
|
+
|
16
|
+
def pin= pin
|
17
|
+
unexport if self.pin
|
18
|
+
@pin = pin
|
19
|
+
end
|
20
|
+
|
21
|
+
def on
|
22
|
+
@state = :on
|
23
|
+
run export, set_out, turn_on
|
24
|
+
end
|
25
|
+
|
26
|
+
def off
|
27
|
+
@state = :off
|
28
|
+
run(unexport) if exported?
|
29
|
+
end
|
30
|
+
|
31
|
+
def run *commands
|
32
|
+
std_out = ''
|
33
|
+
if host == :local
|
34
|
+
commands.each {|cmd| std_out << %x(#{cmd})}
|
35
|
+
else
|
36
|
+
commands.each do |cmd|
|
37
|
+
Net::SSH.start(self.host.address, self.host.user, password: self.host.password) do |ssh|
|
38
|
+
std_out << ssh.exec!(cmd)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
std_out
|
43
|
+
end
|
44
|
+
|
45
|
+
def turn_on
|
46
|
+
set_value 1
|
47
|
+
end
|
48
|
+
|
49
|
+
def set_out
|
50
|
+
set_direction 'out'
|
51
|
+
end
|
52
|
+
|
53
|
+
def send_in
|
54
|
+
set_direction 'in'
|
55
|
+
end
|
56
|
+
|
57
|
+
def set_direction dir
|
58
|
+
"echo #{dir} > /sys/class/gpio/gpio#{self.pin}/direction"
|
59
|
+
end
|
60
|
+
|
61
|
+
def set_value val
|
62
|
+
"echo #{val} > /sys/class/gpio/gpio#{self.pin}/value"
|
63
|
+
end
|
64
|
+
|
65
|
+
def export
|
66
|
+
"echo #{self.pin} > /sys/class/gpio/export"
|
67
|
+
end
|
68
|
+
|
69
|
+
def unexport
|
70
|
+
"echo #{self.pin} > /sys/class/gpio/unexport"
|
71
|
+
end
|
72
|
+
|
73
|
+
def exported?
|
74
|
+
run("ls /sys/class/gpio/").include? "#{self.pin}"
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
data/lib/ruby_pins/version.rb
CHANGED
data/lib/ruby_pins.rb
CHANGED
@@ -1,70 +1,9 @@
|
|
1
|
-
require
|
1
|
+
require 'ruby_pins/version'
|
2
|
+
require 'ruby_pins/pin'
|
3
|
+
require 'ruby_pins/host'
|
4
|
+
require 'net/ssh'
|
5
|
+
require 'byebug'
|
2
6
|
|
3
7
|
module RubyPins
|
4
8
|
|
5
|
-
class Pin
|
6
|
-
attr_accessor :pin, :name, :state
|
7
|
-
|
8
|
-
def initialize args
|
9
|
-
args.each {|k, v| self.send "#{k}=", v}
|
10
|
-
self.state= :off unless self.state
|
11
|
-
end
|
12
|
-
|
13
|
-
def state= state
|
14
|
-
self.send state
|
15
|
-
end
|
16
|
-
|
17
|
-
def pin= pin
|
18
|
-
unexport if self.pin
|
19
|
-
@pin = pin
|
20
|
-
end
|
21
|
-
|
22
|
-
def on
|
23
|
-
@state = :on
|
24
|
-
export
|
25
|
-
set_out
|
26
|
-
turn_on
|
27
|
-
end
|
28
|
-
|
29
|
-
def off
|
30
|
-
@state = :off
|
31
|
-
unexport if exported?
|
32
|
-
end
|
33
|
-
|
34
|
-
def turn_on
|
35
|
-
set_value 1
|
36
|
-
end
|
37
|
-
|
38
|
-
def set_out
|
39
|
-
set_direction 'out'
|
40
|
-
end
|
41
|
-
|
42
|
-
def send_in
|
43
|
-
set_direction 'in'
|
44
|
-
end
|
45
|
-
|
46
|
-
def set_direction dir
|
47
|
-
`echo #{dir} > /sys/class/gpio/gpio#{self.pin}/direction`
|
48
|
-
end
|
49
|
-
|
50
|
-
def set_value val
|
51
|
-
`echo #{val} > /sys/class/gpio/gpio#{self.pin}/value`
|
52
|
-
end
|
53
|
-
|
54
|
-
def export
|
55
|
-
`echo #{self.pin} > /sys/class/gpio/export`
|
56
|
-
end
|
57
|
-
|
58
|
-
def unexport
|
59
|
-
`echo #{self.pin} > /sys/class/gpio/unexport`
|
60
|
-
end
|
61
|
-
|
62
|
-
def exported?
|
63
|
-
File.directory? "/sys/class/gpio/gpio#{self.pin}"
|
64
|
-
end
|
65
|
-
|
66
|
-
end
|
67
|
-
|
68
9
|
end
|
69
|
-
|
70
|
-
|
data/ruby_pins.gemspec
CHANGED
@@ -4,22 +4,23 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'ruby_pins/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'ruby_pins'
|
8
8
|
spec.version = RubyPins::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['MainShayne233']
|
10
|
+
spec.email = ['shaynetremblay@hotmail.com']
|
11
11
|
|
12
12
|
spec.summary = "Ridiculously simple way to interact with your Raspberry Pi's GPIO pins, with Ruby!"
|
13
13
|
spec.homepage = 'https://github.com/MainShayne233/ruby_pins'
|
14
|
-
spec.license =
|
14
|
+
spec.license = 'MIT'
|
15
15
|
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
-
spec.bindir =
|
18
|
+
spec.bindir = 'exe'
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
-
spec.require_paths = [
|
20
|
+
spec.require_paths = ['lib']
|
21
21
|
|
22
|
-
spec.add_development_dependency
|
23
|
-
spec.add_development_dependency
|
24
|
-
spec.add_development_dependency
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
25
|
+
spec.add_dependency 'net-ssh', '~> 3.2'
|
25
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_pins
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MainShayne233
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: net-ssh
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.2'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.2'
|
55
69
|
description:
|
56
70
|
email:
|
57
71
|
- shaynetremblay@hotmail.com
|
@@ -59,6 +73,7 @@ executables: []
|
|
59
73
|
extensions: []
|
60
74
|
extra_rdoc_files: []
|
61
75
|
files:
|
76
|
+
- ".byebug_history"
|
62
77
|
- ".gitignore"
|
63
78
|
- ".rspec"
|
64
79
|
- ".travis.yml"
|
@@ -71,6 +86,8 @@ files:
|
|
71
86
|
- bin/setup
|
72
87
|
- lib/.byebug_history
|
73
88
|
- lib/ruby_pins.rb
|
89
|
+
- lib/ruby_pins/host.rb
|
90
|
+
- lib/ruby_pins/pin.rb
|
74
91
|
- lib/ruby_pins/version.rb
|
75
92
|
- ruby_pins.gemspec
|
76
93
|
homepage: https://github.com/MainShayne233/ruby_pins
|