Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions myDevices/os/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@
import os
from glob import glob
from time import sleep
from myDevices.utils.logger import exception
from myDevices.utils.logger import debug,exception
from myDevices.os.hardware import Hardware

class CpuInfo(object):
"""Class for retrieving CPU info"""

def get_cpu_info(self):
"""Return CPU temperature, load average and usage info as a dict"""
info = {}
info['temperature'] = self.get_cpu_temp()
hardware = Hardware()
if hardware.getManufacturer() == "Pine" :
info['temperature'] = self.get_cpu_temp(1)
else:
info['temperature'] = self.get_cpu_temp(1000)
info["loadavg"] = self.get_load_avg()
info["usage"] = self.get_cpu_usage()
return info
Expand Down Expand Up @@ -39,7 +44,7 @@ def get_cpu_load(self, interval = 1):
exception('Error getting CPU load info')
return cpu_load

def get_cpu_temp(self):
def get_cpu_temp(self,divider = 1000.0):
"""Get CPU temperature"""
info = {}
thermal_dirs = glob('/sys/class/thermal/thermal_zone*')
Expand All @@ -54,7 +59,7 @@ def get_cpu_temp(self):
if thermal_type != 'gpu_thermal':
with open(thermal_dir + '/temp', 'r') as temp_file:
content = int(temp_file.read().strip())
temp = content / 1000.0
temp = content / divider
break
except:
pass
Expand Down
43 changes: 27 additions & 16 deletions myDevices/os/hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

class Hardware:
def __init__(self):
self.Architecture = "0"
self.Revision = "0"
try:
with open('/proc/cpuinfo','r') as f:
Expand All @@ -12,41 +13,51 @@ def __init__(self):
continue
key = splitLine[0].strip()
value = splitLine[1].strip()
if key=='CPU architecture':
self.Architecture = value
if key=='CPU revision':
self.Revision = value
if key=='Revision':
self.Revision = value
except:
exception ("Error reading cpuinfo")
self.model = 'Unknown'
if self.Revision == 'Beta':

if self.Architecture == 'AArch64':
self.manufacturer = 'Pine'
if self.Revision == '4':
self.model = 'A64+ 1GB'
else:
if self.Revision == 'Beta':
self.model = 'Model B (Beta)'
if self.Revision in ('000d', '000e', '000f', '0002', '0003', '0004', '0005', '0006'):
if self.Revision in ('000d', '000e', '000f', '0002', '0003', '0004', '0005', '0006'):
self.model = 'Model B'
if self.Revision in ('0007', '0008', '0009'):
if self.Revision in ('0007', '0008', '0009'):
self.model = 'Model A'
if self.Revision in ('0010', '0013', '900032'):
if self.Revision in ('0010', '0013', '900032'):
self.model = 'Model B +'
if self.Revision in ('0011', '0014'):
if self.Revision in ('0011', '0014'):
self.model = 'Compute Module'
if self.Revision in ('0012', '0015'):
if self.Revision in ('0012', '0015'):
self.model = 'Model A+'
if self.Revision in ('a01041', 'a21041', 'a22042'):
if self.Revision in ('a01041', 'a21041', 'a22042'):
self.model = 'Pi 2 Model B'
if self.Revision in ('900092', '900093'):
if self.Revision in ('900092', '900093'):
self.model = 'Zero'
if self.Revision in ('9000c1',):
if self.Revision in ('9000c1',):
self.model = 'Zero W'
if self.Revision in ('a02082', 'a22082'):
if self.Revision in ('a02082', 'a22082'):
self.model = 'Pi 3 Model B'
self.manufacturer = 'Element14/Premier Farnell'
if self.Revision in ('a01041', '900092', 'a02082', '0012', '0011', '0010', '000e', '0008', '0004'):
self.manufacturer = 'Element14/Premier Farnell'
if self.Revision in ('a01041', '900092', 'a02082', '0012', '0011', '0010', '000e', '0008', '0004'):
self.manufacturer = 'Sony, UK'
if self.Revision in ('0014', '0015', 'a21041', 'a22082'):
if self.Revision in ('0014', '0015', 'a21041', 'a22082'):
self.manufacturer = 'Embest, China'
if self.Revision in ('0005', '0009', '000f'):
if self.Revision in ('0005', '0009', '000f'):
self.manufacturer = 'Qisda'
if self.Revision in ('0006', '0007', '000d'):
if self.Revision in ('0006', '0007', '000d'):
self.manufacturer = 'Egoman'

def getManufacturer(self):
return self.manufacturer

Expand Down