From 9462cd7d2b64241c89737db73e06b47da28d0cd5 Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Tue, 7 Jan 2025 21:19:57 -0700 Subject: [PATCH] work to date on an application to run QuantiMotor --- application/quantimotor.py | 55 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100755 application/quantimotor.py diff --git a/application/quantimotor.py b/application/quantimotor.py new file mode 100755 index 0000000..99ee421 --- /dev/null +++ b/application/quantimotor.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python3 +# Copyright (C) 2025 Bdale Garbee . 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!") + -- 2.47.2