Sensor设备的常用操作:

  1. 首先查找传感器设置获取设备句柄。rt_device_find

  2. 以轮询、FIFO、中断、任意一种方式打开传感器,中断和FIFO需要设置接收回调函数(释放一个信号量给接收线程处理。)。rt_device_open(dev, RT_DEVICE_FLAG_RDONLY)

  3. 连续读取 数据并打印出来。rt_size_t rt_device_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size);

  4. 关闭传感器。rt_err_t rt_device_close(rt_device_t dev);

  5. 控制传感器rt_err_t rt_device_control(rt_device_t dev, rt_uint8_t cmd, void* arg);
#define  RT_SENSOR_CTRL_GET_ID        /* 读设备ID */
#define RT_SENSOR_CTRL_GET_INFO /* 获取设备信息 struct rt_sensor_info info*/
#define RT_SENSOR_CTRL_SET_RANGE /* 设置传感器测量范围 */
#define RT_SENSOR_CTRL_SET_ODR /* 设置传感器数据输出速率,unit is HZ */
#define RT_SENSOR_CTRL_SET_POWER /* 设置电源模式 */
#define RT_SENSOR_CTRL_SELF_TEST /* 自检 */
05-28 07:08