]> git.gag.com Git - fw/quantimotor/commitdiff
work to date on an application to run QuantiMotor
authorBdale Garbee <bdale@gag.com>
Wed, 8 Jan 2025 04:19:57 +0000 (21:19 -0700)
committerBdale Garbee <bdale@gag.com>
Wed, 8 Jan 2025 04:19:57 +0000 (21:19 -0700)
application/quantimotor.py [new file with mode: 0755]

diff --git a/application/quantimotor.py b/application/quantimotor.py
new file mode 100755 (executable)
index 0000000..99ee421
--- /dev/null
@@ -0,0 +1,55 @@
+#!/usr/bin/env python3
+# Copyright (C) 2025 Bdale Garbee <bdale@gag.com>.  GPLv3+
+
+import gpiod
+import signal
+import sys
+import time
+
+from gpiod.line import Direction, Value
+
+def handler(signum, frame):
+    print('Ctrl+C pressed, shutting down cleanly.')
+    set_line_values(
+        "/dev/gpiochip0", 
+        { 4: Value.INACTIVE,   # indicate 'not ready' to LPC
+         20: Value.INACTIVE,   # turn continuity LED off
+         21: Value.INACTIVE,   # turn armed LED off
+         25: Value.ACTIVE      # put ADS8688 in reset
+        }
+    )
+    exit(1)
+
+signal.signal(signal.SIGINT, handler)
+
+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:
+        # initialize hardware
+        set_line_values(
+            "/dev/gpiochip0", 
+            {25: Value.ACTIVE,         # take ADS8688 out of reset
+              4: Value.ACTIVE,         # indicate 'ready' to LPC
+             20: Value.ACTIVE,         # turn continuity LED on
+             21: Value.INACTIVE                # turn armed LED off
+            }
+        )
+        # Iterate until ctrl/c
+        while True:
+            print('tick')
+            time.sleep(1)
+
+    except OSError as ex:
+        print(ex, "\nD'oh!")
+