Skip to content

Instantly share code, notes, and snippets.

@andrewn
Created February 4, 2015 14:53
Show Gist options
  • Save andrewn/2c4a46e0530a41c4d71b to your computer and use it in GitHub Desktop.
Save andrewn/2c4a46e0530a41c4d71b to your computer and use it in GitHub Desktop.

Physical UI config

The JSON config for the physical UI allows you to set-up initial transition defaults e.g.

Below you can see the "power" RGBLED has default transition options set. This means all transitions will happen over 750ms.

initialTransition is used to set-up the RGBLED when it's initialised and before any messages to change it's state are received. In this case, the LED will be transitions to the colour [200, 200, 200] over 5 seconds backwards and forwards repeatedly (yoyo).

...
  "RGBLEDs": [
    {
      "id": "power",
      "pins": [6,10,11],
      "colour": [200, 200, 200],
      "transitions": {
        "duration": 750
      },
      "initialTransition": {
        "duration": 5000,
        "yoyo": true
      }
    }
...

This is roughly mapped to:

var rgb = RGB.create(config.pins, anyOtherOpts);
rgb.transitions(config.transitions);

rgb.colour(config.colour, config.initialTransition);

message using rgbled.emit(content)

content = {
  colour: [255, 0, 128], // RGB colour
  transition: {
    duration: 1000, // in ms
    yoyo: true, // boolean
    easing: 'easingFuncName' // from this list http://easings.net/
  }
}

This is mapped to rgb.colour(content.colour, content.transition).

queueing using rgbled.queue(content)

content = {
  queue: [
    {
      colour: [0, 0, 255],
      transition: {
        duration: 1000
      }
    }, 
    {
      colour: [255, 0, 0],
    }
  ]
}

This allows a queuing of changes in a single message. The queue above will change RGBLED to blue over 1second, then change to red using default transitions (or instantly if no default transitions).

This maps to:

rgb.colour([0,0,255], { chain: true, duration: 1000}); rgb.colour([255, 0, 0]);

current status of LED .status()

This queries the current colour of the RGBLED and returns over the message bus.

https://github.com/radiodan/physical-ui/blob/master/lib/bootstrap.js#L189-L193

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment