-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfan.h
82 lines (54 loc) · 1.07 KB
/
fan.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
76
77
78
79
80
81
82
#ifndef __INCLUDED_FAN__
#define __INCLUDED_FAN__
#include <Arduino.h>
#include "sensor.h"
enum class Mode
{
Auto,
Low,
High,
Full,
};
const char* modeToStr(Mode mode);
// This can handle 2 tachometers
#define TACHOMETER_MAX 2
struct SpeedCurvePoint {
double temp;
uint8_t speed;// 0 -> 100
};
typedef SpeedCurvePoint SpeedCurve[];
struct FanDef{
const char* name;
uint8_t pin;
uint8_t tachoPin;
uint8_t sensorIndex;
SpeedCurvePoint* speedCurve;
uint8_t speedCurveLength;
bool kickStart;
};
class Fan {
public:
Fan(){};
Fan(const FanDef* _def, const Sensor* sensor);
uint8_t currentSpeed() const {
return speed;
}
void setSpeed(uint8_t speed);
void setModeSpeed(Mode mode);
bool hasTacho() const {
return def->tachoPin != (uint8_t)-1;
}
void resetTacho(){
*tachoCounter = 0;
tachoTimer = millis();
}
uint16_t getRPM() const;
const FanDef* def = nullptr;
const Sensor* sensor;
private:
unsigned long tachoTimer;
volatile uint32_t* tachoCounter;
uint8_t speed, minSpeed, maxSpeed;
uint8_t calcSpeed(double temp) const;
};
#endif