summaryrefslogtreecommitdiff
path: root/src/driver/hdc1080.cc
blob: 26c97ef2a1de6b82d0eaf692d3dda4350ff59daa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#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::heater(bool on)
{
	txbuf[0] = 0x02;
	i2c.xmit(address, 1, txbuf, 2, rxbuf);
	if (on) {
		txbuf[1] = rxbuf[0] | (1<<5);
	} else {
		txbuf[1] = rxbuf[0] & ~(1<<5);
	}
	i2c.xmit(address, 2, txbuf, 0, rxbuf);
}

void HDC1080::init()
{
	txbuf[0] = 0x02;
	txbuf[1] = 0x00;
	txbuf[2] = 0x00;
	i2c.xmit(address, 3, txbuf, 0, rxbuf);
	arch.delay_ms(15);
}

HDC1080 hdc1080;