Listen for state changes
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
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
Other libraries handle GPIO as interrupts which is probably the preferred method: http://code.google.com/p/raspberry-gpio-python/wiki/Inputs
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?
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.
How does wiring-pi implement interrupts?
This package claims to be using interrupts: https://github.com/fivdi/onoff