From ee33eee44b7be4ecadc5cb94fda5365fa5f63bc8 Mon Sep 17 00:00:00 2001 From: Mike Cifelli <1836280-mike-cifelli@users.noreply.gitlab.com> Date: Thu, 17 Jun 2021 10:07:58 -0400 Subject: [PATCH] Show temp and cpu values --- system-status.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/system-status.py b/system-status.py index 6c9f124..be84a2e 100644 --- a/system-status.py +++ b/system-status.py @@ -1,3 +1,4 @@ +import psutil import sys import signal @@ -10,6 +11,8 @@ from unicornhatmini import UnicornHATMini, BUTTON_A POWER_BUTTON_HOLD_TIME_IN_SECONDS = 1 TEMP_COLOR = [64, 0, 0] CPU_COLOR = [0, 16, 32] +MAX_TEMP = 80 +MIN_TEMP = 40 class SystemStatus: @@ -50,10 +53,14 @@ class SystemStatus: self.hat.set_pixel(x, y, *color) 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): - return self.height + return int(self.height * (psutil.cpu_percent() / 100)) def exit(self): self.hat.set_all(0, 0, 0)