aboutsummaryrefslogtreecommitdiff
path: root/platformio/common/libs/temphum/homekit/temphum.h
blob: 1952ce03d2bef0f5fa3510671ac0bc9032d93bd4 (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
#pragma once

#include <Wire.h>

namespace homekit::temphum {

struct SensorData {
    uint8_t error = 0;
    double temp = 0; // celsius
    double rh = 0; // relative humidity percentage
};


class Sensor {
protected:
    int dev_addr;
public:
    explicit Sensor(int dev) : dev_addr(dev) {}
    void setup() const;
    void writeCommand(int reg) const;
    virtual SensorData read() = 0;
};


class Si7021 : public Sensor {
public:
    SensorData read() override;
    Si7021() : Sensor(0x40) {}
};


class DHT12 : public Sensor {
public:
    SensorData read() override;
    DHT12() : Sensor(0x5c) {}
};

}