@linuxcnc-node/hal
Version:
Node.js bindings for LinuxCNC HAL library
62 lines (61 loc) • 1.76 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Param = exports.Pin = exports.HalItem = void 0;
const events_1 = require("events");
class HalItem extends events_1.EventEmitter {
constructor(component, nameSuffix, type, direction) {
super();
this.component = component;
this.name = nameSuffix;
this.type = type;
this.direction = direction;
}
/**
* Retrieves the current value of this item.
*
* @returns The item's value (number or boolean depending on type).
*/
getValue() {
return this.component.getValue(this.name);
}
/**
* Sets the value of this item.
*
* For pins, only applicable to `HAL_OUT` or `HAL_IO` pins.
* For parameters, only applicable to `HAL_RW` parameters.
*
* @param value - The new value for the item.
* @returns The value that was set.
* @throws Error if trying to set an `HAL_IN` pin or `HAL_RO` parameter.
*/
setValue(value) {
return this.component.setValue(this.name, value);
}
}
exports.HalItem = HalItem;
/**
* Represents a HAL pin. Instances are returned by `component.newPin()`.
*
* @example
* ```typescript
* const pin = comp.newPin("output", "float", "out");
* pin.setValue(123.45);
* pin.on('change', (newVal, oldVal) => console.log(newVal));
* ```
*/
class Pin extends HalItem {
}
exports.Pin = Pin;
/**
* Represents a HAL parameter. Instances are returned by `component.newParam()`.
*
* @example
* ```typescript
* const param = comp.newParam("speed", "float", "rw");
* param.setValue(100.0);
* param.on('change', (newVal, oldVal) => console.log(newVal));
* ```
*/
class Param extends HalItem {
}
exports.Param = Param;