-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPump.h
75 lines (61 loc) · 1.13 KB
/
Pump.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
74
75
/*
* Pump.h
*
* Created on: 11 Nov 2014
* Author: pdavies
*/
#include <Arduino.h>
#include "Constants.h"
#include "sharedVars.h"
#ifndef PUMP_H_
#define PUMP_H_
class Pump {
private:
bool enabled;
bool offActionsDone;
uint64_t secondPumpStopped;
public:
int16_t leakyBucket;
int16_t prevBucket;
Pump() {
prevBucket = leakyBucket = 0;
enabled = true;
secondPumpStopped = 0;
}
virtual ~Pump() {
}
/**
* Capped at 512
*/
void requestMinSpeed(int16_t speed) {
prevBucket = leakyBucket;
leakyBucket = min(512, max(leakyBucket, speed));
if (prevBucket == 0 && leakyBucket > 0) {
offActionsDone = false;
}
}
bool isRunning() {
return getEffectiveMotorSpeed() > 0;
}
uint16_t getEffectiveMotorSpeed() {
return enabled ? leakyBucket : 0;
}
bool doOffActions(uint64_t numSeconds) {
if (!offActionsDone && beenOffForSeconds() > numSeconds) {
return offActionsDone = true;
}
return false;
}
uint64_t beenOffForSeconds();
void tick();
bool requested() {
return leakyBucket > 0;
}
void enable() {
enabled = true;
}
void disable() {
enabled = false;
}
};
#endif /* PUMP_H_ */