in src/sensors/accelerometer.ts [82:117]
async run() {
if (this.simulated) {
const intId = setInterval(
function (this: Accelerometer) {
this.emit(DATA_AVAILABLE_EVENT, this.id, {
// Make limits +-2g
x: getRandom(-19.62, 19.62),
y: getRandom(-19.62, 19.62),
z: getRandom(-19.62, 19.62),
});
}.bind(this),
this.interval,
);
this.currentRun = {
unsubscribe: () => {
clearInterval(intId);
},
};
} else {
this.currentRun = accelerometer.subscribe(
function (this: Accelerometer, {x, y, z}: Vector) {
this.emit(
DATA_AVAILABLE_EVENT,
this.id,
this.getNormalizedData(x, y, z),
);
}.bind(this),
function (this: Accelerometer, error: any) {
if (error) {
this.enable(false);
this.emit(SENSOR_UNAVAILABLE_EVENT, this.id);
}
}.bind(this),
);
}
}