diff options
author | Daniel Friesel <derf@finalrewind.org> | 2021-02-26 19:16:55 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2021-02-26 19:16:55 +0100 |
commit | bdb1590839e5962741140ce2f4db722219f9d6f6 (patch) | |
tree | db565f530096ad63c82640150718fb144c47d9c9 /src/driver/scd4x.cc | |
parent | 9a3d3bcc93f8cefea74af2a86b5834a57738e2c3 (diff) |
Add SCD4x driver and datalog integration
Diffstat (limited to 'src/driver/scd4x.cc')
-rw-r--r-- | src/driver/scd4x.cc | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/driver/scd4x.cc b/src/driver/scd4x.cc new file mode 100644 index 0000000..c0901e8 --- /dev/null +++ b/src/driver/scd4x.cc @@ -0,0 +1,40 @@ +/* + * Copyright 2021 Daniel Friesel + * + * SPDX-License-Identifier: BSD-2-Clause + */ +#include "driver/scd4x.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 + +void SCD4x::start() +{ + txbuf[0] = 0x21; + txbuf[1] = 0xb1; + i2c.xmit(address, 2, txbuf, 0, rxbuf); +} + +void SCD4x::stop() +{ + txbuf[0] = 0x3f; + txbuf[1] = 0x86; + i2c.xmit(address, 2, txbuf, 0, rxbuf); +} + +void SCD4x::read() +{ + txbuf[0] = 0xec; + txbuf[1] = 0x05; + + if (i2c.xmit(address, 1, txbuf, 9, rxbuf) == 0) { + co2 = (rxbuf[0] << 8) + rxbuf[1]; + rawTemperature = ((rxbuf[3] << 8) + rxbuf[4]); + rawHumidity = (rxbuf[6] << 8) + rxbuf[7]; + } +} + +SCD4x scd4x; |