Module: RaspberryPi

Defined in:
lib/thermal_sensor.rb,
lib/raspberry_pi.rb

Overview

ThermalSensor - Raspberry Pi internal SoC temperature sensor

Defined Under Namespace

Classes: ThermalSensor

Class Method Summary collapse

Class Method Details

.hardware_infoObject

Return hardware info as a hash



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/raspberry_pi.rb', line 17

def self.hardware_info
  info = {}
  lines = ` pinout | grep ': '`
  lines << `cat /proc/cpuinfo | grep ': '`
  lines.split("\n").each do |line|
    key, value = line.split(':')
    key.strip!
    if key == 'processor'
      value = (value.to_i+1).to_s
      key = 'Cores'
    end
    key = 'CPU name' if key == 'model name'
    info[key] = value.strip
  end
  info
end

.model_name(source = 'proc') ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/raspberry_pi.rb', line 5

def self.model_name(source='proc')
  info = if source == 'proc'
    `cat /proc/device-tree/model`
  elsif
    `pinout | grep -Eo "Pi Model[^|]+"`
  else
    'N/A'
  end
  info.strip
end