]> git.gag.com Git - fw/quantimotor/commitdiff
add signal handler to put hardware back in a safe configuration on exit
authorBdale Garbee <bdale@gag.com>
Mon, 21 Apr 2025 08:46:46 +0000 (08:46 +0000)
committerBdale Garbee <bdale@gag.com>
Mon, 21 Apr 2025 08:46:46 +0000 (08:46 +0000)
application/app.py

index 26226a2d6a1b510afa9e5401efdd6a88124c1a87..8135eae38b0596e6a4dabba90001bc8094a59891 100755 (executable)
@@ -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 = {