Android sensor framework

1. Framework

1. Application layer

App:这个是给手机软件来使用的。

2. framework layer    

(1)SensorManager: 

作用:
    初始化并连接SensorService;
    对应用层提供接口,获取sensor类型和sensor数据;
    处理sensor传感器数据,转化成android可以识别的数据格式; 

(2)SensorService:

作用:
    根据平台动态加载hal层的库,初始化hal库;
    抓取底层数据根据需要向上转发sensor数据;

3.hal layer

    It is a set of standard interfaces. sensorHal is a dynamic library. Whenever sensorService is started, it will dynamically load the sensorHal library, that is, sensorlib.so, and load different dynamic libraries according to different platforms. In this way, these libraries can be added to the system according to the hardware settings of different platforms, so that the sensorSevice automatically matches the hal layer, and the hal layer is connected to the underlying driver, which is the real sensor entity.

作用:
    封装底层接口,向上提供统一接口;
    打开sensor设备,提供相关操作函数接口;   

4.kernal layer

    These physical sensors generate a series of device nodes in the dev/input/ directory. These device nodes are sensor device nodes, and the kernal is what actually deals with hardware. The way to deal with it is I2C, SPI plus some clocks and some IO controls, so that you can get the information of all sensors.

2. Data flow

       When the application layer needs to obtain the data of a sensor, it will first get the sensorManager, and then register an interface to monitor the sensor with the sensorManager, so that the sensorManager will establish communication with the sensorService. The sensorService sends the received information to the sensorManager, and then the sensorManager notifies the upper-layer application through a series of callback interfaces, so that the upper-layer application can get the specific value, which is the value processed by the android system.

       When the sensorService is initialized, all sensor devices are connected. The value sent by the sensor is a self-starting value. It needs to be converted by the android system to be recognized by the system. The recognized data will be based on the number of upper-level monitors. Send a message to the monitoring interface, that is, send data, so that each sensor application will get the data.

Guess you like

Origin blog.csdn.net/weixin_41734758/article/details/129817080