UNPKG

node-anemometer

Version:

Measuring the wind speed with an anemometer

122 lines (121 loc) 4.35 kB
import { type I2CBus, type OpenOptions } from 'i2c-bus'; import { type PCF8583Mode } from './constants'; /** * Represents a PCF8583 real-time clock module. * This class provides methods to interact with the PCF8583 module over I2C. */ export declare class PCF8583 { readonly address: number; readonly bus: number; readonly i2cOptions?: OpenOptions | undefined; protected wire: I2CBus | null; /** * Creates an instance of PCF8583. * * @param address The I2C address of the PCF8583 module. * @param bus The I2C bus number. */ constructor(address: number, bus: number, i2cOptions?: OpenOptions | undefined); /** * Indicates whether the I2C connection is currently open. * * @readonly * @returns `true` if the connection is open, otherwise `false`. */ get isOpen(): boolean; /** * Writes an array of bytes to the specified register. * * @param register The register address to write to. * @param bytes The array of bytes to write. * @returns A promise that resolves when the write operation is complete. * @throws If the I2C connection is not open. * @throws If the write operation fails. */ protected i2cWriteBytes(register: number, bytes: number[]): Promise<void>; /** * Reads an array of bytes from the specified register. * * @param register The register address to read from. * @param length The number of bytes to read. * @returns A promise that resolves with the read bytes as a Buffer. * @throws If the I2C connection is not open. * @throws If the read operation fails. */ protected i2cReadBytes(register: number, length: number): Promise<Buffer<ArrayBufferLike>>; /** * Reads a single byte from the specified register. * * @param offset The register address to read from. * @returns A promise that resolves with the read byte value. * @throws If the I2C connection is not open. * @throws If the read operation fails. */ protected i2cReadRegister(offset: number): Promise<number>; /** * Writes a single byte to the specified register. * * @param offset The register address to write to. * @param value The byte value to write. * @returns A promise that resolves when the write operation is complete. * @throws If the I2C connection is not open. * @throws If the write operation fails. */ protected i2cWriteRegister(offset: number, value: number): Promise<void>; /** * Opens the I2C connection to the PCF8583 module. * * @returns Resolves when the connection is successfully opened. * @throws If the i2c connection is already opened. */ open(): Promise<void>; /** * Closes the I2C connection to the PCF8583 module and stops the clock. * * @returns Resolves when the connection is successfully closed. * @throws If the i2c connection is already closed. */ close(): Promise<void>; /** * Starts the clock on the PCF8583 module. * * @returns A promise that resolves when the clock is started. * @throws If the I2C connection is not open. * @throws If the start operation fails. */ start(): Promise<void>; /** * Stops the clock on the PCF8583 module. * * @returns A promise that resolves when the clock is stopped. * @throws If the I2C connection is not open. * @throws If the stop operation fails. */ stop(): Promise<void>; /** * Resets the PCF8583 module to its default values. * * @returns Resolves when the module is successfully reset. */ reset(): Promise<void>; /** * Sets the clock mode of the PCF8583 module. * * @param mode The mode to set. * @returns Resolves when the mode is successfully set. */ setMode(mode: PCF8583Mode): Promise<void>; /** * Sets the counter value of the PCF8583 module. * * @param value The value to set in the counter. * @returns Resolves when the counter value is successfully set. */ setCount(value: number): Promise<void>; /** * Retrieves the current counter value from the PCF8583 module. * * @returns Resolves with the current counter value. */ getCount(): Promise<number>; }