Closed thecodershome closed 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);
})
I think that would be simpler to support. I'll put something together.
51
There are design choices I would appreciate input on. Calling
setup
,write
andread
with both an object and method parameters the object values will be used over method parameters. AlsoonSetup
is only used when passed as a method parameter. Example:setup({'channel': 7, 'direction': gpio.DIR_OUT}, gpio.DIR_IN)
will setup 7 as out.setup({'channel': 7, 'direction': null}, gpio.DIR_IN)
will throw invalid directionTested on a Raspberry Pi 1 Model B