嵌入式技术论坛
直播中

申根换

7年用户 1579经验值
私信 关注
[问答]

请问sensor传感器组件缺少变量怎么办呢?

struct rt_sensor_data
{
rt_uint32_t timestamp; / The timestamp when the data was received /
rt_uint8_t type; / The sensor type of the data /
union
{
struct sensor_3_axis acce; / Accelerometer. unit: mG /
struct sensor_3_axis gyro; / Gyroscope. unit: mdps /
struct sensor_3_axis mag; / Magnetometer. unit: mGauss /
rt_int32_t temp; / Temperature. unit: dCelsius /
rt_int32_t humi; / Relative humidity. unit: permillage /
rt_int32_t baro; / Pressure. unit: pascal (Pa) /
rt_int32_t light; / Light. unit: lux /
rt_int32_t proximity; / Distance. unit: centimeters /
rt_int32_t hr; / Heart rate. unit: bpm /
rt_int32_t tvoc; / TVOC. unit: permillage /
rt_int32_t noise; / Noise Loudness. unit: HZ /
rt_uint32_t step; / Step sensor. unit: 1 /
rt_int32_t force; / Force sensor. unit: mN /
} data;
};

以上这个数据类型只能放一个变量,但是市场上有一种传感器是可以放置两个的,名称叫DHT11也是单总线,但是可以一次传输两个数据,一个是温度,一个是湿度,所以相应的注册部分也是需要修改的,请官方熟知

回帖(2)

申换换

2023-5-17 10:54:10
这个里面是把两个数据分开,已经处理好了,直接通过接口获取就行。官方早已知道这个,特意分开直接读取的
举报

訾存贵

2023-5-17 10:54:17
传感器框架设计的时候考虑了这个问题,一个传感器芯片或者模块确实可能支持同时测量多种数据,但是并没有规范规定一定是哪几种,所以如果数据结构里面所有数据类型都写上的话,必定会占用很大的内存,但其实大部分变量都是不必要的,这就造成了资源的浪费。

所以后来考虑抽象出来,一个传感器芯片或者模块如果支持测量多种数据类型的话,就注册成多个传感器设备,每一个传感器设备只对应的其中的一种测量功能。
举报

更多回帖

发帖
×
20
完善资料,
赚取积分