Skip to content
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

Led Matrix Layout - Save/Restore (#669) #697

Merged
merged 2 commits into from
Feb 22, 2020
Merged
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
106 changes: 93 additions & 13 deletions assets/webconfig/js/content_leds.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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.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.classic[key] = $('#ip_cl_'+key).val();
}

for(var key in slConfig.matrix)
{
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.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[key] = $('#ip_cl_'+key).val();
ledConfig.matrix[key] = $('#ip_ma_'+key).val();
}
setTimeout(requestWriteConfig, 100, {ledConfig});
requestWriteConfig({ledConfig});
}

// check access level and adjust ui
Expand Down
38 changes: 25 additions & 13 deletions config/hyperion.config.json.default
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
182 changes: 112 additions & 70 deletions libsrc/hyperion/schema/schema-ledConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}