Add --led-active-low for inverted LED wiring
active_high was hardcoded to True, so an LED wired the other way round - cathode to the pin, anode to 3.3 V, or an inverting transistor driver - had no configuration at all. The symptom is easy to misread as a dark LED: the light actually does the opposite, on with no card and off with one. Exposed as --led-active-low on the app and on install.sh, which rewrites the unit's ExecStart like the other LED options. The startup line now names the polarity, so the journal says which configuration is actually running: LED on GPIO 23 (presence mode, active-high, gpiozero) Default is unchanged, so existing installs behave identically. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
+11
-4
@@ -13,6 +13,9 @@
|
||||
# --device PATH serial device the service opens (default /dev/serial0)
|
||||
# --led-pin N BCM GPIO number of the status LED (default 23)
|
||||
# --led-mode M 'presence' (default) or 'error'
|
||||
# --led-active-low LED wired active-low (cathode to the pin, anode to
|
||||
# 3.3 V, or an inverting driver); or the light will be on
|
||||
# with no card and off with one
|
||||
# --heartbeat S seconds before a silent reader counts as card removed
|
||||
# (default 2.0; this is also the presence/LED window)
|
||||
# --dir PATH install location (default /opt/rdm-card-reader)
|
||||
@@ -33,6 +36,7 @@ INSTALL_SERVICE=1
|
||||
SERIAL_DEVICE=/dev/serial0
|
||||
LED_PIN=23
|
||||
LED_MODE=presence
|
||||
LED_ACTIVE_LOW=0
|
||||
HEARTBEAT=2.0
|
||||
SOURCE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
|
||||
@@ -45,6 +49,7 @@ while [[ $# -gt 0 ]]; do
|
||||
--device) SERIAL_DEVICE="$2"; shift 2 ;;
|
||||
--led-pin) LED_PIN="$2"; shift 2 ;;
|
||||
--led-mode) LED_MODE="$2"; shift 2 ;;
|
||||
--led-active-low) LED_ACTIVE_LOW=1; shift ;;
|
||||
--heartbeat) HEARTBEAT="$2"; shift 2 ;;
|
||||
--no-service) INSTALL_SERVICE=0; shift ;;
|
||||
-h|--help) sed -n '2,33p' "$0"; exit 0 ;;
|
||||
@@ -274,11 +279,11 @@ for origin in "${ORIGINS[@]:-}"; do
|
||||
done
|
||||
|
||||
python3 - "$UNIT" "$INSTALL_DIR" "$BRIDGE_PORT" "$ORIGIN_ARGS" "$SERVICE_USER" \
|
||||
"$SERIAL_DEVICE" "$LED_PIN" "$LED_MODE" "$HEARTBEAT" <<'PY'
|
||||
"$SERIAL_DEVICE" "$LED_PIN" "$LED_MODE" "$LED_ACTIVE_LOW" "$HEARTBEAT" <<'PY'
|
||||
import os, re, sys
|
||||
|
||||
(unit, install_dir, port, origin_args, user, device, led_pin, led_mode,
|
||||
heartbeat) = sys.argv[1:10]
|
||||
led_active_low, heartbeat) = sys.argv[1:11]
|
||||
text = open(unit).read()
|
||||
|
||||
# The console script is created by the installer, but the .pth file is what
|
||||
@@ -288,11 +293,13 @@ wrapper = f"{install_dir}/.venv/bin/rdm-card-reader"
|
||||
if not os.path.exists(wrapper):
|
||||
wrapper = f"{install_dir}/.venv/bin/python -m rdm_card_reader"
|
||||
|
||||
led_active_args = " --led-active-low" if led_active_low == "1" else ""
|
||||
|
||||
command = (
|
||||
f"{wrapper} --serve "
|
||||
f"--port {device} --bridge-port {port} --mode login "
|
||||
f"--led-pin {led_pin} --led-mode {led_mode} --heartbeat {heartbeat}"
|
||||
f"{origin_args}"
|
||||
f"{led_active_args}{origin_args}"
|
||||
)
|
||||
|
||||
|
||||
@@ -348,7 +355,7 @@ $(log "Installed")
|
||||
|
||||
Bridge : http://127.0.0.1:$BRIDGE_PORT
|
||||
Device : $SERIAL_DEVICE
|
||||
LED : GPIO $LED_PIN, $LED_MODE mode
|
||||
LED : GPIO $LED_PIN, $LED_MODE mode$( [[ "$LED_ACTIVE_LOW" -eq 1 ]] && echo ", active-low" )
|
||||
Heartbeat : ${HEARTBEAT}s (presence/LED window)
|
||||
Card state : curl http://127.0.0.1:$BRIDGE_PORT/api/card
|
||||
Health : curl http://127.0.0.1:$BRIDGE_PORT/api/health
|
||||
|
||||
Reference in New Issue
Block a user