onion_omega 0.1.0
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 +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +87 -0
- data/Rakefile +10 -0
- data/bin/console +11 -0
- data/bin/setup +8 -0
- data/lib/onion_omega.rb +7 -0
- data/lib/onion_omega/gpio.rb +21 -0
- data/lib/onion_omega/stepper.rb +67 -0
- data/lib/onion_omega/stepper_sequencer.rb +35 -0
- data/lib/onion_omega/version.rb +3 -0
- data/onion_omega.gemspec +27 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f9d2c0b9d8143d9dc99dd4a636a01d4a4261188e
|
4
|
+
data.tar.gz: d741dac4ef006fe7fa760054d914e0ccec5ab699
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e432c87f1e438d6074daa08cc4ef4bedbe2332f8fc7e0f4de79ab2870c356ed5fe7e7501c45592f329b5974e83f158e402f696c79552e338eb71fbfc0f661fc5
|
7
|
+
data.tar.gz: c73a9eff3adad498516ee21fa1f452b481da5e184daf0181abc0cfc012c548722fb17bf9b3b471eaac3fa6c23c50abf51c0a60f6e6168a3c9b8fadd89d9925dd
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Steve Occhipinti
|
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,87 @@
|
|
1
|
+
OnionOmega
|
2
|
+
==========
|
3
|
+
|
4
|
+
A Ruby wrapper for the `fast-gpio` command line tool found on the Onion Omega
|
5
|
+
base operating system.
|
6
|
+
|
7
|
+
This gem provides a basic `GPIO` class and a `Stepper` class that uses the GPIO
|
8
|
+
pins to drive a stepper motor.
|
9
|
+
|
10
|
+
|
11
|
+
Installation
|
12
|
+
------------
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'onion_omega'
|
18
|
+
```
|
19
|
+
|
20
|
+
And then execute `bundle`
|
21
|
+
|
22
|
+
|
23
|
+
Usage
|
24
|
+
-----
|
25
|
+
|
26
|
+
The `GPIO` class simply wraps the `fast-gpio` command line tool and has a
|
27
|
+
similar interface:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
gpio = OnionOmega::GPIO.new(dry_mode: false) # dry_mode defaults to false
|
31
|
+
gpio.set_output 0 # Sets pin 0 to be an output pin
|
32
|
+
gpio.set 0, 1 # Sets pin 0 to HIGH (on with 3v)
|
33
|
+
```
|
34
|
+
|
35
|
+
The `Stepper` class uses the GPIO class above to perform sequence of operations
|
36
|
+
to drive a stepper motor:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
stepper = OnionOmega::Stepper.new(
|
40
|
+
range: 1000, # Required. Used to calculate steps for percentage
|
41
|
+
pins: [0, 1, 2, 3], # Defaults. Which pins used to drive stepper motor
|
42
|
+
half_stepping: false, # Defaults. Whether to use full or half stepping
|
43
|
+
persist_to_file: nil, # Defaults. Persist position to file at every step
|
44
|
+
gpio: GPIO.new # Defaults. Allow GPIO object to be overridden
|
45
|
+
)
|
46
|
+
|
47
|
+
stepper.forward 1 # Defaults. Move forward 1 step
|
48
|
+
stepper.backward 1 # Defaults. Move backward 1 step
|
49
|
+
stepper.set_percentage 0.1 # Required. Move to percentage based on range
|
50
|
+
stepper.reset # Move to 0% based on current position and range
|
51
|
+
```
|
52
|
+
|
53
|
+
While `range` is a required parameter, it is only used for
|
54
|
+
`Stepper#set_percentage` and `Stepper#reset`.
|
55
|
+
|
56
|
+
The option to override the `GPIO` object is useful for testing to allow a `GPIO`
|
57
|
+
object that has `dry_mode` enabled to passed in which will only result in STDOUT
|
58
|
+
messages instead of actual commands being executed.
|
59
|
+
|
60
|
+
|
61
|
+
Development
|
62
|
+
-----------
|
63
|
+
|
64
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
65
|
+
`rake test` to run the tests. You can also run `bin/console` for an interactive
|
66
|
+
prompt that will allow you to experiment.
|
67
|
+
|
68
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To
|
69
|
+
release a new version, update the version number in `version.rb`, and then run
|
70
|
+
`bundle exec rake release`, which will create a git tag for the version, push
|
71
|
+
git commits and tags, and push the `.gem` file to
|
72
|
+
[rubygems.org](https://rubygems.org).
|
73
|
+
|
74
|
+
|
75
|
+
Contributing
|
76
|
+
------------
|
77
|
+
|
78
|
+
Bug reports and pull requests are welcome on GitHub at
|
79
|
+
https://github.com/stevenocchipinti/onion_omega.
|
80
|
+
|
81
|
+
|
82
|
+
License
|
83
|
+
-------
|
84
|
+
|
85
|
+
The gem is available as open source under the terms of the [MIT
|
86
|
+
License](http://opensource.org/licenses/MIT).
|
87
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "onion_omega"
|
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
|
data/bin/setup
ADDED
data/lib/onion_omega.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
class OnionOmega::GPIO
|
2
|
+
attr_accessor :dry_mode
|
3
|
+
|
4
|
+
def initialize(dry_mode: false)
|
5
|
+
@dry_mode = dry_mode
|
6
|
+
end
|
7
|
+
|
8
|
+
def set(pin, value)
|
9
|
+
execute "fast-gpio set #{pin} #{value}"
|
10
|
+
end
|
11
|
+
|
12
|
+
def set_output(pin)
|
13
|
+
execute "fast-gpio set-output #{pin}"
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def execute(command)
|
19
|
+
@dry_mode ? puts(command) : system(command)
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require_relative "./gpio"
|
2
|
+
require_relative "./stepper_sequencer"
|
3
|
+
|
4
|
+
module OnionOmega
|
5
|
+
class Stepper
|
6
|
+
def initialize(
|
7
|
+
range:,
|
8
|
+
pins: [0, 1, 2, 3],
|
9
|
+
half_stepping: false,
|
10
|
+
persist_to_file: nil,
|
11
|
+
gpio: GPIO.new
|
12
|
+
)
|
13
|
+
@range = range
|
14
|
+
@pins = pins
|
15
|
+
@sequencer = StepperSequencer.new(
|
16
|
+
number_of_pins: @pins.count,
|
17
|
+
half_stepping: half_stepping
|
18
|
+
)
|
19
|
+
@file = persist_to_file
|
20
|
+
@current_step = (@file && File.exists?(@file)) ? File.read(@file).to_i : 0
|
21
|
+
@gpio = gpio
|
22
|
+
initialise_gpio
|
23
|
+
end
|
24
|
+
|
25
|
+
def forward(steps=1)
|
26
|
+
steps.times { step(1) }
|
27
|
+
end
|
28
|
+
|
29
|
+
def backward(steps=1)
|
30
|
+
steps.times { step(-1) }
|
31
|
+
end
|
32
|
+
|
33
|
+
def set_percentage(percentage)
|
34
|
+
desired_step = (percentage * @range).round
|
35
|
+
steps = desired_step - @current_step
|
36
|
+
if steps > 0
|
37
|
+
steps.times { forward }
|
38
|
+
elsif steps < 0
|
39
|
+
steps.abs.times { backward }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def reset
|
44
|
+
set_percentage 0
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def initialise_gpio
|
50
|
+
@pins.each do |pin|
|
51
|
+
@gpio.set_output pin
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def step(increment = 1)
|
56
|
+
@current_step += increment
|
57
|
+
set_pins @sequencer.pins_for_step(@current_step)
|
58
|
+
File.write @file, @current_step if @file
|
59
|
+
end
|
60
|
+
|
61
|
+
def set_pins(pins)
|
62
|
+
pins.each_with_index do |value, index|
|
63
|
+
@gpio.set @pins[index], value
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module OnionOmega
|
2
|
+
class StepperSequencer
|
3
|
+
attr_accessor :number_of_pins, :half_stepping
|
4
|
+
|
5
|
+
def initialize(number_of_pins: 4, half_stepping: false)
|
6
|
+
@number_of_pins = number_of_pins
|
7
|
+
@half_stepping = half_stepping
|
8
|
+
end
|
9
|
+
|
10
|
+
def pins_for_step(step)
|
11
|
+
@half_stepping ? pins_for_half_step(step) : pins_for_full_step(step)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def pins_for_full_step(step)
|
17
|
+
@number_of_pins.times.map do |index|
|
18
|
+
phase = step % @number_of_pins
|
19
|
+
index == phase ? 1 : 0
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def pins_for_half_step(step)
|
24
|
+
phase = step % (@number_of_pins * 2)
|
25
|
+
@number_of_pins.times.map do |index|
|
26
|
+
case index * 2
|
27
|
+
when phase, phase - 1, (phase + 1) % (@number_of_pins * 2)
|
28
|
+
1
|
29
|
+
else
|
30
|
+
0
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/onion_omega.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'onion_omega/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "onion_omega"
|
8
|
+
spec.version = OnionOmega::VERSION
|
9
|
+
spec.authors = ["Steve Occhipinti"]
|
10
|
+
spec.email = ["dev@stevenocchipinti.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Control the Onion Omega GPIO pins with Ruby}
|
13
|
+
spec.homepage = "https://github.com/stevenocchipinti/onion-omega"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
26
|
+
spec.add_development_dependency "pry", "~> 0"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: onion_omega
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Steve Occhipinti
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-10-16 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.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
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: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- dev@stevenocchipinti.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".travis.yml"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- bin/console
|
83
|
+
- bin/setup
|
84
|
+
- lib/onion_omega.rb
|
85
|
+
- lib/onion_omega/gpio.rb
|
86
|
+
- lib/onion_omega/stepper.rb
|
87
|
+
- lib/onion_omega/stepper_sequencer.rb
|
88
|
+
- lib/onion_omega/version.rb
|
89
|
+
- onion_omega.gemspec
|
90
|
+
homepage: https://github.com/stevenocchipinti/onion-omega
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.6.13
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: Control the Onion Omega GPIO pins with Ruby
|
114
|
+
test_files: []
|