diff options
author | David Crocker <dcrocker@eschertech.com> | 2020-02-16 17:10:43 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2020-02-16 17:10:43 +0300 |
commit | 315f4f47613fe09e613b6c639a7ddc37af3516d2 (patch) | |
tree | 45133ce063bf3bb2c40f522471f0074038168149 /src/Heating/HeaterMonitor.h | |
parent | 9885ed7cc55cb19fde1be14c8adfd11dfa7f86cf (diff) |
Replaced HeaterProtection instances by HeaterMonitors
Diffstat (limited to 'src/Heating/HeaterMonitor.h')
-rw-r--r-- | src/Heating/HeaterMonitor.h | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/src/Heating/HeaterMonitor.h b/src/Heating/HeaterMonitor.h new file mode 100644 index 00000000..42bdac38 --- /dev/null +++ b/src/Heating/HeaterMonitor.h @@ -0,0 +1,81 @@ +/* + * HeaterMonitor.h + * + * Created on: 16 Nov 2017 + * Author: Christian + */ + +#ifndef HEATERMONITOR_H +#define HEATERMONITOR_H + +#include <RepRapFirmware.h> +#include <General/FreelistManager.h> + +// Condition of a heater monitor event +enum class HeaterMonitorTrigger : int8_t +{ + Disabled = -1, + TemperatureExceeded = 0, + TemperatureTooLow +}; + +const HeaterMonitorTrigger MaxHeaterMonitorTrigger = HeaterMonitorTrigger::TemperatureTooLow; + +// The action to trigger when the target condition is met +enum class HeaterMonitorAction : uint8_t +{ + GenerateFault = 0, + PermanentSwitchOff, + TemporarySwitchOff +}; + +const HeaterMonitorAction MaxHeaterMonitorAction = HeaterMonitorAction::TemporarySwitchOff; + +// A note about using this class. Its size is currently 8 bytes, and will be 12 bytes of object model support is added. +// - If we allocate them statically within the heater object, then assuming 3 per heater we need 24 bytes, or 36 bytes with OM support. +// - If we allocate them dynamically then there is an overhead of at least 8 bytes per object. All heaters have at least 2. +// So each heater needs 12 bytes for the pointers plus 32 bytes (without OM support) or 40 bytes (with OM support). Total 44 or 52 bytes. +// For unconfigured heaters, the cost is 24 or 36 bytes each using static allocation, or 4 bytes each using dynamic allocation. +// Summary: +// - Static allocation saves 20 bytes (no OM) or 16 bytes (with OM) per configured heater, if the 3rd heater monitor is not used (and more if it is used) +// - Dynamic allocation saves 20 bytes (no OM) or 32 bytes (with OM) per unconfigured heater +// For now we use static allocation, i.e. we embed the heater monitor in the heater object. +class HeaterMonitor +{ +public: + HeaterMonitor() noexcept; + + void Set(int sn, float lim, HeaterMonitorAction act, HeaterMonitorTrigger trig) noexcept; + void Disable() noexcept; + bool Check() noexcept; // Check if any action needs to be taken + + int GetSensorNumber() const noexcept { return sensorNumber; } // Get the supervisory sensor number + float GetTemperatureLimit() const noexcept { return limit; } // Get the temperature limit + HeaterMonitorAction GetAction() const noexcept { return action; } // Get the action to trigger when a temperature event occurs + HeaterMonitorTrigger GetTrigger() const noexcept { return trigger; } // Get the condition for a temperature event + + void Report(unsigned int heater, unsigned int index, const StringRef& reply) const noexcept; // Append a report of this monitor to the string + +private: + float limit; // temperature limit + int8_t sensorNumber; // the sensor that we use to monitor the heater + HeaterMonitorAction action; // what action we take of we detect a fault + HeaterMonitorTrigger trigger; // what is treated a fault + uint8_t badTemperatureCount; // how many consecutive sensor reading faults we have had +}; + +inline void HeaterMonitor::Set(int sn, float lim, HeaterMonitorAction act, HeaterMonitorTrigger trig) noexcept +{ + sensorNumber = sn; + limit = lim; + action = act; + trigger = trig; + badTemperatureCount = 0; +} + +inline void HeaterMonitor::Disable() noexcept +{ + trigger = HeaterMonitorTrigger::Disabled; +} + +#endif |