Skip to content

Commit

Permalink
Allow to start Orbital server with the Display API
Browse files Browse the repository at this point in the history
  • Loading branch information
BinaryBrain committed Aug 13, 2024
1 parent f907fd3 commit 62387bb
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions server/NB_LED.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@ export let NB_LED: number = null;

export async function fetchNB_LED(): Promise<void> {
const endpoint = env.USE_WLED ? 'json' : 'config';
const res = await axios.get(
`http://${env.DISPLAY_API_HOSTNAME}:${env.DISPLAY_API_INFO_PORT}/${endpoint}`
);
NB_LED = env.USE_WLED ? parseInt(res.data.info.leds.count) : parseInt(res.data.NB_LED);

if (typeof NB_LED !== "number" || isNaN(NB_LED)) {
throw new Error(
`NB_LED fetched from http://${env.DISPLAY_API_HOSTNAME}:${env.DISPLAY_API_INFO_PORT}/${endpoint} is not a number`
try {
const res = await axios.get(
`http://${env.DISPLAY_API_HOSTNAME}:${env.DISPLAY_API_INFO_PORT}/${endpoint}`
);
NB_LED = env.USE_WLED ? parseInt(res.data.info.leds.count) : parseInt(res.data.NB_LED);

if (typeof NB_LED !== "number" || isNaN(NB_LED)) {
throw new Error(
`NB_LED fetched from http://${env.DISPLAY_API_HOSTNAME}:${env.DISPLAY_API_INFO_PORT}/${endpoint} is not a number`
);
}
} catch (e) {
console.error("Error while fetching NB_LED. Please make sure the display API is running.");
console.error(e);
console.log("Falling back to default value");
NB_LED = 60;
}
}

0 comments on commit 62387bb

Please sign in to comment.