Merge pull request #70 from Fensterbank/feature/library

Modernize code and enforcing eslint rules
This commit is contained in:
Frédéric Bolvin 2018-12-29 16:19:03 +01:00 committed by GitHub
commit 65f24c5031
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 1192 additions and 987 deletions

12
.editorconfig Normal file
View file

@ -0,0 +1,12 @@
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = LF
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false

179
.eslintrc Normal file
View file

@ -0,0 +1,179 @@
{
"env": {
"browser": true,
"es6": true,
"node": true
},
"globals": {
"document": false,
"escape": false,
"navigator": false,
"unescape": false,
"window": false,
"describe": true,
"before": true,
"it": true,
"expect": true,
"sinon": true
},
"parser": "babel-eslint",
"plugins": [
],
"rules": {
"block-scoped-var": 2,
"brace-style": [2, "1tbs", { "allowSingleLine": true }],
"camelcase": [2, { "properties": "always" }],
"comma-dangle": [2, "always-multiline"],
"comma-spacing": [2, { "before": false, "after": true }],
"comma-style": [2, "last"],
"complexity": 0,
"consistent-return": 2,
"consistent-this": 0,
"curly": [2, "multi-line"],
"default-case": 0,
"dot-location": [2, "property"],
"dot-notation": 0,
"eol-last": 2,
"eqeqeq": [2, "allow-null"],
"func-names": 0,
"func-style": 0,
"generator-star-spacing": [2, "both"],
"guard-for-in": 0,
"handle-callback-err": [0, "^(err|error|anySpecificError)$" ],
"indent": [2, 2, { "SwitchCase": 1 }],
"key-spacing": [2, { "beforeColon": false, "afterColon": true }],
"keyword-spacing": [2, {"before": true, "after": true}],
"linebreak-style": 0,
"max-depth": 0,
"max-len": [2, 120, 4],
"max-nested-callbacks": 0,
"max-params": 0,
"max-statements": 0,
"new-cap": [2, { "newIsCap": true, "capIsNew": false }],
"newline-after-var": [2, "always"],
"new-parens": 2,
"no-alert": 0,
"no-array-constructor": 2,
"no-bitwise": 0,
"no-caller": 2,
"no-catch-shadow": 0,
"no-cond-assign": 2,
"no-console": 0,
"no-constant-condition": 0,
"no-continue": 0,
"no-control-regex": 2,
"no-debugger": 2,
"no-delete-var": 2,
"no-div-regex": 0,
"no-dupe-args": 2,
"no-dupe-keys": 2,
"no-duplicate-case": 2,
"no-else-return": 2,
"no-empty": 0,
"no-empty-character-class": 2,
"no-eq-null": 0,
"no-eval": 2,
"no-ex-assign": 2,
"no-extend-native": 2,
"no-extra-bind": 2,
"no-extra-boolean-cast": 2,
"no-extra-parens": 0,
"no-extra-semi": 0,
"no-extra-strict": 0,
"no-fallthrough": 2,
"no-floating-decimal": 2,
"no-func-assign": 2,
"no-implied-eval": 2,
"no-inline-comments": 0,
"no-inner-declarations": [2, "functions"],
"no-invalid-regexp": 2,
"no-irregular-whitespace": 2,
"no-iterator": 2,
"no-label-var": 2,
"no-labels": 2,
"no-lone-blocks": 0,
"no-lonely-if": 0,
"no-loop-func": 0,
"no-mixed-requires": 0,
"no-mixed-spaces-and-tabs": [2, false],
"no-multi-spaces": 2,
"no-multi-str": 2,
"no-multiple-empty-lines": [2, { "max": 1 }],
"no-native-reassign": 2,
"no-negated-in-lhs": 2,
"no-nested-ternary": 0,
"no-new": 2,
"no-new-func": 2,
"no-new-object": 2,
"no-new-require": 2,
"no-new-wrappers": 2,
"no-obj-calls": 2,
"no-octal": 2,
"no-octal-escape": 2,
"no-path-concat": 0,
"no-plusplus": 0,
"no-process-env": 0,
"no-process-exit": 0,
"no-proto": 2,
"no-redeclare": 2,
"no-regex-spaces": 2,
"no-reserved-keys": 0,
"no-restricted-modules": 0,
"no-return-assign": 2,
"no-script-url": 0,
"no-self-compare": 2,
"no-sequences": 2,
"no-shadow": 0,
"no-shadow-restricted-names": 2,
"no-spaced-func": 2,
"no-sparse-arrays": 2,
"no-sync": 0,
"no-ternary": 0,
"no-throw-literal": 2,
"no-trailing-spaces": 2,
"no-undef": 2,
"no-undef-init": 2,
"no-undefined": 0,
"no-underscore-dangle": 0,
"no-unneeded-ternary": 2,
"no-unreachable": 1,
"no-unused-expressions": 0,
"no-unused-vars": [2, { "vars": "all", "args": "none" }],
"no-use-before-define": 2,
"no-var": 2,
"no-void": 0,
"no-warning-comments": 0,
"no-with": 2,
"one-var": 0,
"operator-assignment": 0,
"operator-linebreak": [2, "after"],
"padded-blocks": 0,
"prefer-const": 2,
"quote-props": 0,
"quotes": [2, "single", "avoid-escape"],
"radix": 2,
"semi": [2, "always"],
"semi-spacing": 0,
"sort-vars": 0,
"space-before-blocks": [2, "always"],
"space-before-function-paren": [2, {"anonymous": "always", "named": "never"}],
"space-in-brackets": 0,
"space-in-parens": [2, "never"],
"space-infix-ops": 2,
"space-unary-ops": [2, { "words": true, "nonwords": false }],
"spaced-comment": [2, "always"],
"strict": 2,
"use-isnan": 2,
"valid-jsdoc": 0,
"valid-typeof": 2,
"vars-on-top": 0,
"wrap-iife": [2, "any"],
"wrap-regex": 0,
"yoda": [2, "never"]
}
}

6
.gitignore vendored
View file

@ -15,3 +15,9 @@ results
node_modules
.project
.com.greenworldsoft.syncfolderspro
# Remove some common IDE working directories
.idea
.vscode
.DS_Store

116
anim.js
View file

@ -1,81 +1,83 @@
"use strict"
const ease = require('./easing.js').ease;
const resolution = 25;
var ease = require('./easing.js').ease
var resolution = 25
class Anim {
constructor() {
this.fxStack = [];
this.interval = null;
}
function Anim() {
this.fx_stack = []
this.interval = null
}
Anim.prototype.add = function(to, duration, options) {
var options = options || {}
var duration = duration || resolution
add(to, duration = resolution, options = {}) {
options.easing = options.easing || 'linear';
this.fx_stack.push({'to': to, 'duration': duration, 'options': options})
return this
}
Anim.prototype.delay = function(duration) {
return this.add({}, duration)
}
Anim.prototype.stop = function () {
if(this.interval) {
clearInterval(this.interval)
this.fxStack.push({ 'to': to, 'duration': duration, 'options': options });
return this;
}
this.fx_stack = []
}
Anim.prototype.run = function(universe, onFinish) {
var config = {}
var ticks = 0
var duration = 0
var animationStep
delay(duration) {
this.add({}, duration);
return this;
}
var fx_stack = this.fx_stack;
var ani_setup = function() {
animationStep = fx_stack.shift()
ticks = 0
duration = animationStep.duration
stop() {
if (this.interval) {
clearInterval(this.interval);
}
this.fxStack = [];
}
config = {}
for (var k in animationStep.to) {
run(universe, onFinish) {
let config = {};
let ticks = 0;
let duration = 0;
let animationStep;
let iid = null;
const stack = [ ...this.fxStack ];
const aniSetup = () => {
animationStep = stack.shift();
ticks = 0;
duration = animationStep.duration;
config = {};
for (const k in animationStep.to) {
config[k] = {
'start': universe.get(k),
'end': animationStep.to[k],
'options': animationStep.options
'options': animationStep.options,
};
}
}
}
var ani_step = function() {
var newValues = {}
for (var k in config) {
var entry = config[k]
var easing = ease[entry.options.easing]
};
const aniStep = () => {
const newValues = {};
newValues[k] = Math.round(entry.start + easing(ticks, 0, 1, duration) * (entry.end - entry.start))
for (const k in config) {
const entry = config[k];
const easing = ease[entry.options.easing];
newValues[k] = Math.round(entry.start + easing(ticks, 0, 1, duration) * (entry.end - entry.start));
}
ticks = ticks + resolution
universe.update(newValues)
ticks = ticks + resolution;
universe.update(newValues);
if (ticks > duration) {
if (fx_stack.length > 0) {
ani_setup()
if (stack.length > 0) {
aniSetup();
} else {
clearInterval(iid)
if(onFinish) {
onFinish()
}
clearInterval(iid);
if (onFinish) {
onFinish();
}
}
}
};
ani_setup()
var iid = this.interval = setInterval(ani_step, resolution)
aniSetup();
iid = this.interval = setInterval(aniStep, resolution);
return this
return this;
}
}
module.exports = Anim
module.exports = Anim;

71
demo.js
View file

@ -1,56 +1,55 @@
"use strict"
const DMX = require('./dmx');
var DMX = require('./dmx')
var dmx = new DMX();
var A = dmx.animation;
const dmx = new DMX();
const A = dmx.animation;
// var universe = dmx.addUniverse('demo', 'enttec-usb-dmx-pro', '/dev/cu.usbserial-6AVNHXS8')
// var universe = dmx.addUniverse('demo', 'enttec-open-usb-dmx', '/dev/cu.usbserial-6AVNHXS8')
var universe = dmx.addUniverse('demo', 'null')
const universe = dmx.addUniverse('demo', 'null');
universe.update({1: 1, 2: 0})
universe.update({16: 1, 17: 255})
universe.update({1: 255, 3: 120, 4: 230, 5: 30, 6: 110, 7: 255, 8: 10, 9: 255, 10: 255, 11: 0})
universe.update({1: 1, 2: 0});
universe.update({16: 1, 17: 255});
universe.update({1: 255, 3: 120, 4: 230, 5: 30, 6: 110, 7: 255, 8: 10, 9: 255, 10: 255, 11: 0});
function done() {console.log('DONE')}
function done() {console.log('DONE');}
function green_water(universe, channels, duration) {
var colors = [
function greenWater(universe, channels, duration) {
const colors = [
[160, 230, 20],
[255, 255, 0],
[110, 255, 10]
]
[110, 255, 10],
];
for(var c in channels) {
var r = Math.floor((Math.random()*colors.length))
var u = {}
for (const c in channels) {
const r = Math.floor((Math.random() * colors.length));
const u = {};
for(var i = 0; i < 3; i++) {
u[channels[c] + i] = colors[r][i]
for (let i = 0; i < 3; i++) {
u[channels[c] + i] = colors[r][i];
}
new A().add(u, duration).run(universe)
new A().add(u, duration).run(universe);
}
setTimeout(function() {green_water(universe, channels, duration);}, duration * 2)
setTimeout(function () {greenWater(universe, channels, duration);}, duration * 2);
}
function warp(universe, channel, min, max, duration) {
var a = {}, b = {}
const a = {}, b = {};
a[channel] = min;
b[channel] = max;
new A().add(a, duration).add(b, duration).run(universe, function() {
warp(universe, channel, min, max, duration)
})
new A().add(a, duration).add(b, duration).run(universe, function () {
warp(universe, channel, min, max, duration);
});
}
warp(universe, 1, 200, 220, 360)
warp(universe, 1+15, 200, 255, 240)
green_water(universe, [3, 6, 9], 4000)
green_water(universe, [3+15, 6+15, 9+15], 4000)
warp(universe, 1, 200, 220, 360);
warp(universe, 1 + 15, 200, 255, 240);
greenWater(universe, [3, 6, 9], 4000);
greenWater(universe, [3 + 15, 6 + 15, 9 + 15], 4000);
return
return;
var x = new A()
const x = new A()
.add({1: 255, 6: 110, 7: 255, 8: 10}, 1200)
.delay(1000)
.add({1: 0}, 600)
@ -76,10 +75,10 @@ var x = new A()
.delay(50)
.add({2: 255}, 6000)
.delay(200)
.add({2: 0})
.add({2: 0});
var y = new A()
.add({9: 255}, 10000)
const y = new A()
.add({9: 255}, 10000);
x.run(universe, done)
y.run(universe, done)
x.run(universe, done);
y.run(universe, done);

View file

@ -1,22 +1,20 @@
"use strict"
const DMX = require('./dmx');
var DMX = require('./dmx');
var dmx = new DMX();
var A = dmx.animation;
const dmx = new DMX();
// var universe = dmx.addUniverse('demo', 'enttec-open-usb-dmx', '/dev/cu.usbserial-6AVNHXS8')
var universe = dmx.addUniverse('demo', 'null')
const universe = dmx.addUniverse('demo', 'null');
var on = false;
setInterval(function(){
if(on){
let on = false;
setInterval(() => {
if (on) {
on = false;
universe.updateAll(0);
console.log("off");
}else{
console.log('off');
} else {
on = true;
universe.updateAll(250);
console.log("on");
console.log('on');
}
}, 1000);

View file

@ -1,44 +1,57 @@
module.exports = {
'generic': {
channels: ['dimmer']
channels: ['dimmer'],
},
'generic-rgb': {
channels: ['red', 'green', 'blue']
channels: ['red', 'green', 'blue'],
},
'showtec-multidim2': {
channels: ['1', '2', '3', '4']
channels: ['1', '2', '3', '4'],
},
'eurolite-led-bar': {
channels: ['ctrl', 'dimmer', 'strobe', 'red0', 'green0', 'blue0', 'red1', 'green1', 'blue1', 'red2', 'green2', 'blue2'],
channels: [
'ctrl',
'dimmer',
'strobe',
'red0',
'green0',
'blue0',
'red1',
'green1',
'blue1',
'red2',
'green2',
'blue2',
],
ranges: {
'ctrl': {
'type': 'option',
'options': [
{'value': 0, 'label': 'Black Out'},
{'value': 1, 'label': 'Dimmer 1'},
{'value': 16, 'label': 'Dimmer 2'},
{'value': 32, 'label': 'Red'},
{'value': 48, 'label': 'Green'},
{'value': 64, 'label': 'Blue'},
{'value': 80, 'label': 'Purple'},
{'value': 96, 'label': 'Yellow'},
{'value': 112, 'label': 'Cyan'},
{'value': 128, 'label': 'White'},
{'value': 144, 'label': 'Color change'},
{'value': 160, 'label': 'Color flow'},
{'value': 176, 'label': 'Color dream'},
{'value': 192, 'label': 'Multi flow'},
{'value': 208, 'label': 'Dream flow'},
{'value': 224, 'label': 'Two color flow'},
{'value': 240, 'label': 'Sound activity'}
]
{ 'value': 0, 'label': 'Black Out' },
{ 'value': 1, 'label': 'Dimmer 1' },
{ 'value': 16, 'label': 'Dimmer 2' },
{ 'value': 32, 'label': 'Red' },
{ 'value': 48, 'label': 'Green' },
{ 'value': 64, 'label': 'Blue' },
{ 'value': 80, 'label': 'Purple' },
{ 'value': 96, 'label': 'Yellow' },
{ 'value': 112, 'label': 'Cyan' },
{ 'value': 128, 'label': 'White' },
{ 'value': 144, 'label': 'Color change' },
{ 'value': 160, 'label': 'Color flow' },
{ 'value': 176, 'label': 'Color dream' },
{ 'value': 192, 'label': 'Multi flow' },
{ 'value': 208, 'label': 'Dream flow' },
{ 'value': 224, 'label': 'Two color flow' },
{ 'value': 240, 'label': 'Sound activity' },
],
},
'dimmer': {
'type': 'slider',
'min': 0,
'max': 255
}
}
'max': 255,
},
},
},
'stairville-led-par-56': {
channels: ['ctrl', 'red', 'green', 'blue', 'speed'],
@ -46,23 +59,23 @@ module.exports = {
'ctrl': {
'type': 'option',
'options': [
{'value': 0, 'label': 'RGB Control'},
{'value': 64, 'label': '7 color fade'},
{'value': 128, 'label': '7 color change'},
{'value': 192, 'label': '3 color change'}
]
}
}
{ 'value': 0, 'label': 'RGB Control' },
{ 'value': 64, 'label': '7 color fade' },
{ 'value': 128, 'label': '7 color change' },
{ 'value': 192, 'label': '3 color change' },
],
},
},
},
'ultra-pro-24ch-rdm': {
channels: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24' ]
channels: [...Array(25).keys()].slice(1),
},
'ultra-pro-6rgbch-rdm': {
channels: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24' ],
channelgroups: ['1', '2', '3', '4', '5', '6']
channels: [...Array(25).keys()].slice(1),
channelgroups: ['1', '2', '3', '4', '5', '6'],
},
'oppsk-cob-uv-par': {
channels: ['dimmer', 'strobe', 'program-speed', 'sound-activity']
channels: ['dimmer', 'strobe', 'program-speed', 'sound-activity'],
},
'lixda-par12-led': {
channels: ['ctrl', 'static-color', 'speed', 'dimmer', 'red', 'green', 'blue', 'white'],
@ -70,47 +83,47 @@ module.exports = {
'ctrl': {
'type': 'option',
'options': [
{'value': 0, 'label': 'Off'},
{'value': 11, 'label': 'Static Color'},
{'value': 51, 'label': 'Jump'},
{'value': 101, 'label': 'Gradual'},
{'value': 151, 'label': 'Sound Activate'},
{'value': 200, 'label': 'Strobe'}
]
{ 'value': 0, 'label': 'Off' },
{ 'value': 11, 'label': 'Static Color' },
{ 'value': 51, 'label': 'Jump' },
{ 'value': 101, 'label': 'Gradual' },
{ 'value': 151, 'label': 'Sound Activate' },
{ 'value': 200, 'label': 'Strobe' },
],
},
'static-color': {
'type': 'option',
'options': [
{'value': 0, 'label': 'All Color'},
{'value': 40, 'label': 'Red'},
{'value': 50, 'label': 'Green'},
{'value': 60, 'label': 'Blue'},
{'value': 70, 'label': 'Yellow'},
{'value': 80, 'label': 'Cyan'},
{'value': 90, 'label': 'Purple'},
{'value': 100, 'label': 'White'},
{'value': 110, 'label': 'Red + Green'},
{'value': 120, 'label': 'Red + Blue'},
{'value': 130, 'label': 'Red + White'},
{'value': 140, 'label': 'Green + Blue'},
{'value': 150, 'label': 'Green + White'},
{'value': 160, 'label': 'Blue + White'},
{'value': 170, 'label': 'Red + Green + White'},
{'value': 180, 'label': 'Red + Blue + White'},
{'value': 190, 'label': 'Green + Blue + White'},
{'value': 200, 'label': 'Red + Green + Blue'},
{'value': 210, 'label': 'Red + Green + Blue + White'}
]
}
}
{ 'value': 0, 'label': 'All Color' },
{ 'value': 40, 'label': 'Red' },
{ 'value': 50, 'label': 'Green' },
{ 'value': 60, 'label': 'Blue' },
{ 'value': 70, 'label': 'Yellow' },
{ 'value': 80, 'label': 'Cyan' },
{ 'value': 90, 'label': 'Purple' },
{ 'value': 100, 'label': 'White' },
{ 'value': 110, 'label': 'Red + Green' },
{ 'value': 120, 'label': 'Red + Blue' },
{ 'value': 130, 'label': 'Red + White' },
{ 'value': 140, 'label': 'Green + Blue' },
{ 'value': 150, 'label': 'Green + White' },
{ 'value': 160, 'label': 'Blue + White' },
{ 'value': 170, 'label': 'Red + Green + White' },
{ 'value': 180, 'label': 'Red + Blue + White' },
{ 'value': 190, 'label': 'Green + Blue + White' },
{ 'value': 200, 'label': 'Red + Green + Blue' },
{ 'value': 210, 'label': 'Red + Green + Blue + White' },
],
},
},
},
'eurolite-led-tha-120PC': {
channels: ['red', 'green', 'blue', 'white', 'dimmer', 'strobe', 'effect']
channels: ['red', 'green', 'blue', 'white', 'dimmer', 'strobe', 'effect'],
},
'briteq-bt-theatre-60FC': {
channels: ['dimmer', 'strobe', 'effect', 'red', 'green', 'blue', 'white']
channels: ['dimmer', 'strobe', 'effect', 'red', 'green', 'blue', 'white'],
},
'lalucenatz-led-4ch': {
channels: ['master', 'red', 'green', 'blue']
channels: ['master', 'red', 'green', 'blue'],
},
}
};

View file

@ -1,129 +1,128 @@
#!/usr/bin/env node
"use strict"
var fs = require('fs')
var http = require('http')
var body = require('body-parser')
var express = require('express')
var socketio = require('socket.io')
var program = require('commander')
var DMX = require('./dmx')
var A = DMX.Animation
const fs = require('fs');
const http = require('http');
const body = require('body-parser');
const express = require('express');
const socketio = require('socket.io');
const program = require('commander');
const DMX = require('./dmx');
const A = DMX.Animation;
program
.version("0.0.1")
.version('0.0.1')
.option('-c, --config <file>', 'Read config from file [/etc/dmx-web.json]', '/etc/dmx-web.json')
.parse(process.argv)
.parse(process.argv);
var config = JSON.parse(fs.readFileSync(program.config, 'utf8'))
const config = JSON.parse(fs.readFileSync(program.config, 'utf8'));
function DMXWeb() {
var app = express()
var server = http.createServer(app)
var io = socketio.listen(server)
const app = express();
const server = http.createServer(app);
const io = socketio.listen(server);
var dmx = new DMX(config)
const dmx = new DMX(config);
for(var universe in config.universes) {
for (const universe in config.universes) {
dmx.addUniverse(
universe,
config.universes[universe].output.driver,
config.universes[universe].output.device,
config.universes[universe].output.options
)
);
}
var listen_port = config.server.listen_port || 8080
var listen_host = config.server.listen_host || '::'
const listenPort = config.server.listen_port || 8080;
const listenHost = config.server.listen_host || '::';
server.listen(listen_port, listen_host, null, function() {
if(config.server.uid && config.server.gid) {
server.listen(listenPort, listenHost, null, () => {
if (config.server.uid && config.server.gid) {
try {
process.setuid(config.server.uid)
process.setgid(config.server.gid)
process.setuid(config.server.uid);
process.setgid(config.server.gid);
} catch (err) {
console.log(err)
process.exit(1)
console.log(err);
process.exit(1);
}
}
})
});
app.use(body.json())
app.use(body.json());
app.get('/', function(req, res) {
res.sendFile(__dirname + '/index.html')
})
app.get('/', (req, res) => {
res.sendFile(__dirname + '/index.html');
});
app.get('/config', function(req, res) {
var response = {"devices": dmx.devices, "universes": {}}
Object.keys(config.universes).forEach(function(key) {
response.universes[key] = config.universes[key].devices
})
app.get('/config', (req, res) => {
const response = {'devices': dmx.devices, 'universes': {}};
res.json(response)
})
Object.keys(config.universes).forEach(key => {
response.universes[key] = config.universes[key].devices;
});
app.get('/state/:universe', function(req, res) {
if(!(req.params.universe in dmx.universes)) {
res.status(404).json({"error": "universe not found"})
return
res.json(response);
});
app.get('/state/:universe', (req, res) => {
if (!(req.params.universe in dmx.universes)) {
res.status(404).json({'error': 'universe not found'});
return;
}
res.json({"state": dmx.universeToObject(req.params.universe)})
})
res.json({'state': dmx.universeToObject(req.params.universe)});
});
app.post('/state/:universe', function(req, res) {
if(!(req.params.universe in dmx.universes)) {
res.status(404).json({"error": "universe not found"})
return
app.post('/state/:universe', (req, res) => {
if (!(req.params.universe in dmx.universes)) {
res.status(404).json({'error': 'universe not found'});
return;
}
dmx.update(req.params.universe, req.body)
res.json({"state": dmx.universeToObject(req.params.universe)})
})
dmx.update(req.params.universe, req.body);
res.json({'state': dmx.universeToObject(req.params.universe)});
});
app.post('/animation/:universe', function(req, res) {
app.post('/animation/:universe', (req, res) => {
try {
var universe = dmx.universes[req.params.universe]
const universe = dmx.universes[req.params.universe];
// preserve old states
var old = dmx.universeToObject(req.params.universe)
const old = dmx.universeToObject(req.params.universe);
var animation = new A()
for(var step in req.body) {
const animation = new A();
for (const step in req.body) {
animation.add(
req.body[step].to,
req.body[step].duration || 0,
req.body[step].options || {}
)
);
}
animation.add(old, 0)
animation.run(universe)
res.json({"success": true})
} catch(e) {
console.log(e)
res.json({"error": String(e)})
animation.add(old, 0);
animation.run(universe);
res.json({'success': true});
} catch (e) {
console.log(e);
res.json({'error': String(e)});
}
})
});
io.sockets.on('connection', function(socket) {
socket.emit('init', {'devices': dmx.devices, 'setup': config})
io.sockets.on('connection', socket => {
socket.emit('init', {'devices': dmx.devices, 'setup': config});
socket.on('request_refresh', function() {
for(var universe in config.universes) {
socket.emit('update', universe, dmx.universeToObject(universe))
socket.on('request_refresh', () => {
for (const universe in config.universes) {
socket.emit('update', universe, dmx.universeToObject(universe));
}
})
});
socket.on('update', function(universe, update) {
dmx.update(universe, update)
})
socket.on('update', (universe, update) => {
dmx.update(universe, update);
});
dmx.on('update', function(universe, update) {
socket.emit('update', universe, update)
})
})
dmx.on('update', (universe, update) => {
socket.emit('update', universe, update);
});
});
}
DMXWeb()
DMXWeb();

99
dmx.js
View file

@ -1,55 +1,58 @@
"use strict"
const util = require('util');
const EventEmitter = require('events').EventEmitter;
var util = require('util')
var EventEmitter = require('events').EventEmitter
class DMX {
constructor(options) {
const opt = options || {};
const devices = opt.devices || {};
function DMX(options) {
var options = options || {}
var devices = options.devices || {}
this.universes = {}
this.drivers = {}
this.universes = {};
this.drivers = {};
this.devices = Object.assign({}, require('./devices'), devices);
this.animation = require('./anim')
this.animation = require('./anim');
this.registerDriver('null', require('./drivers/null'))
this.registerDriver('dmx4all', require('./drivers/dmx4all'))
this.registerDriver('enttec-usb-dmx-pro', require('./drivers/enttec-usb-dmx-pro'))
this.registerDriver('enttec-open-usb-dmx', require('./drivers/enttec-open-usb-dmx'))
this.registerDriver('dmxking-ultra-dmx-pro', require('./drivers/dmxking-ultra-dmx-pro'))
this.registerDriver('artnet', require('./drivers/artnet'))
this.registerDriver('bbdmx', require('./drivers/bbdmx'))
}
util.inherits(DMX, EventEmitter)
DMX.devices = require('./devices')
DMX.Animation = require('./anim')
DMX.prototype.registerDriver = function(name, module) {
this.drivers[name] = module
}
DMX.prototype.addUniverse = function(name, driver, device_id, options) {
return this.universes[name] = new this.drivers[driver](device_id, options)
}
DMX.prototype.update = function(universe, channels) {
this.universes[universe].update(channels)
this.emit('update', universe, channels)
}
DMX.prototype.updateAll = function(universe, value) {
this.universes[universe].updateAll(value)
this.emit('updateAll', universe, value)
}
DMX.prototype.universeToObject = function(universe) {
var universe = this.universes[universe]
var u = {}
for(var i = 0; i < 512; i++) {
u[i] = universe.get(i)
this.registerDriver('null', require('./drivers/null'));
this.registerDriver('dmx4all', require('./drivers/dmx4all'));
this.registerDriver('enttec-usb-dmx-pro', require('./drivers/enttec-usb-dmx-pro'));
this.registerDriver('enttec-open-usb-dmx', require('./drivers/enttec-open-usb-dmx'));
this.registerDriver('dmxking-ultra-dmx-pro', require('./drivers/dmxking-ultra-dmx-pro'));
this.registerDriver('artnet', require('./drivers/artnet'));
this.registerDriver('bbdmx', require('./drivers/bbdmx'));
}
registerDriver(name, module) {
this.drivers[name] = module;
}
addUniverse(name, driver, deviceId, options) {
this.universes[name] = new this.drivers[driver](deviceId, options);
return this.universes[name];
}
update(universe, channels) {
this.universes[universe].update(channels);
this.emit('update', universe, channels);
}
updateAll(universe, value) {
this.universes[universe].updateAll(value);
this.emit('updateAll', universe, value);
}
universeToObject(universeKey) {
const universe = this.universes[universeKey];
const u = {};
for (let i = 0; i < 512; i++) {
u[i] = universe.get(i);
}
return u;
}
return u
}
module.exports = DMX
util.inherits(DMX, EventEmitter);
DMX.devices = require('./devices');
DMX.Animation = require('./anim');
module.exports = DMX;

View file

@ -1,72 +1,67 @@
"use strict"
const dgram = require('dgram');
var dgram = require('dgram')
function EnttecODE(deviceId = '127.0.0.1', options = {}) {
const self = this;
function EnttecODE(device_id, options) {
var self = this
self.header = new Buffer([65, 114, 116, 45, 78, 101, 116, 0, 0, 80, 0, 14]);
self.sequence = new Buffer([0]);
self.physical = new Buffer([0]);
self.universeId = new Buffer([0x00, 0x00]);
self.length = new Buffer([0x02, 0x00]);
self.header = new Buffer([65, 114, 116, 45, 78, 101, 116, 0, 0, 80, 0, 14])
self.sequence = new Buffer([0])
self.physical = new Buffer([0])
self.universe_id = new Buffer([0x00, 0x00])
self.length = new Buffer([0x02, 0x00])
self.universe = new Buffer(513);
self.universe.fill(0);
self.universe = new Buffer(513)
self.universe.fill(0)
self.sleepTime = 24;
self.sleepTime = 24
options = options || {}
self.universe_id.writeInt16LE(options.universe || 0, 0)
self.host = device_id || '127.0.0.1'
self.port = options.port || 6454
self.dev = dgram.createSocket('udp4')
self.dev.bind(function() {
self.dev.setBroadcast(true)
})
self.start()
self.universe_id.writeInt16LE(options.universe || 0, 0);
self.host = deviceId;
self.port = options.port || 6454;
self.dev = dgram.createSocket('udp4');
self.dev.bind(() => self.dev.setBroadcast(true));
self.start();
}
EnttecODE.prototype.send_universe = function() {
var pkg = Buffer.concat([
EnttecODE.prototype.sendUniverse = function () {
const pkg = Buffer.concat([
this.header,
this.sequence,
this.physical,
this.universe_id,
this.length,
this.universe.slice(1)
])
this.universe.slice(1),
]);
this.dev.send(pkg, 0, pkg.length, this.port, this.host)
}
this.dev.send(pkg, 0, pkg.length, this.port, this.host);
};
EnttecODE.prototype.start = function() {
this.timeout = setInterval(this.send_universe.bind(this), this.sleepTime)
}
EnttecODE.prototype.start = function () {
this.timeout = setInterval(this.sendUniverse.bind(this), this.sleepTime);
};
EnttecODE.prototype.stop = function() {
clearInterval(this.timeout)
}
EnttecODE.prototype.stop = function () {
clearInterval(this.timeout);
};
EnttecODE.prototype.close = function(cb) {
this.stop()
cb(null)
}
EnttecODE.prototype.close = function (cb) {
this.stop();
cb(null);
};
EnttecODE.prototype.update = function(u) {
for (var c in u) {
this.universe[c] = u[c]
EnttecODE.prototype.update = function (u) {
for (const c in u) {
this.universe[c] = u[c];
}
}
};
EnttecODE.prototype.updateAll = function(v) {
for (var i = 1; i <= 512; i++) {
this.universe[i] = v
EnttecODE.prototype.updateAll = function (v) {
for (const i = 1; i <= 512; i++) {
this.universe[i] = v;
}
}
};
EnttecODE.prototype.get = function(c) {
return this.universe[c]
}
EnttecODE.prototype.get = function (c) {
return this.universe[c];
};
module.exports = EnttecODE
module.exports = EnttecODE;

View file

@ -1,59 +1,58 @@
'use strict'
const dgram = require('dgram');
var dgram = require('dgram')
const UNIVERSE_LEN = 512;
var UNIVERSE_LEN = 512
function BBDMX(deviceId = '127.0.0.1', options = {}) {
const self = this;
function BBDMX(device_id, options) {
var self = this
self.options = options || {}
self.universe = new Buffer(UNIVERSE_LEN + 1)
self.universe.fill(0)
self.host = device_id || '127.0.0.1'
self.port = self.options.port || 9930
self.dev = dgram.createSocket('udp4')
self.sleepTime = 24
self.start()
self.options = options;
self.universe = new Buffer(UNIVERSE_LEN + 1);
self.universe.fill(0);
self.host = deviceId;
self.port = self.options.port || 9930;
self.dev = dgram.createSocket('udp4');
self.sleepTime = 24;
self.start();
}
BBDMX.prototype.send_universe = function() {
var channel
var messageBuffer = new Buffer(UNIVERSE_LEN.toString())
BBDMX.prototype.sendUniverse = function () {
let channel;
let messageBuffer = new Buffer(UNIVERSE_LEN.toString());
for (var i = 1; i <= UNIVERSE_LEN; i++) {
channel = new Buffer(' ' + this.universe[i])
messageBuffer = Buffer.concat([messageBuffer, channel])
for (const i = 1; i <= UNIVERSE_LEN; i++) {
channel = new Buffer(' ' + this.universe[i]);
messageBuffer = Buffer.concat([messageBuffer, channel]);
}
this.dev.send(messageBuffer, 0, messageBuffer.length, this.port, this.host)
}
BBDMX.prototype.start = function() {
this.timeout = setInterval(this.send_universe.bind(this), this.sleepTime)
}
BBDMX.prototype.stop = function() {
clearInterval(this.timeout)
}
BBDMX.prototype.close = function(cb) {
this.stop()
cb(null)
this.dev.send(messageBuffer, 0, messageBuffer.length, this.port, this.host);
};
BBDMX.prototype.update = function(u) {
for (var c in u) {
this.universe[c] = u[c]
BBDMX.prototype.start = function () {
this.timeout = setInterval(this.sendUniverse.bind(this), this.sleepTime);
};
BBDMX.prototype.stop = function () {
clearInterval(this.timeout);
};
BBDMX.prototype.close = function (cb) {
this.stop();
cb(null);
};
BBDMX.prototype.update = function (u) {
for (const c in u) {
this.universe[c] = u[c];
}
}
};
BBDMX.prototype.updateAll = function(v) {
for (var i = 1; i <= UNIVERSE_LEN; i++) {
this.universe[i] = v
BBDMX.prototype.updateAll = function (v) {
for (const i = 1; i <= UNIVERSE_LEN; i++) {
this.universe[i] = v;
}
}
};
BBDMX.prototype.get = function(c) {
return this.universe[c]
}
BBDMX.prototype.get = function (c) {
return this.universe[c];
};
module.exports = BBDMX
module.exports = BBDMX;

View file

@ -1,67 +1,66 @@
"use strict"
const SerialPort = require('serialport');
var SerialPort = require("serialport")
const UNIVERSE_LEN = 512;
var UNIVERSE_LEN = 512
function DMX4ALL(deviceId, options = {}) {
const self = this;
function DMX4ALL(device_id, options) {
var self = this
options = options || {}
this.universe = new Buffer(UNIVERSE_LEN + 1)
this.universe.fill(0)
this.universe = new Buffer(UNIVERSE_LEN + 1);
this.universe.fill(0);
this.dev = new SerialPort(device_id, {
this.dev = new SerialPort(deviceId, {
'baudRate': 38400,
'dataBits': 8,
'stopBits': 1,
'parity': 'none'
}, function(err) {
if(!err) {
self.send_universe()
'parity': 'none',
}, err => {
if (!err) {
self.sendUniverse();
}
})
this.dev.on('data', function(data) {
//process.stdout.write(data.toString('ascii'))
})
});
this.dev.on('data', data => {
// process.stdout.write(data.toString('ascii'))
});
}
DMX4ALL.prototype.send_universe = function() {
if(!this.dev.writable) {
return
DMX4ALL.prototype.sendUniverse = function () {
if (!this.dev.writable) {
return;
}
var msg = Buffer(UNIVERSE_LEN * 3)
for(var i = 0; i < UNIVERSE_LEN; i++) {
msg[i * 3 + 0] = (i < 256) ? 0xE2 : 0xE3
msg[i * 3 + 1] = i
msg[i * 3 + 2] = this.universe[i + 1]
const msg = Buffer(UNIVERSE_LEN * 3);
for (let i = 0; i < UNIVERSE_LEN; i++) {
msg[i * 3 + 0] = (i < 256) ? 0xE2 : 0xE3;
msg[i * 3 + 1] = i;
msg[i * 3 + 2] = this.universe[i + 1];
}
this.dev.write(msg)
}
this.dev.write(msg);
};
DMX4ALL.prototype.start = function() {}
DMX4ALL.prototype.stop = function() {}
DMX4ALL.prototype.start = () => {};
DMX4ALL.prototype.stop = () => {};
DMX4ALL.prototype.close = function(cb) {
this.dev.close(cb)
}
DMX4ALL.prototype.close = function (cb) {
this.dev.close(cb);
};
DMX4ALL.prototype.update = function(u) {
for(var c in u) {
this.universe[c] = u[c]
DMX4ALL.prototype.update = function (u) {
for (const c in u) {
this.universe[c] = u[c];
}
this.send_universe()
}
this.sendUniverse();
};
DMX4ALL.prototype.updateAll = function(v){
for(var i = 1; i <= 512; i++) {
this.universe[i] = v
DMX4ALL.prototype.updateAll = function (v) {
for (let i = 1; i <= 512; i++) {
this.universe[i] = v;
}
this.send_universe()
}
this.sendUniverse();
};
DMX4ALL.prototype.get = function(c) {
return this.universe[c]
}
DMX4ALL.prototype.get = function (c) {
return this.universe[c];
};
module.exports = DMX4ALL
module.exports = DMX4ALL;

View file

@ -1,83 +1,82 @@
"use strict"
const SerialPort = require('serialport');
var SerialPort = require("serialport")
const DMXKING_ULTRA_DMX_PRO_DMX_STARTCODE = 0x00;
const DMXKING_ULTRA_DMX_PRO_START_OF_MSG = 0x7e;
const DMXKING_ULTRA_DMX_PRO_END_OF_MSG = 0xe7;
const DMXKING_ULTRA_DMX_PRO_SEND_DMX_RQ = 0x06;
const DMXKING_ULTRA_DMX_PRO_SEND_DMX_A_RQ = 0x64;
const DMXKING_ULTRA_DMX_PRO_SEND_DMX_B_RQ = 0x65;
// var DMXKING_ULTRA_DMX_PRO_RECV_DMX_PKT = 0x05;
var DMXKING_ULTRA_DMX_PRO_DMX_STARTCODE = 0x00
, DMXKING_ULTRA_DMX_PRO_START_OF_MSG = 0x7e
, DMXKING_ULTRA_DMX_PRO_END_OF_MSG = 0xe7
, DMXKING_ULTRA_DMX_PRO_SEND_DMX_RQ = 0x06
, DMXKING_ULTRA_DMX_PRO_SEND_DMX_A_RQ = 0x64
, DMXKING_ULTRA_DMX_PRO_SEND_DMX_B_RQ = 0x65
, DMXKING_ULTRA_DMX_PRO_RECV_DMX_PKT = 0x05
;
function DMXKingUltraDMXPro(deviceId, options = {}) {
const self = this;
function DMXKingUltraDMXPro(device_id, options) {
var self = this
this.options = options || {}
this.options = options;
this.universe = Buffer.alloc(513, 0);
this.sendDMXReq = DMXKING_ULTRA_DMX_PRO_SEND_DMX_RQ
if (this.options.port === "A") {
this.sendDMXReq = DMXKING_ULTRA_DMX_PRO_SEND_DMX_A_RQ
} else if (this.options.port === "B") {
this.sendDMXReq = DMXKING_ULTRA_DMX_PRO_SEND_DMX_B_RQ
this.sendDMXReq = DMXKING_ULTRA_DMX_PRO_SEND_DMX_RQ;
if (this.options.port === 'A') {
this.sendDMXReq = DMXKING_ULTRA_DMX_PRO_SEND_DMX_A_RQ;
} else if (this.options.port === 'B') {
this.sendDMXReq = DMXKING_ULTRA_DMX_PRO_SEND_DMX_B_RQ;
}
this.dev = new SerialPort(device_id, {
this.dev = new SerialPort(deviceId, {
'baudRate': 250000,
'dataBits': 8,
'stopBits': 2,
'parity': 'none'
}, function(err) {
if(!err) {
self.send_universe()
'parity': 'none',
}, err => {
if (!err) {
self.sendUniverse();
}
})
});
}
DMXKingUltraDMXPro.prototype.send_universe = function() {
if(!this.dev.writable) {
return
DMXKingUltraDMXPro.prototype.sendUniverse = function () {
if (!this.dev.writable) {
return;
}
var hdr = Buffer.from([
const hdr = Buffer.from([
DMXKING_ULTRA_DMX_PRO_START_OF_MSG,
this.sendDMXReq,
(this.universe.length) & 0xff,
((this.universe.length) >> 8) & 0xff,
DMXKING_ULTRA_DMX_PRO_DMX_STARTCODE
])
DMXKING_ULTRA_DMX_PRO_DMX_STARTCODE,
]);
var msg = Buffer.concat([
const msg = Buffer.concat([
hdr,
this.universe.slice(1),
Buffer.from([DMXKING_ULTRA_DMX_PRO_END_OF_MSG])
])
this.dev.write(msg)
}
Buffer.from([DMXKING_ULTRA_DMX_PRO_END_OF_MSG]),
]);
DMXKingUltraDMXPro.prototype.start = function() {}
DMXKingUltraDMXPro.prototype.stop = function() {}
this.dev.write(msg);
};
DMXKingUltraDMXPro.prototype.close = function(cb) {
this.dev.close(cb)
}
DMXKingUltraDMXPro.prototype.start = () => { };
DMXKingUltraDMXPro.prototype.stop = () => { };
DMXKingUltraDMXPro.prototype.update = function(u) {
for(var c in u) {
this.universe[c] = u[c]
DMXKingUltraDMXPro.prototype.close = function (cb) {
this.dev.close(cb);
};
DMXKingUltraDMXPro.prototype.update = function (u) {
for (const c in u) {
this.universe[c] = u[c];
}
this.send_universe()
}
this.sendUniverse();
};
DMXKingUltraDMXPro.prototype.updateAll = function(v){
for(var i = 1; i <= 512; i++) {
this.universe[i] = v
DMXKingUltraDMXPro.prototype.updateAll = function (v) {
for (let i = 1; i <= 512; i++) {
this.universe[i] = v;
}
this.send_universe()
}
this.sendUniverse();
};
DMXKingUltraDMXPro.prototype.get = function(c) {
return this.universe[c]
}
DMXKingUltraDMXPro.prototype.get = function (c) {
return this.universe[c];
};
module.exports = DMXKingUltraDMXPro
module.exports = DMXKingUltraDMXPro;

View file

@ -1,75 +1,75 @@
"use strict"
const SerialPort = require('serialport');
var SerialPort = require("serialport")
function EnttecOpenUsbDMX(deviceId, options) {
const self = this;
function EnttecOpenUsbDMX(device_id, options) {
var self = this
options = options || {}
options = options || {};
this.universe = new Buffer(513)
this.universe.fill(0)
this.universe = new Buffer(513);
this.universe.fill(0);
self.interval = 46
self.interval = 46;
this.dev = new SerialPort(device_id, {
this.dev = new SerialPort(deviceId, {
'baudRate': 250000,
'dataBits': 8,
'stopBits': 2,
'parity': 'none'
}, function(err) {
if(err) {
console.log(err)
return
'parity': 'none',
}, err => {
if (err) {
console.log(err);
return;
}
self.start()
})
self.start();
});
}
EnttecOpenUsbDMX.prototype.send_universe = function() {
var self = this
if(!this.dev.writable) {
return
EnttecOpenUsbDMX.prototype.sendUniverse = function () {
const self = this;
if (!this.dev.writable) {
return;
}
// toggle break
self.dev.set({brk: true, rts: true}, function(err, r) {
setTimeout(function() {
self.dev.set({brk: false, rts: true}, function(err, r) {
setTimeout(function() {
self.dev.write(Buffer.concat([Buffer([0]), self.universe.slice(1)]))
}, 1)
})
}, 1)
})
}
self.dev.set({brk: true, rts: true}, (err, r) => {
setTimeout(() => {
self.dev.set({brk: false, rts: true}, (err, r) => {
setTimeout(() => {
self.dev.write(Buffer.concat([Buffer([0]), self.universe.slice(1)]));
}, 1);
});
}, 1);
});
};
EnttecOpenUsbDMX.prototype.start = function() {
this.intervalhandle = setInterval(this.send_universe.bind(this), this.interval)
}
EnttecOpenUsbDMX.prototype.start = function () {
this.intervalhandle = setInterval(this.sendUniverse.bind(this), this.interval);
};
EnttecOpenUsbDMX.prototype.stop = function() {
clearInterval(this.intervalhandle)
}
EnttecOpenUsbDMX.prototype.stop = function () {
clearInterval(this.intervalhandle);
};
EnttecOpenUsbDMX.prototype.close = function(cb) {
this.stop()
this.dev.close(cb)
}
EnttecOpenUsbDMX.prototype.close = function (cb) {
this.stop();
this.dev.close(cb);
};
EnttecOpenUsbDMX.prototype.update = function(u) {
for(var c in u) {
this.universe[c] = u[c]
EnttecOpenUsbDMX.prototype.update = function (u) {
for (const c in u) {
this.universe[c] = u[c];
}
}
};
EnttecOpenUsbDMX.prototype.updateAll = function(v) {
for(var i = 1; i <= 512; i++) {
this.universe[i] = v
EnttecOpenUsbDMX.prototype.updateAll = function (v) {
for (let i = 1; i <= 512; i++) {
this.universe[i] = v;
}
}
};
EnttecOpenUsbDMX.prototype.get = function(c) {
return this.universe[c]
}
EnttecOpenUsbDMX.prototype.get = function (c) {
return this.universe[c];
};
module.exports = EnttecOpenUsbDMX
module.exports = EnttecOpenUsbDMX;

View file

@ -1,74 +1,72 @@
"use strict"
const SerialPort = require('serialport');
var SerialPort = require("serialport")
const ENTTEC_PRO_DMX_STARTCODE = 0x00;
const ENTTEC_PRO_START_OF_MSG = 0x7e;
const ENTTEC_PRO_END_OF_MSG = 0xe7;
const ENTTEC_PRO_SEND_DMX_RQ = 0x06;
// var ENTTEC_PRO_RECV_DMX_PKT = 0x05;
var ENTTEC_PRO_DMX_STARTCODE = 0x00
, ENTTEC_PRO_START_OF_MSG = 0x7e
, ENTTEC_PRO_END_OF_MSG = 0xe7
, ENTTEC_PRO_SEND_DMX_RQ = 0x06
, ENTTEC_PRO_RECV_DMX_PKT = 0x05
;
function EnttecUSBDMXPRO(deviceId, options = {}) {
const self = this;
function EnttecUSBDMXPRO(device_id, options) {
var self = this
options = options || {}
this.universe = Buffer.alloc(513, 0);
this.dev = new SerialPort(device_id, {
this.dev = new SerialPort(deviceId, {
'baudRate': 250000,
'dataBits': 8,
'stopBits': 2,
'parity': 'none'
}, function(err) {
if(!err) {
self.send_universe()
'parity': 'none',
}, err => {
if (!err) {
self.sendUniverse();
}
})
});
}
EnttecUSBDMXPRO.prototype.send_universe = function() {
if(!this.dev.writable) {
return
EnttecUSBDMXPRO.prototype.sendUniverse = function () {
if (!this.dev.writable) {
return;
}
var hdr = Buffer.from([
const hdr = Buffer.from([
ENTTEC_PRO_START_OF_MSG,
ENTTEC_PRO_SEND_DMX_RQ,
(this.universe.length) & 0xff,
((this.universe.length) >> 8) & 0xff,
ENTTEC_PRO_DMX_STARTCODE
])
ENTTEC_PRO_DMX_STARTCODE,
]);
var msg = Buffer.concat([
const msg = Buffer.concat([
hdr,
this.universe.slice(1),
Buffer.from([ENTTEC_PRO_END_OF_MSG])
])
this.dev.write(msg)
}
Buffer.from([ENTTEC_PRO_END_OF_MSG]),
]);
EnttecUSBDMXPRO.prototype.start = function() {}
EnttecUSBDMXPRO.prototype.stop = function() {}
this.dev.write(msg);
};
EnttecUSBDMXPRO.prototype.close = function(cb) {
this.dev.close(cb)
}
EnttecUSBDMXPRO.prototype.start = () => { };
EnttecUSBDMXPRO.prototype.stop = () => { };
EnttecUSBDMXPRO.prototype.update = function(u) {
for(var c in u) {
this.universe[c] = u[c]
EnttecUSBDMXPRO.prototype.close = function (cb) {
this.dev.close(cb);
};
EnttecUSBDMXPRO.prototype.update = function (u) {
for (const c in u) {
this.universe[c] = u[c];
}
this.send_universe()
}
this.sendUniverse();
};
EnttecUSBDMXPRO.prototype.updateAll = function(v){
for(var i = 1; i <= 512; i++) {
this.universe[i] = v
EnttecUSBDMXPRO.prototype.updateAll = function (v) {
for (let i = 1; i <= 512; i++) {
this.universe[i] = v;
}
this.send_universe()
}
this.sendUniverse();
};
EnttecUSBDMXPRO.prototype.get = function(c) {
return this.universe[c]
}
EnttecUSBDMXPRO.prototype.get = function (c) {
return this.universe[c];
};
module.exports = EnttecUSBDMXPRO
module.exports = EnttecUSBDMXPRO;

View file

@ -1,42 +1,42 @@
"use strict"
function Null(deviceId, options) {
const self = this;
function Null(device_id, options) {
var self = this
options = options || {}
options = options || {};
this.universe = Buffer.alloc(513, 0);
self.start()
self.start();
}
Null.prototype.start = function() {
var self = this
self.timeout = setInterval(function() {
console.log(self.universe)
}, 1000)
}
Null.prototype.start = function () {
const self = this;
Null.prototype.stop = function() {
clearInterval(this.timeout)
}
self.timeout = setInterval(() => {
console.log(self.universe);
}, 1000);
};
Null.prototype.close = function(cb) {
cb(null)
}
Null.prototype.stop = function () {
clearInterval(this.timeout);
};
Null.prototype.update = function(u) {
for(var c in u) {
this.universe[c] = u[c]
Null.prototype.close = cb => {
cb(null);
};
Null.prototype.update = function (u) {
for (const c in u) {
this.universe[c] = u[c];
}
console.log(this.universe.slice(1))
}
console.log(this.universe.slice(1));
};
Null.prototype.updateAll = function(v){
for(var i = 1; i <= 512; i++) {
this.universe[i] = v
Null.prototype.updateAll = function (v) {
for (let i = 1; i <= 512; i++) {
this.universe[i] = v;
}
}
};
Null.prototype.get = function(c) {
return this.universe[c]
}
Null.prototype.get = function (c) {
return this.universe[c];
};
module.exports = Null
module.exports = Null;

187
easing.js
View file

@ -35,124 +35,127 @@
// t: current time, b: begInnIng value, c: change In value, d: duration
exports.ease = {
linear: function (t, b, c, d) { return c * t/d + b; },
inQuad: function (t, b, c, d) { return c * (t/=d) * t + b; },
outQuad: function (t, b, c, d) { return -c * (t/=d) * (t-2) + b; },
inOutQuad: function (t, b, c, d) {
if ((t/=d/2) < 1) return c/2*t*t + b;
return -c/2 * ((--t)*(t-2) - 1) + b;
linear(t, b, c, d) { return c * t / d + b; },
inQuad(t, b, c, d) { return c * (t /= d) * t + b; },
outQuad(t, b, c, d) { return -c * (t /= d) * (t - 2) + b; },
inOutQuad(t, b, c, d) {
if ((t /= d / 2) < 1) return c / 2 * t * t + b;
return -c / 2 * ((--t) * (t - 2) - 1) + b;
},
inCubic: function (t, b, c, d) { return c*(t/=d)*t*t + b; },
outCubic: function (t, b, c, d) { return c*((t=t/d-1)*t*t + 1) + b; },
inOutCubic: function (t, b, c, d) {
if ((t/=d/2) < 1) return c/2*t*t*t + b;
return c/2*((t-=2)*t*t + 2) + b;
inCubic(t, b, c, d) { return c * (t /= d) * t * t + b; },
outCubic(t, b, c, d) { return c * ((t = t / d - 1) * t * t + 1) + b; },
inOutCubic(t, b, c, d) {
if ((t /= d / 2) < 1) return c / 2 * t * t * t + b;
return c / 2 * ((t -= 2) * t * t + 2) + b;
},
inQuart: function (t, b, c, d) {
return c*(t/=d)*t*t*t + b;
inQuart(t, b, c, d) {
return c * (t /= d) * t * t * t + b;
},
outQuart: function (t, b, c, d) {
return -c * ((t=t/d-1)*t*t*t - 1) + b;
outQuart(t, b, c, d) {
return -c * ((t = t / d - 1) * t * t * t - 1) + b;
},
inOutQuart: function (t, b, c, d) {
if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
return -c/2 * ((t-=2)*t*t*t - 2) + b;
inOutQuart(t, b, c, d) {
if ((t /= d / 2) < 1) return c / 2 * t * t * t * t + b;
return -c / 2 * ((t -= 2) * t * t * t - 2) + b;
},
inQuint: function (t, b, c, d) {
return c*(t/=d)*t*t*t*t + b;
inQuint(t, b, c, d) {
return c * (t /= d) * t * t * t * t + b;
},
outQuint: function (t, b, c, d) {
return c*((t=t/d-1)*t*t*t*t + 1) + b;
outQuint(t, b, c, d) {
return c * ((t = t / d - 1) * t * t * t * t + 1) + b;
},
inOutQuint: function (t, b, c, d) {
if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
return c/2*((t-=2)*t*t*t*t + 2) + b;
inOutQuint(t, b, c, d) {
if ((t /= d / 2) < 1) return c / 2 * t * t * t * t * t + b;
return c / 2 * ((t -= 2) * t * t * t * t + 2) + b;
},
inSine: function (t, b, c, d) {
return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
inSine(t, b, c, d) {
return -c * Math.cos(t / d * (Math.PI / 2)) + c + b;
},
outSine: function (t, b, c, d) {
return c * Math.sin(t/d * (Math.PI/2)) + b;
outSine(t, b, c, d) {
return c * Math.sin(t / d * (Math.PI / 2)) + b;
},
inOutSine: function (t, b, c, d) {
return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
inOutSine(t, b, c, d) {
return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b;
},
inExpo: function (t, b, c, d) {
return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
inExpo(t, b, c, d) {
return (t === 0) ? b : c * (2 ** (10 * (t / d - 1))) + b;
},
outExpo: function (t, b, c, d) {
return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
outExpo(t, b, c, d) {
return (t === d) ? b + c : c * (-(2 ** (-10 * t / d)) + 1) + b;
},
inOutExpo: function (t, b, c, d) {
if (t==0) return b;
if (t==d) return b+c;
if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
inOutExpo(t, b, c, d) {
if (t === 0) return b;
if (t === d) return b + c;
if ((t /= d / 2) < 1) return c / 2 * (2 ** (10 * (t - 1))) + b;
return c / 2 * (-(2 ** (-10 * --t)) + 2) + b;
},
inCirc: function (t, b, c, d) {
return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
inCirc(t, b, c, d) {
return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b;
},
outCirc: function (t, b, c, d) {
return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
outCirc(t, b, c, d) {
return c * Math.sqrt(1 - (t = t / d - 1) * t) + b;
},
inOutCirc: function (t, b, c, d) {
if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
inOutCirc(t, b, c, d) {
if ((t /= d / 2) < 1) return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b;
return c / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1) + b;
},
inElastic: function (t, b, c, d) {
var s=1.70158;var p=0;var a=c;
if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3;
if (a < Math.abs(c)) { a=c; var s=p/4; }
else var s = p/(2*Math.PI) * Math.asin (c/a);
return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
inElastic(t, b, c, d) {
let s = 1.70158; let p = 0; let a = c;
if (t === 0) return b; if ((t /= d) === 1) return b + c; if (!p) p = d * 0.3;
if (a < Math.abs(c)) { a = c; s = p / 4; } else s = p / (2 * Math.PI) * Math.asin(c / a);
return -(a * (2 ** (10 * (t -= 1))) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
},
outElastic: function (t, b, c, d) {
var s=1.70158;var p=0;var a=c;
if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3;
if (a < Math.abs(c)) { a=c; var s=p/4; }
else var s = p/(2*Math.PI) * Math.asin (c/a);
return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
outElastic(t, b, c, d) {
let s = 1.70158; let p = 0; let a = c;
if (t === 0) return b; if ((t /= d) === 1) return b + c; if (!p) p = d * 0.3;
if (a < Math.abs(c)) { a = c; s = p / 4; } else s = p / (2 * Math.PI) * Math.asin(c / a);
return a * (2 ** (-10 * t)) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b;
},
inOutElastic: function (t, b, c, d) {
var s=1.70158;var p=0;var a=c;
if (t==0) return b; if ((t/=d/2)==2) return b+c; if (!p) p=d*(.3*1.5);
if (a < Math.abs(c)) { a=c; var s=p/4; }
else var s = p/(2*Math.PI) * Math.asin (c/a);
if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
inOutElastic(t, b, c, d) {
let s = 1.70158; let p = 0; let a = c;
if (t === 0) return b; if ((t /= d / 2) === 2) return b + c; if (!p) p = d * (0.3 * 1.5);
if (a < Math.abs(c)) { a = c; s = p / 4; } else s = p / (2 * Math.PI) * Math.asin(c / a);
if (t < 1) return -0.5 * (a * (2 ** (10 * (t -= 1))) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
return a * (2 ** (-10 * (t -= 1))) * Math.sin((t * d - s) * (2 * Math.PI) / p) * 0.5 + c + b;
},
inBack: function (t, b, c, d, s) {
if (s == undefined) s = 1.70158;
return c*(t/=d)*t*((s+1)*t - s) + b;
inBack(t, b, c, d, s) {
if (s === undefined) s = 1.70158;
return c * (t /= d) * t * ((s + 1) * t - s) + b;
},
outBack: function (t, b, c, d, s) {
if (s == undefined) s = 1.70158;
return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
outBack(t, b, c, d, s) {
if (s === undefined) s = 1.70158;
return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
},
inOutBack: function (t, b, c, d, s) {
if (s == undefined) s = 1.70158;
if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
inOutBack(t, b, c, d, s) {
if (s === undefined) s = 1.70158;
if ((t /= d / 2) < 1) return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b;
return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b;
},
inBounce: function (t, b, c, d) {
return c - exports.ease.outBounce (d-t, 0, c, d) + b;
inBounce(t, b, c, d) {
return c - exports.ease.outBounce(d - t, 0, c, d) + b;
},
outBounce: function (t, b, c, d) {
if ((t/=d) < (1/2.75)) {
return c*(7.5625*t*t) + b;
} else if (t < (2/2.75)) {
return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
} else if (t < (2.5/2.75)) {
return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
} else {
return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
outBounce(t, b, c, d) {
if ((t /= d) < (1 / 2.75)) {
return c * (7.5625 * t * t) + b;
} else if (t < (2 / 2.75)) {
return c * (7.5625 * (t -= (1.5 / 2.75)) * t + 0.75) + b;
} else if (t < (2.5 / 2.75)) {
return c * (7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375) + b;
}
return c * (7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375) + b;
},
inOutBounce: function (t, b, c, d) {
if (t < d/2) return exports.ease.inBounce (t*2, 0, c, d) * .5 + b;
return exports.ease.outBounce (t*2-d, 0, c, d) * .5 + c*.5 + b;
}
}
inOutBounce(t, b, c, d) {
if (t < d / 2) return exports.ease.inBounce(t * 2, 0, c, d) * 0.5 + b;
return exports.ease.outBounce(t * 2 - d, 0, c, d) * 0.5 + c * 0.5 + b;
},
};
/*
*

View file

@ -1,12 +1,14 @@
{
"name": "dmx",
"version": "0.1.1",
"version": "0.2.0",
"author": "Sebastian Wiedenroth <wiedi@frubar.net>",
"description": "DMX library and webservice",
"url": "https://github.com/wiedi/node-dmx",
"main": "dmx.js",
"bin": {
"dmx-web": "./dmx-web.js"
"dmx-web": "./dmx.js"
},
"scripts": {
"test": "node_modules/eslint/bin/eslint.js -c .eslintrc .; exit 0"
},
"repository": {
"type": "git",
@ -17,19 +19,18 @@
"light control"
],
"dependencies": {
"serialport": "^6.0.4",
"socket.io": "^2.0.4",
"express": "^4.16.2",
"body-parser": "^1.5.2",
"commander": "^2.12.2"
"commander": "^2.12.2",
"express": "^4.16.2",
"serialport": "^6.0.4",
"socket.io": "^2.0.4"
},
"licenses": [
{
"name": "MIT",
"url": "http://www.opensource.org/licenses/mit-license.php"
}
],
"devDependencies": {
"babel-eslint": "^10.0.1",
"eslint": "^5.0.1"
},
"license": "MIT",
"engines": {
"node": ">=5.1.0"
"node": ">=10.0.0"
}
}