]> git.gag.com Git - fw/quantimotor/commitdiff
craft and deliver to systemd a script to turn power off
authorBdale Garbee <bdale@gag.com>
Thu, 24 Jul 2025 22:19:50 +0000 (16:19 -0600)
committerBdale Garbee <bdale@gag.com>
Thu, 24 Jul 2025 22:19:50 +0000 (16:19 -0600)
debian/quantimotor.install
power-off.py [new file with mode: 0755]

index 38f315de1d57dc2508d0a3623d71e83ea628e1f6..2fc4fd1dc51de40fcc98314476bbe8c8066ae88c 100644 (file)
@@ -1,6 +1,7 @@
 ui/* usr/share/quantimotor/ui
 bcm2837-rpi-zero-2-w.dtb usr/share/quantimotor
 enable_ads.py usr/share/quantimotor
+power-off.py usr/lib/systemd/system-shutdown
 quantimotor.conf etc/modules-load.d
 raspi-extra-cmdline etc/default
 raspi-firmware-custom etc/default
diff --git a/power-off.py b/power-off.py
new file mode 100755 (executable)
index 0000000..be15f43
--- /dev/null
@@ -0,0 +1,50 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+#
+# Turn ourselves off by lowering the GPIO line in the soft power switch circuit
+# Copyright (C) 2025 Bdale Garbee <bdale@gag.com>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
+#
+
+import gpiod
+import signal
+import sys
+import time
+
+from gpiod.line import Direction, Value
+
+def set_line_values(chip_path, line_values):
+    value_str = {Value.ACTIVE: "Active", Value.INACTIVE: "Inactive"}
+
+    request = gpiod.request_lines(
+        chip_path,
+        consumer=sys.argv[0],
+        config={
+            tuple(line_values.keys()): gpiod.LineSettings(direction=Direction.OUTPUT)
+        },
+    )
+    request.set_values(line_values)
+
+if __name__ == "__main__":
+    try:
+        set_line_values(
+            "/dev/gpiochip0", 
+            {13: Value.INACTIVE,       # turn off soft power switch
+            }
+        )
+
+    except OSError as ex:
+        print(ex, "\nD'oh!  Powering off failed.")
+