XGZP6847DDevice
XGZP6847D 数字压力传感器驱动。 https://cfsensor.com/product/xgzp6847d/ 官方产品页: https://cfsensor.com/wp-content/uploads/2026/04/XGZP6847D-Pressure-Sensor-V3.0.pdf V3.0 datasheet: https://www.scribd.com/document/891923775/XGZP6847D-Pressure-Sensor-V2-2025-05-04-21-28-42 V2.8 检索页: 旧版协议/量程换算参考资料: 当前实现使用的是旧版协议里的 K 表换算: pressure_pa = signExtend24(raw_pressure) / K -100~100 kPa -> pressure_range_kpa = 100 -> K = 64 量程 -100~300 kPa -> pressure_range_kpa = 300 -> K = 16 量程 这里的 pressure_range_kpa 不是总量程跨度,而是 max(abs(Pmin), abs(Pmax))。 例如: onTrigger() onRead() 该设备需要先写命令触发一次联合转换,再等待芯片完成内部测量,最后读取 压力和温度原始值并更新缓存。因此它重写了、conversionMs() 和三个状态机钩子。
继承关系
- 基类
I2CDevice公开
构造与析构
1XGZP6847DDevice
XGZP6847DDevice::XGZP6847DDevice (float pressure_range_kpa, uint8_t address_7bit=DefaultAddress)
构造压力传感器设备对象 pressure_range_kpa 旧版 K 表使用的等效量程,单位 kPa; 取 max(abs(Pmin), abs(Pmax)),不是 Pmax - Pmin address_7bit 设备的 7 位 I2C 地址
pressure/XGZP6847D/XGZP6847DDevice.hpp:55成员函数
11address7bit
uint8_t XGZP6847DDevice::address7bit () const override
获取设备的 7 位 I2C 地址 当前设备地址
pressure/XGZP6847D/XGZP6847DDevice.hpp:69calcK
int32_t XGZP6847DDevice::calcK (float pressure_range_kpa)
根据量程计算压力换算系数 pressure_range_kpa 旧版 K 表使用的等效量程,单位 kPa; 取 max(abs(Pmin), abs(Pmax)),不是 Pmax - Pmin 对应的压力换算系数
pressure/XGZP6847D/XGZP6847DDevice.hpp:139conversionMs
uint32_t XGZP6847DDevice::conversionMs () const override
获取芯片一次联合转换的最大等待时间 转换时间上限,单位毫秒
pressure/XGZP6847D/XGZP6847DDevice.hpp:107getPressure
float XGZP6847DDevice::getPressure () const
获取当前缓存的压力值 当前缓存压力,单位 Pa
pressure/XGZP6847D/XGZP6847DDevice.hpp:92init
bool XGZP6847DDevice::init (I2CBusDMA &bus, uint32_t timeout_ms) override
通过最小寄存器读操作确认设备在线 bus 当前设备所在的 I2C 总线 timeout_ms 单次事务超时时间,单位毫秒 初始化探活是否成功
pressure/XGZP6847D/XGZP6847DDevice.hpp:80name
const char * XGZP6847DDevice::name () const override
获取设备名称 固定返回设备名字符串
pressure/XGZP6847D/XGZP6847DDevice.hpp:61onDataInvalidated
void XGZP6847DDevice::onDataInvalidated () override
在父类判定数据失效时同步清理样本有效位
pressure/XGZP6847D/XGZP6847DDevice.hpp:124onRead
bool XGZP6847DDevice::onRead (I2CBusDMA &bus, uint32_t now_ms, uint32_t timeout_ms) override
读取原始数据并更新缓存 bus 当前设备所在的 I2C 总线 now_ms 当前时间戳,单位毫秒 timeout_ms 单次事务超时时间,单位毫秒 读取并解析是否成功
pressure/XGZP6847D/XGZP6847DDevice.hpp:119onTrigger
bool XGZP6847DDevice::onTrigger (I2CBusDMA &bus, uint32_t timeout_ms) override
发送一次联合转换命令 bus 当前设备所在的 I2C 总线 timeout_ms 单次事务超时时间,单位毫秒 触发采样是否成功
pressure/XGZP6847D/XGZP6847DDevice.hpp:101signExtend24
int32_t XGZP6847DDevice::signExtend24 (const uint8_t data[3])
将 24 位补码原始压力扩展为 32 位有符号整数 data 指向 3 字节原始压力数据 符号扩展后的 32 位压力原始值
pressure/XGZP6847D/XGZP6847DDevice.hpp:146snapshot
XGZP6847DDevice::Sample XGZP6847DDevice::snapshot () const
返回当前缓存的样本快照 当前缓存样本的拷贝
pressure/XGZP6847D/XGZP6847DDevice.hpp:86成员变量
9CmdCombined
uint8_t XGZP6847DDevice::CmdCombined
压力和温度联合转换命令
pressure/XGZP6847D/XGZP6847DDevice.hpp:130ConversionMs
uint32_t XGZP6847DDevice::ConversionMs
datasheet 给出的转换时间上限
pressure/XGZP6847D/XGZP6847DDevice.hpp:131DefaultAddress
uint8_t XGZP6847DDevice::DefaultAddress
设备默认 7 位 I2C 地址
pressure/XGZP6847D/XGZP6847DDevice.hpp:127RegCmd
uint8_t XGZP6847DDevice::RegCmd
命令寄存器地址
pressure/XGZP6847D/XGZP6847DDevice.hpp:129RegPressure
uint8_t XGZP6847DDevice::RegPressure
压力原始值起始寄存器地址
pressure/XGZP6847D/XGZP6847DDevice.hpp:128active_sample_index_
std::atomic<uint8_t> XGZP6847DDevice::active_sample_index_
当前对外发布的样本缓冲索引
pressure/XGZP6847D/XGZP6847DDevice.hpp:151address_
uint8_t XGZP6847DDevice::address_
当前设备实际使用的 I2C 地址
pressure/XGZP6847D/XGZP6847DDevice.hpp:148k_
int32_t XGZP6847DDevice::k_
当前量程对应的压力换算系数
pressure/XGZP6847D/XGZP6847DDevice.hpp:149sample_buffers_
std::array<Sample, 2> XGZP6847DDevice::sample_buffers_
双缓冲样本缓存
pressure/XGZP6847D/XGZP6847DDevice.hpp:150嵌套类型
1保存最近一次成功更新后的传感器样本
pressure/XGZP6847D/XGZP6847DDevice.hpp:41