Barometer API
Variable: Barometer
Type: [IBarometer | undefined]
Interface: IBarometer
The Barometer API provides access to the atmospheric pressure data measured by the hardware sensor.
Atmospheric pressure varies with elevation, so a barometer can be used to simulate an altimeter.
Read the Barometer Sensor Guide for further information.
import { Barometer } from "barometer";
if (Barometer) {
console.log("This device has a Barometer!");
const barometer = new Barometer({ frequency: 1 });
barometer.addEventListener("reading", () => {
console.log(`Pressure: ${barometer.pressure} Pa`);
});
barometer.start();
} else {
console.log("This device does NOT have a Barometer!");
}
Properties
readonly activated
boolean
Flag that indicates if the sensor is activated or not. When a sensor
is created, the sensor is not activated, thus the initial value of
this property equals false
.
onactivate
((this: Sensor, event: Event) => any) or undefined
Event handler that is called when the sensor is activated.
onerror
((this: Sensor, event: SensorErrorEvent) => any) or undefined
Event handler that is called when an error occurs. When an error
occurs, the sensor is automatically stopped, and the activated
property equals false
.
onreading
((this: Sensor, event: Event) => any) or undefined
Event handler that is called whenever a new reading is available.
readonly readings
BatchedBarometerReading or undefined
New in SDK 2.0
Interface: BatchedBarometerReading
New in SDK 2.0
Properties
readonly pressure
Float32Array
readonly timestamp
Uint32Array
Interface: BarometerReading
Atmospheric pressure reading from the barometer sensor.
Properties
readonly pressure
number or null
Atmospheric pressure, in Pascal units (Pa).
readonly timestamp
number or null
Timestamp of the reading in milliseconds.
NOTE: this is relative to an unspecified arbitrary
0
time, ornull
if no reading is available (when the sensor is not yet activated and there are no valid cached values that can be used).