diff options
Diffstat (limited to 'src/Fan.cpp')
-rw-r--r-- | src/Fan.cpp | 47 |
1 files changed, 38 insertions, 9 deletions
diff --git a/src/Fan.cpp b/src/Fan.cpp index 4e66b713..1e638632 100644 --- a/src/Fan.cpp +++ b/src/Fan.cpp @@ -5,12 +5,14 @@ * Author: David */ -#include "Fan.h" #include "RepRapFirmware.h" void Fan::Init(Pin p_pin, bool hwInverted) { val = 0.0; + minVal = 0.1; // 10% minimum fan speed + blipTime = 100; // 100ms fan blip + blipStartTime = 0; freq = DefaultFanPwmFreq; pin = p_pin; hardwareInverted = hwInverted; @@ -26,10 +28,31 @@ void Fan::SetValue(float speed) { speed /= 255.0; } - val = constrain<float>(speed, 0.0, 1.0); + const float newVal = (speed > 0.0) ? constrain<float>(speed, minVal, 1.0) : 0.0; + if (val == 0.0 && newVal < 1.0 && blipTime != 0) + { + // Starting the fan from standstill, so blip the fan + blipStartTime = millis(); + } + val = newVal; Refresh(); } +void Fan::SetMinValue(float speed) +{ + if (speed > 1.0) + { + speed /= 255.0; + } + minVal = constrain<float>(speed, 0.0, 1.0); + Refresh(); +} + +void Fan::SetBlipTime(float t) +{ + blipTime = (uint32_t)(max<float>(t, 0.0) * SecondsToMillis); +} + void Fan::SetInverted(bool inv) { inverted = inv; @@ -63,22 +86,28 @@ void Fan::SetHeatersMonitored(uint16_t h) void Fan::Refresh() { - if (heatersMonitored != 0) + float reqVal = (heatersMonitored == 0) + ? val + : (reprap.GetPlatform()->AnyHeaterHot(heatersMonitored, triggerTemperature)) + ? max<float>(0.5, val) // make sure that thermostatic fans always run at 50% speed or more + : 0.0; + if (reqVal > 0.0 && millis() - blipStartTime < blipTime) + { + SetHardwarePwm(1.0); + } + else if (reqVal > 0.0 && reqVal < minVal) { - const float pwmVal = (reprap.GetPlatform()->AnyHeaterHot(heatersMonitored, triggerTemperature)) - ? max<float>(0.5, val) // make sure that thermostatic fans always run at 50% speed or more - : 0.0; - SetHardwarePwm(pwmVal); + SetHardwarePwm(minVal); } else { - SetHardwarePwm(val); + SetHardwarePwm(reqVal); } } void Fan::Check() { - if (heatersMonitored != 0) + if (heatersMonitored != 0 || blipTime != 0) { Refresh(); } |