Add a status LED driven by card events
The workstation app lit an LED on GPIO 23 with the card. This brings that
across, with three deliberate differences: it never blocks the reader, it
cannot be fatal, and its state is reported.
WMT toggled the LED directly inside card_inserted, on the reader thread, where
a slow write stalls card detection. Here every change is queued to a worker, so
insert() returns immediately (tested with a deliberately slow pin).
Two modes, because the light can mean two things:
error (default) lit while the reader runs, dark while reading, blinks on a
bad read - a health indicator
presence lit only while a card is on the reader
gpiozero raises BadPinFactory on a machine with no GPIO, and that subclasses
ImportError - so a single except ImportError reports 'gpiozero is not
installed' when the library is present but has no usable pin provider. The
library check and the pin construction are therefore separate.
Vendors gpiozero + colorzero (~180 KB) so the LED installs offline too, and
deliberately not setuptools: gpiozero declares it via colorzero, but it is only
a packaging requirement and is never imported at runtime. Installing to the
bundled wheels therefore uses --no-deps, saving 818 KB.
Verified end to end over a pseudo-terminal with a fake pin: a real RDM6300
frame drives the LED through the app's own CLI in both modes.
This commit is contained in:
@@ -105,6 +105,24 @@ else
|
||||
fi
|
||||
fi
|
||||
|
||||
# Status LED support. Best-effort: the reader works fine without a LED, so a
|
||||
# failure here must not stop the install.
|
||||
#
|
||||
# --no-deps is deliberate: gpiozero declares colorzero, which in turn declares
|
||||
# setuptools. setuptools is only a packaging requirement and is never imported
|
||||
# at runtime, so it is not vendored (it would add 818 KB for nothing).
|
||||
if [[ -d "$WHEEL_DIR" ]] && "$VENV_PY" -m pip install --quiet --no-index \
|
||||
--no-deps --find-links "$WHEEL_DIR" gpiozero colorzero 2>/dev/null; then
|
||||
echo " installed gpiozero + colorzero for the status LED (offline)"
|
||||
else
|
||||
if "$VENV_PY" -m pip install --quiet gpiozero colorzero 2>/dev/null; then
|
||||
echo " installed gpiozero + colorzero from PyPI"
|
||||
else
|
||||
warn "could not install LED support - the reader still works, the LED"
|
||||
warn "will be inactive. The app can install it later on first use."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Make the package importable. The .pth file adds src/ to sys.path, so
|
||||
# 'python -m rdm_card_reader' resolves from any working directory.
|
||||
SITE_PACKAGES="$("$VENV_PY" -c 'import sysconfig; print(sysconfig.get_paths()["purelib"])')"
|
||||
|
||||
Reference in New Issue
Block a user