2016-09-06 10:14:54 +02:00
|
|
|
|
|
|
|
var ledsCustomCfgInitialized = false;
|
2016-11-18 18:39:27 +01:00
|
|
|
var finalLedArray = [];
|
2017-04-07 21:33:40 +02:00
|
|
|
var conf_editor = null;
|
2016-09-06 10:14:54 +02:00
|
|
|
|
2016-11-30 17:32:12 +01:00
|
|
|
function round(number) {
|
|
|
|
var factor = Math.pow(10, 4);
|
|
|
|
var tempNumber = number * factor;
|
|
|
|
var roundedTempNumber = Math.round(tempNumber);
|
|
|
|
return roundedTempNumber / factor;
|
|
|
|
};
|
|
|
|
|
2016-11-18 18:39:27 +01:00
|
|
|
function createLedPreview(leds, origin){
|
2016-12-04 19:32:23 +01:00
|
|
|
|
2016-11-18 18:39:27 +01:00
|
|
|
if (origin == "classic"){
|
2017-01-17 21:53:35 +01:00
|
|
|
$('#previewcreator').html($.i18n('conf_leds_layout_preview_originCL'));
|
2016-11-18 18:39:27 +01:00
|
|
|
$('#leds_preview').css("padding-top", "56.25%");
|
|
|
|
}
|
|
|
|
else if(origin == "text"){
|
2017-01-17 21:53:35 +01:00
|
|
|
$('#previewcreator').html($.i18n('conf_leds_layout_preview_originTEXT'));
|
2016-11-18 18:39:27 +01:00
|
|
|
$('#leds_preview').css("padding-top", "56.25%");
|
|
|
|
}
|
|
|
|
else if(origin == "matrix"){
|
2017-01-17 21:53:35 +01:00
|
|
|
$('#previewcreator').html($.i18n('conf_leds_layout_preview_originMA'));
|
2016-11-18 18:39:27 +01:00
|
|
|
$('#leds_preview').css("padding-top", "100%");
|
|
|
|
}
|
|
|
|
|
2017-01-17 21:53:35 +01:00
|
|
|
$('#previewledcount').html($.i18n('conf_leds_layout_preview_totalleds', leds.length));
|
2017-02-28 17:53:41 +01:00
|
|
|
$('#previewledpower').html($.i18n('conf_leds_layout_preview_ledpower', ((leds.length * 0.06)*1.1).toFixed(1)));
|
2016-11-18 18:39:27 +01:00
|
|
|
|
|
|
|
$('.st_helper').css("border", "8px solid grey");
|
|
|
|
|
|
|
|
canvas_height = $('#leds_preview').innerHeight();
|
|
|
|
canvas_width = $('#leds_preview').innerWidth();
|
|
|
|
|
|
|
|
leds_html = "";
|
|
|
|
for(var idx=0; idx<leds.length; idx++)
|
|
|
|
{
|
|
|
|
led = leds[idx];
|
|
|
|
led_id='ledc_'+[idx];
|
|
|
|
bgcolor = "background-color:hsl("+(idx*360/leds.length)+",100%,50%);";
|
|
|
|
pos = "left:"+(led.hscan.minimum * canvas_width)+"px;"+
|
|
|
|
"top:"+(led.vscan.minimum * canvas_height)+"px;"+
|
|
|
|
"width:"+((led.hscan.maximum-led.hscan.minimum) * canvas_width-1)+"px;"+
|
|
|
|
"height:"+((led.vscan.maximum-led.vscan.minimum) * canvas_height-1)+"px;";
|
2016-12-08 23:39:41 +01:00
|
|
|
leds_html += '<div id="'+led_id+'" class="led" style="'+bgcolor+pos+'" title="'+led.index+'"><span id="'+led_id+'_num" class="led_prev_num">'+led.index+'</span></div>';
|
2016-11-18 18:39:27 +01:00
|
|
|
}
|
|
|
|
$('#leds_preview').html(leds_html);
|
2016-11-30 17:32:12 +01:00
|
|
|
$('#ledc_0').css({"background-color":"black","z-index":"12"});
|
|
|
|
$('#ledc_1').css({"background-color":"grey","z-index":"11"});
|
2016-11-18 18:39:27 +01:00
|
|
|
$('#ledc_2').css({"background-color":"#A9A9A9","z-index":"10"});
|
2016-11-30 17:32:12 +01:00
|
|
|
|
|
|
|
if($('#leds_prev_toggle_num').hasClass('btn-success'))
|
|
|
|
$('.led_prev_num').css("display", "inline");
|
2016-12-04 19:32:23 +01:00
|
|
|
|
2016-11-18 18:39:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function createClassicLeds(){
|
|
|
|
//get values
|
2017-02-15 15:53:35 +01:00
|
|
|
var ledstop = parseInt($("#ip_cl_top").val());
|
|
|
|
var ledsbottom = parseInt($("#ip_cl_bottom").val());
|
|
|
|
var ledsleft = parseInt($("#ip_cl_left").val());
|
|
|
|
var ledsright = parseInt($("#ip_cl_right").val());
|
|
|
|
var ledsglength = parseInt($("#ip_cl_glength").val());
|
|
|
|
var ledsgpos = parseInt($("#ip_cl_gpos").val());
|
2016-11-18 18:39:27 +01:00
|
|
|
var position = parseInt($("#ip_cl_position").val());
|
|
|
|
var reverse = $("#ip_cl_reverse").is(":checked");
|
|
|
|
|
|
|
|
//advanced values
|
2017-02-15 15:53:35 +01:00
|
|
|
var ledsVDepth = parseInt($("#ip_cl_vdepth").val())/100;
|
|
|
|
var ledsHDepth = parseInt($("#ip_cl_hdepth").val())/100;
|
|
|
|
var edgeVGap = parseInt($("#ip_cl_edgegap").val())/100/2;
|
|
|
|
//var cornerVGap = parseInt($("#ip_cl_cornergap").val())/100/2;
|
2017-02-08 14:36:28 +01:00
|
|
|
var overlap = $("#ip_cl_overlap").val()/4000;
|
2016-11-18 18:39:27 +01:00
|
|
|
|
|
|
|
//helper
|
2016-11-30 17:32:12 +01:00
|
|
|
var edgeHGap = edgeVGap/(16/9);
|
2017-02-08 14:36:28 +01:00
|
|
|
//var cornerHGap = cornerVGap/(16/9);
|
2016-11-30 17:32:12 +01:00
|
|
|
var Vmin = 0.0 + edgeVGap;
|
|
|
|
var Vmax = 1.0 - edgeVGap;
|
|
|
|
var Hmin = 0.0 + edgeHGap;
|
|
|
|
var Hmax = 1.0 - edgeHGap;
|
2017-02-08 14:36:28 +01:00
|
|
|
var Hdiff = Hmax-Hmin;
|
|
|
|
var Vdiff = Vmax-Vmin;
|
2016-11-18 18:39:27 +01:00
|
|
|
var ledArray = [];
|
|
|
|
|
|
|
|
function createFinalArray(array){
|
2016-11-21 22:16:57 +01:00
|
|
|
finalLedArray = [];
|
2016-11-18 18:39:27 +01:00
|
|
|
for(var i = 0; i<array.length; i++){
|
|
|
|
hmin = array[i].hscan.minimum;
|
|
|
|
hmax = array[i].hscan.maximum;
|
|
|
|
vmin = array[i].vscan.minimum;
|
|
|
|
vmax = array[i].vscan.maximum;
|
|
|
|
finalLedArray[i] = { "index" : i, "hscan": { "maximum" : hmax, "minimum" : hmin }, "vscan": { "maximum": vmax, "minimum": vmin}}
|
|
|
|
}
|
2016-12-08 23:39:41 +01:00
|
|
|
createLedPreview(finalLedArray, 'classic');
|
2016-11-18 18:39:27 +01:00
|
|
|
}
|
2017-02-08 14:36:28 +01:00
|
|
|
|
2016-11-18 18:39:27 +01:00
|
|
|
function rotateArray(array, times){
|
2017-02-28 17:53:41 +01:00
|
|
|
if (times > 0){
|
2016-11-18 18:39:27 +01:00
|
|
|
while( times-- ){
|
|
|
|
array.push(array.shift())
|
|
|
|
}
|
|
|
|
return array;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while( times++ ){
|
|
|
|
array.unshift(array.pop())
|
|
|
|
}
|
|
|
|
return array;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-08 14:36:28 +01:00
|
|
|
function valScan(val)
|
|
|
|
{
|
|
|
|
if(val > 1)
|
|
|
|
return val = 1;
|
|
|
|
if(val < 0)
|
|
|
|
return val = 0;
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
function ovl(scan,val)
|
|
|
|
{
|
|
|
|
if(scan == "+")
|
|
|
|
return valScan(val += overlap);
|
|
|
|
else
|
|
|
|
return valScan(val -= overlap);
|
|
|
|
}
|
|
|
|
|
2016-11-18 18:39:27 +01:00
|
|
|
function createLedArray(hmin, hmax, vmin, vmax){
|
2016-11-30 17:32:12 +01:00
|
|
|
hmin = round(hmin);
|
|
|
|
hmax = round(hmax);
|
|
|
|
vmin = round(vmin);
|
|
|
|
vmax = round(vmax);
|
2016-11-18 18:39:27 +01:00
|
|
|
ledArray.push( { "hscan" : { "minimum" : hmin, "maximum" : hmax }, "vscan": { "minimum": vmin, "maximum": vmax }} );
|
|
|
|
}
|
|
|
|
|
|
|
|
function createTopLeds(){
|
2017-01-17 21:53:35 +01:00
|
|
|
step=(Hmax-Hmin)/ledstop;
|
2017-02-08 14:36:28 +01:00
|
|
|
//if(cornerVGap != '0')
|
|
|
|
// step=(Hmax-Hmin-(cornerHGap*2))/ledstop;
|
|
|
|
|
|
|
|
vmin=Vmin;
|
2016-11-18 18:39:27 +01:00
|
|
|
vmax=vmin+ledsHDepth;
|
2017-01-17 21:53:35 +01:00
|
|
|
for (var i = 0; i<ledstop; i++){
|
2017-02-08 14:36:28 +01:00
|
|
|
hmin = ovl("-",(Hdiff/ledstop*[i])+edgeHGap);
|
|
|
|
hmax = ovl("+",(Hdiff/ledstop*[i])+step+edgeHGap);
|
2016-11-18 18:39:27 +01:00
|
|
|
createLedArray(hmin, hmax, vmin, vmax);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function createLeftLeds(){
|
2017-01-17 21:53:35 +01:00
|
|
|
step=(Vmax-Vmin)/ledsleft;
|
2017-02-08 14:36:28 +01:00
|
|
|
//if(cornerVGap != '0')
|
|
|
|
// step=(Vmax-Vmin-(cornerVGap*2))/ledsleft;
|
|
|
|
|
2016-11-30 17:32:12 +01:00
|
|
|
hmin=Hmin;
|
|
|
|
hmax=hmin+ledsVDepth;
|
2017-02-08 14:36:28 +01:00
|
|
|
for (var i = ledsleft-1; i>-1; --i){
|
|
|
|
vmin = ovl("-",(Vdiff/ledsleft*[i])+edgeVGap);
|
|
|
|
vmax = ovl("+",(Vdiff/ledsleft*[i])+step+edgeVGap);
|
2016-11-18 18:39:27 +01:00
|
|
|
createLedArray(hmin, hmax, vmin, vmax);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function createRightLeds(){
|
2017-01-17 21:53:35 +01:00
|
|
|
step=(Vmax-Vmin)/ledsright;
|
2017-02-08 14:36:28 +01:00
|
|
|
//if(cornerVGap != '0')
|
|
|
|
// step=(Vmax-Vmin-(cornerVGap*2))/ledsright;
|
|
|
|
|
2016-11-30 17:32:12 +01:00
|
|
|
hmax=Hmax;
|
2016-11-18 18:39:27 +01:00
|
|
|
hmin=hmax-ledsVDepth;
|
2017-01-17 21:53:35 +01:00
|
|
|
for (var i = 0; i<ledsright; i++){
|
2017-02-08 14:36:28 +01:00
|
|
|
vmin = ovl("-",(Vdiff/ledsright*[i])+edgeVGap);
|
|
|
|
vmax = ovl("+",(Vdiff/ledsright*[i])+step+edgeVGap);
|
|
|
|
createLedArray(hmin, hmax, vmin, vmax);
|
2016-11-18 18:39:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function createBottomLeds(){
|
2017-01-17 21:53:35 +01:00
|
|
|
step=(Hmax-Hmin)/ledsbottom;
|
2017-02-08 14:36:28 +01:00
|
|
|
//if(cornerVGap != '0')
|
|
|
|
// step=(Hmax-Hmin-(cornerHGap*2))/ledsbottom;
|
|
|
|
|
2016-11-30 17:32:12 +01:00
|
|
|
vmax=Vmax;
|
2016-11-18 18:39:27 +01:00
|
|
|
vmin=vmax-ledsHDepth;
|
2017-02-08 14:36:28 +01:00
|
|
|
for (var i = ledsbottom-1; i>-1; i--){
|
|
|
|
hmin = ovl("-",(Hdiff/ledsbottom*[i])+edgeHGap);
|
|
|
|
hmax = ovl("+",(Hdiff/ledsbottom*[i])+step+edgeHGap);
|
2016-11-18 18:39:27 +01:00
|
|
|
createLedArray(hmin, hmax, vmin, vmax);
|
|
|
|
}
|
|
|
|
}
|
2016-12-08 23:39:41 +01:00
|
|
|
|
|
|
|
createLeftLeds(createBottomLeds(createRightLeds(createTopLeds())));
|
|
|
|
|
2017-02-08 14:36:28 +01:00
|
|
|
//check led gap pos
|
|
|
|
if (ledsgpos+ledsglength > ledArray.length)
|
|
|
|
{
|
|
|
|
var mpos = Math.max(0,ledArray.length-ledsglength);
|
|
|
|
$('#ip_cl_ledsgpos').val(mpos);
|
|
|
|
ledsgpos = mpos;
|
|
|
|
}
|
|
|
|
|
|
|
|
//check led gap length
|
|
|
|
if(ledsglength >= ledArray.length)
|
|
|
|
{
|
|
|
|
$('#ip_cl_ledsglength').val(ledArray.length-1);
|
|
|
|
ledsglength = ledArray.length-ledsglength-1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ledsglength != 0){
|
2017-01-17 21:53:35 +01:00
|
|
|
ledArray.splice(ledsgpos, ledsglength);
|
2016-12-08 23:39:41 +01:00
|
|
|
}
|
|
|
|
|
2017-02-08 14:36:28 +01:00
|
|
|
if (position != 0){
|
2016-12-08 23:39:41 +01:00
|
|
|
rotateArray(ledArray, position);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (reverse)
|
|
|
|
ledArray.reverse();
|
|
|
|
|
|
|
|
createFinalArray(ledArray);
|
2016-11-18 18:39:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function createMatrixLeds(){
|
|
|
|
// Big thank you to RanzQ (Juha Rantanen) from Github for this script
|
|
|
|
// https://raw.githubusercontent.com/RanzQ/hyperion-audio-effects/master/matrix-config.js
|
2016-12-04 19:32:23 +01:00
|
|
|
|
2016-11-18 18:39:27 +01:00
|
|
|
//get values
|
2017-01-17 21:53:35 +01:00
|
|
|
var ledshoriz = parseInt($("#ip_ma_ledshoriz").val());
|
|
|
|
var ledsvert = parseInt($("#ip_ma_ledsvert").val());
|
2016-11-18 18:39:27 +01:00
|
|
|
var cabling = $("#ip_ma_cabling").val();
|
|
|
|
//var order = $("#ip_ma_order").val();
|
|
|
|
var start = $("#ip_ma_start").val();
|
|
|
|
|
|
|
|
var parallel = false
|
|
|
|
var index = 0
|
|
|
|
var leds = []
|
2017-01-17 21:53:35 +01:00
|
|
|
var hblock = 1.0 / ledshoriz
|
|
|
|
var vblock = 1.0 / ledsvert
|
2016-11-18 18:39:27 +01:00
|
|
|
|
|
|
|
if (cabling == "parallel"){
|
|
|
|
parallel = true
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds led to the hyperion config led array
|
|
|
|
* @param {Number} index Index of the led
|
|
|
|
* @param {Number} x Horizontal position in matrix
|
|
|
|
* @param {Number} y Vertical position in matrix
|
|
|
|
*/
|
|
|
|
function addLed (index, x, y) {
|
|
|
|
var hscanMin = x * hblock
|
|
|
|
var hscanMax = (x + 1) * hblock
|
|
|
|
var vscanMin = y * vblock
|
|
|
|
var vscanMax = (y + 1) * vblock
|
|
|
|
|
2016-11-30 17:32:12 +01:00
|
|
|
hscanMin = round(hscanMin);
|
|
|
|
hscanMax = round(hscanMax);
|
|
|
|
vscanMin = round(vscanMin);
|
|
|
|
vscanMax = round(vscanMax);
|
|
|
|
|
2016-11-18 18:39:27 +01:00
|
|
|
leds.push({
|
|
|
|
index: index,
|
|
|
|
hscan: {
|
|
|
|
minimum: hscanMin,
|
|
|
|
maximum: hscanMax
|
|
|
|
},
|
|
|
|
vscan: {
|
2016-11-30 17:32:12 +01:00
|
|
|
minimum: vscanMin,
|
|
|
|
maximum: vscanMax
|
2016-11-18 18:39:27 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
var startYX = start.split('-')
|
2017-01-17 21:53:35 +01:00
|
|
|
var startX = startYX[1] === 'right' ? ledshoriz - 1 : 0
|
|
|
|
var startY = startYX[0] === 'bottom' ? ledsvert - 1 : 0
|
|
|
|
var endX = startX === 0 ? ledshoriz - 1 : 0
|
|
|
|
var endY = startY === 0 ? ledsvert - 1 : 0
|
2016-11-18 18:39:27 +01:00
|
|
|
var forward = startX < endX
|
|
|
|
|
|
|
|
var downward = startY < endY
|
|
|
|
|
|
|
|
var x, y
|
|
|
|
|
|
|
|
for (y = startY; downward && y <= endY || !downward && y >= endY; y += downward ? 1 : -1) {
|
|
|
|
for (x = startX; forward && x <= endX || !forward && x >= endX; x += forward ? 1 : -1) {
|
|
|
|
addLed(index, x, y)
|
|
|
|
index++
|
|
|
|
}
|
|
|
|
if (!parallel) {
|
|
|
|
forward = !forward
|
|
|
|
var tmp = startX
|
|
|
|
startX = endX
|
|
|
|
endX = tmp
|
|
|
|
}
|
|
|
|
}
|
2016-11-21 22:16:57 +01:00
|
|
|
finalLedArray =[];
|
2016-11-18 18:39:27 +01:00
|
|
|
finalLedArray = leds
|
|
|
|
createLedPreview(leds, 'matrix');
|
|
|
|
}
|
2016-09-06 10:14:54 +02:00
|
|
|
|
|
|
|
$(document).ready(function() {
|
2017-01-17 21:53:35 +01:00
|
|
|
// translate
|
2016-12-04 19:32:23 +01:00
|
|
|
performTranslation();
|
2017-01-17 21:53:35 +01:00
|
|
|
|
2017-02-08 14:36:28 +01:00
|
|
|
//add intros
|
|
|
|
if(showOptHelp)
|
|
|
|
{
|
|
|
|
createHintH("intro", $.i18n('conf_leds_device_intro'), "leddevice_intro");
|
|
|
|
createHintH("intro", $.i18n('conf_leds_layout_intro'), "layout_intro");
|
|
|
|
$('#led_vis_help').html('<div><div class="led_ex" style="background-color:black;margin-right:5px;margin-top:3px"></div><div style="display:inline-block;vertical-align:top">'+$.i18n('conf_leds_layout_preview_l1')+'</div></div><div class="led_ex" style="background-color:grey;margin-top:3px;margin-right:2px"></div><div class="led_ex" style="background-color: rgb(169, 169, 169);margin-right:5px;margin-top:3px;"></div><div style="display:inline-block;vertical-align:top">'+$.i18n('conf_leds_layout_preview_l2')+'</div>');
|
|
|
|
}
|
|
|
|
|
2017-02-15 15:53:35 +01:00
|
|
|
var slConfig = serverConfig.ledConfig;
|
2017-02-08 14:36:28 +01:00
|
|
|
|
2017-02-15 15:53:35 +01:00
|
|
|
//restore ledConfig
|
|
|
|
for(key in slConfig)
|
|
|
|
{
|
|
|
|
if(typeof(slConfig[key]) === "boolean")
|
|
|
|
$('#ip_cl_'+key).prop('checked', slConfig[key]);
|
|
|
|
else
|
|
|
|
$('#ip_cl_'+key).val(slConfig[key]);
|
|
|
|
}
|
|
|
|
|
|
|
|
function saveValues()
|
|
|
|
{
|
|
|
|
var ledConfig = {};
|
|
|
|
for(key in slConfig)
|
|
|
|
{
|
|
|
|
if(typeof(slConfig[key]) === "boolean")
|
|
|
|
ledConfig[key] = $('#ip_cl_'+key).is(':checked');
|
|
|
|
else if(Number.isInteger(slConfig[key]))
|
|
|
|
ledConfig[key] = parseInt($('#ip_cl_'+key).val());
|
|
|
|
else
|
|
|
|
ledConfig[key] = $('#ip_cl_'+key).val();
|
|
|
|
}
|
|
|
|
setTimeout(requestWriteConfig, 100, {ledConfig});
|
|
|
|
}
|
2017-01-17 21:53:35 +01:00
|
|
|
|
|
|
|
// check access level and adjust ui
|
|
|
|
if(storedAccess == "default")
|
|
|
|
{
|
|
|
|
$('#btn_ma_generate').toggle(false);
|
|
|
|
$('#btn_cl_generate').toggle(false);
|
|
|
|
$('#texfield_panel').toggle(false);
|
|
|
|
$('#previewcreator').toggle(false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$('#btn_ma_save').toggle(false);
|
|
|
|
$('#btn_cl_save').toggle(false);
|
|
|
|
}
|
|
|
|
|
2017-04-07 21:33:40 +02:00
|
|
|
//Wiki link
|
|
|
|
$('#leds_wl').append('<p style="font-weight:bold">'+$.i18n('general_wiki_moreto',$.i18n('conf_leds_nav_label_ledlayout'))+buildWL("user/moretopics/ledarea","Wiki")+'</p>');
|
|
|
|
|
2017-01-17 21:53:35 +01:00
|
|
|
// bind change event to all inputs
|
2016-11-18 18:39:27 +01:00
|
|
|
$('.ledCLconstr').bind("change", function() {
|
2017-02-28 17:53:41 +01:00
|
|
|
valValue(this.id,this.value,this.min,this.max);
|
2016-11-18 18:39:27 +01:00
|
|
|
createClassicLeds();
|
|
|
|
});
|
2017-01-17 21:53:35 +01:00
|
|
|
|
2016-11-18 18:39:27 +01:00
|
|
|
$('.ledMAconstr').bind("change", function() {
|
2017-02-28 17:53:41 +01:00
|
|
|
valValue(this.id,this.value,this.min,this.max);
|
2016-11-18 18:39:27 +01:00
|
|
|
createMatrixLeds();
|
|
|
|
});
|
2017-02-28 17:53:41 +01:00
|
|
|
|
|
|
|
// v4 of json schema with diff required assignment - remove when hyperion schema moved to v4
|
|
|
|
var ledschema = {"items":{"additionalProperties":false,"required":["hscan","vscan","index"],"properties":{"clone":{"type":"integer"},"colorOrder":{"enum":["rgb","bgr","rbg","brg","gbr","grb"],"type":"string"},"hscan":{"additionalProperties":false,"properties":{"maximum":{"maximum":1,"minimum":0,"type":"number"},"minimum":{"maximum":1,"minimum":0,"type":"number"}},"type":"object"},"index":{"type":"integer"},"vscan":{"additionalProperties":false,"properties":{"maximum":{"maximum":1,"minimum":0,"type":"number"},"minimum":{"maximum":1,"minimum":0,"type":"number"}},"type":"object"}},"type":"object"},"type":"array"}
|
|
|
|
//create jsonace editor
|
|
|
|
var aceEdt = new JSONACEEditor(document.getElementById("aceedit"),{
|
|
|
|
mode: 'code',
|
|
|
|
schema: ledschema,
|
|
|
|
onChange: function(){
|
|
|
|
var success = true;
|
|
|
|
try{
|
|
|
|
aceEdt.get();
|
|
|
|
}
|
|
|
|
catch(err)
|
|
|
|
{
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(success)
|
|
|
|
{
|
|
|
|
$('#leds_custom_updsim').attr("disabled", false);
|
|
|
|
$('#leds_custom_save').attr("disabled", false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$('#leds_custom_updsim').attr("disabled", true);
|
|
|
|
$('#leds_custom_save').attr("disabled", true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, serverConfig.leds);
|
2016-11-18 18:39:27 +01:00
|
|
|
|
2017-02-28 17:53:41 +01:00
|
|
|
//TODO: HACK! No callback for schema validation - Add it!
|
|
|
|
setInterval(function(){
|
|
|
|
if($('#aceedit table').hasClass('jsoneditor-text-errors'))
|
|
|
|
{
|
|
|
|
$('#leds_custom_updsim').attr("disabled", true);
|
|
|
|
$('#leds_custom_save').attr("disabled", true);
|
2016-11-18 18:39:27 +01:00
|
|
|
}
|
2017-02-28 17:53:41 +01:00
|
|
|
},1000)
|
2016-11-18 18:39:27 +01:00
|
|
|
|
2017-02-28 17:53:41 +01:00
|
|
|
$('.jsoneditor-menu').toggle();
|
|
|
|
|
|
|
|
// leds to finalLedArray
|
|
|
|
finalLedArray = serverConfig.leds;
|
|
|
|
|
|
|
|
// cl/ma leds push to textfield
|
|
|
|
$('#btn_cl_generate, #btn_ma_generate').off().on("click", function(e) {
|
|
|
|
if(e.currentTarget.id == "btn_cl_generate")
|
|
|
|
$('#collapse1').collapse('hide');
|
|
|
|
else
|
2017-01-17 21:53:35 +01:00
|
|
|
$('#collapse2').collapse('hide');
|
2017-02-28 17:53:41 +01:00
|
|
|
|
|
|
|
aceEdt.set(finalLedArray);
|
|
|
|
$('#collapse4').collapse('show');
|
|
|
|
|
2016-11-18 18:39:27 +01:00
|
|
|
});
|
2017-01-17 21:53:35 +01:00
|
|
|
|
2017-02-08 14:36:28 +01:00
|
|
|
// create and update editor
|
|
|
|
$("#leddevices").off().on("change", function() {
|
|
|
|
generalOptions = serverSchema.properties.device;
|
|
|
|
specificOptions = serverSchema.properties.alldevices[$(this).val()];
|
|
|
|
conf_editor = createJsonEditor('editor_container', {
|
|
|
|
generalOptions : generalOptions,
|
|
|
|
specificOptions : specificOptions,
|
|
|
|
});
|
2016-11-30 17:32:12 +01:00
|
|
|
|
2017-02-08 14:36:28 +01:00
|
|
|
values_general = {};
|
|
|
|
values_specific = {};
|
2017-03-18 00:05:04 +01:00
|
|
|
isCurrentDevice = (serverInfo.ledDevices.active == $(this).val());
|
2017-02-08 14:36:28 +01:00
|
|
|
|
|
|
|
for(var key in serverConfig.device){
|
|
|
|
if (key != "type" && key in generalOptions.properties)
|
|
|
|
values_general[key] = serverConfig.device[key];
|
|
|
|
};
|
|
|
|
conf_editor.getEditor("root.generalOptions").setValue( values_general );
|
|
|
|
|
|
|
|
if (isCurrentDevice)
|
2016-09-07 20:10:37 +02:00
|
|
|
{
|
2017-02-08 14:36:28 +01:00
|
|
|
specificOptions_val = conf_editor.getEditor("root.specificOptions").getValue()
|
|
|
|
for(var key in specificOptions_val){
|
|
|
|
values_specific[key] = (key in serverConfig.device) ? serverConfig.device[key] : specificOptions_val[key];
|
|
|
|
};
|
|
|
|
|
|
|
|
conf_editor.getEditor("root.specificOptions").setValue( values_specific );
|
|
|
|
};
|
2016-11-30 17:32:12 +01:00
|
|
|
|
2017-02-08 14:36:28 +01:00
|
|
|
// change save button state based on validation result
|
|
|
|
conf_editor.validate().length ? $('#btn_submit_controller').attr('disabled', true) : $('#btn_submit_controller').attr('disabled', false);
|
2017-04-07 21:33:40 +02:00
|
|
|
|
|
|
|
// led controller sepecific wizards
|
|
|
|
if($(this).val() == "philipshue")
|
|
|
|
{
|
|
|
|
createHint("wizard", $.i18n('wiz_hue_title'), "btn_wiz_holder","btn_led_device_wiz");
|
|
|
|
$('#btn_led_device_wiz').off().on('click',startWizardPhilipsHue);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$('#btn_wiz_holder').html("")
|
|
|
|
$('#btn_led_device_wiz').off();
|
|
|
|
}
|
2016-09-07 20:10:37 +02:00
|
|
|
});
|
2017-02-08 14:36:28 +01:00
|
|
|
|
|
|
|
// create led device selection
|
2017-03-18 00:05:04 +01:00
|
|
|
ledDevices = serverInfo.ledDevices.available
|
2017-02-14 09:33:28 +01:00
|
|
|
devRPiSPI = ['apa102', 'ws2801', 'lpd6803', 'lpd8806', 'p9813', 'sk6812spi', 'sk6822spi', 'ws2812spi'];
|
2017-02-08 14:36:28 +01:00
|
|
|
devRPiPWM = ['ws281x'];
|
|
|
|
devRPiGPIO = ['piblaster'];
|
|
|
|
devNET = ['atmoorb', 'fadecandy', 'philipshue', 'tinkerforge', 'tpm2net', 'udpe131', 'udph801', 'udpraw'];
|
|
|
|
devUSB = ['adalight', 'dmx', 'atmo', 'hyperionusbasp', 'lightpack', 'multilightpack', 'paintpack', 'rawhid', 'sedu', 'tpm2'];
|
|
|
|
|
|
|
|
var optArr = [[]];
|
|
|
|
optArr[1]=[];
|
|
|
|
optArr[2]=[];
|
|
|
|
optArr[3]=[];
|
|
|
|
optArr[4]=[];
|
|
|
|
optArr[5]=[];
|
|
|
|
|
|
|
|
for (idx=0; idx<ledDevices.length; idx++)
|
|
|
|
{
|
|
|
|
if($.inArray(ledDevices[idx], devRPiSPI) != -1)
|
|
|
|
optArr[0].push(ledDevices[idx]);
|
|
|
|
else if($.inArray(ledDevices[idx], devRPiPWM) != -1)
|
|
|
|
optArr[1].push(ledDevices[idx]);
|
|
|
|
else if($.inArray(ledDevices[idx], devRPiGPIO) != -1)
|
|
|
|
optArr[2].push(ledDevices[idx]);
|
|
|
|
else if($.inArray(ledDevices[idx], devNET) != -1)
|
|
|
|
optArr[3].push(ledDevices[idx]);
|
|
|
|
else if($.inArray(ledDevices[idx], devUSB) != -1)
|
|
|
|
optArr[4].push(ledDevices[idx]);
|
|
|
|
else
|
|
|
|
optArr[5].push(ledDevices[idx]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$("#leddevices").append(createSel(optArr[0], $.i18n('conf_leds_optgroup_RPiSPI')));
|
|
|
|
$("#leddevices").append(createSel(optArr[1], $.i18n('conf_leds_optgroup_RPiPWM')));
|
|
|
|
$("#leddevices").append(createSel(optArr[2], $.i18n('conf_leds_optgroup_RPiGPIO')));
|
|
|
|
$("#leddevices").append(createSel(optArr[3], $.i18n('conf_leds_optgroup_network')));
|
|
|
|
$("#leddevices").append(createSel(optArr[4], $.i18n('conf_leds_optgroup_usb')));
|
|
|
|
$("#leddevices").append(createSel(optArr[5], $.i18n('conf_leds_optgroup_debug')));
|
2017-03-18 00:05:04 +01:00
|
|
|
$("#leddevices").val(serverInfo.ledDevices.active);
|
2017-02-08 14:36:28 +01:00
|
|
|
$("#leddevices").trigger("change");
|
2016-09-07 20:10:37 +02:00
|
|
|
|
2017-01-17 21:53:35 +01:00
|
|
|
// validate textfield and update preview
|
2016-11-18 18:39:27 +01:00
|
|
|
$("#leds_custom_updsim").off().on("click", function() {
|
2017-02-28 17:53:41 +01:00
|
|
|
createLedPreview(aceEdt.get(), 'text');
|
2016-09-06 10:14:54 +02:00
|
|
|
});
|
2016-11-18 18:39:27 +01:00
|
|
|
|
2017-01-17 21:53:35 +01:00
|
|
|
// save led config and saveValues - passing textfield
|
|
|
|
$("#btn_ma_save, #btn_cl_save").off().on("click", function() {
|
2017-01-19 17:51:11 +01:00
|
|
|
requestWriteConfig({"leds" :finalLedArray});
|
2017-01-17 21:53:35 +01:00
|
|
|
saveValues();
|
|
|
|
});
|
|
|
|
|
2017-02-28 17:53:41 +01:00
|
|
|
// save led config from textfield
|
2016-09-09 18:59:58 +02:00
|
|
|
$("#leds_custom_save").off().on("click", function() {
|
2017-02-28 17:53:41 +01:00
|
|
|
requestWriteConfig(JSON.parse('{"leds" :'+aceEdt.getText()+'}'));
|
|
|
|
saveValues();
|
2016-09-06 10:14:54 +02:00
|
|
|
});
|
|
|
|
|
2017-01-17 21:53:35 +01:00
|
|
|
// toggle led numbers
|
2016-11-30 17:32:12 +01:00
|
|
|
$('#leds_prev_toggle_num').off().on("click", function() {
|
|
|
|
$('.led_prev_num').toggle();
|
|
|
|
toggleClass('#leds_prev_toggle_num', "btn-danger", "btn-success");
|
|
|
|
});
|
2017-01-17 21:53:35 +01:00
|
|
|
|
2017-02-08 14:36:28 +01:00
|
|
|
// open checklist
|
|
|
|
$('#leds_prev_checklist').off().on("click", function() {
|
2017-02-26 20:55:41 +01:00
|
|
|
var liList = [$.i18n('conf_leds_layout_checkp1'),$.i18n('conf_leds_layout_checkp3'),$.i18n('conf_leds_layout_checkp2'),$.i18n('conf_leds_layout_checkp4')];
|
2017-02-08 14:36:28 +01:00
|
|
|
var ul = document.createElement("ul");
|
|
|
|
ul.className = "checklist"
|
|
|
|
|
|
|
|
for(var i = 0; i<liList.length; i++)
|
|
|
|
{
|
|
|
|
var li = document.createElement("li");
|
|
|
|
li.innerHTML = liList[i];
|
|
|
|
ul.appendChild(li);
|
|
|
|
}
|
|
|
|
showInfoDialog('checklist', "", ul);
|
|
|
|
});
|
|
|
|
|
2017-01-17 21:53:35 +01:00
|
|
|
// nav
|
2016-09-09 18:59:58 +02:00
|
|
|
$('#leds_cfg_nav a[data-toggle="tab"]').off().on('shown.bs.tab', function (e) {
|
2016-09-06 10:14:54 +02:00
|
|
|
var target = $(e.target).attr("href") // activated tab
|
2016-09-07 20:10:37 +02:00
|
|
|
if (target == "#menu_gencfg" && !ledsCustomCfgInitialized)
|
2016-09-06 10:14:54 +02:00
|
|
|
{
|
2016-12-21 18:24:03 +01:00
|
|
|
$('#leds_custom_updsim').trigger('click');
|
2016-09-06 10:14:54 +02:00
|
|
|
ledsCustomCfgInitialized = true;
|
|
|
|
}
|
|
|
|
});
|
2017-01-17 21:53:35 +01:00
|
|
|
|
|
|
|
// save led device config
|
2016-09-13 11:51:16 +02:00
|
|
|
$("#btn_submit_controller").off().on("click", function(event) {
|
|
|
|
|
|
|
|
ledDevice = $("#leddevices").val();
|
|
|
|
result = {device:{}};
|
|
|
|
|
2016-10-10 23:15:50 +02:00
|
|
|
general = conf_editor.getEditor("root.generalOptions").getValue();
|
|
|
|
specific = conf_editor.getEditor("root.specificOptions").getValue();
|
2016-09-13 11:51:16 +02:00
|
|
|
for(var key in general){
|
|
|
|
result.device[key] = general[key];
|
|
|
|
}
|
|
|
|
|
|
|
|
for(var key in specific){
|
|
|
|
result.device[key] = specific[key];
|
|
|
|
}
|
|
|
|
result.device.type=ledDevice;
|
|
|
|
requestWriteConfig(result)
|
|
|
|
});
|
|
|
|
|
2017-02-08 14:36:28 +01:00
|
|
|
removeOverlay();
|
2016-09-06 10:14:54 +02:00
|
|
|
});
|
2016-09-13 11:51:16 +02:00
|
|
|
|
|
|
|
|
2017-01-17 21:53:35 +01:00
|
|
|
|