0

I am trying to read a value from a pseudo file in a linux system. Basically, I am using a pandaboard and trying to detect a change on GPIO pin. for the first time when I thought about it, I though of having a while(1) loop and keep opening the file and check its value if it is 0 or 1. This is stupid I know. The other way to solve is to have an interrupt or something to generate me an event or send me a signal whenever the content of the pseudo file changes. I have been searching for 3 days but no useful result. Any help ??

The file I would like to read is

/sys/class/gpio/gpio113/value

This is the input value of the button on the pandaboard.

I.el-sayed
  • 325
  • 1
  • 5
  • 18
  • Maybe you should consider [inotify(7)](http://man7.org/linux/man-pages/man7/inotify.7.html) with [poll(2)](http://man7.org/linux/man-pages/man2/poll.2.html) – Basile Starynkevitch Mar 05 '14 at 14:31
  • @BasileStarynkevitch I am not sure If I should use poll or not. Isn't poll should be inside a while loop ?? and keep "polling" the file ?? I want something like interrupts .. signals. I want the program to be doing something and whenever the file changes, the program stops what it is doing and execute another function. One more thing I believe inotify doesn't work with psudo-files isn't it?? – I.el-sayed Mar 05 '14 at 14:36
  • I'd be surprised if inotify worked on such pseudo-files. But isn't there a parallel set which is interrupt based (iirc, basically, reads block until the condition is met)? If not, consider extending the GPIO driver to provide such as it has been done for other embedded linux targets. – Chris Stratton Mar 05 '14 at 16:02
  • `/sys , /proc` are virtual filesystem , you can't access them sych as normal FS, search for `Virtual File System` – PersianGulf Mar 05 '14 at 17:56
  • @MohsenPahlevanzadeh Yeah I know the /sys and /proc are virtual file system ... the question how can I solve this problem !! ?? is there away to deal with the virtual file system or what ?? – I.el-sayed Mar 05 '14 at 18:47
  • Oh, i read again your post , you'd like to generate an automatically system, You have some option: 1. use hash of the given file. 2. using `lshw command` with direct parameter related to your device 3. use SYSFS APIs in a daemon which you have to write it. – PersianGulf Mar 05 '14 at 18:55

0 Answers0