jtguggedal / thingy_web_bluetooth

BSD 3-Clause "New" or "Revised" License
7 stars 4 forks source link

Reconsider functions like ledBreathe #6

Open kenchris opened 6 years ago

kenchris commented 6 years ago

These are kind of higher level animations/effects, so what about something like

thingy.led.breathe({ duration: 1500, ... }).then(() => console.log("animation stopped"))

It should probably receive an options array like above, so make it more clear what the numbers actually mean.

LED effects can actually easily turn a bit complicated, like look at Johnny Five

var led = new five.Led(11);

led.fade({
  easing: "outSine",
  duration: 1000,
  cuePoints: [0, 0.2, 0.4, 0.6, 0.8, 1],
  keyFrames: [0, 250, 25, 150, 100, 125],
  onstop: function() {
    console.log("Animation stopped");
  }
});

It might make some sense to align names etc with https://developer.mozilla.org/en-US/docs/Web/API/Animation

I also think it might make sense to just return a promise which executes when done instead on an onstop method.

jtguggedal commented 6 years ago

In the latest commit (in the async branch), the LED methods now receive options objects to make it more clear what the options are.

Currently the LED modes in use are the ones predefined in the firmware for animation (breathe and oneShot), but I assume it can be possible to use the constant LED feature to continuously send new RGB values that will make animation. I will look more into it, it certainly would be a nice to have more control over the LEDs.