From: Bdale Garbee Date: Sat, 5 Apr 2025 04:35:03 +0000 (-0600) Subject: turn on systemd support, delivery a service, startup file, and module loader X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=c7f57f4d24f29a611f004bd6c00f5d5edd037b69;p=fw%2Fquantimotor turn on systemd support, delivery a service, startup file, and module loader --- diff --git a/debian/quantimotor.install b/debian/quantimotor.install index 2a45b1b..cc50a74 100644 --- a/debian/quantimotor.install +++ b/debian/quantimotor.install @@ -1,4 +1,7 @@ bcm2837-rpi-zero-2-w.dtb usr/share/quantimotor +enable_ads.py usr/share/quantimotor +quantimotor.conf etc/modules-load.d raspi-extra-cmdline etc/default raspi-firmware-custom etc/default +startup usr/share/quantimotor z99-quantimotor etc/kernel/postinst.d diff --git a/debian/rules b/debian/rules index eb2b855..59a5b1f 100755 --- a/debian/rules +++ b/debian/rules @@ -3,5 +3,5 @@ export DH_VERBOSE = 1 %: - dh $@ + dh $@ --with=systemd diff --git a/enable_ads.py b/enable_ads.py new file mode 100755 index 0000000..e5a9120 --- /dev/null +++ b/enable_ads.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python3 +# Copyright (C) 2025 Bdale Garbee . GPLv3+ + +import gpiod +import iio +import signal +import sys +import time + +ctx = iio.LocalContext() +ctrl = ctx.find_device('ads8688') + +# configuration for each channel on ADS8688 +OFFSET = "0" +SCALE = "0.078127104" +VOLTAGES = ['voltage0', 'voltage1', 'voltage2', 'voltage3', 'voltage4', 'voltage5', 'voltage6', 'voltage7'] + +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: + # initialize hardware + set_line_values( + "/dev/gpiochip0", + {25: Value.ACTIVE, # take ADS8688 out of reset + 4: Value.ACTIVE, # indicate '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 + } + ) + + # configure ADC channels + for id in VOLTAGES: + chan = ctrl.find_channel(id) + # must set scale before offset, so offset 0 is valid! + chan.attrs['scale'].value = SCALE + chan.attrs['offset'].value = OFFSET + + print('ADS set up .. do your thing!') + + + except OSError as ex: + print(ex, "\nD'oh!") + diff --git a/quantimotor.conf b/quantimotor.conf new file mode 100644 index 0000000..8dccec1 --- /dev/null +++ b/quantimotor.conf @@ -0,0 +1 @@ +iio-trig-hrtimer diff --git a/startup b/startup new file mode 100644 index 0000000..df373db --- /dev/null +++ b/startup @@ -0,0 +1,6 @@ +#!/bin/sh + +# set up gpio lines, enabling ADC and setting channel parameters +# /usr/share/quantimotor/enable_ads.py + +echo "quantimotor startup script ran" > /tmp/status