dtex / j5e

Framework for embedded devices using ECMA-419, the ECMAScript® embedded systems API specification, based on Johnny-Five's API
https://www.j5e.dev/
MIT License
64 stars 6 forks source link

Signature for devices that require more than one IO #35

Closed dtex closed 4 years ago

dtex commented 4 years ago

Signature for devices that require more than one IO are kind of a mess. Take RGB for example. If you're just passing pin numbers and using the default IO (builtin/pwm) it could be:

const rgb = new RGB([12, 13, 14]);

But if you need usa a specific IO it could be:

const rgb = new RGB({
  pins: [12, 13, 14],
  io: PWM
});

But what if you want to use multiple IO providers? That would have to be:

const rgb = new RGB([
  { pin: 12, io: PWM },
  { pin: 13, io: ExpanderPWM },
  { pin: 14, io: PWM }
]);

or

const rgb = new RGB([
  12,
  { pin: 13, io: ExpanderPWM },
  14
]);

I need to make sure all of these cases are addressed. Any others?

dtex commented 4 years ago

It's either an array or not an array. If it's not an array, we need to normalize it to an array and then call normalizeParams on each member of the array.

dtex commented 4 years ago

Here's another pattern... If there are device params we could have:

const rgb = new RGB({
  pins: [12, 13, 14],
  io: PWM,
  sink: true
});

or worse, device params along with multiple providers:

const rgb = new RGB({
  pins: [12, { pin: 13, io: ExpanderPWM }, 14],
  sink: true
});