teardown cleaned up

This commit is contained in:
Balthasar Reuter
2015-06-04 16:13:58 +02:00
parent d8b65b0d29
commit db922938cc

View File

@@ -382,10 +382,10 @@ def handle_gpio_event(channel):
elif channel == gpio_shutdown_channel: elif channel == gpio_shutdown_channel:
display.clear() display.clear()
print("Shutting down!") print("Shutting down!")
display.show_message("Shutting down!") display.show_message("\n\nShutting down!")
display.apply() display.apply()
sleep(1) sleep(1)
os.system("shutdown -h now") teardown(0, True)
def handle_exception(msg): def handle_exception(msg):
"""Displays an error message and returns""" """Displays an error message and returns"""
@@ -413,14 +413,15 @@ def setup_gpio():
def handle_gpio(channel): def handle_gpio(channel):
"""Interrupt handler for GPIO events""" """Interrupt handler for GPIO events"""
print("Channel " + str(channel) + " triggered")
display.trigger_event(gpio_pygame_event, channel) display.trigger_event(gpio_pygame_event, channel)
def teardown(exit_code=0): def teardown(exit_code=0, shutdown=False):
display.teardown() display.teardown()
if gpio_enabled: if gpio_enabled:
GPIO.cleanup() GPIO.cleanup()
exit(exit_code) exit(exit_code)
if shutdown:
os.system("shutdown -h now")
def main(): def main():
setup_gpio() setup_gpio()
@@ -429,7 +430,7 @@ def main():
display.mainloop(image_idle) display.mainloop(image_idle)
except CameraException as e: except CameraException as e:
handle_exception(e.message) handle_exception(e.message)
display.teardown() teardown()
return 0 return 0
######################## ########################