class UdooNeoRest::Base

Public Class Methods

axis_path(sensor) click to toggle source

Build the path to common axis sensors

sensor : the sensor name

# File lib/udooneorest.rb, line 112
def self.axis_path(sensor)
  "/sys/class/misc/Freescale#{sensor}"
end
axis_path_data(sensor) click to toggle source

Build the path to common axis sensors to retrieve data

sensor : the sensor name

# File lib/udooneorest.rb, line 130
def self.axis_path_data(sensor)
  UdooNeoRest::Base.axis_path(sensor) + '/data'
end
axis_path_enable(sensor) click to toggle source

Build the path to common axis sensors to enable/disable

sensor : the sensor name

# File lib/udooneorest.rb, line 121
def self.axis_path_enable(sensor)
  UdooNeoRest::Base.axis_path(sensor) + '/enable'
end
cat(file) click to toggle source

Cat a file

file : the file to cat

# File lib/udooneorest.rb, line 81
def self.cat(file)
  begin
    return File.read(file).chomp
  rescue Exception => e
    return nil
  end
end
cat_and_status(file) click to toggle source

Cat a file contents and return the status

file : the file to cat

# File lib/udooneorest.rb, line 139
def self.cat_and_status(file)
  result = UdooNeoRest::Base.cat file
  unless result.nil?
    return UdooNeoRest::Base.status_ok result
  end

  return UdooNeoRest::Base.status_error 'GPIO/PIN could not be read. Have you already exported the GPIO/PIN?'
end
change_state(file, value) click to toggle source

Enable or disable one of the axis sensors

Value : 0 disables the axis, 1 enables it

# File lib/udooneorest.rb, line 153
def self.change_state(file, value)
  result        = UdooNeoRest::Base.echo value, file
  result.empty? ? UdooNeoRest::Base.status_ok : UdooNeoRest::Base.status_error(result)
end
echo(value, file) click to toggle source

Echo a value to a file

value : the value to echo to the file file : the file to echo the value too

# File lib/udooneorest.rb, line 65
def self.echo(value, file)
  begin
    File.write(file, value)
  rescue Errno::EINVAL
    # close always error on the udoo gpios - cause unknown
  rescue Exception => e
    return e.message
  end
  ''
end
sensor_calc(sensor) click to toggle source

Calculate the Barometer/Temp value from raw and scale values

# File lib/udooneorest.rb, line 92
def self.sensor_calc(sensor)
  raw   = UdooNeoRest::Base.cat(UdooNeoRest::Base.sensor_path(sensor) + '_raw').to_i
  scale = UdooNeoRest::Base.cat(UdooNeoRest::Base.sensor_path(sensor) + '_scale').to_f
  UdooNeoRest::Base.status_ok(raw * scale)
end
sensor_path(sensor) click to toggle source

Build the path to common sensors

sensor : the sensor name

# File lib/udooneorest.rb, line 103
def self.sensor_path(sensor)
  "/sys/class/i2c-dev/i2c-1/device/1-0060/iio:device0/in_#{sensor}"
end
status_error(message) click to toggle source

Construct the status message when an error occurred

message : the message to be displayed

# File lib/udooneorest.rb, line 55
def self.status_error(message)
  [400, status_message(FAILED_MESSAGE, message)]
end
status_message(status, message) click to toggle source

Message constructor

status : the status of the operation message : the message to be displayed

# File lib/udooneorest.rb, line 37
def self.status_message(status, message)
  %Q({"status" : "#{status}", "message" : "#{message}"})
end
status_ok(message = '') click to toggle source

Construct the status message when no errors occurred

message : the message to be displayed

# File lib/udooneorest.rb, line 46
def self.status_ok(message = '')
  status_message(SUCCESS_MESSAGE, message)
end