diff options
Diffstat (limited to 'src/driver/ccs811.cc')
-rw-r--r-- | src/driver/ccs811.cc | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/driver/ccs811.cc b/src/driver/ccs811.cc new file mode 100644 index 0000000..a2b3940 --- /dev/null +++ b/src/driver/ccs811.cc @@ -0,0 +1,29 @@ +#include "driver/ccs811.h" +#include "driver/gpio.h" +#if defined(MULTIPASS_ARCH_HAS_I2C) && !defined(DRIVER_SOFTI2C) +#include "driver/i2c.h" +#else +#include "driver/soft_i2c.h" +#endif + +#ifdef MULTIPASS_ARCH_esp8266 +#define nWAKE GPIO::d5 +#endif + +void CCS811::init() +{ + gpio.output(nWAKE); + gpio.write(nWAKE, 1); +} + +short CCS811::check() +{ + gpio.write(nWAKE, 0); + txbuf[0] = 0x20; + rxbuf[0] = 0; + i2c.xmit(address, 1, txbuf, 1, rxbuf); + gpio.write(nWAKE, 1); + return rxbuf[0]; +} + +CCS811 ccs811(0x5a); |