summaryrefslogtreecommitdiff
path: root/src/driver
diff options
context:
space:
mode:
Diffstat (limited to 'src/driver')
-rw-r--r--src/driver/hdc1080.cc51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/driver/hdc1080.cc b/src/driver/hdc1080.cc
new file mode 100644
index 0000000..8da2ba7
--- /dev/null
+++ b/src/driver/hdc1080.cc
@@ -0,0 +1,51 @@
+#include "driver/hdc1080.h"
+#include "arch.h"
+#if defined(MULTIPASS_ARCH_HAS_I2C) && !defined(DRIVER_SOFTI2C)
+#include "driver/i2c.h"
+#else
+#include "driver/soft_i2c.h"
+#endif
+
+float HDC1080::getTemp()
+{
+ txbuf[0] = 0x00;
+
+ i2c.xmit(address, 1, txbuf, 0, rxbuf);
+
+ arch.delay_ms(10);
+
+ i2c.xmit(address, 0, txbuf, 2, rxbuf);
+
+ return (((unsigned int)rxbuf[0] << 8) | rxbuf[1]) * .00251770019531250000 - 40.;
+}
+
+float HDC1080::getRH()
+{
+ txbuf[0] = 0x01;
+
+ i2c.xmit(address, 1, txbuf, 0, rxbuf);
+
+ arch.delay_ms(10);
+
+ i2c.xmit(address, 0, txbuf, 2, rxbuf);
+
+ return (((unsigned int)rxbuf[0] << 8) | rxbuf[1]) * .00152587890625000000;
+}
+
+unsigned int HDC1080::getManufacturerID()
+{
+ txbuf[0] = 0xfe;
+ i2c.xmit(address, 1, txbuf, 2, rxbuf);
+ return (unsigned int)rxbuf[0] << 8 | rxbuf[1];
+}
+
+void HDC1080::init()
+{
+ txbuf[0] = 0x02;
+ txbuf[1] = 0x08;
+ txbuf[2] = 0x00;
+ i2c.xmit(address, 3, txbuf, 0, rxbuf);
+ arch.delay_ms(15);
+}
+
+HDC1080 hdc1080;