omega2_gpio 0.1.05 → 0.1.06.pre.alpha01
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.travis.yml +21 -21
- data/README.md +2 -2
- data/lib/omega2_gpio/configuration.rb +56 -56
- data/lib/omega2_gpio/fast_gpio_error.rb +8 -8
- data/lib/omega2_gpio/gpio.rb +76 -64
- data/lib/omega2_gpio/input.rb +7 -4
- data/lib/omega2_gpio/messaging.rb +15 -15
- data/lib/omega2_gpio/output.rb +29 -17
- data/lib/omega2_gpio/version.rb +4 -4
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 77040ca234ecd31572765fe213728ddccc6f510b
|
4
|
+
data.tar.gz: 5f79acc2d383d214f238939b0f566ab81ed17d8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44e73fa735f855c1fa49d0cd5a98e20ec0eeccfa276d7d26de4cad8d3a1e4e155e3d0e054d09cf994cd34c3bf8a996814921e2f3fcc440527faa46e48439dbfc
|
7
|
+
data.tar.gz: a2e366d12d9e592d9723bad44887b783feace6895573b8a498833465ec09febbc898eb4cc95775a9efd83a27cc4fbc87a6426a86a5fd7fa9c301982c45bee179
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
language: ruby
|
2
|
-
before_install: gem install bundler -v 1.11.2
|
3
|
-
|
4
|
-
rvm:
|
5
|
-
- 1.9
|
6
|
-
- 2.2.4
|
7
|
-
- 2.3
|
8
|
-
- 2.4
|
9
|
-
|
10
|
-
script: echo "Running tests against $(ruby -v) ..."
|
11
|
-
|
12
|
-
jobs:
|
13
|
-
include:
|
14
|
-
- stage: gem build
|
15
|
-
rvm: 2.2
|
16
|
-
script: echo "Deploying to rubygems.org ..."
|
17
|
-
deploy:
|
18
|
-
provider: rubygems
|
19
|
-
#gem: omega2_gpio
|
20
|
-
api_key: $RUBYGEMS_API_KEY
|
21
|
-
on:
|
1
|
+
language: ruby
|
2
|
+
before_install: gem install bundler -v 1.11.2
|
3
|
+
|
4
|
+
rvm:
|
5
|
+
- 1.9
|
6
|
+
- 2.2.4
|
7
|
+
- 2.3
|
8
|
+
- 2.4
|
9
|
+
|
10
|
+
script: echo "Running tests against $(ruby -v) ..."
|
11
|
+
|
12
|
+
jobs:
|
13
|
+
include:
|
14
|
+
- stage: gem build
|
15
|
+
rvm: 2.2
|
16
|
+
script: echo "Deploying to rubygems.org ..."
|
17
|
+
deploy:
|
18
|
+
provider: rubygems
|
19
|
+
#gem: omega2_gpio
|
20
|
+
api_key: $RUBYGEMS_API_KEY
|
21
|
+
on:
|
22
22
|
branch: master
|
data/README.md
CHANGED
@@ -21,9 +21,9 @@ Or install it yourself as:
|
|
21
21
|
|
22
22
|
## Get Started
|
23
23
|
An Omega2 GPIO can be
|
24
|
-
- an Input
|
24
|
+
- an Input
|
25
25
|
- an Output or
|
26
|
-
- a PWM
|
26
|
+
- a PWM-Output (not yet implemented in this Gem)
|
27
27
|
### Input GPIO
|
28
28
|
To use GPIO1 as an input, just instantiate an Omega2GPIO::Input using the `new`methode and pass in the number of the GPIO to use. (In this case 1 for GPIO1)
|
29
29
|
This will set the GPIO orientation to 'output'.
|
@@ -1,56 +1,56 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
module Omega2Gpio
|
3
|
-
class Configuration
|
4
|
-
|
5
|
-
# Controls whether the GPIO shall be controlled on Onion Omegas file system
|
6
|
-
# or just mocked/faked as valid to allow development on systems that
|
7
|
-
# do not support Omega's GPIO control and would raise errors constantly
|
8
|
-
# Defaults to `false`. Set to `true` to mock Onion Omega GPIO
|
9
|
-
attr_accessor :mock
|
10
|
-
|
11
|
-
# Controls whether the Gem shall write debug messages
|
12
|
-
# to standard out.
|
13
|
-
# This can be helpful messages like file system commands that are mocked
|
14
|
-
# Defaults to :debug.
|
15
|
-
# Defined are
|
16
|
-
# 2 ==> puts all messages
|
17
|
-
# 1 ==> puts warnings
|
18
|
-
# 0 ==> no messages at all
|
19
|
-
attr_accessor :messaging_level
|
20
|
-
|
21
|
-
# depends on Onion Omega2 hardware,
|
22
|
-
# needed to raise error in mock-mode
|
23
|
-
attr_accessor :highest_gpio_number
|
24
|
-
|
25
|
-
def initialize
|
26
|
-
@mock = false
|
27
|
-
@messaging_level = 2
|
28
|
-
@highest_gpio_number = 46
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
# @return [Omega2Gpio::Configuration] Omega2Gpio's current configuration
|
33
|
-
def self.configuration
|
34
|
-
@configuration ||= Configuration.new
|
35
|
-
end
|
36
|
-
|
37
|
-
## Set Omega2Gpio's configuration
|
38
|
-
## @param config [Omega2Gpio::Configuration]
|
39
|
-
def self.configuration=(config)
|
40
|
-
@configuration = config
|
41
|
-
end
|
42
|
-
|
43
|
-
# Modify Omega2Gpio's current configuration
|
44
|
-
# @yieldparam [Omega2Gpio::Configuration] config current Omega2Gpio config
|
45
|
-
# ```
|
46
|
-
# Omega2Gpio.configure do |config|
|
47
|
-
# config.routes = false
|
48
|
-
# end
|
49
|
-
# ```
|
50
|
-
def self.configure
|
51
|
-
yield configuration
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
# Configuration pattern stolen from Thoughtbot's Clearance
|
56
|
-
# https://github.com/thoughtbot/clearance/blob/master/lib/clearance/configuration.rb
|
1
|
+
# coding: utf-8
|
2
|
+
module Omega2Gpio
|
3
|
+
class Configuration
|
4
|
+
|
5
|
+
# Controls whether the GPIO shall be controlled on Onion Omegas file system
|
6
|
+
# or just mocked/faked as valid to allow development on systems that
|
7
|
+
# do not support Omega's GPIO control and would raise errors constantly
|
8
|
+
# Defaults to `false`. Set to `true` to mock Onion Omega GPIO
|
9
|
+
attr_accessor :mock
|
10
|
+
|
11
|
+
# Controls whether the Gem shall write debug messages
|
12
|
+
# to standard out.
|
13
|
+
# This can be helpful messages like file system commands that are mocked
|
14
|
+
# Defaults to :debug.
|
15
|
+
# Defined are
|
16
|
+
# 2 ==> puts all messages
|
17
|
+
# 1 ==> puts warnings
|
18
|
+
# 0 ==> no messages at all
|
19
|
+
attr_accessor :messaging_level
|
20
|
+
|
21
|
+
# depends on Onion Omega2 hardware,
|
22
|
+
# needed to raise error in mock-mode
|
23
|
+
attr_accessor :highest_gpio_number
|
24
|
+
|
25
|
+
def initialize
|
26
|
+
@mock = false
|
27
|
+
@messaging_level = 2
|
28
|
+
@highest_gpio_number = 46
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# @return [Omega2Gpio::Configuration] Omega2Gpio's current configuration
|
33
|
+
def self.configuration
|
34
|
+
@configuration ||= Configuration.new
|
35
|
+
end
|
36
|
+
|
37
|
+
## Set Omega2Gpio's configuration
|
38
|
+
## @param config [Omega2Gpio::Configuration]
|
39
|
+
def self.configuration=(config)
|
40
|
+
@configuration = config
|
41
|
+
end
|
42
|
+
|
43
|
+
# Modify Omega2Gpio's current configuration
|
44
|
+
# @yieldparam [Omega2Gpio::Configuration] config current Omega2Gpio config
|
45
|
+
# ```
|
46
|
+
# Omega2Gpio.configure do |config|
|
47
|
+
# config.routes = false
|
48
|
+
# end
|
49
|
+
# ```
|
50
|
+
def self.configure
|
51
|
+
yield configuration
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# Configuration pattern stolen from Thoughtbot's Clearance
|
56
|
+
# https://github.com/thoughtbot/clearance/blob/master/lib/clearance/configuration.rb
|
@@ -1,9 +1,9 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
module Omega2Gpio
|
3
|
-
class FastGpioError < StandardError
|
4
|
-
end
|
5
|
-
|
6
|
-
def raise_error(error)
|
7
|
-
raise(FastGpioError, error.message)
|
8
|
-
end
|
1
|
+
# coding: utf-8
|
2
|
+
module Omega2Gpio
|
3
|
+
class FastGpioError < StandardError
|
4
|
+
end
|
5
|
+
|
6
|
+
def raise_error(error)
|
7
|
+
raise(FastGpioError, error.message)
|
8
|
+
end
|
9
9
|
end
|
data/lib/omega2_gpio/gpio.rb
CHANGED
@@ -1,64 +1,76 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
module Omega2Gpio
|
3
|
-
class Gpio
|
4
|
-
attr_reader :gpio_number
|
5
|
-
attr_reader :value
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
@
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
def
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
def read
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
1
|
+
# coding: utf-8
|
2
|
+
module Omega2Gpio
|
3
|
+
class Gpio
|
4
|
+
attr_reader :gpio_number
|
5
|
+
attr_reader :value
|
6
|
+
attr_reader :direction
|
7
|
+
|
8
|
+
def initialize(gpio_number, direction)
|
9
|
+
@gpio_number = gpio_number
|
10
|
+
@value = 0
|
11
|
+
@direction = direction
|
12
|
+
|
13
|
+
command = "fast-gpio set-#{direction} #{self.gpio_number}"
|
14
|
+
if Omega2Gpio.configuration.mock && gpio_number.between?(0, Omega2Gpio.configuration.highest_gpio_number)
|
15
|
+
Omega2Gpio.messenger.debug "Init Fake-GPIO#{@gpio_number} and mock all interactions as valid"
|
16
|
+
mock_fast_gpio_command command
|
17
|
+
else
|
18
|
+
execute_fast_gpio_command command
|
19
|
+
end
|
20
|
+
|
21
|
+
self
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.is_mock?
|
25
|
+
Omega2Gpio.configuration.mock
|
26
|
+
end
|
27
|
+
|
28
|
+
def read
|
29
|
+
command = "fast-gpio read #{@gpio_number}"
|
30
|
+
if Omega2Gpio.configuration.mock
|
31
|
+
mock_fast_gpio_command command
|
32
|
+
else
|
33
|
+
stdout = execute_fast_gpio_command command
|
34
|
+
@value = stdout.gets.to_s.split.last.to_i
|
35
|
+
end
|
36
|
+
|
37
|
+
@value
|
38
|
+
end
|
39
|
+
|
40
|
+
def get
|
41
|
+
read
|
42
|
+
end
|
43
|
+
|
44
|
+
def is_high?
|
45
|
+
read == 1
|
46
|
+
end
|
47
|
+
|
48
|
+
def high?
|
49
|
+
is_high?
|
50
|
+
end
|
51
|
+
|
52
|
+
def is_low?
|
53
|
+
read == 0
|
54
|
+
end
|
55
|
+
|
56
|
+
def low?
|
57
|
+
is_low?
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def execute_fast_gpio_command(command)
|
63
|
+
stdin, stdout, stderr = Open3.popen3(command)
|
64
|
+
if stderr.gets
|
65
|
+
Omega2Gpio.raise_error(stderr.gets)
|
66
|
+
end
|
67
|
+
Omega2Gpio.messenger.debug "System command: #{command}"
|
68
|
+
Omega2Gpio.messenger.debug " returns: #{stdout}"
|
69
|
+
stdout
|
70
|
+
end
|
71
|
+
|
72
|
+
def mock_fast_gpio_command(command)
|
73
|
+
Omega2Gpio.messenger.debug "Mock command: #{command}"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/lib/omega2_gpio/input.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
module Omega2Gpio
|
3
|
-
class Messaging
|
4
|
-
def debug(message)
|
5
|
-
puts message if Omega2Gpio.configuration.messaging_level >= 2
|
6
|
-
end
|
7
|
-
|
8
|
-
def warn(message)
|
9
|
-
puts message if Omega2Gpio.configuration.messaging_level >= 1
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.messenger
|
14
|
-
@messenger ||= Messaging.new
|
15
|
-
end
|
1
|
+
# coding: utf-8
|
2
|
+
module Omega2Gpio
|
3
|
+
class Messaging
|
4
|
+
def debug(message)
|
5
|
+
puts message if Omega2Gpio.configuration.messaging_level >= 2
|
6
|
+
end
|
7
|
+
|
8
|
+
def warn(message)
|
9
|
+
puts message if Omega2Gpio.configuration.messaging_level >= 1
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.messenger
|
14
|
+
@messenger ||= Messaging.new
|
15
|
+
end
|
16
16
|
end
|
data/lib/omega2_gpio/output.rb
CHANGED
@@ -1,17 +1,29 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
module Omega2Gpio
|
3
|
-
class Output < Gpio
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
1
|
+
# coding: utf-8
|
2
|
+
module Omega2Gpio
|
3
|
+
class Output < Gpio
|
4
|
+
def initialize(gpio_number)
|
5
|
+
super(gpio_number, "output")
|
6
|
+
end
|
7
|
+
|
8
|
+
def set(value)
|
9
|
+
command = "fast-gpio set #{self.gpio_number} #{value}"
|
10
|
+
if Omega2Gpio.configuration.mock
|
11
|
+
mock_fast_gpio_command command
|
12
|
+
else
|
13
|
+
execute_fast_gpio_command command
|
14
|
+
end
|
15
|
+
@value = value
|
16
|
+
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
def high
|
21
|
+
set(1)
|
22
|
+
end
|
23
|
+
|
24
|
+
def low
|
25
|
+
set(0)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
data/lib/omega2_gpio/version.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
module Omega2Gpio
|
3
|
-
VERSION = "0.1.
|
4
|
-
end
|
1
|
+
# coding: utf-8
|
2
|
+
module Omega2Gpio
|
3
|
+
VERSION = "0.1.06-alpha01".freeze
|
4
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omega2_gpio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.06.pre.alpha01
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sönke Ohls
|
@@ -106,12 +106,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
106
106
|
version: '0'
|
107
107
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
108
|
requirements:
|
109
|
-
- - "
|
109
|
+
- - ">"
|
110
110
|
- !ruby/object:Gem::Version
|
111
|
-
version:
|
111
|
+
version: 1.3.1
|
112
112
|
requirements: []
|
113
113
|
rubyforge_project:
|
114
|
-
rubygems_version: 2.
|
114
|
+
rubygems_version: 2.6.3
|
115
115
|
signing_key:
|
116
116
|
specification_version: 4
|
117
117
|
summary: Ruby wrapper to control Onion Omega2 GPIOs
|