UNPKG

@linuxcnc-node/hal

Version:

Node.js bindings for LinuxCNC HAL library

62 lines (61 loc) 1.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RtapiMsgLevelFromValue = exports.HalParamDirFromValue = exports.HalPinDirFromValue = exports.HalTypeFromValue = exports.RtapiMsgLevelValue = exports.HalParamDirValue = exports.HalPinDirValue = exports.HalTypeValue = exports.halNative = void 0; // Native addon - loaded once on module import // eslint-disable-next-line @typescript-eslint/no-explicit-any function loadAddon() { const paths = [ "../build/Release/hal_addon.node", "../../build/Release/hal_addon.node", ]; for (const path of paths) { try { return require(path); } catch { // Try next path } } throw new Error("Failed to load linuxcnc-node hal native addon. Please ensure it's built correctly and that LinuxCNC is in your PATH."); } // eslint-disable-next-line @typescript-eslint/no-explicit-any exports.halNative = loadAddon(); // Numeric value mappings for native interop exports.HalTypeValue = { bit: 1, float: 2, s32: 3, u32: 4, s64: 6, u64: 7, }; exports.HalPinDirValue = { in: 16, out: 32, io: 48, }; exports.HalParamDirValue = { ro: 64, rw: 192, }; exports.RtapiMsgLevelValue = { none: 0, err: 1, warn: 2, info: 3, dbg: 4, all: 5, }; // Helper to generate reverse mapping function createReverseMap(map) { const reverse = {}; for (const [key, value] of Object.entries(map)) { reverse[value] = key; } return reverse; } // Reverse mappings for native -> TS conversion exports.HalTypeFromValue = createReverseMap(exports.HalTypeValue); exports.HalPinDirFromValue = createReverseMap(exports.HalPinDirValue); exports.HalParamDirFromValue = createReverseMap(exports.HalParamDirValue); exports.RtapiMsgLevelFromValue = createReverseMap(exports.RtapiMsgLevelValue);