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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: ecba9beae161bb3fdb27be8113b2274995d2ee13e3c12c3aed228e6b832f416a
4
- data.tar.gz: 4f4ef467a1729b7f0c40be973be147cc4d4d379553d2943b7f4d9512fbde70c0
2
+ SHA1:
3
+ metadata.gz: 77040ca234ecd31572765fe213728ddccc6f510b
4
+ data.tar.gz: 5f79acc2d383d214f238939b0f566ab81ed17d8f
5
5
  SHA512:
6
- metadata.gz: f31e693e896c1169ebb5bf384a79477a0054f3e15d0467328d6e1622f3ea8a77bf55c16337b5590bf4d2da137d6f89aa97421eb2a1739db4d7f60f07df936c6c
7
- data.tar.gz: 92397fdba753f798fc36c77023193dc56844e052972f69c9d867cb95f3ab7815356d991c7e3671197773f3b5a6c8727cbb06c1af9c9176dc3df8c92488cf8a01
6
+ metadata.gz: 44e73fa735f855c1fa49d0cd5a98e20ec0eeccfa276d7d26de4cad8d3a1e4e155e3d0e054d09cf994cd34c3bf8a996814921e2f3fcc440527faa46e48439dbfc
7
+ data.tar.gz: a2e366d12d9e592d9723bad44887b783feace6895573b8a498833465ec09febbc898eb4cc95775a9efd83a27cc4fbc87a6426a86a5fd7fa9c301982c45bee179
data/.gitignore CHANGED
@@ -8,4 +8,5 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  /*.gem
11
+ /private
11
12
  .idea
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 Output.
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
@@ -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
- def initialize(gpio_number)
8
- @gpio_number = gpio_number
9
- @value = 0
10
-
11
- if Omega2Gpio.configuration.mock and gpio_number.between?(0, Omega2Gpio.configuration.highest_gpio_number)
12
- Omega2Gpio.messenger.debug "Init Fake-GPIO#{@gpio_number} and mock all interactions as valid"
13
- else
14
- set_direction('output')
15
- end
16
-
17
- self
18
- end
19
-
20
- def self.is_mock?
21
- Omega2Gpio.configuration.mock
22
- end
23
-
24
- def set_direction(direction)
25
- execute_fast_gpio_command "fast-gpio set-#{direction} #{self.gpio_number}"
26
- end
27
-
28
- def read
29
- if Omega2Gpio.configuration.mock
30
- Omega2Gpio.messenger.debug "Mocked GPIO#{self.gpio_number} value is '#{@value}'"
31
- else
32
- stdin, stdout, stderr = Open3.popen3("fast-gpio read #{@gpio_number}")
33
- if stderr.gets
34
- raise_error(stderr.gets)
35
- else
36
- @value = stdout.gets.to_s.split.last.to_i
37
- end
38
- end
39
-
40
- @value
41
- end
42
-
43
- def get
44
- read
45
- end
46
-
47
- def is_high?
48
- self.read == 1
49
- end
50
-
51
- def is_low?
52
- self.read == 0
53
- end
54
-
55
- private
56
-
57
- def execute_fast_gpio_command(command)
58
- stdin, stdout, stderr = Open3.popen3(command)
59
- if stderr.gets
60
- Omega2Gpio.raise_error(stderr.gets)
61
- end
62
- end
63
- end
64
- end
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
@@ -1,5 +1,8 @@
1
- # coding: utf-8
2
- module Omega2Gpio
3
- class Input < Gpio
4
- end
1
+ # coding: utf-8
2
+ module Omega2Gpio
3
+ class Input < Gpio
4
+ def initialize(gpio_number)
5
+ super(gpio_number, "input")
6
+ end
7
+ end
5
8
  end
@@ -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
@@ -1,17 +1,29 @@
1
- # coding: utf-8
2
- module Omega2Gpio
3
- class Output < Gpio
4
-
5
- def set(value)
6
- if Omega2Gpio.configuration.mock
7
- Omega2Gpio.messenger.debug "Mocked GPIO#{self.gpio_number} is set to '#{value}'"
8
- else
9
- execute_fast_gpio_command "fast-gpio set #{self.gpio_number} #{value}"
10
- end
11
- @value = value
12
-
13
- self
14
- end
15
-
16
- end
17
- end
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
@@ -1,4 +1,4 @@
1
- # coding: utf-8
2
- module Omega2Gpio
3
- VERSION = "0.1.05".freeze
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.05
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: '0'
111
+ version: 1.3.1
112
112
  requirements: []
113
113
  rubyforge_project:
114
- rubygems_version: 2.7.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