Don't immediately poweroff
This commit is contained in:
parent
2a810ce1ec
commit
086a0afe0b
|
@ -1,3 +1,6 @@
|
||||||
|
import sys
|
||||||
|
import signal
|
||||||
|
|
||||||
from gpiozero import Button
|
from gpiozero import Button
|
||||||
from signal import pause
|
from signal import pause
|
||||||
from subprocess import check_call
|
from subprocess import check_call
|
||||||
|
@ -17,28 +20,59 @@ class SystemStatus:
|
||||||
self.hat.set(0, 0, 0, 0, 50)
|
self.hat.set(0, 0, 0, 0, 50)
|
||||||
self.hat.show()
|
self.hat.show()
|
||||||
|
|
||||||
def terminate(self):
|
def exit(self):
|
||||||
self.hat.set_all(10, 0, 0)
|
self.hat.set_all(0, 0, 50)
|
||||||
self.hat.show()
|
self.hat.show()
|
||||||
sleep(0.25)
|
sleep(0.25)
|
||||||
self.hat.set_all(0, 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(10, 0, 0)
|
self.hat.set_all(0, 0, 50)
|
||||||
|
self.hat.show()
|
||||||
|
sleep(0.25)
|
||||||
|
self.hat.set_all(0, 0, 0)
|
||||||
|
self.hat.show()
|
||||||
|
|
||||||
|
def terminate(self):
|
||||||
|
self.hat.set_all(50, 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(50, 0, 0)
|
||||||
|
self.hat.show()
|
||||||
|
sleep(0.25)
|
||||||
|
self.hat.set_all(0, 0, 0)
|
||||||
self.hat.show()
|
self.hat.show()
|
||||||
|
|
||||||
|
|
||||||
def poweroff(systemStatus):
|
def cleanExit(systemStatus, button):
|
||||||
|
def exit(signum, frame):
|
||||||
|
button.close()
|
||||||
|
systemStatus.exit()
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
return exit
|
||||||
|
|
||||||
|
|
||||||
|
def poweroff(systemStatus, button):
|
||||||
|
def terminate():
|
||||||
|
button.close()
|
||||||
systemStatus.terminate()
|
systemStatus.terminate()
|
||||||
sleep(1)
|
|
||||||
check_call(['sudo', 'poweroff'])
|
check_call(['sudo', 'poweroff'])
|
||||||
|
|
||||||
|
return terminate
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
systemStatus = SystemStatus(UnicornHATMini())
|
systemStatus = SystemStatus(UnicornHATMini())
|
||||||
powerButton = Button(POWER_BUTTON_GPIO_PIN, hold_time=HOLD_TIME_IN_SECONDS)
|
powerButton = Button(POWER_BUTTON_GPIO_PIN, hold_time=HOLD_TIME_IN_SECONDS)
|
||||||
powerButton.when_held = poweroff(systemStatus)
|
signal.signal(signal.SIGTERM, cleanExit(systemStatus, powerButton))
|
||||||
powerButton.display()
|
|
||||||
|
powerButton.when_held = poweroff(systemStatus, powerButton)
|
||||||
|
systemStatus.display()
|
||||||
|
|
||||||
pause()
|
pause()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue