JamesBarwell / rpi-gpio.js

Control Raspberry Pi GPIO pins with node.js
MIT License
657 stars 116 forks source link

Promises!! #54

Closed thecodershome closed 7 years ago

thecodershome commented 7 years ago

51

There are design choices I would appreciate input on. Calling setup, write and read with both an object and method parameters the object values will be used over method parameters. Also onSetup is only used when passed as a method parameter. Example:

Tested on a Raspberry Pi 1 Model B

JamesBarwell commented 7 years ago

This is great, really appreciate the effort.

Just from a brief glance, I think trying to support object and parameter arguments to the functions might be overcomplicating it a bit. But give me a couple of days to study this a bit more and have a go with it myself though before I give proper feedback.

I was originally thinking that rather than auto-detect how the functions are called, the promises API would be entirely separate and sit alongside the other one. Internally it would call the standard API. Something like this - what do you think?

var gpio = require('rpi-gpio').promise;

gpio.setup(7, gpio.DIR_IN)
  .then(() => {
    return gpio.read(7)
  })
  .then((value) => {
    console.log('The value is ' + value);
  })
thecodershome commented 7 years ago

I think that would be simpler to support. I'll put something together.