numato-gpio 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +35 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +5 -0
- data/Rakefile +1 -0
- data/lib/numato-gpio.rb +122 -0
- data/lib/numato-gpio/version.rb +5 -0
- data/numato-gpio.gemspec +27 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4ed0c74fedbbd1190b321c5fed6a53466d2ff493
|
4
|
+
data.tar.gz: 105fe2322d41835d88d2839ecfcb0997c50b67ae
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e9bc747ca1d6258cf9a4a1150a324fdb6238816d4abc2784b42f42d0c19d3d336b30b2fe8a55a277fffa4c93f0e92e0b70d6aabe127b038eb134d1b6af37c321
|
7
|
+
data.tar.gz: ad8e224c2a02e753306627af3d01663330a72608e750bec7981f3c0787df2437c15450799666e62c2a84f126c5d20a40b907be95435a9ab9a8a2a1f2a64df40e
|
data/.gitignore
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/vendor/bundle
|
26
|
+
/lib/bundler/man/
|
27
|
+
|
28
|
+
# for a library or gem, you might want to ignore these files since the code is
|
29
|
+
# intended to run in multiple environments; otherwise, check them in:
|
30
|
+
Gemfile.lock
|
31
|
+
# .ruby-version
|
32
|
+
# .ruby-gemset
|
33
|
+
|
34
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
35
|
+
.rvmrc
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 jslabovitz
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/lib/numato-gpio.rb
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'rubyserial'
|
2
|
+
|
3
|
+
require 'numato-gpio/version'
|
4
|
+
|
5
|
+
class NumatoGPIO
|
6
|
+
|
7
|
+
attr_accessor :device
|
8
|
+
attr_accessor :io_map
|
9
|
+
attr_accessor :mock
|
10
|
+
attr_accessor :verbose
|
11
|
+
|
12
|
+
def initialize(params={})
|
13
|
+
{
|
14
|
+
mock: false,
|
15
|
+
verbose: false,
|
16
|
+
io_map: {},
|
17
|
+
}.merge(params).each { |k, v| send("#{k}=", v) }
|
18
|
+
open_device
|
19
|
+
end
|
20
|
+
|
21
|
+
def open_device
|
22
|
+
return if @mock
|
23
|
+
unless @device
|
24
|
+
devices = Dir.glob('/dev/tty.usbmodem*')
|
25
|
+
raise "More than one device: #{devices.join(', ')}" if devices.length > 2
|
26
|
+
@device = devices.first
|
27
|
+
end
|
28
|
+
@port = Serial.new(@device)
|
29
|
+
warn "connected to device #{@device}" if @verbose
|
30
|
+
end
|
31
|
+
|
32
|
+
def version
|
33
|
+
command('ver')
|
34
|
+
end
|
35
|
+
|
36
|
+
def id
|
37
|
+
command('id get')
|
38
|
+
end
|
39
|
+
|
40
|
+
def id=(id)
|
41
|
+
#FIXME
|
42
|
+
raise
|
43
|
+
end
|
44
|
+
|
45
|
+
def set(x)
|
46
|
+
command("gpio set #{gpio_str(io_id_to_num(x))}", false)
|
47
|
+
end
|
48
|
+
|
49
|
+
def clear(x)
|
50
|
+
command("gpio clear #{gpio_str(io_id_to_num(x))}", false)
|
51
|
+
end
|
52
|
+
|
53
|
+
def read(x)
|
54
|
+
status = command("gpio read #{gpio_str(io_id_to_num(x))}", true)
|
55
|
+
case status
|
56
|
+
when '1'
|
57
|
+
true
|
58
|
+
when '0'
|
59
|
+
false
|
60
|
+
else
|
61
|
+
raise "Unknown status on read from IO #{x.inspect}: #{status.inspect}"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def command(cmd, wait_for_response=true)
|
68
|
+
warn "* #{cmd}" if @verbose
|
69
|
+
return if @mock
|
70
|
+
@port.write("#{cmd}\r")
|
71
|
+
@port.gets # echo
|
72
|
+
if wait_for_response
|
73
|
+
response = @port.gets.strip
|
74
|
+
#FIXME
|
75
|
+
# prompt = @port.gets
|
76
|
+
# prompt.strip!
|
77
|
+
# if prompt != '>'
|
78
|
+
# raise "Expected prompt, but got #{prompt.inspect}"
|
79
|
+
# end
|
80
|
+
response
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
IONames = ('0'..'9').to_a + ('A'..'V').to_a.freeze
|
85
|
+
|
86
|
+
def gpio_str(x)
|
87
|
+
IONames[x] or raise "Can't convert GPIO number #{x.inspect} to string"
|
88
|
+
end
|
89
|
+
|
90
|
+
def io_id_to_num(x)
|
91
|
+
case x
|
92
|
+
when Numeric
|
93
|
+
x
|
94
|
+
when Symbol
|
95
|
+
@io_map[x] or raise "No IO ID #{x.inspect}"
|
96
|
+
else
|
97
|
+
raise "Can't convert #{x.class} to IO: #{x.inspect}"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
if $0 == __FILE__
|
104
|
+
|
105
|
+
gpio = NumatoGPIO.new(mock: true)
|
106
|
+
|
107
|
+
gpio.clear(0)
|
108
|
+
gpio.clear(1)
|
109
|
+
|
110
|
+
gpio.set(1)
|
111
|
+
|
112
|
+
3.times do |i|
|
113
|
+
puts i
|
114
|
+
gpio.set(0)
|
115
|
+
sleep 0.5
|
116
|
+
gpio.clear(0)
|
117
|
+
sleep 0.5
|
118
|
+
end
|
119
|
+
|
120
|
+
gpio.clear(1)
|
121
|
+
|
122
|
+
end
|
data/numato-gpio.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require 'numato-gpio/version'
|
7
|
+
|
8
|
+
Gem::Specification.new do |s|
|
9
|
+
s.name = 'numato-gpio'
|
10
|
+
s.version = NumatoGPIO::VERSION
|
11
|
+
s.summary = 'Interfaces with Numato GPIO board via USB interface.'
|
12
|
+
s.author = 'John Labovitz'
|
13
|
+
s.email = 'johnl@johnlabovitz.com'
|
14
|
+
s.description = %q{
|
15
|
+
NumatoGPIO interfaces with Numato GPIO board via USB interface.
|
16
|
+
}
|
17
|
+
s.homepage = 'http://github.com/jslabovitz/numato-gpio'
|
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_path = 'lib'
|
22
|
+
|
23
|
+
s.add_dependency 'rubyserial'
|
24
|
+
|
25
|
+
s.add_development_dependency 'bundler'
|
26
|
+
s.add_development_dependency 'rake'
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: numato-gpio
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Labovitz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rubyserial
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '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
|
+
description: "\nNumatoGPIO interfaces with Numato GPIO board via USB interface.\n
|
56
|
+
\ "
|
57
|
+
email: johnl@johnlabovitz.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/numato-gpio.rb
|
68
|
+
- lib/numato-gpio/version.rb
|
69
|
+
- numato-gpio.gemspec
|
70
|
+
homepage: http://github.com/jslabovitz/numato-gpio
|
71
|
+
licenses: []
|
72
|
+
metadata: {}
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 2.5.0
|
90
|
+
signing_key:
|
91
|
+
specification_version: 4
|
92
|
+
summary: Interfaces with Numato GPIO board via USB interface.
|
93
|
+
test_files: []
|
94
|
+
has_rdoc:
|