cgpio 0.1.0 → 0.1.1
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/Gemfile +0 -3
- data/README.md +36 -2
- data/cgpio.gemspec +2 -0
- data/ext/cgpio/cgpio.c +9 -9
- data/ext/cgpio/extconf.rb +5 -2
- data/lib/cgpio.rb +17 -54
- data/lib/cgpio/configuration.rb +7 -0
- data/lib/cgpio/gpio.rb +12 -0
- data/lib/cgpio/real_gpio.rb +55 -0
- data/lib/cgpio/version.rb +1 -1
- data/lib/cgpio/virtual_gpio.rb +53 -0
- metadata +22 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 35a8a5032424dc30fda2e8c0eb848e508cb3b9a5
|
|
4
|
+
data.tar.gz: 69606dbcb7728573176b25ef4a130cae028519a3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1087a17b35e4ec77e22c06db7651060258247a1affe00bae3fa149baf3c23b789a9a6ea93664a98214f45016cb4da30425805ff9383ca5efa69180692b1a1b21
|
|
7
|
+
data.tar.gz: d2c4343dd1ae15c68cf8627ea1b469b3c0ee6547328cdb006c1e4d804709c9a0ac2ee16076538017de26d86ed55ef45f3d33ae554bc129840a73d12daa54b587
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -2,13 +2,29 @@
|
|
|
2
2
|
|
|
3
3
|
A simple GPIO Wrapper in Ruby (which uses C to access the SYSFS structures)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
```ruby
|
|
6
|
+
require 'cgpio'
|
|
7
|
+
|
|
8
|
+
# switch on a led on port 48
|
|
9
|
+
led = Cgpio::Gpio.new(48)
|
|
10
|
+
led.on
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Tested with Linux-Kernel Version "4.1.6" on
|
|
14
|
+
* [Beaglebone Black](http://beagleboard.org/black)
|
|
15
|
+
* [Raspberry Pi Model B+](https://www.raspberrypi.org/products/model-b-plus/)
|
|
6
16
|
|
|
7
17
|
WARN: the gem is not stable yet!
|
|
8
18
|
|
|
9
19
|
## Features
|
|
10
20
|
* set/get value
|
|
11
21
|
* set/get direction
|
|
22
|
+
* virtual GPIO
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
```
|
|
26
|
+
gem install cgpio
|
|
27
|
+
```
|
|
12
28
|
|
|
13
29
|
## Usage
|
|
14
30
|
### Example
|
|
@@ -64,7 +80,6 @@ led.on
|
|
|
64
80
|
led.value = false
|
|
65
81
|
# or
|
|
66
82
|
led.off
|
|
67
|
-
|
|
68
83
|
```
|
|
69
84
|
|
|
70
85
|
### Read value of port
|
|
@@ -74,6 +89,25 @@ val = switch.on?
|
|
|
74
89
|
val = switch.off?
|
|
75
90
|
```
|
|
76
91
|
|
|
92
|
+
### Get static info about port
|
|
93
|
+
```ruby
|
|
94
|
+
# get port number
|
|
95
|
+
nr = port.nr
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Virtual GPIO
|
|
99
|
+
When you want to run your program on a hardware which don't have GPIO, you can
|
|
100
|
+
use virtual GPIOs.
|
|
101
|
+
|
|
102
|
+
For this you have to configure the Cgpio before you use it:
|
|
103
|
+
```ruby
|
|
104
|
+
# put this at the beginning of your program
|
|
105
|
+
Cgpio.configure do |config|
|
|
106
|
+
# use virtual gpio instead of real gpio
|
|
107
|
+
config.virtual = true
|
|
108
|
+
end
|
|
109
|
+
```
|
|
110
|
+
|
|
77
111
|
## License
|
|
78
112
|
|
|
79
113
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/cgpio.gemspec
CHANGED
|
@@ -19,7 +19,9 @@ Gem::Specification.new do |spec|
|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
20
20
|
spec.require_paths = ["lib"]
|
|
21
21
|
spec.extensions = %w[ext/cgpio/extconf.rb]
|
|
22
|
+
spec.required_ruby_version = '~> 2.2'
|
|
22
23
|
|
|
23
24
|
spec.add_development_dependency "bundler", "~> 1.10"
|
|
24
25
|
spec.add_development_dependency "rake", "~> 10.0"
|
|
26
|
+
spec.add_development_dependency "rake-compiler", "~> 0.9"
|
|
25
27
|
end
|
data/ext/cgpio/cgpio.c
CHANGED
|
@@ -126,18 +126,18 @@ void
|
|
|
126
126
|
Init_cgpio()
|
|
127
127
|
{
|
|
128
128
|
VALUE module_Cgpio;
|
|
129
|
-
VALUE
|
|
129
|
+
VALUE class_RealGpio;
|
|
130
130
|
|
|
131
131
|
// get module
|
|
132
132
|
module_Cgpio = rb_const_get(rb_cObject, rb_intern("Cgpio"));
|
|
133
133
|
|
|
134
134
|
// get class
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
rb_define_alloc_func(
|
|
138
|
-
rb_define_private_method(
|
|
139
|
-
rb_define_private_method(
|
|
140
|
-
rb_define_private_method(
|
|
141
|
-
rb_define_method(
|
|
142
|
-
rb_define_method(
|
|
135
|
+
class_RealGpio = rb_const_get(module_Cgpio, rb_intern("RealGpio"));
|
|
136
|
+
|
|
137
|
+
rb_define_alloc_func(class_RealGpio, cgpio_alloc);
|
|
138
|
+
rb_define_private_method(class_RealGpio, "setup", cgpio_setup, 1);
|
|
139
|
+
rb_define_private_method(class_RealGpio, "set_direction", cgpio_set_direction, 1);
|
|
140
|
+
rb_define_private_method(class_RealGpio, "get_direction", cgpio_get_direction, 0);
|
|
141
|
+
rb_define_method(class_RealGpio, "value=", cgpio_set_value, 1);
|
|
142
|
+
rb_define_method(class_RealGpio, "value", cgpio_get_value, 0);
|
|
143
143
|
}
|
data/ext/cgpio/extconf.rb
CHANGED
data/lib/cgpio.rb
CHANGED
|
@@ -1,61 +1,24 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'cgpio/version'
|
|
2
|
+
require 'cgpio/gpio'
|
|
3
|
+
require 'cgpio/configuration'
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
attr_reader :pin
|
|
7
|
-
|
|
8
|
-
def initialize(pin, options={})
|
|
9
|
-
options = {
|
|
10
|
-
direction: :out
|
|
11
|
-
}.merge(options)
|
|
12
|
-
|
|
13
|
-
@pin = pin
|
|
14
|
-
|
|
15
|
-
# this will export the pin
|
|
16
|
-
setup @pin
|
|
17
|
-
|
|
18
|
-
# set the initial direction
|
|
19
|
-
self.direction = options[:direction]
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def direction=(direction)
|
|
23
|
-
if direction == :out
|
|
24
|
-
# direction values defined in ext/cgpio/gpio.h
|
|
25
|
-
set_direction(0x01)
|
|
26
|
-
elsif direction == :in
|
|
27
|
-
set_direction(0x02)
|
|
28
|
-
else
|
|
29
|
-
raise "unsupported gpio direction. use :out or :in"
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def direction
|
|
34
|
-
if (get_direction == 0x01)
|
|
35
|
-
:out
|
|
36
|
-
elsif (get_direction == 0x02)
|
|
37
|
-
:in
|
|
38
|
-
else
|
|
39
|
-
raise "unknown gpio direction"
|
|
40
|
-
end
|
|
41
|
-
end
|
|
5
|
+
# include c extensions
|
|
6
|
+
require 'cgpio/cgpio'
|
|
42
7
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
8
|
+
module Cgpio
|
|
9
|
+
class << self
|
|
10
|
+
attr_accessor :configuration
|
|
11
|
+
end
|
|
46
12
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
13
|
+
def self.configuration
|
|
14
|
+
@configuration ||= Configuration.new
|
|
15
|
+
end
|
|
50
16
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
17
|
+
def self.reset
|
|
18
|
+
@configuration = Configuration.new
|
|
19
|
+
end
|
|
54
20
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
end
|
|
21
|
+
def self.configure
|
|
22
|
+
yield configuration
|
|
58
23
|
end
|
|
59
24
|
end
|
|
60
|
-
|
|
61
|
-
require 'cgpio/cgpio'
|
data/lib/cgpio/gpio.rb
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
class Cgpio::RealGpio
|
|
2
|
+
|
|
3
|
+
attr_reader :nr
|
|
4
|
+
|
|
5
|
+
def initialize(nr, options={})
|
|
6
|
+
options = {
|
|
7
|
+
direction: :out
|
|
8
|
+
}.merge(options)
|
|
9
|
+
|
|
10
|
+
@nr = nr
|
|
11
|
+
|
|
12
|
+
# this will export the pin
|
|
13
|
+
setup @nr
|
|
14
|
+
|
|
15
|
+
# set the initial direction
|
|
16
|
+
self.direction = options[:direction]
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def direction=(direction)
|
|
20
|
+
if direction == :out
|
|
21
|
+
# direction values defined in ext/cgpio/gpio.h
|
|
22
|
+
set_direction(0x01)
|
|
23
|
+
elsif direction == :in
|
|
24
|
+
set_direction(0x02)
|
|
25
|
+
else
|
|
26
|
+
raise "unsupported gpio direction. use :out or :in"
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def direction
|
|
31
|
+
if (get_direction == 0x01)
|
|
32
|
+
:out
|
|
33
|
+
elsif (get_direction == 0x02)
|
|
34
|
+
:in
|
|
35
|
+
else
|
|
36
|
+
raise "unknown gpio direction"
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def on
|
|
41
|
+
self.value = true
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def off
|
|
45
|
+
self.value = false
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def on?
|
|
49
|
+
self.value
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def off?
|
|
53
|
+
!self.value
|
|
54
|
+
end
|
|
55
|
+
end
|
data/lib/cgpio/version.rb
CHANGED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
class Cgpio::VirtualGpio
|
|
2
|
+
attr_reader :nr
|
|
3
|
+
|
|
4
|
+
def initialize(nr, options={})
|
|
5
|
+
options = {
|
|
6
|
+
direction: :out
|
|
7
|
+
}.merge(options)
|
|
8
|
+
|
|
9
|
+
@nr = nr
|
|
10
|
+
@value = false
|
|
11
|
+
|
|
12
|
+
# set the initial direction
|
|
13
|
+
self.direction = options[:direction]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def direction=(direction)
|
|
17
|
+
if direction == :out
|
|
18
|
+
@direction = 0x01
|
|
19
|
+
elsif direction == :in
|
|
20
|
+
@direction = 0x02
|
|
21
|
+
else
|
|
22
|
+
raise "unsupported gpio direction. use :out or :in"
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def value
|
|
27
|
+
@value
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def value=(val)
|
|
31
|
+
@value = val
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def direction
|
|
35
|
+
@direction
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def on
|
|
39
|
+
self.value = true
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def off
|
|
43
|
+
self.value = false
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def on?
|
|
47
|
+
value
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def off?
|
|
51
|
+
!value
|
|
52
|
+
end
|
|
53
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cgpio
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Maximilian Etti
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-08-
|
|
11
|
+
date: 2015-08-30 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -38,6 +38,20 @@ dependencies:
|
|
|
38
38
|
- - "~>"
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: '10.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rake-compiler
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0.9'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0.9'
|
|
41
55
|
description: A simple GPIO C Wrapper for Beaglebone Black.
|
|
42
56
|
email:
|
|
43
57
|
- maximilian_etti@yahoo.de
|
|
@@ -60,7 +74,11 @@ files:
|
|
|
60
74
|
- ext/cgpio/gpio.c
|
|
61
75
|
- ext/cgpio/gpio.h
|
|
62
76
|
- lib/cgpio.rb
|
|
77
|
+
- lib/cgpio/configuration.rb
|
|
78
|
+
- lib/cgpio/gpio.rb
|
|
79
|
+
- lib/cgpio/real_gpio.rb
|
|
63
80
|
- lib/cgpio/version.rb
|
|
81
|
+
- lib/cgpio/virtual_gpio.rb
|
|
64
82
|
homepage: http://github.com/metix/cgpio
|
|
65
83
|
licenses:
|
|
66
84
|
- MIT
|
|
@@ -71,9 +89,9 @@ require_paths:
|
|
|
71
89
|
- lib
|
|
72
90
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
73
91
|
requirements:
|
|
74
|
-
- - "
|
|
92
|
+
- - "~>"
|
|
75
93
|
- !ruby/object:Gem::Version
|
|
76
|
-
version: '
|
|
94
|
+
version: '2.2'
|
|
77
95
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
96
|
requirements:
|
|
79
97
|
- - ">="
|