From 3ed3cbd488e4b895d9af424698f14b6df517d8f6 Mon Sep 17 00:00:00 2001 From: David Crocker Date: Sun, 15 Dec 2019 18:19:14 +0000 Subject: Added more noexcept specifiers --- .cproject | 50 +------ .gitignore | 1 + src/Fans/DotStarLed.cpp | 2 +- src/Fans/DotStarLed.h | 2 +- src/Fans/Fan.cpp | 8 +- src/Fans/Fan.h | 34 ++--- src/Fans/FansManager.cpp | 32 ++--- src/Fans/FansManager.h | 32 ++--- src/Fans/LocalFan.cpp | 26 ++-- src/Fans/LocalFan.h | 30 ++--- src/Fans/RemoteFan.cpp | 22 ++-- src/Fans/RemoteFan.h | 22 ++-- src/FilamentMonitors/Duet3DFilamentMonitor.cpp | 12 +- src/FilamentMonitors/Duet3DFilamentMonitor.h | 12 +- src/FilamentMonitors/FilamentMonitor.cpp | 16 +-- src/FilamentMonitors/FilamentMonitor.h | 32 ++--- src/FilamentMonitors/LaserFilamentMonitor.cpp | 18 +-- src/FilamentMonitors/LaserFilamentMonitor.h | 18 +-- src/FilamentMonitors/PulsedFilamentMonitor.cpp | 18 +-- src/FilamentMonitors/PulsedFilamentMonitor.h | 18 +-- .../RotatingMagnetFilamentMonitor.cpp | 18 +-- .../RotatingMagnetFilamentMonitor.h | 18 +-- src/FilamentMonitors/SimpleFilamentMonitor.cpp | 12 +- src/FilamentMonitors/SimpleFilamentMonitor.h | 12 +- src/Heating/FOPDT.cpp | 14 +- src/Heating/FOPDT.h | 40 +++--- src/Heating/Heat.cpp | 112 ++++++++-------- src/Heating/Heat.h | 146 ++++++++++----------- src/Heating/Heater.cpp | 32 ++--- src/Heating/Heater.h | 92 ++++++------- src/Heating/HeaterProtection.cpp | 8 +- src/Heating/HeaterProtection.h | 38 +++--- src/Heating/LocalHeater.cpp | 50 +++---- src/Heating/LocalHeater.h | 58 ++++---- src/Heating/RemoteHeater.cpp | 36 ++--- src/Heating/RemoteHeater.h | 38 +++--- src/Heating/Sensors/AdditionalOutputSensor.cpp | 7 +- src/Heating/Sensors/AdditionalOutputSensor.h | 6 +- src/Heating/Sensors/CpuTemperatureSensor.cpp | 4 +- src/Heating/Sensors/CpuTemperatureSensor.h | 4 +- .../Sensors/CurrentLoopTemperatureSensor.cpp | 8 +- src/Heating/Sensors/CurrentLoopTemperatureSensor.h | 8 +- src/Heating/Sensors/DhtSensor.cpp | 22 ++-- src/Heating/Sensors/DhtSensor.h | 22 ++-- src/Heating/Sensors/LinearAnalogSensor.cpp | 6 +- src/Heating/Sensors/LinearAnalogSensor.h | 6 +- src/Heating/Sensors/RemoteSensor.cpp | 4 +- src/Heating/Sensors/RemoteSensor.h | 8 +- src/Heating/Sensors/RtdSensor31865.cpp | 6 +- src/Heating/Sensors/RtdSensor31865.h | 6 +- src/Heating/Sensors/SensorWithPort.cpp | 6 +- src/Heating/Sensors/SensorWithPort.h | 6 +- src/Heating/Sensors/SpiTemperatureSensor.cpp | 6 +- src/Heating/Sensors/SpiTemperatureSensor.h | 6 +- src/Heating/Sensors/TemperatureSensor.cpp | 24 ++-- src/Heating/Sensors/TemperatureSensor.h | 46 +++---- src/Heating/Sensors/Thermistor.cpp | 6 +- src/Heating/Sensors/Thermistor.h | 6 +- src/Heating/Sensors/ThermocoupleSensor31855.cpp | 4 +- src/Heating/Sensors/ThermocoupleSensor31855.h | 4 +- src/Heating/Sensors/ThermocoupleSensor31856.cpp | 6 +- src/Heating/Sensors/ThermocoupleSensor31856.h | 6 +- src/Heating/Sensors/TmcDriverTemperatureSensor.cpp | 4 +- src/Heating/Sensors/TmcDriverTemperatureSensor.h | 6 +- src/Heating/TemperatureError.cpp | 2 +- src/Heating/TemperatureError.h | 2 +- src/OutputMemory.cpp | 80 +++++------ src/OutputMemory.h | 110 ++++++++-------- src/Tools/Filament.cpp | 14 +- src/Tools/Filament.h | 20 +-- src/Tools/Spindle.cpp | 8 +- src/Tools/Spindle.h | 20 +-- src/Tools/Tool.cpp | 52 ++++---- src/Tools/Tool.h | 104 +++++++-------- 74 files changed, 877 insertions(+), 917 deletions(-) diff --git a/.cproject b/.cproject index 2b277355..c12bae3c 100644 --- a/.cproject +++ b/.cproject @@ -1866,76 +1866,34 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - - - - - - - - - - + - + diff --git a/.gitignore b/.gitignore index 5ce3e62b..c47873e7 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ .settings/language.settings.xml /PCCB/ /PCCB_X5/ +/Duet3_V06/ diff --git a/src/Fans/DotStarLed.cpp b/src/Fans/DotStarLed.cpp index eb94df7a..984bc2b2 100644 --- a/src/Fans/DotStarLed.cpp +++ b/src/Fans/DotStarLed.cpp @@ -28,7 +28,7 @@ namespace DotStarLed static bool busy = false; static uint32_t chunkBuffer[MaxChunkSize]; - void Init() + void Init() noexcept { // Set up the USART or QSPI pins for SPI mode // The pins are already set up for SPI in the pins table diff --git a/src/Fans/DotStarLed.h b/src/Fans/DotStarLed.h index 902918ec..d27a55f8 100644 --- a/src/Fans/DotStarLed.h +++ b/src/Fans/DotStarLed.h @@ -15,7 +15,7 @@ class GCodeBuffer; namespace DotStarLed { - void Init(); + void Init() noexcept; GCodeResult SetColours(GCodeBuffer& gb, const StringRef& reply); }; diff --git a/src/Fans/Fan.cpp b/src/Fans/Fan.cpp index cec04f8b..c45f602c 100644 --- a/src/Fans/Fan.cpp +++ b/src/Fans/Fan.cpp @@ -8,7 +8,7 @@ #include "Fan.h" #include "GCodes/GCodeBuffer/GCodeBuffer.h" -Fan::Fan(unsigned int fanNum) +Fan::Fan(unsigned int fanNum) noexcept : fanNumber(fanNum), val(0.0), lastVal(0.0), minVal(DefaultMinFanPwm), @@ -28,7 +28,7 @@ Fan::Fan(unsigned int fanNum) // Exceptions: // 1. Only process the S parameter if other values were processed. // 2. Don't process the R parameter, but if it is present don't print the existing configuration. -bool Fan::Configure(unsigned int mcode, size_t fanNum, GCodeBuffer& gb, const StringRef& reply, bool& error) +bool Fan::Configure(unsigned int mcode, size_t fanNum, GCodeBuffer& gb, const StringRef& reply, bool& error) noexcept { bool seen = false; if (mcode == 106) @@ -160,7 +160,7 @@ bool Fan::Configure(unsigned int mcode, size_t fanNum, GCodeBuffer& gb, const St } // Set the PWM. 'speed' is in the interval 0.0..1.0. -GCodeResult Fan::SetPwm(float speed, const StringRef& reply) +GCodeResult Fan::SetPwm(float speed, const StringRef& reply) noexcept { val = speed; return Refresh(reply); @@ -169,7 +169,7 @@ GCodeResult Fan::SetPwm(float speed, const StringRef& reply) #if HAS_MASS_STORAGE // Save the settings of this fan if it isn't thermostatic -bool Fan::WriteSettings(FileStore *f, size_t fanNum) const +bool Fan::WriteSettings(FileStore *f, size_t fanNum) const noexcept { if (sensorsMonitored == 0) { diff --git a/src/Fans/Fan.h b/src/Fans/Fan.h index a5c7b249..12a088f0 100644 --- a/src/Fans/Fan.h +++ b/src/Fans/Fan.h @@ -21,16 +21,16 @@ class GCodeBuffer; class Fan { public: - Fan(unsigned int fanNum); + Fan(unsigned int fanNum) noexcept; - virtual ~Fan() { } - virtual bool Check() = 0; // update the fan PWM returning true if it is a thermostatic fan that is on - virtual GCodeResult SetPwmFrequency(PwmFrequency freq, const StringRef& reply) = 0; - virtual bool IsEnabled() const = 0; - virtual int32_t GetRPM() = 0; - virtual GCodeResult ReportPortDetails(const StringRef& str) const = 0; + virtual ~Fan() noexcept { } + virtual bool Check() noexcept = 0; // update the fan PWM returning true if it is a thermostatic fan that is on + virtual GCodeResult SetPwmFrequency(PwmFrequency freq, const StringRef& reply) noexcept = 0; + virtual bool IsEnabled() const noexcept = 0; + virtual int32_t GetRPM() noexcept = 0; + virtual GCodeResult ReportPortDetails(const StringRef& str) const noexcept = 0; #if SUPPORT_CAN_EXPANSION - virtual void UpdateRpmFromRemote(CanAddress src, int32_t rpm) = 0; + virtual void UpdateRpmFromRemote(CanAddress src, int32_t rpm) noexcept = 0; #endif // Set or report the parameters for this fan @@ -38,21 +38,21 @@ public: // then search for parameters used to configure the fan. If any are found, perform appropriate actions and return true. // If errors were discovered while processing parameters, put an appropriate error message in 'reply' and set 'error' to true. // If no relevant parameters are found, print the existing ones to 'reply' and return false. - bool Configure(unsigned int mcode, size_t fanNum, GCodeBuffer& gb, const StringRef& reply, bool& error); - bool IsConfigured() const { return isConfigured && IsEnabled(); } + bool Configure(unsigned int mcode, size_t fanNum, GCodeBuffer& gb, const StringRef& reply, bool& error) noexcept; + bool IsConfigured() const noexcept { return isConfigured && IsEnabled(); } - float GetConfiguredPwm() const { return val; } // returns the configured PWM. Actual PWM may be different, e.g. due to blipping or for thermostatic fans. + float GetConfiguredPwm() const noexcept { return val; } // returns the configured PWM. Actual PWM may be different, e.g. due to blipping or for thermostatic fans. - GCodeResult SetPwm(float speed, const StringRef& reply); - bool HasMonitoredSensors() const { return sensorsMonitored != 0; } - const char *GetName() const { return name.c_str(); } + GCodeResult SetPwm(float speed, const StringRef& reply) noexcept; + bool HasMonitoredSensors() const noexcept { return sensorsMonitored != 0; } + const char *GetName() const noexcept { return name.c_str(); } #if HAS_MASS_STORAGE - bool WriteSettings(FileStore *f, size_t fanNum) const; // save the settings of this fan if it isn't thermostatic + bool WriteSettings(FileStore *f, size_t fanNum) const noexcept; // save the settings of this fan if it isn't thermostatic #endif protected: - virtual GCodeResult Refresh(const StringRef& reply) = 0; - virtual bool UpdateFanConfiguration(const StringRef& reply) = 0; + virtual GCodeResult Refresh(const StringRef& reply) noexcept = 0; + virtual bool UpdateFanConfiguration(const StringRef& reply) noexcept = 0; unsigned int fanNumber; diff --git a/src/Fans/FansManager.cpp b/src/Fans/FansManager.cpp index ecfe7d66..7aa484b3 100644 --- a/src/Fans/FansManager.cpp +++ b/src/Fans/FansManager.cpp @@ -17,7 +17,7 @@ #include -FansManager::FansManager() +FansManager::FansManager() noexcept { for (Fan*& f : fans) { @@ -27,14 +27,14 @@ FansManager::FansManager() // Retrieve the pointer to a fan, or nullptr if it doesn't exist. // Lock the fan system before calling this, so that the fan can't be deleted while we are accessing it. -ReadLockedPointer FansManager::FindFan(size_t fanNum) const +ReadLockedPointer FansManager::FindFan(size_t fanNum) const noexcept { ReadLocker locker(fansLock); return ReadLockedPointer(locker, (fanNum < ARRAY_SIZE(fans)) ? fans[fanNum] : nullptr); } // Create and return a local fan. if it fails, return nullptr with the error message in 'reply'. -LocalFan *FansManager::CreateLocalFan(uint32_t fanNum, const char *pinNames, PwmFrequency freq, const StringRef& reply) +LocalFan *FansManager::CreateLocalFan(uint32_t fanNum, const char *pinNames, PwmFrequency freq, const StringRef& reply) noexcept { LocalFan *newFan = new LocalFan(fanNum); if (!newFan->AssignPorts(pinNames, reply)) @@ -47,7 +47,7 @@ LocalFan *FansManager::CreateLocalFan(uint32_t fanNum, const char *pinNames, Pwm } // Check and if necessary update all fans. Return true if a thermostatic fan is running. -bool FansManager::CheckFans() +bool FansManager::CheckFans() noexcept { ReadLocker lock(fansLock); bool thermostaticFanRunning = false; @@ -62,7 +62,7 @@ bool FansManager::CheckFans() } // Return the highest used fan number. Used by RepRap.cpp to shorten responses by omitting unused trailing fan numbers. If no fans are configured, return 0. -size_t FansManager::GetHighestUsedFanNumber() const +size_t FansManager::GetHighestUsedFanNumber() const noexcept { size_t highestFan = ARRAY_SIZE(fans); do @@ -74,7 +74,7 @@ size_t FansManager::GetHighestUsedFanNumber() const #if HAS_MASS_STORAGE -bool FansManager::WriteFanSettings(FileStore *f) const +bool FansManager::WriteFanSettings(FileStore *f) const noexcept { ReadLocker lock(fansLock); bool ok = true; @@ -88,7 +88,7 @@ bool FansManager::WriteFanSettings(FileStore *f) const #endif // This is called by M950 to create a fan or change its PWM frequency -GCodeResult FansManager::ConfigureFanPort(uint32_t fanNum, GCodeBuffer& gb, const StringRef& reply) +GCodeResult FansManager::ConfigureFanPort(uint32_t fanNum, GCodeBuffer& gb, const StringRef& reply) noexcept { if (fanNum < MaxFans) { @@ -155,7 +155,7 @@ GCodeResult FansManager::ConfigureFanPort(uint32_t fanNum, GCodeBuffer& gb, cons // then search for parameters used to configure the fan. If any are found, perform appropriate actions and return true. // If errors were discovered while processing parameters, put an appropriate error message in 'reply' and set 'error' to true. // If no relevant parameters are found, print the existing ones to 'reply' and return false. -bool FansManager::ConfigureFan(unsigned int mcode, size_t fanNum, GCodeBuffer& gb, const StringRef& reply, bool& error) +bool FansManager::ConfigureFan(unsigned int mcode, size_t fanNum, GCodeBuffer& gb, const StringRef& reply, bool& error) noexcept { auto fan = FindFan(fanNum); if (fan.IsNull()) @@ -168,13 +168,13 @@ bool FansManager::ConfigureFan(unsigned int mcode, size_t fanNum, GCodeBuffer& g return fan->Configure(mcode, fanNum, gb, reply, error); } -float FansManager::GetFanValue(size_t fanNum) const +float FansManager::GetFanValue(size_t fanNum) const noexcept { auto fan = FindFan(fanNum); return (fan.IsNull()) ? -1 : fan->GetConfiguredPwm(); } -GCodeResult FansManager::SetFanValue(size_t fanNum, float speed, const StringRef& reply) +GCodeResult FansManager::SetFanValue(size_t fanNum, float speed, const StringRef& reply) noexcept { auto fan = FindFan(fanNum); if (fan.IsNotNull()) @@ -185,7 +185,7 @@ GCodeResult FansManager::SetFanValue(size_t fanNum, float speed, const StringRef return GCodeResult::error; } -void FansManager::SetFanValue(size_t fanNum, float speed) +void FansManager::SetFanValue(size_t fanNum, float speed) noexcept { String<1> dummy; (void)SetFanValue(fanNum, speed, dummy.GetRef()); @@ -193,28 +193,28 @@ void FansManager::SetFanValue(size_t fanNum, float speed) // Check if the given fan can be controlled manually so that DWC can decide whether or not to show the corresponding fan // controls. This is the case if no thermostatic control is enabled and if the fan was configured at least once before. -bool FansManager::IsFanControllable(size_t fanNum) const +bool FansManager::IsFanControllable(size_t fanNum) const noexcept { auto fan = FindFan(fanNum); return fan.IsNotNull() && !fan->HasMonitoredSensors() && fan->IsConfigured(); } // Return the fan's name -const char *FansManager::GetFanName(size_t fanNum) const +const char *FansManager::GetFanName(size_t fanNum) const noexcept { auto fan = FindFan(fanNum); return (fan.IsNull()) ? "" : fan->GetName(); } // Get current fan RPM, or -1 if the fan is invalid or doesn't have a tacho pin -int32_t FansManager::GetFanRPM(size_t fanNum) const +int32_t FansManager::GetFanRPM(size_t fanNum) const noexcept { auto fan = FindFan(fanNum); return (fan.IsNull()) ? -1 : fan->GetRPM(); } // Initialise fans. Call this only once, and only during initialisation. -void FansManager::Init() +void FansManager::Init() noexcept { #if ALLOCATE_DEFAULT_PORTS for (size_t i = 0; i < ARRAY_SIZE(DefaultFanPinNames); ++i) @@ -236,7 +236,7 @@ void FansManager::Init() #if SUPPORT_CAN_EXPANSION -void FansManager::ProcessRemoteFanRpms(CanAddress src, const CanMessageFanRpms& msg) +void FansManager::ProcessRemoteFanRpms(CanAddress src, const CanMessageFanRpms& msg) noexcept { size_t numFansProcessed = 0; uint64_t whichFans = msg.whichFans; diff --git a/src/Fans/FansManager.h b/src/Fans/FansManager.h index db213ee0..5e30b123 100644 --- a/src/Fans/FansManager.h +++ b/src/Fans/FansManager.h @@ -24,28 +24,28 @@ class LocalFan; class FansManager { public: - FansManager(); - void Init(); - bool CheckFans(); - size_t GetHighestUsedFanNumber() const; - GCodeResult ConfigureFanPort(uint32_t fanNum, GCodeBuffer& gb, const StringRef& reply); - bool ConfigureFan(unsigned int mcode, size_t fanNum, GCodeBuffer& gb, const StringRef& reply, bool& error); - float GetFanValue(size_t fanNum) const; - GCodeResult SetFanValue(size_t fanNum, float speed, const StringRef& reply); - void SetFanValue(size_t fanNum, float speed); - bool IsFanControllable(size_t fanNum) const; - const char *GetFanName(size_t fanNum) const; - int32_t GetFanRPM(size_t fanNum) const; + FansManager() noexcept; + void Init() noexcept; + bool CheckFans() noexcept; + size_t GetHighestUsedFanNumber() const noexcept; + GCodeResult ConfigureFanPort(uint32_t fanNum, GCodeBuffer& gb, const StringRef& reply) noexcept; + bool ConfigureFan(unsigned int mcode, size_t fanNum, GCodeBuffer& gb, const StringRef& reply, bool& error) noexcept; + float GetFanValue(size_t fanNum) const noexcept; + GCodeResult SetFanValue(size_t fanNum, float speed, const StringRef& reply) noexcept; + void SetFanValue(size_t fanNum, float speed) noexcept; + bool IsFanControllable(size_t fanNum) const noexcept; + 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); + void ProcessRemoteFanRpms(CanAddress src, const CanMessageFanRpms& msg) noexcept; #endif #if HAS_MASS_STORAGE - bool WriteFanSettings(FileStore *f) const; + bool WriteFanSettings(FileStore *f) const noexcept; #endif private: - ReadLockedPointer FindFan(size_t fanNum) const; - LocalFan *CreateLocalFan(uint32_t fanNum, const char *pinNames, PwmFrequency freq, const StringRef& reply); + ReadLockedPointer FindFan(size_t fanNum) const noexcept; + LocalFan *CreateLocalFan(uint32_t fanNum, const char *pinNames, PwmFrequency freq, const StringRef& reply) noexcept; mutable ReadWriteLock fansLock; Fan *fans[MaxFans]; diff --git a/src/Fans/LocalFan.cpp b/src/Fans/LocalFan.cpp index dab83bd9..460d4aec 100644 --- a/src/Fans/LocalFan.cpp +++ b/src/Fans/LocalFan.cpp @@ -14,12 +14,12 @@ #include "Heating/Heat.h" #include "Heating/Sensors/TemperatureSensor.h" -void FanInterrupt(CallbackParameter cb) +void FanInterrupt(CallbackParameter cb) noexcept { static_cast(cb.vp)->Interrupt(); } -LocalFan::LocalFan(unsigned int fanNum) +LocalFan::LocalFan(unsigned int fanNum) noexcept : Fan(fanNum), lastPwm(-1.0), // force a refresh fanInterruptCount(0), fanLastResetTime(0), fanInterval(0), @@ -27,14 +27,14 @@ LocalFan::LocalFan(unsigned int fanNum) { } -LocalFan::~LocalFan() +LocalFan::~LocalFan() noexcept { port.WriteAnalog(0.0); port.Release(); tachoPort.Release(); } -GCodeResult LocalFan::ReportPortDetails(const StringRef& str) const +GCodeResult LocalFan::ReportPortDetails(const StringRef& str) const noexcept { str.printf("Fan %u", fanNumber); port.AppendDetails(str); @@ -46,7 +46,7 @@ GCodeResult LocalFan::ReportPortDetails(const StringRef& str) const return GCodeResult::ok; } -GCodeResult LocalFan::SetPwmFrequency(PwmFrequency freq, const StringRef& reply) +GCodeResult LocalFan::SetPwmFrequency(PwmFrequency freq, const StringRef& reply) noexcept { port.SetFrequency(freq); return GCodeResult::ok; @@ -54,7 +54,7 @@ GCodeResult LocalFan::SetPwmFrequency(PwmFrequency freq, const StringRef& reply) // Set the hardware PWM // If you want make sure that the PWM is definitely updated, set lastPWM negative before calling this -void LocalFan::SetHardwarePwm(float pwmVal) +void LocalFan::SetHardwarePwm(float pwmVal) noexcept { // Only set the PWM if it has changed, to avoid a lot of I2C traffic when we have a DueX5 connected if (pwmVal != lastPwm) @@ -66,7 +66,7 @@ void LocalFan::SetHardwarePwm(float pwmVal) // Refresh the fan PWM // If you want make sure that the PWM is definitely updated, set lastPWM negative before calling this -void LocalFan::InternalRefresh() +void LocalFan::InternalRefresh() noexcept { float reqVal; #if HAS_SMART_DRIVERS @@ -160,19 +160,19 @@ void LocalFan::InternalRefresh() lastVal = reqVal; } -GCodeResult LocalFan::Refresh(const StringRef& reply) +GCodeResult LocalFan::Refresh(const StringRef& reply) noexcept { InternalRefresh(); return GCodeResult::ok; } -bool LocalFan::UpdateFanConfiguration(const StringRef& reply) +bool LocalFan::UpdateFanConfiguration(const StringRef& reply) noexcept { InternalRefresh(); return true; } -bool LocalFan::Check() +bool LocalFan::Check() noexcept { if (sensorsMonitored != 0 || blipping) { @@ -181,7 +181,7 @@ bool LocalFan::Check() return sensorsMonitored != 0 && lastVal != 0.0; } -bool LocalFan::AssignPorts(const char *pinNames, const StringRef& reply) +bool LocalFan::AssignPorts(const char *pinNames, const StringRef& reply) noexcept { IoPort* const ports[] = { &port, &tachoPort }; const PinAccess access1[] = { PinAccess::pwm, PinAccess::read}; @@ -205,7 +205,7 @@ bool LocalFan::AssignPorts(const char *pinNames, const StringRef& reply) } // Tacho support -int32_t LocalFan::GetRPM() +int32_t LocalFan::GetRPM() noexcept { // The ISR sets fanInterval to the number of step interrupt clocks it took to get fanMaxInterruptCount interrupts. // We get 2 tacho pulses per revolution, hence 2 interrupts per revolution. @@ -217,7 +217,7 @@ int32_t LocalFan::GetRPM() : 0; // else assume fan is off or tacho not connected } -void LocalFan::Interrupt() +void LocalFan::Interrupt() noexcept { ++fanInterruptCount; if (fanInterruptCount == fanMaxInterruptCount) diff --git a/src/Fans/LocalFan.h b/src/Fans/LocalFan.h index 2fcfa789..6835952b 100644 --- a/src/Fans/LocalFan.h +++ b/src/Fans/LocalFan.h @@ -13,29 +13,29 @@ class LocalFan : public Fan { public: - LocalFan(unsigned int fanNum); - ~LocalFan(); - - bool Check() override; // update the fan PWM returning true if it is a thermostatic fan that is on - bool IsEnabled() const override { return port.IsValid(); } - GCodeResult SetPwmFrequency(PwmFrequency freq, const StringRef& reply) override; - int32_t GetRPM() override; - GCodeResult ReportPortDetails(const StringRef& str) const override; + LocalFan(unsigned int fanNum) noexcept; + ~LocalFan() noexcept; + + bool Check() 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(); } + GCodeResult SetPwmFrequency(PwmFrequency freq, const StringRef& reply) noexcept override; + int32_t GetRPM() noexcept override; + GCodeResult ReportPortDetails(const StringRef& str) const noexcept override; #if SUPPORT_CAN_EXPANSION - void UpdateRpmFromRemote(CanAddress src, int32_t rpm) override { } + void UpdateRpmFromRemote(CanAddress src, int32_t rpm) noexcept override { } #endif - bool AssignPorts(const char *pinNames, const StringRef& reply); + bool AssignPorts(const char *pinNames, const StringRef& reply) noexcept; - void Interrupt(); + void Interrupt() noexcept; protected: - GCodeResult Refresh(const StringRef& reply) override; - bool UpdateFanConfiguration(const StringRef& reply) override; + GCodeResult Refresh(const StringRef& reply) noexcept override; + bool UpdateFanConfiguration(const StringRef& reply) noexcept override; private: - void SetHardwarePwm(float pwmVal); - void InternalRefresh(); + void SetHardwarePwm(float pwmVal) noexcept; + void InternalRefresh() noexcept; PwmPort port; // port used to control the fan IoPort tachoPort; // port used to read the tacho diff --git a/src/Fans/RemoteFan.cpp b/src/Fans/RemoteFan.cpp index c36b271e..d48401d9 100644 --- a/src/Fans/RemoteFan.cpp +++ b/src/Fans/RemoteFan.cpp @@ -13,13 +13,13 @@ #include "CAN/CanInterface.h" #include "CAN/CanMessageGenericConstructor.h" -RemoteFan::RemoteFan(unsigned int fanNum, CanAddress boardNum) +RemoteFan::RemoteFan(unsigned int fanNum, CanAddress boardNum) noexcept : Fan(fanNum), lastRpm(-1), whenLastRpmReceived(0), boardNumber(boardNum), thermostaticFanRunning(false) { } -RemoteFan::~RemoteFan() +RemoteFan::~RemoteFan() noexcept { CanMessageGenericConstructor cons(M950FanParams); cons.AddUParam('F', fanNumber); @@ -28,17 +28,17 @@ RemoteFan::~RemoteFan() (void)cons.SendAndGetResponse(CanMessageType::m950Fan, boardNumber, dummy.GetRef()); } -bool RemoteFan::Check() +bool RemoteFan::Check() noexcept { return thermostaticFanRunning; } -bool RemoteFan::IsEnabled() const +bool RemoteFan::IsEnabled() const noexcept { return true; } -GCodeResult RemoteFan::SetPwmFrequency(PwmFrequency freq, const StringRef& reply) +GCodeResult RemoteFan::SetPwmFrequency(PwmFrequency freq, const StringRef& reply) noexcept { CanMessageGenericConstructor cons(M950FanParams); cons.AddUParam('F', fanNumber); @@ -46,7 +46,7 @@ GCodeResult RemoteFan::SetPwmFrequency(PwmFrequency freq, const StringRef& reply return cons.SendAndGetResponse(CanMessageType::m950Fan, boardNumber, reply); } -void RemoteFan::UpdateRpmFromRemote(CanAddress src, int32_t rpm) +void RemoteFan::UpdateRpmFromRemote(CanAddress src, int32_t rpm) noexcept { if (src == boardNumber) { @@ -55,7 +55,7 @@ void RemoteFan::UpdateRpmFromRemote(CanAddress src, int32_t rpm) } } -int32_t RemoteFan::GetRPM() +int32_t RemoteFan::GetRPM() noexcept { if (millis() - whenLastRpmReceived > RpmReadingTimeout) { @@ -64,14 +64,14 @@ int32_t RemoteFan::GetRPM() return lastRpm; } -GCodeResult RemoteFan::ReportPortDetails(const StringRef& str) const +GCodeResult RemoteFan::ReportPortDetails(const StringRef& str) const noexcept { CanMessageGenericConstructor cons(M950FanParams); cons.AddUParam('F', fanNumber); return cons.SendAndGetResponse(CanMessageType::m950Fan, boardNumber, str); } -bool RemoteFan::UpdateFanConfiguration(const StringRef& reply) +bool RemoteFan::UpdateFanConfiguration(const StringRef& reply) noexcept { CanMessageBuffer *buf = CanMessageBuffer::Allocate(); if (buf == nullptr) @@ -95,7 +95,7 @@ bool RemoteFan::UpdateFanConfiguration(const StringRef& reply) } // Update the hardware PWM -GCodeResult RemoteFan::Refresh(const StringRef& reply) +GCodeResult RemoteFan::Refresh(const StringRef& reply) noexcept { CanMessageBuffer *buf = CanMessageBuffer::Allocate(); if (buf == nullptr) @@ -111,7 +111,7 @@ GCodeResult RemoteFan::Refresh(const StringRef& reply) return CanInterface::SendRequestAndGetStandardReply(buf, rid, reply); } -GCodeResult RemoteFan::ConfigurePort(const char* pinNames, PwmFrequency freq, const StringRef& reply) +GCodeResult RemoteFan::ConfigurePort(const char* pinNames, PwmFrequency freq, const StringRef& reply) noexcept { CanMessageGenericConstructor cons(M950FanParams); cons.AddUParam('F', fanNumber); diff --git a/src/Fans/RemoteFan.h b/src/Fans/RemoteFan.h index ca61f818..e88a1840 100644 --- a/src/Fans/RemoteFan.h +++ b/src/Fans/RemoteFan.h @@ -17,21 +17,21 @@ class RemoteFan : public Fan { public: - RemoteFan(unsigned int fanNum, CanAddress boardNum); - ~RemoteFan(); + RemoteFan(unsigned int fanNum, CanAddress boardNum) noexcept; + ~RemoteFan() noexcept; - bool Check() override; // update the fan PWM returning true if it is a thermostatic fan that is on - bool IsEnabled() const override; - GCodeResult SetPwmFrequency(PwmFrequency freq, const StringRef& reply) override; - int32_t GetRPM() override; - GCodeResult ReportPortDetails(const StringRef& str) const override; - void UpdateRpmFromRemote(CanAddress src, int32_t rpm) override; + bool Check() noexcept override; // update the fan PWM returning true if it is a thermostatic fan that is on + bool IsEnabled() const noexcept override; + GCodeResult SetPwmFrequency(PwmFrequency freq, const StringRef& reply) noexcept override; + int32_t GetRPM() noexcept override; + GCodeResult ReportPortDetails(const StringRef& str) const noexcept override; + void UpdateRpmFromRemote(CanAddress src, int32_t rpm) noexcept override; - GCodeResult ConfigurePort(const char *pinNames, PwmFrequency freq, const StringRef& reply); + GCodeResult ConfigurePort(const char *pinNames, PwmFrequency freq, const StringRef& reply) noexcept; protected: - bool UpdateFanConfiguration(const StringRef& reply) override; - GCodeResult Refresh(const StringRef& reply) override; + bool UpdateFanConfiguration(const StringRef& reply) noexcept override; + GCodeResult Refresh(const StringRef& reply) noexcept override; private: static constexpr uint32_t RpmReadingTimeout = 2000; // any reading older than this number of milliseconds is considered unreliable diff --git a/src/FilamentMonitors/Duet3DFilamentMonitor.cpp b/src/FilamentMonitors/Duet3DFilamentMonitor.cpp index cbdc58b5..7bce6644 100644 --- a/src/FilamentMonitors/Duet3DFilamentMonitor.cpp +++ b/src/FilamentMonitors/Duet3DFilamentMonitor.cpp @@ -12,13 +12,13 @@ #include "RepRap.h" // Constructors -Duet3DFilamentMonitor::Duet3DFilamentMonitor(unsigned int extruder, unsigned int type) +Duet3DFilamentMonitor::Duet3DFilamentMonitor(unsigned int extruder, unsigned int type) noexcept : FilamentMonitor(extruder, type), overrunErrorCount(0), polarityErrorCount(0) { InitReceiveBuffer(); } -void Duet3DFilamentMonitor::InitReceiveBuffer() +void Duet3DFilamentMonitor::InitReceiveBuffer() noexcept { edgeCaptureReadPointer = edgeCaptureWritePointer = 1; edgeCaptures[0] = StepTimer::GetTimerTicks(); // pretend we just had a high-to-low transition @@ -26,7 +26,7 @@ void Duet3DFilamentMonitor::InitReceiveBuffer() } // ISR for when the pin state changes. It should return true if the ISR wants the commanded extrusion to be fetched. -bool Duet3DFilamentMonitor::Interrupt() +bool Duet3DFilamentMonitor::Interrupt() noexcept { uint32_t now = StepTimer::GetTimerTicks(); bool wantReading = false; @@ -66,7 +66,7 @@ bool Duet3DFilamentMonitor::Interrupt() } // Call the following regularly to keep the status up to date -Duet3DFilamentMonitor::PollResult Duet3DFilamentMonitor::PollReceiveBuffer(uint16_t& measurement) +Duet3DFilamentMonitor::PollResult Duet3DFilamentMonitor::PollReceiveBuffer(uint16_t& measurement) noexcept { // For the Duet3D sensors we need to decode the received data from the transition times recorded in the edgeCaptures array static constexpr uint32_t BitsPerSecond = 1000; // the nominal bit rate that the data is transmitted at @@ -212,13 +212,13 @@ Duet3DFilamentMonitor::PollResult Duet3DFilamentMonitor::PollReceiveBuffer(uint1 } // Return true if we are on the process of receiving data form the filament monitor -bool Duet3DFilamentMonitor::IsReceiving() const +bool Duet3DFilamentMonitor::IsReceiving() const noexcept { return state == RxdState::waitingForEndOfStartBit || state == RxdState::waitingForNibble; } // Return true if we are waiting for a start bit -bool Duet3DFilamentMonitor::IsWaitingForStartBit() const +bool Duet3DFilamentMonitor::IsWaitingForStartBit() const noexcept { return state == RxdState::waitingForStartBit; } diff --git a/src/FilamentMonitors/Duet3DFilamentMonitor.h b/src/FilamentMonitors/Duet3DFilamentMonitor.h index 5e44ce09..25aa7e16 100644 --- a/src/FilamentMonitors/Duet3DFilamentMonitor.h +++ b/src/FilamentMonitors/Duet3DFilamentMonitor.h @@ -15,12 +15,12 @@ class Duet3DFilamentMonitor : public FilamentMonitor { public: - Duet3DFilamentMonitor(unsigned int extruder, unsigned int type); + Duet3DFilamentMonitor(unsigned int extruder, unsigned int type) noexcept; - bool Interrupt() override; + bool Interrupt() noexcept override; protected: - void InitReceiveBuffer(); + void InitReceiveBuffer() noexcept; enum class PollResult : uint8_t { @@ -28,9 +28,9 @@ protected: complete, error }; - PollResult PollReceiveBuffer(uint16_t& measurement); - bool IsReceiving() const; - bool IsWaitingForStartBit() const; + PollResult PollReceiveBuffer(uint16_t& measurement) noexcept; + bool IsReceiving() const noexcept; + bool IsWaitingForStartBit() const noexcept; protected: uint32_t overrunErrorCount; diff --git a/src/FilamentMonitors/FilamentMonitor.cpp b/src/FilamentMonitors/FilamentMonitor.cpp index d3d6e751..0a360772 100644 --- a/src/FilamentMonitors/FilamentMonitor.cpp +++ b/src/FilamentMonitors/FilamentMonitor.cpp @@ -21,12 +21,12 @@ Mutex FilamentMonitor::filamentSensorsMutex; FilamentMonitor *FilamentMonitor::filamentSensors[MaxExtruders] = { 0 }; // Default destructor -FilamentMonitor::~FilamentMonitor() +FilamentMonitor::~FilamentMonitor() noexcept { } // Call this to disable the interrupt before deleting or re-configuring a filament monitor -void FilamentMonitor::Disable() +void FilamentMonitor::Disable() noexcept { port.Release(); } @@ -60,7 +60,7 @@ bool FilamentMonitor::ConfigurePin(GCodeBuffer& gb, const StringRef& reply, Inte } // Static initialisation -/*static*/ void FilamentMonitor::InitStatic() +/*static*/ void FilamentMonitor::InitStatic() noexcept { filamentSensorsMutex.Create("FilamentSensors"); } @@ -113,7 +113,7 @@ bool FilamentMonitor::ConfigurePin(GCodeBuffer& gb, const StringRef& reply, Inte } // Factory function -/*static*/ FilamentMonitor *FilamentMonitor::Create(unsigned int extruder, unsigned int type) +/*static*/ FilamentMonitor *FilamentMonitor::Create(unsigned int extruder, unsigned int type) noexcept { switch (type) { @@ -140,7 +140,7 @@ bool FilamentMonitor::ConfigurePin(GCodeBuffer& gb, const StringRef& reply, Inte } // Return an error message corresponding to a status code -/*static*/ const char *FilamentMonitor::GetErrorMessage(FilamentSensorStatus f) +/*static*/ const char *FilamentMonitor::GetErrorMessage(FilamentSensorStatus f) noexcept { switch(f) { @@ -154,7 +154,7 @@ bool FilamentMonitor::ConfigurePin(GCodeBuffer& gb, const StringRef& reply, Inte } // ISR -/*static*/ void FilamentMonitor::InterruptEntry(CallbackParameter param) +/*static*/ void FilamentMonitor::InterruptEntry(CallbackParameter param) noexcept { FilamentMonitor * const fm = static_cast(param.vp); if (fm->Interrupt()) @@ -165,7 +165,7 @@ bool FilamentMonitor::ConfigurePin(GCodeBuffer& gb, const StringRef& reply, Inte } } -/*static*/ void FilamentMonitor::Spin() +/*static*/ void FilamentMonitor::Spin() noexcept { MutexLocker lock(filamentSensorsMutex); @@ -222,7 +222,7 @@ bool FilamentMonitor::ConfigurePin(GCodeBuffer& gb, const StringRef& reply, Inte } // Send diagnostics info -/*static*/ void FilamentMonitor::Diagnostics(MessageType mtype) +/*static*/ void FilamentMonitor::Diagnostics(MessageType mtype) noexcept { bool first = true; for (size_t i = 0; i < MaxExtruders; ++i) diff --git a/src/FilamentMonitors/FilamentMonitor.h b/src/FilamentMonitors/FilamentMonitor.h index cbd5b6dc..a5ede0dd 100644 --- a/src/FilamentMonitors/FilamentMonitor.h +++ b/src/FilamentMonitors/FilamentMonitor.h @@ -31,55 +31,55 @@ public: // Call the following at intervals to check the status. This is only called when extrusion is in progress or imminent. // 'filamentConsumed' is the net amount of extrusion since the last call to this function. - virtual FilamentSensorStatus Check(bool isPrinting, bool fromIsr, uint32_t isrMillis, float filamentConsumed) = 0; + virtual FilamentSensorStatus Check(bool isPrinting, bool fromIsr, uint32_t isrMillis, float filamentConsumed) noexcept = 0; // Clear the measurement state - called when we are not printing a file. Return the present/not present status if available. - virtual FilamentSensorStatus Clear() = 0; + virtual FilamentSensorStatus Clear() noexcept = 0; // Print diagnostic info for this sensor - virtual void Diagnostics(MessageType mtype, unsigned int extruder) = 0; + virtual void Diagnostics(MessageType mtype, unsigned int extruder) noexcept = 0; // ISR for when the pin state changes. It should return true if the ISR wants the commanded extrusion to be fetched. - virtual bool Interrupt() = 0; + virtual bool Interrupt() noexcept = 0; // Call this to disable the interrupt before deleting a filament monitor - virtual void Disable(); + virtual void Disable() noexcept; // Override the virtual destructor if your derived class allocates any dynamic memory - virtual ~FilamentMonitor(); + virtual ~FilamentMonitor() noexcept; // Return the type of this sensor - unsigned int GetType() const { return type; } + unsigned int GetType() const noexcept { return type; } // Static initialisation - static void InitStatic(); + static void InitStatic() noexcept; // Return an error message corresponding to a status code - static const char *GetErrorMessage(FilamentSensorStatus f); + static const char *GetErrorMessage(FilamentSensorStatus f) noexcept; // Poll the filament sensors - static void Spin(); + static void Spin() noexcept; // Handle M591 static GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply, unsigned int extruder) pre(extruder < MaxExtruders); // Send diagnostics info - static void Diagnostics(MessageType mtype); + static void Diagnostics(MessageType mtype) noexcept; protected: - FilamentMonitor(unsigned int extruder, unsigned int t) : extruderNumber(extruder), type(t) { } + FilamentMonitor(unsigned int extruder, unsigned int t) noexcept : extruderNumber(extruder), type(t) { } bool ConfigurePin(GCodeBuffer& gb, const StringRef& reply, InterruptMode interruptMode, bool& seen); - const IoPort& GetPort() const { return port; } - bool HaveIsrStepsCommanded() const { return haveIsrStepsCommanded; } + const IoPort& GetPort() const noexcept { return port; } + bool HaveIsrStepsCommanded() const noexcept { return haveIsrStepsCommanded; } private: // Create a filament sensor returning null if not a valid sensor type - static FilamentMonitor *Create(unsigned int extruder, unsigned int type); + static FilamentMonitor *Create(unsigned int extruder, unsigned int type) noexcept; - static void InterruptEntry(CallbackParameter param); + static void InterruptEntry(CallbackParameter param) noexcept; static Mutex filamentSensorsMutex; static FilamentMonitor *filamentSensors[MaxExtruders]; diff --git a/src/FilamentMonitors/LaserFilamentMonitor.cpp b/src/FilamentMonitors/LaserFilamentMonitor.cpp index e6a5f5c8..c793bf75 100644 --- a/src/FilamentMonitors/LaserFilamentMonitor.cpp +++ b/src/FilamentMonitors/LaserFilamentMonitor.cpp @@ -16,7 +16,7 @@ // is more likely to cause errors. This constant sets the delay required after a retract or reprime move before we accept the measurement. const int32_t SyncDelayMillis = 10; -LaserFilamentMonitor::LaserFilamentMonitor(unsigned int extruder, unsigned int type) +LaserFilamentMonitor::LaserFilamentMonitor(unsigned int extruder, unsigned int type) noexcept : Duet3DFilamentMonitor(extruder, type), minMovementAllowed(DefaultMinMovementAllowed), maxMovementAllowed(DefaultMaxMovementAllowed), minimumExtrusionCheckLength(DefaultMinimumExtrusionCheckLength), comparisonEnabled(false), checkNonPrintingMoves(false) @@ -25,7 +25,7 @@ LaserFilamentMonitor::LaserFilamentMonitor(unsigned int extruder, unsigned int t Init(); } -void LaserFilamentMonitor::Init() +void LaserFilamentMonitor::Init() noexcept { dataReceived = false; sensorValue = 0; @@ -39,7 +39,7 @@ void LaserFilamentMonitor::Init() Reset(); } -void LaserFilamentMonitor::Reset() +void LaserFilamentMonitor::Reset() noexcept { extrusionCommandedThisSegment = extrusionCommandedSinceLastSync = movementMeasuredThisSegment = movementMeasuredSinceLastSync = 0.0; laserMonitorState = LaserMonitorState::idle; @@ -141,7 +141,7 @@ bool LaserFilamentMonitor::Configure(GCodeBuffer& gb, const StringRef& reply, bo } // Return the current position -float LaserFilamentMonitor::GetCurrentPosition() const +float LaserFilamentMonitor::GetCurrentPosition() const noexcept { const uint16_t positionRange = (sensorValue & TypeLaserLargeDataRangeBitMask) ? TypeLaserLargeRange : TypeLaserDefaultRange; int32_t pos = (int32_t)(sensorValue & (positionRange - 1)); @@ -153,7 +153,7 @@ float LaserFilamentMonitor::GetCurrentPosition() const } // Deal with any received data -void LaserFilamentMonitor::HandleIncomingData() +void LaserFilamentMonitor::HandleIncomingData() noexcept { uint16_t val; PollResult res; @@ -257,7 +257,7 @@ void LaserFilamentMonitor::HandleIncomingData() // 'filamentConsumed' is the net amount of extrusion commanded since the last call to this function. // 'hadNonPrintingMove' is true if filamentConsumed includes extruder movement from non-printing moves. // 'fromIsr' is true if this measurement was taken at the end of the ISR because a potential start bit was seen -FilamentSensorStatus LaserFilamentMonitor::Check(bool isPrinting, bool fromIsr, uint32_t isrMillis, float filamentConsumed) +FilamentSensorStatus LaserFilamentMonitor::Check(bool isPrinting, bool fromIsr, uint32_t isrMillis, float filamentConsumed) noexcept { // 1. Update the extrusion commanded and whether we have had an extruding but non-printing move extrusionCommandedSinceLastSync += filamentConsumed; @@ -303,7 +303,7 @@ FilamentSensorStatus LaserFilamentMonitor::Check(bool isPrinting, bool fromIsr, } // Compare the amount commanded with the amount of extrusion measured, and set up for the next comparison -FilamentSensorStatus LaserFilamentMonitor::CheckFilament(float amountCommanded, float amountMeasured, bool overdue) +FilamentSensorStatus LaserFilamentMonitor::CheckFilament(float amountCommanded, float amountMeasured, bool overdue) noexcept { if (reprap.Debug(moduleFilamentSensors)) { @@ -382,7 +382,7 @@ FilamentSensorStatus LaserFilamentMonitor::CheckFilament(float amountCommanded, } // Clear the measurement state. Called when we are not printing a file. Return the present/not present status if available. -FilamentSensorStatus LaserFilamentMonitor::Clear() +FilamentSensorStatus LaserFilamentMonitor::Clear() noexcept { Reset(); // call this first so that haveStartBitData and synced are false when we call HandleIncomingData HandleIncomingData(); // to keep the diagnostics up to date @@ -393,7 +393,7 @@ FilamentSensorStatus LaserFilamentMonitor::Clear() } // Print diagnostic info for this sensor -void LaserFilamentMonitor::Diagnostics(MessageType mtype, unsigned int extruder) +void LaserFilamentMonitor::Diagnostics(MessageType mtype, unsigned int extruder) noexcept { String buf; buf.printf("Extruder %u: ", extruder); diff --git a/src/FilamentMonitors/LaserFilamentMonitor.h b/src/FilamentMonitors/LaserFilamentMonitor.h index 3264d1cf..ae48cec0 100644 --- a/src/FilamentMonitors/LaserFilamentMonitor.h +++ b/src/FilamentMonitors/LaserFilamentMonitor.h @@ -13,12 +13,12 @@ class LaserFilamentMonitor : public Duet3DFilamentMonitor { public: - LaserFilamentMonitor(unsigned int extruder, unsigned int type); + LaserFilamentMonitor(unsigned int extruder, unsigned int type) noexcept; bool Configure(GCodeBuffer& gb, const StringRef& reply, bool& seen) override; - FilamentSensorStatus Check(bool isPrinting, bool fromIsr, uint32_t isrMillis, float filamentConsumed) override; - FilamentSensorStatus Clear() override; - void Diagnostics(MessageType mtype, unsigned int extruder) override; + FilamentSensorStatus Check(bool isPrinting, bool fromIsr, uint32_t isrMillis, float filamentConsumed) noexcept override; + FilamentSensorStatus Clear() noexcept override; + void Diagnostics(MessageType mtype, unsigned int extruder) noexcept override; private: static constexpr float DefaultMinMovementAllowed = 0.6; @@ -61,11 +61,11 @@ private: static constexpr size_t EdgeCaptureBufferSize = 64; // must be a power of 2 - void Init(); - void Reset(); - void HandleIncomingData(); - float GetCurrentPosition() const; - FilamentSensorStatus CheckFilament(float amountCommanded, float amountMeasured, bool overdue); + void Init() noexcept; + void Reset() noexcept; + void HandleIncomingData() noexcept; + float GetCurrentPosition() const noexcept; + FilamentSensorStatus CheckFilament(float amountCommanded, float amountMeasured, bool overdue) noexcept; // Configuration parameters float minMovementAllowed, maxMovementAllowed; diff --git a/src/FilamentMonitors/PulsedFilamentMonitor.cpp b/src/FilamentMonitors/PulsedFilamentMonitor.cpp index 4a9101a3..8d894d2e 100644 --- a/src/FilamentMonitors/PulsedFilamentMonitor.cpp +++ b/src/FilamentMonitors/PulsedFilamentMonitor.cpp @@ -16,7 +16,7 @@ // is more likely to cause errors. This constant sets the delay required after a retract or reprime move before we accept the measurement. const int32_t SyncDelayMillis = 10; -PulsedFilamentMonitor::PulsedFilamentMonitor(unsigned int extruder, unsigned int type) +PulsedFilamentMonitor::PulsedFilamentMonitor(unsigned int extruder, unsigned int type) noexcept : FilamentMonitor(extruder, type), mmPerPulse(DefaultMmPerPulse), minMovementAllowed(DefaultMinMovementAllowed), maxMovementAllowed(DefaultMaxMovementAllowed), @@ -25,7 +25,7 @@ PulsedFilamentMonitor::PulsedFilamentMonitor(unsigned int extruder, unsigned int Init(); } -void PulsedFilamentMonitor::Init() +void PulsedFilamentMonitor::Init() noexcept { sensorValue = 0; calibrationStarted = false; @@ -34,7 +34,7 @@ void PulsedFilamentMonitor::Init() Reset(); } -void PulsedFilamentMonitor::Reset() +void PulsedFilamentMonitor::Reset() noexcept { extrusionCommandedThisSegment = extrusionCommandedSinceLastSync = movementMeasuredThisSegment = movementMeasuredSinceLastSync = 0.0; comparisonStarted = false; @@ -116,7 +116,7 @@ bool PulsedFilamentMonitor::Configure(GCodeBuffer& gb, const StringRef& reply, b } // ISR for when the pin state changes. It should return true if the ISR wants the commanded extrusion to be fetched. -bool PulsedFilamentMonitor::Interrupt() +bool PulsedFilamentMonitor::Interrupt() noexcept { ++sensorValue; if (samplesReceived < 100) @@ -136,7 +136,7 @@ bool PulsedFilamentMonitor::Interrupt() } // Call the following regularly to keep the status up to date -void PulsedFilamentMonitor::Poll() +void PulsedFilamentMonitor::Poll() noexcept { cpu_irq_disable(); const uint32_t locSensorVal = sensorValue; @@ -164,7 +164,7 @@ void PulsedFilamentMonitor::Poll() // 'filamentConsumed' is the net amount of extrusion since the last call to this function. // 'isPrinting' is true unless a non-printing extruder move was in progress // 'fromIsr' is true if this measurement was taken at the end of the ISR because the ISR returned true -FilamentSensorStatus PulsedFilamentMonitor::Check(bool isPrinting, bool fromIsr, uint32_t isrMillis, float filamentConsumed) +FilamentSensorStatus PulsedFilamentMonitor::Check(bool isPrinting, bool fromIsr, uint32_t isrMillis, float filamentConsumed) noexcept { // 1. Update the extrusion commanded extrusionCommandedSinceLastSync += filamentConsumed; @@ -199,7 +199,7 @@ FilamentSensorStatus PulsedFilamentMonitor::Check(bool isPrinting, bool fromIsr, } // Compare the amount commanded with the amount of extrusion measured, and set up for the next comparison -FilamentSensorStatus PulsedFilamentMonitor::CheckFilament(float amountCommanded, float amountMeasured, bool overdue) +FilamentSensorStatus PulsedFilamentMonitor::CheckFilament(float amountCommanded, float amountMeasured, bool overdue) noexcept { if (reprap.Debug(moduleFilamentSensors)) { @@ -263,7 +263,7 @@ FilamentSensorStatus PulsedFilamentMonitor::CheckFilament(float amountCommanded, } // Clear the measurement state - called when we are not printing a file. Return the present/not present status if available. -FilamentSensorStatus PulsedFilamentMonitor::Clear() +FilamentSensorStatus PulsedFilamentMonitor::Clear() noexcept { Poll(); // to keep the diagnostics up to date Reset(); @@ -271,7 +271,7 @@ FilamentSensorStatus PulsedFilamentMonitor::Clear() } // Print diagnostic info for this sensor -void PulsedFilamentMonitor::Diagnostics(MessageType mtype, unsigned int extruder) +void PulsedFilamentMonitor::Diagnostics(MessageType mtype, unsigned int extruder) noexcept { Poll(); const char* const statusText = (samplesReceived < 2) ? "no data received" : "ok"; diff --git a/src/FilamentMonitors/PulsedFilamentMonitor.h b/src/FilamentMonitors/PulsedFilamentMonitor.h index 1664b3d3..f9423680 100644 --- a/src/FilamentMonitors/PulsedFilamentMonitor.h +++ b/src/FilamentMonitors/PulsedFilamentMonitor.h @@ -13,13 +13,13 @@ class PulsedFilamentMonitor : public FilamentMonitor { public: - PulsedFilamentMonitor(unsigned int extruder, unsigned int type); + PulsedFilamentMonitor(unsigned int extruder, unsigned int type) noexcept; bool Configure(GCodeBuffer& gb, const StringRef& reply, bool& seen) override; - FilamentSensorStatus Check(bool isPrinting, bool fromIsr, uint32_t isrMillis, float filamentConsumed) override; - FilamentSensorStatus Clear() override; - void Diagnostics(MessageType mtype, unsigned int extruder) override; - bool Interrupt() override; + FilamentSensorStatus Check(bool isPrinting, bool fromIsr, uint32_t isrMillis, float filamentConsumed) noexcept override; + FilamentSensorStatus Clear() noexcept override; + void Diagnostics(MessageType mtype, unsigned int extruder) noexcept override; + bool Interrupt() noexcept override; private: static constexpr float DefaultMmPerPulse = 1.0; @@ -27,10 +27,10 @@ private: static constexpr float DefaultMaxMovementAllowed = 1.6; static constexpr float DefaultMinimumExtrusionCheckLength = 5.0; - void Init(); - void Reset(); - void Poll(); - FilamentSensorStatus CheckFilament(float amountCommanded, float amountMeasured, bool overdue); + void Init() noexcept; + void Reset() noexcept; + void Poll() noexcept; + FilamentSensorStatus CheckFilament(float amountCommanded, float amountMeasured, bool overdue) noexcept; // Configuration parameters float mmPerPulse; diff --git a/src/FilamentMonitors/RotatingMagnetFilamentMonitor.cpp b/src/FilamentMonitors/RotatingMagnetFilamentMonitor.cpp index 9a0dfc2b..6cd95c88 100644 --- a/src/FilamentMonitors/RotatingMagnetFilamentMonitor.cpp +++ b/src/FilamentMonitors/RotatingMagnetFilamentMonitor.cpp @@ -16,7 +16,7 @@ // is more likely to cause errors. This constant sets the delay required after a retract or reprime move before we accept the measurement. const int32_t SyncDelayMillis = 10; -RotatingMagnetFilamentMonitor::RotatingMagnetFilamentMonitor(unsigned int extruder, unsigned int type) +RotatingMagnetFilamentMonitor::RotatingMagnetFilamentMonitor(unsigned int extruder, unsigned int type) noexcept : Duet3DFilamentMonitor(extruder, type), mmPerRev(DefaultMmPerRev), minMovementAllowed(DefaultMinMovementAllowed), maxMovementAllowed(DefaultMaxMovementAllowed), @@ -26,7 +26,7 @@ RotatingMagnetFilamentMonitor::RotatingMagnetFilamentMonitor(unsigned int extrud Init(); } -void RotatingMagnetFilamentMonitor::Init() +void RotatingMagnetFilamentMonitor::Init() noexcept { dataReceived = false; sensorValue = 0; @@ -42,7 +42,7 @@ void RotatingMagnetFilamentMonitor::Init() Reset(); } -void RotatingMagnetFilamentMonitor::Reset() +void RotatingMagnetFilamentMonitor::Reset() noexcept { extrusionCommandedThisSegment = extrusionCommandedSinceLastSync = movementMeasuredThisSegment = movementMeasuredSinceLastSync = 0.0; magneticMonitorState = MagneticMonitorState::idle; @@ -143,13 +143,13 @@ bool RotatingMagnetFilamentMonitor::Configure(GCodeBuffer& gb, const StringRef& } // Return the current wheel angle -float RotatingMagnetFilamentMonitor::GetCurrentPosition() const +float RotatingMagnetFilamentMonitor::GetCurrentPosition() const noexcept { return (sensorValue & TypeMagnetAngleMask) * (360.0/1024.0); } // Deal with any received data -void RotatingMagnetFilamentMonitor::HandleIncomingData() +void RotatingMagnetFilamentMonitor::HandleIncomingData() noexcept { uint16_t val; PollResult res; @@ -289,7 +289,7 @@ void RotatingMagnetFilamentMonitor::HandleIncomingData() // 'filamentConsumed' is the net amount of extrusion commanded since the last call to this function. // 'hadNonPrintingMove' is true if filamentConsumed includes extruder movement from non-printing moves. // 'fromIsr' is true if this measurement was taken at the end of the ISR because a potential start bit was seen -FilamentSensorStatus RotatingMagnetFilamentMonitor::Check(bool isPrinting, bool fromIsr, uint32_t isrMillis, float filamentConsumed) +FilamentSensorStatus RotatingMagnetFilamentMonitor::Check(bool isPrinting, bool fromIsr, uint32_t isrMillis, float filamentConsumed) noexcept { // 1. Update the extrusion commanded and whether we have had an extruding but non-printing move extrusionCommandedSinceLastSync += filamentConsumed; @@ -335,7 +335,7 @@ FilamentSensorStatus RotatingMagnetFilamentMonitor::Check(bool isPrinting, bool } // Compare the amount commanded with the amount of extrusion measured, and set up for the next comparison -FilamentSensorStatus RotatingMagnetFilamentMonitor::CheckFilament(float amountCommanded, float amountMeasured, bool overdue) +FilamentSensorStatus RotatingMagnetFilamentMonitor::CheckFilament(float amountCommanded, float amountMeasured, bool overdue) noexcept { if (reprap.Debug(moduleFilamentSensors)) { @@ -419,7 +419,7 @@ FilamentSensorStatus RotatingMagnetFilamentMonitor::CheckFilament(float amountCo } // Clear the measurement state. Called when we are not printing a file. Return the present/not present status if available. -FilamentSensorStatus RotatingMagnetFilamentMonitor::Clear() +FilamentSensorStatus RotatingMagnetFilamentMonitor::Clear() noexcept { Reset(); // call this first so that haveStartBitData and synced are false when we call HandleIncomingData HandleIncomingData(); // to keep the diagnostics up to date @@ -430,7 +430,7 @@ FilamentSensorStatus RotatingMagnetFilamentMonitor::Clear() } // Print diagnostic info for this sensor -void RotatingMagnetFilamentMonitor::Diagnostics(MessageType mtype, unsigned int extruder) +void RotatingMagnetFilamentMonitor::Diagnostics(MessageType mtype, unsigned int extruder) noexcept { String buf; buf.printf("Extruder %u: ", extruder); diff --git a/src/FilamentMonitors/RotatingMagnetFilamentMonitor.h b/src/FilamentMonitors/RotatingMagnetFilamentMonitor.h index b3ed01a6..a56ae62e 100644 --- a/src/FilamentMonitors/RotatingMagnetFilamentMonitor.h +++ b/src/FilamentMonitors/RotatingMagnetFilamentMonitor.h @@ -13,12 +13,12 @@ class RotatingMagnetFilamentMonitor : public Duet3DFilamentMonitor { public: - RotatingMagnetFilamentMonitor(unsigned int extruder, unsigned int type); + RotatingMagnetFilamentMonitor(unsigned int extruder, unsigned int type) noexcept; bool Configure(GCodeBuffer& gb, const StringRef& reply, bool& seen) override; - FilamentSensorStatus Check(bool isPrinting, bool fromIsr, uint32_t isrMillis, float filamentConsumed) override; - FilamentSensorStatus Clear() override; - void Diagnostics(MessageType mtype, unsigned int extruder) override; + FilamentSensorStatus Check(bool isPrinting, bool fromIsr, uint32_t isrMillis, float filamentConsumed) noexcept override; + FilamentSensorStatus Clear() noexcept override; + void Diagnostics(MessageType mtype, unsigned int extruder) noexcept override; private: static constexpr float DefaultMmPerRev = 28.8; @@ -50,11 +50,11 @@ private: static constexpr uint16_t TypeMagnetAngleMask = 0x03FF; // we use a 10-bit sensor angle - void Init(); - void Reset(); - void HandleIncomingData(); - float GetCurrentPosition() const; - FilamentSensorStatus CheckFilament(float amountCommanded, float amountMeasured, bool overdue); + void Init() noexcept; + void Reset() noexcept; + void HandleIncomingData() noexcept; + float GetCurrentPosition() const noexcept; + FilamentSensorStatus CheckFilament(float amountCommanded, float amountMeasured, bool overdue) noexcept; // Configuration parameters float mmPerRev; diff --git a/src/FilamentMonitors/SimpleFilamentMonitor.cpp b/src/FilamentMonitors/SimpleFilamentMonitor.cpp index c3aed41c..51def779 100644 --- a/src/FilamentMonitors/SimpleFilamentMonitor.cpp +++ b/src/FilamentMonitors/SimpleFilamentMonitor.cpp @@ -10,7 +10,7 @@ #include "Platform.h" #include "GCodes/GCodeBuffer/GCodeBuffer.h" -SimpleFilamentMonitor::SimpleFilamentMonitor(unsigned int extruder, unsigned int type) +SimpleFilamentMonitor::SimpleFilamentMonitor(unsigned int extruder, unsigned int type) noexcept : FilamentMonitor(extruder, type), highWhenNoFilament(type == 2), filamentPresent(false), enabled(false) { } @@ -47,7 +47,7 @@ bool SimpleFilamentMonitor::Configure(GCodeBuffer& gb, const StringRef& reply, b } // ISR for when the pin state changes -bool SimpleFilamentMonitor::Interrupt() +bool SimpleFilamentMonitor::Interrupt() noexcept { // Nothing needed here GetPort().DetachInterrupt(); @@ -55,7 +55,7 @@ bool SimpleFilamentMonitor::Interrupt() } // Call the following regularly to keep the status up to date -void SimpleFilamentMonitor::Poll() +void SimpleFilamentMonitor::Poll() noexcept { const bool b = GetPort().Read(); filamentPresent = (highWhenNoFilament) ? !b : b; @@ -63,21 +63,21 @@ void SimpleFilamentMonitor::Poll() // Call the following at intervals to check the status. This is only called when extrusion is in progress or imminent. // 'filamentConsumed' is the net amount of extrusion since the last call to this function. -FilamentSensorStatus SimpleFilamentMonitor::Check(bool isPrinting, bool fromIsr, uint32_t isrMillis, float filamentConsumed) +FilamentSensorStatus SimpleFilamentMonitor::Check(bool isPrinting, bool fromIsr, uint32_t isrMillis, float filamentConsumed) noexcept { Poll(); return (!enabled || filamentPresent) ? FilamentSensorStatus::ok : FilamentSensorStatus::noFilament; } // Clear the measurement state - called when we are not printing a file. Return the present/not present status if available. -FilamentSensorStatus SimpleFilamentMonitor::Clear() +FilamentSensorStatus SimpleFilamentMonitor::Clear() noexcept { Poll(); return (!enabled || filamentPresent) ? FilamentSensorStatus::ok : FilamentSensorStatus::noFilament; } // Print diagnostic info for this sensor -void SimpleFilamentMonitor::Diagnostics(MessageType mtype, unsigned int extruder) +void SimpleFilamentMonitor::Diagnostics(MessageType mtype, unsigned int extruder) noexcept { Poll(); reprap.GetPlatform().MessageF(mtype, "Extruder %u sensor: %s\n", extruder, (filamentPresent) ? "ok" : "no filament"); diff --git a/src/FilamentMonitors/SimpleFilamentMonitor.h b/src/FilamentMonitors/SimpleFilamentMonitor.h index 116ceba5..232569c3 100644 --- a/src/FilamentMonitors/SimpleFilamentMonitor.h +++ b/src/FilamentMonitors/SimpleFilamentMonitor.h @@ -13,16 +13,16 @@ class SimpleFilamentMonitor : public FilamentMonitor { public: - SimpleFilamentMonitor(unsigned int extruder, unsigned int type); + SimpleFilamentMonitor(unsigned int extruder, unsigned int type) noexcept; bool Configure(GCodeBuffer& gb, const StringRef& reply, bool& seen) override; - FilamentSensorStatus Check(bool isPrinting, bool fromIsr, uint32_t isrMillis, float filamentConsumed) override; - FilamentSensorStatus Clear() override; - void Diagnostics(MessageType mtype, unsigned int extruder) override; - bool Interrupt() override; + FilamentSensorStatus Check(bool isPrinting, bool fromIsr, uint32_t isrMillis, float filamentConsumed) noexcept override; + FilamentSensorStatus Clear() noexcept override; + void Diagnostics(MessageType mtype, unsigned int extruder) noexcept override; + bool Interrupt() noexcept override; private: - void Poll(); + void Poll() noexcept; bool highWhenNoFilament; bool filamentPresent; diff --git a/src/Heating/FOPDT.cpp b/src/Heating/FOPDT.cpp index 94152fa2..8a68b796 100644 --- a/src/Heating/FOPDT.cpp +++ b/src/Heating/FOPDT.cpp @@ -17,14 +17,14 @@ // Heater 6 on the Duet 0.8.5 is disabled by default at startup so that we can use fan 2. // Set up sensible defaults here in case the user enables the heater without specifying values for all the parameters. -FopDt::FopDt() +FopDt::FopDt() noexcept : gain(DefaultHotEndHeaterGain), timeConstant(DefaultHotEndHeaterTimeConstant), deadTime(DefaultHotEndHeaterDeadTime), maxPwm(1.0), standardVoltage(0.0), enabled(false), usePid(true), inverted(false), pidParametersOverridden(false) { } // Check the model parameters are sensible, if they are then save them and return true. -bool FopDt::SetParameters(float pg, float ptc, float pdt, float pMaxPwm, float temperatureLimit, float pVoltage, bool pUsePid, bool pInverted) +bool FopDt::SetParameters(float pg, float ptc, float pdt, float pMaxPwm, float temperatureLimit, float pVoltage, bool pUsePid, bool pInverted) noexcept { if (pg == -1.0 && ptc == -1.0 && pdt == -1.0) { @@ -52,7 +52,7 @@ bool FopDt::SetParameters(float pg, float ptc, float pdt, float pMaxPwm, float t } // Get the PID parameters as reported by M301 -M301PidParameters FopDt::GetM301PidParameters(bool forLoadChange) const +M301PidParameters FopDt::GetM301PidParameters(bool forLoadChange) const noexcept { M301PidParameters rslt; const PidParameters& pp = GetPidParameters(forLoadChange); @@ -64,7 +64,7 @@ M301PidParameters FopDt::GetM301PidParameters(bool forLoadChange) const } // Override the PID parameters. We set both sets to the same parameters. -void FopDt::SetM301PidParameters(const M301PidParameters& pp) +void FopDt::SetM301PidParameters(const M301PidParameters& pp) noexcept { loadChangeParams.kP = setpointChangeParams.kP = pp.kP * (1.0/255.0); loadChangeParams.recipTi = setpointChangeParams.recipTi = pp.kI/pp.kP; @@ -75,7 +75,7 @@ void FopDt::SetM301PidParameters(const M301PidParameters& pp) #if HAS_MASS_STORAGE // Write the model parameters to file returning true if no error -bool FopDt::WriteParameters(FileStore *f, size_t heater) const +bool FopDt::WriteParameters(FileStore *f, size_t heater) const noexcept { String scratchString; scratchString.printf("M307 H%u A%.1f C%.1f D%.1f S%.2f V%.1f B%d\n", @@ -122,7 +122,7 @@ bool FopDt::WriteParameters(FileStore *f, size_t heater) const * ones tend to have massive overshoot when the setpoint is changed, and even in the steady state some of them have marginal stability. */ -void FopDt::CalcPidConstants() +void FopDt::CalcPidConstants() noexcept { const float timeFrac = deadTime/timeConstant; loadChangeParams.kP = 0.7/(gain * timeFrac); @@ -138,7 +138,7 @@ void FopDt::CalcPidConstants() #if SUPPORT_CAN_EXPANSION -void FopDt::SetupCanMessage(unsigned int heater, CanMessageUpdateHeaterModel& msg) +void FopDt::SetupCanMessage(unsigned int heater, CanMessageUpdateHeaterModel& msg) noexcept { msg.heater = heater; msg.gain = gain; diff --git a/src/Heating/FOPDT.h b/src/Heating/FOPDT.h index 208e1b5b..0a7c033e 100644 --- a/src/Heating/FOPDT.h +++ b/src/Heating/FOPDT.h @@ -39,37 +39,37 @@ struct CanMessageUpdateHeaterModel; class FopDt { public: - FopDt(); - - bool SetParameters(float pg, float ptc, float pdt, float pMaxPwm, float temperatureLimit, float pVoltage, bool pUsePid, bool pInverted); - - float GetGain() const { return gain; } - float GetTimeConstant() const { return timeConstant; } - float GetDeadTime() const { return deadTime; } - float GetMaxPwm() const { return maxPwm; } - float GetVoltage() const { return standardVoltage; } - bool UsePid() const { return usePid; } - bool IsInverted() const { return inverted; } - bool IsEnabled() const { return enabled; } - bool ArePidParametersOverridden() const { return pidParametersOverridden; } - M301PidParameters GetM301PidParameters(bool forLoadChange) const; - void SetM301PidParameters(const M301PidParameters& params); - - const PidParameters& GetPidParameters(bool forLoadChange) const + FopDt() noexcept; + + bool SetParameters(float pg, float ptc, float pdt, float pMaxPwm, float temperatureLimit, float pVoltage, bool pUsePid, bool pInverted) noexcept; + + float GetGain() const noexcept { return gain; } + float GetTimeConstant() const noexcept { return timeConstant; } + float GetDeadTime() const noexcept { return deadTime; } + float GetMaxPwm() const noexcept { return maxPwm; } + float GetVoltage() const noexcept { return standardVoltage; } + bool UsePid() const noexcept { return usePid; } + bool IsInverted() const noexcept { return inverted; } + bool IsEnabled() const noexcept { return enabled; } + bool ArePidParametersOverridden() const noexcept { return pidParametersOverridden; } + M301PidParameters GetM301PidParameters(bool forLoadChange) const noexcept; + void SetM301PidParameters(const M301PidParameters& params) noexcept; + + const PidParameters& GetPidParameters(bool forLoadChange) const noexcept { return (forLoadChange) ? loadChangeParams : setpointChangeParams; } #if HAS_MASS_STORAGE - bool WriteParameters(FileStore *f, size_t heater) const; // erite the model parameters to file returning true if no error + bool WriteParameters(FileStore *f, size_t heater) const noexcept; // erite the model parameters to file returning true if no error #endif #if SUPPORT_CAN_EXPANSION - void SetupCanMessage(unsigned int heater, CanMessageUpdateHeaterModel& msg); + void SetupCanMessage(unsigned int heater, CanMessageUpdateHeaterModel& msg) noexcept; #endif private: - void CalcPidConstants(); + void CalcPidConstants() noexcept; float gain; float timeConstant; diff --git a/src/Heating/Heat.cpp b/src/Heating/Heat.cpp index 5fcbf771..1ef6c48b 100644 --- a/src/Heating/Heat.cpp +++ b/src/Heating/Heat.cpp @@ -42,7 +42,7 @@ Licence: GPL constexpr uint32_t HeaterTaskStackWords = 400; // task stack size in dwords, must be large enough for auto tuning static Task heaterTask; -extern "C" [[noreturn]] void HeaterTaskStart(void * pvParameters) +extern "C" [[noreturn]] void HeaterTaskStart(void * pvParameters) noexcept { reprap.GetHeat().HeaterTask(); } @@ -50,7 +50,7 @@ extern "C" [[noreturn]] void HeaterTaskStart(void * pvParameters) static constexpr uint16_t SensorsTaskStackWords = 100; // task stack size in dwords. 80 was not enough. Use 300 if debugging is enabled. static Task *sensorsTask = nullptr; -extern "C" [[noreturn]] void SensorsTaskStart(void * pvParameters) +extern "C" [[noreturn]] void SensorsTaskStart(void * pvParameters) noexcept { reprap.GetHeat().SensorsTask(); } @@ -88,7 +88,7 @@ DEFINE_GET_OBJECT_MODEL_TABLE(Heat) ReadWriteLock Heat::heatersLock; ReadWriteLock Heat::sensorsLock; -Heat::Heat() +Heat::Heat() noexcept : sensorCount(0), sensorsRoot(nullptr), coldExtrude(false), heaterBeingTuned(-1), lastHeaterTuned(-1) { for (int8_t& h : bedHeaters) @@ -118,14 +118,14 @@ Heat::Heat() } } -ReadLockedPointer Heat::FindHeater(int heater) const +ReadLockedPointer Heat::FindHeater(int heater) const noexcept { ReadLocker locker(heatersLock); return ReadLockedPointer(locker, (heater < 0 || heater >= (int)MaxHeaters) ? nullptr : heaters[heater]); } // Process M307 -GCodeResult Heat::SetOrReportHeaterModel(GCodeBuffer& gb, const StringRef& reply) +GCodeResult Heat::SetOrReportHeaterModel(GCodeBuffer& gb, const StringRef& reply) noexcept { if (gb.Seen('H')) { @@ -195,7 +195,7 @@ GCodeResult Heat::SetOrReportHeaterModel(GCodeBuffer& gb, const StringRef& reply } // Process M301 or M304. 'heater' is the default heater number to use. -GCodeResult Heat::SetPidParameters(unsigned int heater, GCodeBuffer& gb, const StringRef& reply) +GCodeResult Heat::SetPidParameters(unsigned int heater, GCodeBuffer& gb, const StringRef& reply) noexcept { if (gb.Seen('H')) { @@ -236,14 +236,14 @@ GCodeResult Heat::SetPidParameters(unsigned int heater, GCodeBuffer& gb, const S } // Is the heater enabled? -bool Heat::IsHeaterEnabled(size_t heater) const +bool Heat::IsHeaterEnabled(size_t heater) const noexcept { const auto h = FindHeater(heater); return h.IsNotNull() && h->IsHeaterEnabled(); } // Get a pointer to the temperature sensor entry, or nullptr if the heater number is bad -ReadLockedPointer Heat::FindSensor(int sn) const +ReadLockedPointer Heat::FindSensor(int sn) const noexcept { ReadLocker locker(sensorsLock); @@ -258,7 +258,7 @@ ReadLockedPointer Heat::FindSensor(int sn) const } // Get a pointer to the first temperature sensor with the specified or higher number -ReadLockedPointer Heat::FindSensorAtOrAbove(unsigned int sn) const +ReadLockedPointer Heat::FindSensorAtOrAbove(unsigned int sn) const noexcept { ReadLocker locker(sensorsLock); @@ -274,7 +274,7 @@ ReadLockedPointer Heat::FindSensorAtOrAbove(unsigned int sn) // Reset all heater models to defaults. Called when running M502. -void Heat::ResetHeaterModels() +void Heat::ResetHeaterModels() noexcept { ReadLocker lock(heatersLock); @@ -287,7 +287,7 @@ void Heat::ResetHeaterModels() } } -void Heat::Init() +void Heat::Init() noexcept { // Initialise the heater protection items first for (size_t index : ARRAY_INDICES(heaterProtections)) @@ -305,7 +305,7 @@ void Heat::Init() heaterTask.Create(HeaterTaskStart, "HEAT", nullptr, TaskPriority::HeatPriority); } -void Heat::Exit() +void Heat::Exit() noexcept { { ReadLocker Lock(heatersLock); @@ -322,7 +322,7 @@ void Heat::Exit() heaterTask.Suspend(); } -[[noreturn]] void Heat::HeaterTask() +[[noreturn]] void Heat::HeaterTask() noexcept { uint32_t lastWakeTime = xTaskGetTickCount(); for (;;) @@ -409,7 +409,7 @@ void Heat::Exit() } -/* static */ void Heat::EnsureSensorsTask() +/* static */ void Heat::EnsureSensorsTask() noexcept { TaskCriticalSectionLocker lock; // make sure we don't create the task more than once @@ -422,7 +422,7 @@ void Heat::Exit() // Code executed by the SensorsTask. // This is run at the same priority as the Heat task, so it must not sit in any spin loops. -/*static*/ [[noreturn]] void Heat::SensorsTask() +/*static*/ [[noreturn]] void Heat::SensorsTask() noexcept { auto lastWakeTime = xTaskGetTickCount(); for (;;) @@ -469,7 +469,7 @@ void Heat::Exit() } } -void Heat::Diagnostics(MessageType mtype) +void Heat::Diagnostics(MessageType mtype) noexcept { Platform& platform = reprap.GetPlatform(); platform.Message(mtype, "=== Heat ===\nBed heaters ="); @@ -504,7 +504,7 @@ void Heat::Diagnostics(MessageType mtype) } // Configure a heater. Invoked by M950. -GCodeResult Heat::ConfigureHeater(size_t heater, GCodeBuffer& gb, const StringRef& reply) +GCodeResult Heat::ConfigureHeater(size_t heater, GCodeBuffer& gb, const StringRef& reply) noexcept { if (heater >= MaxHeaters) { @@ -585,7 +585,7 @@ GCodeResult Heat::ConfigureHeater(size_t heater, GCodeBuffer& gb, const StringRe return h->ReportDetails(reply); } -bool Heat::AllHeatersAtSetTemperatures(bool includingBed, float tolerance) const +bool Heat::AllHeatersAtSetTemperatures(bool includingBed, float tolerance) const noexcept { for (size_t heater : ARRAY_INDICES(heaters)) { @@ -598,7 +598,7 @@ bool Heat::AllHeatersAtSetTemperatures(bool includingBed, float tolerance) const } //query an individual heater -bool Heat::HeaterAtSetTemperature(int heater, bool waitWhenCooling, float tolerance) const +bool Heat::HeaterAtSetTemperature(int heater, bool waitWhenCooling, float tolerance) const noexcept { const auto h = FindHeater(heater); if (h.IsNotNull()) @@ -619,13 +619,13 @@ bool Heat::HeaterAtSetTemperature(int heater, bool waitWhenCooling, float tolera return true; } -HeaterStatus Heat::GetStatus(int heater) const +HeaterStatus Heat::GetStatus(int heater) const noexcept { const auto h = FindHeater(heater); return (h.IsNull()) ? HeaterStatus::off : heaters[heater]->GetStatus(); } -void Heat::SetBedHeater(size_t index, int heater) +void Heat::SetBedHeater(size_t index, int heater) noexcept { const auto h = FindHeater(bedHeaters[index]); if (h.IsNotNull()) @@ -635,7 +635,7 @@ void Heat::SetBedHeater(size_t index, int heater) bedHeaters[index] = heater; } -bool Heat::IsBedHeater(int heater) const +bool Heat::IsBedHeater(int heater) const noexcept { for (int8_t bedHeater : bedHeaters) { @@ -647,7 +647,7 @@ bool Heat::IsBedHeater(int heater) const return false; } -void Heat::SetChamberHeater(size_t index, int heater) +void Heat::SetChamberHeater(size_t index, int heater) noexcept { const auto h = FindHeater(chamberHeaters[index]); if (h.IsNotNull()) @@ -657,7 +657,7 @@ void Heat::SetChamberHeater(size_t index, int heater) chamberHeaters[index] = heater; } -bool Heat::IsChamberHeater(int heater) const +bool Heat::IsChamberHeater(int heater) const noexcept { for (int8_t chamberHeater : chamberHeaters) { @@ -669,7 +669,7 @@ bool Heat::IsChamberHeater(int heater) const return false; } -void Heat::SetActiveTemperature(int heater, float t) +void Heat::SetActiveTemperature(int heater, float t) noexcept { const auto h = FindHeater(heater); if (h.IsNotNull()) @@ -678,13 +678,13 @@ void Heat::SetActiveTemperature(int heater, float t) } } -float Heat::GetActiveTemperature(int heater) const +float Heat::GetActiveTemperature(int heater) const noexcept { const auto h = FindHeater(heater); return (h.IsNull()) ? ABS_ZERO : h->GetActiveTemperature(); } -void Heat::SetStandbyTemperature(int heater, float t) +void Heat::SetStandbyTemperature(int heater, float t) noexcept { const auto h = FindHeater(heater); if (h.IsNotNull()) @@ -693,13 +693,13 @@ void Heat::SetStandbyTemperature(int heater, float t) } } -float Heat::GetStandbyTemperature(int heater) const +float Heat::GetStandbyTemperature(int heater) const noexcept { const auto h = FindHeater(heater); return (h.IsNull()) ? ABS_ZERO : h->GetStandbyTemperature(); } -float Heat::GetHighestTemperatureLimit(int heater) const +float Heat::GetHighestTemperatureLimit(int heater) const noexcept { float limit = BadErrorTemperature; if (heater >= 0 && heater < (int)MaxHeaters) @@ -719,7 +719,7 @@ float Heat::GetHighestTemperatureLimit(int heater) const return limit; } -float Heat::GetLowestTemperatureLimit(int heater) const +float Heat::GetLowestTemperatureLimit(int heater) const noexcept { float limit = ABS_ZERO; if (heater >= 0 && heater < (int)MaxHeaters) @@ -741,14 +741,14 @@ float Heat::GetLowestTemperatureLimit(int heater) const // Get the current temperature of a real or virtual heater // Return ABS_ZERO if the heater doesn't exist. The Z probe class relies on this. -float Heat::GetHeaterTemperature(int heater) const +float Heat::GetHeaterTemperature(int heater) const noexcept { const auto h = FindHeater(heater); return (h.IsNull()) ? ABS_ZERO : h->GetTemperature(); } // Get the target temperature of a heater -float Heat::GetTargetTemperature(int heater) const +float Heat::GetTargetTemperature(int heater) const noexcept { const HeaterStatus hs = GetStatus(heater); return (hs == HeaterStatus::active) ? GetActiveTemperature(heater) @@ -756,7 +756,7 @@ float Heat::GetTargetTemperature(int heater) const : 0.0; } -GCodeResult Heat::Activate(int heater, const StringRef& reply) +GCodeResult Heat::Activate(int heater, const StringRef& reply) noexcept { const auto h = FindHeater(heater); if (h.IsNotNull()) @@ -767,7 +767,7 @@ GCodeResult Heat::Activate(int heater, const StringRef& reply) return GCodeResult::error; } -void Heat::SwitchOff(int heater) +void Heat::SwitchOff(int heater) noexcept { const auto h = FindHeater(heater); if (h.IsNotNull()) @@ -777,7 +777,7 @@ void Heat::SwitchOff(int heater) } } -void Heat::SwitchOffAll(bool includingChamberAndBed) +void Heat::SwitchOffAll(bool includingChamberAndBed) noexcept { ReadLocker lock(heatersLock); @@ -791,7 +791,7 @@ void Heat::SwitchOffAll(bool includingChamberAndBed) } } -void Heat::Standby(int heater, const Tool *tool) +void Heat::Standby(int heater, const Tool *tool) noexcept { const auto h = FindHeater(heater); if (h.IsNotNull()) @@ -801,26 +801,26 @@ void Heat::Standby(int heater, const Tool *tool) } } -GCodeResult Heat::ResetFault(int heater, const StringRef& reply) +GCodeResult Heat::ResetFault(int heater, const StringRef& reply) noexcept { // This gets called for all heater numbers when clearing all temperature faults, so don't report an error if the heater was not found const auto h = FindHeater(heater); return (h.IsNotNull()) ? h->ResetFault(reply) : GCodeResult::ok; } -float Heat::GetAveragePWM(size_t heater) const +float Heat::GetAveragePWM(size_t heater) const noexcept { const auto h = FindHeater(heater); return (h.IsNull()) ? 0.0 : h->GetAveragePWM(); } -bool Heat::IsBedOrChamberHeater(int heater) const +bool Heat::IsBedOrChamberHeater(int heater) const noexcept { return IsBedHeater(heater) || IsChamberHeater(heater); } // Get the highest temperature limit of any heater -float Heat::GetHighestTemperatureLimit() const +float Heat::GetHighestTemperatureLimit() const noexcept { float limit = ABS_ZERO; for (HeaterProtection *prot : heaterProtections) @@ -840,7 +840,7 @@ float Heat::GetHighestTemperatureLimit() const #if HAS_MASS_STORAGE // Write heater model parameters to file returning true if no error -bool Heat::WriteModelParameters(FileStore *f) const +bool Heat::WriteModelParameters(FileStore *f) const noexcept { bool ok = f->Write("; Heater model parameters\n"); for (size_t h : ARRAY_INDICES(heaters)) @@ -860,7 +860,7 @@ bool Heat::WriteModelParameters(FileStore *f) const #endif // Process M570 -GCodeResult Heat::ConfigureHeaterMonitoring(size_t heater, GCodeBuffer& gb, const StringRef& reply) +GCodeResult Heat::ConfigureHeaterMonitoring(size_t heater, GCodeBuffer& gb, const StringRef& reply) noexcept { const auto h = FindHeater(heater); if (h.IsNull()) @@ -884,7 +884,7 @@ GCodeResult Heat::ConfigureHeaterMonitoring(size_t heater, GCodeBuffer& gb, cons } // Process M303 -GCodeResult Heat::TuneHeater(GCodeBuffer& gb, const StringRef& reply) +GCodeResult Heat::TuneHeater(GCodeBuffer& gb, const StringRef& reply) noexcept { if (gb.Seen('H')) { @@ -945,7 +945,7 @@ GCodeResult Heat::TuneHeater(GCodeBuffer& gb, const StringRef& reply) } // Process M308 -GCodeResult Heat::ConfigureSensor(GCodeBuffer& gb, const StringRef& reply) +GCodeResult Heat::ConfigureSensor(GCodeBuffer& gb, const StringRef& reply) noexcept { if (gb.Seen('S')) { @@ -1031,14 +1031,14 @@ GCodeResult Heat::ConfigureSensor(GCodeBuffer& gb, const StringRef& reply) } // Get the name of a heater, or nullptr if it hasn't been named -const char *Heat::GetHeaterSensorName(size_t heater) const +const char *Heat::GetHeaterSensorName(size_t heater) const noexcept { const auto h = FindHeater(heater); return (h.IsNotNull()) ? h->GetSensorName() : nullptr; } // Configure heater protection (M143). Returns true if an error occurred -GCodeResult Heat::SetHeaterProtection(GCodeBuffer& gb, const StringRef& reply) +GCodeResult Heat::SetHeaterProtection(GCodeBuffer& gb, const StringRef& reply) noexcept { WriteLocker lock(heatersLock); @@ -1163,7 +1163,7 @@ GCodeResult Heat::SetHeaterProtection(GCodeBuffer& gb, const StringRef& reply) } // Updates the PIDs and HeaterProtection items after a heater change. Caller must already have a write lock on the heaters. -void Heat::UpdateHeaterProtection(int heaterNumber) +void Heat::UpdateHeaterProtection(int heaterNumber) noexcept { auto h = FindHeater(heaterNumber); if (h.IsNotNull()) @@ -1199,7 +1199,7 @@ void Heat::UpdateHeaterProtection(int heaterNumber) } // Get the temperature of a sensor -float Heat::GetSensorTemperature(int sensorNum, TemperatureError& err) const +float Heat::GetSensorTemperature(int sensorNum, TemperatureError& err) const noexcept { const auto sensor = FindSensor(sensorNum); if (sensor.IsNotNull()) @@ -1214,7 +1214,7 @@ float Heat::GetSensorTemperature(int sensorNum, TemperatureError& err) const } // Return the highest used heater number. Used by RepRap.cpp to shorten responses by omitting unused trailing heater numbers. If no heaters are configured, return 0. -size_t Heat::GetHighestUsedHeaterNumber() const +size_t Heat::GetHighestUsedHeaterNumber() const noexcept { size_t highestHeater = ARRAY_SIZE(heaters); do @@ -1225,14 +1225,14 @@ size_t Heat::GetHighestUsedHeaterNumber() const } // Get the temperature of a heater -float Heat::GetHeaterTemperature(size_t heater) const +float Heat::GetHeaterTemperature(size_t heater) const noexcept { const auto h = FindHeater(heater); return (h.IsNull()) ? ABS_ZERO : h->GetTemperature(); } // Suspend the heaters to conserve power or while doing Z probing -void Heat::SuspendHeaters(bool sus) +void Heat::SuspendHeaters(bool sus) noexcept { for (Heater *h : heaters) { @@ -1244,7 +1244,7 @@ void Heat::SuspendHeaters(bool sus) } // Delete a sensor, if there is one. Must write-lock the sensors lock before calling this. -void Heat::DeleteSensor(unsigned int sn) +void Heat::DeleteSensor(unsigned int sn) noexcept { TemperatureSensor *currentSensor = sensorsRoot; TemperatureSensor *lastSensor = nullptr; @@ -1274,7 +1274,7 @@ void Heat::DeleteSensor(unsigned int sn) } // Insert a sensor. Must write-lock the sensors lock before calling this. -void Heat::InsertSensor(TemperatureSensor *newSensor) +void Heat::InsertSensor(TemperatureSensor *newSensor) noexcept { TemperatureSensor *prev = nullptr; TemperatureSensor *ts = sensorsRoot; @@ -1303,7 +1303,7 @@ void Heat::InsertSensor(TemperatureSensor *newSensor) // Save some resume information returning true if successful. // We assume that the bed and chamber heaters are either on and active, or off (not on standby). -bool Heat::WriteBedAndChamberTempSettings(FileStore *f) const +bool Heat::WriteBedAndChamberTempSettings(FileStore *f) const noexcept { String<100> bufSpace; const StringRef buf = bufSpace.GetRef(); @@ -1330,7 +1330,7 @@ bool Heat::WriteBedAndChamberTempSettings(FileStore *f) const #if SUPPORT_CAN_EXPANSION -void Heat::ProcessRemoteSensorsReport(CanAddress src, const CanMessageSensorTemperatures& msg) +void Heat::ProcessRemoteSensorsReport(CanAddress src, const CanMessageSensorTemperatures& msg) noexcept { uint64_t sensorsReported = msg.whichSensors; size_t index = 0; @@ -1352,7 +1352,7 @@ void Heat::ProcessRemoteSensorsReport(CanAddress src, const CanMessageSensorTemp } } -void Heat::ProcessRemoteHeatersReport(CanAddress src, const CanMessageHeatersStatus& msg) +void Heat::ProcessRemoteHeatersReport(CanAddress src, const CanMessageHeatersStatus& msg) noexcept { uint64_t heatersReported = msg.whichHeaters; size_t index = 0; diff --git a/src/Heating/Heat.h b/src/Heating/Heat.h index 379f3409..0862665a 100644 --- a/src/Heating/Heat.h +++ b/src/Heating/Heat.h @@ -42,104 +42,104 @@ class CanMessageHeatersStatus; class Heat INHERIT_OBJECT_MODEL { public: - Heat(); + Heat() noexcept; // Methods that don't relate to a particular heater - void HeaterTask(); - void Init(); // Set everything up - void Exit(); // Shut everything down - void ResetHeaterModels(); // Reset all active heater models to defaults - - bool ColdExtrude() const; // Is cold extrusion allowed? - void AllowColdExtrude(bool b); // Allow or deny cold extrusion - float GetExtrusionMinTemp() const; // Get minimum extrusion temperature - float GetRetractionMinTemp() const; // Get minimum retraction temperature - void SetExtrusionMinTemp(float t); // Set minimum extrusion temperature - void SetRetractionMinTemp(float t); // Set minimum retraction temperature - - int GetBedHeater(size_t index) const // Get a hot bed heater number + void HeaterTask() noexcept; + void Init() noexcept; // Set everything up + void Exit() noexcept; // Shut everything down + void ResetHeaterModels() noexcept; // Reset all active heater models to defaults + + bool ColdExtrude() const noexcept; // Is cold extrusion allowed? + void AllowColdExtrude(bool b) noexcept; // Allow or deny cold extrusion + float GetExtrusionMinTemp() const noexcept; // Get minimum extrusion temperature + float GetRetractionMinTemp() const noexcept; // Get minimum retraction temperature + void SetExtrusionMinTemp(float t) noexcept; // Set minimum extrusion temperature + void SetRetractionMinTemp(float t) noexcept; // Set minimum retraction temperature + + int GetBedHeater(size_t index) const noexcept // Get a hot bed heater number pre(index < NumBedHeaters); - void SetBedHeater(size_t index, int heater) // Set a hot bed heater number + void SetBedHeater(size_t index, int heater) noexcept // Set a hot bed heater number pre(index < NumBedHeaters; -1 <= heater; heater < MaxHeaters); - bool IsBedHeater(int heater) const; // Check if this heater is a bed heater + bool IsBedHeater(int heater) const noexcept; // Check if this heater is a bed heater - int GetChamberHeater(size_t index) const // Get a chamber heater number + int GetChamberHeater(size_t index) const noexcept // Get a chamber heater number pre(index < NumChamberHeaters); - void SetChamberHeater(size_t index, int heater) // Set a chamber heater number + void SetChamberHeater(size_t index, int heater) noexcept // Set a chamber heater number pre(index < NumChamberHeaters; -1 <= heater; heater < MaxHeaters); - bool IsChamberHeater(int heater) const; // Check if this heater is a chamber heater + bool IsChamberHeater(int heater) const noexcept; // Check if this heater is a chamber heater - bool AllHeatersAtSetTemperatures(bool includingBed, float tolerance) const; // Is everything at temperature within tolerance? + bool AllHeatersAtSetTemperatures(bool includingBed, float tolerance) const noexcept; // Is everything at temperature within tolerance? - void SwitchOffAll(bool includingChamberAndBed); // Turn all heaters off - GCodeResult ResetFault(int heater, const StringRef& reply); // Reset a heater fault for a specific heater or all heaters - GCodeResult SetOrReportHeaterModel(GCodeBuffer& gb, const StringRef& reply); - GCodeResult TuneHeater(GCodeBuffer& gb, const StringRef& reply); - GCodeResult ConfigureSensor(GCodeBuffer& gb, const StringRef& reply); // Create a sensor or change the parameters for an existing sensor - GCodeResult SetPidParameters(unsigned int heater, GCodeBuffer& gb, const StringRef& reply); // Set the P/I/D parameters for a heater + void SwitchOffAll(bool includingChamberAndBed) noexcept; // Turn all heaters off + GCodeResult ResetFault(int heater, const StringRef& reply) noexcept; // Reset a heater fault for a specific heater or all heaters + GCodeResult SetOrReportHeaterModel(GCodeBuffer& gb, const StringRef& reply) noexcept; + GCodeResult TuneHeater(GCodeBuffer& gb, const StringRef& reply) noexcept; + GCodeResult ConfigureSensor(GCodeBuffer& gb, const StringRef& reply) noexcept; // Create a sensor or change the parameters for an existing sensor + GCodeResult SetPidParameters(unsigned int heater, GCodeBuffer& gb, const StringRef& reply) noexcept; // Set the P/I/D parameters for a heater - GCodeResult SetHeaterProtection(GCodeBuffer &gb, const StringRef &reply); // Configure heater protection (M143) - void UpdateHeaterProtection(int heaterNumber); // Updates the PIDs and HeaterProtection items when a heater is remapped + GCodeResult SetHeaterProtection(GCodeBuffer &gb, const StringRef &reply) noexcept; // Configure heater protection (M143) + void UpdateHeaterProtection(int heaterNumber) noexcept; // Updates the PIDs and HeaterProtection items when a heater is remapped - void SuspendHeaters(bool sus); // Suspend the heaters to conserve power + void SuspendHeaters(bool sus) noexcept; // Suspend the heaters to conserve power - void SensorsTask(); - static void EnsureSensorsTask(); + void SensorsTask() noexcept; + static void EnsureSensorsTask() noexcept; - ReadLockedPointer FindSensor(int sn) const; // Get a pointer to the temperature sensor entry - ReadLockedPointer FindSensorAtOrAbove(unsigned int sn) const; // Get a pointer to the first temperature sensor with the specified or higher number + ReadLockedPointer FindSensor(int sn) const noexcept; // Get a pointer to the temperature sensor entry + ReadLockedPointer FindSensorAtOrAbove(unsigned int sn) const noexcept; // Get a pointer to the first temperature sensor with the specified or higher number - float GetSensorTemperature(int sensorNum, TemperatureError& err) const; // Result is in degrees Celsius + float GetSensorTemperature(int sensorNum, TemperatureError& err) const noexcept; // Result is in degrees Celsius - float GetHighestTemperatureLimit() const; // Get the highest temperature limit of any heater - size_t GetHighestUsedHeaterNumber() const; + float GetHighestTemperatureLimit() const noexcept; // Get the highest temperature limit of any heater + size_t GetHighestUsedHeaterNumber() const noexcept; - void Diagnostics(MessageType mtype); // Output useful information + void Diagnostics(MessageType mtype) noexcept; // Output useful information // Methods that relate to a particular heater - const char *GetHeaterSensorName(size_t heater) const; // Get the name of the sensor associated with heater, or nullptr if it hasn't been named - float GetAveragePWM(size_t heater) const // Return the running average PWM to the heater as a fraction in [0, 1]. + const char *GetHeaterSensorName(size_t heater) const noexcept; // Get the name of the sensor associated with heater, or nullptr if it hasn't been named + float GetAveragePWM(size_t heater) const noexcept // Return the running average PWM to the heater as a fraction in [0, 1]. pre(heater < MaxHeaters); - bool IsBedOrChamberHeater(int heater) const; // Queried by the Platform class + bool IsBedOrChamberHeater(int heater) const noexcept; // Queried by the Platform class - float GetHeaterTemperature(size_t heater) const; // Result is in degrees Celsius + float GetHeaterTemperature(size_t heater) const noexcept; // Result is in degrees Celsius - const Tool* GetLastStandbyTool(int heater) const + const Tool* GetLastStandbyTool(int heater) const noexcept pre(heater >= 0; heater < MaxHeaters) { return lastStandbyTools[heater]; } - bool IsHeaterEnabled(size_t heater) const; // Is this heater enabled? + bool IsHeaterEnabled(size_t heater) const noexcept; // Is this heater enabled? pre(heater < MaxHeaters); - float GetActiveTemperature(int heater) const; - float GetStandbyTemperature(int heater) const; - float GetHighestTemperatureLimit(int heater) const; - float GetLowestTemperatureLimit(int heater) const; - float GetHeaterTemperature(int heater) const; // Get the current temperature of a heater - float GetTargetTemperature(int heater) const; // Get the target temperature - HeaterStatus GetStatus(int heater) const; // Get the off/standby/active status - bool HeaterAtSetTemperature(int heater, bool waitWhenCooling, float tolerance) const; + float GetActiveTemperature(int heater) const noexcept; + float GetStandbyTemperature(int heater) const noexcept; + float GetHighestTemperatureLimit(int heater) const noexcept; + float GetLowestTemperatureLimit(int heater) const noexcept; + float GetHeaterTemperature(int heater) const noexcept; // Get the current temperature of a heater + float GetTargetTemperature(int heater) const noexcept; // Get the target temperature + HeaterStatus GetStatus(int heater) const noexcept; // Get the off/standby/active status + bool HeaterAtSetTemperature(int heater, bool waitWhenCooling, float tolerance) const noexcept; - GCodeResult ConfigureHeater(size_t heater, GCodeBuffer& gb, const StringRef& reply); - GCodeResult ConfigureHeaterMonitoring(size_t heater, GCodeBuffer& gb, const StringRef& reply); + GCodeResult ConfigureHeater(size_t heater, GCodeBuffer& gb, const StringRef& reply) noexcept; + GCodeResult ConfigureHeaterMonitoring(size_t heater, GCodeBuffer& gb, const StringRef& reply) noexcept; - void SetActiveTemperature(int heater, float t); - void SetStandbyTemperature(int heater, float t); - GCodeResult Activate(int heater, const StringRef& reply); // Turn on a heater - void Standby(int heater, const Tool* tool); // Set a heater to standby - void SwitchOff(int heater); // Turn off a specific heater + void SetActiveTemperature(int heater, float t) noexcept; + void SetStandbyTemperature(int heater, float t) noexcept; + GCodeResult Activate(int heater, const StringRef& reply) noexcept; // Turn on a heater + void Standby(int heater, const Tool* tool) noexcept; // Set a heater to standby + void SwitchOff(int heater) noexcept; // Turn off a specific heater #if HAS_MASS_STORAGE - bool WriteModelParameters(FileStore *f) const; // Write heater model parameters to file returning true if no error - bool WriteBedAndChamberTempSettings(FileStore *f) const; // Save some resume information + bool WriteModelParameters(FileStore *f) const noexcept; // Write heater model parameters to file returning true if no error + bool WriteBedAndChamberTempSettings(FileStore *f) const noexcept; // Save some resume information #endif #if SUPPORT_CAN_EXPANSION - void ProcessRemoteSensorsReport(CanAddress src, const CanMessageSensorTemperatures& msg); - void ProcessRemoteHeatersReport(CanAddress src, const CanMessageHeatersStatus& msg); + void ProcessRemoteSensorsReport(CanAddress src, const CanMessageSensorTemperatures& msg) noexcept; + void ProcessRemoteHeatersReport(CanAddress src, const CanMessageHeatersStatus& msg) noexcept; #endif protected: @@ -148,9 +148,9 @@ protected: private: Heat(const Heat&) = delete; // Private copy constructor to prevent copying - ReadLockedPointer FindHeater(int heater) const; - void DeleteSensor(unsigned int sn); - void InsertSensor(TemperatureSensor *newSensor); + ReadLockedPointer FindHeater(int heater) const noexcept; + void DeleteSensor(unsigned int sn) noexcept; + void InsertSensor(TemperatureSensor *newSensor) noexcept; static ReadWriteLock heatersLock; static ReadWriteLock sensorsLock; @@ -173,42 +173,42 @@ private: //*********************************************************************************************************** -inline bool Heat::ColdExtrude() const +inline bool Heat::ColdExtrude() const noexcept { return coldExtrude; } -inline void Heat::AllowColdExtrude(bool b) +inline void Heat::AllowColdExtrude(bool b) noexcept { coldExtrude = b; } -inline float Heat::GetExtrusionMinTemp() const +inline float Heat::GetExtrusionMinTemp() const noexcept { return extrusionMinTemp; } -inline float Heat::GetRetractionMinTemp() const +inline float Heat::GetRetractionMinTemp() const noexcept { return retractionMinTemp; } -inline void Heat::SetExtrusionMinTemp(float t) +inline void Heat::SetExtrusionMinTemp(float t) noexcept { extrusionMinTemp = t; } -inline void Heat::SetRetractionMinTemp(float t) +inline void Heat::SetRetractionMinTemp(float t) noexcept { retractionMinTemp = t; } -inline int Heat::GetBedHeater(size_t index) const +inline int Heat::GetBedHeater(size_t index) const noexcept { return bedHeaters[index]; } -inline int Heat::GetChamberHeater(size_t index) const +inline int Heat::GetChamberHeater(size_t index) const noexcept { return chamberHeaters[index]; } diff --git a/src/Heating/Heater.cpp b/src/Heating/Heater.cpp index a5ecb54c..87b7b57c 100644 --- a/src/Heating/Heater.cpp +++ b/src/Heating/Heater.cpp @@ -12,19 +12,19 @@ #include "HeaterProtection.h" #include "Sensors/TemperatureSensor.h" -Heater::Heater(unsigned int num) +Heater::Heater(unsigned int num) noexcept : heaterNumber(num), sensorNumber(-1), activeTemperature(0.0), standbyTemperature(0.0), maxTempExcursion(DefaultMaxTempExcursion), maxHeatingFaultTime(DefaultMaxHeatingFaultTime), heaterProtection(nullptr), active(false) { } -Heater::~Heater() +Heater::~Heater() noexcept { } // Set the process model returning true if successful -GCodeResult Heater::SetModel(float gain, float tc, float td, float maxPwm, float voltage, bool usePid, bool inverted, const StringRef& reply) +GCodeResult Heater::SetModel(float gain, float tc, float td, float maxPwm, float voltage, bool usePid, bool inverted, const StringRef& reply) noexcept { const float temperatureLimit = GetHighestTemperatureLimit(); const bool rslt = model.SetParameters(gain, tc, td, maxPwm, temperatureLimit, voltage, usePid, inverted); @@ -57,14 +57,14 @@ GCodeResult Heater::SetModel(float gain, float tc, float td, float maxPwm, float return GCodeResult::error; } -GCodeResult Heater::SetFaultDetectionParameters(float pMaxTempExcursion, float pMaxFaultTime, const StringRef& reply) +GCodeResult Heater::SetFaultDetectionParameters(float pMaxTempExcursion, float pMaxFaultTime, const StringRef& reply) noexcept { maxTempExcursion = pMaxTempExcursion; maxHeatingFaultTime = pMaxFaultTime; return UpdateFaultDetectionParameters(reply); } -HeaterStatus Heater::GetStatus() const +HeaterStatus Heater::GetStatus() const noexcept { const HeaterMode mode = GetMode(); return (mode == HeaterMode::fault) ? HeaterStatus::fault @@ -75,13 +75,13 @@ HeaterStatus Heater::GetStatus() const : HeaterStatus::standby; } -const char* Heater::GetSensorName() const +const char* Heater::GetSensorName() const noexcept { const auto sensor = reprap.GetHeat().FindSensor(sensorNumber); return (sensor.IsNotNull()) ? sensor->GetSensorName() : nullptr; } -GCodeResult Heater::Activate(const StringRef& reply) +GCodeResult Heater::Activate(const StringRef& reply) noexcept { if (GetMode() != HeaterMode::fault) { @@ -92,7 +92,7 @@ GCodeResult Heater::Activate(const StringRef& reply) return GCodeResult::error; } -void Heater::Standby() +void Heater::Standby() noexcept { if (GetMode() != HeaterMode::fault) { @@ -102,7 +102,7 @@ void Heater::Standby() } } -void Heater::SetActiveTemperature(float t) +void Heater::SetActiveTemperature(float t) noexcept { if (t > GetHighestTemperatureLimit()) { @@ -123,7 +123,7 @@ void Heater::SetActiveTemperature(float t) } } -void Heater::SetStandbyTemperature(float t) +void Heater::SetStandbyTemperature(float t) noexcept { if (t > GetHighestTemperatureLimit()) { @@ -145,24 +145,24 @@ void Heater::SetStandbyTemperature(float t) } // Get the highest temperature limit -float Heater::GetHighestTemperatureLimit() const +float Heater::GetHighestTemperatureLimit() const noexcept { return reprap.GetHeat().GetHighestTemperatureLimit(GetHeaterNumber()); } // Get the lowest temperature limit -float Heater::GetLowestTemperatureLimit() const +float Heater::GetLowestTemperatureLimit() const noexcept { return reprap.GetHeat().GetLowestTemperatureLimit(GetHeaterNumber()); } -void Heater::SetHeaterProtection(HeaterProtection *h) +void Heater::SetHeaterProtection(HeaterProtection *h) noexcept { heaterProtection = h; } // Check heater protection elements and return true if everything is good -bool Heater::CheckProtection() const +bool Heater::CheckProtection() const noexcept { for (HeaterProtection *prot = heaterProtection; prot != nullptr; prot = prot->Next()) { @@ -175,12 +175,12 @@ bool Heater::CheckProtection() const return true; } -bool Heater::CheckGood() const +bool Heater::CheckGood() const noexcept { return GetMode() != HeaterMode::fault && CheckProtection(); } -void Heater::SetModelDefaults() +void Heater::SetModelDefaults() noexcept { if (reprap.GetHeat().IsBedOrChamberHeater(GetHeaterNumber())) { diff --git a/src/Heating/Heater.h b/src/Heating/Heater.h index 1d358bbe..f8bbb33d 100644 --- a/src/Heating/Heater.h +++ b/src/Heating/Heater.h @@ -25,58 +25,58 @@ enum class HeaterStatus { off = 0, standby = 1, active = 2, fault = 3, tuning = class Heater { public: - Heater(unsigned int num); - virtual ~Heater(); + Heater(unsigned int num) noexcept; + virtual ~Heater() noexcept; // Configuration methods virtual GCodeResult ConfigurePortAndSensor(const char *portName, PwmFrequency freq, unsigned int sensorNumber, const StringRef& reply) = 0; virtual GCodeResult SetPwmFrequency(PwmFrequency freq, const StringRef& reply) = 0; - virtual GCodeResult ReportDetails(const StringRef& reply) const = 0; - - virtual float GetTemperature() const = 0; // Get the current temperature - virtual float GetAveragePWM() const = 0; // Return the running average PWM to the heater. Answer is a fraction in [0, 1]. - virtual GCodeResult ResetFault(const StringRef& reply) = 0; // Reset a fault condition - only call this if you know what you are doing - virtual void SwitchOff() = 0; - virtual void Spin() = 0; - virtual void StartAutoTune(float targetTemp, float maxPwm, const StringRef& reply) = 0; // Start an auto tune cycle for this PID + virtual GCodeResult ReportDetails(const StringRef& reply) const noexcept = 0; + + virtual float GetTemperature() const noexcept = 0; // Get the current temperature + virtual float GetAveragePWM() const noexcept = 0; // Return the running average PWM to the heater. Answer is a fraction in [0, 1]. + virtual GCodeResult ResetFault(const StringRef& reply) noexcept = 0; // Reset a fault condition - only call this if you know what you are doing + virtual void SwitchOff() noexcept = 0; + virtual void Spin() noexcept = 0; + virtual void StartAutoTune(float targetTemp, float maxPwm, const StringRef& reply) noexcept = 0; // Start an auto tune cycle for this PID virtual void GetAutoTuneStatus(const StringRef& reply) const = 0; // Get the auto tune status or last result - virtual void Suspend(bool sus) = 0; // Suspend the heater to conserve power or while doing Z probing - virtual float GetAccumulator() const = 0; // Get the inertial term accumulator + virtual void Suspend(bool sus) noexcept = 0; // Suspend the heater to conserve power or while doing Z probing + virtual float GetAccumulator() const noexcept = 0; // Get the inertial term accumulator #if SUPPORT_CAN_EXPANSION - virtual void UpdateRemoteStatus(CanAddress src, const CanHeaterReport& report) = 0; + virtual void UpdateRemoteStatus(CanAddress src, const CanHeaterReport& report) noexcept = 0; #endif - HeaterStatus GetStatus() const; // Get the status of the heater - unsigned int GetHeaterNumber() const { return heaterNumber; } - const char *GetSensorName() const; // Get the name of the sensor for this heater, or nullptr if it hasn't been named - void SetActiveTemperature(float t); - float GetActiveTemperature() const { return activeTemperature; } - void SetStandbyTemperature(float t); - float GetStandbyTemperature() const { return standbyTemperature; } - GCodeResult Activate(const StringRef& reply); // Switch from idle to active - void Standby(); // Switch from active to idle - - void GetFaultDetectionParameters(float& pMaxTempExcursion, float& pMaxFaultTime) const + HeaterStatus GetStatus() const noexcept; // Get the status of the heater + unsigned int GetHeaterNumber() const noexcept { return heaterNumber; } + const char *GetSensorName() const noexcept; // Get the name of the sensor for this heater, or nullptr if it hasn't been named + void SetActiveTemperature(float t) noexcept; + float GetActiveTemperature() const noexcept { return activeTemperature; } + void SetStandbyTemperature(float t) noexcept; + float GetStandbyTemperature() const noexcept { return standbyTemperature; } + GCodeResult Activate(const StringRef& reply) noexcept; // Switch from idle to active + void Standby() noexcept; // Switch from active to idle + + void GetFaultDetectionParameters(float& pMaxTempExcursion, float& pMaxFaultTime) const noexcept { pMaxTempExcursion = maxTempExcursion; pMaxFaultTime = maxHeatingFaultTime; } - GCodeResult SetFaultDetectionParameters(float pMaxTempExcursion, float pMaxFaultTime, const StringRef& reply); + GCodeResult SetFaultDetectionParameters(float pMaxTempExcursion, float pMaxFaultTime, const StringRef& reply) noexcept; - float GetHighestTemperatureLimit() const; // Get the highest temperature limit - float GetLowestTemperatureLimit() const; // Get the lowest temperature limit - void SetHeaterProtection(HeaterProtection *h); + float GetHighestTemperatureLimit() const noexcept; // Get the highest temperature limit + float GetLowestTemperatureLimit() const noexcept; // Get the lowest temperature limit + void SetHeaterProtection(HeaterProtection *h) noexcept; - const FopDt& GetModel() const { return model; } // Get the process model - GCodeResult SetModel(float gain, float tc, float td, float maxPwm, float voltage, bool usePid, bool inverted, const StringRef& reply); // Set the process model - void SetModelDefaults(); + const FopDt& GetModel() const noexcept { return model; } // Get the process model + GCodeResult SetModel(float gain, float tc, float td, float maxPwm, float voltage, bool usePid, bool inverted, const StringRef& reply) noexcept; // Set the process model + void SetModelDefaults() noexcept; - bool IsHeaterEnabled() const // Is this heater enabled? + bool IsHeaterEnabled() const noexcept // Is this heater enabled? { return model.IsEnabled(); } - void SetM301PidParameters(const M301PidParameters& params) + void SetM301PidParameters(const M301PidParameters& params) noexcept { model.SetM301PidParameters(params); } - bool CheckGood() const; + bool CheckGood() const noexcept; protected: enum class HeaterMode : uint8_t @@ -98,23 +98,23 @@ protected: lastTuningMode = tuning3 }; - virtual void ResetHeater() = 0; - virtual HeaterMode GetMode() const = 0; - virtual GCodeResult SwitchOn(const StringRef& reply) = 0; - virtual GCodeResult UpdateModel(const StringRef& reply) = 0; - virtual GCodeResult UpdateFaultDetectionParameters(const StringRef& reply) = 0; + virtual void ResetHeater() noexcept = 0; + virtual HeaterMode GetMode() const noexcept = 0; + virtual GCodeResult SwitchOn(const StringRef& reply) noexcept = 0; + virtual GCodeResult UpdateModel(const StringRef& reply) noexcept = 0; + virtual GCodeResult UpdateFaultDetectionParameters(const StringRef& reply) noexcept = 0; - int GetSensorNumber() const { return sensorNumber; } - void SetSensorNumber(int sn) { sensorNumber = sn; } - float GetMaxTemperatureExcursion() const { return maxTempExcursion; } - float GetMaxHeatingFaultTime() const { return maxHeatingFaultTime; } - float GetTargetTemperature() const { return (active) ? activeTemperature : standbyTemperature; } - HeaterProtection *GetHeaterProtections() const { return heaterProtection; } + int GetSensorNumber() const noexcept { return sensorNumber; } + void SetSensorNumber(int sn) noexcept { sensorNumber = sn; } + float GetMaxTemperatureExcursion() const noexcept { return maxTempExcursion; } + float GetMaxHeatingFaultTime() const noexcept { return maxHeatingFaultTime; } + float GetTargetTemperature() const noexcept { return (active) ? activeTemperature : standbyTemperature; } + HeaterProtection *GetHeaterProtections() const noexcept { return heaterProtection; } FopDt model; private: - bool CheckProtection() const; // Check heater protection elements and return true if everything is good + bool CheckProtection() const noexcept; // Check heater protection elements and return true if everything is good unsigned int heaterNumber; int sensorNumber; // the sensor number used by this heater diff --git a/src/Heating/HeaterProtection.cpp b/src/Heating/HeaterProtection.cpp index 8f78cbe1..f13911d0 100644 --- a/src/Heating/HeaterProtection.cpp +++ b/src/Heating/HeaterProtection.cpp @@ -12,7 +12,7 @@ #include "Heat.h" -HeaterProtection::HeaterProtection(size_t index) : next(nullptr) +HeaterProtection::HeaterProtection(size_t index) noexcept : next(nullptr) { // By default each heater protection element is mapped to its corresponding heater. // All other heater protection elements are unused and can be optionally assigned. @@ -20,7 +20,7 @@ HeaterProtection::HeaterProtection(size_t index) : next(nullptr) sensorNumber = -1; } -void HeaterProtection::Init(float tempLimit) +void HeaterProtection::Init(float tempLimit) noexcept { next = nullptr; limit = tempLimit; @@ -31,7 +31,7 @@ void HeaterProtection::Init(float tempLimit) } // Check if any action needs to be taken. Returns true if everything is OK -bool HeaterProtection::Check() +bool HeaterProtection::Check() noexcept { if (sensorNumber >= 0) { @@ -63,7 +63,7 @@ bool HeaterProtection::Check() return true; } -void HeaterProtection::SetHeater(int newHeater) +void HeaterProtection::SetHeater(int newHeater) noexcept { heater = newHeater; } diff --git a/src/Heating/HeaterProtection.h b/src/Heating/HeaterProtection.h index 7db1f383..19f5df36 100644 --- a/src/Heating/HeaterProtection.h +++ b/src/Heating/HeaterProtection.h @@ -38,28 +38,28 @@ class HeaterProtection public: friend class Heat; - HeaterProtection(size_t index); - void Init(float tempLimit); + HeaterProtection(size_t index) noexcept; + void Init(float tempLimit) noexcept; - HeaterProtection *Next() const { return next; } - void SetNext(HeaterProtection *n) { next = n; } + HeaterProtection *Next() const noexcept { return next; } + void SetNext(HeaterProtection *n) noexcept { next = n; } - bool Check(); // Check if any action needs to be taken + bool Check() noexcept; // Check if any action needs to be taken - int GetHeater() const { return heater; } - void SetHeater(int newHeater); // Set the heater to control + int GetHeater() const noexcept { return heater; } + void SetHeater(int newHeater) noexcept; // Set the heater to control - int GetSensorNumber() const { return sensorNumber; } // Get the supervisory sensor number - void SetSensorNumber(int sn); // Set the supervisory sensor number + int GetSensorNumber() const noexcept { return sensorNumber; } // Get the supervisory sensor number + void SetSensorNumber(int sn) noexcept; // Set the supervisory sensor number - float GetTemperatureLimit() const { return limit; } // Get the temperature limit - void SetTemperatureLimit(float newLimit); // Set the temperature limit + float GetTemperatureLimit() const noexcept { return limit; } // Get the temperature limit + void SetTemperatureLimit(float newLimit) noexcept; // Set the temperature limit - HeaterProtectionAction GetAction() const { return action; } // Get the action to trigger when a temperature event occurs - void SetAction(HeaterProtectionAction newAction); // Set the action to trigger when a temperature event occurs + HeaterProtectionAction GetAction() const noexcept { return action; } // Get the action to trigger when a temperature event occurs + void SetAction(HeaterProtectionAction newAction) noexcept; // Set the action to trigger when a temperature event occurs - HeaterProtectionTrigger GetTrigger() const { return trigger; } // Get the condition for a temperature event - void SetTrigger(HeaterProtectionTrigger newTrigger); // Set the condition for a temperature event + HeaterProtectionTrigger GetTrigger() const noexcept { return trigger; } // Get the condition for a temperature event + void SetTrigger(HeaterProtectionTrigger newTrigger) noexcept; // Set the condition for a temperature event private: HeaterProtection *next; // link to next HeaterProtection item for the same heater @@ -73,22 +73,22 @@ private: size_t badTemperatureCount; // how many consecutive sensor reading faults we have had }; -inline void HeaterProtection::SetSensorNumber(int sn) +inline void HeaterProtection::SetSensorNumber(int sn) noexcept { sensorNumber = sn; } -inline void HeaterProtection::SetTemperatureLimit(float newLimit) +inline void HeaterProtection::SetTemperatureLimit(float newLimit) noexcept { limit = newLimit; } -inline void HeaterProtection::SetAction(HeaterProtectionAction newAction) +inline void HeaterProtection::SetAction(HeaterProtectionAction newAction) noexcept { action = newAction; } -inline void HeaterProtection::SetTrigger(HeaterProtectionTrigger newTrigger) +inline void HeaterProtection::SetTrigger(HeaterProtectionTrigger newTrigger) noexcept { trigger = newTrigger; } diff --git a/src/Heating/LocalHeater.cpp b/src/Heating/LocalHeater.cpp index 797e5735..b67c4e69 100644 --- a/src/Heating/LocalHeater.cpp +++ b/src/Heating/LocalHeater.cpp @@ -40,7 +40,7 @@ float tuningVoltageAccumulator; // sum of the voltage readings we take during // Member functions and constructors -LocalHeater::LocalHeater(unsigned int heaterNum) : Heater(heaterNum), mode(HeaterMode::off) +LocalHeater::LocalHeater(unsigned int heaterNum) noexcept : Heater(heaterNum), mode(HeaterMode::off) { ResetHeater(); SetHeater(0.0); // set up the pin even if the heater is not enabled (for PCCB) @@ -50,28 +50,28 @@ LocalHeater::LocalHeater(unsigned int heaterNum) : Heater(heaterNum), mode(Heate lastSampleTime = millis(); } -LocalHeater::~LocalHeater() +LocalHeater::~LocalHeater() noexcept { SwitchOff(); port.Release(); } -float LocalHeater::GetTemperature() const +float LocalHeater::GetTemperature() const noexcept { return temperature; } -float LocalHeater::GetAccumulator() const +float LocalHeater::GetAccumulator() const noexcept { return iAccumulator; } -inline void LocalHeater::SetHeater(float power) const +inline void LocalHeater::SetHeater(float power) const noexcept { port.WriteAnalog(power); } -void LocalHeater::ResetHeater() +void LocalHeater::ResetHeater() noexcept { mode = HeaterMode::off; previousTemperaturesGood = 0; @@ -102,13 +102,13 @@ GCodeResult LocalHeater::ConfigurePortAndSensor(const char *portName, PwmFrequen return GCodeResult::ok; } -GCodeResult LocalHeater::SetPwmFrequency(PwmFrequency freq, const StringRef& reply) +GCodeResult LocalHeater::SetPwmFrequency(PwmFrequency freq, const StringRef& reply) noexcept { port.SetFrequency(freq); return GCodeResult::ok; } -GCodeResult LocalHeater::ReportDetails(const StringRef& reply) const +GCodeResult LocalHeater::ReportDetails(const StringRef& reply) const noexcept { reply.printf("Heater %u", GetHeaterNumber()); port.AppendDetails(reply); @@ -124,7 +124,7 @@ GCodeResult LocalHeater::ReportDetails(const StringRef& reply) const } // Read and store the temperature of this heater and returns the error code. -TemperatureError LocalHeater::ReadTemperature() +TemperatureError LocalHeater::ReadTemperature() noexcept { TemperatureError err; temperature = reprap.GetHeat().GetSensorTemperature(GetSensorNumber(), err); // in the event of an error, err is set and BAD_ERROR_TEMPERATURE is returned @@ -132,7 +132,7 @@ TemperatureError LocalHeater::ReadTemperature() } // This must be called whenever the heater is turned on, and any time the heater is active and the target temperature is changed -GCodeResult LocalHeater::SwitchOn(const StringRef& reply) +GCodeResult LocalHeater::SwitchOn(const StringRef& reply) noexcept { if (!GetModel().IsEnabled()) { @@ -167,7 +167,7 @@ GCodeResult LocalHeater::SwitchOn(const StringRef& reply) } // Switch off the specified heater. If in tuning mode, delete the array used to store tuning temperature readings. -void LocalHeater::SwitchOff() +void LocalHeater::SwitchOff() noexcept { lastPwm = 0.0; if (GetModel().IsEnabled()) @@ -190,13 +190,13 @@ void LocalHeater::SwitchOff() } // This is called when the heater model has been updated. Returns true if successful. -GCodeResult LocalHeater::UpdateModel(const StringRef& reply) +GCodeResult LocalHeater::UpdateModel(const StringRef& reply) noexcept { return GCodeResult::ok; } // This is the main heater control loop function -void LocalHeater::Spin() +void LocalHeater::Spin() noexcept { // Read the temperature even if the heater is suspended or the model is not enabled const TemperatureError err = ReadTemperature(); @@ -446,7 +446,7 @@ void LocalHeater::Spin() } } -GCodeResult LocalHeater::ResetFault(const StringRef& reply) +GCodeResult LocalHeater::ResetFault(const StringRef& reply) noexcept { badTemperatureCount = 0; if (mode == HeaterMode::fault) @@ -457,13 +457,13 @@ GCodeResult LocalHeater::ResetFault(const StringRef& reply) return GCodeResult::ok; } -float LocalHeater::GetAveragePWM() const +float LocalHeater::GetAveragePWM() const noexcept { return averagePWM * HeatSampleIntervalMillis/(HeatPwmAverageTime * SecondsToMillis); } // Get a conservative estimate of the expected heating rate at the current temperature and average PWM. The result may be negative. -float LocalHeater::GetExpectedHeatingRate() const +float LocalHeater::GetExpectedHeatingRate() const noexcept { // In the following we allow for the gain being only 75% of what we think it should be, to avoid false alarms const float maxTemperatureRise = 0.75 * GetModel().GetGain() * GetAveragePWM(); // this is the highest temperature above ambient we expect the heater can reach at this PWM @@ -474,7 +474,7 @@ float LocalHeater::GetExpectedHeatingRate() const } // Auto tune this PID -void LocalHeater::StartAutoTune(float targetTemp, float maxPwm, const StringRef& reply) +void LocalHeater::StartAutoTune(float targetTemp, float maxPwm, const StringRef& reply) noexcept { // Starting an auto tune if (!GetModel().IsEnabled()) @@ -512,7 +512,7 @@ void LocalHeater::StartAutoTune(float targetTemp, float maxPwm, const StringRef& } // Get the auto tune status or last result -void LocalHeater::GetAutoTuneStatus(const StringRef& reply) const +void LocalHeater::GetAutoTuneStatus(const StringRef& reply) const noexcept { if (mode >= HeaterMode::tuning0) { @@ -578,7 +578,7 @@ void LocalHeater::GetAutoTuneStatus(const StringRef& reply) const // This is called on each temperature sample when auto tuning // It must set lastPWM to the required PWM, unless it is the same as last time. -void LocalHeater::DoTuningStep() +void LocalHeater::DoTuningStep() noexcept { // See if another sample is due if (tuningReadingsTaken == 0) @@ -738,7 +738,7 @@ void LocalHeater::DoTuningStep() } // Return true if the last 'numReadings' readings are stable -/*static*/ bool LocalHeater::ReadingsStable(size_t numReadings, float maxDiff) +/*static*/ bool LocalHeater::ReadingsStable(size_t numReadings, float maxDiff) noexcept { if (tuningTempReadings == nullptr || tuningReadingsTaken < numReadings) { @@ -760,7 +760,7 @@ void LocalHeater::DoTuningStep() // Calculate which reading gave us the peak temperature. // Return -1 if peak not identified yet, 0 if we are never going to find a peak, else the index of the peak // If the readings show a continuous decrease then we return 1, because zero dead time would lead to infinities -/*static*/ int LocalHeater::GetPeakTempIndex() +/*static*/ int LocalHeater::GetPeakTempIndex() noexcept { // Check we have enough readings to look for the peak if (tuningReadingsTaken < 15) @@ -794,7 +794,7 @@ void LocalHeater::DoTuningStep() // See if there is exactly one peak in the readings. // Return -1 if more than one peak, else the index of the peak. The so-called peak may be right at the end, in which case it isn't really a peak. // With a well-insulated bed heater the temperature may not start dropping appreciably within the 120 second time limit allowed. -/*static*/ int LocalHeater::IdentifyPeak(size_t numToAverage) +/*static*/ int LocalHeater::IdentifyPeak(size_t numToAverage) noexcept { int firstPeakIndex = -1, lastSameIndex = -1; float peakTempTimesN = -999.0; @@ -826,7 +826,7 @@ void LocalHeater::DoTuningStep() } // Calculate the heater model from the accumulated heater parameters -void LocalHeater::CalculateModel() +void LocalHeater::CalculateModel() noexcept { if (reprap.Debug(moduleHeat)) { @@ -866,7 +866,7 @@ void LocalHeater::CalculateModel() } } -void LocalHeater::DisplayBuffer(const char *intro) +void LocalHeater::DisplayBuffer(const char *intro) noexcept { OutputBuffer *buf; if (OutputBuffer::Allocate(buf)) @@ -882,7 +882,7 @@ void LocalHeater::DisplayBuffer(const char *intro) } // Suspend the heater, or resume it -void LocalHeater::Suspend(bool sus) +void LocalHeater::Suspend(bool sus) noexcept { if (sus) { diff --git a/src/Heating/LocalHeater.h b/src/Heating/LocalHeater.h index 5c207714..3ad48f5a 100644 --- a/src/Heating/LocalHeater.h +++ b/src/Heating/LocalHeater.h @@ -25,45 +25,45 @@ class LocalHeater : public Heater static const size_t NumPreviousTemperatures = 4; // How many samples we average the temperature derivative over public: - LocalHeater(unsigned int heaterNum); - ~LocalHeater(); + LocalHeater(unsigned int heaterNum) noexcept; + ~LocalHeater() noexcept; GCodeResult ConfigurePortAndSensor(const char *portName, PwmFrequency freq, unsigned int sensorNumber, const StringRef& reply) override; - GCodeResult SetPwmFrequency(PwmFrequency freq, const StringRef& reply) override; - GCodeResult ReportDetails(const StringRef& reply) const override; - - void Spin() override; // Called in a tight loop to keep things running - void SwitchOff() override; // Not even standby - all heater power off - GCodeResult ResetFault(const StringRef& reply) override; // Reset a fault condition - only call this if you know what you are doing - float GetTemperature() const override; // Get the current temperature - float GetAveragePWM() const override; // Return the running average PWM to the heater. Answer is a fraction in [0, 1]. - float GetAccumulator() const override; // Return the integral accumulator - void StartAutoTune(float targetTemp, float maxPwm, const StringRef& reply) override; // Start an auto tune cycle for this PID - void GetAutoTuneStatus(const StringRef& reply) const override; // Get the auto tune status or last result - void Suspend(bool sus) override; // Suspend the heater to conserve power or while doing Z probing + GCodeResult SetPwmFrequency(PwmFrequency freq, const StringRef& reply) noexcept override; + GCodeResult ReportDetails(const StringRef& reply) const noexcept override; + + void Spin() noexcept override; // Called in a tight loop to keep things running + void SwitchOff() noexcept override; // Not even standby - all heater power off + GCodeResult ResetFault(const StringRef& reply) noexcept override; // Reset a fault condition - only call this if you know what you are doing + float GetTemperature() const noexcept override; // Get the current temperature + float GetAveragePWM() const noexcept override; // Return the running average PWM to the heater. Answer is a fraction in [0, 1]. + float GetAccumulator() const noexcept override; // Return the integral accumulator + void StartAutoTune(float targetTemp, float maxPwm, const StringRef& reply) noexcept override; // Start an auto tune cycle for this PID + void GetAutoTuneStatus(const StringRef& reply) const noexcept override; // Get the auto tune status or last result + void Suspend(bool sus) noexcept override; // Suspend the heater to conserve power or while doing Z probing #if SUPPORT_CAN_EXPANSION - void UpdateRemoteStatus(CanAddress src, const CanHeaterReport& report) override { } + void UpdateRemoteStatus(CanAddress src, const CanHeaterReport& report) noexcept override { } #endif protected: - void ResetHeater() override; - HeaterMode GetMode() const override { return mode; } - GCodeResult SwitchOn(const StringRef& reply) override; // Turn the heater on and set the mode - GCodeResult UpdateModel(const StringRef& reply) override; // Called when the heater model has been changed - GCodeResult UpdateFaultDetectionParameters(const StringRef& reply) override { return GCodeResult::ok; } + void ResetHeater() noexcept override; + HeaterMode GetMode() const noexcept override { return mode; } + GCodeResult SwitchOn(const StringRef& reply) noexcept override; // Turn the heater on and set the mode + GCodeResult UpdateModel(const StringRef& reply) noexcept override; // Called when the heater model has been changed + GCodeResult UpdateFaultDetectionParameters(const StringRef& reply) noexcept override { return GCodeResult::ok; } private: - void SetHeater(float power) const; // Power is a fraction in [0,1] - TemperatureError ReadTemperature(); // Read and store the temperature of this heater - void DoTuningStep(); // Called on each temperature sample when auto tuning - static bool ReadingsStable(size_t numReadings, float maxDiff) + void SetHeater(float power) const noexcept; // Power is a fraction in [0,1] + TemperatureError ReadTemperature() noexcept; // Read and store the temperature of this heater + void DoTuningStep() noexcept; // Called on each temperature sample when auto tuning + static bool ReadingsStable(size_t numReadings, float maxDiff) noexcept pre(numReadings >= 2; numReadings <= MaxTuningTempReadings); - static int GetPeakTempIndex(); // Auto tune helper function - static int IdentifyPeak(size_t numToAverage); // Auto tune helper function - void CalculateModel(); // Calculate G, td and tc from the accumulated readings - void DisplayBuffer(const char *intro); // Debug helper - float GetExpectedHeatingRate() const; // Get the minimum heating rate we expect + static int GetPeakTempIndex() noexcept; // Auto tune helper function + static int IdentifyPeak(size_t numToAverage) noexcept; // Auto tune helper function + void CalculateModel() noexcept; // Calculate G, td and tc from the accumulated readings + void DisplayBuffer(const char *intro) noexcept; // Debug helper + float GetExpectedHeatingRate() const noexcept; // Get the minimum heating rate we expect PwmPort port; // The port that drives the heater float temperature; // The current temperature diff --git a/src/Heating/RemoteHeater.cpp b/src/Heating/RemoteHeater.cpp index 8ef8558e..ace55336 100644 --- a/src/Heating/RemoteHeater.cpp +++ b/src/Heating/RemoteHeater.cpp @@ -17,12 +17,12 @@ #include #include -RemoteHeater::RemoteHeater(unsigned int num, CanAddress board) +RemoteHeater::RemoteHeater(unsigned int num, CanAddress board) noexcept : Heater(num), boardAddress(board), lastMode(HeaterMode::offline), averagePwm(0), lastTemperature(0.0), whenLastStatusReceived(0) { } -RemoteHeater::~RemoteHeater() +RemoteHeater::~RemoteHeater() noexcept { CanMessageGenericConstructor cons(M950HeaterParams); cons.AddUParam('H', GetHeaterNumber()); @@ -31,12 +31,12 @@ RemoteHeater::~RemoteHeater() (void)cons.SendAndGetResponse(CanMessageType::m950Heater, boardAddress, dummy.GetRef()); } -void RemoteHeater::Spin() +void RemoteHeater::Spin() noexcept { // Nothing needed here unless we want to copy the sensor temperature across. For now we don't store the temperature locally. } -void RemoteHeater::ResetHeater() +void RemoteHeater::ResetHeater() noexcept { //TODO } @@ -60,14 +60,14 @@ GCodeResult RemoteHeater::SetPwmFrequency(PwmFrequency freq, const StringRef& re return cons.SendAndGetResponse(CanMessageType::m950Heater, boardAddress, reply); } -GCodeResult RemoteHeater::ReportDetails(const StringRef& reply) const +GCodeResult RemoteHeater::ReportDetails(const StringRef& reply) const noexcept { CanMessageGenericConstructor cons(M950HeaterParams); cons.AddUParam('H', GetHeaterNumber()); return cons.SendAndGetResponse(CanMessageType::m950Heater, boardAddress, reply); } -void RemoteHeater::SwitchOff() +void RemoteHeater::SwitchOff() noexcept { CanMessageBuffer * const buf = CanMessageBuffer::Allocate(); if (buf == nullptr) @@ -89,7 +89,7 @@ void RemoteHeater::SwitchOff() } } -GCodeResult RemoteHeater::ResetFault(const StringRef& reply) +GCodeResult RemoteHeater::ResetFault(const StringRef& reply) noexcept { CanMessageBuffer * const buf = CanMessageBuffer::Allocate(); if (buf == nullptr) @@ -106,7 +106,7 @@ GCodeResult RemoteHeater::ResetFault(const StringRef& reply) return CanInterface::SendRequestAndGetStandardReply(buf, rid, reply); } -float RemoteHeater::GetTemperature() const +float RemoteHeater::GetTemperature() const noexcept { if (millis() - whenLastStatusReceived < RemoteStatusTimeout) { @@ -117,28 +117,28 @@ float RemoteHeater::GetTemperature() const return reprap.GetHeat().GetSensorTemperature(GetSensorNumber(), err); } -float RemoteHeater::GetAveragePWM() const +float RemoteHeater::GetAveragePWM() const noexcept { return (millis() - whenLastStatusReceived < RemoteStatusTimeout) ? (float)averagePwm / 255.0 : 0; } // Return the integral accumulator -float RemoteHeater::GetAccumulator() const +float RemoteHeater::GetAccumulator() const noexcept { return 0.0; // not supported } -void RemoteHeater::StartAutoTune(float targetTemp, float maxPwm, const StringRef& reply) +void RemoteHeater::StartAutoTune(float targetTemp, float maxPwm, const StringRef& reply) noexcept { //TODO } -void RemoteHeater::GetAutoTuneStatus(const StringRef& reply) const +void RemoteHeater::GetAutoTuneStatus(const StringRef& reply) const noexcept { //TODO } -void RemoteHeater::Suspend(bool sus) +void RemoteHeater::Suspend(bool sus) noexcept { CanMessageBuffer * const buf = CanMessageBuffer::Allocate(); if (buf != nullptr) @@ -153,13 +153,13 @@ void RemoteHeater::Suspend(bool sus) } } -Heater::HeaterMode RemoteHeater::GetMode() const +Heater::HeaterMode RemoteHeater::GetMode() const noexcept { return (millis() - whenLastStatusReceived < RemoteStatusTimeout) ? lastMode : HeaterMode::offline; } // This isn't just called to turn the heater on, it is called when the temperature needs to be updated -GCodeResult RemoteHeater::SwitchOn(const StringRef& reply) +GCodeResult RemoteHeater::SwitchOn(const StringRef& reply) noexcept { if (!GetModel().IsEnabled()) { @@ -182,7 +182,7 @@ GCodeResult RemoteHeater::SwitchOn(const StringRef& reply) } // This is called when the heater model has been updated -GCodeResult RemoteHeater::UpdateModel(const StringRef& reply) +GCodeResult RemoteHeater::UpdateModel(const StringRef& reply) noexcept { CanMessageBuffer *buf = CanMessageBuffer::Allocate(); if (buf != nullptr) @@ -197,7 +197,7 @@ GCodeResult RemoteHeater::UpdateModel(const StringRef& reply) return GCodeResult::error; } -GCodeResult RemoteHeater::UpdateFaultDetectionParameters(const StringRef& reply) +GCodeResult RemoteHeater::UpdateFaultDetectionParameters(const StringRef& reply) noexcept { CanMessageBuffer *buf = CanMessageBuffer::Allocate(); if (buf != nullptr) @@ -214,7 +214,7 @@ GCodeResult RemoteHeater::UpdateFaultDetectionParameters(const StringRef& reply) return GCodeResult::error; } -void RemoteHeater::UpdateRemoteStatus(CanAddress src, const CanHeaterReport& report) +void RemoteHeater::UpdateRemoteStatus(CanAddress src, const CanHeaterReport& report) noexcept { if (src == boardAddress) { diff --git a/src/Heating/RemoteHeater.h b/src/Heating/RemoteHeater.h index f373f84a..ebaa99cc 100644 --- a/src/Heating/RemoteHeater.h +++ b/src/Heating/RemoteHeater.h @@ -15,30 +15,30 @@ class RemoteHeater : public Heater { public: - RemoteHeater(unsigned int num, CanAddress board); - ~RemoteHeater(); + RemoteHeater(unsigned int num, CanAddress board) noexcept; + ~RemoteHeater() noexcept; GCodeResult ConfigurePortAndSensor(const char *portName, PwmFrequency freq, unsigned int sensorNumber, const StringRef& reply) override; GCodeResult SetPwmFrequency(PwmFrequency freq, const StringRef& reply) override; - GCodeResult ReportDetails(const StringRef& reply) const override; - - void Spin() override; // Called in a tight loop to keep things running - void SwitchOff() override; // Not even standby - all heater power off - GCodeResult ResetFault(const StringRef& reply) override; // Reset a fault condition - only call this if you know what you are doing - float GetTemperature() const override; // Get the current temperature - float GetAveragePWM() const override; // Return the running average PWM to the heater. Answer is a fraction in [0, 1]. - float GetAccumulator() const override; // Return the integral accumulator - void StartAutoTune(float targetTemp, float maxPwm, const StringRef& reply) override; // Start an auto tune cycle for this PID - void GetAutoTuneStatus(const StringRef& reply) const override; // Get the auto tune status or last result - void Suspend(bool sus) override; // Suspend the heater to conserve power or while doing Z probing - void UpdateRemoteStatus(CanAddress src, const CanHeaterReport& report) override; + GCodeResult ReportDetails(const StringRef& reply) const noexcept override; + + void Spin() noexcept override; // Called in a tight loop to keep things running + void SwitchOff() noexcept override; // Not even standby - all heater power off + GCodeResult ResetFault(const StringRef& reply) noexcept override; // Reset a fault condition - only call this if you know what you are doing + float GetTemperature() const noexcept override; // Get the current temperature + float GetAveragePWM() const noexcept override; // Return the running average PWM to the heater. Answer is a fraction in [0, 1]. + float GetAccumulator() const noexcept override; // Return the integral accumulator + void StartAutoTune(float targetTemp, float maxPwm, const StringRef& reply) noexcept override; // Start an auto tune cycle for this PID + void GetAutoTuneStatus(const StringRef& reply) const noexcept override; // Get the auto tune status or last result + void Suspend(bool sus) noexcept override; // Suspend the heater to conserve power or while doing Z probing + void UpdateRemoteStatus(CanAddress src, const CanHeaterReport& report) noexcept override; protected: - void ResetHeater() override; - HeaterMode GetMode() const override; - GCodeResult SwitchOn(const StringRef& reply) override; // Turn the heater on and set the mode - GCodeResult UpdateModel(const StringRef& reply) override; // Called when the heater model has been changed - GCodeResult UpdateFaultDetectionParameters(const StringRef& reply) override; + void ResetHeater() noexcept override; + HeaterMode GetMode() const noexcept override; + GCodeResult SwitchOn(const StringRef& reply) noexcept override; // Turn the heater on and set the mode + GCodeResult UpdateModel(const StringRef& reply) noexcept override; // Called when the heater model has been changed + GCodeResult UpdateFaultDetectionParameters(const StringRef& reply) noexcept override; private: static constexpr uint32_t RemoteStatusTimeout = 2000; diff --git a/src/Heating/Sensors/AdditionalOutputSensor.cpp b/src/Heating/Sensors/AdditionalOutputSensor.cpp index 904d1bb8..496386bf 100644 --- a/src/Heating/Sensors/AdditionalOutputSensor.cpp +++ b/src/Heating/Sensors/AdditionalOutputSensor.cpp @@ -11,12 +11,13 @@ #include "Heating/Heat.h" #include "GCodes/GCodeBuffer/GCodeBuffer.h" -AdditionalOutputSensor::AdditionalOutputSensor(unsigned int sensorNum, const char *type, bool enforcePollOrder) +AdditionalOutputSensor::AdditionalOutputSensor(unsigned int sensorNum, const char *type, bool enforcePollOrder) noexcept : TemperatureSensor(sensorNum, type), parentSensor(0), outputNumber(0), enforcePollOrder(enforcePollOrder) { } -AdditionalOutputSensor::~AdditionalOutputSensor() { +AdditionalOutputSensor::~AdditionalOutputSensor() noexcept +{ } GCodeResult AdditionalOutputSensor::Configure(GCodeBuffer& gb, const StringRef& reply) @@ -97,7 +98,7 @@ GCodeResult AdditionalOutputSensor::Configure(GCodeBuffer& gb, const StringRef& return GCodeResult::ok; } -void AdditionalOutputSensor::Poll() +void AdditionalOutputSensor::Poll() noexcept { float t; const auto parent = reprap.GetHeat().FindSensor(parentSensor); diff --git a/src/Heating/Sensors/AdditionalOutputSensor.h b/src/Heating/Sensors/AdditionalOutputSensor.h index 7ea36931..61654479 100644 --- a/src/Heating/Sensors/AdditionalOutputSensor.h +++ b/src/Heating/Sensors/AdditionalOutputSensor.h @@ -13,10 +13,10 @@ class AdditionalOutputSensor : public TemperatureSensor { public: - AdditionalOutputSensor(unsigned int sensorNum, const char *type, bool enforcePollOrder); - virtual ~AdditionalOutputSensor(); + AdditionalOutputSensor(unsigned int sensorNum, const char *type, bool enforcePollOrder) noexcept; + virtual ~AdditionalOutputSensor() noexcept; GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply) override; - void Poll() override; + void Poll() noexcept override; protected: uint8_t parentSensor; diff --git a/src/Heating/Sensors/CpuTemperatureSensor.cpp b/src/Heating/Sensors/CpuTemperatureSensor.cpp index d9d464c5..abcac784 100644 --- a/src/Heating/Sensors/CpuTemperatureSensor.cpp +++ b/src/Heating/Sensors/CpuTemperatureSensor.cpp @@ -11,11 +11,11 @@ #if HAS_CPU_TEMP_SENSOR -CpuTemperatureSensor::CpuTemperatureSensor(unsigned int sensorNum) : TemperatureSensor(sensorNum, "microcontroller embedded temperature sensor") +CpuTemperatureSensor::CpuTemperatureSensor(unsigned int sensorNum) noexcept : TemperatureSensor(sensorNum, "microcontroller embedded temperature sensor") { } -void CpuTemperatureSensor::Poll() +void CpuTemperatureSensor::Poll() noexcept { float minT, currentT, maxT; reprap.GetPlatform().GetMcuTemperatures(minT, currentT, maxT); diff --git a/src/Heating/Sensors/CpuTemperatureSensor.h b/src/Heating/Sensors/CpuTemperatureSensor.h index 18efe965..c7125e24 100644 --- a/src/Heating/Sensors/CpuTemperatureSensor.h +++ b/src/Heating/Sensors/CpuTemperatureSensor.h @@ -15,11 +15,11 @@ class CpuTemperatureSensor : public TemperatureSensor { public: - CpuTemperatureSensor(unsigned int sensorNum); + CpuTemperatureSensor(unsigned int sensorNum) noexcept; static constexpr const char *TypeName = "mcutemp"; - void Poll() override; + void Poll() noexcept override; }; #endif diff --git a/src/Heating/Sensors/CurrentLoopTemperatureSensor.cpp b/src/Heating/Sensors/CurrentLoopTemperatureSensor.cpp index eaeebbf9..9932cf8d 100644 --- a/src/Heating/Sensors/CurrentLoopTemperatureSensor.cpp +++ b/src/Heating/Sensors/CurrentLoopTemperatureSensor.cpp @@ -18,7 +18,7 @@ const uint8_t MCP3204_SpiMode = SPI_MODE_0; // Define the minimum interval between readings const uint32_t MinimumReadInterval = 100; // minimum interval between reads, in milliseconds -CurrentLoopTemperatureSensor::CurrentLoopTemperatureSensor(unsigned int sensorNum) +CurrentLoopTemperatureSensor::CurrentLoopTemperatureSensor(unsigned int sensorNum) noexcept : SpiTemperatureSensor(sensorNum, "Current Loop", MCP3204_SpiMode, MCP3204_Frequency), tempAt4mA(DefaultTempAt4mA), tempAt20mA(DefaultTempAt20mA), chipChannel(DefaultChipChannel), isDifferential(false) { @@ -74,21 +74,21 @@ GCodeResult CurrentLoopTemperatureSensor::Configure(GCodeBuffer& gb, const Strin return GCodeResult::ok; } -void CurrentLoopTemperatureSensor::Poll() +void CurrentLoopTemperatureSensor::Poll() noexcept { float t; const TemperatureError rslt = TryGetLinearAdcTemperature(t); SetResult(t, rslt); } -void CurrentLoopTemperatureSensor::CalcDerivedParameters() +void CurrentLoopTemperatureSensor::CalcDerivedParameters() noexcept { minLinearAdcTemp = tempAt4mA - 0.25 * (tempAt20mA - tempAt4mA); linearAdcDegCPerCount = (tempAt20mA - minLinearAdcTemp) / 4096.0; } // Try to get a temperature reading from the linear ADC by doing an SPI transaction -TemperatureError CurrentLoopTemperatureSensor::TryGetLinearAdcTemperature(float& t) +TemperatureError CurrentLoopTemperatureSensor::TryGetLinearAdcTemperature(float& t) noexcept { /* * The MCP3204 waits for a high input input bit before it does anything. Call this clock 1. diff --git a/src/Heating/Sensors/CurrentLoopTemperatureSensor.h b/src/Heating/Sensors/CurrentLoopTemperatureSensor.h index 234614c2..c1db9f3c 100644 --- a/src/Heating/Sensors/CurrentLoopTemperatureSensor.h +++ b/src/Heating/Sensors/CurrentLoopTemperatureSensor.h @@ -13,16 +13,16 @@ class CurrentLoopTemperatureSensor : public SpiTemperatureSensor { public: - CurrentLoopTemperatureSensor(unsigned int sensorNum); + CurrentLoopTemperatureSensor(unsigned int sensorNum) noexcept; GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply) override; static constexpr const char *TypeName = "currentloop"; - void Poll() override; + void Poll() noexcept override; private: - TemperatureError TryGetLinearAdcTemperature(float& t); - void CalcDerivedParameters(); + TemperatureError TryGetLinearAdcTemperature(float& t) noexcept; + void CalcDerivedParameters() noexcept; // Configurable parameters float tempAt4mA, tempAt20mA; diff --git a/src/Heating/Sensors/DhtSensor.cpp b/src/Heating/Sensors/DhtSensor.cpp index a0a5cf1a..af295ec2 100644 --- a/src/Heating/Sensors/DhtSensor.cpp +++ b/src/Heating/Sensors/DhtSensor.cpp @@ -20,18 +20,18 @@ constexpr uint8_t MinimumOneBitLength = 50; // microseconds constexpr uint32_t MinimumOneBitStepClocks = (StepTimer::StepClockRate * MinimumOneBitLength)/1000000; // Pulse ISR -extern "C" void DhtDataTransition(CallbackParameter cp) +extern "C" void DhtDataTransition(CallbackParameter cp) noexcept { static_cast(cp.vp)->Interrupt(); } // Class DhtTemperatureSensor members -DhtTemperatureSensor::DhtTemperatureSensor(unsigned int sensorNum, DhtSensorType type) +DhtTemperatureSensor::DhtTemperatureSensor(unsigned int sensorNum, DhtSensorType type) noexcept : SensorWithPort(sensorNum, "DHT-temperature"), type(type), lastReadTime(0) { } -DhtTemperatureSensor::~DhtTemperatureSensor() +DhtTemperatureSensor::~DhtTemperatureSensor() noexcept { } @@ -79,7 +79,7 @@ GCodeResult DhtTemperatureSensor::Configure(GCodeBuffer& gb, const StringRef& re return GCodeResult::ok; } -TemperatureError DhtTemperatureSensor::GetLatestTemperature(float &t, uint8_t outputNumber) +TemperatureError DhtTemperatureSensor::GetLatestTemperature(float &t, uint8_t outputNumber) noexcept { if (outputNumber > 1) { @@ -94,7 +94,7 @@ TemperatureError DhtTemperatureSensor::GetLatestTemperature(float &t, uint8_t ou return result; } -void DhtTemperatureSensor::Interrupt() +void DhtTemperatureSensor::Interrupt() noexcept { if (numPulses < ARRAY_SIZE(pulses)) { @@ -110,12 +110,12 @@ void DhtTemperatureSensor::Interrupt() } } -void DhtTemperatureSensor::Poll() +void DhtTemperatureSensor::Poll() noexcept { SetResult(GetStoredReading(), TemperatureError::success); } -bool DhtTemperatureSensor::PollInTask() +bool DhtTemperatureSensor::PollInTask() noexcept { const auto now = millis(); if ((now - lastReadTime) >= MinimumReadInterval) @@ -126,7 +126,7 @@ bool DhtTemperatureSensor::PollInTask() return false; } -void DhtTemperatureSensor::TakeReading() +void DhtTemperatureSensor::TakeReading() noexcept { // Send the start bit. This must be at least 18ms for the DHT11, 0.8ms for the DHT21, and 1ms long for the DHT22. port.SetMode(PinAccess::write0); @@ -180,7 +180,7 @@ void DhtTemperatureSensor::TakeReading() // Process a reading. If success then update the temperature and humidity and return TemperatureError::success. // Else return the TemperatureError code but do not update the readings. -TemperatureError DhtTemperatureSensor::ProcessReadings(float& t, float& h) +TemperatureError DhtTemperatureSensor::ProcessReadings(float& t, float& h) noexcept { // Check enough bits received and check start bit if (numPulses != ARRAY_SIZE(pulses) || pulses[0] < MinimumOneBitStepClocks) @@ -235,12 +235,12 @@ TemperatureError DhtTemperatureSensor::ProcessReadings(float& t, float& h) // Class DhtHumiditySensor members -DhtHumiditySensor::DhtHumiditySensor(unsigned int sensorNum) +DhtHumiditySensor::DhtHumiditySensor(unsigned int sensorNum) noexcept : AdditionalOutputSensor(sensorNum, "DHT-humidity", false) { } -DhtHumiditySensor::~DhtHumiditySensor() +DhtHumiditySensor::~DhtHumiditySensor() noexcept { } diff --git a/src/Heating/Sensors/DhtSensor.h b/src/Heating/Sensors/DhtSensor.h index 797961aa..5cf86c0d 100644 --- a/src/Heating/Sensors/DhtSensor.h +++ b/src/Heating/Sensors/DhtSensor.h @@ -28,19 +28,19 @@ enum class DhtSensorType class DhtTemperatureSensor : public SensorWithPort { public: - DhtTemperatureSensor(unsigned int sensorNum, DhtSensorType type); - ~DhtTemperatureSensor(); + DhtTemperatureSensor(unsigned int sensorNum, DhtSensorType type) noexcept; + ~DhtTemperatureSensor() noexcept; GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply) override; - TemperatureError GetLatestTemperature(float& t, uint8_t outputNumber = 0) override; - const uint8_t GetNumAdditionalOutputs() const override { return 1; } + TemperatureError GetLatestTemperature(float& t, uint8_t outputNumber = 0) noexcept override; + const uint8_t GetNumAdditionalOutputs() const noexcept override { return 1; } - void Poll() override; - bool PollInTask() override; + void Poll() noexcept override; + bool PollInTask() noexcept override; - void Interrupt(); - void TakeReading(); - TemperatureError ProcessReadings(float& t, float& h); + void Interrupt() noexcept; + void TakeReading() noexcept; + TemperatureError ProcessReadings(float& t, float& h) noexcept; static constexpr const char *TypeNameDht11 = "dht11"; static constexpr const char *TypeNameDht21 = "dht21"; @@ -62,8 +62,8 @@ private: class DhtHumiditySensor : public AdditionalOutputSensor { public: - DhtHumiditySensor(unsigned int sensorNum); - ~DhtHumiditySensor(); + DhtHumiditySensor(unsigned int sensorNum) noexcept; + ~DhtHumiditySensor() noexcept; static constexpr const char *TypeName = "dhthumidity"; }; diff --git a/src/Heating/Sensors/LinearAnalogSensor.cpp b/src/Heating/Sensors/LinearAnalogSensor.cpp index 8b72582a..8117a839 100644 --- a/src/Heating/Sensors/LinearAnalogSensor.cpp +++ b/src/Heating/Sensors/LinearAnalogSensor.cpp @@ -11,7 +11,7 @@ #include "RepRap.h" #include "Platform.h" -LinearAnalogSensor::LinearAnalogSensor(unsigned int sensorNum) +LinearAnalogSensor::LinearAnalogSensor(unsigned int sensorNum) noexcept : SensorWithPort(sensorNum, "Linear analog"), lowTemp(DefaultLowTemp), highTemp(DefaultHighTemp), filtered(true), adcFilterChannel(-1) { CalcDerivedParameters(); @@ -50,7 +50,7 @@ GCodeResult LinearAnalogSensor::Configure(GCodeBuffer& gb, const StringRef& repl return GCodeResult::ok; } -void LinearAnalogSensor::Poll() +void LinearAnalogSensor::Poll() noexcept { if (filtered && adcFilterChannel >= 0) { @@ -71,7 +71,7 @@ void LinearAnalogSensor::Poll() } } -void LinearAnalogSensor::CalcDerivedParameters() +void LinearAnalogSensor::CalcDerivedParameters() noexcept { adcFilterChannel = reprap.GetPlatform().GetAveragingFilterIndex(port); linearIncreasePerCount = (highTemp - lowTemp)/((filtered) ? FilteredAdcRange : UnfilteredAdcRange); diff --git a/src/Heating/Sensors/LinearAnalogSensor.h b/src/Heating/Sensors/LinearAnalogSensor.h index 046dd6aa..43c7f61b 100644 --- a/src/Heating/Sensors/LinearAnalogSensor.h +++ b/src/Heating/Sensors/LinearAnalogSensor.h @@ -13,16 +13,16 @@ class LinearAnalogSensor : public SensorWithPort { public: - LinearAnalogSensor(unsigned int sensorNum); + LinearAnalogSensor(unsigned int sensorNum) noexcept; GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply) override; static constexpr const char *TypeName = "linearanalog"; - void Poll() override; + void Poll() noexcept override; private: - void CalcDerivedParameters(); + void CalcDerivedParameters() noexcept; // Configurable parameters float lowTemp, highTemp; diff --git a/src/Heating/Sensors/RemoteSensor.cpp b/src/Heating/Sensors/RemoteSensor.cpp index 700d02f0..0806f783 100644 --- a/src/Heating/Sensors/RemoteSensor.cpp +++ b/src/Heating/Sensors/RemoteSensor.cpp @@ -14,7 +14,7 @@ constexpr uint32_t RemoteTemperatureTimeoutMillis = 1000; -RemoteSensor::RemoteSensor(unsigned int sensorNum, CanAddress pBoardAddress) +RemoteSensor::RemoteSensor(unsigned int sensorNum, CanAddress pBoardAddress) noexcept : TemperatureSensor(sensorNum, "remote"), boardAddress(pBoardAddress) { } @@ -31,7 +31,7 @@ GCodeResult RemoteSensor::Configure(GCodeBuffer& gb, const StringRef& reply) return cons.SendAndGetResponse(CanMessageType::m308, boardAddress, reply); } -void RemoteSensor::UpdateRemoteTemperature(CanAddress src, const CanSensorReport& report) +void RemoteSensor::UpdateRemoteTemperature(CanAddress src, const CanSensorReport& report) noexcept { if (src == boardAddress) { diff --git a/src/Heating/Sensors/RemoteSensor.h b/src/Heating/Sensors/RemoteSensor.h index 823ab9e5..22edb4d4 100644 --- a/src/Heating/Sensors/RemoteSensor.h +++ b/src/Heating/Sensors/RemoteSensor.h @@ -15,14 +15,14 @@ class RemoteSensor : public TemperatureSensor { public: - RemoteSensor(unsigned int sensorNum, CanAddress pBoardAddress); + RemoteSensor(unsigned int sensorNum, CanAddress pBoardAddress) noexcept; GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply) override; - CanAddress GetBoardAddress() const override { return boardAddress; } - void UpdateRemoteTemperature(CanAddress src, const CanSensorReport& report) override; + CanAddress GetBoardAddress() const noexcept override { return boardAddress; } + void UpdateRemoteTemperature(CanAddress src, const CanSensorReport& report) noexcept override; // Try to get a temperature reading - void Poll() override { } // nothing to do here because reception of CAN messages update the reading + void Poll() noexcept override { } // nothing to do here because reception of CAN messages update the reading private: CanAddress boardAddress; diff --git a/src/Heating/Sensors/RtdSensor31865.cpp b/src/Heating/Sensors/RtdSensor31865.cpp index 9f6df81b..44dbfcb0 100644 --- a/src/Heating/Sensors/RtdSensor31865.cpp +++ b/src/Heating/Sensors/RtdSensor31865.cpp @@ -35,7 +35,7 @@ const uint8_t Cr0ReadMask = 0b11011101; // bits 1 and 5 auto clear, so ignore t const uint16_t DefaultRef = 400; -RtdSensor31865::RtdSensor31865(unsigned int sensorNum) +RtdSensor31865::RtdSensor31865(unsigned int sensorNum) noexcept : SpiTemperatureSensor(sensorNum, "PT100 (MAX31865)", MAX31865_SpiMode, MAX31865_Frequency), rref(DefaultRef), cr0(DefaultCr0) { @@ -117,7 +117,7 @@ GCodeResult RtdSensor31865::Configure(GCodeBuffer& gb, const StringRef& reply) } // Try to initialise the RTD -TemperatureError RtdSensor31865::TryInitRtd() const +TemperatureError RtdSensor31865::TryInitRtd() const noexcept { const uint8_t modeData[2] = { 0x80, cr0 }; // write register 0 uint32_t rawVal; @@ -139,7 +139,7 @@ TemperatureError RtdSensor31865::TryInitRtd() const return sts; } -void RtdSensor31865::Poll() +void RtdSensor31865::Poll() noexcept { static const uint8_t dataOut[4] = {0, 0x55, 0x55, 0x55}; // read registers 0 (control), 1 (MSB) and 2 (LSB) uint32_t rawVal; diff --git a/src/Heating/Sensors/RtdSensor31865.h b/src/Heating/Sensors/RtdSensor31865.h index 4a31d36e..bb78a40d 100644 --- a/src/Heating/Sensors/RtdSensor31865.h +++ b/src/Heating/Sensors/RtdSensor31865.h @@ -13,15 +13,15 @@ class RtdSensor31865 : public SpiTemperatureSensor { public: - RtdSensor31865(unsigned int sensorNum); + RtdSensor31865(unsigned int sensorNum) noexcept; GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply) override; static constexpr const char *TypeName = "rtdmax31865"; - void Poll() override; + void Poll() noexcept override; private: - TemperatureError TryInitRtd() const; + TemperatureError TryInitRtd() const noexcept; uint16_t rref; // reference resistor in ohms uint8_t cr0; diff --git a/src/Heating/Sensors/SensorWithPort.cpp b/src/Heating/Sensors/SensorWithPort.cpp index 7609ad81..004645e1 100644 --- a/src/Heating/Sensors/SensorWithPort.cpp +++ b/src/Heating/Sensors/SensorWithPort.cpp @@ -8,12 +8,12 @@ #include "SensorWithPort.h" #include "GCodes/GCodeBuffer/GCodeBuffer.h" -SensorWithPort::SensorWithPort(unsigned int sensorNum, const char *type) +SensorWithPort::SensorWithPort(unsigned int sensorNum, const char *type) noexcept : TemperatureSensor(sensorNum, type) { } -SensorWithPort::~SensorWithPort() +SensorWithPort::~SensorWithPort() noexcept { port.Release(); } @@ -35,7 +35,7 @@ bool SensorWithPort::ConfigurePort(GCodeBuffer& gb, const StringRef& reply, PinA } // Copy the basic details to the reply buffer. This hides the version in the base class. -void SensorWithPort::CopyBasicDetails(const StringRef& reply) const +void SensorWithPort::CopyBasicDetails(const StringRef& reply) const noexcept { reply.printf("Sensor %u", GetSensorNumber()); if (GetSensorName() != nullptr) diff --git a/src/Heating/Sensors/SensorWithPort.h b/src/Heating/Sensors/SensorWithPort.h index 140cd0e9..d627247c 100644 --- a/src/Heating/Sensors/SensorWithPort.h +++ b/src/Heating/Sensors/SensorWithPort.h @@ -13,14 +13,14 @@ class SensorWithPort : public TemperatureSensor { protected: - SensorWithPort(unsigned int sensorNum, const char *type); - ~SensorWithPort(); + SensorWithPort(unsigned int sensorNum, const char *type) noexcept; + ~SensorWithPort() noexcept; // Try to configure the port bool ConfigurePort(GCodeBuffer& gb, const StringRef& reply, PinAccess access, bool& seen); // Copy the basic details to the reply buffer. This hides the version in the base class. - void CopyBasicDetails(const StringRef& reply) const; + void CopyBasicDetails(const StringRef& reply) const noexcept; IoPort port; }; diff --git a/src/Heating/Sensors/SpiTemperatureSensor.cpp b/src/Heating/Sensors/SpiTemperatureSensor.cpp index 15d64bc3..53665b6f 100644 --- a/src/Heating/Sensors/SpiTemperatureSensor.cpp +++ b/src/Heating/Sensors/SpiTemperatureSensor.cpp @@ -8,7 +8,7 @@ #include "SpiTemperatureSensor.h" #include "Tasks.h" -SpiTemperatureSensor::SpiTemperatureSensor(unsigned int sensorNum, const char *name, uint8_t spiMode, uint32_t clockFrequency) +SpiTemperatureSensor::SpiTemperatureSensor(unsigned int sensorNum, const char *name, uint8_t spiMode, uint32_t clockFrequency) noexcept : SensorWithPort(sensorNum, name) { device.csPin = NoPin; @@ -29,14 +29,14 @@ bool SpiTemperatureSensor::ConfigurePort(GCodeBuffer& gb, const StringRef& reply return ret; } -void SpiTemperatureSensor::InitSpi() +void SpiTemperatureSensor::InitSpi() noexcept { sspi_master_init(&device, 8); lastReadingTime = millis(); } // Send and receive 1 to 8 bytes of data and return the result as a single 32-bit word -TemperatureError SpiTemperatureSensor::DoSpiTransaction(const uint8_t dataOut[], size_t nbytes, uint32_t& rslt) const +TemperatureError SpiTemperatureSensor::DoSpiTransaction(const uint8_t dataOut[], size_t nbytes, uint32_t& rslt) const noexcept { uint8_t rawBytes[8]; spi_status_t sts; diff --git a/src/Heating/Sensors/SpiTemperatureSensor.h b/src/Heating/Sensors/SpiTemperatureSensor.h index cbe8478e..f243f259 100644 --- a/src/Heating/Sensors/SpiTemperatureSensor.h +++ b/src/Heating/Sensors/SpiTemperatureSensor.h @@ -14,10 +14,10 @@ class SpiTemperatureSensor : public SensorWithPort { protected: - SpiTemperatureSensor(unsigned int sensorNum, const char *name, uint8_t spiMode, uint32_t clockFrequency); + SpiTemperatureSensor(unsigned int sensorNum, const char *name, uint8_t spiMode, uint32_t clockFrequency) noexcept; bool ConfigurePort(GCodeBuffer& gb, const StringRef& reply, bool& seen); - void InitSpi(); - TemperatureError DoSpiTransaction(const uint8_t dataOut[], size_t nbytes, uint32_t& rslt) const + void InitSpi() noexcept; + TemperatureError DoSpiTransaction(const uint8_t dataOut[], size_t nbytes, uint32_t& rslt) const noexcept pre(nbytes <= 8); sspi_device device; diff --git a/src/Heating/Sensors/TemperatureSensor.cpp b/src/Heating/Sensors/TemperatureSensor.cpp index 47ef5048..566e8747 100644 --- a/src/Heating/Sensors/TemperatureSensor.cpp +++ b/src/Heating/Sensors/TemperatureSensor.cpp @@ -25,18 +25,18 @@ #endif // Constructor -TemperatureSensor::TemperatureSensor(unsigned int sensorNum, const char *t) +TemperatureSensor::TemperatureSensor(unsigned int sensorNum, const char *t) noexcept : next(nullptr), sensorNumber(sensorNum), sensorType(t), sensorName(nullptr), lastTemperature(0.0), whenLastRead(0), lastResult(TemperatureError::notReady), lastRealError(TemperatureError::success) {} // Virtual destructor -TemperatureSensor::~TemperatureSensor() +TemperatureSensor::~TemperatureSensor() noexcept { delete sensorName; } // Return the latest temperature reading -TemperatureError TemperatureSensor::GetLatestTemperature(float& t, uint8_t outputNumber) +TemperatureError TemperatureSensor::GetLatestTemperature(float& t, uint8_t outputNumber) noexcept { if (millis() - whenLastRead > TemperatureReadingTimeout) { @@ -48,7 +48,7 @@ TemperatureError TemperatureSensor::GetLatestTemperature(float& t, uint8_t outpu } // Set the name - normally called only once, so we allow heap memory to be allocated -void TemperatureSensor::SetSensorName(const char *newName) +void TemperatureSensor::SetSensorName(const char *newName) noexcept { // Change the heater name in a thread-safe manner const char *oldName = sensorName; @@ -76,7 +76,7 @@ GCodeResult TemperatureSensor::Configure(GCodeBuffer& gb, const StringRef& reply return GCodeResult::ok; } -void TemperatureSensor::CopyBasicDetails(const StringRef& reply) const +void TemperatureSensor::CopyBasicDetails(const StringRef& reply) const noexcept { reply.printf("Sensor %d", sensorNumber); if (sensorName != nullptr) @@ -99,7 +99,7 @@ void TemperatureSensor::TryConfigureSensorName(GCodeBuffer& gb, bool& seen) } } -void TemperatureSensor::SetResult(float t, TemperatureError rslt) +void TemperatureSensor::SetResult(float t, TemperatureError rslt) noexcept { lastResult = rslt; lastTemperature = t; @@ -111,7 +111,7 @@ void TemperatureSensor::SetResult(float t, TemperatureError rslt) } // This version is used for unsuccessful readings only -void TemperatureSensor::SetResult(TemperatureError rslt) +void TemperatureSensor::SetResult(TemperatureError rslt) noexcept { lastResult = lastRealError = rslt; lastTemperature = BadErrorTemperature; @@ -121,13 +121,13 @@ void TemperatureSensor::SetResult(TemperatureError rslt) #if SUPPORT_CAN_EXPANSION // Get the expansion board address. Overridden for remote sensors. -CanAddress TemperatureSensor::GetBoardAddress() const +CanAddress TemperatureSensor::GetBoardAddress() const noexcept { return CanInterface::GetCanAddress(); } // Update the temperature, if it is a remote sensor. Overridden in class RemoteSensor. -void TemperatureSensor::UpdateRemoteTemperature(CanAddress src, const CanSensorReport& report) +void TemperatureSensor::UpdateRemoteTemperature(CanAddress src, const CanSensorReport& report) noexcept { // Nothing to do here. This function is overridden in class RemoteSensor. } @@ -136,9 +136,9 @@ void TemperatureSensor::UpdateRemoteTemperature(CanAddress src, const CanSensorR // Factory method #if SUPPORT_CAN_EXPANSION -TemperatureSensor *TemperatureSensor::Create(unsigned int sensorNum, CanAddress boardAddress, const char *typeName, const StringRef& reply) +TemperatureSensor *TemperatureSensor::Create(unsigned int sensorNum, CanAddress boardAddress, const char *typeName, const StringRef& reply) noexcept #else -TemperatureSensor *TemperatureSensor::Create(unsigned int sensorNum, const char *typeName, const StringRef& reply) +TemperatureSensor *TemperatureSensor::Create(unsigned int sensorNum, const char *typeName, const StringRef& reply) noexcept #endif { TemperatureSensor *ts; @@ -251,7 +251,7 @@ static const uint16_t tempTable[] = const size_t NumTempTableEntries = sizeof(tempTable)/sizeof(tempTable[0]); -/*static*/ TemperatureError TemperatureSensor::GetPT100Temperature(float& t, uint16_t ohmsx100) +/*static*/ TemperatureError TemperatureSensor::GetPT100Temperature(float& t, uint16_t ohmsx100) noexcept { // Formally-verified binary search routine, adapted from one of the eCv examples diff --git a/src/Heating/Sensors/TemperatureSensor.h b/src/Heating/Sensors/TemperatureSensor.h index a68a99ea..d4b50a6d 100644 --- a/src/Heating/Sensors/TemperatureSensor.h +++ b/src/Heating/Sensors/TemperatureSensor.h @@ -12,19 +12,19 @@ struct CanSensorReport; class TemperatureSensor { public: - TemperatureSensor(unsigned int sensorNum, const char *type); + TemperatureSensor(unsigned int sensorNum, const char *type) noexcept; // Virtual destructor - virtual ~TemperatureSensor(); + virtual ~TemperatureSensor() noexcept; // Try to get a temperature reading - virtual TemperatureError GetLatestTemperature(float& t, uint8_t outputNumber = 0); + virtual TemperatureError GetLatestTemperature(float& t, uint8_t outputNumber = 0) noexcept; // How many additional outputs does this sensor have - virtual const uint8_t GetNumAdditionalOutputs() const { return 0; } + virtual const uint8_t GetNumAdditionalOutputs() const noexcept { return 0; } // Get the most recent reading without checking for timeout - float GetStoredReading() const { return lastTemperature; } + float GetStoredReading() const noexcept { return lastTemperature; } // Configure the sensor from M308 parameters. // If we find any parameters, process them, if successful then initialise the sensor and return GCodeResult::ok. @@ -33,57 +33,57 @@ public: virtual GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply); // Return the sensor type - const char *GetSensorType() const { return sensorType; } + const char *GetSensorType() const noexcept { return sensorType; } // Return the sensor number - unsigned int GetSensorNumber() const { return sensorNumber; } + unsigned int GetSensorNumber() const noexcept { return sensorNumber; } // Return the code for the most recent error - TemperatureError GetLastError() const { return lastRealError; } + TemperatureError GetLastError() const noexcept { return lastRealError; } // Configure the sensor name, if it is provided void TryConfigureSensorName(GCodeBuffer& gb, bool& seen); // Set the name - normally called only once - void SetSensorName(const char *newName); + void SetSensorName(const char *newName) noexcept; // Get the name. Returns nullptr if no name has been assigned. - const char *GetSensorName() const { return sensorName; } + const char *GetSensorName() const noexcept { return sensorName; } // Copy the basic details to the reply buffer - void CopyBasicDetails(const StringRef& reply) const; + void CopyBasicDetails(const StringRef& reply) const noexcept; // Get/set the next sensor in the linked list - TemperatureSensor *GetNext() const { return next; } - void SetNext(TemperatureSensor *n) { next = n; } + TemperatureSensor *GetNext() const noexcept { return next; } + void SetNext(TemperatureSensor *n) noexcept { next = n; } // Get the smart drivers channel that this sensor monitors, or -1 if it doesn't - virtual int GetSmartDriversChannel() const { return -1; } + virtual int GetSmartDriversChannel() const noexcept { return -1; } #if SUPPORT_CAN_EXPANSION // Get the expansion board address. Overridden for remote sensors. - virtual CanAddress GetBoardAddress() const; + virtual CanAddress GetBoardAddress() const noexcept; // Update the temperature, if it is a remote sensor. Overridden in class RemoteSensor. - virtual void UpdateRemoteTemperature(CanAddress src, const CanSensorReport& report); + virtual void UpdateRemoteTemperature(CanAddress src, const CanSensorReport& report) noexcept; #endif // Factory method #if SUPPORT_CAN_EXPANSION - static TemperatureSensor *Create(unsigned int sensorNum, CanAddress boardAddress, const char *typeName, const StringRef& reply); + static TemperatureSensor *Create(unsigned int sensorNum, CanAddress boardAddress, const char *typeName, const StringRef& reply) noexcept; #else - static TemperatureSensor *Create(unsigned int sensorNum, const char *typeName, const StringRef& reply); + static TemperatureSensor *Create(unsigned int sensorNum, const char *typeName, const StringRef& reply) noexcept; #endif // Try to get a temperature reading - virtual void Poll() = 0; - virtual bool PollInTask() { return false; }; // Classes implementing this method need to also call Heat::EnsureSensorsTask() after succesful configuration + virtual void Poll() noexcept = 0; + virtual bool PollInTask() noexcept { return false; }; // Classes implementing this method need to also call Heat::EnsureSensorsTask() after succesful configuration protected: - void SetResult(float t, TemperatureError rslt); - void SetResult(TemperatureError rslt); + void SetResult(float t, TemperatureError rslt) noexcept; + void SetResult(TemperatureError rslt) noexcept; - static TemperatureError GetPT100Temperature(float& t, uint16_t ohmsx100); // shared function used by two derived classes + static TemperatureError GetPT100Temperature(float& t, uint16_t ohmsx100) noexcept; // shared function used by two derived classes private: static constexpr uint32_t TemperatureReadingTimeout = 2000; // any reading older than this number of milliseconds is considered unreliable diff --git a/src/Heating/Sensors/Thermistor.cpp b/src/Heating/Sensors/Thermistor.cpp index b3f405e1..f54f8a14 100644 --- a/src/Heating/Sensors/Thermistor.cpp +++ b/src/Heating/Sensors/Thermistor.cpp @@ -20,7 +20,7 @@ // The parameters that can be configured in RRF are R25 (the resistance at 25C), Beta, and optionally C. // Create an instance with default values -Thermistor::Thermistor(unsigned int sensorNum, bool p_isPT1000) +Thermistor::Thermistor(unsigned int sensorNum, bool p_isPT1000) noexcept : SensorWithPort(sensorNum, (p_isPT1000) ? "PT1000" : "Thermistor"), r25(DefaultR25), beta(DefaultBeta), shC(DefaultShc), seriesR(DefaultThermistorSeriesR), adcFilterChannel(-1), isPT1000(p_isPT1000) #if !HAS_VREF_MONITOR || defined(DUET3) @@ -102,7 +102,7 @@ GCodeResult Thermistor::Configure(GCodeBuffer& gb, const StringRef& reply) } // Get the temperature -void Thermistor::Poll() +void Thermistor::Poll() noexcept { int32_t averagedTempReading; bool tempFilterValid; @@ -222,7 +222,7 @@ void Thermistor::Poll() } // Calculate shA and shB from the other parameters -void Thermistor::CalcDerivedParameters() +void Thermistor::CalcDerivedParameters() noexcept { shB = 1.0/beta; const float lnR25 = logf(r25); diff --git a/src/Heating/Sensors/Thermistor.h b/src/Heating/Sensors/Thermistor.h index 62ee37de..ccaaaa1c 100644 --- a/src/Heating/Sensors/Thermistor.h +++ b/src/Heating/Sensors/Thermistor.h @@ -21,19 +21,19 @@ class Thermistor : public SensorWithPort { public: - Thermistor(unsigned int sensorNum, bool p_isPT1000); // create an instance with default values + Thermistor(unsigned int sensorNum, bool p_isPT1000) noexcept; // create an instance with default values GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply) override; // configure the sensor from M305 parameters static constexpr const char *TypeNameThermistor = "thermistor"; static constexpr const char *TypeNamePT1000 = "pt1000"; - void Poll() override; + void Poll() noexcept override; private: // For the theory behind ADC oversampling, see http://www.atmel.com/Images/doc8003.pdf static constexpr unsigned int AdcOversampleBits = 2; // we use 2-bit oversampling - void CalcDerivedParameters(); // calculate shA and shB + void CalcDerivedParameters() noexcept; // calculate shA and shB // The following are configurable parameters float r25, beta, shC, seriesR; // parameters declared in the M305 command diff --git a/src/Heating/Sensors/ThermocoupleSensor31855.cpp b/src/Heating/Sensors/ThermocoupleSensor31855.cpp index 7177d936..15842081 100644 --- a/src/Heating/Sensors/ThermocoupleSensor31855.cpp +++ b/src/Heating/Sensors/ThermocoupleSensor31855.cpp @@ -61,7 +61,7 @@ const uint8_t MAX31855_SpiMode = SPI_MODE_0; // Define the minimum interval between readings const uint32_t MinimumReadInterval = 100; // minimum interval between reads, in milliseconds -ThermocoupleSensor31855::ThermocoupleSensor31855(unsigned int sensorNum) +ThermocoupleSensor31855::ThermocoupleSensor31855(unsigned int sensorNum) noexcept : SpiTemperatureSensor(sensorNum, "Thermocouple (MAX31855)", MAX31855_SpiMode, MAX31855_Frequency) { } @@ -90,7 +90,7 @@ GCodeResult ThermocoupleSensor31855::Configure(GCodeBuffer& gb, const StringRef& return GCodeResult::ok; } -void ThermocoupleSensor31855::Poll() +void ThermocoupleSensor31855::Poll() noexcept { uint32_t rawVal; TemperatureError sts = DoSpiTransaction(nullptr, 4, rawVal); diff --git a/src/Heating/Sensors/ThermocoupleSensor31855.h b/src/Heating/Sensors/ThermocoupleSensor31855.h index 2fb81a9a..fdd8de98 100644 --- a/src/Heating/Sensors/ThermocoupleSensor31855.h +++ b/src/Heating/Sensors/ThermocoupleSensor31855.h @@ -13,12 +13,12 @@ class ThermocoupleSensor31855 : public SpiTemperatureSensor { public: - ThermocoupleSensor31855(unsigned int sensorNum); + ThermocoupleSensor31855(unsigned int sensorNum) noexcept; GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply) override; static constexpr const char *TypeName = "thermocouplemax31855"; - void Poll() override; + void Poll() noexcept override; }; #endif /* SRC_HEATING_THERMOCOUPLESENSOR31855_H_ */ diff --git a/src/Heating/Sensors/ThermocoupleSensor31856.cpp b/src/Heating/Sensors/ThermocoupleSensor31856.cpp index cc4402e7..df257349 100644 --- a/src/Heating/Sensors/ThermocoupleSensor31856.cpp +++ b/src/Heating/Sensors/ThermocoupleSensor31856.cpp @@ -53,7 +53,7 @@ const uint8_t Cr1ReadMask = 0b01111111; // ignore the reserved bits // Openfault=0 assert fault on open circuit condition const uint8_t DefaultFaultMask = 0b00111100; -ThermocoupleSensor31856::ThermocoupleSensor31856(unsigned int sensorNum) +ThermocoupleSensor31856::ThermocoupleSensor31856(unsigned int sensorNum) noexcept : SpiTemperatureSensor(sensorNum, "Thermocouple (MAX31856)", MAX31856_SpiMode, MAX31856_Frequency), cr0(DefaultCr0), thermocoupleType(TypeK) { @@ -130,7 +130,7 @@ GCodeResult ThermocoupleSensor31856::Configure(GCodeBuffer& gb, const StringRef& return GCodeResult::ok; } -TemperatureError ThermocoupleSensor31856::TryInitThermocouple() const +TemperatureError ThermocoupleSensor31856::TryInitThermocouple() const noexcept { const uint8_t modeData[4] = { 0x80, cr0, (uint8_t)(DefaultCr1 | thermocoupleType), DefaultFaultMask }; // write registers 0, 1, 2 uint32_t rawVal; @@ -158,7 +158,7 @@ TemperatureError ThermocoupleSensor31856::TryInitThermocouple() const return sts; } -void ThermocoupleSensor31856::Poll() +void ThermocoupleSensor31856::Poll() noexcept { static const uint8_t dataOut[5] = {0x0C, 0x55, 0x55, 0x55, 0x55}; // read registers LTCB0, LTCB1, LTCB2, Fault status uint32_t rawVal; diff --git a/src/Heating/Sensors/ThermocoupleSensor31856.h b/src/Heating/Sensors/ThermocoupleSensor31856.h index cb2bc6a5..080a639c 100644 --- a/src/Heating/Sensors/ThermocoupleSensor31856.h +++ b/src/Heating/Sensors/ThermocoupleSensor31856.h @@ -13,15 +13,15 @@ class ThermocoupleSensor31856 : public SpiTemperatureSensor { public: - ThermocoupleSensor31856(unsigned int sensorNum); + ThermocoupleSensor31856(unsigned int sensorNum) noexcept; GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply) override; static constexpr const char *TypeName = "thermocouplemax31856"; - void Poll() override; + void Poll() noexcept override; private: - TemperatureError TryInitThermocouple() const; + TemperatureError TryInitThermocouple() const noexcept; uint8_t cr0; uint8_t thermocoupleType; diff --git a/src/Heating/Sensors/TmcDriverTemperatureSensor.cpp b/src/Heating/Sensors/TmcDriverTemperatureSensor.cpp index 14a93850..e0b6f8b2 100644 --- a/src/Heating/Sensors/TmcDriverTemperatureSensor.cpp +++ b/src/Heating/Sensors/TmcDriverTemperatureSensor.cpp @@ -11,12 +11,12 @@ #if HAS_SMART_DRIVERS -TmcDriverTemperatureSensor::TmcDriverTemperatureSensor(unsigned int sensorNum, unsigned int chan) +TmcDriverTemperatureSensor::TmcDriverTemperatureSensor(unsigned int sensorNum, unsigned int chan) noexcept : TemperatureSensor(sensorNum, "TMC2660 temperature warnings"), channel(chan) { } -void TmcDriverTemperatureSensor::Poll() +void TmcDriverTemperatureSensor::Poll() noexcept { SetResult(reprap.GetPlatform().GetTmcDriversTemperature(channel), TemperatureError::success); } diff --git a/src/Heating/Sensors/TmcDriverTemperatureSensor.h b/src/Heating/Sensors/TmcDriverTemperatureSensor.h index 98e1a513..e16534fe 100644 --- a/src/Heating/Sensors/TmcDriverTemperatureSensor.h +++ b/src/Heating/Sensors/TmcDriverTemperatureSensor.h @@ -15,7 +15,7 @@ class TmcDriverTemperatureSensor : public TemperatureSensor { public: - TmcDriverTemperatureSensor(unsigned int sensorNum, unsigned int chan); + TmcDriverTemperatureSensor(unsigned int sensorNum, unsigned int chan) noexcept; static constexpr const char *PrimaryTypeName = "drivers"; #ifdef DUET_NG @@ -23,9 +23,9 @@ public: #endif // Get the smart drivers channel that this sensor monitors, or -1 if it doesn't - int GetSmartDriversChannel() const override { return (int) channel; } + int GetSmartDriversChannel() const noexcept override { return (int) channel; } - void Poll() override; + void Poll() noexcept override; private: unsigned int channel; diff --git a/src/Heating/TemperatureError.cpp b/src/Heating/TemperatureError.cpp index 931b24c1..b342a1c8 100644 --- a/src/Heating/TemperatureError.cpp +++ b/src/Heating/TemperatureError.cpp @@ -7,7 +7,7 @@ #include "TemperatureError.h" -const char* TemperatureErrorString(TemperatureError err) +const char* TemperatureErrorString(TemperatureError err) noexcept { switch(err) { diff --git a/src/Heating/TemperatureError.h b/src/Heating/TemperatureError.h index 56eeea57..4b583232 100644 --- a/src/Heating/TemperatureError.h +++ b/src/Heating/TemperatureError.h @@ -33,6 +33,6 @@ enum class TemperatureError : uint8_t badVssa }; -const char* TemperatureErrorString(TemperatureError err); +const char* TemperatureErrorString(TemperatureError err) noexcept; #endif /* TEMPERATUREERROR_H_ */ diff --git a/src/OutputMemory.cpp b/src/OutputMemory.cpp index de2bd8e9..ccfee6c3 100644 --- a/src/OutputMemory.cpp +++ b/src/OutputMemory.cpp @@ -17,7 +17,7 @@ //************************************************************************************************* // OutputBuffer class implementation -void OutputBuffer::Append(OutputBuffer *other) +void OutputBuffer::Append(OutputBuffer *other) noexcept { if (other != nullptr) { @@ -35,7 +35,7 @@ void OutputBuffer::Append(OutputBuffer *other) } } -void OutputBuffer::IncreaseReferences(size_t refs) +void OutputBuffer::IncreaseReferences(size_t refs) noexcept { if (refs > 0) { @@ -49,7 +49,7 @@ void OutputBuffer::IncreaseReferences(size_t refs) } } -size_t OutputBuffer::Length() const +size_t OutputBuffer::Length() const noexcept { size_t totalLength = 0; for (const OutputBuffer *current = this; current != nullptr; current = current->Next()) @@ -59,7 +59,7 @@ size_t OutputBuffer::Length() const return totalLength; } -char &OutputBuffer::operator[](size_t index) +char &OutputBuffer::operator[](size_t index) noexcept { // Get the right buffer to access OutputBuffer *itemToIndex = this; @@ -73,7 +73,7 @@ char &OutputBuffer::operator[](size_t index) return itemToIndex->data[index]; } -char OutputBuffer::operator[](size_t index) const +char OutputBuffer::operator[](size_t index) const noexcept { // Get the right buffer to access const OutputBuffer *itemToIndex = this; @@ -87,14 +87,14 @@ char OutputBuffer::operator[](size_t index) const return itemToIndex->data[index]; } -const char *OutputBuffer::Read(size_t len) +const char *OutputBuffer::Read(size_t len) noexcept { size_t offset = bytesRead; bytesRead += len; return data + offset; } -size_t OutputBuffer::printf(const char *fmt, ...) +size_t OutputBuffer::printf(const char *fmt, ...) noexcept { char formatBuffer[FormatStringLength]; va_list vargs; @@ -105,7 +105,7 @@ size_t OutputBuffer::printf(const char *fmt, ...) return copy(formatBuffer); } -size_t OutputBuffer::vprintf(const char *fmt, va_list vargs) +size_t OutputBuffer::vprintf(const char *fmt, va_list vargs) noexcept { char formatBuffer[FormatStringLength]; SafeVsnprintf(formatBuffer, ARRAY_SIZE(formatBuffer), fmt, vargs); @@ -113,7 +113,7 @@ size_t OutputBuffer::vprintf(const char *fmt, va_list vargs) return cat(formatBuffer); } -size_t OutputBuffer::catf(const char *fmt, ...) +size_t OutputBuffer::catf(const char *fmt, ...) noexcept { char formatBuffer[FormatStringLength]; va_list vargs; @@ -125,7 +125,7 @@ size_t OutputBuffer::catf(const char *fmt, ...) return cat(formatBuffer); } -size_t OutputBuffer::copy(const char c) +size_t OutputBuffer::copy(const char c) noexcept { // Unlink existing entries before starting the copy process if (next != nullptr) @@ -140,12 +140,12 @@ size_t OutputBuffer::copy(const char c) return 1; } -size_t OutputBuffer::copy(const char *src) +size_t OutputBuffer::copy(const char *src) noexcept { return copy(src, strlen(src)); } -size_t OutputBuffer::copy(const char *src, size_t len) +size_t OutputBuffer::copy(const char *src, size_t len) noexcept { // Unlink existing entries before starting the copy process if (next != nullptr) @@ -158,7 +158,7 @@ size_t OutputBuffer::copy(const char *src, size_t len) return cat(src, len); } -size_t OutputBuffer::cat(const char c) +size_t OutputBuffer::cat(const char c) noexcept { // See if we can append a char if (last->dataLength == OUTPUT_BUFFER_SIZE) @@ -189,12 +189,12 @@ size_t OutputBuffer::cat(const char c) return 1; } -size_t OutputBuffer::cat(const char *src) +size_t OutputBuffer::cat(const char *src) noexcept { return cat(src, strlen(src)); } -size_t OutputBuffer::cat(const char *src, size_t len) +size_t OutputBuffer::cat(const char *src, size_t len) noexcept { size_t copied = 0; while (copied < len) @@ -225,13 +225,13 @@ size_t OutputBuffer::cat(const char *src, size_t len) return copied; } -size_t OutputBuffer::cat(StringRef &str) +size_t OutputBuffer::cat(StringRef &str) noexcept { return cat(str.c_str(), str.strlen()); } // Encode a character in JSON format, and append it to the buffer and return the number of bytes written -size_t OutputBuffer::EncodeChar(char c) +size_t OutputBuffer::EncodeChar(char c) noexcept { char esc; switch (c) @@ -271,7 +271,7 @@ size_t OutputBuffer::EncodeChar(char c) } // Encode a string in JSON format and append it to the buffer and return the number of bytes written -size_t OutputBuffer::EncodeString(const char *src, bool allowControlChars, bool prependAsterisk) +size_t OutputBuffer::EncodeString(const char *src, bool allowControlChars, bool prependAsterisk) noexcept { size_t bytesWritten = cat('"'); if (prependAsterisk) @@ -292,7 +292,7 @@ size_t OutputBuffer::EncodeString(const char *src, bool allowControlChars, bool return bytesWritten; } -size_t OutputBuffer::EncodeReply(OutputBuffer *src) +size_t OutputBuffer::EncodeReply(OutputBuffer *src) noexcept { size_t bytesWritten = cat('"'); @@ -313,7 +313,7 @@ size_t OutputBuffer::EncodeReply(OutputBuffer *src) // Write all the data to file, but don't release the buffers // Returns true if successful -bool OutputBuffer::WriteToFile(FileData& f) const +bool OutputBuffer::WriteToFile(FileData& f) const noexcept { bool endedInNewline = false; const OutputBuffer *current = this; @@ -340,7 +340,7 @@ bool OutputBuffer::WriteToFile(FileData& f) const #endif // Initialise the output buffers manager -/*static*/ void OutputBuffer::Init() +/*static*/ void OutputBuffer::Init() noexcept { freeOutputBuffers = nullptr; for (size_t i = 0; i < OUTPUT_BUFFER_COUNT; i++) @@ -350,7 +350,7 @@ bool OutputBuffer::WriteToFile(FileData& f) const } // Allocates an output buffer instance which can be used for (large) string outputs. This must be thread safe. Not safe to call from interrupts! -/*static*/ bool OutputBuffer::Allocate(OutputBuffer *&buf) +/*static*/ bool OutputBuffer::Allocate(OutputBuffer *&buf) noexcept { { TaskCriticalSectionLocker lock; @@ -383,7 +383,7 @@ bool OutputBuffer::WriteToFile(FileData& f) const } // Get the number of bytes left for continuous writing -/*static*/ size_t OutputBuffer::GetBytesLeft(const OutputBuffer *writingBuffer) +/*static*/ size_t OutputBuffer::GetBytesLeft(const OutputBuffer *writingBuffer) noexcept { const size_t freeOutputBuffers = OUTPUT_BUFFER_COUNT - usedOutputBuffers; const size_t bytesLeft = OUTPUT_BUFFER_SIZE - writingBuffer->last->DataLength(); @@ -399,7 +399,7 @@ bool OutputBuffer::WriteToFile(FileData& f) const // Truncate an output buffer to free up more memory. Returns the number of released bytes. // This never releases the first buffer in the chain, so call it with a large value of bytesNeeded to release all buffers except the first. -/*static */ size_t OutputBuffer::Truncate(OutputBuffer *buffer, size_t bytesNeeded) +/*static */ size_t OutputBuffer::Truncate(OutputBuffer *buffer, size_t bytesNeeded) noexcept { // Can we free up space from this chain? Don't break it up if it's referenced anywhere else if (buffer == nullptr || buffer->Next() == nullptr || buffer->IsReferenced()) @@ -436,7 +436,7 @@ bool OutputBuffer::WriteToFile(FileData& f) const } // Releases an output buffer instance and returns the next entry from the chain -/*static */ OutputBuffer *OutputBuffer::Release(OutputBuffer *buf) +/*static */ OutputBuffer *OutputBuffer::Release(OutputBuffer *buf) noexcept { TaskCriticalSectionLocker lock; OutputBuffer * const nextBuffer = buf->next; @@ -457,7 +457,7 @@ bool OutputBuffer::WriteToFile(FileData& f) const return nextBuffer; } -/*static */ void OutputBuffer::ReleaseAll(OutputBuffer * volatile &buf) +/*static */ void OutputBuffer::ReleaseAll(OutputBuffer * volatile &buf) noexcept { while (buf != nullptr) { @@ -465,7 +465,7 @@ bool OutputBuffer::WriteToFile(FileData& f) const } } -/*static*/ void OutputBuffer::Diagnostics(MessageType mtype) +/*static*/ void OutputBuffer::Diagnostics(MessageType mtype) noexcept { reprap.GetPlatform().MessageF(mtype, "Used output buffers: %d of %d (%d max)\n", usedOutputBuffers, OUTPUT_BUFFER_COUNT, maxUsedOutputBuffers); @@ -475,7 +475,7 @@ bool OutputBuffer::WriteToFile(FileData& f) const // OutputStack class implementation // Push an OutputBuffer chain. Return true if successful, else release the buffer and return false. -bool OutputStack::Push(OutputBuffer *buffer, MessageType type) volatile +bool OutputStack::Push(OutputBuffer *buffer, MessageType type) volatile noexcept { { TaskCriticalSectionLocker lock; @@ -498,7 +498,7 @@ bool OutputStack::Push(OutputBuffer *buffer, MessageType type) volatile } // Pop an OutputBuffer chain or return nullptr if none is available -OutputBuffer *OutputStack::Pop() volatile +OutputBuffer *OutputStack::Pop() volatile noexcept { TaskCriticalSectionLocker lock; @@ -519,13 +519,13 @@ OutputBuffer *OutputStack::Pop() volatile } // Returns the first item from the stack or nullptr if none is available -OutputBuffer *OutputStack::GetFirstItem() const volatile +OutputBuffer *OutputStack::GetFirstItem() const volatile noexcept { return (count == 0) ? nullptr : items[0]; } // Returns the first item's type from the stack or NoDestinationMessage if none is available -MessageType OutputStack::GetFirstItemType() const volatile +MessageType OutputStack::GetFirstItemType() const volatile noexcept { return (count == 0) ? MessageType::NoDestinationMessage : types[0]; } @@ -533,7 +533,7 @@ MessageType OutputStack::GetFirstItemType() const volatile #if HAS_LINUX_INTERFACE // Update the first item of the stack -void OutputStack::SetFirstItem(OutputBuffer *buffer) volatile +void OutputStack::SetFirstItem(OutputBuffer *buffer) volatile noexcept { if (count != 0) { @@ -552,7 +552,7 @@ void OutputStack::SetFirstItem(OutputBuffer *buffer) volatile #endif // Release the first item at the top of the stack -void OutputStack::ReleaseFirstItem() volatile +void OutputStack::ReleaseFirstItem() volatile noexcept { if (count != 0) { @@ -569,7 +569,7 @@ void OutputStack::ReleaseFirstItem() volatile } // Release the first item on the top of the stack if it is too old. Return true if the item was timed out or was null. -bool OutputStack::ApplyTimeout(uint32_t ticks) volatile +bool OutputStack::ApplyTimeout(uint32_t ticks) volatile noexcept { bool ret = false; if (count != 0) @@ -590,19 +590,19 @@ bool OutputStack::ApplyTimeout(uint32_t ticks) volatile } // Returns the last item from the stack or nullptr if none is available -OutputBuffer *OutputStack::GetLastItem() const volatile +OutputBuffer *OutputStack::GetLastItem() const volatile noexcept { return (count == 0) ? nullptr : items[count - 1]; } // Returns the type of the last item from the stack or NoDestinationMessage if none is available -MessageType OutputStack::GetLastItemType() const volatile +MessageType OutputStack::GetLastItemType() const volatile noexcept { return (count == 0) ? MessageType::NoDestinationMessage : types[count - 1]; } // Get the total length of all queued buffers -size_t OutputStack::DataLength() const volatile +size_t OutputStack::DataLength() const volatile noexcept { size_t totalLength = 0; @@ -620,7 +620,7 @@ size_t OutputStack::DataLength() const volatile // Append another OutputStack to this instance. If no more space is available, // all OutputBuffers that can't be added are automatically released -void OutputStack::Append(volatile OutputStack& stack) volatile +void OutputStack::Append(volatile OutputStack& stack) volatile noexcept { for (size_t i = 0; i < stack.count; i++) { @@ -639,7 +639,7 @@ void OutputStack::Append(volatile OutputStack& stack) volatile } // Increase the number of references for each OutputBuffer on the stack -void OutputStack::IncreaseReferences(size_t num) volatile +void OutputStack::IncreaseReferences(size_t num) volatile noexcept { TaskCriticalSectionLocker lock; for (size_t i = 0; i < count; i++) @@ -652,7 +652,7 @@ void OutputStack::IncreaseReferences(size_t num) volatile } // Release all buffers and clean up -void OutputStack::ReleaseAll() volatile +void OutputStack::ReleaseAll() volatile noexcept { for (size_t i = 0; i < count; i++) { diff --git a/src/OutputMemory.h b/src/OutputMemory.h index 80f4e893..4c832ba3 100644 --- a/src/OutputMemory.h +++ b/src/OutputMemory.h @@ -26,78 +26,78 @@ class OutputBuffer public: friend class OutputStack; - OutputBuffer(OutputBuffer *n) : next(n) { } + OutputBuffer(OutputBuffer *n) noexcept : next(n) { } - void Append(OutputBuffer *other); - OutputBuffer *Next() const { return next; } - bool IsReferenced() const { return isReferenced; } - bool HadOverflow() const { return hadOverflow; } - void IncreaseReferences(size_t refs); + void Append(OutputBuffer *other) noexcept; + OutputBuffer *Next() const noexcept { return next; } + bool IsReferenced() const noexcept { return isReferenced; } + bool HadOverflow() const noexcept { return hadOverflow; } + void IncreaseReferences(size_t refs) noexcept; - const char *Data() const { return data; } - const char *UnreadData() const { return data + bytesRead; } - size_t DataLength() const { return dataLength; } // How many bytes have been written to this instance? - size_t Length() const; // How many bytes have been written to the whole chain? + const char *Data() const noexcept { return data; } + const char *UnreadData() const noexcept { return data + bytesRead; } + size_t DataLength() const noexcept { return dataLength; } // How many bytes have been written to this instance? + size_t Length() const noexcept; // How many bytes have been written to the whole chain? - char& operator[](size_t index); - char operator[](size_t index) const; - const char *Read(size_t len); - void Taken(size_t len) { bytesRead += len; } - size_t BytesLeft() const { return dataLength - bytesRead; } // How many bytes have not been sent yet? + char& operator[](size_t index) noexcept; + char operator[](size_t index) const noexcept; + const char *Read(size_t len) noexcept; + void Taken(size_t len) noexcept { bytesRead += len; } + size_t BytesLeft() const noexcept { return dataLength - bytesRead; } // How many bytes have not been sent yet? - size_t printf(const char *fmt, ...) __attribute__ ((format (printf, 2, 3))); - size_t vprintf(const char *fmt, va_list vargs); - size_t catf(const char *fmt, ...) __attribute__ ((format (printf, 2, 3))); + size_t printf(const char *fmt, ...) noexcept __attribute__ ((format (printf, 2, 3))); + size_t vprintf(const char *fmt, va_list vargs) noexcept; + size_t catf(const char *fmt, ...) noexcept __attribute__ ((format (printf, 2, 3))); - size_t copy(const char c); - size_t copy(const char *src); - size_t copy(const char *src, size_t len); + size_t copy(const char c) noexcept; + size_t copy(const char *src) noexcept; + size_t copy(const char *src, size_t len) noexcept; - size_t cat(const char c); - size_t cat(const char *src); - size_t cat(const char *src, size_t len); - size_t cat(StringRef &str); + size_t cat(const char c) noexcept; + size_t cat(const char *src) noexcept; + size_t cat(const char *src, size_t len) noexcept; + size_t cat(StringRef &str) noexcept; - size_t EncodeString(const char *src, bool allowControlChars, bool prependAsterisk = false); + size_t EncodeString(const char *src, bool allowControlChars, bool prependAsterisk = false) noexcept; - template size_t EncodeString(const String& str, bool allowControlChars, bool prependAsterisk = false) + template size_t EncodeString(const String& str, bool allowControlChars, bool prependAsterisk = false) noexcept { return EncodeString(str.c_str(), allowControlChars, prependAsterisk); } - size_t EncodeReply(OutputBuffer *src); + size_t EncodeReply(OutputBuffer *src) noexcept; - uint32_t GetAge() const; + uint32_t GetAge() const noexcept; #if HAS_MASS_STORAGE // Write the buffer to file returning true if successful - bool WriteToFile(FileData& f) const; + bool WriteToFile(FileData& f) const noexcept; #endif // Initialise the output buffers manager - static void Init(); + static void Init() noexcept; // Allocate an unused OutputBuffer instance. Returns true on success or false if no instance could be allocated. - static bool Allocate(OutputBuffer *&buf); + static bool Allocate(OutputBuffer *&buf) noexcept; // Get the number of bytes left for allocation. If writingBuffer is not NULL, this returns the number of free bytes for // continuous writes, i.e. for writes that need to allocate an extra OutputBuffer instance to finish the message. - static size_t GetBytesLeft(const OutputBuffer *writingBuffer); + static size_t GetBytesLeft(const OutputBuffer *writingBuffer) noexcept; // Truncate an OutputBuffer instance to free up more memory. Returns the number of released bytes. - static size_t Truncate(OutputBuffer *buffer, size_t bytesNeeded); + static size_t Truncate(OutputBuffer *buffer, size_t bytesNeeded) noexcept; // Release one OutputBuffer instance. Returns the next item from the chain or nullptr if this was the last instance. - static OutputBuffer *Release(OutputBuffer *buf); + static OutputBuffer *Release(OutputBuffer *buf) noexcept; // Release all OutputBuffer objects in a chain - static void ReleaseAll(OutputBuffer * volatile &buf); + static void ReleaseAll(OutputBuffer * volatile &buf) noexcept; - static void Diagnostics(MessageType mtype); + static void Diagnostics(MessageType mtype) noexcept; static unsigned int GetFreeBuffers() { return OUTPUT_BUFFER_COUNT - usedOutputBuffers; } private: - size_t EncodeChar(char c); + size_t EncodeChar(char c) noexcept; OutputBuffer *next; OutputBuffer *last; @@ -116,7 +116,7 @@ class OutputBuffer static volatile size_t maxUsedOutputBuffers; }; -inline uint32_t OutputBuffer::GetAge() const +inline uint32_t OutputBuffer::GetAge() const noexcept { return millis() - whenQueued; } @@ -126,54 +126,54 @@ inline uint32_t OutputBuffer::GetAge() const class OutputStack { public: - OutputStack() : count(0) { } + OutputStack() noexcept : count(0) { } // Is there anything on this stack? - bool IsEmpty() const volatile { return count == 0; } + bool IsEmpty() const volatile noexcept { return count == 0; } // Clear the reference list - void Clear() volatile { count = 0; } + void Clear() volatile noexcept { count = 0; } // Push an OutputBuffer chain. Return true if successful, else release the buffer and return false. - bool Push(OutputBuffer *buffer, MessageType type = NoDestinationMessage) volatile; + bool Push(OutputBuffer *buffer, MessageType type = NoDestinationMessage) volatile noexcept; // Pop an OutputBuffer chain or return NULL if none is available - OutputBuffer *Pop() volatile; + OutputBuffer *Pop() volatile noexcept; // Returns the first item from the stack or NULL if none is available - OutputBuffer *GetFirstItem() const volatile; + OutputBuffer *GetFirstItem() const volatile noexcept; // Returns the first item's type from the stack or NoDestinationMessage if none is available - MessageType GetFirstItemType() const volatile; + MessageType GetFirstItemType() const volatile noexcept; #if HAS_LINUX_INTERFACE // Set the first item of the stack. If it's NULL, then the first item will be removed - void SetFirstItem(OutputBuffer *buffer) volatile; + void SetFirstItem(OutputBuffer *buffer) volatile noexcept; #endif // Release the first item at the top of the stack - void ReleaseFirstItem() volatile; + void ReleaseFirstItem() volatile noexcept; // Apply a timeout to the first item at the top of the stack - bool ApplyTimeout(uint32_t ticks) volatile; + bool ApplyTimeout(uint32_t ticks) volatile noexcept; // Returns the last item from the stack or NULL if none is available - OutputBuffer *GetLastItem() const volatile; + OutputBuffer *GetLastItem() const volatile noexcept; // Returns the type of the last item from the stack or NoDestinationMessage if none is available - MessageType GetLastItemType() const volatile; + MessageType GetLastItemType() const volatile noexcept; // Get the total length of all queued buffers - size_t DataLength() const volatile; + size_t DataLength() const volatile noexcept; // Append another OutputStack to this instance. If no more space is available, // all OutputBuffers that can't be added are automatically released - void Append(volatile OutputStack& stack) volatile; + void Append(volatile OutputStack& stack) volatile noexcept; // Increase the number of references for each OutputBuffer on the stack - void IncreaseReferences(size_t num) volatile; + void IncreaseReferences(size_t num) volatile noexcept; // Release all buffers and clean up - void ReleaseAll() volatile; + void ReleaseAll() volatile noexcept; private: size_t count; diff --git a/src/Tools/Filament.cpp b/src/Tools/Filament.cpp index 5e2e8ff4..e6321847 100644 --- a/src/Tools/Filament.cpp +++ b/src/Tools/Filament.cpp @@ -19,7 +19,7 @@ const char * const Filament::FilamentAssignmentFileComment = "RepRapFirmware fil Filament *Filament::filamentList = nullptr; -Filament::Filament(int extr) : extruder(extr) +Filament::Filament(int extr) noexcept : extruder(extr) { strcpy(name, ""); @@ -27,19 +27,19 @@ Filament::Filament(int extr) : extruder(extr) filamentList = this; } -void Filament::Load(const char *filamentName) +void Filament::Load(const char *filamentName) noexcept { SafeStrncpy(name, filamentName, ARRAY_SIZE(name)); Filament::SaveAssignments(); } -void Filament::Unload() +void Filament::Unload() noexcept { strcpy(name, ""); Filament::SaveAssignments(); } -void Filament::LoadAssignment() +void Filament::LoadAssignment() noexcept { #if HAS_MASS_STORAGE FileStore *file = reprap.GetPlatform().OpenSysFile(FilamentAssignmentFile, OpenMode::read); @@ -78,7 +78,7 @@ void Filament::LoadAssignment() #endif } -/*static*/ void Filament::SaveAssignments() +/*static*/ void Filament::SaveAssignments() noexcept { #if HAS_MASS_STORAGE FileStore * const file = reprap.GetPlatform().OpenSysFile(FilamentAssignmentFile, OpenMode::write); @@ -118,7 +118,7 @@ void Filament::LoadAssignment() #endif } -/*static*/ bool Filament::IsInUse(const char *filamentName) +/*static*/ bool Filament::IsInUse(const char *filamentName) noexcept { for (Filament *f = filamentList; f != nullptr; f = f->next) { @@ -130,7 +130,7 @@ void Filament::LoadAssignment() return false; } -/*static*/ Filament *Filament::GetFilamentByExtruder(const int drive) +/*static*/ Filament *Filament::GetFilamentByExtruder(const int drive) noexcept { for (Filament *f = filamentList; f != nullptr; f = f->next) { diff --git a/src/Tools/Filament.h b/src/Tools/Filament.h index 58ebd1a7..282b8161 100644 --- a/src/Tools/Filament.h +++ b/src/Tools/Filament.h @@ -16,23 +16,23 @@ const size_t FilamentNameLength = 32; class Filament { public: - Filament(int extr); + Filament(int extr) noexcept; - int GetExtruder() const { return extruder; } // Returns the assigned extruder drive - const char *GetName() const { return name; } // Returns the name of the currently loaded filament + int GetExtruder() const noexcept { return extruder; } // Returns the assigned extruder drive + const char *GetName() const noexcept { return name; } // Returns the name of the currently loaded filament // TODO: Add support for filament counters, tool restrictions etc. // These should be stored in a dedicate file per filament directory like /filaments//filament.json - bool IsLoaded() const { return (name[0] != 0); } // Returns true if a valid filament is assigned to this instance - void Load(const char *filamentName); // Loads filament parameters from the SD card - void Unload(); // Unloads the current filament + bool IsLoaded() const noexcept { return (name[0] != 0); } // Returns true if a valid filament is assigned to this instance + void Load(const char *filamentName) noexcept; // Loads filament parameters from the SD card + void Unload() noexcept; // Unloads the current filament - void LoadAssignment(); // Read the assigned material for the given extruder from the SD card + void LoadAssignment() noexcept; // Read the assigned material for the given extruder from the SD card - static void SaveAssignments(); // Rewrite the CSV file containing the extruder <-> filament assignments - static bool IsInUse(const char *filamentName); // Check if this material is already assigned to an extruder - static Filament *GetFilamentByExtruder(const int extruder); // Retrieve the Filament instance assigned to the given extruder drive + static void SaveAssignments() noexcept; // Rewrite the CSV file containing the extruder <-> filament assignments + static bool IsInUse(const char *filamentName) noexcept; // Check if this material is already assigned to an extruder + static Filament *GetFilamentByExtruder(const int extruder) noexcept; // Retrieve the Filament instance assigned to the given extruder drive private: static const char * const FilamentAssignmentFile; // In which file the extruder <-> filament assignments are stored diff --git a/src/Tools/Spindle.cpp b/src/Tools/Spindle.cpp index ae20b2bd..4ecb3027 100644 --- a/src/Tools/Spindle.cpp +++ b/src/Tools/Spindle.cpp @@ -8,20 +8,20 @@ #include "Spindle.h" // Allocate the pins returning true if successful -bool Spindle::AllocatePins(GCodeBuffer& gb, const StringRef& reply) +bool Spindle::AllocatePins(GCodeBuffer& gb, const StringRef& reply) noexcept { IoPort * const ports[] = { &spindleForwardPort, &spindleReversePort }; const PinAccess access[] = { PinAccess::pwm, PinAccess::pwm }; return IoPort::AssignPorts(gb, reply, PinUsedBy::spindle, 2, ports, access); } -void Spindle::SetFrequency(PwmFrequency freq) +void Spindle::SetFrequency(PwmFrequency freq) noexcept { spindleForwardPort.SetFrequency(freq); spindleReversePort.SetFrequency(freq); } -void Spindle::SetRpm(float rpm) +void Spindle::SetRpm(float rpm) noexcept { const float pwm = abs(rpm / maxRpm); if (rpm >= 0.0) @@ -37,7 +37,7 @@ void Spindle::SetRpm(float rpm) currentRpm = configuredRpm = rpm; } -void Spindle::TurnOff() +void Spindle::TurnOff() noexcept { spindleReversePort.WriteAnalog(0.0); spindleForwardPort.WriteAnalog(0.0); diff --git a/src/Tools/Spindle.h b/src/Tools/Spindle.h index 3662876c..51c0bad3 100644 --- a/src/Tools/Spindle.h +++ b/src/Tools/Spindle.h @@ -19,22 +19,22 @@ private: int toolNumber; public: - Spindle() : currentRpm(0.0), configuredRpm(0.0), maxRpm(DefaultMaxSpindleRpm), toolNumber(-1) { } + Spindle() noexcept : currentRpm(0.0), configuredRpm(0.0), maxRpm(DefaultMaxSpindleRpm), toolNumber(-1) { } - bool AllocatePins(GCodeBuffer& gb, const StringRef& reply); // Allocate the pins returning true if successful + bool AllocatePins(GCodeBuffer& gb, const StringRef& reply) noexcept; // Allocate the pins returning true if successful - void SetFrequency(PwmFrequency freq); + void SetFrequency(PwmFrequency freq) noexcept; - int GetToolNumber() const { return toolNumber; } - void SetToolNumber(int tool) { toolNumber = tool; } + int GetToolNumber() const noexcept { return toolNumber; } + void SetToolNumber(int tool) noexcept { toolNumber = tool; } - void SetMaxRpm(float max) { maxRpm = max; } + void SetMaxRpm(float max) noexcept { maxRpm = max; } - float GetCurrentRpm() const { return currentRpm; } - float GetRpm() const { return configuredRpm; } - void SetRpm(float rpm); + float GetCurrentRpm() const noexcept { return currentRpm; } + float GetRpm() const noexcept { return configuredRpm; } + void SetRpm(float rpm) noexcept; - void TurnOff(); + void TurnOff() noexcept; }; #endif diff --git a/src/Tools/Tool.cpp b/src/Tools/Tool.cpp index 324755fd..51ba9ac1 100644 --- a/src/Tools/Tool.cpp +++ b/src/Tools/Tool.cpp @@ -34,7 +34,7 @@ Tool * Tool::freelist = nullptr; // Create a new tool and return a pointer to it. If an error occurs, put an error message in 'reply' and return nullptr. -/*static*/ Tool *Tool::Create(unsigned int toolNumber, const char *name, int32_t d[], size_t dCount, int32_t h[], size_t hCount, AxesBitmap xMap, AxesBitmap yMap, FansBitmap fanMap, int filamentDrive, const StringRef& reply) +/*static*/ Tool *Tool::Create(unsigned int toolNumber, const char *name, int32_t d[], size_t dCount, int32_t h[], size_t hCount, AxesBitmap xMap, AxesBitmap yMap, FansBitmap fanMap, int filamentDrive, const StringRef& reply) noexcept { const size_t numExtruders = reprap.GetGCodes().GetNumExtruders(); if (dCount > ARRAY_SIZE(Tool::drives)) @@ -144,7 +144,7 @@ Tool * Tool::freelist = nullptr; return t; } -/*static*/ void Tool::Delete(Tool *t) +/*static*/ void Tool::Delete(Tool *t) noexcept { if (t != nullptr) { @@ -158,22 +158,22 @@ Tool * Tool::freelist = nullptr; } } -/*static*/ AxesBitmap Tool::GetXAxes(const Tool *tool) +/*static*/ AxesBitmap Tool::GetXAxes(const Tool *tool) noexcept { return (tool == nullptr) ? DefaultXAxisMapping : tool->xMapping; } -/*static*/ AxesBitmap Tool::GetYAxes(const Tool *tool) +/*static*/ AxesBitmap Tool::GetYAxes(const Tool *tool) noexcept { return (tool == nullptr) ? DefaultYAxisMapping : tool->yMapping; } -/*static*/ float Tool::GetOffset(const Tool *tool, size_t axis) +/*static*/ float Tool::GetOffset(const Tool *tool, size_t axis) noexcept { return (tool == nullptr) ? 0.0 : tool->offset[axis]; } -void Tool::Print(const StringRef& reply) const +void Tool::Print(const StringRef& reply) const noexcept { reply.printf("Tool %u - ", myNumber); if (name != nullptr) @@ -249,7 +249,7 @@ void Tool::Print(const StringRef& reply) const // There is a temperature fault on a heater, so disable all tools using that heater. // This function must be called for the first entry in the linked list. -void Tool::FlagTemperatureFault(int8_t heater) +void Tool::FlagTemperatureFault(int8_t heater) noexcept { Tool* n = this; while (n != nullptr) @@ -259,7 +259,7 @@ void Tool::FlagTemperatureFault(int8_t heater) } } -void Tool::ClearTemperatureFault(int8_t heater) +void Tool::ClearTemperatureFault(int8_t heater) noexcept { Tool* n = this; while (n != nullptr) @@ -269,7 +269,7 @@ void Tool::ClearTemperatureFault(int8_t heater) } } -void Tool::SetTemperatureFault(int8_t dudHeater) +void Tool::SetTemperatureFault(int8_t dudHeater) noexcept { for (size_t heater = 0; heater < heaterCount; heater++) { @@ -281,7 +281,7 @@ void Tool::SetTemperatureFault(int8_t dudHeater) } } -void Tool::ResetTemperatureFault(int8_t wasDudHeater) +void Tool::ResetTemperatureFault(int8_t wasDudHeater) noexcept { for (size_t heater = 0; heater < heaterCount; heater++) { @@ -293,7 +293,7 @@ void Tool::ResetTemperatureFault(int8_t wasDudHeater) } } -bool Tool::AllHeatersAtHighTemperature(bool forExtrusion) const +bool Tool::AllHeatersAtHighTemperature(bool forExtrusion) const noexcept { for (size_t heater = 0; heater < heaterCount; heater++) { @@ -306,7 +306,7 @@ bool Tool::AllHeatersAtHighTemperature(bool forExtrusion) const return true; } -void Tool::Activate() +void Tool::Activate() noexcept { for (size_t heater = 0; heater < heaterCount; heater++) { @@ -318,7 +318,7 @@ void Tool::Activate() state = ToolState::active; } -void Tool::Standby() +void Tool::Standby() noexcept { const Tool * const currentTool = reprap.GetCurrentTool(); for (size_t heater = 0; heater < heaterCount; heater++) @@ -334,7 +334,7 @@ void Tool::Standby() } // May be called from ISR -bool Tool::ToolCanDrive(bool extrude) +bool Tool::ToolCanDrive(bool extrude) noexcept { if (!heaterFault && AllHeatersAtHighTemperature(extrude)) { @@ -346,7 +346,7 @@ bool Tool::ToolCanDrive(bool extrude) } // Update the number of active drives and extruders in use to reflect what this tool uses -void Tool::UpdateExtruderAndHeaterCount(uint16_t &numExtruders, uint16_t &numHeaters) const +void Tool::UpdateExtruderAndHeaterCount(uint16_t &numExtruders, uint16_t &numHeaters) const noexcept { for (size_t drive = 0; drive < driveCount; drive++) { @@ -365,14 +365,14 @@ void Tool::UpdateExtruderAndHeaterCount(uint16_t &numExtruders, uint16_t &numHea } } -bool Tool::DisplayColdExtrudeWarning() +bool Tool::DisplayColdExtrudeWarning() noexcept { bool result = displayColdExtrudeWarning; displayColdExtrudeWarning = false; return result; } -void Tool::DefineMix(const float m[]) +void Tool::DefineMix(const float m[]) noexcept { for(size_t drive = 0; drive < driveCount; drive++) { @@ -383,7 +383,7 @@ void Tool::DefineMix(const float m[]) #if HAS_MASS_STORAGE // Write the tool's settings to file returning true if successful. The settings written leave the tool selected unless it is off. -bool Tool::WriteSettings(FileStore *f) const +bool Tool::WriteSettings(FileStore *f) const noexcept { String buf; bool ok = true; @@ -419,7 +419,7 @@ bool Tool::WriteSettings(FileStore *f) const #endif -void Tool::SetOffset(size_t axis, float offs, bool byProbing) +void Tool::SetOffset(size_t axis, float offs, bool byProbing) noexcept { offset[axis] = offs; if (byProbing) @@ -428,17 +428,17 @@ void Tool::SetOffset(size_t axis, float offs, bool byProbing) } } -float Tool::GetToolHeaterActiveTemperature(size_t heaterNumber) const +float Tool::GetToolHeaterActiveTemperature(size_t heaterNumber) const noexcept { return (heaterNumber < heaterCount) ? activeTemperatures[heaterNumber] : 0.0; } -float Tool::GetToolHeaterStandbyTemperature(size_t heaterNumber) const +float Tool::GetToolHeaterStandbyTemperature(size_t heaterNumber) const noexcept { return (heaterNumber < heaterCount) ? standbyTemperatures[heaterNumber] : 0.0; } -void Tool::SetToolHeaterActiveTemperature(size_t heaterNumber, float temp) +void Tool::SetToolHeaterActiveTemperature(size_t heaterNumber, float temp) noexcept { if (heaterNumber < heaterCount) { @@ -468,7 +468,7 @@ void Tool::SetToolHeaterActiveTemperature(size_t heaterNumber, float temp) } } -void Tool::SetToolHeaterStandbyTemperature(size_t heaterNumber, float temp) +void Tool::SetToolHeaterStandbyTemperature(size_t heaterNumber, float temp) noexcept { if (heaterNumber < heaterCount) { @@ -499,7 +499,7 @@ void Tool::SetToolHeaterStandbyTemperature(size_t heaterNumber, float temp) } } -void Tool::IterateExtruders(std::function f) const +void Tool::IterateExtruders(std::function f) const noexcept { for (size_t i = 0; i < driveCount; ++i) { @@ -507,7 +507,7 @@ void Tool::IterateExtruders(std::function f) const } } -void Tool::IterateHeaters(std::function f) const +void Tool::IterateHeaters(std::function f) const noexcept { for (size_t i = 0; i < heaterCount; ++i) { @@ -516,7 +516,7 @@ void Tool::IterateHeaters(std::function f) const } // Return true if this tool uses the specified heater -bool Tool::UsesHeater(int8_t heater) const +bool Tool::UsesHeater(int8_t heater) const noexcept { for (size_t i = 0; i < heaterCount; ++i) { diff --git a/src/Tools/Tool.h b/src/Tools/Tool.h index f8e37e75..814326d0 100644 --- a/src/Tools/Tool.h +++ b/src/Tools/Tool.h @@ -47,65 +47,65 @@ class Tool { public: - static Tool *Create(unsigned int toolNumber, const char *name, int32_t d[], size_t dCount, int32_t h[], size_t hCount, AxesBitmap xMap, AxesBitmap yMap, FansBitmap fanMap, int filamentDrive, const StringRef& reply); - static void Delete(Tool *t); - static AxesBitmap GetXAxes(const Tool *tool); - static AxesBitmap GetYAxes(const Tool *tool); - static float GetOffset(const Tool *tool, size_t axis) pre(axis < MaxAxes); - - float GetOffset(size_t axis) const pre(axis < MaxAxes); - void SetOffset(size_t axis, float offs, bool byProbing) pre(axis < MaxAxes); - AxesBitmap GetAxisOffsetsProbed() const { return axisOffsetsProbed; } - size_t DriveCount() const; - int Drive(size_t driveNumber) const; - bool ToolCanDrive(bool extrude); - size_t HeaterCount() const; - int Heater(size_t heaterNumber) const; - const char *GetName() const; - int Number() const; - void DefineMix(const float m[]); - const float* GetMix() const; - void Print(const StringRef& reply) const; - AxesBitmap GetXAxisMap() const { return xMapping; } - AxesBitmap GetYAxisMap() const { return yMapping; } - FansBitmap GetFanMapping() const { return fanMapping; } - Filament *GetFilament() const { return filament; } - Tool *Next() const { return next; } - ToolState GetState() const { return state; } + static Tool *Create(unsigned int toolNumber, const char *name, int32_t d[], size_t dCount, int32_t h[], size_t hCount, AxesBitmap xMap, AxesBitmap yMap, FansBitmap fanMap, int filamentDrive, const StringRef& reply) noexcept; + static void Delete(Tool *t) noexcept; + static AxesBitmap GetXAxes(const Tool *tool) noexcept; + static AxesBitmap GetYAxes(const Tool *tool) noexcept; + static float GetOffset(const Tool *tool, size_t axis) noexcept pre(axis < MaxAxes); + + float GetOffset(size_t axis) const noexcept pre(axis < MaxAxes); + void SetOffset(size_t axis, float offs, bool byProbing) noexcept pre(axis < MaxAxes); + AxesBitmap GetAxisOffsetsProbed() const noexcept { return axisOffsetsProbed; } + size_t DriveCount() const noexcept; + int Drive(size_t driveNumber) const noexcept; + bool ToolCanDrive(bool extrude) noexcept; + size_t HeaterCount() const noexcept; + int Heater(size_t heaterNumber) const noexcept; + const char *GetName() const noexcept; + int Number() const noexcept; + void DefineMix(const float m[]) noexcept; + const float* GetMix() const noexcept; + void Print(const StringRef& reply) const noexcept; + AxesBitmap GetXAxisMap() const noexcept { return xMapping; } + AxesBitmap GetYAxisMap() const noexcept { return yMapping; } + FansBitmap GetFanMapping() const noexcept { return fanMapping; } + Filament *GetFilament() const noexcept { return filament; } + Tool *Next() const noexcept { return next; } + ToolState GetState() const noexcept { return state; } #if HAS_MASS_STORAGE - bool WriteSettings(FileStore *f) const; // write the tool's settings to file + bool WriteSettings(FileStore *f) const noexcept; // write the tool's settings to file #endif - float GetToolHeaterActiveTemperature(size_t heaterNumber) const; - float GetToolHeaterStandbyTemperature(size_t heaterNumber) const; - void SetToolHeaterActiveTemperature(size_t heaterNumber, float temp); - void SetToolHeaterStandbyTemperature(size_t heaterNumber, float temp); + float GetToolHeaterActiveTemperature(size_t heaterNumber) const noexcept; + float GetToolHeaterStandbyTemperature(size_t heaterNumber) const noexcept; + void SetToolHeaterActiveTemperature(size_t heaterNumber, float temp) noexcept; + void SetToolHeaterStandbyTemperature(size_t heaterNumber, float temp) noexcept; - bool HasTemperatureFault() const { return heaterFault; } + bool HasTemperatureFault() const noexcept { return heaterFault; } - void IterateExtruders(std::function f) const; - void IterateHeaters(std::function f) const; + void IterateExtruders(std::function f) const noexcept; + void IterateHeaters(std::function f) const noexcept; friend class RepRap; protected: - void Activate(); - void Standby(); - void FlagTemperatureFault(int8_t dudHeater); - void ClearTemperatureFault(int8_t wasDudHeater); - void UpdateExtruderAndHeaterCount(uint16_t &extruders, uint16_t &heaters) const; - bool DisplayColdExtrudeWarning(); + void Activate() noexcept; + void Standby() noexcept; + void FlagTemperatureFault(int8_t dudHeater) noexcept; + void ClearTemperatureFault(int8_t wasDudHeater) noexcept; + void UpdateExtruderAndHeaterCount(uint16_t &extruders, uint16_t &heaters) const noexcept; + bool DisplayColdExtrudeWarning() noexcept; private: static Tool *freelist; - Tool() : next(nullptr), filament(nullptr), name(nullptr) { } + Tool() noexcept : next(nullptr), filament(nullptr), name(nullptr) { } - void SetTemperatureFault(int8_t dudHeater); - void ResetTemperatureFault(int8_t wasDudHeater); - bool AllHeatersAtHighTemperature(bool forExtrusion) const; - bool UsesHeater(int8_t heater) const; + void SetTemperatureFault(int8_t dudHeater) noexcept; + void ResetTemperatureFault(int8_t wasDudHeater) noexcept; + bool AllHeatersAtHighTemperature(bool forExtrusion) const noexcept; + bool UsesHeater(int8_t heater) const noexcept; Tool* next; Filament *filament; @@ -128,42 +128,42 @@ private: volatile bool displayColdExtrudeWarning; }; -inline int Tool::Drive(size_t driveNumber) const +inline int Tool::Drive(size_t driveNumber) const noexcept { return drives[driveNumber]; } -inline size_t Tool::HeaterCount() const +inline size_t Tool::HeaterCount() const noexcept { return heaterCount; } -inline int Tool::Heater(size_t heaterNumber) const +inline int Tool::Heater(size_t heaterNumber) const noexcept { return heaters[heaterNumber]; } -inline const char *Tool::GetName() const +inline const char *Tool::GetName() const noexcept { return (name == nullptr) ? "" : name; } -inline int Tool::Number() const +inline int Tool::Number() const noexcept { return myNumber; } -inline const float* Tool::GetMix() const +inline const float* Tool::GetMix() const noexcept { return mix; } -inline size_t Tool::DriveCount() const +inline size_t Tool::DriveCount() const noexcept { return driveCount; } -inline float Tool::GetOffset(size_t axis) const +inline float Tool::GetOffset(size_t axis) const noexcept { return offset[axis]; } -- cgit v1.2.3