diff --git a/system-status.py b/system-status.py index 193b5d8..f4db105 100644 --- a/system-status.py +++ b/system-status.py @@ -5,34 +5,44 @@ from gpiozero import Button from signal import pause from subprocess import check_call from time import sleep -from unicornhatmini import UnicornHATMini +from unicornhatmini import UnicornHATMini, BUTTON_A + +POWER_BUTTON_HOLD_TIME_IN_SECONDS = 1 -POWER_BUTTON_GPIO_PIN = 5 -HOLD_TIME_IN_SECONDS = 1 class SystemStatus: def __init__(self, hat): self.hat = hat self.hat.set_brightness(0.1) + self.hat.set_rotation(90) + self.width, self.height = self.hat.get_shape() + self.cpuStartColumn = 0 + self.cpuEndColumn = self.width / 2 - 1 + self.tempStartColumn = self.width / 2 + 1 + self.tempEndColumn = self.width - 1 def display(self): - self.hat.set_pixel(0, 0, 0, 0, 50) + 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.hat.show() def exit(self): - self.hat.set_all(50, 0, 0) - self.hat.show() - sleep(0.50) self.hat.set_all(0, 0, 0) self.hat.show() def terminate(self): for _ in range(3): - self.hat.set_all(50, 0, 0) + self.hat.set_all(0, 0, 0) self.hat.show() sleep(0.25) - self.hat.set_all(0, 0, 0) + self.hat.set_all(255, 127, 0) self.hat.show() sleep(0.25) @@ -46,7 +56,7 @@ def cleanExit(systemStatus, button): return exit -def poweroff(systemStatus, button): +def poweroff(systemStatus): def terminate(): systemStatus.terminate() check_call(['sudo', 'poweroff']) @@ -56,13 +66,14 @@ def poweroff(systemStatus, button): def main(): systemStatus = SystemStatus(UnicornHATMini()) - powerButton = Button(POWER_BUTTON_GPIO_PIN, hold_time=HOLD_TIME_IN_SECONDS) + powerButton = Button(BUTTON_A, hold_time=POWER_BUTTON_HOLD_TIME_IN_SECONDS) signal.signal(signal.SIGTERM, cleanExit(systemStatus, powerButton)) - powerButton.when_held = poweroff(systemStatus, powerButton) - systemStatus.display() + powerButton.when_held = poweroff(systemStatus) - pause() + while True: + systemStatus.display() + sleep(2) if __name__ == '__main__':