diff --git a/myDevices/os/cpu.py b/myDevices/os/cpu.py index 0b9f36a..18a01ce 100644 --- a/myDevices/os/cpu.py +++ b/myDevices/os/cpu.py @@ -2,7 +2,8 @@ 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""" @@ -10,7 +11,11 @@ class CpuInfo(object): 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 @@ -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*') @@ -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 diff --git a/myDevices/os/hardware.py b/myDevices/os/hardware.py index 0db63d7..3e7181a 100644 --- a/myDevices/os/hardware.py +++ b/myDevices/os/hardware.py @@ -3,6 +3,7 @@ class Hardware: def __init__(self): + self.Architecture = "0" self.Revision = "0" try: with open('/proc/cpuinfo','r') as f: @@ -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