From f1cf235613ecb5e40500c3a4216ac107c591f564 Mon Sep 17 00:00:00 2001 From: cff Date: Wed, 8 Nov 2023 10:00:40 +0000 Subject: [PATCH 1/5] =?UTF-8?q?sensor=20capi=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cff --- README.en.md | 2 + README.md | 2 + sensors/sensor/BUILD.gn | 31 ++ sensors/sensor/include/sensor_capi.h | 89 ++++ sensors/sensor/include/sensor_capi_base.h | 502 ++++++++++++++++++++++ sensors/sensor/libsensor_capi.ndk.json | 11 + 6 files changed, 637 insertions(+) create mode 100644 sensors/sensor/BUILD.gn create mode 100644 sensors/sensor/include/sensor_capi.h create mode 100644 sensors/sensor/include/sensor_capi_base.h create mode 100644 sensors/sensor/libsensor_capi.ndk.json diff --git a/README.en.md b/README.en.md index 4559b64dd9..0c3af2fd57 100644 --- a/README.en.md +++ b/README.en.md @@ -37,6 +37,8 @@ This repository is used to store .h declaration files of C APIs. The OpenHarmony | ├─ffrt ├─security | ├─huks + ├─sensors + | ├─sensor ├─startup | ├─init ├─third_party diff --git a/README.md b/README.md index 959da5d1f1..8ff8d5939b 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,8 @@ | ├─ffrt ├─security | ├─huks +├─sensors +| ├─sensor ├─startup | ├─init ├─third_party diff --git a/sensors/sensor/BUILD.gn b/sensors/sensor/BUILD.gn new file mode 100644 index 0000000000..6ecc8ae6cd --- /dev/null +++ b/sensors/sensor/BUILD.gn @@ -0,0 +1,31 @@ +# Copyright (C) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//build/ohos/ndk/ndk.gni") +import("./../../../sensor.gni") + +ohos_ndk_headers("sensor_capi_header") { + dest_dir = "$ndk_headers_out_dir/sensor_capi" + sources = [ + "./include/sensor_capi.h", + "./include/sensor_capi_base.h", + ] +} + +ohos_ndk_library("libsensor_capi_ndk") { + ndk_description_file = "./libsensor_capi.ndk.json" + output_name = "sensor_capi_ndk" + output_extension = "z.so" + min_compact_version = "10" +} diff --git a/sensors/sensor/include/sensor_capi.h b/sensors/sensor/include/sensor_capi.h new file mode 100644 index 0000000000..db1eb3d7a4 --- /dev/null +++ b/sensors/sensor/include/sensor_capi.h @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup 传感器 + * @{ + * + * @brief 为您提供标准的开放api,以使用传感器的常用功能。 + * + * 例如,您可以调用这些api来获取传感器属性信息、订阅或取消订阅传感器数据等。 + * @since 11 + */ + +/** + * @file sensor_capi.h + * + * @brief 声明操作传感器的常用api,用于获取传感器信息、订阅或取消订阅传感器数据等。 + * @library 引用sensor_capi_base.h,链接生成libsensor_capi_ndk.so。 + * @syscap SystemCapability.Sensors.Sensor + * @since 11 + */ + +#ifndef SENSOR_CAPI_H +#define SENSOR_CAPI_H + +#include + +#include "sensor_capi_base.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief 获取设备上的所有传感器信息。 + * + * @param sensorInfo 设备上的所有传感器信息, + * 详情请参见{@Link Sensor_SensorInfo}。 + * @param count 设备上的传感器数量。 + * @return 获取传感器信息成功返回SENSOR_SUCCESS,否则返回对应的错误码, + * 详情请参见{@Link Sensor_Result}。 + * + * @since 11 + */ +Sensor_Result OH_Sensor_GetAllSensors(Sensor_SensorInfo **sensorMessage, int32_t *count); + +/** + * @brief 订阅传感器数据,系统将按照用户指定的上报频率向用户报告传感器数据。 + * + * @param id 传感器类型, 详情请参见{@link Sensor_SubscribeId}。 + * @param attribute 订阅属性,用于指定传感器的上报频率,详情请参见{@Link Sensor_SubscribeAttribute}。 + * @param user 订阅者信息,指定传感器数据回调函数,详情请参见{@Link Sensor_SubscribeUser}。 + * @return 订阅传感器成功返回SENSOR_SUCCESS,否则返回对应的错误码, + * 详情请参见{@Link Sensor_Result}。 + * + * @since 11 + */ +Sensor_Result OH_Sensor_SubscribeSensor(Sensor_SubscribeId subscribeId, Sensor_SubscribeAttribute attribute, + const Sensor_SubscribeUser *cb); + +/** + * @brief 取消订阅传感器数据。 + * + * @param id 传感器类型, 详情请参见{@link Sensor_SubscribeId}。 + * @param user 订阅者信息,指定传感器数据回调函数, + * 详情请参见{@Link Sensor_SubscribeUser}。 + * @return 取消订阅传感器成功返回SENSOR_SUCCESS,否则返回对应的错误码, + * 详情请参见{@Link Sensor_Result}。 + * + * @since 11 + */ +Sensor_Result OH_Sensor_UnsubscribeSensor(Sensor_SubscribeId subscribeId, const Sensor_SubscribeUser *cb); + +#ifdef __cplusplus +} +#endif +#endif // SENSOR_CAPI_H \ No newline at end of file diff --git a/sensors/sensor/include/sensor_capi_base.h b/sensors/sensor/include/sensor_capi_base.h new file mode 100644 index 0000000000..eabdebe4f2 --- /dev/null +++ b/sensors/sensor/include/sensor_capi_base.h @@ -0,0 +1,502 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup 传感器 + * @{ + * + * @brief 为您提供标准的开放api,定义常用传感器属性。 + * + * @since 11 + */ + +/** + * @file sensor_capi_base.h + * + * @brief 定义常用传感器属性。 + * @library 需要链接生成libsensor_capi_ndk.so。 + * @syscap SystemCapability.Sensors.Sensor + * + * @since 11 + */ +#ifndef SENSOR_CAPI_BASE_H +#define SENSOR_CAPI_BASE_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif +/** 传感器名称的最大长度 */ +#ifndef NAME_MAX_LEN +#define NAME_MAX_LEN 128 +#endif /* NAME_MAX_LEN */ +/** 传感器数据大小 */ +#ifndef SENSOR_USER_DATA_SIZE +#define SENSOR_USER_DATA_SIZE 104 +#endif /* SENSOR_USER_DATA_SIZE */ +/** 传感器版本的最大长度 */ +#ifndef VERSION_MAX_LEN +#define VERSION_MAX_LEN 16 +#endif /* SENSOR_USER_DATA_SIZE */ +/** 分布式组网最大长度 */ +#ifndef NETWORK_ID_MAX_LEN +#define NETWORK_ID_MAX_LEN 96 +#endif /* NETWORK_ID_MAX_LEN */ +/** + * @brief 传感器类型。 + * + * @since 11 + */ +typedef enum Sensor_SensorTypeId { + INVALID = -1, + ACCELEROMETER = 1, /**< 加速度传感器 */ + GYROSCOPE = 2, /**< 陀螺仪传感测器 */ + AMBIENT_LIGHT = 5, /**< 环境光传感器 */ + MAGNETIC_FIELD = 6, /**< 地磁传感器 */ + BAROMETER = 8, /**< 气压计传感器 */ + HALL = 10, /**< 霍尔传感器 */ + PROXIMITY = 12, /**< 接近光传感器 */ + HUMIDITY = 13, /**< 湿度传感器 */ + COLOR = 14, /**< 颜色传感器 */ + SAR = 15, /**< 吸收比率传感器 */ + ORIENTATION = 256, /**< 方向传感器 */ + GRAVITY = 257, /**< 重力传感器 */ + LINEAR_ACCELEROMETER = 258, /**< 线性加速度传感器 */ + ROTATION_VECTOR = 259, /**< 旋转矢量传感器 */ + AMBIENT_TEMPERATURE = 260, /**< 温度传感器 */ + MAGNETIC_FIELD_UNCALIBRATED = 261, /**< 未校准地磁传感器 */ + GYROSCOPE_UNCALIBRATED = 263, /**< 未校准陀螺仪传感器 */ + SIGNIFICANT_MOTION = 264, /**< 大幅动作检测传感器 */ + PEDOMETER_DETECTION = 265, /**< 计步器检测传感器 */ + PEDOMETER = 266, /**< 计步器传感器 */ + HEART_RATE = 278, /**< 心率传感器 */ + WEAR_DETECTION = 280, /**< 佩戴检测传感器 */ + ACCELEROMETER_UNCALIBRATED = 281, /**< 未校准加速度传感器 */ +} Sensor_SensorTypeId; + +/** + * @brief 定义传感器操作错误码。 + * + * @since 11 + */ +typedef enum Sensor_Result { + SENSOR_SUCCESS = 0, /**< 操作成功时返回该值 */ + SENSOR_PERMISSION_DENIED = 201, /**< 当权限被拒绝时使用此错误代码 */ + SENSOR_PARAMETER_ERROR = 401, /**< 当输入参数类型或范围不匹配时使用此错误代码 */ + SENSOR_SERVICE_EXCEPTION = 14500101, /**< 当服务异常时使用此错误代码 */ +} Sensor_Result; + +/** + * @brief 传感器属性信息。 + * + * @since 11 + */ +typedef struct Sensor_SensorInfo { + char sensorName[NAME_MAX_LEN]; /**< 传感器名字 */ + char vendorName[NAME_MAX_LEN]; /**< 传感器供应商 */ + char firmwareVersion[VERSION_MAX_LEN]; /**< 传感器固件版本 */ + char hardwareVersion[VERSION_MAX_LEN]; /**< 传感器硬件版本 */ + int32_t sensorTypeId; /**< 传感器类型 ID */ + int32_t sensorId; /**< 传感器 ID */ + int32_t index; /**< 传感器编号,表示同类传感器的第几个器件,从0开始,默认是0, 0表示默认器件(主传感器)*/ + float maxRange; /**< 传感器的最大测量范围 */ + float precision; /**< 传感器精度 */ + float power; /**< 传感器功率 */ + int64_t minSamplePeriod; /**< 允许的最小采样周期,以纳秒为单位 */ + int64_t maxSamplePeriod; /**< 允许的最大采样周期,以纳秒为单位 */ +} Sensor_SensorInfo; + +/** + * @brief 列举传感器的数据报告模式。 + * + * @since 11 + */ +typedef enum Sensor_SensorMode { + DEFAULT_MODE = 0, /**< 默认数据报告模式 */ + REALTIME_MODE = 1, /**< 实时数据上报模式,每次上报一组数据 */ + ON_CHANGE = 2, /**< 数据实时上报模式,在状态发生变化时上报数据 */ + ONE_SHOT = 3, /**< 数据实时上报模式,只上报一次数据 */ + FIFO_MODE = 4, /**< 基于fifo的数据上报模式,根据BatchCnt设置上报数据 */ + MODE_MAX2, /**< 最大传感器数据上报模式 */ +} Sensor_SensorMode; + +/** + * @brief 上报的传感器数据信息。 + * + * @since 11 + */ +typedef struct Sensor_SensorEvent { + int32_t sensorTypeId; /**< 传感器类型 ID */ + int32_t version; /**< 传感器算法版本 */ + int64_t timestamp; /**< 报告传感器数据的时间 */ + int32_t option; /**< 传感器数据选项,包括测量范围和精度 */ + int32_t mode; /**< 传感器数据上报方式 (详细参考{@link Sensor_SensorMode}) */ + uint8_t *data = nullptr; /**< 传感器数据 */ + uint32_t dataLen; /**< 传感器数据长度 */ +} Sensor_SensorEvent; + +/** + * @brief 列举传感器的数据报告模式。 + * + * @since 11 + */ +typedef struct Sensor_SubscribeId { + Sensor_SensorTypeId sensorTypeId; /**< 用于报告传感器的类型 */ + int32_t sensorIndex; // 表示同类型的第几个传感器,0表示默认值 + int32_t sensorId; // 表示同类型的第几个传感器,0表示默认值 + char networkId[NETWORK_ID_MAX_LEN]; // 分布式设备的networkId,默认值 "local",用户什么都不传或者用户主动传了"local",都都表示本地设备 + // 只有用户主动传其他设备的networkId,才订阅分布式设备 + //暂时的实现上,我们在cpp里直接把这个字段里先忽略掉 + // 上接口时,在注释上得说明一下,networkID是预留字段,暂无实现 +} Sensor_SubscribeId; + +/** + * @brief 传感器订阅属性。 + * + * @since 11 + */ +typedef struct Sensor_SubscribeAttribute { + int64_t samplingInterval; /**< 传感器采样周期 */ + int64_t reportInterval; /**< 传感器上报频率 */ +} Sensor_SubscribeAttribute; + +/** + * @brief 定义传感器代理报告数据的回调。 + * + * @since 11 + */ +typedef void (*Sensor_RecordSensorCallback)(Sensor_SensorEvent *event); + +/** + * @brief 为传感器数据订阅者定义保留字段。 + * + * @since 11 + */ +typedef struct Sensor_UserData { + char userData[SENSOR_USER_DATA_SIZE]; /**< 为传感器数据订阅者保留 */ +} Sensor_UserData; + +/** + * @brief 定义有关传感器数据订阅者的信息。 + * + * @since 11 + */ +typedef struct Sensor_SubscribeUser { + char name[NAME_MAX_LEN]; /**< 传感器数据订阅者的名称 */ + Sensor_RecordSensorCallback callback; /**< 用于报告传感器数据的回调 */ + Sensor_UserData *userData = nullptr; /**< 传感器数据订阅者的保留字段 */ +} Sensor_SubscribeUser; + +/** + * @brief 定义有关传感器数据精度的信息。 + * + * @since 11 + */ +typedef enum Sensor_SensorAccuracy { + UNRELIABLE = 0, /**< 传感器数据不可信 */ + LOW = 1, /**< 传感器数据精度较低 */ + MEDIUM = 2, /**< 传感器数据精度中等 */ + HIGH = 3, /**< 传感器数据高 */ +} Sensor_SensorAccuracy; + +/** + * @brief 加速度传感器数据格式, + * 设备在m/s2的三个物理轴(x、y、z)上。 + * + * @since 11 + */ +typedef struct Sensor_AccelerometerData { + float x; /**< 施加在设备x轴的加速度,单位 : m/s² */ + float y; /**< 施加在设备y轴的加速度,单位 : m/s² */ + float z; /**< 施加在设备z轴的加速度,单位 : m/s² */ +} Sensor_AccelerometerData; + +/** + * @brief 定义线性加速度计的数据结构。测量施加于的线性加速度 + * 设备在m/s2的三个物理轴(x、y、z)上。 + * + * @since 11 + */ +typedef struct Sensor_LinearAccelData { + float x; /**< 施加在设备x轴的线性加速度,单位 : m/s² */ + float y; /**< 施加在设备y轴的线性加速度,单位 : m/s² */ + float z; /**< 施加在设备z轴的线性加速度,单位 : m/s² */ +} Sensor_LinearAccelData; + +/** + * @brief 定义陀螺仪传感器数据结构。测量物体的旋转角速度 + * 三个物理轴(x, y和z)上的设备,单位为rad/s。 + * + * @since 11 + */ +typedef struct Sensor_GyroscopeData { + float x; /**< 设备x轴的旋转角速度,单位rad/s */ + float y; /**< 设备y轴的旋转角速度,单位rad/s */ + float z; /**< 设备z轴的旋转角速度,单位rad/s */ +} Sensor_GyroscopeData; + +/** + * @brief 定义重力传感器数据结构。测量重力加速度 + * 在m/s2的三个物理轴(x, y和z)上到设备。 + * + * @since 11 + */ +typedef struct Sensor_GravityData { + float x; /**< 施加在设备x轴的重力加速度,单位 : m/s² */ + float y; /**< 施加在设备y轴的重力加速度,单位 : m/s² */ + float z; /**< 施加在设备z轴的重力加速度,单位 : m/s² */ +} Sensor_GravityData; + +/** + * @brief 定义未校准加速度计数据结构。测量应用于的未校准加速度计 + * 设备在m/s2的三个物理轴(x、y、z)上。 + * + * @since 11 + */ +typedef struct Sensor_AccelUncalibratedData { + float x; /**< 施加在设备x轴未校准的加速度,单位 : m/s² */ + float y; /**< 施加在设备y轴未校准的加速度,单位 : m/s² */ + float z; /**< 施加在设备z轴未校准的加速度,单位 : m/s² */ + float biasX; /**< 施加在设备x轴未校准的加速度偏量,单位 : m/s² */ + float biasY; /**< 施加在设备上y轴未校准的加速度偏量,单位 : m/s² */ + float biasZ; /**< 施加在设备z轴未校准的加速度偏量,单位 : m/s² */ +} Sensor_AccelUncalibratedData; + +/** + * @brief 定义未校准陀螺仪传感器数据结构。测量未校准的旋转角速度 + * 三个物理轴(x, y和z)上的设备,单位为rad/s。 + * + * @since 11 + */ +typedef struct Sensor_GyroUncalibratedData { + float x; /**< 设备x轴未校准的旋转角速度,单位rad/s */ + float y; /**< 设备y轴未校准的旋转角速度,单位rad/s */ + float z; /**< 设备z轴未校准的旋转角速度,单位rad/s */ + float biasX; /**< 设备x轴未校准的旋转角速度偏量,单位rad/s */ + float biasY; /**< 设备y轴未校准的旋转角速度偏量,单位rad/s */ + float biasZ; /**< 设备z轴未校准的旋转角速度偏量,单位rad/s */ +} Sensor_GyroUncalibratedData; + +/** + * @brief 定义大幅动作检测传感器数据结构。测量设备上是否有实质性的运动 + * 三个物理轴(x, y和z);值为1表示存在较大的运动;0表示这个值没有大的变动。 + * + * @since 11 + */ +typedef struct Sensor_SignificantMotionData { + float scalar; /**< 表示剧烈运动程度。如果取值为1则代表存在大幅度运动,取值为0则代表没有大幅度运动 */ +} Sensor_SignificantMotionData; + +/** + * @brief 定义计步器检测传感器数据结构。检测用户的计步动作;如果值为1, + * 它表示用户产生了计数行走的动作; 如果该值为0,则表示用户没有移动。 + * + * @since 11 + */ +typedef struct Sensor_PedometerDetectData { + float scalar; /**< 计步器检测状态,1表示有行走动作,0表示没有动作 */ +} Sensor_PedometerDetectData; + +/** + * @brief 定义计步器传感器数据结构。统计用户走过的步数。 + * + * @since 11 + */ +typedef struct Sensor_PedometerData { + float steps; /**< 用户的行走步数 */ +} Sensor_PedometerData; + +/** + * @brief 定义温度传感器数据结构。测量环境温度,单位为摄氏度。 + * + * @since 11 + */ +typedef struct Sensor_AmbientTemperatureData { + float temperature; /**< 环境温度,单位为摄氏度 */ +} Sensor_AmbientTemperatureData; + +/** + * @brief 定义颜色传感器数据结构。 + * + * @since 11 + */ +typedef struct Sensor_ColorData { + float lightIntensity; /**< 表示光的强度,单位 : 勒克斯 */ + float colorTemperature; /**< 表示色温,单位是开尔文(k) */ +} Sensor_ColorData; + +/** + * @brief 定义吸收比率传感器数据结构。 + * + * @since 11 + */ +typedef struct Sensor_SarData { + float absorptionRatio; /**< 表示具体的吸收率,单位 : W/kg */ +} Sensor_SarData; + +/** + * @brief 定义湿度传感器数据结构。测量环境的相对湿度,以百分比(%)表示。 + * + * @since 11 + */ +typedef struct Sensor_HumidityData { + float humidity; /**< 湿度值。测量环境的相对湿度,以百分比 (%) 表示 */ +} Sensor_HumidityData; + +/** + * @brief 定义温度传感器数据结构。测量环境的相对温度,单位为摄氏度。 + * + * @since 11 + */ +typedef struct Sensor_TemperatureData { + float temperature; /**< 显示环境温度,单位为摄氏度 */ +} Sensor_TemperatureData; + +/** + * @brief 定义地磁传感器数据结构。 + * 三次测量周围的地磁场物理轴(x, y, z),单位为μT。 + * + * @since 11 + */ +typedef struct Sensor_MagneticFieldData { + float x; /**< x轴环境磁场强度,单位 : μT */ + float y; /**< y轴环境磁场强度,单位 : μT */ + float z; /**< z轴环境磁场强度,单位 : μT */ +} Sensor_MagneticFieldData; + +/** + * @brief 义未校准地磁传感器数据结构。 + * 测量未校准的环境地磁场在三个物理轴(x, y, z)上以μT为单位。 + * + * @since 11 + */ +typedef struct Sensor_MagneticFieldUncalibratedData { + float x; /**< x轴未校准环境磁场强度,单位 : μT */ + float y; /**< y轴未校准环境磁场强度,单位 : μT */ + float z; /**< z轴未校准环境磁场强度,单位 : μT */ + float biasX; /**< x轴未校准环境磁场强度偏量,单位 : μT */ + float biasY; /**< y轴未校准环境磁场强度偏量,单位 : μT */ + float biasZ; /**< z轴未校准环境磁场强度偏量,单位 : μT */ +} Sensor_MagneticFieldUncalibratedData; + +/** + * @brief 定义气压计传感器数据结构。测量环境气压,单位:hPa或mbar。 + * + * @since 11 + */ +typedef struct Sensor_BarometerData { + float pressure; /**< 压力值,单位:帕斯卡 */ +} Sensor_BarometerData; + +/** + * @brief 定义设备方向传感器数据结构。测量设备的旋转方向,单位为rad。 + * + * @since 11 + */ +typedef struct Sensor_DeviceOrientationData { + float scalar; /**< 表示设备的方向 */ +} Sensor_DeviceOrientationData; + +/** + * @brief 定义方向传感器数据结构。 + * 测量设备围绕所有三个物理轴(z, x, y)旋转的角度值,单位为rad。 + * + * @since 11 + */ +typedef struct Sensor_OrientationData { + float alpha; /**< 设备围绕Z轴的旋转角度,单位:度 */ + float beta; /**< 设备围绕X轴的旋转角度,单位:度 */ + float gamma; /**< 设备围绕Y轴的旋转角度,单位:度 */ +} Sensor_OrientationData; + +/** + * @brief 定义旋转矢量传感器数据结构。测量设备游戏旋转矢量,复合传感器: + * 由加速度传感器、陀螺仪传感器合成。 + * + * @since 11 + */ +typedef struct Sensor_RotationVectorData { + float x; /**< 旋转矢量x轴分量 */ + float y; /**< 旋转矢量y轴分量 */ + float z; /**< 旋转矢量z轴分量 */ + float w; /**< 标量 */ +} Sensor_RotationVectorData; + +/** + * @brief 定义了地磁旋转矢量传感器的数据结构。 测量装置地磁旋转矢量,复合传感器: + * 由加速度传感器和磁场传感器合成。 + * + * @since 11 + */ +typedef struct Sensor_GeomagneticRotaVectorData { + float x; /**< 地磁旋转矢量x轴分量 */ + float y; /**< 地磁旋转矢量y轴分量 */ + float z; /**< 地磁旋转矢量z轴分量 */ + float w; /**< 标量 */ +} Sensor_GeomagneticRotaVectorData; + +/** + * @brief 定义接近光传感器数据结构。 测量相对于设备显示的可见物体的接近度或距离; + * 其中0表示接近,1表示距离。 + * + * @since 11 + */ +typedef struct Sensor_ProximityData { + float distance; /**< 可见物体与设备显示器的接近程度。0表示接近,1表示远离 */ +} Sensor_ProximityData; + +/** + * @brief 定义环境光传感器数据结构。以勒克斯为单位测量设备周围的光强度。 + * + * @since 11 + */ +typedef struct Sensor_AmbientLightData { + float intensity; /**< 表示光强度,单位为:勒克斯 */ +} Sensor_AmbientLightData; + +/** + * @brief 定义霍尔传感器数据结构。测量设备周围是否有磁力, + * 0表示没有磁力,1表示有磁力。 + * + * @since 11 + */ +typedef struct Sensor_HallData { + float status; /**< 显示霍尔状态。测量设备周围是否存在磁力吸引,0表示没有,大于0表示有 */ +} Sensor_HallData; + +/** + * @brief 定义心率传感器数据结构。测量用户的心率,以bpm为单位。 + * + * @since 11 + */ +typedef struct Sensor_HeartRateData { + float heartRate; /**< 心率值。测量用户的心率数值,单位:bpm */ +} Sensor_HeartRateData; + +/** + * @brief 定义佩戴检测传感器数据结构。表示设备是否被穿戴, + * 1表示已穿戴,0表示未穿戴。 + * + * @since 11 + */ +typedef struct Sensor_WearDetectionData { + float value; /**< 佩戴检测状态,穿戴为1,不穿戴为0 */ +} Sensor_WearDetectionData; + +#ifdef __cplusplus +} +#endif +#endif // SENSOR_CAPI_BASE_H \ No newline at end of file diff --git a/sensors/sensor/libsensor_capi.ndk.json b/sensors/sensor/libsensor_capi.ndk.json new file mode 100644 index 0000000000..dc53b9d067 --- /dev/null +++ b/sensors/sensor/libsensor_capi.ndk.json @@ -0,0 +1,11 @@ +[ + { + "name": "OH_Sensor_GetAllSensors" + }, + { + "name": "OH_Sensor_SubscribeSensor" + }, + { + "name": "OH_Sensor_UnsubscribeSensor" + } +] \ No newline at end of file -- Gitee From 22c4c850a1f9b7a133a8ab9636d9c99891774a3a Mon Sep 17 00:00:00 2001 From: cff Date: Thu, 9 Nov 2023 01:58:19 +0000 Subject: [PATCH 2/5] =?UTF-8?q?sensor=20capi=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cff --- sensors/sensor/BUILD.gn | 5 +- sensors/sensor/include/sensor_capi_base.h | 300 +++++++++------------- 2 files changed, 130 insertions(+), 175 deletions(-) diff --git a/sensors/sensor/BUILD.gn b/sensors/sensor/BUILD.gn index 6ecc8ae6cd..69f2ad927b 100644 --- a/sensors/sensor/BUILD.gn +++ b/sensors/sensor/BUILD.gn @@ -13,10 +13,9 @@ import("//build/ohos.gni") import("//build/ohos/ndk/ndk.gni") -import("./../../../sensor.gni") ohos_ndk_headers("sensor_capi_header") { - dest_dir = "$ndk_headers_out_dir/sensor_capi" + dest_dir = "$ndk_headers_out_dir/sensors/sensor" sources = [ "./include/sensor_capi.h", "./include/sensor_capi_base.h", @@ -27,5 +26,5 @@ ohos_ndk_library("libsensor_capi_ndk") { ndk_description_file = "./libsensor_capi.ndk.json" output_name = "sensor_capi_ndk" output_extension = "z.so" - min_compact_version = "10" + min_compact_version = "11" } diff --git a/sensors/sensor/include/sensor_capi_base.h b/sensors/sensor/include/sensor_capi_base.h index eabdebe4f2..1422d0d445 100644 --- a/sensors/sensor/include/sensor_capi_base.h +++ b/sensors/sensor/include/sensor_capi_base.h @@ -26,7 +26,6 @@ * @file sensor_capi_base.h * * @brief 定义常用传感器属性。 - * @library 需要链接生成libsensor_capi_ndk.so。 * @syscap SystemCapability.Sensors.Sensor * * @since 11 @@ -51,17 +50,13 @@ extern "C" { #ifndef VERSION_MAX_LEN #define VERSION_MAX_LEN 16 #endif /* SENSOR_USER_DATA_SIZE */ -/** 分布式组网最大长度 */ -#ifndef NETWORK_ID_MAX_LEN -#define NETWORK_ID_MAX_LEN 96 -#endif /* NETWORK_ID_MAX_LEN */ + /** * @brief 传感器类型。 * * @since 11 */ typedef enum Sensor_SensorTypeId { - INVALID = -1, ACCELEROMETER = 1, /**< 加速度传感器 */ GYROSCOPE = 2, /**< 陀螺仪传感测器 */ AMBIENT_LIGHT = 5, /**< 环境光传感器 */ @@ -110,7 +105,6 @@ typedef struct Sensor_SensorInfo { char firmwareVersion[VERSION_MAX_LEN]; /**< 传感器固件版本 */ char hardwareVersion[VERSION_MAX_LEN]; /**< 传感器硬件版本 */ int32_t sensorTypeId; /**< 传感器类型 ID */ - int32_t sensorId; /**< 传感器 ID */ int32_t index; /**< 传感器编号,表示同类传感器的第几个器件,从0开始,默认是0, 0表示默认器件(主传感器)*/ float maxRange; /**< 传感器的最大测量范围 */ float precision; /**< 传感器精度 */ @@ -126,9 +120,9 @@ typedef struct Sensor_SensorInfo { */ typedef enum Sensor_SensorMode { DEFAULT_MODE = 0, /**< 默认数据报告模式 */ - REALTIME_MODE = 1, /**< 实时数据上报模式,每次上报一组数据 */ - ON_CHANGE = 2, /**< 数据实时上报模式,在状态发生变化时上报数据 */ - ONE_SHOT = 3, /**< 数据实时上报模式,只上报一次数据 */ + REALTIME_MODE = 1, /**< 实时上报数据模式,每次上报一组数据 */ + ON_CHANGE = 2, /**< 实时上报数据模式,在状态发生变化时上报数据 */ + ONE_SHOT = 3, /**< 实时上报数据模式,只上报一次数据 */ FIFO_MODE = 4, /**< 基于fifo的数据上报模式,根据BatchCnt设置上报数据 */ MODE_MAX2, /**< 最大传感器数据上报模式 */ } Sensor_SensorMode; @@ -149,21 +143,17 @@ typedef struct Sensor_SensorEvent { } Sensor_SensorEvent; /** - * @brief 列举传感器的数据报告模式。 + * @brief 传感器订阅Id。 * * @since 11 */ typedef struct Sensor_SubscribeId { - Sensor_SensorTypeId sensorTypeId; /**< 用于报告传感器的类型 */ - int32_t sensorIndex; // 表示同类型的第几个传感器,0表示默认值 - int32_t sensorId; // 表示同类型的第几个传感器,0表示默认值 - char networkId[NETWORK_ID_MAX_LEN]; // 分布式设备的networkId,默认值 "local",用户什么都不传或者用户主动传了"local",都都表示本地设备 - // 只有用户主动传其他设备的networkId,才订阅分布式设备 - //暂时的实现上,我们在cpp里直接把这个字段里先忽略掉 - // 上接口时,在注释上得说明一下,networkID是预留字段,暂无实现 + Sensor_SensorTypeId sensorTypeId; /**< 传感器类型ID */ + int32_t sensorIndex; /**< 当前类型的第几个传感器,默认值为0 */ + char networkId[NETWORK_ID_MAX_LEN]; /**< 分布式设备的networkId,默认值 "local" */ } Sensor_SubscribeId; -/** +/** * @brief 传感器订阅属性。 * * @since 11 @@ -174,19 +164,19 @@ typedef struct Sensor_SubscribeAttribute { } Sensor_SubscribeAttribute; /** - * @brief 定义传感器代理报告数据的回调。 + * @brief 上报传感器数据的回调函数。 * * @since 11 */ typedef void (*Sensor_RecordSensorCallback)(Sensor_SensorEvent *event); /** - * @brief 为传感器数据订阅者定义保留字段。 + * @brief 为传感器订阅者预留的字段。 * * @since 11 */ typedef struct Sensor_UserData { - char userData[SENSOR_USER_DATA_SIZE]; /**< 为传感器数据订阅者保留 */ + char userData[SENSOR_USER_DATA_SIZE]; /**< 为传感器数据订阅者预留的字段 */ } Sensor_UserData; /** @@ -200,119 +190,108 @@ typedef struct Sensor_SubscribeUser { Sensor_UserData *userData = nullptr; /**< 传感器数据订阅者的保留字段 */ } Sensor_SubscribeUser; -/** - * @brief 定义有关传感器数据精度的信息。 - * - * @since 11 - */ -typedef enum Sensor_SensorAccuracy { - UNRELIABLE = 0, /**< 传感器数据不可信 */ - LOW = 1, /**< 传感器数据精度较低 */ - MEDIUM = 2, /**< 传感器数据精度中等 */ - HIGH = 3, /**< 传感器数据高 */ -} Sensor_SensorAccuracy; - /** * @brief 加速度传感器数据格式, - * 设备在m/s2的三个物理轴(x、y、z)上。 - * + * 表示施加在设备三个物理轴向(x、y 和 z)上的加速度(包含重力加速度),以 m/s2 为单位。 + * * @since 11 */ typedef struct Sensor_AccelerometerData { - float x; /**< 施加在设备x轴的加速度,单位 : m/s² */ - float y; /**< 施加在设备y轴的加速度,单位 : m/s² */ - float z; /**< 施加在设备z轴的加速度,单位 : m/s² */ + float x; /**< 施加在设备x轴的加速度(包含重力加速度),单位:m/s² */ + float y; /**< 施加在设备y轴的加速度(包含重力加速度),单位:m/s² */ + float z; /**< 施加在设备z轴的加速度(包含重力加速度),单位:m/s² */ } Sensor_AccelerometerData; /** - * @brief 定义线性加速度计的数据结构。测量施加于的线性加速度 - * 设备在m/s2的三个物理轴(x、y、z)上。 - * + * @brief 线性加速度传感器数据格式。 + * 表示施加在设备三个物理轴向(x、y 和 z)上除去重力影响的线性加速度,以 m/s2 为单位。 + * * @since 11 */ typedef struct Sensor_LinearAccelData { - float x; /**< 施加在设备x轴的线性加速度,单位 : m/s² */ - float y; /**< 施加在设备y轴的线性加速度,单位 : m/s² */ - float z; /**< 施加在设备z轴的线性加速度,单位 : m/s² */ + float x; /**< 施加在设备x轴的线性加速度(不包含重力加速度),单位:m/s² */ + float y; /**< 施加在设备y轴的线性加速度(不包含重力加速度),单位:m/s² */ + float z; /**< 施加在设备z轴的线性加速度(不包含重力加速度),单位:m/s² */ } Sensor_LinearAccelData; /** - * @brief 定义陀螺仪传感器数据结构。测量物体的旋转角速度 - * 三个物理轴(x, y和z)上的设备,单位为rad/s。 - * + * @brief 陀螺仪传感器数据格式。 + * 表示设备在三个物理轴向(x、y 和 z)上的旋转角速度,以 rad/s 为单位。 + * * @since 11 */ typedef struct Sensor_GyroscopeData { - float x; /**< 设备x轴的旋转角速度,单位rad/s */ - float y; /**< 设备y轴的旋转角速度,单位rad/s */ - float z; /**< 设备z轴的旋转角速度,单位rad/s */ + float x; /**< 设备x轴的旋转角速度,单位:rad/s */ + float y; /**< 设备y轴的旋转角速度,单位:rad/s */ + float z; /**< 设备z轴的旋转角速度,单位:rad/s */ } Sensor_GyroscopeData; /** - * @brief 定义重力传感器数据结构。测量重力加速度 - * 在m/s2的三个物理轴(x, y和z)上到设备。 - * + * @brief 重力传感器数据格式。 + * 表示设备在三个物理轴向(x、y 和 z)上的重力,以 m/s2 为单位。 + * * @since 11 */ typedef struct Sensor_GravityData { - float x; /**< 施加在设备x轴的重力加速度,单位 : m/s² */ - float y; /**< 施加在设备y轴的重力加速度,单位 : m/s² */ - float z; /**< 施加在设备z轴的重力加速度,单位 : m/s² */ + float x; /**< 施加在设备x轴的重力,单位:m/s² */ + float y; /**< 施加在设备y轴的重力,单位:m/s² */ + float z; /**< 施加在设备z轴的重力,单位:m/s² */ } Sensor_GravityData; /** - * @brief 定义未校准加速度计数据结构。测量应用于的未校准加速度计 - * 设备在m/s2的三个物理轴(x、y、z)上。 - * + * @brief 未校准加速度传感器。 + * 表示设备在三个物理轴(x、y 和 z)上的未校准加速度,以 m/s2 为单位。 + * * @since 11 */ typedef struct Sensor_AccelUncalibratedData { - float x; /**< 施加在设备x轴未校准的加速度,单位 : m/s² */ - float y; /**< 施加在设备y轴未校准的加速度,单位 : m/s² */ - float z; /**< 施加在设备z轴未校准的加速度,单位 : m/s² */ - float biasX; /**< 施加在设备x轴未校准的加速度偏量,单位 : m/s² */ - float biasY; /**< 施加在设备上y轴未校准的加速度偏量,单位 : m/s² */ - float biasZ; /**< 施加在设备z轴未校准的加速度偏量,单位 : m/s² */ + float x; /**< 施加在设备x轴未校准的加速度,单位:m/s² */ + float y; /**< 施加在设备y轴未校准的加速度,单位:m/s² */ + float z; /**< 施加在设备z轴未校准的加速度,单位:m/s² */ + float biasX; /**< 施加在设备x轴未校准的加速度偏量,单位:m/s² */ + float biasY; /**< 施加在设备上y轴未校准的加速度偏量,单位:m/s² */ + float biasZ; /**< 施加在设备z轴未校准的加速度偏量,单位:m/s² */ } Sensor_AccelUncalibratedData; /** - * @brief 定义未校准陀螺仪传感器数据结构。测量未校准的旋转角速度 - * 三个物理轴(x, y和z)上的设备,单位为rad/s。 - * + * @brief 未校准陀螺仪传感器数据结构。 + * 表示设备在三个物理轴(x, y 和 z)上未校准旋转角速度,以 rad/s 为单位。 + * * @since 11 */ typedef struct Sensor_GyroUncalibratedData { - float x; /**< 设备x轴未校准的旋转角速度,单位rad/s */ - float y; /**< 设备y轴未校准的旋转角速度,单位rad/s */ - float z; /**< 设备z轴未校准的旋转角速度,单位rad/s */ - float biasX; /**< 设备x轴未校准的旋转角速度偏量,单位rad/s */ - float biasY; /**< 设备y轴未校准的旋转角速度偏量,单位rad/s */ - float biasZ; /**< 设备z轴未校准的旋转角速度偏量,单位rad/s */ + float x; /**< 设备x轴未校准的旋转角速度,单位:rad/s */ + float y; /**< 设备y轴未校准的旋转角速度,单位:rad/s */ + float z; /**< 设备z轴未校准的旋转角速度,单位:rad/s */ + float biasX; /**< 设备x轴未校准的旋转角速度偏量,单位:rad/s */ + float biasY; /**< 设备y轴未校准的旋转角速度偏量,单位:rad/s */ + float biasZ; /**< 设备z轴未校准的旋转角速度偏量,单位:rad/s */ } Sensor_GyroUncalibratedData; /** - * @brief 定义大幅动作检测传感器数据结构。测量设备上是否有实质性的运动 - * 三个物理轴(x, y和z);值为1表示存在较大的运动;0表示这个值没有大的变动。 - * + * @brief 大幅动作检测传感器数据结构。 + * 表示设备在三个物理轴(x, y 和 z)是否存在大幅的运动,1 表示存在大幅的运动;0 表示没有大幅的运动。 + * * @since 11 */ typedef struct Sensor_SignificantMotionData { - float scalar; /**< 表示剧烈运动程度。如果取值为1则代表存在大幅度运动,取值为0则代表没有大幅度运动 */ + float scalar; /**< 表示剧烈运动程度。1 表示存在大幅度运动,0 表示没有大幅度运动 */ } Sensor_SignificantMotionData; /** - * @brief 定义计步器检测传感器数据结构。检测用户的计步动作;如果值为1, - * 它表示用户产生了计数行走的动作; 如果该值为0,则表示用户没有移动。 - * + * @brief 计步器检测传感器数 + * 检测用户的计行走的状态;1 表示有行走的动作;0 则表示没有行走的动作。 + * * @since 11 */ typedef struct Sensor_PedometerDetectData { - float scalar; /**< 计步器检测状态,1表示有行走动作,0表示没有动作 */ + float scalar; /**< 计步器检测状态,1 表示有行走动作,0 表示没有动作 */ } Sensor_PedometerDetectData; /** - * @brief 定义计步器传感器数据结构。统计用户走过的步数。 - * + * @brief 计步器传感器数据结构。 + * 统计用户走过的步数。 + * * @since 11 */ typedef struct Sensor_PedometerData { @@ -320,36 +299,41 @@ typedef struct Sensor_PedometerData { } Sensor_PedometerData; /** - * @brief 定义温度传感器数据结构。测量环境温度,单位为摄氏度。 - * + * @brief 温度传感器数据结构。 + * 测量环境温度,以摄氏度为单位。 + * * @since 11 */ typedef struct Sensor_AmbientTemperatureData { - float temperature; /**< 环境温度,单位为摄氏度 */ + float temperature; /**< 环境温度,单位:摄氏度 */ } Sensor_AmbientTemperatureData; /** - * @brief 定义颜色传感器数据结构。 - * + * @brief 颜色传感器数据结构。 + * 测量光的强度,以勒克斯为单位; + * 测量光的色温,以开尔文为单位。 + * * @since 11 */ typedef struct Sensor_ColorData { - float lightIntensity; /**< 表示光的强度,单位 : 勒克斯 */ - float colorTemperature; /**< 表示色温,单位是开尔文(k) */ + float lightIntensity; /**< 表示光的强度,单位:勒克斯 */ + float colorTemperature; /**< 表示色温,单位:开尔文(k) */ } Sensor_ColorData; /** - * @brief 定义吸收比率传感器数据结构。 - * + * @brief 吸收比率传感器数据结构。 + * 测量吸收比率,以 W/kg 为单位。 + * * @since 11 */ typedef struct Sensor_SarData { - float absorptionRatio; /**< 表示具体的吸收率,单位 : W/kg */ + float absorptionRatio; /**< 表示具体的吸收率,单位:W/kg */ } Sensor_SarData; /** - * @brief 定义湿度传感器数据结构。测量环境的相对湿度,以百分比(%)表示。 - * + * @brief 湿度传感器数据结构。 + * 测量环境的相对湿度,以百分比(%)表示。 + * * @since 11 */ typedef struct Sensor_HumidityData { @@ -357,44 +341,36 @@ typedef struct Sensor_HumidityData { } Sensor_HumidityData; /** - * @brief 定义温度传感器数据结构。测量环境的相对温度,单位为摄氏度。 - * - * @since 11 - */ -typedef struct Sensor_TemperatureData { - float temperature; /**< 显示环境温度,单位为摄氏度 */ -} Sensor_TemperatureData; - -/** - * @brief 定义地磁传感器数据结构。 - * 三次测量周围的地磁场物理轴(x, y, z),单位为μT。 - * + * @brief 地磁传感器数据结构。 + * 表示设备在三个物理轴(x, y 和 z)上的环境磁场强度,以 μT 为单位。 + * * @since 11 */ typedef struct Sensor_MagneticFieldData { - float x; /**< x轴环境磁场强度,单位 : μT */ - float y; /**< y轴环境磁场强度,单位 : μT */ - float z; /**< z轴环境磁场强度,单位 : μT */ + float x; /**< 设备在x轴上的环境磁场强度,单位:μT */ + float y; /**< 设备在y轴上的环境磁场强度,单位:μT */ + float z; /**< 设备在z轴上的环境磁场强度,单位:μT */ } Sensor_MagneticFieldData; /** - * @brief 义未校准地磁传感器数据结构。 - * 测量未校准的环境地磁场在三个物理轴(x, y, z)上以μT为单位。 - * + * @brief 未校准地磁传感器数据结构。 + * 表示设备在三个物理轴(x, y 和 z)上的未校准环境磁场强度,以 μT 为单位。 + * * @since 11 */ typedef struct Sensor_MagneticFieldUncalibratedData { - float x; /**< x轴未校准环境磁场强度,单位 : μT */ - float y; /**< y轴未校准环境磁场强度,单位 : μT */ - float z; /**< z轴未校准环境磁场强度,单位 : μT */ - float biasX; /**< x轴未校准环境磁场强度偏量,单位 : μT */ - float biasY; /**< y轴未校准环境磁场强度偏量,单位 : μT */ - float biasZ; /**< z轴未校准环境磁场强度偏量,单位 : μT */ + float x; /**< 设备在x轴上的未校准环境磁场强度,单位:μT */ + float y; /**< 设备在y轴上的未校准环境磁场强度,单位:μT */ + float z; /**< 设备在z轴上的未校准环境磁场强度,单位:μT */ + float biasX; /**< 设备在x轴上的未校准环境磁场强度偏量,单位:μT */ + float biasY; /**< 设备在y轴上的未校准环境磁场强度偏量,单位:μT */ + float biasZ; /**< 设备在z轴上的未校准环境磁场强度偏量,单位:μT */ } Sensor_MagneticFieldUncalibratedData; /** - * @brief 定义气压计传感器数据结构。测量环境气压,单位:hPa或mbar。 - * + * @brief 气压计传感器数据结构。 + * 测量环境气压,以帕斯卡为单位。 + * * @since 11 */ typedef struct Sensor_BarometerData { @@ -402,30 +378,21 @@ typedef struct Sensor_BarometerData { } Sensor_BarometerData; /** - * @brief 定义设备方向传感器数据结构。测量设备的旋转方向,单位为rad。 - * - * @since 11 - */ -typedef struct Sensor_DeviceOrientationData { - float scalar; /**< 表示设备的方向 */ -} Sensor_DeviceOrientationData; - -/** - * @brief 定义方向传感器数据结构。 - * 测量设备围绕所有三个物理轴(z, x, y)旋转的角度值,单位为rad。 - * + * @brief 方向传感器数据结构。 + * 表示设备在三个物理轴(z, x 和 y)上旋转的角度值,以 rad 为单位。 + * * @since 11 */ typedef struct Sensor_OrientationData { - float alpha; /**< 设备围绕Z轴的旋转角度,单位:度 */ - float beta; /**< 设备围绕X轴的旋转角度,单位:度 */ - float gamma; /**< 设备围绕Y轴的旋转角度,单位:度 */ + float alpha; /**< 设备在Z轴的旋转角度值,单位:rad */ + float beta; /**< 设备在X轴的旋转角度值,单位:rad */ + float gamma; /**< 设备在Y轴的旋转角度值,单位:rad */ } Sensor_OrientationData; /** - * @brief 定义旋转矢量传感器数据结构。测量设备游戏旋转矢量,复合传感器: - * 由加速度传感器、陀螺仪传感器合成。 - * + * @brief 旋转矢量传感器数据结构。 + * 表示设备在三个物理轴(z, x 和 y)上旋转矢量,由加速度传感器和陀螺仪传感器合成。 + * * @since 11 */ typedef struct Sensor_RotationVectorData { @@ -436,64 +403,53 @@ typedef struct Sensor_RotationVectorData { } Sensor_RotationVectorData; /** - * @brief 定义了地磁旋转矢量传感器的数据结构。 测量装置地磁旋转矢量,复合传感器: - * 由加速度传感器和磁场传感器合成。 - * - * @since 11 - */ -typedef struct Sensor_GeomagneticRotaVectorData { - float x; /**< 地磁旋转矢量x轴分量 */ - float y; /**< 地磁旋转矢量y轴分量 */ - float z; /**< 地磁旋转矢量z轴分量 */ - float w; /**< 标量 */ -} Sensor_GeomagneticRotaVectorData; - -/** - * @brief 定义接近光传感器数据结构。 测量相对于设备显示的可见物体的接近度或距离; - * 其中0表示接近,1表示距离。 - * + * @brief 接近光传感器数据结构。 + * 表示设备显示的可见物体的接近度或距离,0 表示接近,大于 0 表示远离。 + * * @since 11 */ typedef struct Sensor_ProximityData { - float distance; /**< 可见物体与设备显示器的接近程度。0表示接近,1表示远离 */ + float distance; /**< 可见物体与设备显示器的接近程度。0 表示接近,大于 0 表示远离 */ } Sensor_ProximityData; /** - * @brief 定义环境光传感器数据结构。以勒克斯为单位测量设备周围的光强度。 - * + * @brief 环境光传感器数据结构。 + * 表示环境光的强度,以勒克斯为单位。 + * * @since 11 */ typedef struct Sensor_AmbientLightData { - float intensity; /**< 表示光强度,单位为:勒克斯 */ + float intensity; /**< 表示光的强度,单位为:勒克斯 */ } Sensor_AmbientLightData; /** - * @brief 定义霍尔传感器数据结构。测量设备周围是否有磁力, - * 0表示没有磁力,1表示有磁力。 - * + * @brief 霍尔传感器数据结构。 + * 表示设备周围是否有磁力,0 表示没有磁力,大于 0 表示有磁力。 + * * @since 11 */ typedef struct Sensor_HallData { - float status; /**< 显示霍尔状态。测量设备周围是否存在磁力吸引,0表示没有,大于0表示有 */ + float status; /**< 显示霍尔状态。测量设备周围是否存在磁力吸引,0 表示没有,大于 0 表示有 */ } Sensor_HallData; /** - * @brief 定义心率传感器数据结构。测量用户的心率,以bpm为单位。 - * + * @brief 心率传感器数据结构。 + * 表示用户的心率,以 bpm 为单位。 + * * @since 11 */ typedef struct Sensor_HeartRateData { - float heartRate; /**< 心率值。测量用户的心率数值,单位:bpm */ + float heartRate; /**< 用户的心率,单位:bpm */ } Sensor_HeartRateData; /** - * @brief 定义佩戴检测传感器数据结构。表示设备是否被穿戴, - * 1表示已穿戴,0表示未穿戴。 - * + * @brief 佩戴检测传感器数据结构。 + * 表示设备佩戴状态,1 表示已穿戴,0 表示未穿戴。 + * * @since 11 */ typedef struct Sensor_WearDetectionData { - float value; /**< 佩戴检测状态,穿戴为1,不穿戴为0 */ + float value; /**< 佩戴状态,1 表示已穿戴,0 表示未穿戴 */ } Sensor_WearDetectionData; #ifdef __cplusplus -- Gitee From fedda70d6487054bf08ba28e8647c6f61a86eacc Mon Sep 17 00:00:00 2001 From: cff Date: Wed, 15 Nov 2023 08:49:13 +0000 Subject: [PATCH 3/5] =?UTF-8?q?sensor=20capi=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cff --- sensors/sensor/BUILD.gn | 58 ++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/sensors/sensor/BUILD.gn b/sensors/sensor/BUILD.gn index 69f2ad927b..c2faa7a085 100644 --- a/sensors/sensor/BUILD.gn +++ b/sensors/sensor/BUILD.gn @@ -1,30 +1,30 @@ -# Copyright (C) 2022 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and +# Copyright (C) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and # limitations under the License. - -import("//build/ohos.gni") -import("//build/ohos/ndk/ndk.gni") - -ohos_ndk_headers("sensor_capi_header") { - dest_dir = "$ndk_headers_out_dir/sensors/sensor" - sources = [ - "./include/sensor_capi.h", - "./include/sensor_capi_base.h", - ] -} - -ohos_ndk_library("libsensor_capi_ndk") { - ndk_description_file = "./libsensor_capi.ndk.json" - output_name = "sensor_capi_ndk" - output_extension = "z.so" - min_compact_version = "11" -} + +import("//build/ohos.gni") +import("//build/ohos/ndk/ndk.gni") + +ohos_ndk_headers("sensor_capi_header") { + dest_dir = "$ndk_headers_out_dir/sensors/sensor" + sources = [ + "./include/sensor_capi.h", + "./include/sensor_capi_base.h", + ] +} + +ohos_ndk_library("libsensor_capi_ndk") { + ndk_description_file = "./libsensor_capi.ndk.json" + output_name = "sensor_capi_ndk" + output_extension = "z.so" + min_compact_version = "11" +} -- Gitee From 2b53b77fda166014c9f8f4306754800926db5ca9 Mon Sep 17 00:00:00 2001 From: cff Date: Sat, 18 Nov 2023 06:20:41 +0000 Subject: [PATCH 4/5] =?UTF-8?q?sensor=20capi=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cff --- README.en.md | 4 +--- README.md | 2 -- sensors/sensor/include/sensor_capi.h | 1 - 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/README.en.md b/README.en.md index 0c3af2fd57..aa1cb84f83 100644 --- a/README.en.md +++ b/README.en.md @@ -36,9 +36,7 @@ This repository is used to store .h declaration files of C APIs. The OpenHarmony ├─resourceschedule | ├─ffrt ├─security - | ├─huks - ├─sensors - | ├─sensor + | ├─huksr ├─startup | ├─init ├─third_party diff --git a/README.md b/README.md index 8ff8d5939b..959da5d1f1 100644 --- a/README.md +++ b/README.md @@ -39,8 +39,6 @@ | ├─ffrt ├─security | ├─huks -├─sensors -| ├─sensor ├─startup | ├─init ├─third_party diff --git a/sensors/sensor/include/sensor_capi.h b/sensors/sensor/include/sensor_capi.h index db1eb3d7a4..32de5036b9 100644 --- a/sensors/sensor/include/sensor_capi.h +++ b/sensors/sensor/include/sensor_capi.h @@ -27,7 +27,6 @@ * @file sensor_capi.h * * @brief 声明操作传感器的常用api,用于获取传感器信息、订阅或取消订阅传感器数据等。 - * @library 引用sensor_capi_base.h,链接生成libsensor_capi_ndk.so。 * @syscap SystemCapability.Sensors.Sensor * @since 11 */ -- Gitee From 312666810cc92de22db7deb88b635804b9e54850 Mon Sep 17 00:00:00 2001 From: cff Date: Sat, 18 Nov 2023 06:21:49 +0000 Subject: [PATCH 5/5] =?UTF-8?q?sensor=20capi=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cff --- README.en.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.en.md b/README.en.md index aa1cb84f83..4559b64dd9 100644 --- a/README.en.md +++ b/README.en.md @@ -36,7 +36,7 @@ This repository is used to store .h declaration files of C APIs. The OpenHarmony ├─resourceschedule | ├─ffrt ├─security - | ├─huksr + | ├─huks ├─startup | ├─init ├─third_party -- Gitee