README.md
sensor_lite
Introduction
The pan-sensor service subsystem provides a lightweight sensor service framework, through which you can perform the following operations:
- Query the sensor list.
- Enable or disable a sensor.
- Subscribe to or unsubscribe from sensor data.
- Set the data reporting mode of a sensor.
- Set the data sampling interval.
The following figure shows the architecture of the pan-sensor framework.
Figure 1 Pan-sensor service architecture
Directory Structure
/base/sensors/sensor_lite
├── frameworks # Framework code
│ ├── include # Header files
│ └── src # Source code
├── interfaces # APIs
│ └── kits # Native APIs
├── services # Code of services
│ ├── include # Header files
│ └── src # Source code
Usage
Available APIs
Table 1 Major APIs in SensorAgent
Usage Guidelines
This section uses the acceleration sensor as an example to describe how to use sensor APIs.
- Import the required header files.
#include "sensor_agent.h"
#include "sensor_agent_type.h"
- Create a callback.
void SensorDataCallbackImpl(SensorEvent *event)
{
if(event == NULL){
return;
}
float *sensorData=(float *)event->data;
}
- Obtain the list of sensors supported by the device.
SensorInfo *sensorInfo = (SensorInfo *)NULL;
int32_t count = 0;
int32_t ret = GetAllSensors(&sensorInfo, &count);
- Create a sensor user.
SensorUser sensorUser;
sensorUser.callback = SensorDataCallbackImpl; // Assign the created callback SensorDataCallbackImpl to the member variable callback.
- Enable the sensor.
int32_t ret = ActivateSensor(SENSOR_TYPE_ID_ACCELEROMETER, &sensorUser);
- Subscribe to sensor data.
int32_t ret = SubscribeSensor(SENSOR_TYPE_ID_ACCELEROMETER, &sensorUser);
- Unsubscribe from the sensor data.
int32_t ret = UnsubscribeSensor(SENSOR_TYPE_ID_ACCELEROMETER, &sensorUser);
- Disable the sensor.
int32_t ret = DeactivateSensor(SENSOR_TYPE_ID_ACCELEROMETER, &sensorUser);
Repositories Involved
sensors_sensor_lite