Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src/Fans
diff options
context:
space:
mode:
authorDavid Crocker <dcrocker@eschertech.com>2020-04-30 14:37:25 +0300
committerDavid Crocker <dcrocker@eschertech.com>2020-04-30 14:37:25 +0300
commit500c6eb865dcb1cc246874da5c187424ffc5dc51 (patch)
treeb17c623c183b477d0b9cdd54508528a8ccae71a4 /src/Fans
parent6f912e9ca47930d7b91d504c0e9c8be31251284a (diff)
Various changes for 3.01-RC11
Changes for new interface to Bitmap::Iterate Duet3 expansion boards now report fan PWM Increased SBC SPI connection timeout to 8 seconds Pass G29 commands to SBC
Diffstat (limited to 'src/Fans')
-rw-r--r--src/Fans/Fan.cpp7
-rw-r--r--src/Fans/Fan.h8
-rw-r--r--src/Fans/FansManager.cpp4
-rw-r--r--src/Fans/FansManager.h4
-rw-r--r--src/Fans/LocalFan.cpp3
-rw-r--r--src/Fans/LocalFan.h6
-rw-r--r--src/Fans/RemoteFan.cpp27
-rw-r--r--src/Fans/RemoteFan.h11
8 files changed, 36 insertions, 34 deletions
diff --git a/src/Fans/Fan.cpp b/src/Fans/Fan.cpp
index 3f3c9320..31ab7c6d 100644
--- a/src/Fans/Fan.cpp
+++ b/src/Fans/Fan.cpp
@@ -23,7 +23,7 @@ constexpr ObjectModelTableEntry Fan::objectModelTable[] =
{
// Within each group, these entries must be in alphabetical order
// 0. Fan members
- { "actualValue", OBJECT_MODEL_FUNC(self->lastVal, 2), ObjectModelEntryFlags::live },
+ { "actualValue", OBJECT_MODEL_FUNC(self->GetPwm(), 2), ObjectModelEntryFlags::live },
{ "blip", OBJECT_MODEL_FUNC(0.001f * (float)self->blipTime, 2), ObjectModelEntryFlags::none },
// TODO add frequency here
{ "max", OBJECT_MODEL_FUNC(self->maxVal, 2), ObjectModelEntryFlags::none },
@@ -47,7 +47,7 @@ DEFINE_GET_OBJECT_MODEL_TABLE(Fan)
Fan::Fan(unsigned int fanNum) noexcept
: fanNumber(fanNum),
- val(0.0), lastVal(-1.0),
+ val(0.0),
minVal(DefaultMinFanPwm),
maxVal(1.0), // 100% maximum fan speed
blipTime(DefaultFanBlipTime)
@@ -169,8 +169,9 @@ bool Fan::Configure(unsigned int mcode, size_t fanNum, GCodeBuffer& gb, const St
if (sensorsMonitored.IsNonEmpty())
{
reply.catf(", temperature: %.1f:%.1fC, sensors:", (double)triggerTemperatures[0], (double)triggerTemperatures[1]);
- sensorsMonitored.Iterate([&reply](unsigned int sensorNum, bool) noexcept { reply.catf(" %u", sensorNum); });
+ sensorsMonitored.Iterate([&reply](unsigned int sensorNum, unsigned int) noexcept { reply.catf(" %u", sensorNum); });
reply.cat(", current speed: ");
+ const float lastVal = GetPwm();
if (lastVal >= 0.0)
{
reply.catf("%d%%:", (int)(lastVal * 100.0));
diff --git a/src/Fans/Fan.h b/src/Fans/Fan.h
index 2539ed5a..1444aa0b 100644
--- a/src/Fans/Fan.h
+++ b/src/Fans/Fan.h
@@ -14,7 +14,7 @@
#include "GCodes/GCodeResult.h"
#if SUPPORT_CAN_EXPANSION
-# include "CanId.h"
+# include <CanMessageFormats.h>
#endif
class GCodeBuffer;
@@ -30,9 +30,10 @@ public:
virtual GCodeResult SetPwmFrequency(PwmFrequency freq, const StringRef& reply) noexcept = 0;
virtual bool IsEnabled() const noexcept = 0;
virtual int32_t GetRPM() const noexcept = 0;
+ virtual float GetPwm() const noexcept = 0;
virtual GCodeResult ReportPortDetails(const StringRef& str) const noexcept = 0;
#if SUPPORT_CAN_EXPANSION
- virtual void UpdateRpmFromRemote(CanAddress src, int32_t rpm) noexcept = 0;
+ virtual void UpdateFromRemote(CanAddress src, const FanReport& report) noexcept = 0;
#endif
// Set or report the parameters for this fan
@@ -55,7 +56,7 @@ public:
protected:
DECLARE_OBJECT_MODEL
- static constexpr uint32_t RpmReadingTimeout = 2000; // any reading older than this number of milliseconds is considered unreliable
+ static constexpr uint32_t FanReportTimeout = 2000; // any reading older than this number of milliseconds is considered unreliable
virtual GCodeResult Refresh(const StringRef& reply) noexcept = 0;
virtual bool UpdateFanConfiguration(const StringRef& reply) noexcept = 0;
@@ -64,7 +65,6 @@ protected:
// Variables that control the fan
float val; // the value requested in the M106 command
- float lastVal; // the last PWM value we sent to the fan, not allowing for blipping, or -1 if we don't know it
float minVal;
float maxVal;
float triggerTemperatures[2];
diff --git a/src/Fans/FansManager.cpp b/src/Fans/FansManager.cpp
index f2918909..e6752828 100644
--- a/src/Fans/FansManager.cpp
+++ b/src/Fans/FansManager.cpp
@@ -233,7 +233,7 @@ void FansManager::Init() noexcept
#if SUPPORT_CAN_EXPANSION
-void FansManager::ProcessRemoteFanRpms(CanAddress src, const CanMessageFanRpms& msg) noexcept
+void FansManager::ProcessRemoteFanRpms(CanAddress src, const CanMessageFansReport& msg) noexcept
{
size_t numFansProcessed = 0;
uint64_t whichFans = msg.whichFans;
@@ -243,7 +243,7 @@ void FansManager::ProcessRemoteFanRpms(CanAddress src, const CanMessageFanRpms&
auto fan = FindFan(fanNum);
if (fan.IsNotNull())
{
- fan->UpdateRpmFromRemote(src, msg.fanRpms[numFansProcessed]);
+ fan->UpdateFromRemote(src, msg.fanReports[numFansProcessed]);
}
++numFansProcessed;
whichFans &= ~((uint64_t)1 << fanNum);
diff --git a/src/Fans/FansManager.h b/src/Fans/FansManager.h
index 850e24aa..b25ce186 100644
--- a/src/Fans/FansManager.h
+++ b/src/Fans/FansManager.h
@@ -15,7 +15,7 @@
#if SUPPORT_CAN_EXPANSION
# include <CanId.h>
-struct CanMessageFanRpms;
+struct CanMessageFansReport;
#endif
class GCodeBuffer;
@@ -38,7 +38,7 @@ public:
const char *GetFanName(size_t fanNum) const noexcept;
int32_t GetFanRPM(size_t fanNum) const noexcept;
#if SUPPORT_CAN_EXPANSION
- void ProcessRemoteFanRpms(CanAddress src, const CanMessageFanRpms& msg) noexcept;
+ void ProcessRemoteFanRpms(CanAddress src, const CanMessageFansReport& msg) noexcept;
#endif
#if HAS_MASS_STORAGE
bool WriteFanSettings(FileStore *f) const noexcept;
diff --git a/src/Fans/LocalFan.cpp b/src/Fans/LocalFan.cpp
index aa6ab24d..8d57c0a7 100644
--- a/src/Fans/LocalFan.cpp
+++ b/src/Fans/LocalFan.cpp
@@ -22,6 +22,7 @@ void FanInterrupt(CallbackParameter cb) noexcept
LocalFan::LocalFan(unsigned int fanNum) noexcept
: Fan(fanNum),
lastPwm(-1.0), // force a refresh
+ lastVal(-1.0),
fanInterruptCount(0), fanLastResetTime(0), fanInterval(0),
blipping(false)
{
@@ -90,7 +91,7 @@ void LocalFan::InternalRefresh(bool checkSensors) noexcept
#if HAS_SMART_DRIVERS
, &driverChannelsMonitored
#endif
- ](unsigned int sensorNum, bool) noexcept
+ ](unsigned int sensorNum, unsigned int) noexcept
{
const auto sensor = reprap.GetHeat().FindSensor(sensorNum);
if (sensor.IsNotNull())
diff --git a/src/Fans/LocalFan.h b/src/Fans/LocalFan.h
index e1683a6a..469053a7 100644
--- a/src/Fans/LocalFan.h
+++ b/src/Fans/LocalFan.h
@@ -19,11 +19,12 @@ public:
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 UpdateRpmFromRemote(CanAddress src, int32_t rpm) noexcept override { }
+ void UpdateFromRemote(CanAddress src, const FanReport& report) noexcept override { }
#endif
bool AssignPorts(const char *pinNames, const StringRef& reply) noexcept;
@@ -41,7 +42,8 @@ private:
PwmPort port; // port used to control the fan
IoPort tachoPort; // port used to read the tacho
- float lastPwm;
+ 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
diff --git a/src/Fans/RemoteFan.cpp b/src/Fans/RemoteFan.cpp
index e2ba74aa..c2d860cc 100644
--- a/src/Fans/RemoteFan.cpp
+++ b/src/Fans/RemoteFan.cpp
@@ -15,8 +15,8 @@
RemoteFan::RemoteFan(unsigned int fanNum, CanAddress boardNum) noexcept
: Fan(fanNum),
- lastRpm(-1), whenLastRpmReceived(0),
- boardNumber(boardNum), thermostaticFanRunning(false)
+ lastRpm(-1), lastPwm(-1.0), whenLastReportReceived(0),
+ boardNumber(boardNum)
{
}
@@ -37,7 +37,12 @@ RemoteFan::~RemoteFan() noexcept
bool RemoteFan::Check(bool checkSensors) noexcept
{
- return thermostaticFanRunning;
+ if (millis() - whenLastReportReceived > FanReportTimeout)
+ {
+ lastRpm = -1;
+ lastPwm = -1.0;
+ }
+ return sensorsMonitored.IsNonEmpty() && lastPwm > 0.0;
}
bool RemoteFan::IsEnabled() const noexcept
@@ -53,21 +58,13 @@ GCodeResult RemoteFan::SetPwmFrequency(PwmFrequency freq, const StringRef& reply
return cons.SendAndGetResponse(CanMessageType::m950Fan, boardNumber, reply);
}
-int32_t RemoteFan::GetRPM() const noexcept
-{
- if (millis() - whenLastRpmReceived > RpmReadingTimeout)
- {
- lastRpm = -1;
- }
- return lastRpm;
-}
-
-void RemoteFan::UpdateRpmFromRemote(CanAddress src, int32_t rpm) noexcept
+void RemoteFan::UpdateFromRemote(CanAddress src, const FanReport& report) noexcept
{
if (src == boardNumber)
{
- lastRpm = rpm;
- whenLastRpmReceived = millis();
+ lastPwm = (report.actualPwm < 0) ? -1.0 : (float)report.actualPwm * (1.0/65535);
+ lastRpm = report.rpm;
+ whenLastReportReceived = millis();
}
}
diff --git a/src/Fans/RemoteFan.h b/src/Fans/RemoteFan.h
index 331c9460..165d7534 100644
--- a/src/Fans/RemoteFan.h
+++ b/src/Fans/RemoteFan.h
@@ -22,10 +22,11 @@ public:
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;
- int32_t GetRPM() const noexcept override;
+ int32_t GetRPM() const noexcept override { return lastRpm; }
+ float GetPwm() const noexcept override { return lastPwm; }
GCodeResult SetPwmFrequency(PwmFrequency freq, const StringRef& reply) noexcept override;
GCodeResult ReportPortDetails(const StringRef& str) const noexcept override;
- void UpdateRpmFromRemote(CanAddress src, int32_t rpm) noexcept override;
+ void UpdateFromRemote(CanAddress src, const FanReport& report) noexcept override;
GCodeResult ConfigurePort(const char *pinNames, PwmFrequency freq, const StringRef& reply) noexcept;
@@ -34,10 +35,10 @@ protected:
GCodeResult Refresh(const StringRef& reply) noexcept override;
private:
- mutable int32_t lastRpm;
- uint32_t whenLastRpmReceived;
+ int32_t lastRpm;
+ float lastPwm;
+ uint32_t whenLastReportReceived;
CanAddress boardNumber;
- bool thermostaticFanRunning;
};
#endif