Skyward boardcore
Loading...
Searching...
No Matches
LPS28DFW.h
Go to the documentation of this file.
1/* Copyright (c) 2023 Skyward Experimental Rocketry
2 * Author: Emilio Corigliano
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23#pragma once
24
25#include <drivers/i2c/I2C.h>
26#include <sensors/Sensor.h>
27
28#include "LPS28DFWData.h"
29
30namespace Boardcore
31{
32
37class LPS28DFW : public Sensor<LPS28DFWData>
38{
39public:
44 enum FullScaleRange : uint8_t
45 {
48 };
49
57 enum ODR : uint8_t
58 {
59 ONE_SHOT = (0b0000 << 3),
60 ODR_1 = (0b0001 << 3),
61 ODR_4 = (0b0010 << 3),
62 ODR_10 = (0b0011 << 3),
63 ODR_25 = (0b0100 << 3),
64 ODR_50 = (0b0101 << 3),
65 ODR_75 = (0b0110 << 3),
66 ODR_100 = (0b0111 << 3),
67 ODR_200 = (0b1000 << 3)
68 };
69
80 enum AVG : uint8_t
81 {
82 AVG_4 = 0b000,
83 AVG_8 = 0b001,
84 AVG_16 = 0b010,
85 AVG_32 = 0b011,
86 AVG_64 = 0b100,
87 AVG_128 = 0b101,
88 AVG_512 = 0b111
89 };
90
94 typedef struct
95 {
96 bool sa0;
101 bool drdy;
102 } SensorConfig;
103
112 LPS28DFW(I2C& i2c, SensorConfig sensorConfig);
113
118 bool init() override;
119
123 bool setConfig(const SensorConfig& config);
124
131 bool selfTest() override;
132
137 bool setAverage(AVG avg);
138
143 bool setOutputDataRate(ODR odr);
144
150
155 bool setDRDYInterrupt(bool drdy);
156
157protected:
158 LPS28DFWData sampleImpl() override;
159
160private:
164 float convertPressure(uint8_t pressXL, uint8_t pressL, uint8_t pressH);
165
170 float convertTemperature(uint8_t tempL, uint8_t tempH);
171
172 I2CDriver::I2CSlaveConfig i2cConfig;
173 I2C& i2c;
174 SensorConfig sensorConfig;
175 bool isInitialized =
176 false;
177 uint16_t pressureSensitivity;
178 PrintLogger logger = Logging::getLogger("lps28dfw");
179};
180
181} // namespace Boardcore
High level driver for the I2C peripherals.
Definition I2C.h:40
Driver for LPS28DFW STMicroelectronics digital pressure sensor working in I2C.
Definition LPS28DFW.h:38
LPS28DFWData sampleImpl() override
Read a data sample from the sensor. In case of errors, the method should return the last available co...
Definition LPS28DFW.cpp:226
bool setOutputDataRate(ODR odr)
Sets and saves the output data rate.
Definition LPS28DFW.cpp:149
bool setAverage(AVG avg)
Sets and saves the oversampling on the sensor.
Definition LPS28DFW.cpp:133
ODR
Enumeration for Output Data Rate Configuration.
Definition LPS28DFW.h:58
FullScaleRange
Enumeration for the full scale range to set on the sensor. Available are 1260 hPa or 4060 hPa.
Definition LPS28DFW.h:45
AVG
Enumeration for the oversampling to set on the sensor.
Definition LPS28DFW.h:81
bool setConfig(const SensorConfig &config)
Sets and saves the configurations passed on the parameters.
Definition LPS28DFW.cpp:108
bool setDRDYInterrupt(bool drdy)
Sets and saves the full scale range.
Definition LPS28DFW.cpp:195
LPS28DFW(I2C &i2c, SensorConfig sensorConfig)
Constructor that stores the initial settings (without applying them to the sensor).
Definition LPS28DFW.cpp:33
bool selfTest() override
The self test method returns true if we read the right whoami value. We can't make a better self test...
Definition LPS28DFW.cpp:65
bool setFullScaleRange(FullScaleRange fs)
Sets and saves the full scale range.
Definition LPS28DFW.cpp:165
bool init() override
Initializes the sensor with the current settings.
Definition LPS28DFW.cpp:43
static PrintLogger getLogger(const string &name)
Base sensor class with has to be extended by any sensor driver.
Definition Sensor.h:91
This file includes all the types the logdecoder script will decode.
Configuration struct for a slave device. This will be used for configuring the bus in order to commun...
Definition I2CDriver.h:104
Struct that sums up all the settings of the sensor.
Definition LPS28DFW.h:95
AVG avg
Average avg samples.
Definition LPS28DFW.h:99
ODR odr
Output data rate.
Definition LPS28DFW.h:100
bool drdy
Enable Interrupt for Data Ready.
Definition LPS28DFW.h:101
FullScaleRange fsr
Full scale range.
Definition LPS28DFW.h:98
Struct for the LPS28DFW barometer data. Pressures stored in Pa and Temperature in °C.