diff --git a/README.md b/README.md index 74fda31..17d3398 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ chmod +x cec-control.sh | `scan` | Scan for CEC devices | `./cec-control.sh scan` | | `status` | Show CEC adapter status | `./cec-control.sh status` | | `info` | Show TV information | `./cec-control.sh info` | +| `fix` | Troubleshoot connection issues | `./cec-control.sh fix` | | `raw ` | Send raw CEC command | `./cec-control.sh raw 4f:82:10:00` | | `help` | Show help message | `./cec-control.sh help` | @@ -55,9 +56,48 @@ chmod +x cec-control.sh ## Troubleshooting -- **CEC not working**: Make sure CEC is enabled in your TV settings -- **Permission denied**: Run with `sudo` if needed -- **Device not found**: Check HDMI connection and try rescanning with `scan` command +### Common Issues + +**ioctl CEC_S_MODE failed - errno=16 (Device or resource busy)** + +This error means something else is using the CEC device. Try these solutions: + +1. Run the built-in fix command: +```bash +./cec-control.sh fix +``` + +2. Kill any existing CEC processes: +```bash +sudo killall cec-client +``` + +3. Check what's using the device: +```bash +sudo lsof /dev/cec0 +``` + +4. Try running with sudo: +```bash +sudo ./cec-control.sh scan +``` + +5. If using Kodi or LibreELEC, CEC may be enabled in the application. Disable it or stop the application first. + +**CEC not working** +- Make sure CEC is enabled in your TV settings (often called "HDMI Control", "CEC Control", or branded names like "Bravia Link", "Anynet+", etc.) +- Try a different HDMI port on your TV +- Check that the HDMI cable is properly connected + +**Permission denied** +- Add your user to the `video` group: `sudo usermod -aG video $USER` +- Then log out and back in +- Or run with `sudo` + +**Device not found** +- Check if `/dev/cec0` exists: `ls -l /dev/cec0` +- Ensure `cec-utils` is installed +- Try rebooting the Pi ## Advanced Usage diff --git a/cec-control.sh b/cec-control.sh index 14e08fd..a0857dc 100755 --- a/cec-control.sh +++ b/cec-control.sh @@ -41,6 +41,7 @@ Commands: scan Scan for CEC devices status Show CEC adapter status info Show TV information + fix Troubleshoot connection issues raw Send raw CEC command (hex) @@ -136,6 +137,46 @@ raw_command() { send_command "tx $cmd" } +fix_connection() { + echo "Attempting to fix CEC connection issues..." + echo "" + + # Check if running as root + if [ "$EUID" -ne 0 ]; then + echo "Checking for existing CEC processes..." + pgrep -a cec-client || echo "No cec-client processes found" + echo "" + echo "Trying with sudo - you may need to enter your password:" + echo "" + sudo "$0" "$@" + exit $? + fi + + echo "Running as root - checking CEC device status..." + echo "" + + # Check if device exists + if [ -e /dev/cec0 ]; then + echo "CEC device /dev/cec0 exists" + ls -l /dev/cec0 + echo "" + + # Check what's using the device + echo "Checking what's using the CEC device:" + lsof /dev/cec0 2>/dev/null || echo "Nothing is locking /dev/cec0" + echo "" + else + echo "Warning: /dev/cec0 does not exist" + echo "Available devices:" + ls -la /dev/cec* /dev/tty* 2>/dev/null | grep -E "cec|ttyAMA|ttyS0" || echo "No CEC devices found" + echo "" + fi + + echo "Attempting to scan for devices..." + echo "" + $CEC_CLIENT -s -d 1 < /dev/null +} + # Main script logic case "$1" in tv-on) @@ -174,6 +215,9 @@ case "$1" in info) show_info ;; + fix) + fix_connection + ;; raw) raw_command "$2" ;;