opengpio
Version:
A performant c++ based general purpose GPIO controller for linux devices. OpenGPIO is written using libgpiod, line & chip based abstractions.
62 lines • 2.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Output = void 0;
const bindings_1 = require("../bindings");
const GpioDriver_1 = require("./GpioDriver");
const DriverStoppedError_1 = require("../errors/DriverStoppedError");
/**
* Represents an output GPIO pin.
* Extends the `GpioDriver` class to provide output-specific functionality.
*/
class Output extends GpioDriver_1.GpioDriver {
/**
* Constructs an `Output` instance.
*
* @param gpio - The GPIO pin configuration, including chip and line information.
* @param options - Configuration options for the output pin.
*/
constructor(gpio, options = {}) {
const [setter, cleanup] = bindings_1.bindings.output(gpio.chip, gpio.line);
super(cleanup);
/**
* A function to set the value of the GPIO pin.
* Defaults to a no-op function.
* @private
*/
this.setter = () => { };
this.lastValue = null;
this.debug('constructing output with', gpio, options);
this.setter = setter;
}
/**
* Sets the value of the output GPIO pin.
*
* @param value - The value to set on the GPIO pin (`true` for high, `false` for low).
* @throws {DriverStoppedError} If the output has been stopped.
*/
set value(value) {
value = !!value; // Ensure value is boolean
if (this.stopped) {
this.debug('output is stopped, throwing error');
throw new DriverStoppedError_1.DriverStoppedError('Cannot set value on stopped output');
}
this.debug('setting output value to', value);
this.lastValue = value;
this.setter(value);
}
/**
* Gets the last value set on the output GPIO pin.
* @returns {boolean | null} The last value set on the GPIO pin, or `null` if no value has been set.
* @throws {DriverStoppedError} If the output has been stopped.
*/
get value() {
if (this.stopped) {
this.debug('output is stopped, returning null');
throw new DriverStoppedError_1.DriverStoppedError('Cannot get value on stopped output');
}
this.debug('getting output value, last value was', this.lastValue);
return this.lastValue;
}
}
exports.Output = Output;
//# sourceMappingURL=Output.js.map