06 手机陀螺仪模块 - MiEcosystem/miot-plugin-sdk GitHub Wiki
手机的陀螺仪
Export: public
Doc_name: 手机陀螺仪模块
Doc_index: 6
Doc_directory: system
Example
import {System} from "miot"
import {CompassChangeEvent} from "miot"
...
System.gyroscope.startGyroscope(//interval).then(() => {
alert(`startGyroscope: ${ JSON.stringify(res) }`);
})
...
System.gyroscope.stopGyroscope().then(() => {})
...
-
miot/system
-
static
-
.GyroscopeChangeEvent ⇒
object
-
.GyroscopeChangeEvent ⇒
-
inner
-
~IGyroscope
-
.startGyroscope(interval) ⇒
[ 'Promise' ].<json>
-
.stopGyroscope() ⇒
[ 'Promise' ].<json>
-
.startGyroscope(interval) ⇒
-
~IGyroscope
-
static
监听陀螺仪数据变化事件。频率根据 wx.startGyroscope() 的 interval 参数。可以使用 wx.stopGyroscope() 停止监听。
Kind: static constant of miot/system
Returns: object
- result 包含X、Y、Z轴的角速度
Since: 10043
Example
GyroscopeChangeEvent.onGyroscopeChange.addListener((result) => {
console.log(result);
});
Kind: inner interface of miot/system
-
~IGyroscope
-
.startGyroscope(interval) ⇒
[ 'Promise' ].<json>
-
.stopGyroscope() ⇒
[ 'Promise' ].<json>
-
.startGyroscope(interval) ⇒
开始监听陀螺仪数据
Kind: instance method of IGyroscope
Returns: [ 'Promise' ].<json>
- 成功时:{code:0,message:'success'}
Since: 10043
Param | Type | Description |
---|---|---|
interval | string |
监听陀螺仪数据回调函数的执行频率。其合法值如下: game 适用于更新游戏的回调频率,在 20ms/次 左右; ui 适用于更新 UI 的回调频率,在 60ms/次 左右; normal 普通的回调频率,在 200ms/次 左右。 |
Example
System.gyroscope.startGyroscope(interval.c).then((res) => {
alert(`startGyroscope: ${ JSON.stringify(res) }`);
}).catch((error) => {
console.log(error);
});
停止监听陀螺仪数据
Kind: instance method of IGyroscope
Returns: [ 'Promise' ].<json>
- 成功时:{code:0,message:'success'}
Since: 10043
Example
System.gyroscope.stopGyroscope().then((res) => {
alert(`stopGyroscope: ${ JSON.stringify(res) }`);
}).catch((error) => {
console.log(error);
});
}