Skip to content

Commit

Permalink
Added extraData parameter to update method and event (node-dmx#96)
Browse files Browse the repository at this point in the history
* Added origin parameter to update method and event

* Fixed origin being missing from final update event

* Changed origin parameter to extraData object

* Updated test with extraData parameter

* Added padding around object braces

* Updated readme
  • Loading branch information
DoctorMcKay authored May 21, 2020
1 parent 084462c commit d935b85
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 25 deletions.
4 changes: 2 additions & 2 deletions anim.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Anim {
...completedAnimations.map(a => a.to)
);

universe.update(completedAnimationStatesToSet);
universe.update(completedAnimationStatesToSet, { origin: 'animation' });
}

this.lastAnimation = currentAnimation;
Expand Down Expand Up @@ -130,7 +130,7 @@ class Anim {
startValue + easeProgress * (endValue - startValue)
);
}
universe.update(intermediateValues);
universe.update(intermediateValues, { origin: 'animation' });
}
}
};
Expand Down
4 changes: 2 additions & 2 deletions drivers/artnet.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ ArtnetDriver.prototype.close = function (cb) {
cb(null);
};

ArtnetDriver.prototype.update = function (u, _) {
ArtnetDriver.prototype.update = function (u, extraData) {
for (const c in u) {
this.universe[c] = u[c];
}

this.emit('update', u);
this.emit('update', u, extraData);
};

ArtnetDriver.prototype.updateAll = function (v, _) {
Expand Down
4 changes: 2 additions & 2 deletions drivers/bbdmx.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ BBDMX.prototype.close = function (cb) {
cb(null);
};

BBDMX.prototype.update = function (u) {
BBDMX.prototype.update = function (u, extraData) {
for (const c in u) {
this.universe[c] = u[c];
}

this.emit('update', u);
this.emit('update', u, extraData);
};

BBDMX.prototype.updateAll = function (v) {
Expand Down
4 changes: 2 additions & 2 deletions drivers/dmx4all.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ DMX4ALL.prototype.close = function (cb) {
this.dev.close(cb);
};

DMX4ALL.prototype.update = function (u) {
DMX4ALL.prototype.update = function (u, extraData) {
for (const c in u) {
this.universe[c] = u[c];
}

this.emit('update', u);
this.emit('update', u, extraData);
};

DMX4ALL.prototype.updateAll = function (v) {
Expand Down
4 changes: 2 additions & 2 deletions drivers/dmxking-ultra-dmx-pro.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ DMXKingUltraDMXPro.prototype.close = function (cb) {
this.dev.close(cb);
};

DMXKingUltraDMXPro.prototype.update = function (u) {
DMXKingUltraDMXPro.prototype.update = function (u, extraData) {
for (const c in u) {
this.universe[c] = u[c];
}

this.emit('update', u);
this.emit('update', u, extraData);
};

DMXKingUltraDMXPro.prototype.updateAll = function (v) {
Expand Down
4 changes: 2 additions & 2 deletions drivers/enttec-open-usb-dmx.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ EnttecOpenUsbDMX.prototype.close = function (cb) {
this.dev.close(cb);
};

EnttecOpenUsbDMX.prototype.update = function (u) {
EnttecOpenUsbDMX.prototype.update = function (u, extraData) {
for (const c in u) {
this.universe[c] = u[c];
}

this.emit('update', u);
this.emit('update', u, extraData);
};

EnttecOpenUsbDMX.prototype.updateAll = function (v) {
Expand Down
4 changes: 2 additions & 2 deletions drivers/enttec-usb-dmx-pro.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ EnttecUSBDMXPRO.prototype.close = function (cb) {
this.dev.close(cb);
};

EnttecUSBDMXPRO.prototype.update = function (u) {
EnttecUSBDMXPRO.prototype.update = function (u, extraData) {
for (const c in u) {
this.universe[c] = u[c];
}

this.emit('update', u);
this.emit('update', u, extraData);
};

EnttecUSBDMXPRO.prototype.updateAll = function (v) {
Expand Down
4 changes: 2 additions & 2 deletions drivers/null.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ NullDriver.prototype.close = cb => {
cb(null);
};

NullDriver.prototype.update = function (u, _) {
NullDriver.prototype.update = function (u, extraData) {
for (const c in u) {
this.universe[c] = u[c];
}
this.logUniverse();

this.emit('update', u);
this.emit('update', u, extraData);
};

NullDriver.prototype.updateAll = function (v, _) {
Expand Down
4 changes: 2 additions & 2 deletions drivers/socketio.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ SocketioDriver.prototype.close = cb => {
cb(null);
};

SocketioDriver.prototype.update = function (u) {
SocketioDriver.prototype.update = function (u, extraData) {
for (const c in u) {
this.universe[c] = u[c];
}
this.server.sockets.emit('update', [...this.universe]);
this.emit('update', u);
this.emit('update', u, extraData);
};

SocketioDriver.prototype.updateAll = function (v) {
Expand Down
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ class DMX {
addUniverse(name, driver, deviceId, options) {
this.universes[name] = new this.drivers[driver](deviceId, options);

this.universes[name].on('update', (channels) => {
this.emit('update', name, channels);
this.universes[name].on('update', (channels, extraData) => {
this.emit('update', name, channels, extraData);
});

return this.universes[name];
}

update(universe, channels) {
this.universes[universe].update(channels);
update(universe, channels, extraData) {
this.universes[universe].update(channels, extraData || {});
}

updateAll(universe, value) {
Expand Down
13 changes: 12 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ These drivers are currently registered by default:
Add a new DMX Universe with a name, driver and an optional device_id used by the driver to identify the device.
For enttec-usb-dmx-pro and enttec-open-usb-dmx device_id is the path the the serial device. For artnet it is the target ip.

#### dmx.update(universe, channels)
#### dmx.update(universe, channels[, extraData])

- <code>universe</code> - String, name of the universe
- <code>channels</code> - Object, keys are channel numbers, values the values to set that channel to
- <code>extraData</code> - Object, this data will be passed unmodified to the <code>update</code> Event. (Optional; default value is `{}`)

Update one or multiple channels of a universe. Also emits a <code>update</code> Event with the same information.

Expand Down Expand Up @@ -150,6 +151,16 @@ setTimeout(() => {
}, 5000)
```

#### update Event

- <code>universe</code> - String, name of the universe
- <code>channels</code> - Object, keys are channel numbers, values the values to set that channel to
- <code>extraData</code> - Object, data that was passed to the <code>update</code> method.

This event is emitted whenever <code>update</code> is called either by the integrating application or by an animation step.

If triggered by an animation step, <code>extraData.origin</code> will be the string <code>'animation'</code>.

## Webinterface

Versions prior to 0.2 included a Webinterface. This has since been moved into its own repository at <https://github.com/node-dmx/dmx-web>
Expand Down
4 changes: 2 additions & 2 deletions test/anim.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ test('fake timers', () => {

jest.runAllTimers();

expect(updateMock).toHaveBeenCalledWith({ 1: 255 });
expect(updateMock).toHaveBeenCalledWith({ 1: 0 });
expect(updateMock).toHaveBeenCalledWith({ 1: 255 }, { origin: 'animation' });
expect(updateMock).toHaveBeenCalledWith({ 1: 0 }, { origin: 'animation' });
});

test('real timers', done => {
Expand Down

0 comments on commit d935b85

Please sign in to comment.