blob: 469053a746b64fd5ca6fa51cf605cb93452b5d6e (
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
/*
* LocalFan.h
*
* Created on: 3 Sep 2019
* Author: David
*/
#ifndef SRC_FANS_LOCALFAN_H_
#define SRC_FANS_LOCALFAN_H_
#include "Fan.h"
class LocalFan : public Fan
{
public:
LocalFan(unsigned int fanNum) noexcept;
~LocalFan() noexcept;
bool Check(bool checkSensors) noexcept override; // update the fan PWM returning true if it is a thermostatic fan that is on
bool IsEnabled() const noexcept override { return port.IsValid(); }
int32_t GetRPM() const noexcept override;
float GetPwm() const noexcept override { return lastVal; }
GCodeResult SetPwmFrequency(PwmFrequency freq, const StringRef& reply) noexcept override;
GCodeResult ReportPortDetails(const StringRef& str) const noexcept override;
#if SUPPORT_CAN_EXPANSION
void UpdateFromRemote(CanAddress src, const FanReport& report) noexcept override { }
#endif
bool AssignPorts(const char *pinNames, const StringRef& reply) noexcept;
void Interrupt() noexcept;
protected:
GCodeResult Refresh(const StringRef& reply) noexcept override;
bool UpdateFanConfiguration(const StringRef& reply) noexcept override;
private:
void SetHardwarePwm(float pwmVal) noexcept;
void InternalRefresh(bool checkSensors) noexcept;
PwmPort port; // port used to control the fan
IoPort tachoPort; // port used to read the tacho
float lastPwm; // the last PWM value we wrote to the hardware
float lastVal; // the last PWM value we sent to the fan, not allowing for blipping, or -1 if we don't know it
// Variables used to read the tacho
static constexpr uint32_t fanMaxInterruptCount = 32; // number of fan interrupts that we average over
uint32_t fanInterruptCount; // accessed only in ISR, so no need to declare it volatile
volatile uint32_t fanLastResetTime; // time (in step clocks) at which we last reset the interrupt count, accessed inside and outside ISR
volatile uint32_t fanInterval; // written by ISR, read outside the ISR
uint32_t blipStartTime;
bool blipping;
};
#endif /* SRC_FANS_LOCALFAN_H_ */
|