artoo-wandboard 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 144e672dde9047b7a040ceedf96a5b35da6e28dd
4
+ data.tar.gz: 048be5401b599e36c06fcc1d8953bcf64888245e
5
+ SHA512:
6
+ metadata.gz: 37f38d0aaef93a25207c53dd3f7c1f7c01099d85e859f88c31a2e324948b910efc4935fb88960e1e9067b569d03f0cb0b5cb634ad6965dbe385ad6be3a0a7d1f
7
+ data.tar.gz: 8acdbc16b60589ba7a35de74925c9bda58237687aa218f768822efd7c8ed5e688e3c5598fb39182922ee500290d7099fcfc88594196f3c225daa0f2ab197c3b5
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ /ext/*/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format progress
3
+ --order default
@@ -0,0 +1 @@
1
+ --markup markdown
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in artoo-wandboard.gemspec
4
+ gemspec
@@ -0,0 +1,32 @@
1
+ # Artoo Adaptor For Wandboard
2
+
3
+ This repository contains the [Artoo](http://artoo.io/) adaptor for [Wandboard](http://wandboard.org/).
4
+
5
+ Artoo is a open source micro-framework for robotics using Ruby.
6
+
7
+ For more information about Artoo, check out repo at https://github.com/hybridgroup/artoo
8
+
9
+ ## Installing
10
+
11
+ ```
12
+ gem install artoo-wandboard
13
+ ```
14
+
15
+ ## Using
16
+
17
+ ```ruby
18
+ require 'artoo'
19
+
20
+ connection :wandboard, :adaptor => :wandboard
21
+ device :led, :driver => :led, :pin => :JP4_4
22
+
23
+ work do
24
+ every 1.second do
25
+ led.on? ? led.off : led.on
26
+ end
27
+ end
28
+ ```
29
+
30
+ ## Connecting
31
+
32
+ Run this Gem on Wandboard device itself.
@@ -0,0 +1,13 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'yard'
4
+
5
+ desc 'Default: run specs.'
6
+ task :default => :spec
7
+
8
+ desc 'Run specs'
9
+ RSpec::Core::RakeTask.new(:spec) do |t|
10
+ end
11
+
12
+ YARD::Rake::YardocTask.new(:doc) do |t|
13
+ end
@@ -0,0 +1,24 @@
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <http://unlicense.org/>
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'artoo-wandboard/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'artoo-wandboard'
7
+ s.version = Artoo::Wandboard::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ['Dāvis']
10
+ s.email = ['davispuh@gmail.com']
11
+ s.homepage = 'https://github.com/davispuh/artoo-wandboard'
12
+ s.license = 'UNLICENSE'
13
+ s.summary = %q{Artoo adaptor and driver for Wandboard}
14
+ s.description = %q{Artoo adaptor and driver for Wandboard}
15
+
16
+ s.rubyforge_project = 'artoo-wandboard'
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ["lib"]
22
+
23
+ s.add_runtime_dependency 'artoo', '>= 1.8.0'
24
+ s.add_development_dependency 'bundler'
25
+ s.add_development_dependency 'rake'
26
+ s.add_development_dependency 'rspec'
27
+ s.add_development_dependency 'yard'
28
+ s.add_development_dependency 'simplecov'
29
+ end
@@ -0,0 +1,3 @@
1
+ require 'artoo/adaptors/wandboard'
2
+ require 'artoo/drivers/wandboard'
3
+ require 'artoo-wandboard/version'
@@ -0,0 +1,5 @@
1
+ module Artoo
2
+ module Wandboard
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1,118 @@
1
+ require 'artoo/adaptors/adaptor'
2
+ require 'artoo/adaptors/io'
3
+
4
+ module Artoo
5
+ module Adaptors
6
+ # Connect to a wandboard device
7
+ # @see device documentation for more information
8
+ class Wandboard < Adaptor
9
+ attr_reader :device, :pins, :camera, :uart, :spdif, :i2c1, :i2c2, :ttl, :lvds, :spi
10
+
11
+ I2C0 = '/dev/i2c-0'
12
+ I2C1 = '/dev/i2c-1'
13
+
14
+ def self.gpio(bank, number)
15
+ (bank - 1) * 32 + number
16
+ end
17
+
18
+ include Artoo::Adaptors::IO
19
+ PINS = {
20
+ :JP4_4 => gpio(3, 11), # 75
21
+ :JP4_6 => gpio(3, 27), # 91
22
+ :JP4_8 => gpio(6, 31), # 191
23
+ :JP4_10 => gpio(1, 24), # 24
24
+ :JP4_12 => gpio(7, 8), # 200
25
+ :JP4_14 => gpio(3, 26), # 90
26
+ :JP4_16 => gpio(3, 8), # 72
27
+ :JP4_18 => gpio(4, 5), # 101
28
+ }
29
+
30
+ # Creates a connection with device
31
+ # @return [Boolean]
32
+ def connect
33
+ @pins ||= {}
34
+ super
35
+ end
36
+
37
+ # Closes connection with device
38
+ # @return [Boolean]
39
+ def disconnect
40
+ @pins.each { |n, p| p.close } if @pins
41
+ @pins = {}
42
+ super
43
+ end
44
+
45
+ # Name of device
46
+ # @return [String]
47
+ def name
48
+ 'wandboard'
49
+ end
50
+
51
+ # Version of device
52
+ # @return [String]
53
+ def version
54
+ Artoo::Wandboard::VERSION
55
+ end
56
+
57
+ def digital_write(pin, val)
58
+ pin = wandboard_pin(pin, 'w')
59
+ pin.digital_write(val)
60
+ end
61
+
62
+ def digital_read(pin)
63
+ pin = wandboard_pin(pin, 'r')
64
+ pin.digital_read
65
+ end
66
+
67
+ def i2c1_start(address)
68
+ @i2c1 = I2c.new(I2C0, address)
69
+ end
70
+
71
+ def i2c1_write(*data)
72
+ raise 'Not started' unless @i2c1
73
+ @i2c1.write(*data)
74
+ end
75
+
76
+ def i2c1_read(len)
77
+ raise 'Not started' unless @i2c1
78
+ @i2c1.read(len)
79
+ end
80
+
81
+ def i2c2_start(address)
82
+ @i2c2 = I2c.new(I2C1, address)
83
+ end
84
+
85
+ def i2c2_write(*data)
86
+ raise 'Not started' unless @i2c2
87
+ @i2c2.write(*data)
88
+ end
89
+
90
+ def i2c2_read(len)
91
+ raise 'Not started' unless @i2c2
92
+ @i2c2.read(len)
93
+ end
94
+
95
+ # Uses method missing to call device actions
96
+ # @see device documentation
97
+ def method_missing(method_name, *arguments, &block)
98
+ device.send(method_name, *arguments, &block)
99
+ end
100
+
101
+ private
102
+
103
+ def translate_pin(pin)
104
+ PINS.fetch(pin)
105
+ rescue KeyError
106
+ raise 'Not a valid pin'
107
+ end
108
+
109
+ def wandboard_pin(pin, mode)
110
+ raise 'Not connected' unless connected?
111
+ pin = translate_pin(pin)
112
+ @pins[pin] = DigitalPin.new(pin, mode) if @pins[pin].nil? or @pins[pin].mode != mode
113
+ @pins[pin]
114
+ end
115
+
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,28 @@
1
+ require 'artoo/drivers/driver'
2
+
3
+ module Artoo
4
+ module Drivers
5
+ # The wandboard driver behaviors
6
+ class Wandboard < Driver
7
+
8
+ # Start driver and any required connections
9
+ def start_driver
10
+ begin
11
+ every(interval) do
12
+ handle_message_events
13
+ end
14
+
15
+ super
16
+ rescue Exception => e
17
+ Logger.error "Error starting Wandboard driver!"
18
+ Logger.error e.message
19
+ Logger.error e.backtrace.inspect
20
+ end
21
+ end
22
+
23
+ def handle_message_events
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,130 @@
1
+ # encoding: UTF-8
2
+ require_relative '../spec_helper'
3
+
4
+ describe Artoo::Adaptors::Wandboard do
5
+
6
+ let(:adaptor) { Artoo::Adaptors::Wandboard.new }
7
+ let(:pin) { double('DigitalPin') }
8
+ let(:i2c) { double('I2C') }
9
+
10
+ describe 'device info interface' do
11
+ describe '#name' do
12
+ it 'should return Wandboard name' do
13
+ expect(adaptor.name).to eq('wandboard')
14
+ end
15
+ end
16
+
17
+ describe '#version' do
18
+ it 'should return Wandboard adapter version' do
19
+ expect(adaptor.version).to eq(Artoo::Wandboard::VERSION)
20
+ end
21
+ end
22
+ end
23
+
24
+ describe 'digital GPIO interface' do
25
+ describe '#connect' do
26
+ it 'should connect to Wandboard hardware' do
27
+ expect(adaptor.connect).to be true
28
+ end
29
+ end
30
+
31
+ describe '#disconnect' do
32
+ it 'should disconnect from Wandboard hardware' do
33
+ adaptor.connect
34
+ allow(Artoo::Adaptors::IO::DigitalPin).to receive(:new).with(200, 'r') { pin }
35
+ allow(pin).to receive(:digital_read) { 1 }
36
+ expect(pin).to receive(:close)
37
+ adaptor.digital_read(:JP4_12)
38
+ expect(adaptor.disconnect).to be true
39
+ end
40
+ end
41
+
42
+ describe '#digital_read' do
43
+ it 'should read from :JP4_12 pin' do
44
+ adaptor.connect
45
+ expect(Artoo::Adaptors::IO::DigitalPin).to receive(:new).with(200, 'r') { pin }
46
+ allow(pin).to receive(:mode) { 'r' }
47
+ expect(pin).to receive(:digital_read) { 1 }
48
+ expect(adaptor.digital_read(:JP4_12)).to eq(1)
49
+ end
50
+
51
+ it 'should raise exception if not connected' do
52
+ expect { adaptor.digital_read(:JP4_8) }.to raise_error('Not connected')
53
+ end
54
+
55
+ it 'should raise exception if invalid pin' do
56
+ adaptor.connect
57
+ expect { adaptor.digital_read(:JP4_80) }.to raise_error('Not a valid pin')
58
+ end
59
+ end
60
+
61
+ describe '#digital_write' do
62
+ it 'should write to :JP4_8 pin' do
63
+ adaptor.connect
64
+ expect(Artoo::Adaptors::IO::DigitalPin).to receive(:new).with(191, 'w') { pin }
65
+ allow(pin).to receive(:mode) { 'w' }
66
+ expect(pin).to receive(:digital_write).with(1)
67
+ expect(pin).to receive(:digital_write).with(0)
68
+ adaptor.digital_write(:JP4_8, 1)
69
+ adaptor.digital_write(:JP4_8, 0)
70
+ end
71
+
72
+ it 'should raise exception if not connected' do
73
+ expect { adaptor.digital_write(:JP4_12, 1) }.to raise_error('Not connected')
74
+ end
75
+ end
76
+ end
77
+
78
+ describe 'i2c interface' do
79
+ describe '#i2c1_start' do
80
+ it 'should start /dev/i2c-0 at address 0x50' do
81
+ expect(Artoo::Adaptors::IO::I2c).to receive(:new).with('/dev/i2c-0', 0x50) { i2c }
82
+ expect(adaptor.i2c1_start(0x50)).to be i2c
83
+ end
84
+ end
85
+
86
+ describe '#i2c1_read' do
87
+ it 'should read i2c-1' do
88
+ allow(Artoo::Adaptors::IO::I2c).to receive(:new) { i2c }
89
+ adaptor.i2c1_start(0x50)
90
+ expect(i2c).to receive(:read).with(3) { [0x00, 0x01, 0x02] }
91
+ expect(adaptor.i2c1_read(3)).to eq([0x00, 0x01, 0x02])
92
+ end
93
+ end
94
+
95
+ describe '#i2c1_write' do
96
+ it 'should write i2c-1' do
97
+ allow(Artoo::Adaptors::IO::I2c).to receive(:new) { i2c }
98
+ adaptor.i2c1_start(0x50)
99
+ expect(i2c).to receive(:write).with(0x00, 0x01, 0x02) { true }
100
+ expect(adaptor.i2c1_write(0x00, 0x01, 0x02)).to be true
101
+ end
102
+ end
103
+
104
+ describe '#i2c2_start' do
105
+ it 'should start /dev/i2c-1 at address 0x50' do
106
+ expect(Artoo::Adaptors::IO::I2c).to receive(:new).with('/dev/i2c-1', 0x50) { i2c }
107
+ expect(adaptor.i2c2_start(0x50)).to be i2c
108
+ end
109
+ end
110
+
111
+ describe '#i2c2_read' do
112
+ it 'should read i2c-2' do
113
+ allow(Artoo::Adaptors::IO::I2c).to receive(:new) { i2c }
114
+ adaptor.i2c2_start(0x50)
115
+ expect(i2c).to receive(:read).with(3) { [0x00, 0x01, 0x02] }
116
+ expect(adaptor.i2c2_read(3)).to eq([0x00, 0x01, 0x02])
117
+ end
118
+ end
119
+
120
+ describe '#i2c2_write' do
121
+ it 'should write i2c-2' do
122
+ allow(Artoo::Adaptors::IO::I2c).to receive(:new) { i2c }
123
+ adaptor.i2c2_start(0x50)
124
+ expect(i2c).to receive(:write).with(0x00, 0x01, 0x02) { true }
125
+ expect(adaptor.i2c2_write(0x00, 0x01, 0x02)).to be true
126
+ end
127
+ end
128
+ end
129
+
130
+ end
@@ -0,0 +1,12 @@
1
+ # encoding: UTF-8
2
+ require_relative '../spec_helper'
3
+
4
+ describe Artoo::Drivers::Wandboard do
5
+
6
+ let(:driver) { Artoo::Drivers::Wandboard.new }
7
+
8
+ it '#start_driver' do
9
+ expect { driver.start_driver }.to_not raise_error
10
+ end
11
+
12
+ end
@@ -0,0 +1,20 @@
1
+ # encoding: UTF-8
2
+ require 'simplecov'
3
+ require 'artoo/robot'
4
+
5
+ Celluloid.logger = nil
6
+ Celluloid.shutdown
7
+ Celluloid.boot
8
+
9
+ RSpec.configure do |config|
10
+ config.expect_with :rspec do |c|
11
+ c.syntax = :expect
12
+ end
13
+ config.mock_with :rspec do |mocks|
14
+ mocks.verify_partial_doubles = true
15
+ end
16
+ end
17
+
18
+ SimpleCov.start
19
+
20
+ require 'artoo-wandboard'
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: artoo-wandboard
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dāvis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: artoo
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.8.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.8.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '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: '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
+ - !ruby/object:Gem::Dependency
70
+ name: yard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Artoo adaptor and driver for Wandboard
98
+ email:
99
+ - davispuh@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".yardopts"
107
+ - Gemfile
108
+ - README.md
109
+ - Rakefile
110
+ - UNLICENSE
111
+ - artoo-wandboard.gemspec
112
+ - lib/artoo-wandboard.rb
113
+ - lib/artoo-wandboard/version.rb
114
+ - lib/artoo/adaptors/wandboard.rb
115
+ - lib/artoo/drivers/wandboard.rb
116
+ - spec/adaptors/wandboard_adaptor_spec.rb
117
+ - spec/drivers/wandboard_driver_spec.rb
118
+ - spec/spec_helper.rb
119
+ homepage: https://github.com/davispuh/artoo-wandboard
120
+ licenses:
121
+ - UNLICENSE
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project: artoo-wandboard
139
+ rubygems_version: 2.4.2
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: Artoo adaptor and driver for Wandboard
143
+ test_files: []
144
+ has_rdoc: