#!/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 
        i2crdserial=$(${SCRIPT_PATH}/i2cutil -y -r ${BUS} ${I2CCONFIGADDRESS} 8 bl) || exit 2
        
        if [ "${i2crdserial}" = "0xffffffff" ] ; then
    	    echo "serial not set"
    	    exit 1
        else
    	    printf "%d " $(${SCRIPT_PATH}/i2cutil -y -r ${BUS} ${I2CCONFIGADDRESS} 8 bl)
        fi
    done
fi     


