File size: 2,594 Bytes
69e3856 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | #!/bin/bash -e
# Pi-5 fixes baked into the image, kept outside the Python package so daemon updates don't wipe them.
echo "Fix 1/3: motor port -> /dev/ttyAMA3 (udev)"
install -d -m 0755 /etc/udev/rules.d
cat > /etc/udev/rules.d/99-reachy-pi5-motor.rules <<'RULE'
# /dev/ttyAMA3 = whichever motor bus exists (USB controller, or GPIO uart2)
SUBSYSTEM=="tty", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="55d3", SYMLINK+="ttyAMA3", GROUP="dialout", MODE="0660"
KERNEL=="ttyAMA2", SYMLINK+="ttyAMA3", GROUP="dialout", MODE="0660"
RULE
echo "Fix 2/3: shutdown button -> gpiozero lgpio backend"
install -d -m 0755 /etc/systemd/system/gpio-shutdown-daemon.service.d
cat > /etc/systemd/system/gpio-shutdown-daemon.service.d/10-pi5-lgpio.conf <<'DROP'
[Service]
Environment=GPIOZERO_PIN_FACTORY=lgpio
DROP
source /opt/uv/env 2>/dev/null || true
if [ -f /venvs/mini_daemon/bin/activate ]; then
source /venvs/mini_daemon/bin/activate
uv pip install lgpio || pip install lgpio || true
fi
echo "Fix 3/3: USB camera"
# free the camera from libcamera so the v4l2 path works
for plugin in /usr/local/lib/*/gstreamer-1.0/libgstlibcamera.so /usr/lib/*/gstreamer-1.0/libgstlibcamera.so; do
[ -f "$plugin" ] && mv "$plugin" "$plugin.disabled" || true
done
# fallback: find the camera ourselves if the daemon's detection returns nothing
cat > /venvs/mini_daemon/lib/python3.12/site-packages/sitecustomize.py <<'PY'
# ReachyPi: scan /dev/video* when get_video_device() finds no camera
import sys
def _camera_fallback():
try:
from reachy_mini.media import device_detection as dd
except Exception:
return
original = dd.get_video_device
def patched():
try:
path, specs = original()
if path:
return path, specs
except Exception:
pass
import glob, subprocess, platform
if platform.system() != "Linux":
return "", None
for dev in sorted(glob.glob("/dev/video*")):
try:
info = subprocess.run(["v4l2-ctl", "-d", dev, "--info"], capture_output=True, text=True, timeout=3).stdout
fmts = subprocess.run(["v4l2-ctl", "-d", dev, "--list-formats-ext"], capture_output=True, text=True, timeout=3).stdout
except Exception:
continue
if "Reachy" in info and "MJPG" in fmts:
sys.stderr.write("camera fallback: %s\n" % dev)
return dev, dd._make_camera_specs("Reachy")
return "", None
dd.get_video_device = patched
_camera_fallback()
PY
echo "Pi-5 fixes applied."
|