Skip to content

Instantly share code, notes, and snippets.

@usefulthink
Created March 11, 2017 14:45
Show Gist options
  • Save usefulthink/6d7f66668671997fa5513ca00e1ac4f7 to your computer and use it in GitHub Desktop.
Save usefulthink/6d7f66668671997fa5513ca00e1ac4f7 to your computer and use it in GitHub Desktop.
A fivetwelve-driver that uses the node-dmx module to send data.
/**
* A fivetwelve-driver that uses a node-dmx instance to send data.
* It is assumed that fivetwelve will have full control over the node-dmx
* instance, concurrent changes via the node-dmx interface are not supported
* and probably wont do anything useful.
*
* @example
* import fivetwelve from 'fivetwelve';
* import DMX from 'dmx';
*
* const nodeDmx = new DMX();
* nodeDmx.addUniverse('universe1', 'enttec-usb-dmx-pro', '/dev/XXX');
* nodeDmx.addUniverse('universe2', 'enttec-usb-dmx-pro', '/dev/YYY');
*
* const output = fivetwelve(new NodeDmxDriver(nodeDmx, {
* 1: 'universe1',
* 2: 'universe2'
* }));
*/
class NodeDmxDriver {
/**
* @param {object} nodeDmx the node-dmx instance.
* @param {object} universeNameMapping a mapping of node-dmx universe names to
* (1-based) universe-numbers as used in the fivetwelve-library.
*/
constructor(nodeDmx, universeNameMapping = null) {
this.nodeDmx = nodeDmx;
this.universeNameMapping = universeNameMapping;
}
send(buffer, universe) {
const universeName = this.universeNameMapping[universe];
const driver = this.nodeDmx.universes[universeName];
// this is a bit hacky, but way more performant than any other way.
buffer.copy(driver.universe);
driver.send_universe();
}
}
@TimPietrusky
Copy link

It's working <3

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