Merge branch 'master' into change-to-sending-expresslrs_RFrates_e-in-sync-packet
[ExpressLRS.git] / src / lib / Baro / baro_base.h
blobf991ef55d0e56bd1a2d2a7970abe4ca868caebf7
1 #pragma once
3 #include <stdint.h>
4 #include <stddef.h>
6 class BaroBase
8 public:
9 static const int32_t ALTITUDE_INVALID = 0x7fffffff;
10 static const int32_t TEMPERATURE_INVALID = 0x7fffffff;
11 static const uint32_t PRESSURE_INVALID = 0xffffffff;
13 BaroBase() : m_initialized(false), m_altitudeHome(ALTITUDE_INVALID) {}
15 virtual void initialize() = 0;
16 // Return expected duration of pressure measurement (ms)
17 virtual uint8_t getPressureDuration() = 0;
18 // Start reading pressure
19 virtual void startPressure() = 0;
20 // Get pressure result (deci-Pascals)
21 virtual uint32_t getPressure() = 0;
22 // Return expected duration of temperature measurement (ms)
23 virtual uint8_t getTemperatureDuration() = 0;
24 // Start reading temperature
25 virtual void startTemperature() = 0;
26 // Get temperature result (centiDegrees)
27 virtual int32_t getTemperature() = 0;
29 // Base functions
30 bool isInitialized() const { return m_initialized; }
31 int32_t pressureToAltitude(uint32_t pressurePa);
32 // Properties
33 int32_t getAltitudeHome() const { return m_altitudeHome; }
34 void setAltitudeHome(int32_t altitudeHome) { m_altitudeHome = altitudeHome; }
35 protected:
36 bool m_initialized;
37 int32_t m_altitudeHome;
40 class BaroI2CBase : public BaroBase
42 protected:
43 static uint8_t m_address;
44 static void readRegister(uint8_t reg, uint8_t *data, size_t size);
45 static void writeRegister(uint8_t reg, uint8_t *data, size_t size);