提交 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.h"
#include "sensor_agent_type.h" #include "sensor_agent_type.h"
#include "stdio.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. 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"
```
``` 2. Create a sensor callback.
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.
1. Obtain the list of sensors supported by the device. ```c
void SensorDataCallbackImpl(SensorEvent *event)
``` {
SensorInfo *sensorInfo = (SensorInfo *)NULL; if(event == NULL){
int32_t count = 0; return;
int32_t ret = GetAllSensors(&sensorInfo, &count); }
``` 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.
``` ```c
SensorUser sensorUser; SensorInfo *sensorInfo = (SensorInfo *)NULL;
sensorUser.callback = SensorDataCallbackImpl; // Assign the created callback SensorDataCallbackImpl to the member variable callback. int32_t count = 0;
``` int32_t ret = GetAllSensors(&sensorInfo, &count);
```
1. Enable the sensor. 4. Create a sensor user.
``` ```c
int32_t ret = ActivateSensor(0, &sensorUser); SensorUser sensorUser;
``` sensorUser.callback = SensorDataCallbackImpl; // Assign the created callback SensorDataCallbackImpl to the member variable callback.
```
1. Subscribe to sensor data. 5. Enable the sensor.
``` ```c
int32_t ret = SubscribeSensor(0, &sensorUser); int32_t ret = ActivateSensor(0, &sensorUser);
``` ```
>![](../public_sys-resources/icon-note.gif) **NOTE:** 6. Subscribe to sensor data.
>Till now, you can obtain the sensor data via the callback.
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.
``` 7. Unsubscribe from the sensor data.
int32_t ret = UnsubscribeSensor(0, &sensorUser);
```
1. Disable the sensor. ```c
int32_t ret = UnsubscribeSensor(0, &sensorUser);
```
``` 8. Disable the sensor.
int32_t ret = DeactivateSensor(0, &sensorUser);
```
```c
int32_t ret = DeactivateSensor(0, &sensorUser);
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册