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