Merge pull request #15 from stagehacks/pjlink-cleanup

Cleanup pjlink variables and logic
This commit is contained in:
2022-11-28 20:04:33 -06:00
committed by GitHub
2 changed files with 72 additions and 75 deletions
+72 -73
View File
@@ -19,59 +19,85 @@ exports.ready = function ready(device) {
// Power status query
// device.send("%1POWR ?\r");
};
const PJLinkCmds = [
'%1POWR=',
'%1INPT=',
'%1AVMT=',
'%1ERST=',
'%1LAMP=',
'%1NAME=',
'%1INF1=',
'%1INF2=',
'%2SNUM=',
'%2SVER='
]
let password = false;
function processPJLink(device, str, that) {
function processPJLink(_device, str, that) {
const arr = str.split('%');
arr.shift();
const d = device;
const device = _device;
arr.forEach((s) => {
const split = s.split('=');
const key = split[0];
const value = split[1];
arr.forEach((response) => {
const parts = response.split('=');
const cmd = parts[0];
const value = parts[1];
if(key === '1POWR'){
d.data.power = value;
switch (cmd) {
case '1POWR':
device.data.power = value;
break;
}else if(key === '1INPT'){
d.data.input = value;
}else if(key === '1AVMT'){
d.data.avmute = value;
}else if(key === '1ERST'){
d.data.fanError = value[0];
d.data.lampError = value[1];
d.data.tempError = value[2];
d.data.coverError = value[3];
d.data.filterError = value[4];
d.data.otherError = value[5];
}else if(key === '1LAMP'){
d.data.lamp = value.split(' ');
}else if(key === '1NAME'){
d.data.name = value;
that.deviceInfoUpdate(d, 'defaultName', d.data.name);
}else if(key === '1INF1'){
d.data.info1 = value;
}else if(key === '1INF2'){
d.data.info2 = value;
}else if(key === '2SNUM'){
d.data.serial = value;
}else if(key === '2SVER'){
d.data.version = value;
case '1INPT':
device.data.input = value;
break;
case '1AVMT':
device.data.avmute = value;
break;
case '1ERST':
device.data.fanError = value[0];
device.data.lampError = value[1];
device.data.tempError = value[2];
device.data.coverError = value[3];
device.data.filterError = value[4];
device.data.otherError = value[5];
break;
case '1LAMP':
device.data.lamp = value.split(' ');
break;
case '1NAME':
device.data.name = value;
that.deviceInfoUpdate(device, 'defaultName', device.data.name);
break;
case '1INF1':
device.data.info1 = value;
break;
case '1INF2':
device.data.info2 = value;
break;
case '2SNUM':
device.data.serial = value;
break;
case '2SVER':
device.data.version = value;
break;
default:
break;
}
});
d.draw();
device.draw();
}
exports.data = function data(device, message) {
@@ -84,35 +110,8 @@ exports.data = function data(device, message) {
`${password}%1POWR ?\r%1INPT ?\r%1AVMT ?\r%1ERST ?\r%1LAMP ?\r%1NAME ?\r%1INF1 ?\r%1INF2 ?\r%2SNUM ?\r%2SVER ?\r`
);
}
if (msg.substring(0, 7) === '%1POWR=') {
processPJLink(device, msg, this);
}
if (msg.substring(0, 7) === '%1INPT=') {
processPJLink(device, msg, this);
}
if (msg.substring(0, 7) === '%1AVMT=') {
processPJLink(device, msg, this);
}
if (msg.substring(0, 7) === '%1ERST=') {
processPJLink(device, msg, this);
}
if (msg.substring(0, 7) === '%1LAMP=') {
processPJLink(device, msg, this);
}
if (msg.substring(0, 7) === '%1NAME=') {
processPJLink(device, msg, this);
}
if (msg.substring(0, 7) === '%1INF1=') {
processPJLink(device, msg, this);
}
if (msg.substring(0, 7) === '%1INF2=') {
processPJLink(device, msg, this);
}
if (msg.substring(0, 7) === '%2SNUM=') {
processPJLink(device, msg, this);
}
if (msg.substring(0, 7) === '%2SVER=') {
processPJLink(device, msg, this);
if(PJLinkCmds.includes(msg.substring(0,7))){
processPJLink(device,msg,this)
}
};
-2
View File
@@ -2,7 +2,6 @@
<h1><%= listName %></h1>
</header>
<table class="cv-table">
<tr>
<td>Power</td>
@@ -73,7 +72,6 @@
<% } %>
<% } %>
<tr>
<td>Name</td>
<td><div><%= data.name %></div></td>