blob: 8f78cbe1af5a73bbb54c61ed066238d8a6edc902 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
/*
* HeaterProtection.cpp
*
* Created on: 16 Nov 2017
* Author: Christian
*/
#include "HeaterProtection.h"
#include "Platform.h"
#include "RepRap.h"
#include "Heat.h"
HeaterProtection::HeaterProtection(size_t index) : 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.
heater = (index >= MaxHeaters) ? -1 : (int8_t)index;
sensorNumber = -1;
}
void HeaterProtection::Init(float tempLimit)
{
next = nullptr;
limit = tempLimit;
action = HeaterProtectionAction::GenerateFault;
trigger = HeaterProtectionTrigger::TemperatureExceeded;
badTemperatureCount = 0;
}
// Check if any action needs to be taken. Returns true if everything is OK
bool HeaterProtection::Check()
{
if (sensorNumber >= 0)
{
TemperatureError err;
const float temperature = reprap.GetHeat().GetSensorTemperature(sensorNumber, err);
if (err != TemperatureError::success)
{
badTemperatureCount++;
if (badTemperatureCount > MaxBadTemperatureCount)
{
reprap.GetPlatform().MessageF(ErrorMessage, "Temperature reading error on sensor %d\n", sensorNumber);
return false;
}
}
else
{
badTemperatureCount = 0;
switch (trigger)
{
case HeaterProtectionTrigger::TemperatureExceeded:
return (temperature <= limit);
case HeaterProtectionTrigger::TemperatureTooLow:
return (temperature >= limit);
}
}
}
return true;
}
void HeaterProtection::SetHeater(int newHeater)
{
heater = newHeater;
}
// End
|