artoo 1.2.2 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -1
- data/Gemfile.lock +1 -1
- data/lib/artoo/adaptors/io.rb +1 -0
- data/lib/artoo/adaptors/io/digital_pin.rb +86 -0
- data/lib/artoo/adaptors/io/i2c.rb +42 -0
- data/lib/artoo/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ec3dffe53098b116ffd1d43926b191217004e92
|
4
|
+
data.tar.gz: 1ac14de8f26da07e301b070a4f49c9953d23e3d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65a2047f7c1a45058ecd1c255912e6fe1ab5b9aaf9a3f476d20f385d150972266a37a036aeddea890fe3e0c0a8b27d04dc4264ef4fe6b27518caf3882c22f552
|
7
|
+
data.tar.gz: b44b3a7e6b8cc1caa1c60f39115c8778d5ec549dd2f7c25ca7c456df6a938a5441ab29ab99cbf0f91aab5fbf267406d4f2ab84c450a823bd079a55b1e2f00355
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
Dir[File.dirname(__FILE__) + '/io/*.rb'].each {|file| require file }
|
@@ -0,0 +1,86 @@
|
|
1
|
+
module Artoo
|
2
|
+
module Adaptors
|
3
|
+
module IO
|
4
|
+
class DigitalPin
|
5
|
+
attr_reader :pin_num, :mode, :pin_file, :status
|
6
|
+
|
7
|
+
GPIO_PATH = "/sys/class/gpio"
|
8
|
+
GPIO_DIRECTION_READ = "in"
|
9
|
+
GPIO_DIRECTION_WRITE = "out"
|
10
|
+
HIGH = 1
|
11
|
+
LOW = 0
|
12
|
+
|
13
|
+
def initialize(pin_num, mode)
|
14
|
+
@pin_num = pin_num
|
15
|
+
|
16
|
+
File.open("#{ GPIO_PATH }/export", "w") { |f| f.write("#{ pin_num }") }
|
17
|
+
|
18
|
+
# Sets the pin for read or write
|
19
|
+
set_mode(mode)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Writes to the specified pin Digitally
|
23
|
+
# accepts values :high or :low, 1 or 0, "1" or "0"
|
24
|
+
def digital_write(value)
|
25
|
+
set_mode('w') unless @mode == 'w'
|
26
|
+
|
27
|
+
if value.is_a? Symbol
|
28
|
+
value = (value == :high) ? 1 : 0
|
29
|
+
end
|
30
|
+
|
31
|
+
value = value.to_i
|
32
|
+
|
33
|
+
raise StandardError unless ([HIGH, LOW].include? value)
|
34
|
+
|
35
|
+
@status = (value == 1) ? 'high' : 'low'
|
36
|
+
|
37
|
+
@pin_file.write(value)
|
38
|
+
@pin_file.flush
|
39
|
+
end
|
40
|
+
|
41
|
+
# Reads digitally from the specified pin on initialize
|
42
|
+
def digital_read
|
43
|
+
set_mode('r') unless @mode == 'r'
|
44
|
+
|
45
|
+
@pin_file.read
|
46
|
+
end
|
47
|
+
|
48
|
+
# Sets the pin in GPIO for read or write.
|
49
|
+
def set_mode(mode)
|
50
|
+
@mode = mode
|
51
|
+
|
52
|
+
if mode == 'w'
|
53
|
+
File.open("#{ GPIO_PATH }/gpio#{ pin_num }/direction", "w") { |f| f.write(GPIO_DIRECTION_WRITE) }
|
54
|
+
@pin_file = File.open("#{ GPIO_PATH }/gpio#{ pin_num }/value", "w")
|
55
|
+
elsif mode =='r'
|
56
|
+
File.open("#{ GPIO_PATH }/gpio#{ pin_num }/direction", "w") { |f| f.write(GPIO_DIRECTION_READ) }
|
57
|
+
@pin_file = File.open("#{ GPIO_PATH }/gpio#{pin_num}/value", "r")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def on?
|
62
|
+
(@status == 'high') ? true : false
|
63
|
+
end
|
64
|
+
|
65
|
+
def off?
|
66
|
+
!self.on?
|
67
|
+
end
|
68
|
+
|
69
|
+
# Sets digital write for the pin to HIGH
|
70
|
+
def on!
|
71
|
+
digital_write(:high)
|
72
|
+
end
|
73
|
+
|
74
|
+
# Sets digital write for the pin to LOW
|
75
|
+
def off!
|
76
|
+
digital_write(:off)
|
77
|
+
end
|
78
|
+
|
79
|
+
# Unexports the pin in GPIO to leave it free
|
80
|
+
def close
|
81
|
+
File.open("#{ GPIO_PATH }/unexport", "w") { |f| f.write("#{pin_num}") }
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Artoo
|
2
|
+
module Adaptors
|
3
|
+
module IO
|
4
|
+
class I2c
|
5
|
+
attr_reader :handle, :address, :i2c_location
|
6
|
+
|
7
|
+
I2C_SLAVE = 0x0703
|
8
|
+
|
9
|
+
def initialize(i2c_location, address)
|
10
|
+
@i2c_location = i2c_location
|
11
|
+
start(address)
|
12
|
+
end
|
13
|
+
|
14
|
+
def start(address)
|
15
|
+
@address = address
|
16
|
+
@handle = File.open(@i2c_location, 'r+')
|
17
|
+
@handle.ioctl(I2C_SLAVE, @address)
|
18
|
+
|
19
|
+
write 0
|
20
|
+
end
|
21
|
+
|
22
|
+
def write(*data)
|
23
|
+
ret = ""
|
24
|
+
ret.force_encoding("US-ASCII")
|
25
|
+
data.each do |n|
|
26
|
+
ret << [n].pack("v")[0]
|
27
|
+
ret << [n].pack("v")[1]
|
28
|
+
end
|
29
|
+
@handle.write(ret)
|
30
|
+
end
|
31
|
+
|
32
|
+
def read(len)
|
33
|
+
begin
|
34
|
+
@handle.read_nonblock(len).unpack("C#{len}")
|
35
|
+
rescue Exception => e
|
36
|
+
start(@address)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/artoo/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: artoo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ron Evans
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2013-
|
15
|
+
date: 2013-10-04 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: celluloid
|
@@ -199,6 +199,9 @@ files:
|
|
199
199
|
- examples/wiiclassic.rb
|
200
200
|
- lib/artoo.rb
|
201
201
|
- lib/artoo/adaptors/adaptor.rb
|
202
|
+
- lib/artoo/adaptors/io.rb
|
203
|
+
- lib/artoo/adaptors/io/digital_pin.rb
|
204
|
+
- lib/artoo/adaptors/io/i2c.rb
|
202
205
|
- lib/artoo/adaptors/loopback.rb
|
203
206
|
- lib/artoo/adaptors/test.rb
|
204
207
|
- lib/artoo/api/api.rb
|