Generic Si7021 Temp/Hum sensor library
Dependents: Turtle_RadioShuttle
HELIOS_Si7021.h@1:5ea2d9a2ef8c, 2019-03-29 (annotated)
- Committer:
- Helmut64
- Date:
- Fri Mar 29 13:32:00 2019 +0000
- Revision:
- 1:5ea2d9a2ef8c
- Parent:
- 0:19633f4a946b
Updated type
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Helmut64 | 1:5ea2d9a2ef8c | 1 | /* |
Helmut64 | 1:5ea2d9a2ef8c | 2 | * Copyright (c) 2019 Helmut Tschemernjak |
Helmut64 | 1:5ea2d9a2ef8c | 3 | * 30826 Garbsen (Hannover) Germany |
Helmut64 | 1:5ea2d9a2ef8c | 4 | * Licensed under the Apache License, Version 2.0); |
Helmut64 | 1:5ea2d9a2ef8c | 5 | */ |
Helmut64 | 1:5ea2d9a2ef8c | 6 | |
Helmut64 | 1:5ea2d9a2ef8c | 7 | #ifndef __HELIOS_Si7021_H__ |
Helmut64 | 1:5ea2d9a2ef8c | 8 | #define __HELIOS_Si7021_H__ |
Helmut64 | 1:5ea2d9a2ef8c | 9 | |
Helmut64 | 1:5ea2d9a2ef8c | 10 | class HELIOS_Si7021 { |
Helmut64 | 1:5ea2d9a2ef8c | 11 | public: |
Helmut64 | 1:5ea2d9a2ef8c | 12 | HELIOS_Si7021(PinName sda, PinName scl); |
Helmut64 | 1:5ea2d9a2ef8c | 13 | ~HELIOS_Si7021(); |
Helmut64 | 0:19633f4a946b | 14 | |
Helmut64 | 1:5ea2d9a2ef8c | 15 | void reset(void); |
Helmut64 | 1:5ea2d9a2ef8c | 16 | void readSerialNumber(void); |
Helmut64 | 1:5ea2d9a2ef8c | 17 | uint8_t getRevision(void) { return _revision; }; |
Helmut64 | 1:5ea2d9a2ef8c | 18 | bool hasSensor(void) { return _foundDevice; }; |
Helmut64 | 1:5ea2d9a2ef8c | 19 | |
Helmut64 | 1:5ea2d9a2ef8c | 20 | float readTemperature(void); |
Helmut64 | 1:5ea2d9a2ef8c | 21 | float readHumidity(void); |
Helmut64 | 1:5ea2d9a2ef8c | 22 | |
Helmut64 | 1:5ea2d9a2ef8c | 23 | enum sensorType { |
Helmut64 | 1:5ea2d9a2ef8c | 24 | SI_Engineering_Samples, |
Helmut64 | 1:5ea2d9a2ef8c | 25 | SI_7013, |
Helmut64 | 1:5ea2d9a2ef8c | 26 | SI_7020, |
Helmut64 | 1:5ea2d9a2ef8c | 27 | SI_7021, |
Helmut64 | 1:5ea2d9a2ef8c | 28 | SI_unkown, |
Helmut64 | 1:5ea2d9a2ef8c | 29 | }; |
Helmut64 | 1:5ea2d9a2ef8c | 30 | const char *getModelName(void); |
Helmut64 | 1:5ea2d9a2ef8c | 31 | sensorType getModel(void); |
Helmut64 | 1:5ea2d9a2ef8c | 32 | |
Helmut64 | 1:5ea2d9a2ef8c | 33 | private: |
Helmut64 | 1:5ea2d9a2ef8c | 34 | I2C *_i2c; |
Helmut64 | 1:5ea2d9a2ef8c | 35 | char _data[8]; |
Helmut64 | 1:5ea2d9a2ef8c | 36 | |
Helmut64 | 1:5ea2d9a2ef8c | 37 | bool _foundDevice; |
Helmut64 | 1:5ea2d9a2ef8c | 38 | void _readRevision(void); |
Helmut64 | 1:5ea2d9a2ef8c | 39 | uint32_t sernum_a, sernum_b; |
Helmut64 | 1:5ea2d9a2ef8c | 40 | sensorType _model; |
Helmut64 | 1:5ea2d9a2ef8c | 41 | uint8_t _revision; |
Helmut64 | 1:5ea2d9a2ef8c | 42 | uint8_t _readRegister8(uint8_t reg); |
Helmut64 | 1:5ea2d9a2ef8c | 43 | uint16_t _readRegister16(uint8_t reg); |
Helmut64 | 1:5ea2d9a2ef8c | 44 | void _writeRegister8(uint8_t reg, uint8_t value); |
Helmut64 | 1:5ea2d9a2ef8c | 45 | const static uint8_t _i2caddr = 0x40 << 1; // convert from 7 to 8 bit. |
Helmut64 | 1:5ea2d9a2ef8c | 46 | const static int _TRANSACTION_TIMEOUT = 100; // Wire NAK/Busy timeout in ms |
Helmut64 | 1:5ea2d9a2ef8c | 47 | }; |
Helmut64 | 1:5ea2d9a2ef8c | 48 | |
Helmut64 | 1:5ea2d9a2ef8c | 49 | /**************************************************************************/ |
Helmut64 | 1:5ea2d9a2ef8c | 50 | |
Helmut64 | 1:5ea2d9a2ef8c | 51 | #endif // __HELIOS_Si7021_H__ |
Helmut64 | 1:5ea2d9a2ef8c | 52 |