Class: Artoo::Adaptors::Wandboard
- Inherits:
-
Adaptor
- Object
- Adaptor
- Artoo::Adaptors::Wandboard
- Includes:
- IO
- Defined in:
- lib/artoo/adaptors/wandboard.rb
Overview
Connect to a wandboard device
Constant Summary collapse
- I2C0 =
'/dev/i2c-0'
- I2C1 =
'/dev/i2c-1'
- PINS =
{ :JP4_4 => gpio(3, 11), # 75 :JP4_6 => gpio(3, 27), # 91 :JP4_8 => gpio(6, 31), # 191 :JP4_10 => gpio(1, 24), # 24 :JP4_12 => gpio(7, 8), # 200 :JP4_14 => gpio(3, 26), # 90 :JP4_16 => gpio(3, 8), # 72 :JP4_18 => gpio(4, 5), # 101 }
Instance Attribute Summary collapse
-
#camera ⇒ Object
readonly
Returns the value of attribute camera.
-
#device ⇒ Object
readonly
Returns the value of attribute device.
-
#i2c1 ⇒ Object
readonly
Returns the value of attribute i2c1.
-
#i2c2 ⇒ Object
readonly
Returns the value of attribute i2c2.
-
#lvds ⇒ Object
readonly
Returns the value of attribute lvds.
-
#pins ⇒ Object
readonly
Returns the value of attribute pins.
-
#spdif ⇒ Object
readonly
Returns the value of attribute spdif.
-
#spi ⇒ Object
readonly
Returns the value of attribute spi.
-
#ttl ⇒ Object
readonly
Returns the value of attribute ttl.
-
#uart ⇒ Object
readonly
Returns the value of attribute uart.
Class Method Summary collapse
Instance Method Summary collapse
-
#connect ⇒ Boolean
Creates a connection with device.
- #digital_read(pin) ⇒ Object
- #digital_write(pin, val) ⇒ Object
-
#disconnect ⇒ Boolean
Closes connection with device.
- #i2c1_read(len) ⇒ Object
- #i2c1_start(address) ⇒ Object
- #i2c1_write(*data) ⇒ Object
- #i2c2_read(len) ⇒ Object
- #i2c2_start(address) ⇒ Object
- #i2c2_write(*data) ⇒ Object
-
#method_missing(method_name, *arguments, &block) ⇒ Object
Uses method missing to call device actions.
-
#name ⇒ String
Name of device.
-
#version ⇒ String
Version of device.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments, &block) ⇒ Object
Uses method missing to call device actions
97 98 99 |
# File 'lib/artoo/adaptors/wandboard.rb', line 97 def method_missing(method_name, *arguments, &block) device.send(method_name, *arguments, &block) end |
Instance Attribute Details
#camera ⇒ Object (readonly)
Returns the value of attribute camera.
9 10 11 |
# File 'lib/artoo/adaptors/wandboard.rb', line 9 def camera @camera end |
#device ⇒ Object (readonly)
Returns the value of attribute device.
9 10 11 |
# File 'lib/artoo/adaptors/wandboard.rb', line 9 def device @device end |
#i2c1 ⇒ Object (readonly)
Returns the value of attribute i2c1.
9 10 11 |
# File 'lib/artoo/adaptors/wandboard.rb', line 9 def i2c1 @i2c1 end |
#i2c2 ⇒ Object (readonly)
Returns the value of attribute i2c2.
9 10 11 |
# File 'lib/artoo/adaptors/wandboard.rb', line 9 def i2c2 @i2c2 end |
#lvds ⇒ Object (readonly)
Returns the value of attribute lvds.
9 10 11 |
# File 'lib/artoo/adaptors/wandboard.rb', line 9 def lvds @lvds end |
#pins ⇒ Object (readonly)
Returns the value of attribute pins.
9 10 11 |
# File 'lib/artoo/adaptors/wandboard.rb', line 9 def pins @pins end |
#spdif ⇒ Object (readonly)
Returns the value of attribute spdif.
9 10 11 |
# File 'lib/artoo/adaptors/wandboard.rb', line 9 def spdif @spdif end |
#spi ⇒ Object (readonly)
Returns the value of attribute spi.
9 10 11 |
# File 'lib/artoo/adaptors/wandboard.rb', line 9 def spi @spi end |
#ttl ⇒ Object (readonly)
Returns the value of attribute ttl.
9 10 11 |
# File 'lib/artoo/adaptors/wandboard.rb', line 9 def ttl @ttl end |
#uart ⇒ Object (readonly)
Returns the value of attribute uart.
9 10 11 |
# File 'lib/artoo/adaptors/wandboard.rb', line 9 def uart @uart end |
Class Method Details
.gpio(bank, number) ⇒ Object
14 15 16 |
# File 'lib/artoo/adaptors/wandboard.rb', line 14 def self.gpio(bank, number) (bank - 1) * 32 + number end |
Instance Method Details
#connect ⇒ Boolean
Creates a connection with device
32 33 34 35 |
# File 'lib/artoo/adaptors/wandboard.rb', line 32 def connect @pins ||= {} super end |
#digital_read(pin) ⇒ Object
62 63 64 65 |
# File 'lib/artoo/adaptors/wandboard.rb', line 62 def digital_read(pin) pin = wandboard_pin(pin, 'r') pin.digital_read end |
#digital_write(pin, val) ⇒ Object
57 58 59 60 |
# File 'lib/artoo/adaptors/wandboard.rb', line 57 def digital_write(pin, val) pin = wandboard_pin(pin, 'w') pin.digital_write(val) end |
#disconnect ⇒ Boolean
Closes connection with device
39 40 41 42 43 |
# File 'lib/artoo/adaptors/wandboard.rb', line 39 def disconnect @pins.each { |n, p| p.close } if @pins @pins = {} super end |
#i2c1_read(len) ⇒ Object
76 77 78 79 |
# File 'lib/artoo/adaptors/wandboard.rb', line 76 def i2c1_read(len) raise 'Not started' unless @i2c1 @i2c1.read(len) end |
#i2c1_start(address) ⇒ Object
67 68 69 |
# File 'lib/artoo/adaptors/wandboard.rb', line 67 def i2c1_start(address) @i2c1 = I2c.new(I2C0, address) end |
#i2c1_write(*data) ⇒ Object
71 72 73 74 |
# File 'lib/artoo/adaptors/wandboard.rb', line 71 def i2c1_write(*data) raise 'Not started' unless @i2c1 @i2c1.write(*data) end |
#i2c2_read(len) ⇒ Object
90 91 92 93 |
# File 'lib/artoo/adaptors/wandboard.rb', line 90 def i2c2_read(len) raise 'Not started' unless @i2c2 @i2c2.read(len) end |
#i2c2_start(address) ⇒ Object
81 82 83 |
# File 'lib/artoo/adaptors/wandboard.rb', line 81 def i2c2_start(address) @i2c2 = I2c.new(I2C1, address) end |
#i2c2_write(*data) ⇒ Object
85 86 87 88 |
# File 'lib/artoo/adaptors/wandboard.rb', line 85 def i2c2_write(*data) raise 'Not started' unless @i2c2 @i2c2.write(*data) end |
#name ⇒ String
Name of device
47 48 49 |
# File 'lib/artoo/adaptors/wandboard.rb', line 47 def name 'wandboard' end |