From d2a127f942965e6bf8284572e92be3465c1c4fd9 Mon Sep 17 00:00:00 2001 From: danielboe Date: Tue, 26 Nov 2024 10:37:09 +0100 Subject: [PATCH] fix(server) wait for init done --- app/hwcontrol.js | 28 ++++++++++++++++------------ server.js | 2 +- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/app/hwcontrol.js b/app/hwcontrol.js index 0cfee34..89d30dd 100644 --- a/app/hwcontrol.js +++ b/app/hwcontrol.js @@ -222,19 +222,23 @@ function pjlinkSet(ip, command) { module.exports = { init: async function () { - beamerArray = BEAMER_IP.split(","); - if (beamerArray.length >= 1) { - console.log("[INIT] projector defined: " + beamerArray); - console.log("[INIT] PJLINK data:"); - for (let index = 0; index < beamerArray.length; index++) { - const element = beamerArray[index]; - //await sendSerialProjector("7E3030303020310D", element); //power on optoma - var status = await pjlinkSet(element, "status"); - console.log(status); + return new Promise(async (resolve, reject) => { + beamerArray = BEAMER_IP.split(","); + if (beamerArray.length >= 1) { + console.log("[INIT] projector defined: " + beamerArray); + console.log("[INIT] PJLINK data:"); + for (let index = 0; index < beamerArray.length; index++) { + const element = beamerArray[index]; + //await sendSerialProjector("7E3030303020310D", element); //power on optoma + var status = await pjlinkSet(element, "status"); + console.log(status); + } + resolve(true); + } else { + console.log("[INIT] NO projector defined"); + resolve(false); } - } else { - console.log("[INIT] NO projector defined"); - } + }); }, setScreenPower: async function (powerState, screenNumber = 0, ddc = false) { diff --git a/server.js b/server.js index e0d5a63..b3d3f51 100644 --- a/server.js +++ b/server.js @@ -89,7 +89,7 @@ httpServer2.listen(PORT2, () => { init(); async function init() { - control.init(); + await control.init(); let displayCount = (await control.getDisplayCount()).data; if (displayCount < 1) { if (AUTOREBOOT) {