class BBB::Pins::IO::AIN

Attributes

io[R]
position[R]

Public Class Methods

check_if_kernel_module_is_loaded!() click to toggle source
# File lib/BBB/pins/io/ain.rb, line 41
def self.check_if_kernel_module_is_loaded!
  ains = `find /sys/ -name '*AIN*'`.split("\n")

  if ains.size > 0
    return true
  else
    raise ModuleNotLoadedException, "Is seems that the ADC module is not
      loaded into the kernel. You might want to try: \n
      sudo modprobe t1_tscadc or add it to the kernel on boot: \n
      echo 't1_tscadc' >> /etc/modules.conf"
  end
end
new(position) click to toggle source
# File lib/BBB/pins/io/ain.rb, line 10
def initialize(position)
  @position = position
  self.export
  @io = get_file_handle
end
setup() click to toggle source
# File lib/BBB/pins/io/ain.rb, line 37
def self.setup
  check_if_kernel_module_is_loaded!
end

Public Instance Methods

export() click to toggle source
# File lib/BBB/pins/io/ain.rb, line 25
def export
  `echo cape-bone-iio > #{cape_dir}`
end
get_file_handle() click to toggle source
# File lib/BBB/pins/io/ain.rb, line 29
def get_file_handle
  dir  = Dir.glob("/sys/devices/ocp.*/helper.*/")
  file = File.expand_path("AIN#{pin_map.ain}", dir.first)
  file = File.open(file, "r")
  file.sync = true
  return file
end
read() click to toggle source
# File lib/BBB/pins/io/ain.rb, line 16
def read
  io.rewind
  io.read.to_i
end
scale() click to toggle source
# File lib/BBB/pins/io/ain.rb, line 21
def scale
  pin_map.scale
end