UNPKG

node-anemometer

Version:

Measuring the wind speed with an anemometer

132 lines (131 loc) 5.08 kB
import { openSync } from 'i2c-bus'; import type { DataRecord } from './History'; export declare enum WindSpeedUnits { kilometersPerHour = "km/h", metersPerSecond = "m/s", knots = "kn" } /** * Represents a WindSpeed unit with the specified value and unit type. */ export declare class WindSpeed { readonly value: number; readonly unit: WindSpeedUnits; /** * Creates an instance of WindSpeed with a numeric value and unit type. * * @param value The numeric value of the WindSpeed. * @param unit The unit type (e.g., km/h, m/s, kn). */ constructor(value: number, unit: WindSpeedUnits); /** * Rounds the WindSpeed value to a specified number of decimal places. * * @param decimalPlaces The number of decimal places to round to. * @returns The rounded WindSpeed value. */ rounded(decimalPlaces?: number): number; /** * Converts the WindSpeed value to kilometers per hour (km/h). * * @returns A new WindSpeed instance with the value converted to km/h. */ toKilometersPerHour(): WindSpeed; /** * Converts the WindSpeed value to meters per second (m/s). * * @returns A new WindSpeed instance with the value converted to m/s. */ toMetersPerSecond(): WindSpeed; /** * Converts the WindSpeed value to knots (kn). * * @returns A new WindSpeed instance with the value converted to knots. */ toKnots(): WindSpeed; } /** * Sleeps for a specified number of milliseconds. * @param ms The number of milliseconds to sleep. * @returns A promise that resolves after the specified time. */ export declare function sleep(ms: number): Promise<unknown>; /** * Rounds a number to a specified number of decimal places * @param value The number to round * @param decimalPlaces The number of decimal places * @returns The rounded number */ export declare function round(value: number, decimalPlaces: number): number; /** * Calculates the animeter factor based on radius and adjustment. * * __Calculation explained:__ * 1. Scope calculation (π * r * 2) * 2. Convert centimeter to kilometer ( / 100000) * 3. Convert to kilometers per hour ( * 3600) * 4. Multiply adjustment * * @param radius Radius between midpoint and edge of a cup in centimeters. * @param adjustment Power loss due to mechanics (approximately 1.18). * @returns The calculated factor. */ export declare function calcFactor(radius: number, adjustment: number): number; /** * Converts a Binary-Coded Decimal (BCD) value to a byte. * * @param value The BCD value to convert. * @returns The converted byte value. */ export declare function bcdToByte(value: number): number; /** * Converts a byte value to Binary-Coded Decimal (BCD) format. * * @param value The byte value to convert. * @returns The converted BCD value. * @throws If the input value is invalid. */ export declare function byteToBCD(value: number): number; /** * Returns an array of numbers, where each number represents the I2C address of a detected device. * @see https://github.com/fivdi/i2c-bus#busscanstartaddr-endaddr-cb */ export declare function scanBus(...args: Parameters<typeof openSync>): number[]; /** * Safely executes a promise and handles any errors, returning an optional fallback value if the promise fails. * * @template TResult The type of the value that the promise resolves to * @template TFallback The type of the fallback value returned on failure * * @param promise The promise to execute * @param returnOnFail The value to return if the promise rejects * @param onCatch Optional callback to handle errors * * @returns A promise that resolves with either the result of the original promise or the fallback value */ export declare function runSave<TResult, TFallback = undefined>(promise: Promise<TResult>, returnOnFail?: TFallback, onCatch?: (error: unknown) => void): Promise<TResult | TFallback>; /** * Evaluates the total pulses and the duration based on the data records. * This function calculates the total number of pulses (revolutions) considering possible sensor resets * and the time span between the first and last record. * * @param data An array of data records containing the value and timestamp of each record. * @returns An object with the total pulses and the duration in seconds. */ export declare function getTotalPulses(data: DataRecord<number>[]): { pulses: number; timeSpan: number; }; /** * Calculates the maximum rate of increase between consecutive data records. * This function identifies the maximum rate of increase (pulses per second) between any two consecutive records, * along with the step (number of pulses) and time span (in seconds) for that maximum rate. * * @param data An array of data records containing the value and timestamp of each record. * @returns An object with the maximum rate of increase, the corresponding step, and time span. */ export declare function getMaxIncreaseRate(data: DataRecord<number>[]): { rate: number; step: number; timeSpan: number; };