#!/bin/bash
# i2c_scan_all.sh - 扫描当前系统所有 I2C 总线上的设备

set -e

if ! command -v i2cdetect >/dev/null 2>&1; then
    echo "未找到 i2cdetect，请先安装 i2c-tools："
    echo "  sudo apt install i2c-tools"
    exit 1
fi

echo "列出 I2C 总线："
i2cdetect -l
echo

buses=$(i2cdetect -l | awk '{print $1}' | sed 's/i2c-//')

for bus in $buses; do
    echo "==============================="
    echo "扫描 I2C bus $bus (/dev/i2c-$bus)"
    echo "==============================="
    i2cdetect -y "$bus"
    echo
done