From 92fe576c4969252793a3bd9292c2aa89b944fa0a Mon Sep 17 00:00:00 2001 From: Mike Cifelli <1836280-mike-cifelli@users.noreply.gitlab.com> Date: Thu, 17 Jun 2021 11:19:01 -0400 Subject: [PATCH] Clean up code --- system-status.py | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/system-status.py b/system-status.py index 36722a7..c3c902d 100644 --- a/system-status.py +++ b/system-status.py @@ -9,12 +9,19 @@ from time import sleep from unicornhatmini import UnicornHATMini, BUTTON_A POWER_BUTTON_HOLD_TIME_IN_SECONDS = 1 -TEMP_COLOR = [64, 0, 0] -CPU_COLOR = [0, 16, 32] -NETWORK_COLOR = [64, 16, 0] -MAX_TEMP = 80 + +BLACK = [00, 00, 00] +RED = [64, 00, 00] +BLUE = [00, 16, 32] +ORANGE = [64, 16, 00] +PINK = [64, 00, 16] + +TEMP_COLOR = RED +CPU_COLOR = BLUE +NETWORK_COLOR = ORANGE + MIN_TEMP = 40 -BLACK = [0, 0, 0] +MAX_TEMP = 80 class SystemStatus: @@ -23,6 +30,7 @@ class SystemStatus: self.hat.set_brightness(0.1) self.hat.set_rotation(270) self.width, self.height = self.hat.get_shape() + self.tempStartColumn = 0 self.tempEndColumn = int(self.width / 2) self.cpuStartColumn = int(self.width / 2) @@ -30,6 +38,20 @@ class SystemStatus: self.networkStartColumn = self.width - 1 self.networkEndColumn = self.width + self.clear() + + def clear(self): + self.hat.set_all(0, 0, 0) + self.hat.show() + + def terminate(self): + for _ in range(3): + self.clear() + sleep(0.25) + self.hat.set_all(128, 0, 0) + self.hat.show() + sleep(0.25) + def display(self): self.displayTemp() self.displayCpu() @@ -83,24 +105,11 @@ class SystemStatus: return min(self.height, len(remoteConnections)) - def exit(self): - self.hat.set_all(0, 0, 0) - self.hat.show() - - def terminate(self): - for _ in range(3): - self.hat.set_all(0, 0, 0) - self.hat.show() - sleep(0.25) - self.hat.set_all(255, 127, 0) - self.hat.show() - sleep(0.25) - def cleanExit(systemStatus, button): def exit(signum, frame): button.close() - systemStatus.exit() + systemStatus.clear() sys.exit(0) return exit