$(document).ready(function() { var modalOpened = false; var ledsim_width = 540; var ledsim_height = 489; var dialog; var leds; var lC = false; var imageCanvasNodeCtx; var ledsCanvasNodeCtx; var canvas_height; var canvas_width; var twoDPaths = []; var toggleLeds, toggleLedsNum = 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_html += ''; $('#leds_canvas').html(leds_html); imageCanvasNodeCtx = document.getElementById("image_preview_canv").getContext("2d"); ledsCanvasNodeCtx = document.getElementById("leds_preview_canv").getContext("2d"); create2dPaths(); printLedsToCanvas(); resetImage(); } // ------------------------------------------------------------------ $('#leds_toggle_num').off().on("click", function() { toggleLedsNum = !toggleLedsNum toggleClass('#leds_toggle_num', "btn-danger", "btn-success"); }); // ------------------------------------------------------------------ $('#leds_toggle').off().on("click", function() { toggleLeds = !toggleLeds ledsCanvasNodeCtx.clear(); toggleClass('#leds_toggle', "btn-success", "btn-danger"); }); // ------------------------------------------------------------------ $('#leds_toggle_live_video').off().on("click", function() { setClassByBool('#leds_toggle_live_video',window.imageStreamActive,"btn-success","btn-danger"); if ( window.imageStreamActive ) { requestLedImageStop(); resetImage(); } else { requestLedImageStart(); } }); // ------------------------------------------------------------------ $(window.hyperion).on("cmd-ledcolors-ledstream-update",function(event){ if (!modalOpened) { requestLedColorsStop(); } else { printLedsToCanvas(event.response.result.leds) } }); // ------------------------------------------------------------------ $(window.hyperion).on("cmd-ledcolors-imagestream-update",function(event){ setClassByBool('#leds_toggle_live_video', window.imageStreamActive, "btn-danger", "btn-success"); if (!modalOpened) { if ($('#leds_prev_toggle_live_video').length > 0) return; requestLedImageStop(); } else { var imageData = (event.response.result.image); var image = new Image(); image.onload = function() { imageCanvasNodeCtx.drawImage(image, 0, 0, canvas_width, canvas_height); }; image.src = imageData; } }); $("#btn_open_ledsim").off().on("click", function(event) { dialog.open(); }); // ------------------------------------------------------------------ $(window.hyperion).on("cmd-settings-update",function(event){ var obj = event.response.data if ( obj.leds) { console.log("ledsim: cmd-settings-update", event.response.data); Object.getOwnPropertyNames(obj).forEach(function(val, idx, array) { window.serverInfo[val] = obj[val]; }); leds = window.serverConfig.leds updateLedLayout(); } }); function resetImage(){ if (getStorage("darkMode", false) == "on") { imageCanvasNodeCtx.clear(); } else { imageCanvasNodeCtx.fillStyle = "rgb(225,225,225)" imageCanvasNodeCtx.fillRect(0, 0, canvas_width, canvas_height); } var image = document.getElementById('navbar_brand_logo'); imageCanvasNodeCtx.drawImage(image, canvas_width / 2 - image.width / 2, canvas_height / 2 - image.height / 2, image.width, image.height); } });