Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T2 Issues #3

Open
reconbot opened this issue Oct 18, 2015 · 5 comments
Open

T2 Issues #3

reconbot opened this issue Oct 18, 2015 · 5 comments

Comments

@reconbot
Copy link

I'm not sure if these are the tessel issues or tessel-button issues, but lets figure that out!

var tessel = require('tessel');
var Button = require('tessel-gpio-button');

var buttonPin = tessel.port.A.pin[0];
var button = Button.use(buttonPin);
var led = tessel.port.B.pin[0];

led.output(0);

button.on('press', function(){
  led.output(1);
});

button.on('release', function(){
  led.output(0);
});

buttonPin is set to A0 and I get this error

INFO Running led-test.js...
/usr/lib/node/tessel-export.js:437
      throw new Error('Interrupts are not supported on pin ' + this.pin);
            ^
Error: Interrupts are not supported on pin 0
    at Tessel.Pin.addListener (/usr/lib/node/tessel-export.js:437:13)
    at new Button (/tmp/remote-script/node_modules/tessel-gpio-button/index.js:17:17)
    at Object.use (/tmp/remote-script/node_modules/tessel-gpio-button/index.js:67:10)
    at Object.<anonymous> (/tmp/remote-script/led-test.js:5:21)
    at Module._compile (module.js:426:26)
    at Object.Module._extensions..js (module.js:444:10)
    at Module.load (module.js:351:32)
    at Function.Module._load (module.js:306:12)
    at Function.Module.runMain (module.js:467:10)
    at startup (node.js:117:18)

The hardware pin mapping doesn't say pin 0 is any different other than that it's pulled up, that's unfortunate.

Alright lets try again with pin A2, since that should be like any other.

/usr/lib/node/tessel-export.js:446
        throw new Error('Cannot set pin interrupt mode to ' + mode +
              ^
Error: Cannot set pin interrupt mode to rise; already listening for fall
    at Tessel.Pin.addListener (/usr/lib/node/tessel-export.js:446:15)
    at new Button (/tmp/remote-script/node_modules/tessel-gpio-button/index.js:21:17)
    at Object.use (/tmp/remote-script/node_modules/tessel-gpio-button/index.js:67:10)
    at Object.<anonymous> (/tmp/remote-script/led-test.js:5:21)
    at Module._compile (module.js:426:26)
    at Object.Module._extensions..js (module.js:444:10)
    at Module.load (module.js:351:32)
    at Function.Module._load (module.js:306:12)
    at Function.Module.runMain (module.js:467:10)
    at startup (node.js:117:18)

What? I can confirm that again when I try to run something like this directly on the t2's repl.

var tessel = require('tessel');
var buttonPin = tessel.port.A.pin[2];
buttonPin.on('fall', console.log);
buttonPin.on('rise', console.log);

I get the same error.

@reconbot
Copy link
Author

Ahh, this is being tracked on tessel/hardware-modules#5

@dudleyjosh
Copy link

There are actually two issues related to using this for T2.

  1. Only pins 2, 5, 6 & 7 allow interrupts on the T2 and you can only add one event per pin (so rise/fall events have to become a single change event.

  2. The pin.read() function works differently between T1 & T2. T1 would allow a callback in the form of:

pin.read(function(value){});

Where as T2 expects:

pin.read(function(err, value){});

It may not be the best solution, but I got the following to work for both T1 & T2:

// Begin listening for events
  /*
  self.hardware.on('fall', function () {
    self._press();
  });

  self.hardware.on('rise', function () {
    self._release();
  });
  */
  self.hardware.on('change', function() {
    self.hardware.read(function(err, value) {
      if ( err && (err != 0 && err != 1) ) {
        console.log(err);
      }
      else if ( err == 0 || value == 0 ) {
        self._press();
      }
      else {
        self._release();
      }
    });
  });

  // Make sure the events get emitted, even if late
  setInterval(function () {
    /*
     if(!self.hardware.read()) {
     self._press();
     } else {
     self._release();
     }
     */
    self.hardware.read(function(err, value) {
      if ( err && (err != 0 && err != 1) ) {
        console.log(err);
      }
      else if ( err == 0 || value == 0 ) {
        self._press();
      }
      else {
        self._release();
      }
    });
  }, self.delay);

@tyler-g
Copy link

tyler-g commented Apr 24, 2016

@dudleyjosh thanks for this. I have the tessel2 and that change made this library work. Yes you're right the difference is in how the 1 and 2 interpret the .read method. Tessel2 passes error and then value whereas Tessel1 just passes value.

@dudleyjosh
Copy link

dudleyjosh commented Apr 25, 2016

@tyler-g FYI, I am working on PR-168 to make the T2 allow both a rise and fall event simultaneously again which will allow this button code to work exactly the way it was originally... with the exception of the one .read() which will have to be addressed per the example above.

@tyler-g
Copy link

tyler-g commented Apr 27, 2016

@dudleyjosh 👍 , glad to help if needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants