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: ECE4180FinalProjectFall22
Diff: ens160_i2c.h
- Revision:
- 3:63ff52373e71
- Child:
- 4:cb50c2f7e2b2
diff -r 36abf8e18ade -r 63ff52373e71 ens160_i2c.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ens160_i2c.h Tue Dec 06 21:21:28 2022 +0000
@@ -0,0 +1,95 @@
+#include "ens160_i2c_regs.h"
+
+#define ENS160_ADDRESS_LOW 0x52
+#define ENS160_ADDRESS_HIGH 0x53
+
+#define ENS160_DEVICE_ID 0x0160
+
+class ENS160 {
+ public:
+ uint8_t i2c_address;
+ I2C i2c;
+ ENS160(PinName sda, PinName scl, uint8_t i2c_device_address);
+ bool ping(uint8_t address);
+
+ ///////////////////////////////////////////////////////////////////////
+ // init()
+ // Called to init the system. Connects to the device and sets it up for
+ // operation
+
+ bool init();
+
+ ///////////////////////////////////////////////////////////////////////
+ // isConnected()
+ // Parameter Description
+ // --------- -----------------------------
+ // retval true if device is connected, false if not connected
+
+ bool isConnected(); // Checks if sensor ack's the I2C request
+
+ //////////////////////////////////////////////////////////////////////////////////
+ // writeRegisterRegion()
+ // Parameter Description
+ // --------- -----------------------------
+ // reg register to write to
+ // data Array to store data in
+ // length Length of the data being written in bytes
+ // retval -1 = error, 0 = success
+
+ int32_t writeRegisterRegion(uint8_t *data, uint8_t length);
+ int32_t writeRegisterRegion(uint8_t reg, uint8_t data);
+
+ //////////////////////////////////////////////////////////////////////////////////
+ // readRegisterRegion()
+ // Parameter Description
+ // --------- -----------------------------
+ // reg register to read from
+ // data Array to store data in
+ // length Length of the data to read in bytes
+ // retval -1 = error, 0 = success
+
+ uint8_t readRegisterRegion(uint8_t reg, uint8_t *data, uint8_t length);
+
+ //////////////////////////////////////////////////////////////////////////////////
+ // General Operation
+ bool setOperatingMode(uint8_t);
+ int8_t getOperatingMode();
+ uint32_t getAppVer();
+ uint16_t getUniqueID();
+
+ //////////////////////////////////////////////////////////////////////////////////
+ // Interrupts
+ bool configureInterrupt(uint8_t);
+ bool enableInterrupt(bool enable = true);
+ bool setInterruptPolarity(bool activeHigh = true);
+ int8_t getInterruptPolarity();
+ bool setInterruptDrive(bool pushPull = true);
+ bool setDataInterrupt(bool enable = true);
+ bool setGPRInterrupt(bool);
+
+ //////////////////////////////////////////////////////////////////////////////////
+ // Temperature and Humidity compensation
+ bool setTempCompensation(float);
+ float getTempCompensation();
+ bool setTempCompensationCelsius(float);
+ float getTempCompensationCelsius();
+ bool setRHCompensation(uint16_t);
+ bool setRHCompensationFloat(float);
+
+ //////////////////////////////////////////////////////////////////////////////////
+ bool checkDataStatus();
+ bool checkGPRStatus();
+ uint8_t getFlags();
+ bool checkOperationStatus();
+ bool getOperationError();
+
+ //////////////////////////////////////////////////////////////////////////////////
+ // Data registers
+ uint8_t getAQI();
+ uint16_t getTVOC();
+ uint16_t getETOH();
+ uint16_t getECO2();
+ float getTempKelvin();
+ float getTempCelsius();
+ float getRH();
+};
