提交 1265b75e 编写于 作者: W wusongqing

update docs against 8800

Signed-off-by: Nwusongqing <wusongqing@huawei.com>
上级 793c2a67
# 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"
......
# 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 = SubscribeSensor(0, &sensorUser);
```
```c
int32_t ret = ActivateSensor(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.
先完成此消息的编辑!
想要评论请 注册