summaryrefslogtreecommitdiff
path: root/platformio/temphum/src/stopwatch.h
blob: bac2fccfae682d0e4e30a2b5e05973adb27446ed (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
#pragma once

#include <Arduino.h>

namespace homekit {

class StopWatch {
private:
    unsigned long time;

public:
    StopWatch() : time(0) {};

    inline void save() {
        time = millis();
    }

    inline bool elapsed(unsigned long ms) {
        unsigned long now = millis();
        if (now < time) {
            // rollover?
            time = now;
        } else if (now - time >= ms) {
            return true;
        }
        return false;
    }
};

}