一个测试GPIO是否可控的bat脚本


:: 
:: 脚本名称:verify_GPIO.bat
:: 脚本作用:用于测试GPIO是否能正常被export以及设置value为1或者0
:: 可以测试一个GPIO或者一系列GPIO,带一个参数则
:: GPIOBASE - 这个是需要测试的GPIO的BASE起始GPIO号,/sys/class/gpio/gpiochip*/base
:: gpiolist - 需要测试的GPIO列表
:: 脚本作者:Ben
:: 脚本时间:2021-12-07
::

@echo on
adb wait-for-device
adb root
adb wait-for-device
@echo off
setlocal enabledelayedexpansion
:: 以下值需要根据不同的项目或者需求进行修改
set /a GPIOBASE=355
set gpiolist=0,1,2,3,134
:: 以上值需要根据不同的项目或者需求进行修改

if "%1"=="" (
	echo.
) else (
	set /a gpio=%1
)
set tempResultFile="test_result_file.txt"
set tempfile="test_temp_file.txt"

echo ========== Test Result ============= > %tempResultFile%

if "%gpio%"=="" (
		for %%i in (%gpiolist%) do (
		call :testGpioFunc %%i
	)
	
) else (
	call :testGpioFunc %gpio%
)

rem pause
echo =========== Test END ============= >> %tempResultFile%
echo.
type %tempResultFile%
echo.
DEL %tempResultFile%
DEL %tempfile%
exit /b 2



:testGpioFunc

set temp=%1
set /a num=%temp%+%GPIOBASE%
echo "=== Test for GPIO%num%(%temp%)  ==="
::先判断目标文件夹是否存在,如果存在则不再export
adb shell "ls /sys/class/gpio/gpio%num% 2>&1 >/dev/null"

if %errorlevel%==0 (
	:: 这个目录存在
	echo "gpio%num% is exist. "
	goto testGpioFunc_setdir
)
adb shell "echo %num% > /sys/class/gpio/export"
::echo "after export: %errorlevel% "
if %errorlevel%==0 (
	goto testGpioFunc_setdir
) else (
	echo "GPIO%num%(%temp%) export fail"
	set errorstr=  error: export fail
	goto testGpioFunc_end_fail
)

:testGpioFunc_setdir
adb shell "echo out > /sys/class/gpio/gpio%num%/direction"

if %errorlevel%==0 (
	goto testGpioFunc_setval_0
) else (
	echo "GPIO%num%(%temp%) set direction fail"
	set errorstr=  error: set direction fail
	goto testGpioFunc_end_fail
)

:testGpioFunc_setval_0
echo "Set GPIO%num%(%temp%) to 0."
adb shell "echo 0 > /sys/class/gpio/gpio%num%/value"
::adb shell "cat /sys/class/gpio/gpio%num%/value"
adb shell "cat /sys/class/gpio/gpio%num%/value" > %tempfile%
set /P value=<%tempfile%
echo "Get GPIO%num%(%temp%) value=%value%"
if %value%==0 (
	goto testGpioFunc_setval_1
) else (
	set errorstr=  error:set val to 0, but get %value%
	goto testGpioFunc_end_fail
)

:testGpioFunc_setval_1
echo "Set GPIO%num%(%temp%) to 1. "
adb shell "echo 1 > /sys/class/gpio/gpio%num%/value"
::adb shell "cat /sys/class/gpio/gpio%num%/value"
adb shell "cat /sys/class/gpio/gpio%num%/value" > %tempfile%
set /P value=<%tempfile%
echo "Get GPIO%num%(%temp%) value=%value%"

if %value%==1 (
	goto testGpioFunc_end
) else (
	set errorstr=  error:set val to 1, but get %value%
	goto testGpioFunc_end_fail
)
goto testGpioFunc_end

:testGpioFunc_end_fail
echo GPIO%num%(%temp%) test fail... >> %tempResultFile%
echo %errorstr% >> %tempResultFile%
echo "=== Test GPIO%num%(%temp%) end ==="
echo.
goto:eof

:testGpioFunc_end
echo "=== Test GPIO%num%(%temp%) end ==="
echo.
echo GPIO%num%(%temp%) test success. >> %tempResultFile%
goto:eof

执行结果:

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值