htd-lync
Version:
This library is meant to be used to interact with an HTD Lync 12
1,487 lines (1,353 loc) • 31 kB
JavaScript
function getID() {
console.log("getID")
command = command = ["02", "00", "00", "08", "00", "0A"];
wsSendBinary(command, true);
//getFirmware();
}
function queryAll() {
console.log("queryAll")
command = command = ["02", "00", "00", "0C", "00", "0E"];
wsSendBinary(command, true);
}
//setInterval(getSourcesPerZone, 5000);
var zn = 1;
var gettingSourcesForZone = false;
function getSourcesPerZone(zone, source) {
gettingSourcesForZone = true;
var zoneOrig = zone;
var sourceOrig = source;
console.log("get sources per zone", zone, source)
zone = zoneLookup(zone);
if (source < 10) {
source = "0" + source;
}
source = source + "";
//source = "02"
switch (sourceOrig) {
case 10:
source = "0A";
break;
case 11:
source = "0B";
break;
case 12:
source = "0C";
break;
case 13:
source = "0D";
break;
case 14:
source = "0E";
break;
case 15:
source = "0F";
break;
case 16:
source = "10";
break;
case 17:
source = "11";
break;
case 18:
source = "12";
break;
}
command = ["02", "00", zone, "0E", source]
console.log("Source Orig: " + sourceOrig + " Sources Total: " + systems[systemIdx].sources.length);
wsSendBinary(command, false);
if (sourceOrig < systems[systemIdx].sources.length - 2) {
setTimeout(function() {
getSourcesPerZone(zoneOrig, sourceOrig + 1);
}, 100);
}
}
function getFirmware() {
console.log("getFirmware")
command = ["02", "00", "00", "0F", "00", "11"];
wsSendBinary(command, true);
}
function getAllZoneStatus() {
console.log("getAllZoneStatus")
command = command = ["02", "00", "00", "05", "00", "07"];
wsSendBinary(command, true);
}
function allOn() {
console.log("All On");
$("#allOn").addClass("active");
command = command = ["02", "00", "00", "04", "55", "5B"];
wsSendBinary(command, true);
setTimeout(function(y) {
$("#allOn").removeClass("active");
}, 1000);
for (i = 1; i < systems[systemIdx].zones.length; i++) {
systems[systemIdx].zones[i].powerOn = true;
}
updateData();
//updateGUI();
}
function allOff() {
$("#allOff").addClass("active");
command = command = ["02", "00", "00", "04", "56", "5C"];
wsSendBinary(command, true);
setTimeout(function(y) {
$("#allOff").removeClass("active");
}, 1000);
for (i = 1; i < systems[systemIdx].zones.length; i++) {
if (systems[systemIdx].zones[i].dndOn == false) {
systems[systemIdx].zones[i].powerOn = false;
systems[systemIdx].zones[i].muteOn = false;
systems[systemIdx].zones[i].dndOn = false;
}
}
$('#systemStatusMute').prop('src', "images/speaker.png");
updateData();
//updateGUI();
}
function toggleZonePower(i, overrideDND) {
var zone = i;
zone = zoneLookup(zone);
if (systems[systemIdx].zones[i].powerOn == true) {
console.log("override DND: " + overrideDND)
if (systems[systemIdx].zones[i].dndOn == false) {
command = ["02", "00", zone, "04", "58"]
wsSendBinary(command, false);
systems[systemIdx].zones[i].powerOn = false;
systems[systemIdx].zones[i].dndOn = false;
} else if (systems[systemIdx].zones[i].dndOn == true && overrideDND == true) {
command = ["02", "00", zone, "04", "58"]
wsSendBinary(command, false);
systems[systemIdx].zones[i].powerOn = false;
systems[systemIdx].zones[i].dndOn = false;
} else {
alert("Zone is in DND")
}
} else {
command = ["02", "00", zone, "04", "57"]
wsSendBinary(command, false);
systems[systemIdx].zones[i].powerOn = true;
}
updateGUI(i);
updateData();
}
function partyMode(i) {
var answer = confirm("This will turn on all zones to " + systems[systemIdx].sources[systems[systemIdx].zones[Gzone].source].appName);
console.log(answer);
if (answer == false) {
return;
}
processPartyMode(i);
}
function processPartyMode(i) {
$('#partyBtn').addClass("active")
if (i >= systems[systemIdx].zones.length) {
$('#partyBtn').removeClass("active")
return;
}
if (systems[systemIdx].zones[i].enabled && systems[systemIdx].zones[i].dndOn == false) {
var zone = i;
zone = zoneLookup(zone);
var partySource = partySourceLookup(systems[systemIdx].zones[Gzone].source);
command = ["02", "00", zone, "04", partySource]
console.log("Party Command:" + command);
wsSendBinary(command, false);
}
setTimeout(function(y) {
processPartyMode(i + 1)
}, 50);
}
function zonePowerOn(zone) {
//var zone = Gzone;
zone = zoneLookup(zone);
command = ["02", "00", zone, "04", "57"]
wsSendBinary(command, false);
}
function zonePowerOff(zone) {
//var zone = Gzone;
systems[systemIdx].zones[zone].muteOn = false;
systems[systemIdx].zones[zone].dndOn = false;
updateData();
updateGUI(zone);
zone = zoneLookup(zone);
command = ["02", "00", zone, "04", "58"]
wsSendBinary(command, false);
//turn mute off
}
function zoneDNDOn() {
var zone = Gzone;
zone = zoneLookup(zone);
command = ["02", "00", zone, "04", "59"]
wsSendBinary(command, false);
updateCommand(Gzone)
}
function setZoneDNDOn(zone) {
console.log("setZoneDNDOn")
var zoneOrig = zone;
zone = zoneLookup(zone);
command = ["02", "00", zone, "04", "59"]
wsSendBinary(command, false);
updateCommand(zoneOrig);
}
function zoneDNDOff() {
var zone = Gzone;
zone = zoneLookup(zone);
command = ["02", "00", zone, "04", "5A"]
wsSendBinary(command, false);
updateCommand(Gzone);
}
function setZoneDNDOff(zone) {
console.log("setZoneDNDOff")
var zoneOrig = zone;
zone = zoneLookup(zone);
command = ["02", "00", zone, "04", "5A"]
wsSendBinary(command, false);
updateCommand(zoneOrig);
}
function muteAllOn() {
console.log("Mute all zones")
checkNextForMuteAllOn(1);
}
function checkNextForMuteAllOn(i) {
if (i < systems[systemIdx].zones.length) {
if (systems[systemIdx].zones[i].powerOn == true && systems[systemIdx].zones[i].dndOn == false) {
var zone = i;
zone = zoneLookup(zone);
console.log("mute zone " + i)
command = ["02", "00", zone, "04", "1E"]
systems[systemIdx].zones[i].muteOn = true;
wsSendBinary(command, false);
updateData();
}
setTimeout(function(y) {
checkNextForMuteAllOn(i + 1)
}, 50);
}
}
function muteAllOff() {
console.log("UNMute all zones")
checkNextForUnMuteAllOn(1);
}
function checkNextForUnMuteAllOn(i) {
if (i < systems[systemIdx].zones.length) {
if (systems[systemIdx].zones[i].powerOn == true && systems[systemIdx].zones[i].dndOn == false) {
var zone = i;
zone = zoneLookup(zone);
console.log("unmute zone " + i)
command = ["02", "00", zone, "04", "1F"]
systems[systemIdx].zones[i].muteOn = false;
wsSendBinary(command, false);
updateCommand(i);
updateData();
}
setTimeout(function(y) {
checkNextForUnMuteAllOn(i + 1)
}, 50);
}
}
function groupMuteOn() {
console.log("Mute all group zones: " + Ggroup + ":" + systems[systemIdx].groups[Ggroup].zones.length)
checkNextForGroupMuteAllOn(0);
}
function checkNextForGroupMuteAllOn(i) {
console.log("checkNextForGroupMuteAllOn: " + i, systems[systemIdx].groups[Ggroup].zones.length)
if (i < systems[systemIdx].groups[Ggroup].zones.length) {
setTimeout(function(y) {
checkNextForGroupMuteAllOn(i + 1)
}, 50);
var zone = systems[systemIdx].groups[Ggroup].zones[i];
if (systems[systemIdx].zones[zone].powerOn == true && systems[systemIdx].zones[zone].dndOn == false) {
var zoneOrig = systems[systemIdx].zones;
zone = zoneLookup(zone);
console.log("mute zone " + zone)
command = ["02", "00", zone, "04", "1E"]
systems[systemIdx].zones[systems[systemIdx].groups[Ggroup].zones[i]].muteOn = true;
wsSendBinary(command, false);
updateCommand(zoneOrig);
updateData();
}
}
}
function setDoorbell() {
//console.log("setDoorbell: " + systems[systemIdx].system.enableDoorbell);
if (systems[systemIdx].system.enableDoorbell == true) {
setNextDoorbell(1);
}
}
function setNextDoorbell(i) {
if (i >= systems[systemIdx].zones.length) {
//console.log("Done setting doorbell zones");
return;
}
//console.log("setDoorbell: " + i + ":" + zones[i].enableDoorbell);
if (systems[systemIdx].zones[i].enableDoorbell) {
ignoreDoorbellOff(i)
} else {
ignoreDoorbellOn(i);
}
setTimeout(function() {
setNextDoorbell(i + 1)
}, 200);
}
function groupMuteOff() {
console.log("UnMute all group zones")
checkNextForGroupMuteAllOff(0);
}
function checkNextForGroupMuteAllOff(i) {
if (i < systems[systemIdx].groups[Ggroup].zones.length) {
setTimeout(function(y) {
checkNextForGroupMuteAllOff(i + 1)
}, 50);
var zone = systems[systemIdx].groups[Ggroup].zones[i];
if (systems[systemIdx].zones[zone].powerOn == true && systems[systemIdx].zones[zone].dndOn == false) {
var zoneOrig = zone;
zone = zoneLookup(zone);
console.log("mute zone " + zone)
command = ["02", "00", zone, "04", "1F"]
console.log(command);
systems[systemIdx].zones[systems[systemIdx].groups[Ggroup].zones[i]].muteOn = false;
wsSendBinary(command, false);
updateCommand(zoneOrig);
updateData();
}
}
}
function resetSourceName(source) {
var name = "Source " + source
source = sourceCommandLookupForReset(source);
var zone = "00";
var command = ["02", "00", zone, "07", source]
for (var n = 0, l = name.length; n < l; n++) {
var hex = Number(name.charCodeAt(n)).toString(16);
hex = hex.toUpperCase();
command.push(hex);
}
//see how many spaces we need to add 00 for
var extraSpaces = 10 - name.length;
for (i = 0; i < extraSpaces; i++) {
command.push("00")
}
command.push("00");
console.log("rename source reset to: ", name, command, source)
wsSendBinary(command, false);
}
function resetZoneName(zone) {
var name = "Zone " + zone;
zone = zoneLookup(zone);
console.log("Name zone " + zone + " to " + name)
//var hexName = ascii_to_hexa(name);
var command = ["02", "00", zone, "06", "00"]
for (var n = 0, l = name.length; n < l; n++) {
var hex = Number(name.charCodeAt(n)).toString(16);
hex = hex.toUpperCase();
command.push(hex);
}
//see how many spaces we need to add 00 for
var extraSpaces = 10 - name.length;
for (i = 0; i < extraSpaces; i++) {
command.push("00")
}
command.push("00")
wsSendBinary(command, false);
}
function resetZoneAudio(zone) {
var zoneOrig = zone;
zone = zoneLookup(zone);
command = ["02", "00", zone, "1E", "00"]
//console.log(command);
wsSendBinary(command, false);
updateCommand(zoneOrig);
}
function mp3PlayPause() {
$('#mp3Play').attr('src', 'images/playActive.png');
console.log("mp3PlayPause")
command = ["02", "00", "00", "04", "0B"]
//console.log(command);
wsSendBinary(command, false);
setTimeout(function() {
$('#mp3Play').attr('src', 'images/play.png');
}, 400);
}
function mp3Back() {
$('#mp3Prev').attr('src', 'images/rarowActive.png');
command = ["02", "00", "00", "04", "0C"]
//console.log(command);
wsSendBinary(command, false);
setTimeout(function() {
$('#mp3Prev').attr('src', 'images/rarow.png');
}, 400);
}
function mp3Next() {
$('#mp3Next').attr('src', 'images/larowActive.png');
command = ["02", "00", "00", "04", "0A"]
//console.log(command);
wsSendBinary(command, false);
setTimeout(function() {
$('#mp3Next').attr('src', 'images/larow.png');
}, 400);
}
function mp3Repeat() {
var src = $('#mp3RepeatImg').attr("src");
if (src == "images/row.png") {
mp3RepeatOn();
} else if (firmware == "v2" && src == "images/rowActive.png") {
mp3RepeatOff();
} else if (firmware == "v3" && src == "images/rowActive.png") {
mp3Shuffle();
} else if (src == "images/shuffleActive.png") {
mp3RepeatOff();
}
}
function mp3Stop() {
$('#mp3Stop').attr('src', 'images/stopActive.png');
command = ["02", "00", "00", "04", "0D"]
//console.log(command);
wsSendBinary(command, false);
if (systems[systemIdx].system.model == "Lync6") {
systems[systemIdx].sources[12].mp31 = "Stopped";
} else {
systems[systemIdx].sources[18].mp31 = "Stopped";
}
$("#artistName").text("Press Play to Begin");
$("#songName").text("Stopped");
setTimeout(function() {
$('#mp3Stop').attr('src', 'images/stop.png');
}, 400);
}
function mp3RepeatOn() {
command = ["02", "00", "00", "01", "FF"]
//console.log(command);
$('#mp3RepeatImg').attr("src", "images/rowActive.png")
wsSendBinary(command, false);
}
function mp3RepeatOff() {
command = ["02", "00", "00", "01", "00"]
//console.log(command);
$('#mp3RepeatImg').attr("src", "images/row.png")
wsSendBinary(command, false);
}
function mp3Shuffle() {
console.log("mp3 shuffle")
command = ["02", "00", "00", "01", "02"]
//console.log(command);
$('#mp3RepeatImg').attr("src", "images/shuffleActive.png")
wsSendBinary(command, false);
}
function zoneMuteOn(zone) {
console.log("zoneMuteOn")
//var zone = Gzone;
var zoneOrig = zone;
zone = zoneLookup(zone);
command = ["02", "00", zone, "04", "1E"]
//console.log(command);
wsSendBinary(command, false);
updateCommand(zoneOrig);
}
function zoneMuteOff() {
console.log("zoneMuteOff")
var zone = Gzone;
zone = zoneLookup(zone);
command = ["02", "00", zone, "04", "1F"]
//console.log(command);
wsSendBinary(command, false);
updateCommand(Gzone);
}
function zoneSetVolume(zone) {
console.log("zoneSetVolume: " + systems[systemIdx].zones[zone].vol)
if (systems[systemIdx].zones[zone].powerOn == false) {
zonePowerOn(zone);
}
if (systems[systemIdx].zones[zone].muteOn == true) {
zoneMuteOff(zone);
}
var zoneOrig = zone;
zone = zoneLookup(zone);
var volume = volumeCommandLookup(systems[systemIdx].zones[zoneOrig].vol);
if (volume <= 0) {
volume = 0;
}
if (volume >= 60) {
volume = 60;
}
command = ["02", "00", zone, "15", volume]
//console.log(command);
wsSendBinary(command, false);
//updateCommand(zoneOrig);
//Take this out so that it only sends on release.
//zonePowerOn(zone);
}
function setVolumeForZone(zone, vol) {
console.log("setVolumeForZone " + vol)
if (systems[systemIdx].zones[zone].powerOn == false) {
zonePowerOn(zone);
}
if (systems[systemIdx].zones[zone].muteOn == true) {
zoneMuteOff(zone);
}
var zoneOrig = zone;
zone = zoneLookup(zone);
var volume = volumeCommandLookup(vol);
command = ["02", "00", zone, "15", volume]
systems[systemIdx].zones[zoneOrig].vol = vol;
updateGUI(zoneOrig);
updateData();
wsSendBinary(command, false);
updateCommand(zoneOrig);
//zonePowerOn(zone);
}
function updateCommand(zone) {
//This will send the source set command after commands are sent. This is needed to update the controller.
var zoneOrig = zone;
zone = zoneLookup(zone);
var source = systems[systemIdx].zones[zoneOrig].source;
//console.log(zoneOrig, source)
var sourceFormatted = sourceCommandLookup(source);
command = ["02", "00", zone, "04", sourceFormatted]
wsSendBinary(command, false);
}
function ignoreDoorbellOn(zone) {
var zoneOrig = zone;
zone = zoneLookup(zone);
command = ["02", "01", zone, "04", "A1"]
wsSendBinary(command, false);
}
function ignoreDoorbellOff(zone) {
var zoneOrig = zone;
zone = zoneLookup(zone);
command = ["02", "01", zone, "04", "A0"]
wsSendBinary(command, false);
}
function sourceCommandLookup(source) {
//console.log(source);
console.log("source command lookup")
source = source * 1;
switch (source) {
case 1:
return "10";
break;
case 2:
return "11";
break;
case 3:
return "12";
break;
case 4:
return "13";
break;
case 5:
return "14";
break;
case 6:
return "15";
break;
case 7:
return "16";
break;
case 8:
return "17";
break;
case 9:
return "18";
break;
case 10:
return "19";
break;
case 11:
return "1A";
break;
case 12:
return "1B";
break;
case 13:
if (systems[systemIdx].system.model == "Lync 6" || systems[systemIdx].sources.length < 15) {
return "7E";
} else {
return "63";
}
break;
case 14:
return "64";
break;
case 15:
return "65";
break;
case 16:
return "66";
break;
case 17:
return "67";
break;
case 18:
return "68";
break;
case 19:
return "7E";
break;
}
}
function zoneLookup(zone) {
//console.log(zone);
zone = zone * 1;
switch (zone) {
case 1:
return "01";
break;
case 2:
return "02";
break;
case 3:
return "03";
break;
case 4:
return "04";
break;
case 5:
return "05";
break;
case 6:
return "06";
break;
case 7:
return "07";
break;
case 8:
return "08";
break;
case 9:
return "09";
break;
case 10:
return "0A";
break;
case 11:
return "0B";
break;
case 12:
//console.log("return 0C")
return "0C";
break;
}
}
function sourceCommandLookupForReset(source) {
//console.log(source);
source = source * 1 - 1;
switch (source) {
case 0:
return "01";
break;
case 1:
return "02";
break;
case 2:
return "03";
break;
case 3:
return '04';
break;
case 4:
return '05';
break;
case 5:
return "06";
break;
case 6:
return "07";
break;
case 7:
return "08";
break;
case 8:
return "09";
break;
case 9:
return "0A";
break;
case 10:
return "0B";
break;
case 11:
return "0C";
break;
case 12:
return "0D";
break;
case 13:
return "0E";
break;
case 14:
return "0F";
break;
case 15:
return "10";
break;
case 16:
return "11";
break;
case 17:
return "12";
break;
case 18:
return "13";
break;
case 19:
return "14";
break;
}
}
function setSourceForZone(zone, source) {
var zoneOrig = zone;
zone = zoneLookup(zone);;
var sourceFormatted = sourceCommandLookup(source);
command = ["02", "00", zone, "04", sourceFormatted]
console.log("---" + source + '--- ')
systems[systemIdx].zones[zoneOrig].source = source;
updateData();
updateGUI(zoneOrig);
wsSendBinary(command, false);
}
function volumeCommandLookup(volume) {
volume = volume * 1 - 60;
console.log("volumeCommandLookup " + volume);
switch (volume) {
case 0:
console.log("00 volume = 60")
return "00";
break;
case -1:
return "FF";
break;
case -2:
return "FE";
break;
case -3:
return "FD";
break;
case -4:
return "FC";
break;
case -5:
return "FB";
break;
case -6:
return "FA";
break;
case -7:
return "F9";
break;
case -8:
return "F8";
break;
case -9:
return "F7";
break;
case -10:
return "F6";
break;
case -11:
return "F5";
break;
case -12:
return "F4";
break;
case -13:
return "F3";
break;
case -14:
return "F2";
break;
case -15:
return "F1";
break;
case -16:
return "F0";
break;
case -17:
return "EF";
break;
case -18:
return "EE";
break;
case -19:
return "ED";
break;
case -20:
return "EC";
break;
case -21:
return "EB";
break;
case -22:
return "EA";
break;
case -23:
return "E9";
break;
case -24:
return "E8";
break;
case -25:
return "E7";
break;
case -26:
return "E6";
break;
case -27:
return "E5";
break;
case -28:
return "E4";
break;
case -29:
return "E3";
break;
case -30:
return "E2";
break;
case -31:
return "E1";
break;
case -32:
return "E0";
break;
case -33:
return "DF";
break;
case -34:
return "DE";
break;
case -35:
return "DD";
break;
case -36:
return "DC";
break;
case -37:
return "DB";
break;
case -38:
return "DA";
break;
case -39:
return "D9";
break;
case -40:
return "D8";
break;
case -41:
return "D7";
break;
case -42:
return "D6";
break;
case -43:
return "D5";
break;
case -44:
return "D4";
break;
case -45:
return "D3";
break;
case -46:
return "D2";
break;
case -47:
return "D1";
break;
case -48:
return "D0";
break;
case -49:
return "CF";
break;
case -50:
return "CE";
break;
case -51:
return "CD";
break;
case -52:
return "CC";
break;
case -53:
return "CB";
break;
case -54:
return "CA";
break;
case -55:
return "49";
break;
case -56:
return "C8";
break;
case -57:
return "C7";
break;
case -58:
return "C6";
break;
case -59:
return "C5";
break;
case -60:
return "C4";
break;
case -61:
return "C3";
break;
}
}
function partySourceLookup(source) {
//console.log(source);
source = source * 1;
switch (source) {
case 1:
return "36";
break;
case 2:
return "37";
break;
case 3:
return "38";
break;
case 4:
return "39";
break;
case 5:
return "3A";
break;
case 6:
return "3B";
break;
case 7:
return "3C";
break;
case 8:
return "3D";
break;
case 9:
return "3E";
break;
case 10:
return "3F";
break;
case 11:
return "40";
break;
case 12:
return "41";
break;
case 13:
return "69";
break;
case 14:
return "6A";
break;
case 15:
return "6B";
break;
case 16:
return "6C";
break;
case 17:
return "6D";
break;
case 18:
return "6E";
break;
}
}
function toggleShowSource(zone, source) {
console.log("toggleShowSource: " + source);
var label = $("#toggleShowSource-" + source).text();
console.log(label);
if (label == "Tap to Hide") {
console.log("hide source");
hideSource(zone, source);
$('#toggleShowSource-' + source).text("Tap to Show");
$('#toggleShowSource-' + source).removeClass("blue");
$('#toggleShowSource-' + source).addClass("grey");
} else {
showSource(zone, source);
console.log("show source");
$('#toggleShowSource-' + source).text("Tap to Hide");
$('#toggleShowSource-' + source).removeClass("grey");
$('#toggleShowSource-' + source).addClass("blue");
}
}
function hideSource(zone, source) {
var sourceOrig = source;
zone = zoneLookup(zone);
if (source < 10) {
source = "0" + source;
}
source = source + "";
//source = "02"
switch (sourceOrig) {
case 10:
source = "0A";
break;
case 11:
source = "0B";
break;
case 12:
source = "0C";
break;
case 13:
source = "0D";
break;
case 14:
source = "0E";
break;
case 15:
source = "0F";
break;
case 16:
source = "10";
break;
case 17:
source = "11";
break;
case 18:
source = "12";
break;
}
var name = "None";
//var hexName = ascii_to_hexa(name);
var command = ["02", "00", zone, "07", source]
for (var n = 0, l = name.length; n < l; n++) {
var hex = Number(name.charCodeAt(n)).toString(16);
hex = hex.toUpperCase();
command.push(hex);
}
//see how many spaces we need to add 00 for
var extraSpaces = 10 - name.length;
for (i = 0; i < extraSpaces; i++) {
command.push("00")
}
command.push("00")
console.log(command, command.length);
wsSendBinary(command, false);
// $('#sourcesOnKeypad').empty();
// zoneSettingsZone = zone;
// getSourcesPerZone(zone, 0);
}
function showSource(zone, source) {
var sourceOrig = source;
zone = zoneLookup(zone);
if (source < 10) {
source = "0" + source;
}
source = source + "";
//source = "02"
switch (sourceOrig) {
case 10:
source = "0A";
break;
case 11:
source = "0B";
break;
case 12:
source = "0C";
break;
case 13:
source = "0D";
break;
case 14:
source = "0E";
break;
case 15:
source = "0F";
break;
case 16:
source = "10";
break;
case 17:
source = "11";
break;
case 18:
source = "12";
break;
}
console.log("original source name: " + sources[sourceOrig].name)
//var name = "Source " + sourceOrig;
var name = sources[sourceOrig].name;
//var hexName = ascii_to_hexa(name);
var command = ["02", "00", zone, "07", source]
for (var n = 0, l = name.length; n < l; n++) {
var hex = Number(name.charCodeAt(n)).toString(16);
hex = hex.toUpperCase();
command.push(hex);
}
//see how many spaces we need to add 00 for
var extraSpaces = 10 - name.length;
for (i = 0; i < extraSpaces; i++) {
command.push("00")
}
command.push("00");
console.log(command, command.length);
wsSendBinary(command, false);
}
function ascii_to_hexa(str) {
var arr1 = [];
for (var n = 0, l = str.length; n < l; n++) {
var hex = Number(str.charCodeAt(n)).toString(16);
arr1.push(hex);
}
console.log(arr1);
return arr1;
}
function zoneSetBass(bass) {
if (!Gzone || !systems[systemIdx].zones) {
return;
}
var zone = Gzone;
zone = zoneLookup(zone);
systems[systemIdx].zones[Gzone].bass = bass;
var bass = bassCommandLookup(systems[systemIdx].zones[Gzone].bass);
command = ["02", "00", zone, "18", bass]
//console.log(command);
wsSendBinary(command, false);
updateCommand(Gzone);
//zonePowerOn(Gzone);
}
function zoneResetBass(zone, bass) {
var zoneOrig = zone;
zone = zoneLookup(zone);
var bass2 = bassCommandLookup(bass);
command = ["02", "00", zone, "18", bass2]
//console.log(command);
wsSendBinary(command, false);
updateCommand(zoneOrig);
}
function zoneSetTreble(treble) {
if (!Gzone || !systems[systemIdx].zones) {
return;
}
var zone = Gzone;
zone = zoneLookup(zone);
systems[systemIdx].zones[Gzone].treble = treble;
var treble = bassCommandLookup(systems[systemIdx].zones[Gzone].treble);
command = ["02", "00", zone, "17", treble]
//console.log(command);
wsSendBinary(command, false);
updateCommand(Gzone);
}
function zoneResetTreble(zone, treble) {
var zoneOrig = zone;
zone = zoneLookup(zone);
var treble2 = bassCommandLookup(treble);
command = ["02", "00", zone, "17", treble2]
//console.log(command);
wsSendBinary(command, false);
updateCommand(zoneOrig);
}
function bassCommandLookup(bass) {
//0 is -10, 10 is 0, 20 is 10
bass = bass * 1;
console.log(bass);
switch (bass) {
case -10:
return "F6";
break;
case -9:
return "F7";
break;
case -8:
return "F8";
break;
case -7:
return "F9";
break;
case -6:
return "FA";
break;
case -5:
return "FB";
break;
case -4:
return "FC";
break;
case -3:
return "FD";
break;
case -2:
return "FE";
break;
case -1:
return "FF";
break;
case 0:
return "00";
break;
case 1:
return "01";
break;
case 2:
return "02";
break;
case 3:
return "03";
break;
case 4:
return "04";
break;
case 5:
return "05";
break;
case 6:
return "06";
break;
case 7:
return "07";
break;
case 8:
return "08";
break;
case 9:
return "09";
break;
case 10:
return "0A";
break;
}
}
function zoneSetBalance(balance) {
if (!Gzone || !systems[systemIdx].zones) {
return;
}
var zone = Gzone;
zone = zoneLookup(zone);
systems[systemIdx].zones[Gzone].balance = balance;
var balance = balanceCommandLookup(systems[systemIdx].zones[Gzone].balance);
command = ["02", "00", zone, "16", balance]
//console.log(command);
wsSendBinary(command, false);
updateCommand(Gzone);
}
function zoneResetBalance(zone, balance) {
var zoneOrig = zone;
zone = zoneLookup(zone);
var balance2 = balanceCommandLookup(balance);
command = ["02", "00", zone, "16", balance2]
//console.log(command);
wsSendBinary(command, false);
updateCommand(zoneOrig);
}
function balanceCommandLookup(balance) {
//0 is -10, 10 is 0, 20 is 10
balance = balance * 1;
console.log(balance);
switch (balance) {
case 18:
return "12";
break;
case 17:
return "11";
break;
case 16:
return "10";
break;
case 15:
return "0F";
break;
case 14:
return "0E";
break;
case 13:
return "0D";
break;
case 12:
return "0C";
break;
case 11:
return "0B";
break;
case 10:
return "0A";
break;
case 9:
return "09";
break;
case 8:
return "08";
break;
case 7:
return "07";
break;
case 6:
return "06";
break;
case 5:
return "05";
break;
case 4:
return "04";
break;
case 3:
return "03";
break;
case 2:
return "02";
break;
case 1:
return "01";
break;
case 0:
return "00";
break;
case -1:
return "FF";
break;
case -2:
return "FE";
break;
case -3:
return "FD";
break;
case -4:
return "FC";
break;
case -5:
return "FB";
break;
case -6:
return "FA";
break;
case -7:
return "F9";
break;
case -8:
return "F8";
break;
case -9:
return "F7";
break;
case -10:
return "F6";
break;
case -11:
return "F5";
break;
case -12:
return "F4";
break;
case -13:
return "F3";
break;
case -14:
return "F2";
break;
case -15:
return "F1";
break;
case -16:
return "F0";
break;
case -17:
return "EF";
break;
case -18:
return "EE";
break;
}
}