omega2_gpio 0.1.05

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ecba9beae161bb3fdb27be8113b2274995d2ee13e3c12c3aed228e6b832f416a
4
+ data.tar.gz: 4f4ef467a1729b7f0c40be973be147cc4d4d379553d2943b7f4d9512fbde70c0
5
+ SHA512:
6
+ metadata.gz: f31e693e896c1169ebb5bf384a79477a0054f3e15d0467328d6e1622f3ea8a77bf55c16337b5590bf4d2da137d6f89aa97421eb2a1739db4d7f60f07df936c6c
7
+ data.tar.gz: 92397fdba753f798fc36c77023193dc56844e052972f69c9d867cb95f3ab7815356d991c7e3671197773f3b5a6c8727cbb06c1af9c9176dc3df8c92488cf8a01
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /*.gem
11
+ .idea
data/.travis.yml ADDED
@@ -0,0 +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:
22
+ branch: master
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at freizeitnerd@googlemail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omega2_gpio.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 freizeitnerd
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # Ruby Gem to control Omega2 GPIO
2
+
3
+ Control [Onion Omega2](https://onion.io/omega2/) GPIOs in ruby
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'omega2_gpio'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install omega2_gpio
20
+
21
+
22
+ ## Get Started
23
+ An Omega2 GPIO can be
24
+ - an Input,
25
+ - an Output or
26
+ - a PWM Output.
27
+ ### Input GPIO
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
+ This will set the GPIO orientation to 'output'.
30
+ ```ruby
31
+ gpio_number = 1
32
+ my_input_gpio = Omega2Gpio::Output.new(gpio_number)
33
+ ```
34
+ Read the value of this GPIO as follows
35
+ ```ruby
36
+ my_input_gpio_value = my_input_gpio.read
37
+ ```
38
+
39
+ ## Usage
40
+
41
+ TODO: Write usage instructions here
42
+
43
+
44
+ ## Contributing
45
+
46
+ Bug reports and pull requests are welcome! This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
47
+
48
+
49
+ ## License
50
+
51
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
52
+
53
+ ## Similar Gems
54
+ [@stevenocchipinti's onion_omega](https://github.com/stevenocchipinti/onion_omega) uses a slightly different approach to include GPIO control. It even supports stepper motors.
55
+ https://github.com/stevenocchipinti/onion_omega
56
+
57
+ [@glurp's ruby-onion-omega2](https://github.com/glurp/ruby-onion-omega2)
58
+ https://github.com/glurp/ruby-onion-omega2 uses Omega2 file system instead of fast-gpio to control GPIO's. It even allows PWM and OLED access.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "omega2_gpio"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +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
@@ -0,0 +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
9
+ end
@@ -0,0 +1,64 @@
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
@@ -0,0 +1,5 @@
1
+ # coding: utf-8
2
+ module Omega2Gpio
3
+ class Input < Gpio
4
+ end
5
+ end
@@ -0,0 +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
16
+ end
@@ -0,0 +1,17 @@
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
@@ -0,0 +1,4 @@
1
+ # coding: utf-8
2
+ module Omega2Gpio
3
+ VERSION = "0.1.05".freeze
4
+ end
@@ -0,0 +1,11 @@
1
+ require "open3"
2
+ require_relative "omega2_gpio/fast_gpio_error"
3
+ require_relative "omega2_gpio/version"
4
+ require_relative "omega2_gpio/configuration"
5
+ require_relative "omega2_gpio/messaging"
6
+ require_relative "omega2_gpio/gpio"
7
+ require_relative "omega2_gpio/input"
8
+ require_relative "omega2_gpio/output"
9
+
10
+ module Omega2Gpio
11
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'omega2_gpio/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "omega2_gpio"
8
+ spec.version = Omega2Gpio::VERSION
9
+ spec.authors = ["Sönke Ohls"]
10
+ spec.email = ["s@ohls.eu"]
11
+
12
+ spec.summary = "Ruby wrapper to control Onion Omega2 GPIOs"
13
+ spec.description = "Ruby wrapper to control Onion Omega2 GPIOs"
14
+ spec.homepage = "https://github.com/freizeitnerd/omega2_gpio"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.11"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "minitest", "~> 5.0"
25
+ spec.add_development_dependency "minitest-hooks", "~> 1.4"
26
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omega2_gpio
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.05
5
+ platform: ruby
6
+ authors:
7
+ - Sönke Ohls
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-11-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest-hooks
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.4'
69
+ description: Ruby wrapper to control Onion Omega2 GPIOs
70
+ email:
71
+ - s@ohls.eu
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - CODE_OF_CONDUCT.md
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - lib/omega2_gpio.rb
86
+ - lib/omega2_gpio/configuration.rb
87
+ - lib/omega2_gpio/fast_gpio_error.rb
88
+ - lib/omega2_gpio/gpio.rb
89
+ - lib/omega2_gpio/input.rb
90
+ - lib/omega2_gpio/messaging.rb
91
+ - lib/omega2_gpio/output.rb
92
+ - lib/omega2_gpio/version.rb
93
+ - omega2_gpio.gemspec
94
+ homepage: https://github.com/freizeitnerd/omega2_gpio
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.7.2
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Ruby wrapper to control Onion Omega2 GPIOs
118
+ test_files: []