-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgetcpu.py
57 lines (43 loc) · 1.71 KB
/
getcpu.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/python
## This file fetches CPU load values and relates them to the caller. This file is used in place of the
from __future__ import division
import copy
import math
import sys
import os
import psutil
import time
class led_display(object):
def __init__(self):
pass
def toggle(self):
pass
# Function to draw a pretty pattern to the display.
def animate(self):
pass
def translate(value, leftMin, leftMax, rightMin, rightMax):
# Figure out how 'wide' each range is
leftSpan = leftMax - leftMin
rightSpan = rightMax - rightMin
# Convert the left range into a 0-1 range (float)
valueScaled = float(value - leftMin) / float(leftSpan)
# Convert the 0-1 range into a value in the right range.
return rightMin + (valueScaled * rightSpan)
def sensorget():
statusram = psutil.virtual_memory()
sensordict = {'humidity': 0, 'temp':0, 'humidtemp':0, 'pressuretemp':0,'pressure':0,'compass':0}
sensordict['humidity'] = psutil.cpu_percent()
sensordict['temp'] = psutil.sensors_temperatures()['acpitz'][0].current
sensordict['humidtemp'] = psutil.cpu_percent()
sensordict['pressuretemp'] = psutil.cpu_percent()
sensordict['pressure'] = translate(statusram.percent, 0, 100, 260, 1260)
#psutil.disk_usage('/').percent + 260
sensordict['compass'] = {"x" : 2, "y" : 2, "z" : 3}
return sensordict
def printscreen(sensordict):
print("Temperature: %s C" % sensordict['temp'])
print("Temperature from humidity: %s C" % sensordict['humidtemp'])
print("Temperature from pressure: %s C" % sensordict['pressuretemp'])
print("Pressure: %s Millibars" % sensordict['pressure'])
print("Humidity: %s %%rH" % sensordict['humidity'])
print("North: %s" % sensordict['compass'])