UNPKG

@linuxcnc-node/hal

Version:

Node.js bindings for LinuxCNC HAL library

163 lines (162 loc) 5.63 kB
import { HalType, HalPinDir, HalParamDir } from "./enums"; export declare const DEFAULT_POLL_INTERVAL = 10; export type HalWatchCallback = (newValue: number | boolean, oldValue: number | boolean, object: Pin | Param) => void; export interface HalWatchOptions { pollInterval?: number; } export interface HalWatchedObject { object: Pin | Param; lastValue: number | boolean; callbacks: Set<HalWatchCallback>; } export interface NativeHalComponent { newPin(nameSuffix: string, type: HalType, direction: HalPinDir): boolean; newParam(nameSuffix: string, type: HalType, direction: HalParamDir): boolean; ready(): void; unready(): void; getProperty(name: string): number | boolean; setProperty(name: string, value: number | boolean): number | boolean; readonly name: string; readonly prefix: string; } export type HalComponentInstance = HalComponent & { [key: string]: number | boolean; }; export declare class HalComponent { private nativeInstance; private proxyInstance; private pins; private params; private watchedObjects; private monitoringTimer; private monitoringOptions; readonly name: string; readonly prefix: string; constructor(nativeInstance: NativeHalComponent, componentName: string, componentPrefix: string); /** * Creates a new HAL pin for this component. * @param nameSuffix The suffix for the pin name (e.g., "in1"). Full name will be "prefix.suffix". * @param type The data type of the pin. * @param direction The direction of the pin (IN, OUT, IO). * @returns A new Pin instance. */ newPin(nameSuffix: string, type: HalType, direction: HalPinDir): Pin; /** * Creates a new HAL parameter for this component. * @param nameSuffix The suffix for the parameter name. * @param type The data type of the parameter. * @param direction The writability of the parameter (RO, RW). * @returns A new Param instance. */ newParam(nameSuffix: string, type: HalType, direction: HalParamDir): Param; /** * Marks this component as ready and locks out adding new pins/params. */ ready(): void; /** * Allows a component to add pins/params after ready() has been called. * ready() must be called again afterwards. */ unready(): void; /** * Retrieves all pins in this component. * @returns Map of all pins in this component */ getPins(): { [key: string]: Pin; }; /** * Retrieves all parameters in this component. * @returns Map of all parameters in this component */ getParams(): { [key: string]: Param; }; /** * Sets monitoring options for the component. * @param options Options to configure monitoring behavior */ setMonitoringOptions(options: HalWatchOptions): void; /** * Gets current monitoring options. * @returns Current monitoring options */ getMonitoringOptions(): HalWatchOptions; /** * Adds a watch callback for a pin or parameter. * @param name Name of the pin or parameter to watch * @param callback Function to call when value changes */ addWatch(name: string, callback: HalWatchCallback): void; /** * Removes a watch callback for a pin or parameter. * @param name Name of the pin or parameter to unwatch * @param callback Function to remove from callbacks */ removeWatch(name: string, callback: HalWatchCallback): void; /** * Gets the list of currently watched objects. * @returns Array of watched object names and types */ getWatchedObjects(): Array<{ object: Pin | Param; callbackCount: number; }>; /** * Starts the monitoring timer. * @private */ private startMonitoring; /** * Stops the monitoring timer. * @private */ private stopMonitoring; /** * Checks all watched objects for value changes and triggers callbacks. * @private */ private checkForChanges; /** * Cleanup method to stop monitoring when component is destroyed. */ destroy(): void; } export declare class Pin { private componentInstance; readonly name: string; readonly type: HalType; readonly direction: HalPinDir; constructor(componentInstance: HalComponentInstance, nameSuffix: string, type: HalType, direction: HalPinDir); getValue(): number | boolean; setValue(value: number | boolean): number | boolean; /** * Starts watching this pin for value changes. * @param callback Function to call when the pin value changes */ watch(callback: HalWatchCallback): void; /** * Stops watching this pin for value changes. * @param callback The specific callback function to remove */ removeWatch(callback: HalWatchCallback): void; } export declare class Param { private componentInstance; readonly name: string; readonly type: HalType; readonly direction: HalParamDir; constructor(componentInstance: HalComponentInstance, nameSuffix: string, type: HalType, direction: HalParamDir); getValue(): number | boolean; setValue(value: number | boolean): number | boolean; /** * Starts watching this parameter for value changes. * @param callback Function to call when the parameter value changes */ watch(callback: HalWatchCallback): void; /** * Stops watching this parameter for value changes. * @param callback The specific callback function to remove */ removeWatch(callback: HalWatchCallback): void; }