> 文章列表 > 华为手表开发:WATCH 3 Pro(19)传感器订阅 光线传感器

华为手表开发:WATCH 3 Pro(19)传感器订阅 光线传感器

华为手表开发:WATCH 3 Pro(19)传感器订阅 光线传感器

华为手表开发:WATCH 3 Pro(19)传感器订阅 光线传感器

  • 环境与设备
      • 光线传感器
    • 鸿蒙开发
      • 文件夹:
      • 文件
      • 新增展示的文本标记
        • index.hml
        • index.css
        • index.js

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

鸿蒙可穿戴开发

环境与设备

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

光线传感器

光线传感器是一种用于测量环境光照强度的传感器

鸿蒙开发

文件夹:

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

文件

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

新增展示的文本标记

代码如下:

index.hml

<div class="container"><text class="title">光照强度 :{{ intensity }} Lux</text>
</div>

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;}
}

index.js

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

import sensor from '@system.sensor';export default {data: {intensity: "",},onInit() {let currJS = this;sensor.subscribeLight({success: function (data) {console.info('dao::接收到光线传感器数据:' + JSON.stringify(data));currJS.intensity = data.intensity;},fail: function (data, code) {console.info('dao::光线传感器报错 failed. Code: ' + code + '; Data: ' + data);},});}
}

在光线传感器中,“intensity”(强度)通常指的是测量到的光照强度值,通常以勒克斯(Lux)为单位表示。

光照强度是指单位面积上每秒接收到的光的流量,通常用勒克斯来衡量。光线传感器通过测量环境中光的强度,并将其转换为勒克斯的数值来表示当前环境的光照强度。光线传感器的输出值或返回值中的"intensity" 通常是一个数字,表示当前环境的光照强度水平。较小的数值表示较暗的环境,而较大的数值表示较亮的环境。

华为手表开发:WATCH 3 Pro(19)传感器订阅 光线传感器

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