From ae4b15678c33b35ede078448ae15d6977052af2b Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Mon, 21 Apr 2025 08:46:46 +0000 Subject: [PATCH] add signal handler to put hardware back in a safe configuration on exit --- application/app.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/application/app.py b/application/app.py index 26226a2..8135eae 100755 --- a/application/app.py +++ b/application/app.py @@ -11,6 +11,7 @@ import gpiod from gpiod.line import Direction, Value import sys +# set gpio lines def set_line_values(chip_path, line_values): value_str = {Value.ACTIVE: "Active", Value.INACTIVE: "Inactive"} @@ -22,6 +23,23 @@ def set_line_values(chip_path, line_values): }, ) request.set_values(line_values) + +# put hardware back in a safe configuration if application killed +def handler(signum, frame): + set_line_values( + "/dev/gpiochip0", + { 4: Value.INACTIVE, # indicate 'not ready' to LPC + 16: Value.INACTIVE, # pyro off + 17: Value.INACTIVE, # alarm b off + 20: Value.INACTIVE, # turn continuity LED off + 21: Value.INACTIVE, # turn armed LED off + 27: Value.INACTIVE # alarm a off + } + ) + sys.exit(0) + +# having systemd use SIGINT to avoid CherryPy consuming the kill signal +signal.signal(signal.SIGINT, handler) path = os.path.abspath(os.path.dirname(__file__)) config = { -- 2.47.2