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)