pi-gpio icon indicating copy to clipboard operation
pi-gpio copied to clipboard

Listen for state changes

Open Ghommey opened this issue 13 years ago • 4 comments

Hi,

right now the gpio.read function uses fs.readFile: fs.readFile(sysFsPath + "/gpio" + pinMapping[pinNumber] + "/value", function(err, data) {

Is it possible to switch to fs.watch and raise the callback whenever the state changes? http://nodejs.org/api/fs.html#fs_fs_watch_filename_options_listener

Ghommey avatar Jan 21 '13 15:01 Ghommey

I recall another nodeJs GPIO repo had a similar issue as fs.Watch looks at file meta data to determine if a files been changed. For some reason it wasnt working..

// fs.watch doesn't get fired because the file never
// gets 'accessed' when setting header via hardware
// manually watching value changes

mikedevita avatar Apr 03 '13 21:04 mikedevita

Other libraries handle GPIO as interrupts which is probably the preferred method: http://code.google.com/p/raspberry-gpio-python/wiki/Inputs

thom-nic avatar Sep 27 '13 13:09 thom-nic

My thoughts, feel free to disagree:

I'm thinking of moving to wiring-pi as the underlying binary (this module currently uses quick2wire). The decision of which one is better was made at a time when it wasn't clear which one was the winner. wiring-pi has won today without doubt.

I'll be glad to work with anyone who can help with making awesome wiring-pi bindings. We can do this with fs-calls and using the the command line tool (child_process.spawn), but that feels wrong. Actual bindings with the library will be more fun, and will probably do better justice to the project.

Any thoughts about this?

rakeshpai avatar Sep 27 '13 20:09 rakeshpai

For now though, as a quick-fix, we could use fs.watchFile. It uses polling, so it isn't ideal, but it should work most of the time.

rakeshpai avatar Apr 12 '14 09:04 rakeshpai

How does wiring-pi implement interrupts?

This package claims to be using interrupts: https://github.com/fivdi/onoff

leefernandes avatar Apr 12 '14 14:04 leefernandes