theoctal / octalbonescript

A more stable, continuously tested and better node.js library for scripting your BeagleBone
MIT License
57 stars 9 forks source link

attachInterrupt mode issue #37

Closed xavierzip closed 9 years ago

xavierzip commented 9 years ago

I have been testing the library and encountered an issue when attaching an interrupt to an input. Here is my testing code

var bone = require('octalbonescript');

var pin = 'P9_15';

bone.pinMode(pin, bone.INPUT_PULLUP, function(pinModeerr, pin){
    if (pinModeerr){
        console.error(pinModeerr.message); //output any error
        return;
    }else{
        console.log(pin+' initialized');
        bone.attachInterrupt(pin, bone.CHANGE, function(atItrperror, resp){
            if(attItrerr){
                console.log(attItrerr.message);
                return;
            }
        }, function(attItrerr){
            if(attItrerr){
                console.log(attItrerr.message);
                return;
            }else{
                console.log(pin+' attached to interrupt');
            }
        })
    }
})

And I got error: attachInterrupt: mode must be "rising", "falling" or "both". Invalid mode argument attachInterrupt: mode must be "rising", "falling" or "both". Invalid mode argument

Any idea what is happening? Many thanks in advance!

adityapatadia commented 9 years ago

You should write

bone.attachInterrupt(pin, bone.BOTH,

On 30-Apr-2015, at 1:40 pm, Xavier Mao notifications@github.com wrote:

I have been testing the library and encountered an issue when attaching an interrupt to an input. Here is my testing code

var bone = require('octalbonescript');

var pin = 'P9_15';

bone.pinMode(pin, bone.INPUT_PULLUP, function(pinModeerr, pin){ if (pinModeerr){ console.error(pinModeerr.message); //output any error return; }else{ console.log(pin+' initialized'); bone.attachInterrupt(pin, bone.CHANGE, function(atItrperror, resp){ if(attItrerr){ console.log(attItrerr.message); return; } }, function(attItrerr){ if(attItrerr){ console.log(attItrerr.message); return; }else{ console.log(pin+' attached to interrupt'); } }) } }) And I got error: attachInterrupt: mode must be "rising", "falling" or "both". Invalid mode argument attachInterrupt: mode must be "rising", "falling" or "both". Invalid mode argument

Any idea what is happening? Many thanks in advance!

— Reply to this email directly or view it on GitHub https://github.com/theoctal/octalbonescript/issues/37.

xavierzip commented 9 years ago

@adityapatadia Thank you for you reply. I have tried that, but there is error, even though it is different.

attachInterrupt: GPIO input file not opened: EINVAL, invalid argument attachInterrupt: GPIO input file not opened: EINVAL, invalid argument

DEBUG info is not really helpful in this case either. bone hw.exportGPIOControls(P9_15,in); +3ms bone gpio: 48 already exported. +4ms P9_15 initialized bone attachInterrupt(P9_15,function (atItrperror, resp){ if(attItrerr){ console.log(attItrerr.message); return; } },); +29ms attachInterrupt: GPIO input file not opened: EINVAL, invalid argument attachInterrupt: GPIO input file not opened: EINVAL, invalid argument

adityapatadia commented 9 years ago

I will try on my own board and get back to you within 1-2 days.

adityapatadia commented 9 years ago

Does this issue still persist? I am somewhat free to work on OBS. Let me know.

adityapatadia commented 9 years ago

I am sorry, the code you wrote first was perfect. There was actually a bug in library. It is fixed in v1.0.2. You should use bone.CHANGE only.

adityapatadia commented 9 years ago

One more thing I wanted to point. There is no need to write PULLUP code. Just the following code will do the job of enabling interrupt as of v1.0.3.


    bone.attachInterrupt(pin, bone.CHANGE, function(atItrperror, resp){
       if(attItrerr){
                console.log(attItrerr.message);
                return;
            }
        }, function(attItrerr){
            if(attItrerr){
                console.log(attItrerr.message);
                return;
            }else{
                console.log(pin+' attached to interrupt');
            }
        })
xavierzip commented 9 years ago

Hi there,

Thank you so much for your support. I have tested the lib, it works fine now :)