2017-01-17 21:53:35 +01:00
|
|
|
$(document).ready(function() {
|
|
|
|
var modalOpened = false;
|
|
|
|
var ledsim_width = 540;
|
|
|
|
var ledsim_height = 489;
|
|
|
|
var dialog;
|
|
|
|
var leds;
|
2017-02-08 14:36:28 +01:00
|
|
|
var lC = false;
|
2018-12-20 14:33:28 +01:00
|
|
|
var imageCanvasNodeCtx;
|
|
|
|
var ledsCanvasNodeCtx;
|
|
|
|
var canvas_height;
|
|
|
|
var canvas_width;
|
|
|
|
var twoDPaths = [];
|
|
|
|
var toggleLeds = false;
|
|
|
|
|
|
|
|
/// add prototype for simple canvas clear() method
|
|
|
|
CanvasRenderingContext2D.prototype.clear = function(){
|
|
|
|
this.clearRect(0, 0, this.canvas.width, this.canvas.height)
|
|
|
|
};
|
|
|
|
|
|
|
|
function create2dPaths(){
|
|
|
|
twoDPaths = [];
|
|
|
|
for(var idx=0; idx<leds.length; idx++)
|
|
|
|
{
|
|
|
|
var led = leds[idx];
|
|
|
|
twoDPaths.push( build2DPath(led.hscan.minimum * canvas_width, led.vscan.minimum * canvas_height, (led.hscan.maximum-led.hscan.minimum) * canvas_width, (led.vscan.maximum-led.vscan.minimum) * canvas_height, 5) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draws a rounded rectangle into a new Path2D object, returns the created path.
|
|
|
|
* If you omit the last three params, it will draw a rectangle
|
|
|
|
* outline with a 5 pixel border radius
|
|
|
|
* @param {Number} x The top left x coordinate
|
|
|
|
* @param {Number} y The top left y coordinate
|
|
|
|
* @param {Number} width The width of the rectangle
|
|
|
|
* @param {Number} height The height of the rectangle
|
|
|
|
* @param {Number} [radius = 5] The corner radius; It can also be an object
|
|
|
|
* to specify different radii for corners
|
|
|
|
* @param {Number} [radius.tl = 0] Top left
|
|
|
|
* @param {Number} [radius.tr = 0] Top right
|
|
|
|
* @param {Number} [radius.br = 0] Bottom right
|
|
|
|
* @param {Number} [radius.bl = 0] Bottom left
|
|
|
|
* @return {Path2D} The final path
|
|
|
|
*/
|
|
|
|
function build2DPath(x, y, width, height, radius) {
|
|
|
|
var useColor = false
|
|
|
|
if (typeof stroke == 'undefined') {
|
|
|
|
stroke = true;
|
|
|
|
}
|
|
|
|
if (typeof radius === 'undefined') {
|
|
|
|
radius = 5;
|
|
|
|
}
|
|
|
|
if (typeof radius === 'number') {
|
|
|
|
radius = {tl: radius, tr: radius, br: radius, bl: radius};
|
|
|
|
} else {
|
|
|
|
var defaultRadius = {tl: 0, tr: 0, br: 0, bl: 0};
|
|
|
|
for (var side in defaultRadius) {
|
|
|
|
radius[side] = radius[side] || defaultRadius[side];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var path = new Path2D()
|
|
|
|
|
|
|
|
path.moveTo(x + radius.tl, y);
|
|
|
|
path.lineTo(x + width - radius.tr, y);
|
|
|
|
path.quadraticCurveTo(x + width, y, x + width, y + radius.tr);
|
|
|
|
path.lineTo(x + width, y + height - radius.br);
|
|
|
|
path.quadraticCurveTo(x + width, y + height, x + width - radius.br, y + height);
|
|
|
|
path.lineTo(x + radius.bl, y + height);
|
|
|
|
path.quadraticCurveTo(x, y + height, x, y + height - radius.bl);
|
|
|
|
path.lineTo(x, y + radius.tl);
|
|
|
|
path.quadraticCurveTo(x, y, x + radius.tl, y);
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2017-02-08 14:36:28 +01:00
|
|
|
$(hyperion).one("ready",function(){
|
|
|
|
leds = serverConfig.leds;
|
2018-12-20 14:33:28 +01:00
|
|
|
|
2017-02-08 14:36:28 +01:00
|
|
|
if(showOptHelp)
|
|
|
|
{
|
|
|
|
createHint('intro', $.i18n('main_ledsim_text'), 'ledsim_text');
|
|
|
|
$('#ledsim_text').css({'margin':'10px 15px 0px 15px'});
|
2017-07-30 14:36:23 +02:00
|
|
|
$('#ledsim_text .bs-callout').css("margin","0px")
|
2017-02-08 14:36:28 +01:00
|
|
|
}
|
2018-12-20 14:33:28 +01:00
|
|
|
|
2017-02-08 14:36:28 +01:00
|
|
|
if(getStorage('ledsim_width') != null)
|
2017-01-17 21:53:35 +01:00
|
|
|
{
|
|
|
|
ledsim_width = getStorage('ledsim_width');
|
|
|
|
ledsim_height = getStorage('ledsim_height');
|
|
|
|
}
|
2018-12-20 14:33:28 +01:00
|
|
|
|
2017-01-17 21:53:35 +01:00
|
|
|
dialog = $("#ledsim_dialog").dialog({
|
|
|
|
uiLibrary: 'bootstrap',
|
|
|
|
resizable: true,
|
|
|
|
modal: false,
|
|
|
|
minWidth: 250,
|
|
|
|
width: ledsim_width,
|
|
|
|
minHeight: 350,
|
|
|
|
height: ledsim_height,
|
|
|
|
closeOnEscape: true,
|
|
|
|
autoOpen: false,
|
|
|
|
title: $.i18n('main_ledsim_title'),
|
|
|
|
resize: function (e) {
|
|
|
|
updateLedLayout();
|
|
|
|
},
|
|
|
|
opened: function (e) {
|
2017-02-08 14:36:28 +01:00
|
|
|
if(!lC)
|
|
|
|
{
|
|
|
|
updateLedLayout();
|
|
|
|
lC = true;
|
|
|
|
}
|
2017-01-17 21:53:35 +01:00
|
|
|
modalOpened = true;
|
|
|
|
requestLedColorsStart();
|
2018-12-20 14:33:28 +01:00
|
|
|
|
2017-01-17 21:53:35 +01:00
|
|
|
if($('#leds_toggle_live_video').hasClass('btn-success'))
|
|
|
|
requestLedImageStart();
|
|
|
|
},
|
|
|
|
closed: function (e) {
|
|
|
|
modalOpened = false;
|
|
|
|
},
|
|
|
|
resizeStop: function (e) {
|
2017-02-08 14:36:28 +01:00
|
|
|
setStorage("ledsim_width", $("#ledsim_dialog").outerWidth());
|
2018-12-20 14:33:28 +01:00
|
|
|
setStorage("ledsim_height", $("#ledsim_dialog").outerHeight());
|
2017-01-17 21:53:35 +01:00
|
|
|
}
|
2017-02-08 14:36:28 +01:00
|
|
|
});
|
2018-12-20 14:33:28 +01:00
|
|
|
// apply new serverinfos
|
|
|
|
$(hyperion).on("cmd-config-getconfig",function(event){
|
|
|
|
leds = event.response.info.leds;
|
|
|
|
updateLedLayout();
|
|
|
|
});
|
2017-01-17 21:53:35 +01:00
|
|
|
});
|
2018-12-20 14:33:28 +01:00
|
|
|
|
|
|
|
function printLedsToCanvas(colors)
|
2017-01-17 21:53:35 +01:00
|
|
|
{
|
2018-12-20 14:33:28 +01:00
|
|
|
// toggle leds, do not print
|
|
|
|
if(toggleLeds)
|
|
|
|
return
|
|
|
|
|
|
|
|
var useColor = false;
|
|
|
|
ledsCanvasNodeCtx.clear();
|
|
|
|
if(typeof colors != "undefined")
|
|
|
|
useColor = true;
|
|
|
|
|
2017-01-17 21:53:35 +01:00
|
|
|
for(var idx=0; idx<leds.length; idx++)
|
|
|
|
{
|
2018-12-20 14:33:28 +01:00
|
|
|
var led = leds[idx];
|
|
|
|
// can be used as fallback when Path2D is not available
|
|
|
|
//roundRect(ledsCanvasNodeCtx, led.hscan.minimum * canvas_width, led.vscan.minimum * canvas_height, (led.hscan.maximum-led.hscan.minimum) * canvas_width, (led.vscan.maximum-led.vscan.minimum) * canvas_height, 4, true, colors[idx])
|
|
|
|
//ledsCanvasNodeCtx.fillRect(led.hscan.minimum * canvas_width, led.vscan.minimum * canvas_height, (led.hscan.maximum-led.hscan.minimum) * canvas_width, (led.vscan.maximum-led.vscan.minimum) * canvas_height);
|
|
|
|
ledsCanvasNodeCtx.fillStyle = (useColor) ? "rgba("+colors[idx].red+","+colors[idx].green+","+colors[idx].blue+",0.9)" : "hsl("+(idx*360/leds.length)+",100%,50%)";
|
|
|
|
ledsCanvasNodeCtx.fill(twoDPaths[idx]);
|
|
|
|
ledsCanvasNodeCtx.stroke(twoDPaths[idx]);
|
2017-01-17 21:53:35 +01:00
|
|
|
}
|
2018-12-20 14:33:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateLedLayout()
|
|
|
|
{
|
|
|
|
//calculate body size
|
|
|
|
canvas_height = $('#ledsim_dialog').outerHeight()-$('#ledsim_text').outerHeight()-$('[data-role=footer]').outerHeight()-$('[data-role=header]').outerHeight()-40;
|
|
|
|
canvas_width = $('#ledsim_dialog').outerWidth()-30;
|
|
|
|
|
|
|
|
$('#leds_canvas').html("");
|
|
|
|
leds_html = '<canvas id="image_preview_canv" width="'+canvas_width+'" height="'+canvas_height+'" style="position: absolute; left: 0; top: 0; z-index: 99998;"></canvas>';
|
|
|
|
leds_html += '<canvas id="leds_preview_canv" width="'+canvas_width+'" height="'+canvas_height+'" style="position: absolute; left: 0; top: 0; z-index: 99999;"></canvas>';
|
|
|
|
|
2017-01-17 21:53:35 +01:00
|
|
|
$('#leds_canvas').html(leds_html);
|
2018-12-20 14:33:28 +01:00
|
|
|
|
|
|
|
imageCanvasNodeCtx = document.getElementById("image_preview_canv").getContext("2d");
|
|
|
|
ledsCanvasNodeCtx = document.getElementById("leds_preview_canv").getContext("2d");
|
|
|
|
create2dPaths();
|
|
|
|
printLedsToCanvas();
|
|
|
|
resetImage()
|
2017-01-17 21:53:35 +01:00
|
|
|
}
|
|
|
|
|
2018-12-20 14:33:28 +01:00
|
|
|
// -----------------------FIX THIS-------------------------
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
// $('#leds_toggle_num').off().on("click", function() {
|
|
|
|
// $('.led_num').toggle();
|
|
|
|
// toggleClass('#leds_toggle_num', "btn-danger", "btn-success");
|
|
|
|
//});
|
2017-01-17 21:53:35 +01:00
|
|
|
// ------------------------------------------------------------------
|
2018-12-20 14:33:28 +01:00
|
|
|
|
2017-01-17 21:53:35 +01:00
|
|
|
$('#leds_toggle').off().on("click", function() {
|
2018-12-20 14:33:28 +01:00
|
|
|
toggleLeds = !toggleLeds
|
|
|
|
ledsCanvasNodeCtx.clear();
|
2017-01-17 21:53:35 +01:00
|
|
|
toggleClass('#leds_toggle', "btn-success", "btn-danger");
|
|
|
|
});
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
$('#leds_toggle_live_video').off().on("click", function() {
|
|
|
|
setClassByBool('#leds_toggle_live_video',imageStreamActive,"btn-success","btn-danger");
|
|
|
|
if ( imageStreamActive )
|
|
|
|
{
|
|
|
|
requestLedImageStop();
|
2018-12-20 14:33:28 +01:00
|
|
|
resetImage();
|
2017-01-17 21:53:35 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
requestLedImageStart();
|
|
|
|
}
|
|
|
|
});
|
2018-12-20 14:33:28 +01:00
|
|
|
|
2017-01-17 21:53:35 +01:00
|
|
|
// ------------------------------------------------------------------
|
|
|
|
$(hyperion).on("cmd-ledcolors-ledstream-update",function(event){
|
|
|
|
if (!modalOpened)
|
|
|
|
{
|
|
|
|
requestLedColorsStop();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-20 14:33:28 +01:00
|
|
|
printLedsToCanvas(event.response.result.leds)
|
2017-01-17 21:53:35 +01:00
|
|
|
}
|
|
|
|
});
|
2018-12-20 14:33:28 +01:00
|
|
|
|
2017-01-17 21:53:35 +01:00
|
|
|
// ------------------------------------------------------------------
|
|
|
|
$(hyperion).on("cmd-ledcolors-imagestream-update",function(event){
|
|
|
|
if (!modalOpened)
|
|
|
|
{
|
|
|
|
requestLedImageStop();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
imageData = (event.response.result.image);
|
2018-12-20 14:33:28 +01:00
|
|
|
|
|
|
|
var image = new Image();
|
|
|
|
image.onload = function() {
|
|
|
|
imageCanvasNodeCtx.drawImage(image, 0, 0, canvas_width, canvas_height);
|
|
|
|
};
|
|
|
|
image.src = imageData;
|
2017-01-17 21:53:35 +01:00
|
|
|
}
|
|
|
|
});
|
2018-12-20 14:33:28 +01:00
|
|
|
|
2017-01-17 21:53:35 +01:00
|
|
|
$("#btn_open_ledsim").off().on("click", function(event) {
|
|
|
|
dialog.open();
|
|
|
|
});
|
2018-12-20 14:33:28 +01:00
|
|
|
|
|
|
|
function resetImage(){
|
|
|
|
imageCanvasNodeCtx.fillStyle = "rgb(225,225,225)"
|
|
|
|
imageCanvasNodeCtx.fillRect(0, 0, canvas_width, canvas_height);
|
|
|
|
var image = new Image();
|
|
|
|
image.onload = function() {
|
|
|
|
imageCanvasNodeCtx.drawImage(image, canvas_width*0.3, canvas_height*0.38);
|
|
|
|
};
|
|
|
|
image.src ='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOgAAABQCAYAAAATMDlgAAAABGdBTUEAALGPC/xhBQAACjppQ0NQUGhvdG9zaG9wIElDQyBwcm9maWxlAABIiZ2Wd1RU1xaHz713eqHNMBQpQ++9DSC9N6nSRGGYGWAoAw4zNLEhogIRRUQEFUGCIgaMhiKxIoqFgGDBHpAgoMRgFFFReTOyVnTl5b2Xl98fZ31rn733PWfvfda6AJC8/bm8dFgKgDSegB/i5UqPjIqmY/sBDPAAA8wAYLIyMwJCPcOASD4ebvRMkRP4IgiAN3fEKwA3jbyD6HTw/0malcEXiNIEidiCzclkibhQxKnZggyxfUbE1PgUMcMoMfNFBxSxvJgTF9nws88iO4uZncZji1h85gx2GlvMPSLemiXkiBjxF3FRFpeTLeJbItZMFaZxRfxWHJvGYWYCgCKJ7QIOK0nEpiIm8cNC3ES8FAAcKfErjv+KBZwcgfhSbukZuXxuYpKArsvSo5vZ2jLo3pzsVI5AYBTEZKUw+Wy6W3paBpOXC8DinT9LRlxbuqjI1ma21tZG5sZmXxXqv27+TYl7u0ivgj/3DKL1fbH9lV96PQCMWVFtdnyxxe8FoGMzAPL3v9g0DwIgKepb+8BX96GJ5yVJIMiwMzHJzs425nJYxuKC/qH/6fA39NX3jMXp/igP3Z2TwBSmCujiurHSU9OFfHpmBpPFoRv9eYj/ceBfn8MwhJPA4XN4oohw0ZRxeYmidvPYXAE3nUfn8v5TE/9h2J+0ONciURo+AWqsMZAaoALk1z6AohABEnNAtAP90Td/fDgQv7wI1YnFuf8s6N+zwmXiJZOb+DnOLSSMzhLysxb3xM8SoAEBSAIqUAAqQAPoAiNgDmyAPXAGHsAXBIIwEAVWARZIAmmAD7JBPtgIikAJ2AF2g2pQCxpAE2gBJ0A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