Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
1265b75e
D
Docs
项目概览
OpenHarmony
/
Docs
1 年多 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
1265b75e
编写于
8月 30, 2022
作者:
W
wusongqing
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update docs against 8800
Signed-off-by:
N
wusongqing
<
wusongqing@huawei.com
>
上级
793c2a67
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
53 addition
and
53 deletion
+53
-53
en/device-dev/subsystems/subsys-sensor-demo.md
en/device-dev/subsystems/subsys-sensor-demo.md
+3
-3
en/device-dev/subsystems/subsys-sensor-guide.md
en/device-dev/subsystems/subsys-sensor-guide.md
+50
-50
未找到文件。
en/device-dev/subsystems/subsys-sensor-demo.md
浏览文件 @
1265b75e
# Sensor Usage Example
<a name="EN-US_TOPIC_0000001092792985"></a>
# Sensor Usage Example
The following sample code uses the sensor whose
**sensorTypeId**
is
**0**
as an example. The code for other sensor types is similar.
The following sample code uses the sensor whose
**sensorTypeId**
is
**0**
as an example. The code for other sensor types is similar.
```
```
c
#include "sensor_agent.h"
#include "sensor_agent_type.h"
#include "stdio.h"
...
...
en/device-dev/subsystems/subsys-sensor-guide.md
浏览文件 @
1265b75e
# Sensor Usage Guidelines
<a name="EN-US_TOPIC_0000001077367158"></a>
# Sensor Usage Guidelines
The following steps use the sensor whose
**sensorTypeId**
is
**0**
as an example. The guidelines for other sensor types are similar.
The following steps use the sensor whose
**sensorTypeId**
is
**0**
as an example. The guidelines for other sensor types are similar.
## How to Use
<a name="section18816105182315"></a>
## How to Use
1.
Import the required header files.
```
#include "sensor_agent.h"
#include "sensor_agent_type.h"
```
1.
Create a sensor callback.
```c
#include "sensor_agent.h"
#include "sensor_agent_type.h"
```
```
void SensorDataCallbackImpl(SensorEvent *event)
{
if(event == NULL){
return;
}
float *sensorData=(float *)event->data;
}
```
>![](../public_sys-resources/icon-note.gif) **NOTE:**
>The callback must be of the RecordSensorCallback type.
2.
Create a sensor callback.
1.
Obtain the list of sensors supported by the device.
```
SensorInfo *sensorInfo = (SensorInfo *)NULL;
int32_t count = 0;
int32_t ret = GetAllSensors(&sensorInfo, &count);
```
```c
void SensorDataCallbackImpl(SensorEvent *event)
{
if(event == NULL){
return;
}
float *sensorData=(float *)event->data;
}
```
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> The callback must be of the RecordSensorCallback type.
1.
Create a sensor user
.
3.
Obtain the list of sensors supported by the device
.
```
SensorUser sensorUser;
sensorUser.callback = SensorDataCallbackImpl; // Assign the created callback SensorDataCallbackImpl to the member variable callback.
```
```c
SensorInfo *sensorInfo = (SensorInfo *)NULL;
int32_t count = 0;
int32_t ret = GetAllSensors(&sensorInfo, &count);
```
1.
Enable the sensor.
4.
Create a sensor user.
```
int32_t ret = ActivateSensor(0, &sensorUser);
```
```c
SensorUser sensorUser;
sensorUser.callback = SensorDataCallbackImpl; // Assign the created callback SensorDataCallbackImpl to the member variable callback.
```
1.
Subscribe to sensor data.
5.
Enable the sensor.
```
int32_t ret = Subscrib
eSensor(0, &sensorUser);
```
```c
int32_t ret = Activat
eSensor(0, &sensorUser);
```
>![](../public_sys-resources/icon-note.gif) **NOTE:**
>Till now, you can obtain the sensor data via the callback.
6.
Subscribe to sensor data.
1.
Unsubscribe from the sensor data.
```c
int32_t ret = SubscribeSensor(0, &sensorUser);
```
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> Till now, you can obtain the sensor data via the callback.
```
int32_t ret = UnsubscribeSensor(0, &sensorUser);
```
7.
Unsubscribe from the sensor data.
1.
Disable the sensor.
```c
int32_t ret = UnsubscribeSensor(0, &sensorUser);
```
```
int32_t ret = DeactivateSensor(0, &sensorUser);
```
8.
Disable the sensor.
```c
int32_t ret = DeactivateSensor(0, &sensorUser);
```
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录