Skip to content
This repository was archived by the owner on Jul 9, 2020. It is now read-only.

Commit 48cd43d

Browse files
committed
3.0beta11 for RPi SD card image (provisional)
Fixed configuration of sensors on RRF3 when no port is given or needed e.g. MCU temperature Fixed heater protection (not tested yet) Fixed tool selection in resurrect.g file
1 parent 1b2f046 commit 48cd43d

File tree

9 files changed

+156
-175
lines changed

9 files changed

+156
-175
lines changed

src/GCodes/GCodes.cpp

Lines changed: 0 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -3316,129 +3316,6 @@ void GCodes::HandleReply(GCodeBuffer& gb, OutputBuffer *reply)
33163316
}
33173317
}
33183318

3319-
// Configure heater protection (M143). Returns true if an error occurred
3320-
GCodeResult GCodes::SetHeaterProtection(GCodeBuffer& gb, const StringRef& reply)
3321-
{
3322-
const int index = (gb.Seen('P'))
3323-
? gb.GetIValue()
3324-
: (gb.Seen('H')) ? gb.GetIValue() : 1; // default to extruder 1 if no heater number provided
3325-
if ((index < 0 || index >= (int)MaxHeaters) && (index < (int)FirstExtraHeaterProtection || index >= (int)(FirstExtraHeaterProtection + NumExtraHeaterProtections)))
3326-
{
3327-
reply.printf("Invalid heater protection item '%d'", index);
3328-
return GCodeResult::error;
3329-
}
3330-
3331-
HeaterProtection &item = reprap.GetHeat().AccessHeaterProtection(index);
3332-
3333-
// Set heater to control
3334-
bool seen = false;
3335-
if (gb.Seen('P') && gb.Seen('H'))
3336-
{
3337-
const int heater = gb.GetIValue();
3338-
if (heater > (int)MaxHeaters) // allow negative values to disable heater protection
3339-
{
3340-
reply.printf("Invalid heater number '%d'", heater);
3341-
return GCodeResult::error;
3342-
}
3343-
3344-
seen = true;
3345-
item.SetHeater(heater);
3346-
}
3347-
3348-
// Set sensor that supervises the heater
3349-
if (gb.Seen('X'))
3350-
{
3351-
item.SetSensorNumber(gb.GetIValue());
3352-
seen = true;
3353-
}
3354-
3355-
// Set trigger action
3356-
if (gb.Seen('A'))
3357-
{
3358-
const int action = gb.GetIValue();
3359-
if (action < 0 || action > (int)MaxHeaterProtectionAction)
3360-
{
3361-
reply.printf("Invalid heater protection action '%d'", action);
3362-
}
3363-
3364-
seen = true;
3365-
item.SetAction(static_cast<HeaterProtectionAction>(action));
3366-
}
3367-
3368-
// Set trigger condition
3369-
if (gb.Seen('C'))
3370-
{
3371-
const int trigger = gb.GetIValue();
3372-
if (trigger < 0 || trigger > (int)MaxHeaterProtectionTrigger)
3373-
{
3374-
reply.printf("Invalid heater protection trigger '%d'", trigger);
3375-
}
3376-
3377-
seen = true;
3378-
item.SetTrigger(static_cast<HeaterProtectionTrigger>(trigger));
3379-
}
3380-
3381-
// Set temperature limit
3382-
if (gb.Seen('S'))
3383-
{
3384-
const float limit = gb.GetFValue();
3385-
if (limit <= BadLowTemperature || limit >= BadErrorTemperature)
3386-
{
3387-
reply.copy("Invalid temperature limit");
3388-
return GCodeResult::error;
3389-
}
3390-
3391-
seen = true;
3392-
item.SetTemperatureLimit(limit);
3393-
}
3394-
3395-
// Report current parameters
3396-
if (!seen)
3397-
{
3398-
if (item.GetHeater() < 0)
3399-
{
3400-
reply.printf("Temperature protection item %d is not configured", index);
3401-
}
3402-
else
3403-
{
3404-
const char *actionString, *triggerString;
3405-
switch (item.GetAction())
3406-
{
3407-
case HeaterProtectionAction::GenerateFault:
3408-
actionString = "generate a heater fault";
3409-
break;
3410-
case HeaterProtectionAction::PermanentSwitchOff:
3411-
actionString = "permanently switch off";
3412-
break;
3413-
case HeaterProtectionAction::TemporarySwitchOff:
3414-
actionString = "temporarily switch off";
3415-
break;
3416-
default:
3417-
actionString = "(undefined)";
3418-
break;
3419-
}
3420-
3421-
switch (item.GetTrigger())
3422-
{
3423-
case HeaterProtectionTrigger::TemperatureExceeded:
3424-
triggerString = "exceeds";
3425-
break;
3426-
case HeaterProtectionTrigger::TemperatureTooLow:
3427-
triggerString = "falls below";
3428-
break;
3429-
default:
3430-
triggerString = "(undefined)";
3431-
break;
3432-
}
3433-
3434-
reply.printf("Temperature protection item %d is configured for heater %d and uses sensor %d to %s if the temperature %s %.1f" DEGREE_SYMBOL "C",
3435-
index, item.GetHeater(), item.GetSensorNumber(), actionString, triggerString, (double)item.GetTemperatureLimit());
3436-
}
3437-
}
3438-
3439-
return GCodeResult::ok;
3440-
}
3441-
34423319
void GCodes::SetToolHeaters(Tool *tool, float temperature, bool both)
34433320
{
34443321
if (tool == nullptr)

src/GCodes/GCodes.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,6 @@ class GCodes INHERIT_OBJECT_MODEL
284284
# endif
285285
#endif
286286

287-
GCodeResult SetHeaterProtection(GCodeBuffer &gb, const StringRef &reply); // Configure heater protection (M143)
288-
289287
GCodeResult ManageTool(GCodeBuffer& gb, const StringRef& reply); // Create a new tool definition
290288
void SetToolHeaters(Tool *tool, float temperature, bool both); // Set all a tool's heaters to the temperature, for M104/M109
291289
bool ToolHeatersAtSetTemperatures(const Tool *tool, bool waitWhenCooling, float tolerance) const;

src/GCodes/GCodes2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1827,7 +1827,7 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply)
18271827
break;
18281828

18291829
case 143: // Configure heater protection
1830-
result = SetHeaterProtection(gb, reply);
1830+
result = reprap.GetHeat().SetHeaterProtection(gb, reply);
18311831
break;
18321832

18331833
case 144: // Set bed to standby, or to active if S1 parameter given

src/Heating/Heat.cpp

Lines changed: 131 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -877,22 +877,12 @@ GCodeResult Heat::ConfigureSensor(GCodeBuffer& gb, const StringRef& reply)
877877
}
878878

879879
#if SUPPORT_CAN_EXPANSION
880-
// Set boardAddress to the board number that the port is on, or NoCanAddress if the port was not given
880+
// Set boardAddress to the board number that the port is on, or MasterAddress if the port was not given
881881
CanAddress boardAddress;
882882
String<StringLength20> portName;
883-
if (gb.Seen('P'))
884-
{
885-
if (!gb.GetReducedString(portName.GetRef()))
886-
{
887-
reply.copy("Missing port name");
888-
return GCodeResult::error;
889-
}
890-
boardAddress = IoPort::RemoveBoardAddress(portName.GetRef());
891-
}
892-
else
893-
{
894-
boardAddress = CanId::NoAddress;
895-
}
883+
boardAddress = (gb.Seen('P') && gb.GetReducedString(portName.GetRef()))
884+
? IoPort::RemoveBoardAddress(portName.GetRef())
885+
: CanId::MasterAddress;
896886
#endif
897887
bool newSensor = gb.Seen('Y');
898888
if (newSensor)
@@ -909,11 +899,6 @@ GCodeResult Heat::ConfigureSensor(GCodeBuffer& gb, const StringRef& reply)
909899
}
910900

911901
#if SUPPORT_CAN_EXPANSION
912-
if (boardAddress == CanId::NoAddress)
913-
{
914-
reply.copy("Missing port name");
915-
return GCodeResult::error;
916-
}
917902
TemperatureSensor * const newSensor = TemperatureSensor::Create(sensorNum, boardAddress, typeName.c_str(), reply);
918903
#else
919904
TemperatureSensor * const newSensor = TemperatureSensor::Create(sensorNum, typeName.c_str(), reply);
@@ -968,31 +953,144 @@ const char *Heat::GetHeaterSensorName(size_t heater) const
968953
return (h.IsNotNull()) ? h->GetSensorName() : nullptr;
969954
}
970955

971-
// Return the protection parameters of the given index
972-
HeaterProtection& Heat::AccessHeaterProtection(size_t index) const
956+
// Configure heater protection (M143). Returns true if an error occurred
957+
GCodeResult Heat::SetHeaterProtection(GCodeBuffer& gb, const StringRef& reply)
973958
{
974-
if (index >= FirstExtraHeaterProtection && index < FirstExtraHeaterProtection + NumExtraHeaterProtections)
959+
WriteLocker lock(heatersLock);
960+
961+
bool seen = false;
962+
int32_t heaterNumber = 1; // default to extruder 1 if no heater number provided
963+
gb.TryGetIValue('H', heaterNumber, seen);
964+
const int index = (gb.Seen('P')) ? gb.GetIValue() : heaterNumber;
965+
966+
if ( index < 0
967+
|| (index >= (int)MaxHeaters && index < (int)FirstExtraHeaterProtection)
968+
|| index >= (int)(FirstExtraHeaterProtection + NumExtraHeaterProtections)
969+
)
970+
{
971+
reply.printf("Invalid heater protection item '%d'", index);
972+
return GCodeResult::error;
973+
}
974+
975+
HeaterProtection &item = (index >= (int)FirstExtraHeaterProtection)
976+
? *heaterProtections[index - FirstExtraHeaterProtection + MaxHeaters]
977+
: *heaterProtections[index];
978+
// Set heater to control
979+
if (seen && heaterNumber != item.GetHeater())
980+
{
981+
const int oldHeaterNumber = item.GetHeater();
982+
item.SetHeater(heaterNumber);
983+
UpdateHeaterProtection(oldHeaterNumber);
984+
UpdateHeaterProtection(heaterNumber);
985+
}
986+
987+
// Set sensor that supervises the heater
988+
if (gb.Seen('X'))
975989
{
976-
return *heaterProtections[index + MaxHeaters - FirstExtraHeaterProtection];
990+
item.SetSensorNumber(gb.GetIValue());
991+
seen = true;
992+
}
993+
994+
// Set trigger action
995+
if (gb.Seen('A'))
996+
{
997+
const int action = gb.GetIValue();
998+
if (action < 0 || action > (int)MaxHeaterProtectionAction)
999+
{
1000+
reply.printf("Invalid heater protection action '%d'", action);
1001+
}
1002+
1003+
seen = true;
1004+
item.SetAction(static_cast<HeaterProtectionAction>(action));
9771005
}
978-
return *heaterProtections[index];
1006+
1007+
// Set trigger condition
1008+
if (gb.Seen('C'))
1009+
{
1010+
const int trigger = gb.GetIValue();
1011+
if (trigger < 0 || trigger > (int)MaxHeaterProtectionTrigger)
1012+
{
1013+
reply.printf("Invalid heater protection trigger '%d'", trigger);
1014+
}
1015+
1016+
seen = true;
1017+
item.SetTrigger(static_cast<HeaterProtectionTrigger>(trigger));
1018+
}
1019+
1020+
// Set temperature limit
1021+
if (gb.Seen('S'))
1022+
{
1023+
const float limit = gb.GetFValue();
1024+
if (limit <= BadLowTemperature || limit >= BadErrorTemperature)
1025+
{
1026+
reply.copy("Invalid temperature limit");
1027+
return GCodeResult::error;
1028+
}
1029+
1030+
seen = true;
1031+
item.SetTemperatureLimit(limit);
1032+
}
1033+
1034+
// Report current parameters
1035+
if (!seen)
1036+
{
1037+
if (item.GetHeater() < 0)
1038+
{
1039+
reply.printf("Temperature protection item %d is not configured", index);
1040+
}
1041+
else
1042+
{
1043+
const char *actionString, *triggerString;
1044+
switch (item.GetAction())
1045+
{
1046+
case HeaterProtectionAction::GenerateFault:
1047+
actionString = "generate a heater fault";
1048+
break;
1049+
case HeaterProtectionAction::PermanentSwitchOff:
1050+
actionString = "permanently switch off";
1051+
break;
1052+
case HeaterProtectionAction::TemporarySwitchOff:
1053+
actionString = "temporarily switch off";
1054+
break;
1055+
default:
1056+
actionString = "(undefined)";
1057+
break;
1058+
}
1059+
1060+
switch (item.GetTrigger())
1061+
{
1062+
case HeaterProtectionTrigger::TemperatureExceeded:
1063+
triggerString = "exceeds";
1064+
break;
1065+
case HeaterProtectionTrigger::TemperatureTooLow:
1066+
triggerString = "falls below";
1067+
break;
1068+
default:
1069+
triggerString = "(undefined)";
1070+
break;
1071+
}
1072+
1073+
reply.printf("Temperature protection item %d is configured for heater %d and uses sensor %d to %s if the temperature %s %.1f" DEGREE_SYMBOL "C",
1074+
index, item.GetHeater(), item.GetSensorNumber(), actionString, triggerString, (double)item.GetTemperatureLimit());
1075+
}
1076+
}
1077+
1078+
return GCodeResult::ok;
9791079
}
9801080

981-
// Updates the PIDs and HeaterProtection items after a heater change
982-
void Heat::UpdateHeaterProtection()
1081+
// Updates the PIDs and HeaterProtection items after a heater change. Caller must already have a write lock on the heaters.
1082+
void Heat::UpdateHeaterProtection(int heaterNumber)
9831083
{
984-
ReadLocker lock(heatersLock);
985-
986-
// Reassign the first mapped heater protection item of each PID where applicable
987-
// and rebuild the linked list of heater protection elements per heater
988-
for (size_t heater : ARRAY_INDICES(heaters))
1084+
auto h = FindHeater(heaterNumber);
1085+
if (h.IsNotNull())
9891086
{
9901087
// Rebuild linked lists
1088+
h->SetHeaterProtection(nullptr);
9911089
HeaterProtection *firstProtectionItem = nullptr;
9921090
HeaterProtection *lastElementInList = nullptr;
9931091
for (HeaterProtection *prot : heaterProtections)
9941092
{
995-
if (prot->GetHeater() == (int)heater)
1093+
if (prot->GetHeater() == heaterNumber)
9961094
{
9971095
if (firstProtectionItem == nullptr)
9981096
{
@@ -1012,11 +1110,7 @@ void Heat::UpdateHeaterProtection()
10121110
}
10131111
}
10141112

1015-
// Update reference to the first item so that we can achieve better performance
1016-
if (heaters[heater] != nullptr)
1017-
{
1018-
heaters[heater]->SetHeaterProtection(firstProtectionItem);
1019-
}
1113+
h->SetHeaterProtection(firstProtectionItem);
10201114
}
10211115
}
10221116

src/Heating/Heat.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ class Heat INHERIT_OBJECT_MODEL
7878
GCodeResult ConfigureSensor(GCodeBuffer& gb, const StringRef& reply); // Create a sensor or change the parameters for an existing sensor
7979
GCodeResult SetPidParameters(unsigned int heater, GCodeBuffer& gb, const StringRef& reply); // Set the P/I/D parameters for a heater
8080

81-
HeaterProtection& AccessHeaterProtection(size_t index) const; // Return the protection parameters of the given index
82-
void UpdateHeaterProtection(); // Updates the PIDs and HeaterProtection items when a heater is remapped
81+
GCodeResult SetHeaterProtection(GCodeBuffer &gb, const StringRef &reply); // Configure heater protection (M143)
82+
void UpdateHeaterProtection(int heaterNumber); // Updates the PIDs and HeaterProtection items when a heater is remapped
8383

8484
void SuspendHeaters(bool sus); // Suspend the heaters to conserve power
8585

src/Heating/HeaterProtection.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ bool HeaterProtection::Check()
6666
void HeaterProtection::SetHeater(int newHeater)
6767
{
6868
heater = newHeater;
69-
reprap.GetHeat().UpdateHeaterProtection();
7069
}
7170

7271
// End

src/Heating/HeaterProtection.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ class HeaterProtection
6262
void SetTrigger(HeaterProtectionTrigger newTrigger); // Set the condition for a temperature event
6363

6464
private:
65-
HeaterProtection *next;
65+
HeaterProtection *next; // link to next HeaterProtection item for the same heater
6666

67-
float limit;
68-
int heater;
69-
int sensorNumber;
70-
HeaterProtectionAction action;
71-
HeaterProtectionTrigger trigger;
67+
float limit; // temperature limit
68+
int heater; // number of the heater we are protecting
69+
int sensorNumber; // the sensor that we use to monitor the heater
70+
HeaterProtectionAction action; // what action we take of we detect a fault
71+
HeaterProtectionTrigger trigger; // what is treated a fault
7272

73-
size_t badTemperatureCount;
73+
size_t badTemperatureCount; // how many consecutive sensor reading faults we have had
7474
};
7575

7676
inline void HeaterProtection::SetSensorNumber(int sn)

0 commit comments

Comments
 (0)