import { Barometer } from 'barometer' ; if ( Barometer ) { let bar = new Barometer ( { frequency : 1 , batch : 10 } ) ; bar . onreading = function ( ) { console . log ( 'ts:' , bar . timestamp , 'pressure:' , parseInt ( bar . pressure ) + ' Pa' ) ; } ; bar . start ( ) ; const approxFloorPa = 36.62293100066991 ; let currentFloorPa = 0 ; let floorCounter = 0 ; bar . onreading = function ( ) { if ( currentFloorPa !== 0 ) { let diffPa = currentFloorPa - bar . pressure ; console . log ( 'Difference: ' + diffPa + ' Pa' ) ; if ( Math . abs ( diffPa ) > approxFloorPa ) { console . log ( 'Floor change detected' ) ; if ( bar . pressure > currentFloorPa ) { console . log ( 'User went downwards' ) ; } else { console . log ( 'User went upwards' ) ; } currentFloorPa = bar . pressure ; floorCounter ++ ; console . log ( 'Floors completed: ' + floorCounter ) ; } } else { currentFloorPa = bar . pressure ; } } ; bar . start ( ) ; bar = new Barometer ( { frequency : 1 , batch : 60 } ) ; bar . onreading = ( ) => { for ( let index = 0 ; index < bar . readings . timestamp . length ; index ++ ) { console . log ( `Barometer Reading: \
        timestamp=${ bar . readings . timestamp [ index ] }, \
        [${ bar . readings . pressure [ index ] }]` ) ; } } ; bar . start ( ) ; bar . stop ( ) ; }