in src/sensors/gyroscope.ts [66:96]
async run() {
if (this.simulated) {
const intId = setInterval(
function (this: Gyroscope) {
this.emit(DATA_AVAILABLE_EVENT, this.id, {
x: getRandom(),
y: getRandom(),
z: getRandom(),
});
}.bind(this),
this.interval,
);
this.currentRun = {
unsubscribe: () => {
clearInterval(intId);
},
};
} else {
this.currentRun = gyroscope.subscribe(
function (this: Gyroscope, {x, y, z}: Vector) {
this.emit(DATA_AVAILABLE_EVENT, this.id, {x, y, z});
}.bind(this),
function (this: Gyroscope, error: any) {
if (error) {
this.enable(false);
this.emit(SENSOR_UNAVAILABLE_EVENT, this.id);
}
}.bind(this),
);
}
}