#!/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

if [ ${3} ]; then
    let offset=(${3}*32)
else
    let offset=0
fi

#read only first card found
for BUS in ${I2CCONFIGBUS};do 
    temp=$(${SCRIPT_PATH}/i2cutil -y -r ${BUS} ${I2CCONFIGADDRESS} ${offset} bl)
    rc=$?
    t=$(printf "%08x" ${temp})
    TYPE=${t:4:2}
    if [ "${1}x" = "x" -a ${TYPE} = '04' -a ${ismgb} = '1' ] ; then #thats a device eeprom maybe SMBUS missing --> check for MGB
        t="00000302"
    fi
    echo ${t:6:2}
    exit $rc
done

