Show temp and cpu values

This commit is contained in:
Mike Cifelli 2021-06-17 10:07:58 -04:00
parent d0a83fbe49
commit ee33eee44b
1 changed files with 9 additions and 2 deletions

View File

@ -1,3 +1,4 @@
import psutil
import sys import sys
import signal import signal
@ -10,6 +11,8 @@ from unicornhatmini import UnicornHATMini, BUTTON_A
POWER_BUTTON_HOLD_TIME_IN_SECONDS = 1 POWER_BUTTON_HOLD_TIME_IN_SECONDS = 1
TEMP_COLOR = [64, 0, 0] TEMP_COLOR = [64, 0, 0]
CPU_COLOR = [0, 16, 32] CPU_COLOR = [0, 16, 32]
MAX_TEMP = 80
MIN_TEMP = 40
class SystemStatus: class SystemStatus:
@ -50,10 +53,14 @@ class SystemStatus:
self.hat.set_pixel(x, y, *color) self.hat.set_pixel(x, y, *color)
def getTempValue(self): def getTempValue(self):
return self.height temp = psutil.sensors_temperatures()['cpu_thermal'][0].current
adjusted = max(0, temp - MIN_TEMP)
percent = min(1, adjusted / (MAX_TEMP - MIN_TEMP))
return int(self.height * percent)
def getCpuValue(self): def getCpuValue(self):
return self.height return int(self.height * (psutil.cpu_percent() / 100))
def exit(self): def exit(self):
self.hat.set_all(0, 0, 0) self.hat.set_all(0, 0, 0)