智能照明系统APP-本地串口
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
LightingSystemApp-serial/.svn/pristine/a6/a62058e270c01faf35681a678b2...

49 lines
805 B

3 years ago
import {
invoke
} from 'uni-core/service/bridge'
import {
onMethod,
invokeMethod
} from '../../platform'
const callbacks = []
onMethod('onCompassChange', function (res) {
callbacks.forEach(callbackId => {
invoke(callbackId, res)
})
})
let isEnable = false
/**
* 监听加速度
* @param {*} callbackId
*/
export function onCompassChange (callbackId) {
// TODO 当没有 start 时,添加 on 需要主动 start?
callbacks.push(callbackId)
if (!isEnable) {
startCompass()
}
}
export function startCompass ({
interval // TODO
} = {}) {
if (isEnable) {
return
}
isEnable = true
return invokeMethod('enableCompass', {
enable: true
})
}
export function stopCompass () {
isEnable = false
return invokeMethod('enableCompass', {
enable: false
})
}