class UdooNeoRest::Base
Public Class Methods
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
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
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 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 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
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 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
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
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
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
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
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