Class: Temperature
- Inherits:
-
Object
- Object
- Temperature
- Defined in:
- lib/w1temp.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.initialize ⇒ Object
2 3 4 5 |
# File 'lib/w1temp.rb', line 2 def self.initialize `sudo modprobe w1-gpio` `sudo modprobe w1-gpio` end |
Instance Method Details
#name ⇒ Object
7 8 9 10 11 |
# File 'lib/w1temp.rb', line 7 def name paths = Dir["/sys/bus/w1/devices/*"] name = paths.select{|path| path.include?('-')}.first.split('/').last return name.strip end |
#reading ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/w1temp.rb', line 13 def reading paths = Dir["/sys/bus/w1/devices/*"] temperature_sensor_path = paths.select{|path| path.include?('-')}.first + '/w1_slave' file_contents = File.read(temperature_sensor_path) temperature_data = file_contents.split('t=').last temperature = temperature_data.to_f / 1000 return temperature end |