34 : i2cConfig{sensorConfig.sa0 ? lsp28dfwAddress1 : lsp28dfwAddress0,
36 i2c(i2c), sensorConfig(sensorConfig)
39 ? pressureSensitivity1260hPa
40 : pressureSensitivity4060hPa);
47 LOG_ERR(logger,
"Attempted to initialized sensor twice but failed");
55 LOG_ERR(logger,
"Configuration not applied correctly");
71 LOG_ERR(logger,
"Invoked selfTest() but sensor was uninitialized");
77 if (!i2c.
probe(i2cConfig))
80 "Can't communicate with the sensor or sensor not attached");
86 uint8_t whoamiValue{0};
89 LOG_ERR(logger,
"Can't communicate with the sensor");
95 if (whoamiValue != WHO_AM_I_VALUE)
98 "WHO_AM_I value differs from expectation: read 0x{02x} "
99 "but expected 0x{02x}",
100 whoamiValue, WHO_AM_I_VALUE);
116 : FIFO_CTRL::CONTINUOUS)))
126 LOG_ERR(logger,
"Sensor not configured");
145 sensorConfig.
avg = avg;
161 sensorConfig.
odr = odr;
176 pressureSensitivity = pressureSensitivity1260hPa;
181 pressureSensitivity = pressureSensitivity4060hPa;
182 ctrl_reg2 = (ctrl_reg2 | CTRL_REG2::FS_MODE);
191 sensorConfig.
fsr = fs;
203 sensorConfig.
drdy = drdy;
207float LPS28DFW::convertPressure(uint8_t pressXL, uint8_t pressL, uint8_t pressH)
215 ((int32_t)((pressH << 24) | (pressL << 16) | (pressXL << 8))) >> 8;
216 return ((
float)press_temp / pressureSensitivity);
219float LPS28DFW::convertTemperature(uint8_t tempL, uint8_t tempH)
222 int16_t temp_temp = (tempH << 8) | (tempL << 0);
223 return ((
float)temp_temp) / temperatureSensitivity;
228 uint8_t statusValue{0};
229 uint8_t val[5] = {0};
236 uint8_t ctrl_reg2_val{0};
241 ctrl_reg2_val | CTRL_REG2::ONE_SHOT_START)))
255 }
while ((statusValue & (STATUS::P_DA | STATUS::T_DA)) !=
256 (STATUS::P_DA | STATUS::T_DA));
273 ((statusValue & STATUS::T_DA) ? 5 : 3)))
280 if (statusValue & STATUS::P_DA)
283 data.
pressure = convertPressure(val[0], val[1], val[2]);
293 if (statusValue & STATUS::T_DA)
296 data.
temperature = convertTemperature(val[3], val[4]);
#define LOG_ERR(logger,...)
Low level driver for I2C peripherals.
High level driver for the I2C peripherals.
bool readFromRegister(const I2CDriver::I2CSlaveConfig &slaveConfig, const uint8_t registerAddress, void *buffer, const size_t nBytes)
Non blocking operation to read n-bytes from register from a slave.
bool probe(const I2CDriver::I2CSlaveConfig &slaveConfig)
Non blocking operation to check if a slave is available.
bool writeRegister(const I2CDriver::I2CSlaveConfig &slaveConfig, const uint8_t registerAddress, const uint8_t registerContent)
Non blocking operation to write an 8-bit register from a slave.
bool readRegister(const I2CDriver::I2CSlaveConfig &slaveConfig, const uint8_t registerAddress, uint8_t ®isterContent)
Non blocking operation to read an 8-bit register from a slave.
LPS28DFWData sampleImpl() override
Read a data sample from the sensor. In case of errors, the method should return the last available co...
bool setOutputDataRate(ODR odr)
Sets and saves the output data rate.
bool setAverage(AVG avg)
Sets and saves the oversampling on the sensor.
ODR
Enumeration for Output Data Rate Configuration.
FullScaleRange
Enumeration for the full scale range to set on the sensor. Available are 1260 hPa or 4060 hPa.
AVG
Enumeration for the oversampling to set on the sensor.
bool setConfig(const SensorConfig &config)
Sets and saves the configurations passed on the parameters.
bool setDRDYInterrupt(bool drdy)
Sets and saves the full scale range.
LPS28DFW(I2C &i2c, SensorConfig sensorConfig)
Constructor that stores the initial settings (without applying them to the sensor).
bool selfTest() override
The self test method returns true if we read the right whoami value. We can't make a better self test...
bool setFullScaleRange(FullScaleRange fs)
Sets and saves the full scale range.
bool init() override
Initializes the sensor with the current settings.
Various LPS28DFW register/enums definitions.
@ FS_MODE
Full-scale selection.
@ WHO_AM_I
Device Who am I register.
@ PRESS_OUT_XL
Pressure output value LSB data.
@ CTRL_REG1
Control Register 1 [ODR, AVG].
@ DRDY
Date-ready signal on INT_DRDY pin.
@ INT_EN
Interrupt signal on INT_DRDY pin.
uint64_t getTimestamp()
Returns the current timer value in microseconds.
This file includes all the types the logdecoder script will decode.
Struct that sums up all the settings of the sensor.
AVG avg
Average avg samples.
bool drdy
Enable Interrupt for Data Ready.
FullScaleRange fsr
Full scale range.
Struct for the LPS28DFW barometer data. Pressures stored in Pa and Temperature in °C.
uint64_t pressureTimestamp
uint64_t temperatureTimestamp