hybridgroup / cylon-gpio

Cylon drivers for GPIO devices
http://cylonjs.com
Other
19 stars 14 forks source link

Button driver doesn't work #22

Closed blalor closed 10 years ago

blalor commented 10 years ago

There are a couple of issues with the Button driver. I'm using the digispark connection, but I don't think this problem is specific to that connector.

From the example here:

var Cylon = require('cylon');

Cylon.robot({
  connection: { name: "digispark", adaptor: "digispark" },

  device: {name: 'button', driver: 'button', pin: 5},

  work: function(my) {
    my.button.on('push', function() {
      Logger.info("Button pushed!");
    });

    every(1000, function() {
        console.log("pressed?", my.button.isPressed());
    });
  }
}).start();
  1. the push event is never fired; I'd expect that it be triggered whenever the pin changes level
  2. Button#isPressed causes a stack trace:
/Users/blalor/devel/BSD/bum/node_modules/cylon/lib/utils.js:181
        return target[method].apply(target, args);
                              ^
TypeError: Object false has no method 'apply'
    at Device.base.(anonymous function) [as isPressed] (…/node_modules/cylon/lib/utils.js:181:31)
    at null.<anonymous> (…/button_test.js:14:31)
    at wrapper [as _onTimeout] (timers.js:258:14)
    at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
blalor commented 10 years ago

It also appears that the value of the pin is only read once, instead of periodically or updated via an interrupt.

edgarsilva commented 10 years ago

Let me take a look into this and I willl get back to you.

ericterpstra commented 10 years ago

I'm getting similar results with a Spark Core. I've connected a button following the diagram in the Cylon button docs (http://cylonjs.com/documentation/drivers/button/). The 'push' event will fire once after holding the button down for a second or two, but 'release' never happens.

At first I thought it was faulty wiring, but I tested using the Tinker iOS app which would accurately report HIGH for a digitalRead when the button was depressed.

Also, looking at the button code, it appears that isPressed is a primitive boolean rather than a function that returns a boolean.

deadprogram commented 10 years ago

There was a major new release of Cylon.js at the end of last week. @ericterpstra are you still having this problem?

edgarsilva commented 10 years ago

@blalor this has been fixed for digispark and will be released shortly in the next npm module release. In the meantime you can give it a try from the repo here:

https://github.com/hybridgroup/cylon-gpio/tree/development

That's the dev branch, you are now able to define an interval for the connection, the reads from the input will be read at the interval specified.

edgarsilva commented 10 years ago

This is an example for the button:

https://github.com/hybridgroup/cylon-digispark/blob/development/examples/button/button.js

ericterpstra commented 10 years ago

@deadprogram I just tried the dev branch from @edgarsilva and it appears to be working as expected now. Thanks!

edgarsilva commented 10 years ago

@ericterpstra great! I'll merge into master and cut a release of the NPM module this week and update here. Feel free to close the issue or wait for the npm module release :+1:

edgarsilva commented 10 years ago

This has should be solved already, closing the issue.