当前位置:   article > 正文

华为手表开发:WATCH 3 Pro(16)传感器订阅气压_华为手表气压单位改成千帕

华为手表气压单位改成千帕

希望能写一些简单的教程和案例分享给需要的人

鸿蒙可穿戴开发

环境与设备

系统:window
设备:HUAWEI WATCH 3 Pro New
开发工具:DevEco Studio 3.0.0.800

气压传感器介绍与说明

Barometer(气压计)是一种用于测量大气压力的仪器。它可以通过测量气体或液体在一个封闭容器中的压力变化来确定大气压力的变化。Barometer广泛应用于气象学、气候预测、航空航天、海洋学、地理学等领域,以及日常生活中的天气观测。

气压传感器通常使用百帕斯卡(hPa,也可以表示为mbar,即毫巴)作为单位来表示气压值。百帕斯卡是一种国际单位制(SI)中的压力单位,定义为100帕斯卡(Pa)。在大气科学和气象学中,常常使用百帕斯卡作为气压的单位,用于表示大气中的压强。在传感器技术中,例如气压传感器、高度传感器等应用中,常常使用百帕斯卡作为标准单位来表示气压值。

手表获取到的单位是百帕斯卡(毫巴)

鸿蒙开发

文件夹:

entry:项目文件夹
js:前端文件夹
pages:页面文件夹
index:首页文件夹

文件

index.css:首页样式
index.hml:首页
index.js:首页脚本
config.json:配置文件

新增展示的文本标记

代码如下:

index.hml
<div class="container">
    <text class="title">
        气压 :{{ barometer }} 毫巴
    </text>
</div>


  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
index.css

.container {
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
}

.title {
    font-size: 40px;
    color: #000000;
    opacity: 0.9;
}

@media screen and (device-type: wearable) {
    .title {
        font-size: 20px;
        color: #FFFFFF;
    }
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
index.js

导入功能包:system.sensor
import sensor from ‘@system.sensor’;


import sensor from '@system.sensor';

export default {
    data: {
        barometer: "",
    },
    onInit() {
        let currJS = this;
        sensor.subscribeBarometer({
            success: function (data) {
                console.info('dao::接收到气压传感器数据:' + JSON.stringify(data));
                // 保留两位
                currJS.barometer = data.pressure.toFixed(2);
            },
            fail: function (data, code) {
                console.info('dao::气压报错 failed. Code: ' + code + '; Data: ' + data);
            },
        });
    }
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

在这里插入图片描述

在这里插入图片描述

需要 demo(代码) 的留下邮箱,或者留言提需要什么样的 demo

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/311497
推荐阅读
相关标签
  

闽ICP备14008679号