Create temp and cpu columns
This commit is contained in:
parent
075159b9ed
commit
43bcc3ba53
|
@ -5,34 +5,44 @@ from gpiozero import Button
|
||||||
from signal import pause
|
from signal import pause
|
||||||
from subprocess import check_call
|
from subprocess import check_call
|
||||||
from time import sleep
|
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:
|
class SystemStatus:
|
||||||
def __init__(self, hat):
|
def __init__(self, hat):
|
||||||
self.hat = hat
|
self.hat = hat
|
||||||
self.hat.set_brightness(0.1)
|
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):
|
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()
|
self.hat.show()
|
||||||
|
|
||||||
def exit(self):
|
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.set_all(0, 0, 0)
|
||||||
self.hat.show()
|
self.hat.show()
|
||||||
|
|
||||||
def terminate(self):
|
def terminate(self):
|
||||||
for _ in range(3):
|
for _ in range(3):
|
||||||
self.hat.set_all(50, 0, 0)
|
self.hat.set_all(0, 0, 0)
|
||||||
self.hat.show()
|
self.hat.show()
|
||||||
sleep(0.25)
|
sleep(0.25)
|
||||||
self.hat.set_all(0, 0, 0)
|
self.hat.set_all(255, 127, 0)
|
||||||
self.hat.show()
|
self.hat.show()
|
||||||
sleep(0.25)
|
sleep(0.25)
|
||||||
|
|
||||||
|
@ -46,7 +56,7 @@ def cleanExit(systemStatus, button):
|
||||||
return exit
|
return exit
|
||||||
|
|
||||||
|
|
||||||
def poweroff(systemStatus, button):
|
def poweroff(systemStatus):
|
||||||
def terminate():
|
def terminate():
|
||||||
systemStatus.terminate()
|
systemStatus.terminate()
|
||||||
check_call(['sudo', 'poweroff'])
|
check_call(['sudo', 'poweroff'])
|
||||||
|
@ -56,13 +66,14 @@ def poweroff(systemStatus, button):
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
systemStatus = SystemStatus(UnicornHATMini())
|
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))
|
signal.signal(signal.SIGTERM, cleanExit(systemStatus, powerButton))
|
||||||
|
|
||||||
powerButton.when_held = poweroff(systemStatus, powerButton)
|
powerButton.when_held = poweroff(systemStatus)
|
||||||
systemStatus.display()
|
|
||||||
|
|
||||||
pause()
|
while True:
|
||||||
|
systemStatus.display()
|
||||||
|
sleep(2)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in New Issue