Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Grove-Barometric_Pressure_Sensor_Example
HP206C.h@2:8f5aa7475f97, 2019-06-25 (annotated)
- Committer:
- pmic
- Date:
- Tue Jun 25 13:40:46 2019 +0000
- Revision:
- 2:8f5aa7475f97
- Parent:
- 1:c5247b2ef5af
- Child:
- 3:dd1c93488020
there is an output (not checked if it is something useful yet)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pmic | 1:c5247b2ef5af | 1 | #ifndef _HP206C |
pmic | 1:c5247b2ef5af | 2 | #define _HP206C |
pmic | 1:c5247b2ef5af | 3 | |
pmic | 1:c5247b2ef5af | 4 | #include "mbed.h" |
pmic | 1:c5247b2ef5af | 5 | |
pmic | 1:c5247b2ef5af | 6 | #define I2C_BAROMETER_ADDRESS 0x76 << 1 // 0xEC, device adress |
pmic | 1:c5247b2ef5af | 7 | |
pmic | 1:c5247b2ef5af | 8 | #define HP20X_SOFT_RST 0x06 // for initializing, takes longer than next |
pmic | 1:c5247b2ef5af | 9 | #define HP20X_ANA_CAL 0x28 // recalibrate analog internal circuitries, for unstable environment |
pmic | 1:c5247b2ef5af | 10 | |
pmic | 1:c5247b2ef5af | 11 | #define HP20X_WR_CONVERT_CMD 0x40 |
pmic | 1:c5247b2ef5af | 12 | |
pmic | 1:c5247b2ef5af | 13 | #define HP20X_READ_PT 0x10 // read pressure and altitude command |
pmic | 1:c5247b2ef5af | 14 | #define HP20X_READ_A 0x31 // read altitude command |
pmic | 1:c5247b2ef5af | 15 | |
pmic | 1:c5247b2ef5af | 16 | #define HP20X_WR_REG_MODE 0xC0 |
pmic | 1:c5247b2ef5af | 17 | #define HP20X_RD_REG_MODE 0x80 |
pmic | 1:c5247b2ef5af | 18 | |
pmic | 1:c5247b2ef5af | 19 | #define HP20X_OK_DEV 0X80 // successfully initialized |
pmic | 1:c5247b2ef5af | 20 | #define HP20X_REG_PARA 0X0F // status register |
pmic | 1:c5247b2ef5af | 21 | |
pmic | 1:c5247b2ef5af | 22 | #define HP20X_CONVERT_OSR4096 0 << 2 |
pmic | 1:c5247b2ef5af | 23 | #define HP20X_CONVERT_OSR2048 1 << 2 |
pmic | 1:c5247b2ef5af | 24 | #define HP20X_CONVERT_OSR1024 2 << 2 |
pmic | 1:c5247b2ef5af | 25 | #define HP20X_CONVERT_OSR512 3 << 2 |
pmic | 1:c5247b2ef5af | 26 | #define HP20X_CONVERT_OSR256 4 << 2 |
pmic | 1:c5247b2ef5af | 27 | #define HP20X_CONVERT_OSR128 5 << 2 |
pmic | 1:c5247b2ef5af | 28 | |
pmic | 1:c5247b2ef5af | 29 | #define OSR_CFG HP20X_CONVERT_OSR1024 |
pmic | 1:c5247b2ef5af | 30 | |
pmic | 1:c5247b2ef5af | 31 | class HP206C |
pmic | 1:c5247b2ef5af | 32 | { |
pmic | 1:c5247b2ef5af | 33 | public: |
pmic | 1:c5247b2ef5af | 34 | |
pmic | 1:c5247b2ef5af | 35 | HP206C(PinName p_sda, PinName p_scl); |
pmic | 1:c5247b2ef5af | 36 | /* |
pmic | 1:c5247b2ef5af | 37 | float operator()() |
pmic | 1:c5247b2ef5af | 38 | { |
pmic | 1:c5247b2ef5af | 39 | return performMeasAndgetAltitude(); |
pmic | 1:c5247b2ef5af | 40 | } |
pmic | 1:c5247b2ef5af | 41 | */ |
pmic | 1:c5247b2ef5af | 42 | virtual ~HP206C(); |
pmic | 1:c5247b2ef5af | 43 | |
pmic | 1:c5247b2ef5af | 44 | void reset(); |
pmic | 1:c5247b2ef5af | 45 | |
pmic | 2:8f5aa7475f97 | 46 | float measureAndreadAltitude(); |
pmic | 1:c5247b2ef5af | 47 | float readTemperature(); |
pmic | 1:c5247b2ef5af | 48 | float readPressure(); |
pmic | 1:c5247b2ef5af | 49 | |
pmic | 1:c5247b2ef5af | 50 | private: |
pmic | 1:c5247b2ef5af | 51 | |
pmic | 1:c5247b2ef5af | 52 | I2C i2c; |
pmic | 1:c5247b2ef5af | 53 | |
pmic | 1:c5247b2ef5af | 54 | float temperature; |
pmic | 1:c5247b2ef5af | 55 | float pressure; |
pmic | 1:c5247b2ef5af | 56 | float altitude; |
pmic | 1:c5247b2ef5af | 57 | bool baro_found; |
pmic | 1:c5247b2ef5af | 58 | |
pmic | 1:c5247b2ef5af | 59 | unsigned char readRegister(unsigned char reg); |
pmic | 1:c5247b2ef5af | 60 | void writeRegister(unsigned char reg, unsigned char data); |
pmic | 1:c5247b2ef5af | 61 | void enableCompensation(); |
pmic | 1:c5247b2ef5af | 62 | void disableCompensation(); |
pmic | 1:c5247b2ef5af | 63 | void softReset(); |
pmic | 1:c5247b2ef5af | 64 | void recalibrate(); |
pmic | 1:c5247b2ef5af | 65 | uint32_t readData3Bytes(); |
pmic | 2:8f5aa7475f97 | 66 | // uint32_t *readData6Bytes(); |
pmic | 1:c5247b2ef5af | 67 | void readTemperatureAndPressureStep1(); |
pmic | 2:8f5aa7475f97 | 68 | // void readTemperatureAndPressureStep2(); |
pmic | 1:c5247b2ef5af | 69 | void readAltitude(); |
pmic | 1:c5247b2ef5af | 70 | uint8_t getConversionTime(); |
pmic | 1:c5247b2ef5af | 71 | |
pmic | 1:c5247b2ef5af | 72 | }; |
pmic | 1:c5247b2ef5af | 73 | |
pmic | 1:c5247b2ef5af | 74 | #endif |