这不是一个问题,而是一个问题。有没有办法一次从所有三个传感器(加速计、陀螺仪、磁力计)获取数据,或者只需为所有三个传感器设置相同的更新间隔即可。像这样
setUpdateIntervalForType(SensorTypes.accelerometer, 100); setUpdateIntervalForType(SensorTypes.magenetometer, 100); setUpdateIntervalForType(SensorTypes.gyroscope, 100);
const subscription = accelerometer.subscribe(({ x, y, z, timestamp }) => console.log({ x, y, z, timestamp }) );
const subscription1 = gyroscope.subscribe(({ x, y, z, timestamp }) => console.log({ x, y, z, timestamp }) );
const subscription2 = magenetometer.subscribe(({ x, y, z, timestamp }) => console.log({ x, y, z, timestamp }) );发布于 2019-06-06 01:24:08
是的,这些是RxJS可观察到的,它们允许组合。
假设您希望得到这样的响应:
{
accelerometer: {x,y,z,timestamp},
gyroscope: {x,y,z,timestamp},
magnetometer: {x,y,z,timestamp}
}如果你有所有的数据,而不是部分数据,你只想在这个可观察的对象上发射。
实现如下所示:
import {
combineLatest
} from "rxjs";
import {
map
} from 'rxjs/operators';
import {
accelerometer,
magnetometer,
gyroscope
} from "react-native-sensors";
const combinedStream = combineLatest(
accelerometer,
magnetometer,
gyroscope
).pipe(
map(([accelerometerValue, magnetometerValue, gyroscopeValue]) => ({
accelerometer: accelerometerValue,
magnetometer: magnetometerValue,
gyroscope: gyroscopeValue
}))
)
https://stackoverflow.com/questions/56372582
复制相似问题