Skip to content

Initial cleanup #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 74 additions & 24 deletions lighting_tools/dmx_terminal_www/src/js/dmx.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,43 @@ 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<this.bytes; i++){
newVal[i] = value[ inputFormat.indexOf(this.format[i]) ]
}

return newVal
}

Dmx.Field.prototype.computeValue = function(value){
if(value.length !== undefined && value.length > 0){
return value;
}

console.log('initial value', value)

if(value > 0.0 && value <= 1.0) {
value = Math.round(value * f.max);
}
Expand All @@ -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<this.bytes; i++){
arr[this.bytes - (1+i)] = (value >> i*8) & 255;
//console.log(byte);
//arr.push(byte);
}


return arr;
}


Dmx.DeviceTemplate = function(options){
this.fields = {};
this.name = '';
Expand Down Expand Up @@ -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});
}
Expand All @@ -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';
}
Expand All @@ -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');

Expand All @@ -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<field.length; i++){
for(j=0; j<val.length; j++){
dmxValue.data.push(val[j]);
if(field.length == null || val.length == field.bytes * field.length){
dmxValue.data = [... val]
}
else{
for(i=0; i<field.length; i++){
for(j=0; j<val.length; j++){
dmxValue.data.push(val[j]);
}
}
}

Expand All @@ -226,7 +274,7 @@ Dmx.CommandClient.prototype.setDevice = function(dev){

frame.durationMs = 1000;

this.command.layers = [frame];
this.command.layers.push(frame);
}

Dmx.CommandClient.prototype.set = function(dev, field){
Expand Down Expand Up @@ -270,12 +318,14 @@ Dmx.CommandClient.prototype.send = function(){
console.log(this.command);

this.srvClient.callService(request,
function(result) {
(result)=> {
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');
}
);
}
8 changes: 4 additions & 4 deletions lighting_tools/dmx_terminal_www/src/js/ui-dmxmovercontrol.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
);

Expand Down
128 changes: 60 additions & 68 deletions lighting_tools/dmx_terminal_www/src/probe.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
</script>

<script>
var dev;
var mover;
var f1;
var f2;
var f3;
Expand Down Expand Up @@ -78,82 +78,74 @@

dmxClient = new Dmx.CommandClient(ros);

dev = new Dmx.Device({name:'mover-01', address: "1.496"});
dmxClient.add(dev);

f = new Dmx.Field();
f.name = 'mode';
f.offset = 0;
dev.template.addField(f);
dev.set('mode', 255);

f = new Dmx.Field();
f.name = 'intensity';
f.offset = 1;
dev.template.addField(f);

f = new Dmx.Field();
f.name = 'pan';
f.offset = 2;
f.setBytes(2);
dev.template.addField(f);
//dev.set('pan', f.computeValue(0));

f = new Dmx.Field();
f.name = 'tilt';
f.offset = 4;
f.setBytes(2);
dev.template.addField(f);
//dev.set('tilt', f.computeValue(0));

f = new Dmx.Field();
f.name = 'zoom';
f.offset = 13;
dev.template.addField(f);

f = new Dmx.Field();
f.name = 'wheel';
f.offset = 7;
dev.template.addField(f);

f = new Dmx.Field();
f.name = 'red';
f.offset = 8;
dev.template.addField(f);

f = new Dmx.Field();
f.name = 'green';
f.offset = 9;
dev.template.addField(f);

f = new Dmx.Field();
f.name = 'blue';
f.offset = 10;
dev.template.addField(f);

f = new Dmx.Field();
f.name = 'white';
f.offset = 11;
dev.template.addField(f);

mover = new Dmx.Device({name:'mover-01', address: "1.496"});

mover.template.addField(new Dmx.Field({ name: 'pan', offset: 2, bytes: 2}))
mover.template.addField(new Dmx.Field({ name: 'tilt', offset: 4, bytes: 2}))
mover.template.addField(new Dmx.Field({ name: 'mode', offset: 0, bytes: 1, defaultVal: 255}))
mover.template.addField(new Dmx.Field({ name: 'intensity', offset: 1, bytes: 1}))
mover.template.addField(new Dmx.Field({ name: 'zoom', offset: 13, bytes: 1}))
mover.template.addField(new Dmx.Field({ name: 'wheel', offset: 7, bytes: 1}))
mover.template.addField(new Dmx.Field({name: 'color', offset: 8, length: 1, bytes: 3, format: 'rgb'}))
/*mover.template.addField(new Dmx.Field({ name: 'red', offset: 8, bytes: 1}))
mover.template.addField(new Dmx.Field({ name: 'green', offset: 9, bytes: 1}))
mover.template.addField(new Dmx.Field({ name: 'blue', offset: 10, bytes: 1}))*/
mover.template.addField(new Dmx.Field({ name: 'white', offset: 11, bytes: 1}))
mover.set('mode', [255]);
blinder.set('color', [0,0,0])
dmxClient.add(mover);

let blinder = new Dmx.Device({name:'blinder-01', address: "1.399"})
blinder.template.addField(new Dmx.Field({ name: 'fun', offset: 0, bytes: 1, defaultVal: 255}))
blinder.template.addField(new Dmx.Field({ name: 'color', offset: 1, length: 1, bytes: 3, defaultVal: 0, format: 'rgb'}))
blinder.template.addField(new Dmx.Field({ name: 'left-color', offset: 4, length: 1, bytes: 3, format: 'rgb'}))
blinder.template.addField(new Dmx.Field({ name: 'center-color', offset: 7, length: 1, bytes: 3, format: 'rgb'}))
blinder.template.addField(new Dmx.Field({ name: 'right-color', offset: 10, length: 1, bytes: 3, format:'rgb'}))
blinder.set('color', [0,0,0])
blinder.set('left-color', [0,0,0])
blinder.set('center-color', [0,0,0])
blinder.set('right-color', [0,0,0])
dmxClient.add(blinder);

pixels = new Dmx.Device({name:'pixels-01', address: "1.0"});
dmxClient.add(pixels);

f = new Dmx.Field();
f.name = 'pixels';
f.offset = 0;
f.length = 60;
f.setBytes(3);
pixels.template.addField(f);
pixels.set('pixels', [0,0,0]);
pixels.template.addField(new Dmx.Field({name: 'kitchen', offset: 0, length: 1, bytes: 3, format: 'rbg'}))
pixels.template.addField(new Dmx.Field({name: 'fridge', length: 8, bytes: 3, format: 'rbg', offset: pixels.getField('kitchen').nextOffset}))
pixels.template.addField(new Dmx.Field({name: 'top', length: 36, bytes: 3, format: 'rbg', offset: pixels.getField('fridge').nextOffset}))
pixels.template.addField(new Dmx.Field({name: 'window', length: 8, bytes: 3, format: 'rbg', offset: pixels.getField('top').nextOffset}))
pixels.template.addField(new Dmx.Field({name: 'couch', length: 25, bytes: 3, format: 'rbg', offset: pixels.getField('window').nextOffset}))
pixels.template.addField(new Dmx.Field({name: 'bottom', length: 20, bytes: 3, format: 'rbg', offset: pixels.getField('couch').nextOffset}))
pixels.set('top', [20,20,20])
pixels.set('kitchen', [0,00,40])
pixels.set('fridge', [50,150,50])
pixels.set('window', [0,10,0])
pixels.set('couch', [80,0,80])
pixels.set('bottom', [80,180,80])

dmxClient.setDevice(pixels)
dmxClient.send()


Ui.emitter.on('select.TileGrid.pixels',
function(evt){
var v = 255* (evt.x + (evt.y * 32)) / (32*16);

pixels.set('pixels', [v,v,v]);
blinder.set('right-color', [v,v/2,v/2])
blinder.set('center-color', [v,v,v])
blinder.set('left-color', [v,v/2,v/2])
//blinder.set('left-color', [v,0,0])
//blinder.set('center-color', [0,v,0])
//blinder.set('right-color', [0,0,v])

pixels.set('top', [v,v,v])
pixels.set('kitchen', [v,v,v])
pixels.set('fridge', [v,v,v])
pixels.set('bottom', [v,v,v])
dmxClient.setDevice(pixels);
dmxClient.send();
dmxClient.setDevice(blinder);
dmxClient.send()
}
);

Expand Down Expand Up @@ -214,7 +206,7 @@

moverMargins = {inner: {x: 0, y: 10}, outer: {x:10, y:5}};
var c = JSON.parse(JSON.stringify({name: options.name, x: options.x, y: options.y, margins: moverMargins, width: 200, height:300}));
c.device = dev;
c.device = mover;
view.mover1 = new Ui.DmxMoverControl(view.stage, c);

options.x += view.mover1.layer.width();
Expand Down