#define CCS811_ERRSTAT_FW_MODE 0x0080 // Firmware is in application mode (not boot mode)
#define CCS811_ERRSTAT_WRITE_REG_INVALID 0x0100 // The CCS811 received an I²C write request addressed to this station but with invalid register address ID
#define CCS811_ERRSTAT_READ_REG_INVALID 0x0200 // The CCS811 received an I²C read request to a mailbox ID that is invalid
#define CCS811_ERRSTAT_MEASMODE_INVALID 0x0400 // The CCS811 received an I²C request to write an unsupported mode to MEAS_MODE
#define CCS811_ERRSTAT_MAX_RESISTANCE 0x0800 // The sensor resistance measurement has reached or exceeded the maximum range
#define CCS811_ERRSTAT_HEATER_FAULT 0x1000 // The heater current in the CCS811 is not in range
#define CCS811_ERRSTAT_HEATER_SUPPLY 0x2000 // The heater voltage is not being applied correctly
// These flags should not be set. They flag errors.
CCS811(intnwake=-1,intslaveaddr=CCS811_SLAVEADDR_0);// Pin number connected to nWAKE (nWAKE can also be bound to GND, then pass -1), slave address (5A or 5B)
boolbegin(void);// Reset the CCS811, switch to app mode and check HW_ID. Returns false on problems.
boolstart(intmode);// Switched CCS811 to `mode`, use constants CCS811_MODE_XXX. Returns false on I2C problems.
voidread(uint16_t*eco2,uint16_t*etvoc,uint16_t*errstat,uint16_t*raw);// Get measurement results from the CCS811 (all args may be NULL), check status via errstat, e.g. ccs811_errstat(errstat)
constchar*errstat_str(uint16_terrstat);// Returns a string version of an errstat. Note, each call, this string is updated.
public:// Extra interface
inthardware_version(void);// Gets version of the CCS811 hardware (returns -1 on I2C failure)
intbootloader_version(void);// Gets version of the CCS811 bootloader (returns -1 on I2C failure)
intapplication_version(void);// Gets version of the CCS811 application (returns -1 on I2C failure)
intget_errorid(void);// Gets the ERROR_ID [same as 'err' part of 'errstat' in 'read'] (returns -1 on I2C failure)
boolset_envdata(uint16_tt,uint16_th);// Writes t and h to ENV_DATA (see datasheet for format). Returns false on I2C problems.
boolset_envdata210(uint16_tt,uint16_th);// Writes t and h (in ENS210 format) to ENV_DATA. Returns false on I2C problems.
boolget_baseline(uint16_t*baseline);// Reads (encoded) baseline from BASELINE. Returns false on I2C problems. Get it, just before power down (but only when sensor was on at least 20min) - see CCS811_AN000370
boolset_baseline(uint16_tbaseline);// Writes (encoded) baseline to BASELINE. Returns false on I2C problems. Set it, after power up (and after 20min)
boolflash(constuint8_t*image,intsize);// Flashes the firmware of the CCS811 with size bytes from image - image _must_ be in PROGMEM
public:// Advanced interface: i2cdelay
voidset_i2cdelay(intus);// Delay before a repeated start - needed for e.g. ESP8266 because it doesn't handle I2C clock stretch correctly
intget_i2cdelay(void);// Get current delay
protected:// Helper interface: nwake pin
voidwake_init(void);// Initialize nwake pin
voidwake_up(void);// Wake up CCS811, i.e. pull nwake pin low
voidwake_down(void);// CCS811 back to sleep, i.e. pull nwake pin high
protected:// Helper interface: i2c wrapper
booli2cwrite(intregaddr,intcount,constuint8_t*buf);// Writes `count` from `buf` to register at address `regaddr` in the CCS811. Returns false on I2C problems.
booli2cread(intregaddr,intcount,uint8_t*buf);// Reads 'count` bytes from register at address `regaddr`, and stores them in `buf`. Returns false on I2C problems.
private:
int_nwake;// Pin number for nWAKE pin (or -1)
int_slaveaddr;// Slave address of the CCS811
int_i2cdelay_us;// Delay in us just before an I2C repeated start condition
int_appversion;// Version of the app firmware inside the CCS811 (for workarounds)