From d0a83fbe49064c81d0ea589342306635ac5a758c Mon Sep 17 00:00:00 2001 From: Mike Cifelli <1836280-mike-cifelli@users.noreply.gitlab.com> Date: Thu, 17 Jun 2021 09:39:49 -0400 Subject: [PATCH] Refactor code --- system-status.py | 50 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/system-status.py b/system-status.py index de03a08..6c9f124 100644 --- a/system-status.py +++ b/system-status.py @@ -8,31 +8,53 @@ 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] class SystemStatus: def __init__(self, hat): self.hat = hat self.hat.set_brightness(0.1) - self.hat.set_rotation(90) + self.hat.set_rotation(270) self.width, self.height = self.hat.get_shape() - self.cpuStartColumn = 0 - self.cpuEndColumn = int(self.width / 2) - 1 - self.tempStartColumn = int(self.width / 2) + 1 - self.tempEndColumn = self.width - 1 + self.tempStartColumn = 0 + self.tempEndColumn = int(self.width / 2) + self.cpuStartColumn = int(self.width / 2) + self.cpuEndColumn = self.width - 1 def display(self): - for x in range(self.cpuStartColumn, self.cpuEndColumn): - for y in range(self.height): - self.hat.set_pixel(x, y, 255, 0, 127) - - for x in range(self.tempStartColumn, self.tempEndColumn): - for y in range(self.height): - self.hat.set_pixel(x, y, 0, 127, 255) - + self.displayTemp() + self.displayCpu() self.hat.show() + def displayTemp(self): + self.displayField( + start=self.tempStartColumn, + end=self.tempEndColumn, + value=self.getTempValue(), + color=TEMP_COLOR + ) + + def displayCpu(self): + self.displayField( + start=self.cpuStartColumn, + end=self.cpuEndColumn, + value=self.getCpuValue(), + color=CPU_COLOR + ) + + def displayField(self, start, end, value, color): + for x in range(start, end): + for y in range(value): + self.hat.set_pixel(x, y, *color) + + def getTempValue(self): + return self.height + + def getCpuValue(self): + return self.height + def exit(self): self.hat.set_all(0, 0, 0) self.hat.show()