Skip to content

Commit

Permalink
fix incorrect rendering #18
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Benjamin Ries authored and cbries committed Jan 7, 2025
1 parent cf89854 commit e7b41cf
Showing 1 changed file with 34 additions and 25 deletions.
59 changes: 34 additions & 25 deletions Source/EsuEcosMiddleman/Renderer/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function generateBaseView(jsonData) {
}
}

if (middleNo === 0) {
if (rightNo === 0) {
const newPortDiv = getNewEmptyPortDiv("right");
$('#s88right').append(newPortDiv);
} else {
Expand Down Expand Up @@ -108,33 +108,42 @@ function updateView(jsonData) {
}
*/

/// TODO handle port addressing
/// something like this
/// if portNo >= 0 && portNo <= event.info.left
/// !!!update left
/// else if portNo > event.info.left && portNo <= (event.info.left + event.info.middle)
/// !!!update middle
/// else if(portNo > (event.info.left + event.info.middle))
/// !!!update right
/// endif

let portState = jsonData.event.state.binary;
for (let pinNo = 1; pinNo <= 16; ++pinNo) {
const idx = 16 - pinNo;
const id = "#left_port" + portNo + "_" + idx;
const pinState = parseInt(portState[idx]);
$(id).removeClass("pinDisabled");
$(id).removeClass("pinEnabled");
if (pinState === 1) {
$(id).addClass("pinEnabled");
} else {
$(id).addClass("pinDisabled");
}
}
let evData = jsonData.event;
let evInfo = jsonData.info;

let portIdAccessor = '';

if( portNo >= 0 && portNo <= evInfo.left ) {
portIdAccessor = "left";
} else if( portNo > evInfo.left && portNo <= (evInfo.left + evInfo.middle) ) {
portIdAccessor = "middle";
} else if( portNo > (evInfo.left + evInfo.middle) ) {
portIdAccessor = "right";
}

if(portIdAccessor.length > 0) {

let portState = evData.state.binary;

for (let pinNo = 1; pinNo <= 16; ++pinNo) {
const idx = 16 - pinNo;
const id = "#" + portIdAccessor + "_port" + portNo + "_" + pinNo;
const pinState = parseInt(portState[idx]);
$(id).removeClass("pinDisabled");
$(id).removeClass("pinEnabled");
if (pinState === 1) {
$(id).addClass("pinEnabled");
} else {
$(id).addClass("pinDisabled");
}
}

}

}

$(document).ready(function () {
let socket = new WebSocket("ws://localhost:15472/s88/");
let socket = new WebSocket("ws://192.168.178.129:15472/s88/");
socket.onclose = function () { console.log("Closed!"); };
socket.onopen = function () { console.log("Connected!"); };
socket.onmessage = function (msg) {
Expand Down

0 comments on commit e7b41cf

Please sign in to comment.