tualo / node-pifacedigital

library and command line tool for pifacedigital
GNU General Public License v3.0
5 stars 7 forks source link

Watch using interrupts? #2

Open n9 opened 9 years ago

n9 commented 9 years ago

Are you going to use interrupts in the watch function? (Maybe using epoll for nodejs.)

thomashoffmann1979 commented 9 years ago

Hi, it sound's interesting. I will have a look at epoll.

n9 commented 9 years ago

I am playing with pifacedigital directly via node-ffi and common fs.watch works ok as well. (So epoll might not be needed.)

cardimajs commented 8 years ago

@n9
you could share your code using node-ffi and fs.whatch ?

n9 commented 8 years ago

Yes:

    async void EnsureInputWatcher()
    {
        if (inputWatcher != null)
            return;
        while (lib.pifacedigital_enable_interrupts() != 0)
        {
            await Task.Delay(100);
        }
        if (inputWatcher != null)
            return;
        var lastValue = lib.pifacedigital_read_reg(INPUT, hwAddress);
        inputWatcher = FS.Watch(GPIO_INTERRUPT_PIN_VALUE, (e, f) =>
        {
            var currentValue = lib.pifacedigital_read_reg(INPUT, hwAddress);
            if (currentValue != lastValue)
            {
                HandleWatchInput(currentValue, lastValue);
                lastValue = currentValue;
            }
        });
    }

(It is not in plain JavaScript. It's written in C#.)