UNPKG

node-anemometer

Version:

Measuring the wind speed with an anemometer

101 lines (100 loc) 3.99 kB
import { type GetDataConditions, type TimeCondition } from './utils/History'; import { type WindSpeed } from './utils/utilities'; /** * Represents an Anemometer device for measuring wind speed using a PCF8583 real-time clock module. * This class allows you to read wind speed data, calculate wind speed values, and maintain a history * of pulse counts to determine wind speed over time. */ export declare class Anemometer { private readonly calc; private readonly opts; private readonly chip; private readonly history; private readInterval; /** * Creates an instance of the Anemometer class, which interfaces with a PCF8583 module. * * @param calc A function that calculates WindSpeed based on pulse count and time. * @param opts Optional configuration options for the Anemometer. */ constructor(calc: (pulses: number, time: number) => WindSpeed, opts?: AnemometerOptions); /** * Indicator of whether a connection has been established and the data is being read.. * * @readonly * @returns `true` if the connection is ready; otherwise, `false`. */ get isReady(): boolean; /** * Resets the PCF8583 chip to its default values and initializes it for event counting mode. * * @returns A promise that resolves when the chip is successfully reset and initialized. */ private resetChip; /** * Clears the read interval if it is set. * * @returns A promise that resolves when the read interval is cleared. */ private clearReadInterval; /** * Opens the i2c connection and start the reading data. * * @returns A promise that resolves when the connection is successfully opened. */ open(): Promise<void>; /** * Closes the i2c connection and stops the reading process. * * @returns A promise that resolves when the connection is successfully closed. */ close(): Promise<void>; /** * Calculates the average wind speed of the past x seconds. * * @deprecated Use `.getAverageWindSpeed()` instead of `.getData()` * @param time The offset for which to retrieve wind speed data. * @returns The average WindSpeed data for the specified time. */ getData(time: number): WindSpeed; /** * Retrieves data records based on the specified conditions. * * @param conditions The conditions to filter and retrieve the data records. * @returns An copied array of data records. Each record includes a value and a timestamp. */ getHistoryData(conditions: GetDataConditions): import("./utils/History").DataRecord<number>[]; /** * Calculates the average wind speed over a specified time period. * The average wind speed is computed from the total pulses and the time span of the data records. * * @param conditions Optional time conditions to filter the data. * @returns The average wind speed calculated from the data records. */ getAverageWindSpeed(conditions?: TimeCondition): WindSpeed; /** * Finds the peak wind gust within a specified time period. * The peak wind gust is determined by finding the largest increase in pulse values and the corresponding time span. * * @param conditions Optional time conditions to filter the data. * @returns The peak wind gust calculated from the data records. */ getPeakWindGust(conditions?: TimeCondition): WindSpeed; } /** * Anemometer configuration options. */ export type AnemometerOptions = { bus?: number; address?: number; readInterval?: number; retries?: number; readFailed?: (error: unknown) => void; history?: { expirationTime?: number; maxElements?: number; }; }; export default Anemometer; export type { GetDataConditions, DataRecord as HistoryDataRecord, TimeCondition } from './utils/History'; export { calcFactor, scanBus, WindSpeed, WindSpeedUnits } from './utils/utilities';