获取传感器温湿度得到的数值非常小10的负14次方
·
查看驱动上报值30左右,前端hap数值非常小,请教一下这个是什么原因呢?
前端代码:
//读取传感器返回值
aboutToAppear() {
this.callback = (data)=>{
console.log('sensor.on receive: ' + JSON.stringify(data))
let ppp = data
this.sss = "温度"+JSON.stringify(ppp)
}
this.callback1 = (value)=>{
console.log('sensor.on receive: ' + JSON.stringify(value))
let qqq = value
this.zzz = "湿度"+JSON.stringify(qqq)
}
}
@Styles pressedStyles() {
.backgroundColor(Color.Gray)
}
@Styles normalStyles() {
.backgroundColor(Color.White)
}
build() {
Column() {
Column() {
Text('温度数值')
.margin({ top: 40 })
.fontSize(20)
Progress({ value: this.progress, type: ProgressType.Linear })
.margin({ top: 10 })
Text(this.sss)
.fontSize(20)
Text(this.zzz)
.fontSize(20)
Text('开始监听')
.textAlign(TextAlign.Center)
.fontSize(20)
.margin({ top: 40 })
.padding({ top: 12, bottom: 12 })
.borderWidth(1)
.stateStyles({
pressed: this.pressedStyles,
normal: this.normalStyles,
clicked: this.pressedStyles
})
.width('100%')
.onClick(() => {
//循环调用温湿度获取其值
let timer: number = 0
clearInterval(timer)
this.timer = setInterval(() => {
try {
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, this.callback);
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY ,this.callback1);
} catch (err) {
console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
}, 1000)
})
更多推荐
所有评论(0)