-
Notifications
You must be signed in to change notification settings - Fork 71
/
Alarm.h
73 lines (56 loc) · 1.58 KB
/
Alarm.h
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
64
65
66
67
68
69
70
71
72
73
//- -----------------------------------------------------------------------------------------------------------------------
// AskSin++
// 2016-10-31 papa Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/
//- -----------------------------------------------------------------------------------------------------------------------
#ifndef __ALARM_H__
#define __ALARM_H__
#include "Link.h"
namespace as {
class AlarmClock;
class Alarm: public Link {
enum { ASYNC=0x01, ACTIVE=0x02 };
protected:
~Alarm() {}
uint8_t flags;
public:
void setflag(bool c,uint8_t mask) { c ? flags |= mask : flags &= ~mask; }
void setflag(uint8_t mask) { flags |= mask; }
void remflag(uint8_t mask) { flags &= ~mask; }
bool hasflag(uint8_t mask) const { return (flags & mask) == mask; }
public:
uint32_t tick : 24;
virtual void trigger(AlarmClock&) = 0;
Alarm () : flags(0), tick(0) {}
Alarm(uint32_t t) : flags(0), tick(t) {}
Alarm(uint32_t t,bool asynch) : flags(0), tick(t) {
async(asynch);
}
void set(uint32_t t) {
tick = t;
}
void async(bool value) {
setflag(value, ASYNC);
}
bool async() const {
return hasflag(ASYNC);
}
void active(bool value) {
setflag(value,ACTIVE);
}
bool active () const {
return hasflag(ACTIVE);
}
};
class RTCAlarm : public Alarm {
public:
uint16_t millis;
protected:
~RTCAlarm() {}
bool delayMillis ();
public:
RTCAlarm() : Alarm(0), millis(0) {}
RTCAlarm(uint32_t t,uint16_t m) : Alarm(t), millis(m) {}
RTCAlarm(uint32_t t,uint16_t m,bool asynch) : Alarm(t,asynch), millis(m) {}
};
}
#endif