class Beaglebone::I2CDevice

Object Oriented I2C Implementation. This treats the I2C device as an object.

Public Class Methods

new(i2c) click to toggle source

Initialize an I2C device. Returns an I2CDevice object

@param i2c should be a symbol representing the I2C device

@example

i2c = I2CDevice.new(:I2C2)
# File lib/beaglebone/i2c.rb, line 216
def initialize(i2c)
  @i2c = i2c
  I2C::setup(@i2c)
end

Public Instance Methods

disable() click to toggle source

Disable the specified I2C device.

@note device trees cannot be unloaded at this time without kernel panic.

# File lib/beaglebone/i2c.rb, line 251
def disable
  I2C::disable(@i2c)
end
file() click to toggle source

Return the file descriptor to the open I2C device

# File lib/beaglebone/i2c.rb, line 256
def file
  I2C::file(@i2c)
end
read(address, bytes=1, register=nil) click to toggle source

Read data from an I2C device

@param address the address of the slave device @param bytes bytes to read @param register optional register to read from

@example

# read 3 big endian signed shorts starting at register 0x03
data = i2c.read(0x1e, 6, [0x03].pack("C*"))
  x,z,y = raw.unpack("s>*")
# File lib/beaglebone/i2c.rb, line 244
def read(address, bytes=1, register=nil)
  I2C::read(@i2c, address, bytes, register)
end
write(address, data) click to toggle source

Write data to an I2C device

@param address the address of the slave device @param data the data to write

@return Integer the number of bytes written

@example

i2c.write(0x1e, [0x00, 0b10010000].pack("C*") )
# File lib/beaglebone/i2c.rb, line 230
def write(address, data)
  I2C::write(@i2c, address, data)
end