diff --git a/assets/webconfig/js/content_leds.js b/assets/webconfig/js/content_leds.js index d4c0add2..7bd132ad 100644 --- a/assets/webconfig/js/content_leds.js +++ b/assets/webconfig/js/content_leds.js @@ -306,6 +306,59 @@ function createMatrixLeds(){ createLedPreview(leds, 'matrix'); } +function migrateLedConfig(slConfig){ + + var newLedConfig = {classic:{}, matrix:{}}; + + //Default Classic layout + newLedConfig.classic = { + "top" : 8, + "bottom" : 8, + "left" : 5, + "right" : 5, + "glength" : 0, + "gpos" : 0, + "position" : 0, + "reverse" : false, + "hdepth" : 8, + "vdepth" : 5, + "overlap" : 0, + "edgegap" : 0 + } + + //Move Classic layout + newLedConfig.classic.top = slConfig.top; + newLedConfig.classic.bottom = slConfig.bottom; + newLedConfig.classic.left = slConfig.left; + newLedConfig.classic.right = slConfig.right; + newLedConfig.classic.glength = slConfig.glength; + newLedConfig.classic.position = slConfig.position; + newLedConfig.classic.reverse = slConfig.reverse; + newLedConfig.classic.hdepth = slConfig.hdepth; + newLedConfig.classic.vdepth = slConfig.vdepth; + newLedConfig.classic.overlap = slConfig.overlap; + + //Default Matrix layout + newLedConfig["matrix"] = { "ledshoriz": 10, + "ledsvert" : 10, + "cabling" : "snake", + "start" : "top-left" + } + + // Persit new structure + requestWriteConfig({ledConfig:newLedConfig}) + return newLedConfig + +} + +function isEmpty(obj) { + for(var key in obj) { + if(obj.hasOwnProperty(key)) + return false; + } + return true; +} + $(document).ready(function() { // translate performTranslation(); @@ -320,28 +373,55 @@ $(document).ready(function() { var slConfig = window.serverConfig.ledConfig; - //restore ledConfig - for(var key in slConfig) + //Check, if structure is not aligned to expected -> migrate structure + var newConfig = {}; + if ( isEmpty(slConfig.classic) ) { - if(typeof(slConfig[key]) === "boolean") - $('#ip_cl_'+key).prop('checked', slConfig[key]); + slConfig = migrateLedConfig( slConfig ); + } + + //restore ledConfig - Classic + for(var key in slConfig.classic) + { + if(typeof(slConfig.classic[key]) === "boolean") + $('#ip_cl_'+key).prop('checked', slConfig.classic[key]); else - $('#ip_cl_'+key).val(slConfig[key]); + $('#ip_cl_'+key).val(slConfig.classic[key]); + } + + //restore ledConfig - Matrix + for(var key in slConfig.matrix) + { + if(typeof(slConfig.matrix[key]) === "boolean") + $('#ip_ma_'+key).prop('checked', slConfig.matrix[key]); + else + $('#ip_ma_'+key).val(slConfig.matrix[key]); } function saveValues() { - var ledConfig = {}; - for(var key in slConfig) + var ledConfig = {classic:{}, matrix:{}}; + + for(var key in slConfig.classic) { - 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()); + if(typeof(slConfig.classic[key]) === "boolean") + ledConfig.classic[key] = $('#ip_cl_'+key).is(':checked'); + else if(Number.isInteger(slConfig.classic[key])) + ledConfig.classic[key] = parseInt($('#ip_cl_'+key).val()); else - ledConfig[key] = $('#ip_cl_'+key).val(); + ledConfig.classic[key] = $('#ip_cl_'+key).val(); } - setTimeout(requestWriteConfig, 100, {ledConfig}); + + for(var key in slConfig.matrix) + { + if(typeof(slConfig.matrix[key]) === "boolean") + ledConfig.matrix[key] = $('#ip_ma_'+key).is(':checked'); + else if(Number.isInteger(slConfig.matrix[key])) + ledConfig.matrix[key] = parseInt($('#ip_ma_'+key).val()); + else + ledConfig.matrix[key] = $('#ip_ma_'+key).val(); + } + requestWriteConfig({ledConfig}); } // check access level and adjust ui diff --git a/config/hyperion.config.json.default b/config/hyperion.config.json.default index 8536e2a0..551bef08 100644 --- a/config/hyperion.config.json.default +++ b/config/hyperion.config.json.default @@ -187,21 +187,33 @@ "ledConfig" : { - "top" : 8, - "bottom" : 8, - "left" : 5, - "right" : 5, - "glength" : 0, - "gpos" : 0, - "position" : 0, - "reverse" : false, - "hdepth" : 8, - "vdepth" : 5, - "overlap" : 0, - "edgegap" : 0 + "classic": + { + "top" : 8, + "bottom" : 8, + "left" : 5, + "right" : 5, + "glength" : 0, + "gpos" : 0, + "position" : 0, + "reverse" : false, + "hdepth" : 8, + "vdepth" : 5, + "overlap" : 0, + "edgegap" : 0 + + }, + + "matrix": + { + "ledshoriz": 10, + "ledsvert" : 10, + "cabling" : "snake", + "start" : "top-left" + } }, - "leds": + "leds": [ { "h": { diff --git a/libsrc/hyperion/schema/schema-ledConfig.json b/libsrc/hyperion/schema/schema-ledConfig.json index b05f581c..dc89af3e 100644 --- a/libsrc/hyperion/schema/schema-ledConfig.json +++ b/libsrc/hyperion/schema/schema-ledConfig.json @@ -2,79 +2,121 @@ "type" : "object", "properties" : { - "top" : + "classic" : { - "type" : "integer", - "minimum" : 0, - "default" : 8 + "type":"object", + "required" : true, + "properties": + { + "top" : + { + "type" : "integer", + "minimum" : 0, + "default" : 8 + }, + "bottom" : + { + "type" : "integer", + "minimum" : 0, + "default" : 8 + }, + "left" : + { + "type" : "integer", + "minimum" : 0, + "default" : 5 + }, + "right" : + { + "type" : "integer", + "minimum" : 0, + "default" : 5 + }, + "glength" : + { + "type" : "integer", + "minimum" : 0, + "default" : 0 + }, + "gpos" : + { + "type" : "integer", + "minimum" : 0, + "default" : 0 + }, + "position" : + { + "type" : "integer", + "default" : 0 + }, + "reverse" : + { + "type" : "boolean", + "default" : false + }, + "hdepth" : + { + "type" : "integer", + "minimum" : 1, + "maximum" : 100, + "default" : 8 + }, + "vdepth" : + { + "type" : "integer", + "minimum" : 1, + "maximum" : 100, + "default" : 5 + }, + "overlap" : + { + "type" : "integer", + "minimum" : 0, + "default" : 0 + }, + "edgegap" : + { + "type" : "integer", + "minimum" : 0, + "maximum" : 50, + "default" : 0 + } + }, + "additionalProperties" : false }, - "bottom" : + "matrix" : { - "type" : "integer", - "minimum" : 0, - "default" : 8 - }, - "left" : - { - "type" : "integer", - "minimum" : 0, - "default" : 5 - }, - "right" : - { - "type" : "integer", - "minimum" : 0, - "default" : 5 - }, - "glength" : - { - "type" : "integer", - "minimum" : 0, - "default" : 0 - }, - "gpos" : - { - "type" : "integer", - "minimum" : 0, - "default" : 0 - }, - "position" : - { - "type" : "integer", - "default" : 0 - }, - "reverse" : - { - "type" : "boolean", - "default" : false - }, - "hdepth" : - { - "type" : "integer", - "minimum" : 1, - "maximum" : 100, - "default" : 8 - }, - "vdepth" : - { - "type" : "integer", - "minimum" : 1, - "maximum" : 100, - "default" : 5 - }, - "overlap" : - { - "type" : "integer", - "minimum" : 0, - "default" : 0 - }, - "edgegap" : - { - "type" : "integer", - "minimum" : 0, - "maximum" : 50, - "default" : 0 + "type":"object", + "required" : true, + "properties": + { + "ledshoriz" : + { + "type" : "integer", + "minimum" : 0, + "maximum" : 50, + "default" : 0 + }, + "ledsvert" : + { + "type" : "integer", + "minimum" : 0, + "maximum" : 50, + "default" : 0 + }, + "cabling" : + { + "type": "string", + "enum" : ["snake", "parallel"] + }, + "start" : + { + "type": "string", + "enum" : ["top-left", "top-right", "bottom-left", "bottom-right"] + } + }, + "additionalProperties" : false } }, - "additionalProperties" : false + "additionalProperties" : true }