adafruit-servo-driver 0.0.1 → 0.0.2
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/.rspec +2 -0
- data/CHANGELOG.md +3 -0
- data/README.md +3 -3
- data/Rakefile +4 -0
- data/adafruit-servo-driver.gemspec +1 -0
- data/lib/adafruit-servo-driver.rb +1 -0
- data/lib/adafruit-servo-driver/i2c_device.rb +23 -0
- data/lib/adafruit-servo-driver/pwm.rb +2 -2
- data/lib/adafruit-servo-driver/version.rb +1 -1
- data/spec/i2c_device_spec.rb +35 -0
- data/spec/spec_helper.rb +75 -0
- metadata +24 -4
- data/example.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f74b96f6805c6533645bb75ac04113d8aafe27f
|
4
|
+
data.tar.gz: 1d4b2532f6b03812ed5a304fae226a0b857e3feb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6aae41cd0482e3716c9494095e83a4272b77c861cd1b2f55c958b320b4377a0c799c5262faf2a604639297014c13b3ebb2e289bd954782bb3618d640ecb8499f
|
7
|
+
data.tar.gz: ee66e655f45e7bad754ad0c4954c960baece4763987f32fcb03ddcf67b64bbaf63c1b389536f01ac3c131196f37e193182ffa8b4db4eabd12f1b852ab7b4e3c8
|
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -17,14 +17,14 @@ gem install adafruit-servo-driver
|
|
17
17
|
require 'adafruit-servo-driver'
|
18
18
|
|
19
19
|
pwm = PWM.new(0x40, true)
|
20
|
-
pwm.
|
20
|
+
pwm.set_pwm_freq(50)
|
21
21
|
|
22
22
|
channel = 0
|
23
23
|
|
24
24
|
3.times do
|
25
|
-
pwm.
|
25
|
+
pwm.set_pwm(channel, 0, 212)
|
26
26
|
sleep(0.5)
|
27
|
-
pwm.
|
27
|
+
pwm.set_pwm(channel, 0, 412)
|
28
28
|
sleep(0.5)
|
29
29
|
end
|
30
30
|
```
|
data/Rakefile
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
module AdafruitServoDriver
|
2
|
+
class I2CDevice
|
3
|
+
DEVICES = [
|
4
|
+
'/dev/i2c-0', # Raspberry Pi rev 1
|
5
|
+
'/dev/i2c-1', # Raspberry Pi rev 2
|
6
|
+
]
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def detect
|
10
|
+
DEVICES.find(if_not_found) do |device_path|
|
11
|
+
File.exist? device_path
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def if_not_found
|
16
|
+
-> { raise DeviceNotFoundError.new }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class DeviceNotFoundError < StandardError
|
22
|
+
end
|
23
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'i2c/i2c'
|
2
|
+
include AdafruitServoDriver
|
2
3
|
|
3
4
|
class PWM
|
4
5
|
# Registers
|
@@ -25,9 +26,8 @@ class PWM
|
|
25
26
|
OUTDRV = 0x04
|
26
27
|
|
27
28
|
def initialize(address=0x40, debug=false)
|
28
|
-
# TODO detect pi revision
|
29
29
|
@address = address
|
30
|
-
@i2c = I2C.create(
|
30
|
+
@i2c = I2C.create(I2CDevice.detect)
|
31
31
|
@debug = debug
|
32
32
|
puts 'Reseting PCA9685 MODE1 (without SLEEP) and MODE2' if @debug
|
33
33
|
setAllPWM(0, 0)
|
@@ -0,0 +1,35 @@
|
|
1
|
+
include AdafruitServoDriver
|
2
|
+
|
3
|
+
describe I2CDevice do
|
4
|
+
context 'A Raspberry Pi rev 1' do
|
5
|
+
before do
|
6
|
+
allow(File).to receive('exist?').with('/dev/i2c-0').and_return true
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'detects the device path' do
|
10
|
+
expect(I2CDevice.detect).to eq '/dev/i2c-0'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'A Raspberry Pi rev 2' do
|
15
|
+
before do
|
16
|
+
allow(File).to receive('exist?').with('/dev/i2c-0').and_return false
|
17
|
+
allow(File).to receive('exist?').with('/dev/i2c-1').and_return true
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'detects the device path' do
|
21
|
+
expect(I2CDevice.detect).to eq '/dev/i2c-1'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'an unknown device' do
|
26
|
+
before do
|
27
|
+
allow(File).to receive('exist?').with('/dev/i2c-0').and_return false
|
28
|
+
allow(File).to receive('exist?').with('/dev/i2c-1').and_return false
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'raises a DeviceNotFoundError' do
|
32
|
+
expect{I2CDevice.detect}.to raise_error DeviceNotFoundError
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require_relative '../lib/adafruit-servo-driver'
|
2
|
+
|
3
|
+
RSpec.configure do |config|
|
4
|
+
# rspec-expectations config goes here. You can use an alternate
|
5
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
6
|
+
# assertions if you prefer.
|
7
|
+
config.expect_with :rspec do |expectations|
|
8
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
9
|
+
# and `failure_message` of custom matchers include text for helper methods
|
10
|
+
# defined using `chain`, e.g.:
|
11
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
12
|
+
# # => "be bigger than 2 and smaller than 4"
|
13
|
+
# ...rather than:
|
14
|
+
# # => "be bigger than 2"
|
15
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
16
|
+
end
|
17
|
+
|
18
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
19
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
20
|
+
config.mock_with :rspec do |mocks|
|
21
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
22
|
+
# a real object. This is generally recommended, and will default to
|
23
|
+
# `true` in RSpec 4.
|
24
|
+
mocks.verify_partial_doubles = true
|
25
|
+
end
|
26
|
+
|
27
|
+
# The settings below are suggested to provide a good initial experience
|
28
|
+
# with RSpec, but feel free to customize to your heart's content.
|
29
|
+
=begin
|
30
|
+
# These two settings work together to allow you to limit a spec run
|
31
|
+
# to individual examples or groups you care about by tagging them with
|
32
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
33
|
+
# get run.
|
34
|
+
config.filter_run :focus
|
35
|
+
config.run_all_when_everything_filtered = true
|
36
|
+
|
37
|
+
# Limits the available syntax to the non-monkey patched syntax that is recommended.
|
38
|
+
# For more details, see:
|
39
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
40
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
41
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
42
|
+
config.disable_monkey_patching!
|
43
|
+
|
44
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
45
|
+
# be too noisy due to issues in dependencies.
|
46
|
+
config.warnings = true
|
47
|
+
|
48
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
49
|
+
# file, and it's useful to allow more verbose output when running an
|
50
|
+
# individual spec file.
|
51
|
+
if config.files_to_run.one?
|
52
|
+
# Use the documentation formatter for detailed output,
|
53
|
+
# unless a formatter has already been configured
|
54
|
+
# (e.g. via a command-line flag).
|
55
|
+
config.default_formatter = 'doc'
|
56
|
+
end
|
57
|
+
|
58
|
+
# Print the 10 slowest examples and example groups at the
|
59
|
+
# end of the spec run, to help surface which specs are running
|
60
|
+
# particularly slow.
|
61
|
+
config.profile_examples = 10
|
62
|
+
|
63
|
+
# Run specs in random order to surface order dependencies. If you find an
|
64
|
+
# order dependency and want to debug it, you can fix the order by providing
|
65
|
+
# the seed, which is printed after each run.
|
66
|
+
# --seed 1234
|
67
|
+
config.order = :random
|
68
|
+
|
69
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
70
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
71
|
+
# test failures related to randomization by passing the same `--seed` value
|
72
|
+
# as the one that triggered the failure.
|
73
|
+
Kernel.srand config.seed
|
74
|
+
=end
|
75
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adafruit-servo-driver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris D'Ambrosio
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i2c
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.1.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.1.0
|
55
69
|
description: A Ruby implementation of Adafruit's Python library for the Adafruit PCA9685
|
56
70
|
16-Channel PWM Servo Driver for use with the Raspberry Pi.
|
57
71
|
email:
|
@@ -61,15 +75,19 @@ extensions: []
|
|
61
75
|
extra_rdoc_files: []
|
62
76
|
files:
|
63
77
|
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- CHANGELOG.md
|
64
80
|
- Gemfile
|
65
81
|
- LICENSE.txt
|
66
82
|
- README.md
|
67
83
|
- Rakefile
|
68
84
|
- adafruit-servo-driver.gemspec
|
69
|
-
- example.rb
|
70
85
|
- lib/adafruit-servo-driver.rb
|
86
|
+
- lib/adafruit-servo-driver/i2c_device.rb
|
71
87
|
- lib/adafruit-servo-driver/pwm.rb
|
72
88
|
- lib/adafruit-servo-driver/version.rb
|
89
|
+
- spec/i2c_device_spec.rb
|
90
|
+
- spec/spec_helper.rb
|
73
91
|
homepage: ''
|
74
92
|
licenses:
|
75
93
|
- MIT
|
@@ -94,4 +112,6 @@ rubygems_version: 2.4.5
|
|
94
112
|
signing_key:
|
95
113
|
specification_version: 4
|
96
114
|
summary: Ruby i2c interface for the Adafruit PCA9685 Servo Driver and Raspberry Pi
|
97
|
-
test_files:
|
115
|
+
test_files:
|
116
|
+
- spec/i2c_device_spec.rb
|
117
|
+
- spec/spec_helper.rb
|
data/example.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# adapted from http://www.raspberrypi.org/phpBB3/viewtopic.php?t=32826
|
4
|
-
|
5
|
-
require File.dirname(__FILE__) + '/adafruit-pwm-servo-driver'
|
6
|
-
|
7
|
-
pwm = PWM.new(0x40, true)
|
8
|
-
pwm.setPWMFreq(50)
|
9
|
-
|
10
|
-
channel = 0
|
11
|
-
|
12
|
-
3.times do
|
13
|
-
pwm.setPWM(channel, 0, 212)
|
14
|
-
sleep(0.5)
|
15
|
-
pwm.setPWM(channel, 0, 412)
|
16
|
-
sleep(0.5)
|
17
|
-
end
|