2016-09-06 10:14:54 +02:00
|
|
|
|
|
|
|
var ledsCustomCfgInitialized = false;
|
2016-11-18 18:39:27 +01:00
|
|
|
var finalLedArray = [];
|
2016-09-06 10:14:54 +02:00
|
|
|
|
2016-09-15 20:42:58 +02:00
|
|
|
function get_hue_lights(){
|
|
|
|
$.ajax({
|
|
|
|
type: "GET",
|
|
|
|
url: 'http://'+$("#ip").val()+'/api/'+$("#user").val()+'/lights',
|
|
|
|
processData: false,
|
|
|
|
contentType: 'application/json',
|
|
|
|
success: function(r) {
|
|
|
|
for(var lightid in r){
|
|
|
|
//console.log(r[lightid].name);
|
|
|
|
$('#hue_lights').append('ID: '+lightid+' Name: '+r[lightid].name+'<br />');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-11-18 18:39:27 +01:00
|
|
|
function validateText(){
|
|
|
|
e = isJsonString($("#ledconfig").val());
|
|
|
|
|
|
|
|
if (e.length != 0){
|
2016-12-04 19:32:23 +01:00
|
|
|
showInfoDialog("error", $.i18n('InfoDialog_leds_validfail_title'), e);
|
2016-11-18 18:39:27 +01:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
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"){
|
2016-12-04 19:32:23 +01:00
|
|
|
$('#previewcreator').html('<h5>'+$.i18n('conf_leds_layout_preview_originCL')+'</h5>');
|
2016-11-18 18:39:27 +01:00
|
|
|
$('#leds_preview').css("padding-top", "56.25%");
|
|
|
|
}
|
|
|
|
else if(origin == "text"){
|
2016-12-04 19:32:23 +01:00
|
|
|
$('#previewcreator').html('<h5>'+$.i18n('conf_leds_layout_preview_originTEXT')+'</h5>');
|
2016-11-18 18:39:27 +01:00
|
|
|
$('#leds_preview').css("padding-top", "56.25%");
|
|
|
|
}
|
|
|
|
else if(origin == "matrix"){
|
2016-12-04 19:32:23 +01:00
|
|
|
$('#previewcreator').html('<h5>'+$.i18n('conf_leds_layout_preview_originMA')+'</h5>');
|
2016-11-18 18:39:27 +01:00
|
|
|
$('#leds_preview').css("padding-top", "100%");
|
|
|
|
}
|
|
|
|
|
2016-12-04 19:32:23 +01:00
|
|
|
$('#previewledcount').html('<h5>'+$.i18n('conf_leds_layout_preview_totalleds', leds.length)+'</h5>');
|
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
|
|
|
|
var ledsTop = parseInt($("#ip_cl_ledstop").val());
|
|
|
|
var ledsBottom = parseInt($("#ip_cl_ledsbottom").val());
|
|
|
|
var ledsLeft = parseInt($("#ip_cl_ledsleft").val());
|
|
|
|
var ledsRight = parseInt($("#ip_cl_ledsright").val());
|
|
|
|
var ledsGlength = parseInt($("#ip_cl_ledsglength").val());
|
|
|
|
var ledsGPos = parseInt($("#ip_cl_ledsgpos").val());
|
|
|
|
var position = parseInt($("#ip_cl_position").val());
|
|
|
|
var reverse = $("#ip_cl_reverse").is(":checked");
|
|
|
|
|
|
|
|
//advanced values
|
|
|
|
var rawledsVDepth = parseInt($("#ip_cl_ledsvdepth").val());
|
|
|
|
var rawledsHDepth = parseInt($("#ip_cl_ledshdepth").val());
|
2016-11-21 22:16:57 +01:00
|
|
|
var rawedgeGap = parseInt($("#ip_cl_ledsedgegap").val());
|
2016-11-30 17:32:12 +01:00
|
|
|
var rawcornerGap = parseInt($("#ip_cl_ledscornergap").val());
|
2016-11-18 18:39:27 +01:00
|
|
|
|
|
|
|
//helper
|
2016-11-30 17:32:12 +01:00
|
|
|
var ledsVDepth = rawledsVDepth /100;
|
|
|
|
var ledsHDepth = rawledsHDepth /100;
|
|
|
|
var edgeVGap = rawedgeGap /100/2;
|
|
|
|
var edgeHGap = edgeVGap/(16/9);
|
|
|
|
var cornerVGap = rawcornerGap /100/2;
|
|
|
|
var cornerHGap = cornerVGap/(16/9);
|
|
|
|
var Vmin = 0.0 + edgeVGap;
|
|
|
|
var Vmax = 1.0 - edgeVGap;
|
|
|
|
var Hmin = 0.0 + edgeHGap;
|
|
|
|
var Hmax = 1.0 - edgeHGap;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
function validateGap(){
|
|
|
|
if (ledsGPos+ledsGlength > ledArray.length){
|
2016-12-04 19:32:23 +01:00
|
|
|
showInfoDialog('error', $.i18n('infoDialog_leds_gap_title'), $.i18n('infoDialog_leds_gap_text'));
|
2016-11-18 18:39:27 +01:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
function rotateArray(array, times){
|
|
|
|
if (times > "0"){
|
|
|
|
while( times-- ){
|
|
|
|
array.push(array.shift())
|
|
|
|
}
|
|
|
|
return array;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while( times++ ){
|
|
|
|
array.unshift(array.pop())
|
|
|
|
}
|
|
|
|
return array;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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(){
|
2016-11-30 17:32:12 +01:00
|
|
|
step=(Hmax-Hmin)/ledsTop;
|
|
|
|
hmin=Hmin
|
|
|
|
if(cornerVGap != '0'){
|
|
|
|
step=(Hmax-Hmin-(cornerHGap*2))/ledsTop;
|
|
|
|
hmin=Hmin+(cornerHGap);
|
|
|
|
}
|
|
|
|
vmin=Vmin
|
2016-11-18 18:39:27 +01:00
|
|
|
vmax=vmin+ledsHDepth;
|
2016-11-30 17:32:12 +01:00
|
|
|
hmax=hmin+step
|
2016-11-18 18:39:27 +01:00
|
|
|
for (var i = 0; i<ledsTop; i++){
|
|
|
|
createLedArray(hmin, hmax, vmin, vmax);
|
2016-11-21 22:16:57 +01:00
|
|
|
hmin += step
|
|
|
|
hmax += step
|
2016-11-18 18:39:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function createLeftLeds(){
|
2016-11-30 17:32:12 +01:00
|
|
|
step=(Vmax-Vmin)/ledsLeft;
|
|
|
|
vmax=Vmax
|
|
|
|
if(cornerVGap != '0'){
|
|
|
|
step=(Vmax-Vmin-(cornerVGap*2))/ledsLeft;
|
|
|
|
vmax=Vmax-(cornerVGap);
|
|
|
|
}
|
|
|
|
hmin=Hmin;
|
|
|
|
hmax=hmin+ledsVDepth;
|
|
|
|
vmin=vmax-step
|
2016-11-18 18:39:27 +01:00
|
|
|
for (var i = ledsLeft; i>0; i--){
|
|
|
|
createLedArray(hmin, hmax, vmin, vmax);
|
2016-11-21 22:16:57 +01:00
|
|
|
vmin -= step
|
|
|
|
vmax -= step
|
2016-11-18 18:39:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function createRightLeds(){
|
2016-11-30 17:32:12 +01:00
|
|
|
step=(Vmax-Vmin)/ledsRight;
|
|
|
|
vmin=Vmin
|
|
|
|
if(cornerVGap != '0'){
|
|
|
|
step=(Vmax-Vmin-(cornerVGap*2))/ledsRight;
|
|
|
|
vmin=Vmin+(cornerVGap);
|
|
|
|
}
|
|
|
|
hmax=Hmax;
|
2016-11-18 18:39:27 +01:00
|
|
|
hmin=hmax-ledsVDepth;
|
2016-11-30 17:32:12 +01:00
|
|
|
vmax=vmin+step
|
2016-11-18 18:39:27 +01:00
|
|
|
for (var i = 0; i<ledsRight; i++){
|
2016-11-21 22:16:57 +01:00
|
|
|
createLedArray(hmin, hmax, vmin, vmax);
|
|
|
|
vmin += step
|
|
|
|
vmax += step
|
2016-11-18 18:39:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function createBottomLeds(){
|
2016-11-30 17:32:12 +01:00
|
|
|
step=(Hmax-Hmin)/ledsBottom;
|
|
|
|
hmax=Hmax
|
|
|
|
if(cornerVGap != '0'){
|
|
|
|
step=(Hmax-Hmin-(cornerHGap*2))/ledsBottom;
|
|
|
|
hmax=Hmax-(cornerHGap);
|
|
|
|
}
|
|
|
|
vmax=Vmax;
|
2016-11-18 18:39:27 +01:00
|
|
|
vmin=vmax-ledsHDepth;
|
2016-11-30 17:32:12 +01:00
|
|
|
hmin=hmax-step
|
2016-11-18 18:39:27 +01:00
|
|
|
for (var i = ledsBottom; i>0; i--){
|
|
|
|
createLedArray(hmin, hmax, vmin, vmax);
|
2016-11-30 17:32:12 +01:00
|
|
|
hmin -= step;
|
|
|
|
hmax -= step;
|
2016-11-18 18:39:27 +01:00
|
|
|
}
|
|
|
|
}
|
2016-12-08 23:39:41 +01:00
|
|
|
|
|
|
|
createLeftLeds(createBottomLeds(createRightLeds(createTopLeds())));
|
|
|
|
|
|
|
|
if(ledsGlength != "0" && validateGap()){
|
|
|
|
ledArray.splice(ledsGPos, ledsGlength);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (position != "0"){
|
|
|
|
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
|
|
|
|
var width = parseInt($("#ip_ma_ledshoriz").val());
|
|
|
|
var height = parseInt($("#ip_ma_ledsvert").val());
|
|
|
|
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 = []
|
|
|
|
var hblock = 1.0 / width
|
|
|
|
var vblock = 1.0 / height
|
|
|
|
|
|
|
|
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('-')
|
|
|
|
var startX = startYX[1] === 'right' ? width - 1 : 0
|
|
|
|
var startY = startYX[0] === 'bottom' ? height - 1 : 0
|
|
|
|
var endX = startX === 0 ? width - 1 : 0
|
|
|
|
var endY = startY === 0 ? height - 1 : 0
|
|
|
|
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() {
|
2016-12-04 19:32:23 +01:00
|
|
|
performTranslation();
|
2016-11-18 18:39:27 +01:00
|
|
|
//-------------------------------------------------------------------
|
|
|
|
$('.ledCLconstr').bind("change", function() {
|
|
|
|
createClassicLeds();
|
|
|
|
});
|
|
|
|
|
2016-12-18 19:00:14 +01:00
|
|
|
// ------------------------------------------------------------------
|
2016-11-18 18:39:27 +01:00
|
|
|
$('.ledMAconstr').bind("change", function() {
|
|
|
|
createMatrixLeds();
|
|
|
|
});
|
|
|
|
|
2016-12-18 19:00:14 +01:00
|
|
|
// ------------------------------------------------------------------
|
2016-11-18 18:39:27 +01:00
|
|
|
$('#btn_cl_generate').off().on("click", function() {
|
|
|
|
if (finalLedArray != ""){
|
|
|
|
$("#ledconfig").text(JSON.stringify(finalLedArray, null, "\t"));
|
|
|
|
$('#collapse1').collapse('hide')
|
|
|
|
$('#collapse4').collapse('show');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-12-18 19:00:14 +01:00
|
|
|
// ------------------------------------------------------------------
|
2016-11-18 18:39:27 +01:00
|
|
|
$('#btn_ma_generate').off().on("click", function() {
|
|
|
|
if (finalLedArray != ""){
|
|
|
|
$("#ledconfig").text(JSON.stringify(finalLedArray, null, "\t"));
|
|
|
|
$('#collapse2').collapse('hide')
|
|
|
|
$('#collapse4').collapse('show');
|
|
|
|
}
|
|
|
|
});
|
2016-12-04 19:32:23 +01:00
|
|
|
|
2016-12-18 19:00:14 +01:00
|
|
|
// ------------------------------------------------------------------
|
|
|
|
$(hyperion).on("cmd-ledcolors-imagestream-update",function(event){
|
|
|
|
if ($("#leddevices").length == 0)
|
|
|
|
{
|
|
|
|
requestLedImageStop();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
imageData = (event.response.result.image);
|
|
|
|
$("#image_preview").attr("src", imageData);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-09-06 10:14:54 +02:00
|
|
|
// ------------------------------------------------------------------
|
2016-09-07 20:10:37 +02:00
|
|
|
$(hyperion).on("cmd-ledcolors-ledstream-update",function(event){
|
|
|
|
if ($("#leddevices").length == 0)
|
|
|
|
{
|
|
|
|
requestLedColorsStop();
|
|
|
|
}
|
|
|
|
else
|
2016-09-06 10:14:54 +02:00
|
|
|
{
|
2016-09-08 16:32:42 +02:00
|
|
|
ledColors = (event.response.result.leds);
|
2016-09-07 20:10:37 +02:00
|
|
|
for(var idx=0; idx<ledColors.length; idx++)
|
|
|
|
{
|
|
|
|
led = ledColors[idx]
|
|
|
|
$("#led_"+led.index).css("background","rgb("+led.red+","+led.green+","+led.blue+")");
|
|
|
|
}
|
2016-09-06 10:14:54 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------
|
2016-09-07 20:10:37 +02:00
|
|
|
$(hyperion).on("cmd-ledcolors-ledstream-stop",function(event){
|
|
|
|
led_count = $(".led").length;
|
|
|
|
for(var idx=0; idx<led_count; idx++)
|
2016-09-06 10:14:54 +02:00
|
|
|
{
|
2016-09-07 20:10:37 +02:00
|
|
|
$('#led_'+idx).css("background-color","hsl("+(idx*360/led_count)+",100%,50%)");
|
2016-09-06 10:14:54 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-09-07 20:10:37 +02:00
|
|
|
// ------------------------------------------------------------------
|
|
|
|
$(hyperion).one("cmd-serverinfo",function(event){
|
|
|
|
server = event.response;
|
|
|
|
ledDevices = server.info.ledDevices.available
|
2016-11-30 17:32:12 +01:00
|
|
|
devRPiSPI = ['apa102', 'ws2801', 'lpd6803', 'lpd8806', 'p9813', 'sk6812spi', 'ws2812spi'];
|
|
|
|
devRPiPWM = ['ws281x'];
|
|
|
|
devRPiGPIO = ['piblaster'];
|
2016-12-04 19:32:23 +01:00
|
|
|
devNET = ['atmoorb', 'fadecandy', 'philipshue', 'tinkerforge', 'tpm2net', 'udpe131', 'udph801', 'udpraw'];
|
|
|
|
devUSB = ['adalight', 'dmx', 'atmo', 'hyperionusbasp', 'lightpack', 'multilightpack', 'paintpack', 'rawhid', 'sedu', 'tpm2'];
|
2016-11-30 17:32:12 +01:00
|
|
|
|
|
|
|
var optArr = [[]];
|
|
|
|
optArr[1]=[];
|
|
|
|
optArr[2]=[];
|
|
|
|
optArr[3]=[];
|
|
|
|
optArr[4]=[];
|
|
|
|
optArr[5]=[];
|
|
|
|
|
2016-09-07 20:10:37 +02:00
|
|
|
for (idx=0; idx<ledDevices.length; idx++)
|
|
|
|
{
|
2016-11-30 17:32:12 +01:00
|
|
|
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]);
|
2016-09-07 20:10:37 +02:00
|
|
|
}
|
2016-11-30 17:32:12 +01:00
|
|
|
|
2016-12-04 19:32:23 +01:00
|
|
|
$("#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')));
|
2016-11-30 17:32:12 +01:00
|
|
|
|
2016-09-07 20:10:37 +02:00
|
|
|
$("#leddevices").val(server.info.ledDevices.active);
|
2016-09-10 19:08:08 +02:00
|
|
|
$("#leddevices").trigger("change");
|
2016-09-07 20:10:37 +02:00
|
|
|
});
|
|
|
|
|
2016-09-06 10:14:54 +02:00
|
|
|
// ------------------------------------------------------------------
|
|
|
|
$(hyperion).on("cmd-config-getconfig",function(event){
|
|
|
|
parsedConfJSON = event.response.result;
|
|
|
|
leds = parsedConfJSON.leds;
|
|
|
|
$("#ledconfig").text(JSON.stringify(leds, null, "\t"));
|
|
|
|
canvas_height = $('#leds_canvas').innerHeight();
|
|
|
|
canvas_width = $('#leds_canvas').innerWidth();
|
|
|
|
|
2016-12-18 19:00:14 +01:00
|
|
|
leds_html = '<img src="" id="image_preview" style="position:relative" />"';
|
2016-09-06 10:14:54 +02:00
|
|
|
for(var idx=0; idx<leds.length; idx++)
|
|
|
|
{
|
|
|
|
led = leds[idx];
|
|
|
|
led_id='led_'+led.index;
|
|
|
|
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;";
|
|
|
|
leds_html += '<div id="'+led_id+'" class="led" style="'+bgcolor+pos+'" title="'+led.index+'"><span id="'+led_id+'_num" class="led_num">'+led.index+'</span></div>';
|
|
|
|
}
|
|
|
|
$('#leds_canvas').html(leds_html);
|
2016-11-18 18:39:27 +01:00
|
|
|
$('#led_0').css({"z-index":"10"});
|
2016-12-21 18:24:03 +01:00
|
|
|
|
|
|
|
$('#image_preview').hide();
|
|
|
|
$('#image_preview').attr("width" , $('#leds_canvas').innerWidth()-2);
|
2016-12-18 19:00:14 +01:00
|
|
|
$('#image_preview').attr("height", $('#leds_canvas').innerHeight()-2);
|
2016-09-06 10:14:54 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------
|
2016-09-09 18:59:58 +02:00
|
|
|
$('#leds_toggle_num').off().on("click", function() {
|
2016-09-06 10:14:54 +02:00
|
|
|
$('.led_num').toggle();
|
|
|
|
toggleClass('#leds_toggle_num', "btn-danger", "btn-success");
|
|
|
|
});
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------
|
2016-09-09 18:59:58 +02:00
|
|
|
$('#leds_toggle').off().on("click", function() {
|
2016-09-06 10:14:54 +02:00
|
|
|
$('.led').toggle();
|
|
|
|
toggleClass('#leds_toggle', "btn-success", "btn-danger");
|
|
|
|
});
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------
|
2016-09-09 18:59:58 +02:00
|
|
|
$('#leds_toggle_live').off().on("click", function() {
|
2016-09-06 10:14:54 +02:00
|
|
|
setClassByBool('#leds_toggle_live',ledStreamActive,"btn-success","btn-danger");
|
|
|
|
if ( ledStreamActive )
|
|
|
|
{
|
2016-09-07 20:10:37 +02:00
|
|
|
requestLedColorsStop();
|
2016-09-06 10:14:54 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-09-07 20:10:37 +02:00
|
|
|
requestLedColorsStart();
|
2016-09-06 10:14:54 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-12-18 19:00:14 +01:00
|
|
|
// ------------------------------------------------------------------
|
|
|
|
$('#leds_toggle_live_video').off().on("click", function() {
|
|
|
|
setClassByBool('#leds_toggle_live_video',imageStreamActive,"btn-success","btn-danger");
|
|
|
|
if ( imageStreamActive )
|
|
|
|
{
|
|
|
|
requestLedImageStop();
|
|
|
|
$('#image_preview').hide();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$('#image_preview').show();
|
|
|
|
requestLedImageStart();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-09-06 10:14:54 +02:00
|
|
|
// ------------------------------------------------------------------
|
2016-11-18 18:39:27 +01:00
|
|
|
$("#leds_custom_updsim").off().on("click", function() {
|
|
|
|
if (validateText()){
|
2016-12-08 23:39:41 +01:00
|
|
|
createLedPreview(JSON.parse($("#ledconfig").val()), 'text');
|
2016-11-18 18:39:27 +01:00
|
|
|
}
|
2016-09-06 10:14:54 +02:00
|
|
|
});
|
2016-11-18 18:39:27 +01:00
|
|
|
|
2016-09-06 10:14:54 +02:00
|
|
|
// ------------------------------------------------------------------
|
2016-09-09 18:59:58 +02:00
|
|
|
$("#leds_custom_save").off().on("click", function() {
|
2016-11-21 22:16:57 +01:00
|
|
|
if (validateText())
|
2016-12-14 22:45:00 +01:00
|
|
|
requestWriteConfig(JSON.parse('{"leds" :'+$("#ledconfig").val()+'}'));
|
2016-09-06 10:14:54 +02:00
|
|
|
});
|
|
|
|
|
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");
|
|
|
|
});
|
2016-09-13 11:51:16 +02:00
|
|
|
// -------------------------------------------------------------
|
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;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-09-13 11:51:16 +02:00
|
|
|
// ------------------------------------------------------------------
|
2016-10-10 23:15:50 +02:00
|
|
|
var conf_editor = null;
|
2016-09-09 18:59:58 +02:00
|
|
|
$("#leddevices").off().on("change", function(event) {
|
2016-09-10 19:08:08 +02:00
|
|
|
generalOptions = parsedConfSchemaJSON.properties.device;
|
|
|
|
specificOptions = parsedConfSchemaJSON.properties.alldevices[$(this).val()];
|
|
|
|
//$('#ledDeviceOptions').html(JSON.stringify(generalOptions)+"<br>"+JSON.stringify(specificOptions));
|
2016-10-10 23:15:50 +02:00
|
|
|
conf_editor = createJsonEditor('editor_container', {
|
|
|
|
generalOptions : generalOptions,
|
|
|
|
specificOptions : specificOptions,
|
2016-09-10 19:08:08 +02:00
|
|
|
});
|
2016-10-09 10:23:04 +02:00
|
|
|
|
2016-09-10 19:08:08 +02:00
|
|
|
values_general = {};
|
|
|
|
values_specific = {};
|
2016-09-10 19:23:13 +02:00
|
|
|
isCurrentDevice = (server.info.ledDevices.active == $(this).val());
|
2016-09-10 19:08:08 +02:00
|
|
|
|
|
|
|
for(var key in parsedConfJSON.device){
|
2016-09-14 13:51:28 +02:00
|
|
|
if (key != "type" && key in generalOptions.properties)
|
2016-09-10 19:08:08 +02:00
|
|
|
values_general[key] = parsedConfJSON.device[key];
|
|
|
|
};
|
2016-10-10 23:15:50 +02:00
|
|
|
conf_editor.getEditor("root.generalOptions").setValue( values_general );
|
2016-09-11 22:20:57 +02:00
|
|
|
|
2016-09-10 19:08:08 +02:00
|
|
|
if (isCurrentDevice)
|
|
|
|
{
|
2016-10-10 23:15:50 +02:00
|
|
|
specificOptions_val = conf_editor.getEditor("root.specificOptions").getValue()
|
2016-09-15 20:42:58 +02:00
|
|
|
for(var key in specificOptions_val){
|
2016-09-13 11:51:16 +02:00
|
|
|
values_specific[key] = (key in parsedConfJSON.device) ? parsedConfJSON.device[key] : specificOptions_val[key];
|
2016-09-10 19:08:08 +02:00
|
|
|
};
|
2016-09-13 11:51:16 +02:00
|
|
|
|
2016-10-10 23:15:50 +02:00
|
|
|
conf_editor.getEditor("root.specificOptions").setValue( values_specific );
|
2016-09-10 19:08:08 +02:00
|
|
|
};
|
2016-09-11 22:20:57 +02:00
|
|
|
|
2016-09-10 23:30:05 +02:00
|
|
|
$('#editor_container .well').css("background-color","white");
|
|
|
|
$('#editor_container .well').css("border","none");
|
|
|
|
$('#editor_container .well').css("box-shadow","none");
|
2016-09-11 22:20:57 +02:00
|
|
|
|
2016-09-09 18:59:58 +02:00
|
|
|
if ($(this).val() == "philipshue")
|
|
|
|
{
|
|
|
|
$("#huebridge").show();
|
2016-09-11 22:20:57 +02:00
|
|
|
|
|
|
|
$("#ip").attr('value', values_specific.output);
|
|
|
|
$("#user").attr('value', values_specific.username);
|
|
|
|
|
|
|
|
if($("#ip").val() != '' && $("#user").val() != '') {
|
|
|
|
get_hue_lights();
|
|
|
|
}
|
|
|
|
|
2016-09-09 18:59:58 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$("#huebridge").hide();
|
|
|
|
}
|
|
|
|
});
|
2016-09-11 22:20:57 +02:00
|
|
|
|
2016-09-13 11:51:16 +02:00
|
|
|
// ------------------------------------------------------------------
|
|
|
|
$("#btn_submit_controller").off().on("click", function(event) {
|
2016-10-10 23:15:50 +02:00
|
|
|
if (conf_editor==null)
|
2016-09-13 11:51:16 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
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)
|
|
|
|
});
|
|
|
|
|
2016-09-06 10:14:54 +02:00
|
|
|
requestServerConfig();
|
|
|
|
});
|
2016-09-13 11:51:16 +02:00
|
|
|
|
|
|
|
|