Class: Artoo::Adaptors::Wandboard

Inherits:
Adaptor
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

See Also:



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

#cameraObject (readonly)

Returns the value of attribute camera.



9
10
11
# File 'lib/artoo/adaptors/wandboard.rb', line 9

def camera
  @camera
end

#deviceObject (readonly)

Returns the value of attribute device.



9
10
11
# File 'lib/artoo/adaptors/wandboard.rb', line 9

def device
  @device
end

#i2c1Object (readonly)

Returns the value of attribute i2c1.



9
10
11
# File 'lib/artoo/adaptors/wandboard.rb', line 9

def i2c1
  @i2c1
end

#i2c2Object (readonly)

Returns the value of attribute i2c2.



9
10
11
# File 'lib/artoo/adaptors/wandboard.rb', line 9

def i2c2
  @i2c2
end

#lvdsObject (readonly)

Returns the value of attribute lvds.



9
10
11
# File 'lib/artoo/adaptors/wandboard.rb', line 9

def lvds
  @lvds
end

#pinsObject (readonly)

Returns the value of attribute pins.



9
10
11
# File 'lib/artoo/adaptors/wandboard.rb', line 9

def pins
  @pins
end

#spdifObject (readonly)

Returns the value of attribute spdif.



9
10
11
# File 'lib/artoo/adaptors/wandboard.rb', line 9

def spdif
  @spdif
end

#spiObject (readonly)

Returns the value of attribute spi.



9
10
11
# File 'lib/artoo/adaptors/wandboard.rb', line 9

def spi
  @spi
end

#ttlObject (readonly)

Returns the value of attribute ttl.



9
10
11
# File 'lib/artoo/adaptors/wandboard.rb', line 9

def ttl
  @ttl
end

#uartObject (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

#connectBoolean

Creates a connection with device

Returns:

  • (Boolean)


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

#disconnectBoolean

Closes connection with device

Returns:

  • (Boolean)


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

#nameString

Name of device

Returns:

  • (String)


47
48
49
# File 'lib/artoo/adaptors/wandboard.rb', line 47

def name
  'wandboard'
end

#versionString

Version of device

Returns:

  • (String)


53
54
55
# File 'lib/artoo/adaptors/wandboard.rb', line 53

def version
  Artoo::Wandboard::VERSION
end