简体   繁体   中英

Real-time watch /dev file in a tail -f fashon

I have an andriod-based device that has a physical button on it, and it's state can be read via this file: /sys/class/gpio/gpio8/value with a 1 or 0 (a "device file"? Is there aa special word for this kind of file?).

I want to know if there is a way to watch this file, but without polling. I know I could do watch with a really small interval, however that seems like bad practice to me/there has to be another way.

Then the next step would be to determine how I could pipe that into an android application.

It is also worth noting that I do not believe that these buttons are integrated into the android sensors api/lib, otherwise I would just use that

I am looking for some direction on how to proceed. Is there really no way to actually watch for the button state aka when the button is pushed and the circuit is completed, there is no event pushed to the OS, the OS itself has to poll.

Thanks!

If GPIO driver supports pollable attributes via sysfs_notify() mechanism then you can use poll() in your program to wait for the state change. I know only two ways how to check this: a) read driver's source code and b) make a test and see if it works for you.

Some upcoming sysfs enhancements

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM