#!/bin/bash

. /tmp/cmdline
. /usr/bin/i2csetup

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

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

if [ -z "$(which i2cutil)" ] ; then
    #echo "i2crdarticle: i2cutil not found" >/dev/stderr
    echo 0
    exit 1
else
    #read only first card found
    for BUS in ${I2CCONFIGBUS};do 
        i2crdarticle=$(i2cutil -y -r ${BUS} ${I2CCONFIGADDRESS} 16 bl) || exit 2

        if [ "${i2crdarticle}" = "0xffffffff" ] ; then
            #echo "i2crdarticle: serial not set" >/dev/stderr
            echo 0
    	    exit 1
        else
    	    printf "%d" $(i2cutil -y -r ${BUS} ${I2CCONFIGADDRESS} 16 bl)
        fi
    done

    printf "\n"
fi

