MRAS
Multi Rocket Avionics System
Loading...
Searching...
No Matches
Sensor_MS5607.h
1//
2// Created by Tom Danvers on 17/12/2022.
3//
4
5#ifndef MRAS_SENSOR_MS5607_H
6#define MRAS_SENSOR_MS5607_H
7
8
9#include <Wire.h>
10#include "Subsystem.h"
11
12#define MS5607_RESET 0x1E
13#define MS5607_PROM_READ 0xA0
14#define R_ADC 0X00
15
36class Sensor_MS5607 : public Subsystem {
37private:
38 uint8_t i2c_address;
39 TwoWire *i2c_bus;
40 uint32_t i2c_frequency;
41
42 uint16_t OSR = 4096; // default oversampling ratio
43 uint8_t CONV_D1 = 0x48; // corresponding pressure conv. command for OSR
44 uint8_t CONV_D2 = 0x58; // corresponding temp conv. command for OSR
45 uint8_t CONV_Delay = 10; // corresponding conv. delay for OSR
46
47 // calibration coefficients
48 // initialising them all separately looks ugly yes
49 uint16_t C1 = 0;
50 uint16_t C2 = 0;
51 uint16_t C3 = 0;
52 uint16_t C4 = 0;
53 uint16_t C5 = 0;
54 uint16_t C6 = 0;
55
56 uint32_t D1_pressure{};
57 uint32_t D2_temperature{};
58
59 float dT{}, TEMP{}, P{};
60 int64_t OFF{}, SENS{};
61
62 uint32_t lastStateChange = 0;
63
64
65 enum {
66 IDLE,
67 READING_PRESSURE,
68 READING_TEMPERATURE
69 } state = IDLE;
70
79 bool read_PROM();
80
87 bool read_PROM_coefficient(uint8_t command, uint16_t &store);
88
94 bool reset();
95
104 void set_oversampling_ratio(uint16_t newOversamplingRatio);
105
111 bool read_ADC(uint32_t &output);
112
113public:
114 Sensor_MS5607(uint8_t id, byte i2c_address, TwoWire &i2c_bus, uint32_t frequency) : Subsystem(id),
115 i2c_address(i2c_address),
116 i2c_bus(&i2c_bus),
117 i2c_frequency(frequency) {};
118
119 int8_t setup() override;
120
121 int8_t loop() override;
122
123 SUBSYSTEM_NO_MESSAGE_HANDLER
124
125 SUBSYSTEM_NAME("MS5607")
126};
127
128
129#endif //MRAS_SENSOR_MS5607_H
Definition: Sensor_MS5607.h:36
Definition: Subsystem.h:30