How to do GPIO on Android Things bypassing Java

和自甴很熟 提交于 2019-12-01 21:21:31

EDITED:

Run something like this everytime you're about to run the app (works for pin 24, replace with your preferred pin):

cd /sys/class/gpio
su root chmod a+w export
echo 24 > export
su root chmod a+w gpio24/direction
su root chmod a+w gpio24/value

ls gpio24/ -l

Unfortunately calling execl returns -1 and system returns 32256, so there's no way to replace this manual step. Even by trying system("/system/bin/date > /storage/self/primary/now "); will give 32256.

Then put together a script that listens to a named pipe and based on that runs the above code. After struggling a bit with su and chmod to make it easy to run I put together a C code that would write to that same pipe. Add 300ms wait for the pipe to be read and I'd start writing to gpio23/direction and gpio/value from C code from inside apk.

Led is getting lit, and as soon as I optimize the C code for a tighter loop I'll post some speed benchmarking.

Full solution here https://github.com/fmatosqg/androidthings_ndk/tree/SO_answer. Have a look at README.md for instructions.

To make it better I'd need to debug the named pipe reading because sometimes I read the wrong info. And also make the script start at boot.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!