::
:: 脚本名称: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
执行结果: