pca9685-promise
Version:
controls a PCA9685 (PWM/Servo driver) in node.js using async-i2c-bus.
89 lines (88 loc) • 3.16 kB
TypeScript
/** A library to use the PCA9685 PWM led/servo controller. This library
* used the promisified version of i2c-bus: async-i2c-bus.
*/
import { BusInterface } from "async-i2c-bus";
/** Types of options */
export interface Options {
/** I2C addres. default address is 0x40 */
address?: number;
/** make the device react to the ALLCALL address (false by default) */
allcall?: boolean;
/** the ALLCALL address. Undefined by default (preconfigured E0 at startup) */
allcallAddress?: number;
/** Global frequency of pulses. Default is set to 203 Hz (prescaler=30) */
frequency?: number;
/** external oscillator frequency in hz (hard to use on an Adafruit board) */
oscillator?: number;
}
/** The device class used to control a PCA9685 board. */
export declare class PCA9685 {
private device;
private oscillator;
private flags;
private allcallAddress;
private prescale;
/** Construct the device abstraction
* @param bus: I2c bus
* @param options: Optional option structure
*/
constructor(bus: BusInterface, options?: Options);
/** Initialize the device
*
* The bus must be opened. This step is necessary before using
* any other function.
* The library uses Auto Increment mode. It sets the flags defined
* at startup.
*/
init(): Promise<void>;
/** Restarts (unconditionaly) the device if it was asleep.
*
* Should not be used for standard operation.
* @ignore
*/
restart(): Promise<boolean>;
/** Put the device in sleep mode and return MODE1 register
*
* Putting the device in sleep mode is often necessary to modify its
* control registers. Should not be used for standard operation.
* @ignore
*/
sleep(): Promise<number>;
/** Sets the prescaler to achieve a given frequency in herz.
*
* @param freq the frequency to set
* @return an empty promise.
*/
set_frequency(freq: number): Promise<void>;
/** Sets the duty cycle of a single channel.
*
* @param chan the channel to configure
* @param onValue the step where the pulse begins
* @param offValue the step where the pulse ends
* @return an empty promise.
*/
set_pwm(chan: number, onValue: number, offValue: number): Promise<void>;
/** Set the pulse length in micro second.
*
* @param chan the channel to configure
* @param length the length of the pulse in microsecond
* @param start an optional offset for the start of the pulse.
* @return an empty promise.
*/
set_pwm_ms(chan: number, length: number, start?: number): Promise<void>;
/** Sets the duty cycle of all channels
*
* @param onValue the step where the pulse begins
* @param offValue the step where the pulse ends
* @return an empty promise.
*/
set_all_pwm(onValue: number, offValue: number): Promise<void>;
/** Shutdown a given channel
*
* @param chan channel to shut
*/
shutdown(chan: number): Promise<void>;
/** Shutdown all channels */
shutdown_all(): Promise<void>;
private compute_prescale;
}