diff --git a/lighting_tools/dmx_terminal_www/src/js/dmx.js b/lighting_tools/dmx_terminal_www/src/js/dmx.js index 9968904..f5cacca 100644 --- a/lighting_tools/dmx_terminal_www/src/js/dmx.js +++ b/lighting_tools/dmx_terminal_www/src/js/dmx.js @@ -64,14 +64,34 @@ Dmx.Address.prototype.set = function(options){ } } -Dmx.Field = function(options){ - this.offset = 0; - this.bytes = 1; - this.chunkSize = 1; - this.name = ''; - /*this.min = 0; - this.default = 0; - this.max = Math.pow(2, 8*this.bytes)-1;*/ +Dmx.Field = function({offset=0, bytes=1, chunkSize=1, name='', min=0, max=null, defaultVal=0, length=null, format=null}){ + this.offset = offset; + this.bytes = bytes; + this.chunkSize = chunkSize; + this.name = name; + this.min = min; + this.default = defaultVal; + this.max = (max != null) ? max : Math.pow(2, 8*this.bytes)-1; + this.length = (length != null) ? length : undefined + this.format = format + + this.nextOffset = ((length != null) ? (length * bytes) : bytes) + this.offset + //this.nextOffset = this.endOffset + 1*this.bytes + 1 +} + +Dmx.Field.prototype.formatValue = function(value, inputFormat='rgb'){ + if(this.format == null || value.length != this.bytes){ + console.error('formatValue() ERROR') + throw new Error('formatValue error') + } + + let newVal = new Array(this.bytes) + + for(i=0; i 0.0 && value <= 1.0) { value = Math.round(value * f.max); } @@ -96,16 +118,21 @@ Dmx.Field.prototype.computeValue = function(value){ console.log(value); + if(value === undefined || isNaN(value) || 'number' !== typeof value){ + console.warn('input type error', value) + throw new Error('Unexpected input type/value') + } + var arr=new Array(this.bytes); for(var i=0; i> i*8) & 255; - //console.log(byte); - //arr.push(byte); } + return arr; } + Dmx.DeviceTemplate = function(options){ this.fields = {}; this.name = ''; @@ -148,10 +175,22 @@ Dmx.Device.prototype.update = function(){ Dmx.emitter.emit('update.Device.'+this.name, this); } -Dmx.Device.prototype.set = function(name, value){ +Dmx.Device.prototype.set = function(name, value, format='rgb'){ console.log("Dmx.Device.setField() - " + name + ',' + value) f = this.getField(name); - this.values[f.name] = value; + + let newVal = value + + if(!Array.isArray(newVal)){ + console.log('computeValue', name, ' from', value) + newVal = f.computeValue(value) + } + else if(value.length == f.bytes && f.format != null){ + console.log('formatValue', name, ' from', value) + newVal = f.formatValue(value, format) + } + + this.values[f.name] = [...newVal]; Dmx.emitter.emit('change.Device.'+this.name, {device:this, field:f}); } @@ -167,7 +206,7 @@ Dmx.CommandClient = function(ros, servicePath){ serviceType : 'lighting_msgs/dmx_command' }); - this.command = {}; + this.command = Dmx.factory.createMessage('lighting_msgs/DmxCommand');; this.mode = 'replace'; } @@ -189,8 +228,10 @@ Dmx.CommandClient.prototype.add = function(dev){ } Dmx.CommandClient.prototype.setDevice = function(dev){ - console.log("Dmx.CommandClient.setDevice"); - this.command = Dmx.factory.createMessage('lighting_msgs/DmxCommand'); + console.log("Dmx.CommandClient.setDevice", dev); + if(!this.command){ + this.command = Dmx.factory.createMessage('lighting_msgs/DmxCommand'); + } var frame = Dmx.factory.createMessage('lighting_msgs/DmxFrame'); @@ -209,15 +250,22 @@ Dmx.CommandClient.prototype.setDevice = function(dev){ var val = dev.values[field.name]; - if(val.length != field.bytes){ - console.log(dev) - console.log(field) + if(val.length != field.bytes/* || val.length != field.bytes * field.length*/){ + console.error('FORMAT ERROR') + console.log('dev', dev) + console.log('field', field) + console.log('val', typeof val, val) throw "DMX data format error (expected " + field.bytes + "bytes but recieved " + val.length + ")"; } - for(i=0; i { console.log('Dmx.CommandClient: Result for service call on: ' + result.status); console.log(result); + this.command = Dmx.factory.createMessage('lighting_msgs/DmxCommand'); }, - function(err){ + (err)=>{ console.log("ERROR - Dmx.CommandClient: " + err); + this.command = Dmx.factory.createMessage('lighting_msgs/DmxCommand'); } ); } diff --git a/lighting_tools/dmx_terminal_www/src/js/ui-dmxmovercontrol.js b/lighting_tools/dmx_terminal_www/src/js/ui-dmxmovercontrol.js index 00f825c..14df3ed 100644 --- a/lighting_tools/dmx_terminal_www/src/js/ui-dmxmovercontrol.js +++ b/lighting_tools/dmx_terminal_www/src/js/ui-dmxmovercontrol.js @@ -161,12 +161,12 @@ Ui.DmxMoverControl.prototype.setupEventHandlers = function(){ polarPath = 'change.PolarInput.'+this.name+'.pan-tilt.hover'; Ui.emitter.on( polarPath, function(value){ - console.log('polar input changed'); + console.log('polar input hover'); console.log(value); - device.set('pan', value.theta); - device.set('tilt', (1-value.r) / 2); - device.update(); + //device.set('pan', value.theta); + //device.set('tilt', (1-value.r) / 2); + //device.update(); } ); diff --git a/lighting_tools/dmx_terminal_www/src/probe.html b/lighting_tools/dmx_terminal_www/src/probe.html index 79db554..33c20a1 100644 --- a/lighting_tools/dmx_terminal_www/src/probe.html +++ b/lighting_tools/dmx_terminal_www/src/probe.html @@ -42,7 +42,7 @@