#!/bin/bash # Ensure we are in the script's directory cd "$(dirname "$0")" # Activate venv if it exists if [ -f "venv/bin/activate" ]; then source venv/bin/activate fi # Configuration for Raspberry Pi Headless Display (EGLFS/KMS) # Default to eglfs, but allow override # Usage: ./run_pi.sh [platform] # Example: ./run_pi.sh linuxfb # Initialize from argument or default # Check if running under X11 (DISPLAY is set) if [ -n "$DISPLAY" ]; then echo "X11 environment detected (DISPLAY=$DISPLAY). Using xcb." TARGET_PLATFORM="xcb" else # If DISPLAY is not set, use the provided argument or default to linuxfb TARGET_PLATFORM=${1:-linuxfb} fi # Diagnostic: Check for DRI devices if [ -z "$(ls /dev/dri/card* 2>/dev/null)" ] && [ "$TARGET_PLATFORM" == "eglfs" ]; then echo "WARNING: /dev/dri/card0 not found. Hardware acceleration (EGLFS) will likely fail." echo "Check /boot/config.txt for 'dtoverlay=vc4-kms-v3d'." echo "Switching to linuxfb..." TARGET_PLATFORM=linuxfb fi if [ "$TARGET_PLATFORM" == "linuxfb" ]; then export QSG_RENDER_LOOP=basic fi export QT_QPA_PLATFORM=$TARGET_PLATFORM # Fix for "EGLFS: Failed to open /dev/dri/card0" or similar when running as root/headless # Qt needs a runtime directory if [ -z "$XDG_RUNTIME_DIR" ]; then export XDG_RUNTIME_DIR=/tmp/runtime-root mkdir -p $XDG_RUNTIME_DIR chmod 700 $XDG_RUNTIME_DIR fi # For Raspberry Pi 4 with KMS (vc4-kms-v3d) export QT_QPA_EGLFS_INTEGRATION=eglfs_kms export QT_QPA_EGLFS_ALWAYS_SET_MODE=1 # export QT_LOGGING_RULES=qt.qpa.*=true # export QSGRENDERER_DEBUG=1 echo "Starting Volvo Display with platform: $TARGET_PLATFORM" if [ -f "./dist/volvodisplay" ]; then ./dist/volvodisplay else python3 main.py fi