#!/system/bin/busybox ash
#
# Linux shell MMPF0100 i2c 获取数据
# 说明:
# 本文主要记录通过shell脚本来获取MMPF0100的数据,更多的是为了更为
# 方便的获取到数据,在进行一些调试的时候能够更有效。
#
#2016-4-1深圳 南山平山村 曾剑锋
#
# 检查参数个数if [ $# -lt 3]; then
echo"USAGE:"echo"i2cData.sh "exit1fi
curPage=$1# 从第几页开始获取
byteCount=$(($3)) # 一次获取多少个字节
firstAddress=$(($2)) # 获取字节的首地址
i2cBusNumber=1# 采用哪个i2c总线
deviceAdress="0x08"# i2c设备地址
pageRegAddress="0x7f"# 存放页的寄存器地址
# 设置MMPF0100地址页
./i2cset -f -y $i2cBusNumber $deviceAdress $pageRegAddress $curPage
# 显示一些参数
echo"currentPage : $curPage"echo"firstAddress : $firstAddress"echo"byteCount : $byteCount"echo"i2cBus : /dev/dev-i2c$i2cBusNumber"echo"deviceAdress : $deviceAdress"echo"pageRegAddress : $pageRegAddress"echo
# 显示行对应的数
busybox printf"00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F"echo
# i是计数变量
i=$firstAddress
firstLine=true# 用于判断第一行是否需要填充0while [ $i -lt $(($byteCount+$firstAddress)) ]do# 16个字节一行,换行并输出行号if [ $((i%16)) -eq 0];then
busybox printf"\n0x%x0" $((i/16))
firstLine=false
else# 用于填充一行前面的0,更多的方便16进制查看数据if [ $firstLine -eq 0];then
padZero=$((i%16))
busybox printf"\n0x%x0"$padZero
# 循环填充数据
j=0
while [ $j -lt $padZero ]dobusybox printf"00"j=$((j+1))
done
firstLine=falsefi
fi
# 读取数据
data=`./i2cget -f -y $i2cBusNumber $deviceAdress $i`
busybox printf"%02x"$data
i=$((i+1))
done
echo
# 输出结果:
# [email protected]:/data/local # ./i2cData.sh 0 0x10 0x50# currentPage :0# firstAddress :16# byteCount :80# i2cBus :/dev/dev-i2c1
# deviceAdress :0x08# pageRegAddress :0x7f#
#00 01 02 03 04 05 06 07 08 090A 0B 0C 0D 0E 0F
#
#0x10 00 00 3f 00 00 00 00 00 00 00 00 10 00 00 00 00#0x20 2b 1b 2b 0c c4 00 00 00 00 00 00 00 00 002b 1b
#0x30 2b 0c c4 00 00 72 72 72 0c d4 00 002c 2c 2c 0c
#0x40 e4 00 00 2c 2c 2c 0c e4 00 00 6f 6f 6f 0c f4 00#0x50 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00