diff --git a/en/device-dev/subsystems/subsys-sensor-demo.md b/en/device-dev/subsystems/subsys-sensor-demo.md index f914d045a59f36cb5bb14972987c8e755a41f363..0c4fd5b13348edf0ff98cfc065b2c06b7aa9ec62 100644 --- a/en/device-dev/subsystems/subsys-sensor-demo.md +++ b/en/device-dev/subsystems/subsys-sensor-demo.md @@ -1,8 +1,8 @@ -# Sensor Usage Example +# 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" diff --git a/en/device-dev/subsystems/subsys-sensor-guide.md b/en/device-dev/subsystems/subsys-sensor-guide.md index 4f65a3d5005b8e771329202364d3c32f120e7440..a7c7e98698f615dba5df6652b0fe5c688ae4adf6 100644 --- a/en/device-dev/subsystems/subsys-sensor-guide.md +++ b/en/device-dev/subsystems/subsys-sensor-guide.md @@ -1,70 +1,70 @@ -# Sensor Usage Guidelines +# 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 +## 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); + ```