#!/bin/bash

SCRIPT_PATH="$( cd "$( dirname "$0" )" && pwd )"

if [ -e /tmp/cmdline ]; then
    . /tmp/cmdline
fi

. ${SCRIPT_PATH}/i2csetup

if [ ${1} ]; then
    I2CCONFIGBUS=${1}
fi

if [ ${2} ]; then
    I2CCONFIGADDRESS=${2}
fi

#read only first card found
if [ -z "${I2CCONFIGBUS}" ] ; then
    cat "/data/serial.txt"
    exit 0;
else
    for BUS in ${I2CCONFIGBUS};do 
        i2crdhwserial=$(${SCRIPT_PATH}/i2cutil -y -r ${BUS} ${I2CCONFIGADDRESS} 12 bl) || exit 2
        
        if [ "${i2crdhwserial}" = "0xffffffff" ] ; then
            echo "i2crdhwserial: hwserial not set"
    	    exit 1
        else
    	    printf "%d " $(${SCRIPT_PATH}/i2cutil -y -r ${BUS} ${I2CCONFIGADDRESS} 12 bl)
        fi
    done
fi

printf "\n"

