UNPKG

jvsveml6070

Version:

Node.js package for the Vishay VEML6070 UVA Light Sensor, written in TypeScript.

193 lines (192 loc) 6.25 kB
import { IntegrationTime, SensorValue } from './module'; import { I2CBusState, SensorState, ShutdownMode, IntegrationTime as IntegrationTimeEnum, AcknowledgeMode, AcknowledgeThreshold } from './enums/module'; export declare class Sensor { /** * The I2C bus number. */ i2cBusNr: number; /** * The RSET value (in kΩ), which is used to determine the sensor's refresh time. */ rSet: number; /** * The internal `CommandRegister` instance. */ private _commandRegister; /** * The sensor state. */ private _state; /** * The I2C bus. */ private _i2cBus; /** * The I2C bus state. */ private _i2cBusState; /** * Creates a new `Sensor` instance. * * @param i2cBusNr - The I2C bus number. Defaults to 1. * @param rSet - The RSET value (in kΩ), which is used to determine the sensor's refresh time. Defaults to 270 kΩ. */ constructor(i2cBusNr?: number, rSet?: number); /** * Creates a new `Sensor` instance and enables the sensor. * * @param i2cBusNr - The I2C bus number. Defaults to 1. * @param rSet - The RSET value (in kΩ), which is used to determine the sensor's refresh time. Defaults to 270 kΩ. * * @returns A `Promise` that resolves when the sensor has been enabled. */ static initialize(i2cBusNr?: number, rSet?: number): Promise<Sensor>; /** * Retrieves the I2C bus state. * * @returns The `I2CBusState` enumeration value. */ getI2cBusState(): I2CBusState; /** * Retrieves the sensor's state. * * @returns The `SensorState` enumeration value. */ getState(): SensorState; /** * Enables the sensor. * * @returns A `Promise` that resolves when the sensor has been initialized. */ enable(): Promise<void>; /** * Disables the sensor. * * @returns A `Promise` that resolves when the sensor has been shut down and all resources have been freed up. */ disable(): Promise<void>; /** * Retrieves the shutdown mode. * * @returns The `ShutdownMode` enumeration value. */ getShutdownMode(): ShutdownMode; /** * Sets the shutdown mode. * * @param shutdownMode - A `ShutdownMode` enumeration value. * * @returns A `Promise` that resolves when the shutdown mode has been set. */ setShutdownMode(shutdownMode: ShutdownMode): Promise<void>; /** * Retrieves the integration time. * * @returns An `IntegrationTime` instance. */ getIntegrationTime(): IntegrationTime; /** * Sets the integration time. * * @param integrationTime - An `IntegrationTime` enumeration value. * * @returns A `Promise` that resolves when the integration time has been set. */ setIntegrationTime(integrationTime: IntegrationTimeEnum): Promise<void>; /** * Retrieves the refresh time. * * @returns The refresh time in milliseconds. */ getRefreshTime(): number; /** * Retrieves the acknowledge mode. * * @returns The `AcknowledgeMode` enumeration value. */ getAcknowledgeMode(): AcknowledgeMode; /** * Sets the acknowledge mode. * * @param ackMode - An `AcknowledgeMode` enumeration value. * * @returns A `Promise` that resolves when the acknowledge mode has been set. */ setAcknowledgeMode(ackMode: AcknowledgeMode): Promise<void>; /** * Retrieves the acknowledge threshold. * * @returns The `AcknowledgeThreshold` enumeration value. */ getAcknowledgeThreshold(): AcknowledgeThreshold; /** * Sets the acknowledge threshold. * * @param ackThreshold - An `AcknowledgeThreshold` enumeration value. * * @returns A `Promise` that resolves when the acknowledge threshold has been set. */ setAcknowledgeThreshold(ackThreshold: AcknowledgeThreshold): Promise<void>; /** * Sets the acknowledge mode and/or threshold. * * @param ackMode - An optional `AcknowledgeMode` enumeration value. * @param ackThreshold - An optional `AcknowledgeThreshold` enumeration value. * * @returns A `Promise` that resolves when the acknowledge mode and/or threshold have been set. */ setAcknowledge(ackMode?: AcknowledgeMode, ackThreshold?: AcknowledgeThreshold): Promise<void>; /** * Clears the ACK state. * * @param ignoreError - A `boolean` value that determines whether the returned `Promise` resolves even on error. * Defaults to `true` because the Alert Response Address seems to be never valid. This seems to * be an error in the datasheet. * * @returns A `Promise` that resolves when the ACK state has been cleared. */ clearAckState(ignoreError?: boolean): Promise<void>; /** * Reads the value. * * @returns - A `Promise` that resolves when the value has been read. */ read(): Promise<SensorValue>; /** * Checks the I2C bus state. * * @param expectedState - The expected `I2CBusState` enumeration value. * * @returns A `Promise` that resolves when the state is as expected. */ private _checkI2cBusState; /** * Opens the I2C bus. * * @returns A `Promise` that resolves when the I2C bus has been opened. */ private _openI2cBus; /** * Closes the I2C bus. * * @returns A `Promise` that resolves when the I2C bus has been closed. */ private _closeI2cBus; /** * Checks the sensor's state. * * @param expectedState - The expected `SensorState` enumeration value. * * @returns A `Promise` that resolves when the state is as expected. */ private _checkState; /** * Updates the sensor's command register. * On success, the internal `CommandRegister` instance is updated. * * @param commandRegister - The `CommandRegister` instance containing the data to write. * * @returns A `Promise` that resolves when the sensor's command register has been updated. */ private _updateCommandRegister; }