Driver for FXPQ3115 sensor.
Example usage
main.cpp
#include "mbed.h" #include "FXPQ3115.h" FXPQ3115 pressure_sensor(P0_13, P0_14); int main() { pressure_sensor.sensor_init(); while (1) { pressure_sensor.read_oneshotMode_bar(); printf("Pressure in Pascals: %d\n", pressure_sensor.print_pressure()); thread_sleep_for(20000); } }
FXPQ3115.h@0:0b221579ed52, 2020-03-05 (annotated)
- Committer:
- Pawel Zarembski
- Date:
- Thu Mar 05 11:13:50 2020 +0100
- Revision:
- 0:0b221579ed52
initial version, one shot mode for pressure only
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Pawel Zarembski |
0:0b221579ed52 | 1 | #ifndef FXPQ3115_H_ |
Pawel Zarembski |
0:0b221579ed52 | 2 | #define FXPQ3115_H_ |
Pawel Zarembski |
0:0b221579ed52 | 3 | |
Pawel Zarembski |
0:0b221579ed52 | 4 | #include "mbed.h" |
Pawel Zarembski |
0:0b221579ed52 | 5 | #include "FXPQ3115_reg.h" |
Pawel Zarembski |
0:0b221579ed52 | 6 | |
Pawel Zarembski |
0:0b221579ed52 | 7 | #ifndef SUCCESS |
Pawel Zarembski |
0:0b221579ed52 | 8 | #define SUCCESS 0 |
Pawel Zarembski |
0:0b221579ed52 | 9 | #endif |
Pawel Zarembski |
0:0b221579ed52 | 10 | |
Pawel Zarembski |
0:0b221579ed52 | 11 | #ifndef FAILURE |
Pawel Zarembski |
0:0b221579ed52 | 12 | #define FAILURE 1 |
Pawel Zarembski |
0:0b221579ed52 | 13 | #endif |
Pawel Zarembski |
0:0b221579ed52 | 14 | |
Pawel Zarembski |
0:0b221579ed52 | 15 | #ifdef FXPQ3115_I2C_ADDRESS |
Pawel Zarembski |
0:0b221579ed52 | 16 | #define FXPQ3115_I2C_ADDRESS_SHIFTED (FXPQ3115_I2C_ADDRESS << 1) |
Pawel Zarembski |
0:0b221579ed52 | 17 | #endif |
Pawel Zarembski |
0:0b221579ed52 | 18 | |
Pawel Zarembski |
0:0b221579ed52 | 19 | #define FXPQ3115_PRESSURE_CONV_FACTOR (64) /* Will give Pascals */ |
Pawel Zarembski |
0:0b221579ed52 | 20 | #define FXPQ3115_ALTITUDE_CONV_FACTOR (65536) /* Will give meters above MSL */ |
Pawel Zarembski |
0:0b221579ed52 | 21 | #define FXPQ3115_TEMPERATURE_CONV_FACTOR (256) /* Will give °C */ |
Pawel Zarembski |
0:0b221579ed52 | 22 | |
Pawel Zarembski |
0:0b221579ed52 | 23 | class FXPQ3115 { |
Pawel Zarembski |
0:0b221579ed52 | 24 | public: |
Pawel Zarembski |
0:0b221579ed52 | 25 | FXPQ3115(PinName sda, PinName scl); |
Pawel Zarembski |
0:0b221579ed52 | 26 | |
Pawel Zarembski |
0:0b221579ed52 | 27 | uint8_t sensor_init(); |
Pawel Zarembski |
0:0b221579ed52 | 28 | uint8_t read_oneshotMode_bar(); |
Pawel Zarembski |
0:0b221579ed52 | 29 | uint32_t print_pressure(); |
Pawel Zarembski |
0:0b221579ed52 | 30 | |
Pawel Zarembski |
0:0b221579ed52 | 31 | private: |
Pawel Zarembski |
0:0b221579ed52 | 32 | I2C _i2c; |
Pawel Zarembski |
0:0b221579ed52 | 33 | char _bar_data[3]; |
Pawel Zarembski |
0:0b221579ed52 | 34 | |
Pawel Zarembski |
0:0b221579ed52 | 35 | uint8_t _config_bar(); |
Pawel Zarembski |
0:0b221579ed52 | 36 | uint8_t _wait_for_acq(); |
Pawel Zarembski |
0:0b221579ed52 | 37 | }; |
Pawel Zarembski |
0:0b221579ed52 | 38 | |
Pawel Zarembski |
0:0b221579ed52 | 39 | #endif // FXPQ3115_H_ |