blob: 3d8f3735634e4442c4bda5997d48cd52803baa74 (
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
|
#pragma once
#include <Wire.h>
namespace homekit::temphum {
struct SensorData {
double temp = 0; // celsius
double rh = 0; // relative humidity percentage
};
class BaseSensor {
protected:
int dev_addr;
public:
explicit BaseSensor(int dev) : dev_addr(dev) {}
void setup() const;
void writeCommand(int reg) const;
virtual SensorData read() = 0;
};
class Si7021 : public BaseSensor {
public:
SensorData read() override;
Si7021() : BaseSensor(0x40) {}
};
class DHT12 : public BaseSensor {
public:
SensorData read() override;
DHT12() : BaseSensor(0x5c) {}
};
}
|