How To Do Gpio On Android Things Bypassing Java
Solution 1:
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 exportecho 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.
Post a Comment for "How To Do Gpio On Android Things Bypassing Java"