2021-06-16 19:26:51 -04:00
|
|
|
from gpiozero import Button
|
|
|
|
from signal import pause
|
|
|
|
from subprocess import check_call
|
|
|
|
from time import sleep
|
2021-06-16 16:59:16 -04:00
|
|
|
from unicornhatmini import UnicornHATMini
|
2021-06-16 19:26:51 -04:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
def display(self):
|
|
|
|
self.hat.set(0, 0, 0, 0, 50)
|
|
|
|
self.hat.show()
|
|
|
|
|
|
|
|
def terminate(self):
|
|
|
|
self.hat.set_all(10, 0, 0)
|
|
|
|
self.hat.show()
|
|
|
|
sleep(0.25)
|
|
|
|
self.hat.set_all(0, 0, 0)
|
|
|
|
self.hat.show()
|
|
|
|
sleep(0.25)
|
|
|
|
self.hat.set_all(10, 0, 0)
|
|
|
|
self.hat.show()
|
|
|
|
|
|
|
|
|
|
|
|
def poweroff(systemStatus):
|
|
|
|
systemStatus.terminate()
|
|
|
|
sleep(1)
|
|
|
|
check_call(['sudo', 'poweroff'])
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
systemStatus = SystemStatus(UnicornHATMini())
|
|
|
|
powerButton = Button(POWER_BUTTON_GPIO_PIN, hold_time=HOLD_TIME_IN_SECONDS)
|
|
|
|
powerButton.when_held = poweroff(systemStatus)
|
|
|
|
powerButton.display()
|
|
|
|
pause()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|