From e73ccac65dc9abc498b34193d1312b0f6a291c8d Mon Sep 17 00:00:00 2001 From: Determinant Date: Sat, 17 Aug 2024 22:01:10 -0700 Subject: prepare for an alpha release on npm --- README.rst | 4 ++-- app.mjs | 48 ++++++++++++++++++++++++++++++------------------ package-lock.json | 11 ++++++++++- package.json | 13 ++++++++++++- 4 files changed, 54 insertions(+), 22 deletions(-) diff --git a/README.rst b/README.rst index 8962eab..1c6c763 100644 --- a/README.rst +++ b/README.rst @@ -5,7 +5,7 @@ NOTICE: please ask me for permission before using the code for any commercial pu - Only tested on `Razer Stream Controller`_ (which is an idential device to `Loupedeck Live`_, I bought it because it's cheaper). - Setup: ``npm install`` -- Run: ``./app.mjs`` +- Run: ``./app.mjs`` (make sure you don't have other software using the same device, such as Loupedeck's official software running) .. _Razer Stream Controller: https://www.amazon.com/Razer-Stream-Controller-All-One/dp/B0B5FV1BY6 .. _Loupedeck Live: https://loupedeck.com/us/products/loupedeck-live/ @@ -24,7 +24,7 @@ Demo Resources --------- -- Only tested on Linux, please let me know if it also runs or doesn't run on macOS/Windows. +- Only tested on Linux/Windows (run with CMD), please let me know if it also runs or doesn't run on macOS. - Currently only X-Plane is supported, to get data feed for the displayed gauges, start the program *after* you launche X-Plane (so it will subscribe the data properly). If you're interested in working on MSFS support, etc., diff --git a/app.mjs b/app.mjs index 97964b1..f5c8904 100755 --- a/app.mjs +++ b/app.mjs @@ -11,9 +11,19 @@ import { XPlane } from "./xplane.mjs"; const labelFont = "OCR A Extended"; const labelSize = 22; -const pages = parse(await readFile("./profile.yaml", "utf8")); const xplane = new XPlane(); +if (process.argv.length > 3) { + console.error("./app.mjs [profile YAML file]"); +} +const profile_file = process.argv[2]; +const pages = parse( + await readFile( + profile_file ? profile_file : `${import.meta.dirname}/profile.yaml`, + "utf8", + ), +); + const isNumber = (x) => { return !isNaN(x); }; @@ -29,7 +39,15 @@ let pressed = new Set(); let highlighted = new Set(); // detects and opens first connected device -const device = await discover(); +let device; +while (!device) { + try { + device = await discover(); + } catch (e) { + console.error(`${e}. retry in 5 secs`); + await new Promise((res) => setTimeout(res, 5000)); + } +} const getCurrentPage = () => { return pages[currentPage] || {}; @@ -48,32 +66,26 @@ const getKeyConf = (i) => { const rectifyLabel = (conf) => { // conf must be non-null - let text; - let text2 = null; - let font2 = null; - let size = labelSize; - let color_bg = null; - let color_fg = null; - let color_bg2 = null; - let color_fg2 = null; + let text, text2, font, font2; + let color_bg, color_fg; + let color_bg2, color_fg2; + let size = labelSize; if (isObject(conf)) { - text = conf.text; if (conf.size != null) { size = conf.size; } - if (conf.text2 != null) { - text2 = conf.text2; - font2 = `${size * 0.9}px '${labelFont}'`; - } + text = conf.text; + text2 = conf.text2; color_bg = conf.color_bg; color_fg = conf.color_fg; color_bg2 = conf.color_bg2; color_fg2 = conf.color_fg2; + font2 = `${size * 0.9}px '${labelFont}'`; } else { text = conf.toString(); } - let font = `${size}px '${labelFont}'`; + font = `${size}px '${labelFont}'`; return { text, text2, @@ -246,9 +258,9 @@ const drawAttitudeIndicator = (c, display, values) => { c.rotate((-roll * Math.PI) / 180); c.translate(0, (pitch / 10) * longSep); c.fillStyle = "#0077b6"; - c.fillRect(-0.75 * w, -0.75 * h, 1.5 * w, 0.75 * h); + c.fillRect(-w, -2 * h, 2 * w, 4 * h); c.fillStyle = "#99582a"; - c.fillRect(-0.75 * w, 0, 1.5 * w, 0.75 * h); + c.fillRect(-w, 0, 2 * w, 4 * h); c.lineWidth = 1; c.strokeStyle = fg; c.beginPath(); diff --git a/package-lock.json b/package-lock.json index 747831e..6934403 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,13 +1,22 @@ { - "name": "loupedeck-ctrl", + "name": "loupe-flightdeck", + "version": "0.0.1", "lockfileVersion": 2, "requires": true, "packages": { "": { + "name": "loupe-flightdeck", + "version": "0.0.1", "dependencies": { "canvas": "^2.11.2", "loupedeck": "^6.0.0", "yaml": "^2.5.0" + }, + "bin": { + "loupe-flightdeck": "app.mjs" + }, + "engines": { + "node": ">=16.0.0" } }, "node_modules/@mapbox/node-pre-gyp": { diff --git a/package.json b/package.json index c3f9bcd..53e9bce 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,18 @@ { + "name": "loupe-flightdeck", + "version": "0.0.1", + "description": "Turn your stream deck into a flight deck!", + "repository": { + "type": "git", + "url": "https://github.com/Determinant/loupe-flightdeck" + }, + "engines": { + "node": ">=16.0.0" + }, "dependencies": { "canvas": "^2.11.2", "loupedeck": "^6.0.0", "yaml": "^2.5.0" - } + }, + "bin": "./app.mjs" } -- cgit v1.2.3-70-g09d2