diff options
author | David Crocker <dcrocker@eschertech.com> | 2022-09-30 12:43:36 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2022-09-30 12:43:36 +0300 |
commit | 5f2f1eb4a091f0e7867352d6ad5c7fce8ae25e14 (patch) | |
tree | 6325e7a43072d599bcfbed52357531c9efcd9281 | |
parent | d99bf2aec4f548847a5031cfcb1e7492ee273cf0 (diff) |
Refactored M570 handling in preparation for new R parameter
-rw-r--r-- | src/Heating/Heat.cpp | 15 | ||||
-rw-r--r-- | src/Heating/Heater.cpp | 28 | ||||
-rw-r--r-- | src/Heating/Heater.h | 10 | ||||
-rw-r--r-- | src/Heating/HeaterMonitor.cpp | 4 | ||||
-rw-r--r-- | src/Heating/HeaterMonitor.h | 2 | ||||
-rw-r--r-- | src/Heating/LocalHeater.cpp | 4 | ||||
-rw-r--r-- | src/Heating/Sensors/DhtSensor.cpp | 2 |
7 files changed, 34 insertions, 31 deletions
diff --git a/src/Heating/Heat.cpp b/src/Heating/Heat.cpp index 178b4d46..37a131f8 100644 --- a/src/Heating/Heat.cpp +++ b/src/Heating/Heat.cpp @@ -931,18 +931,7 @@ GCodeResult Heat::ConfigureHeaterMonitoring(size_t heater, GCodeBuffer& gb, cons return GCodeResult::error; } - bool seenValue = false; - float maxTempExcursion, maxFaultTime; - h->GetFaultDetectionParameters(maxTempExcursion, maxFaultTime); - gb.TryGetFValue('P', maxFaultTime, seenValue); - gb.TryGetFValue('T', maxTempExcursion, seenValue); - if (seenValue) - { - return h->SetFaultDetectionParameters(maxTempExcursion, maxFaultTime, reply); - } - - reply.printf("Heater %u allowed excursion %.1f" DEGREE_SYMBOL "C, fault trigger time %.1f seconds", heater, (double)maxTempExcursion, (double)maxFaultTime); - return GCodeResult::ok; + return h->ConfigureFaultDetectionParameters(gb, reply); } // Process M303 @@ -1450,7 +1439,7 @@ GCodeResult Heat::SetFaultDetection(const CanMessageSetHeaterFaultDetectionParam { const auto h = FindHeater(msg.heater); return (h.IsNotNull()) - ? h->SetFaultDetectionParameters(msg.maxTempExcursion, msg.maxFaultTime, reply) + ? h->SetFaultDetectionParameters(msg, reply) : UnknownHeater(msg.heater, reply); } diff --git a/src/Heating/Heater.cpp b/src/Heating/Heater.cpp index 4e7cde41..19017fa5 100644 --- a/src/Heating/Heater.cpp +++ b/src/Heating/Heater.cpp @@ -109,7 +109,7 @@ Heater::HeaterParameters Heater::fanOffParams, Heater::fanOnParams; Heater::Heater(unsigned int num) noexcept : tuned(false), heaterNumber(num), sensorNumber(-1), activeTemperature(0.0), standbyTemperature(0.0), - maxTempExcursion(DefaultMaxTempExcursion), maxHeatingFaultTime(DefaultMaxHeatingFaultTime), + maxTempExcursion(DefaultMaxTempExcursion), maxHeatingFaultTime(DefaultMaxHeatingFaultTime), maxBadTemperatureCount(DefaultMaxBadTemperatureCount), isBedOrChamber(false), active(false), modelSetByUser(false), monitorsSetByUser(false) { @@ -456,13 +456,20 @@ void Heater::SetAndReportModelAfterTuning(bool usingFans) noexcept } } -GCodeResult Heater::SetFaultDetectionParameters(float pMaxTempExcursion, float pMaxFaultTime, const StringRef& reply) noexcept +GCodeResult Heater::ConfigureFaultDetectionParameters(GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeException) { - maxTempExcursion = pMaxTempExcursion; - maxHeatingFaultTime = pMaxFaultTime; - const GCodeResult rslt = UpdateFaultDetectionParameters(reply); - reprap.HeatUpdated(); - return rslt; + bool seenValue = false; + gb.TryGetNonNegativeFValue('P', maxHeatingFaultTime, seenValue); + gb.TryGetNonNegativeFValue('T', maxTempExcursion, seenValue); + if (seenValue) + { + const GCodeResult rslt = UpdateFaultDetectionParameters(reply); + reprap.HeatUpdated(); + return rslt; + } + + reply.printf("Heater %u allowed excursion %.1f" DEGREE_SYMBOL "C, fault trigger time %.1f seconds", heaterNumber, (double)maxTempExcursion, (double)maxHeatingFaultTime); + return GCodeResult::ok; } // Process M143 for this heater @@ -663,6 +670,13 @@ GCodeResult Heater::SetHeaterMonitors(const CanMessageSetHeaterMonitors& msg, co return GCodeResult::ok; } +GCodeResult Heater::SetFaultDetectionParameters(const CanMessageSetHeaterFaultDetectionParameters& msg, const StringRef& reply) noexcept +{ + maxTempExcursion = msg.maxTempExcursion; + maxHeatingFaultTime = msg.maxFaultTime; + return GCodeResult::ok; +} + GCodeResult Heater::SetModel(unsigned int heater, const CanMessageHeaterModelNewNew& msg, const StringRef& reply) noexcept { const float temperatureLimit = GetHighestTemperatureLimit(); diff --git a/src/Heating/Heater.h b/src/Heating/Heater.h index 83e90902..9da5c919 100644 --- a/src/Heating/Heater.h +++ b/src/Heating/Heater.h @@ -32,6 +32,7 @@ struct CanMessageHeaterModelNewNew; struct CanMessageSetHeaterTemperature; struct CanMessageSetHeaterMonitors; struct CanMessageHeaterTuningCommand; +struct CanMessageSetHeaterFaultDetectionParameters; #endif // Enumeration to describe the status of a heater. Note that the web interface returns the numerical values, so don't change them. @@ -75,11 +76,7 @@ public: GCodeResult StartAutoTune(GCodeBuffer& gb, const StringRef& reply, FansBitmap fans) THROWS(GCodeException); // Start an auto tune cycle for this heater void GetAutoTuneStatus(const StringRef& reply) const noexcept; // Get the auto tune status or last result - - void GetFaultDetectionParameters(float& pMaxTempExcursion, float& pMaxFaultTime) const noexcept - { pMaxTempExcursion = maxTempExcursion; pMaxFaultTime = maxHeatingFaultTime; } - GCodeResult SetFaultDetectionParameters(float pMaxTempExcursion, float pMaxFaultTime, const StringRef& reply) noexcept; - + GCodeResult ConfigureFaultDetectionParameters(GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeException); GCodeResult ConfigureMonitor(GCodeBuffer &gb, const StringRef &reply) THROWS(GCodeException); float GetHighestTemperatureLimit() const noexcept; @@ -92,6 +89,7 @@ public: virtual GCodeResult TuningCommand(const CanMessageHeaterTuningCommand& msg, const StringRef& reply) noexcept = 0; GCodeResult SetModel(unsigned int heater, const CanMessageHeaterModelNewNew& msg, const StringRef& reply) noexcept; GCodeResult SetTemperature(const CanMessageSetHeaterTemperature& msg, const StringRef& reply) noexcept; + GCodeResult SetFaultDetectionParameters(const CanMessageSetHeaterFaultDetectionParameters& msg, const StringRef& reply) noexcept; GCodeResult SetHeaterMonitors(const CanMessageSetHeaterMonitors& msg, const StringRef& reply) noexcept; #endif @@ -137,6 +135,7 @@ protected: void SetSensorNumber(int sn) noexcept; float GetMaxTemperatureExcursion() const noexcept { return maxTempExcursion; } float GetMaxHeatingFaultTime() const noexcept { return maxHeatingFaultTime; } + unsigned int GetMaxBadTemperatureCount() const noexcept { return maxBadTemperatureCount; } float GetTargetTemperature() const noexcept { return (active) ? activeTemperature : standbyTemperature; } bool IsBedOrChamber() const noexcept { return isBedOrChamber; } @@ -201,6 +200,7 @@ private: float standbyTemperature; // the required standby temperature float maxTempExcursion; // the maximum temperature excursion permitted while maintaining the setpoint float maxHeatingFaultTime; // how long a heater fault is permitted to persist before a heater fault is raised + unsigned int maxBadTemperatureCount; // the number of consecutive bad sensor readings we allow before raising a fault bool isBedOrChamber; // true if this was a bed or chamber heater when we were switched on bool active; // are we active or standby? diff --git a/src/Heating/HeaterMonitor.cpp b/src/Heating/HeaterMonitor.cpp index 3f9255a2..7b1ef9fb 100644 --- a/src/Heating/HeaterMonitor.cpp +++ b/src/Heating/HeaterMonitor.cpp @@ -17,7 +17,7 @@ HeaterMonitor::HeaterMonitor() noexcept } // Check if any action needs to be taken. Returns true if everything is OK -bool HeaterMonitor::Check() noexcept +bool HeaterMonitor::Check(unsigned int maxBadTemperatureCount) noexcept { if (sensorNumber >= 0 && trigger != HeaterMonitorTrigger::Disabled) { @@ -27,7 +27,7 @@ bool HeaterMonitor::Check() noexcept if (err != TemperatureError::success) { badTemperatureCount++; - if (badTemperatureCount > MaxBadTemperatureCount) + if (badTemperatureCount > maxBadTemperatureCount) { reprap.GetPlatform().MessageF(ErrorMessage, "Temperature reading error on sensor %d\n", sensorNumber); return false; diff --git a/src/Heating/HeaterMonitor.h b/src/Heating/HeaterMonitor.h index 441dbf26..f10a27a4 100644 --- a/src/Heating/HeaterMonitor.h +++ b/src/Heating/HeaterMonitor.h @@ -48,7 +48,7 @@ public: void Set(int sn, float lim, HeaterMonitorAction act, HeaterMonitorTrigger trig) noexcept; void Disable() noexcept; - bool Check() noexcept; // Check if any action needs to be taken + bool Check(unsigned int maxBadTemperatureCount) noexcept; // Check if any action needs to be taken int GetSensorNumber() const noexcept { return sensorNumber; } // Get the supervisory sensor number float GetTemperatureLimit() const noexcept { return limit; } // Get the temperature limit diff --git a/src/Heating/LocalHeater.cpp b/src/Heating/LocalHeater.cpp index f3dbef7c..6ea9b866 100644 --- a/src/Heating/LocalHeater.cpp +++ b/src/Heating/LocalHeater.cpp @@ -251,7 +251,7 @@ void LocalHeater::Spin() noexcept { // Error may be a temporary error and may correct itself after a few additional reads badTemperatureCount++; - if (badTemperatureCount > MaxBadTemperatureCount) + if (badTemperatureCount > GetMaxBadTemperatureCount()) { RaiseHeaterFault(HeaterFaultType::failedToReadSensor, "%s", TemperatureErrorString(err)); } @@ -443,7 +443,7 @@ void LocalHeater::Spin() noexcept for (size_t i = 0; i < ARRAY_SIZE(monitors); ++i) { HeaterMonitor& prot = monitors[i]; - if (!prot.Check()) + if (!prot.Check(GetMaxBadTemperatureCount())) { if (reprap.Debug(moduleHeat)) { diff --git a/src/Heating/Sensors/DhtSensor.cpp b/src/Heating/Sensors/DhtSensor.cpp index 56dae81b..9c55cb72 100644 --- a/src/Heating/Sensors/DhtSensor.cpp +++ b/src/Heating/Sensors/DhtSensor.cpp @@ -214,7 +214,7 @@ void DhtTemperatureSensor::TakeReading() noexcept SetResult(t, rslt); badTemperatureCount = 0; } - else if (badTemperatureCount < MaxBadTemperatureCount) + else if (badTemperatureCount < MaxDhtBadTemperatureCount) { badTemperatureCount++; } |