Linux下控制GPIO的方法有N种,详细请参考《RPi GPIO Code Samples》,文中用十多种语言演示了如何控制GPIO,非常全面详尽。因此,这里不再多做赘述,仅把调试过程中整理的脚本贴上并做简单的分析。特别说明,Linux必须有root权限!!!否则会出现/system/bin/sh: can't create /sys/class/gpio/export: Permission denied等错误。
@echo off
echo adb root
adb root >%temp%\_tmp
@findstr "already" %temp%\_tmp
@if NOT errorlevel goto config
timeout /T
:config
@echo on
adb shell chmod /sys/class/gpio/export
adb shell chmod /sys/class/gpio/unexport
adb shell echo ">" /sys/class/gpio/export
adb shell echo ">" /sys/class/gpio/export
adb shell chmod /sys/class/gpio/gpio62/direction
adb shell chmod /sys/class/gpio/gpio63/direction
adb shell chmod /sys/class/gpio/gpio62/value
adb shell chmod /sys/class/gpio/gpio63/value