2020#include " GCodes/GCodeBuffer/GCodeBuffer.h"
2121#include " GCodes/GCodes.h"
2222#include " Movement/Move.h"
23+ #include < OutputMemory.h>
2324
2425#if SUPPORT_CAN_EXPANSION
2526# include " CanMessageBuffer.h"
@@ -49,7 +50,7 @@ void EndstopsManager::Init()
4950 for (size_t axis = 0 ; axis < ARRAY_SIZE (DefaultEndstopPinNames); ++axis)
5051 {
5152 SwitchEndstop * const sw = new SwitchEndstop (axis, EndStopPosition::lowEndStop);
52- sw->Configure (DefaultEndstopPinNames[axis], dummy.GetRef (), EndStopInputType::activeHigh );
53+ sw->Configure (DefaultEndstopPinNames[axis], dummy.GetRef ());
5354 axisEndstops[axis] = sw;
5455 }
5556#endif
@@ -206,7 +207,7 @@ EndstopHitDetails EndstopsManager::CheckEndstops(bool goingSlow)
206207}
207208
208209// Configure the endstops in response to M574
209- GCodeResult EndstopsManager::HandleM574 (GCodeBuffer& gb, const StringRef& reply)
210+ GCodeResult EndstopsManager::HandleM574 (GCodeBuffer& gb, const StringRef& reply, OutputBuffer*& outbuf )
210211{
211212 // First count how many axes we are configuring, and lock movement if necessary
212213 unsigned int axesSeen = 0 ;
@@ -229,22 +230,29 @@ GCodeResult EndstopsManager::HandleM574(GCodeBuffer& gb, const StringRef& reply)
229230
230231 if (axesSeen == 0 )
231232 {
232- reply.copy (" Endstop configuration" );
233- char sep = ' :' ;
233+ // Report current configuration
234+ // The response can get very long, so allocate an output buffer
235+ if (outbuf == nullptr && !OutputBuffer::Allocate (outbuf))
236+ {
237+ return GCodeResult::notFinished;
238+ }
239+
240+ outbuf->copy (" Endstop configuration:" );
234241 ReadLocker lock (endstopsLock);
235242
236243 for (size_t axis = 0 ; axis < reprap.GetGCodes ().GetTotalAxes (); ++axis)
237244 {
238- reply.catf (" %c %c: " , sep, reprap.GetGCodes ().GetAxisLetters ()[axis]);
239- sep = ' ,' ;
245+ outbuf->catf (" \n %c: " , reprap.GetGCodes ().GetAxisLetters ()[axis]);
240246 if (axisEndstops[axis] == nullptr )
241247 {
242- reply. cat (" none" );
248+ outbuf-> cat (" none" );
243249 }
244250 else
245251 {
246- reply.cat ((axisEndstops[axis]->GetAtHighEnd ()) ? " high end " : " low end " );
252+ outbuf->cat ((axisEndstops[axis]->GetAtHighEnd ()) ? " high end " : " low end " );
253+ reply.Clear ();
247254 axisEndstops[axis]->AppendDetails (reply);
255+ outbuf->cat (reply.c_str ());
248256 }
249257 }
250258 return GCodeResult::ok;
@@ -258,17 +266,22 @@ GCodeResult EndstopsManager::HandleM574(GCodeBuffer& gb, const StringRef& reply)
258266
259267 activeEndstops = nullptr ; // we may be about to remove endstops, so make sure they are not in the active list
260268
261- const EndStopInputType inputType = (gb.Seen (' S' )) ? (EndStopInputType )gb.GetUIValue () : EndStopInputType::activeHigh ;
262- if (inputType >= EndStopInputType ::numInputTypes)
269+ const EndStopType inputType = (gb.Seen (' S' )) ? (EndStopType )gb.GetUIValue () : EndStopType::inputPin ;
270+ if (inputType >= EndStopType ::numInputTypes)
263271 {
264272 reply.copy (" invalid input type" );
265273 return GCodeResult::error;
266274 }
275+ if (inputType == EndStopType::unused_wasActiveLow)
276+ {
277+ reply.copy (" endstop type 0 is no longer supported. Use type 1 and invert the input pin instead." );
278+ return GCodeResult::error;
279+ }
267280
268281 if (gb.Seen (' P' )) // we use P not C, because C may be an axis
269282 {
270283 // Setting the port number(s), so there must be just one axis and we must be using switch-type endstops
271- if (axesSeen > 1 || ( inputType != EndStopInputType::activeLow && inputType != EndStopInputType::activeHigh) )
284+ if (axesSeen > 1 || inputType != EndStopType::inputPin )
272285 {
273286 reply.copy (" Invalid use of P parameter" );
274287 return GCodeResult::error;
@@ -279,7 +292,7 @@ GCodeResult EndstopsManager::HandleM574(GCodeBuffer& gb, const StringRef& reply)
279292 delete axisEndstops[lastAxisSeen];
280293 axisEndstops[lastAxisSeen] = nullptr ;
281294 SwitchEndstop * const sw = new SwitchEndstop (lastAxisSeen, lastPosSeen);
282- const GCodeResult rslt = sw->Configure (gb, reply, inputType );
295+ const GCodeResult rslt = sw->Configure (gb, reply);
283296 axisEndstops[lastAxisSeen] = sw;
284297 return rslt;
285298 }
@@ -302,28 +315,27 @@ GCodeResult EndstopsManager::HandleM574(GCodeBuffer& gb, const StringRef& reply)
302315 {
303316 switch (inputType)
304317 {
305- case EndStopInputType ::motorStallAny:
318+ case EndStopType ::motorStallAny:
306319 // Asking for stall detection endstop, so we can delete any existing endstop(s) and create new ones
307320 delete axisEndstops[axis];
308321 axisEndstops[axis] = new StallDetectionEndstop (axis, pos, false );
309322 break ;
310323
311- case EndStopInputType ::motorStallIndividual:
324+ case EndStopType ::motorStallIndividual:
312325 // Asking for stall detection endstop, so we can delete any existing endstop(s) and create new ones
313326 delete axisEndstops[axis];
314327 axisEndstops[axis] = new StallDetectionEndstop (axis, pos, true );
315328 break ;
316329
317- case EndStopInputType ::zProbeAsEndstop:
330+ case EndStopType ::zProbeAsEndstop:
318331 // Asking for a ZProbe or stall detection endstop, so we can delete any existing endstop(s) and create new ones
319332 delete axisEndstops[axis];
320333 axisEndstops[axis] = new ZProbeEndstop (axis, pos);
321334 break ;
322335
323- case EndStopInputType::activeHigh:
324- case EndStopInputType::activeLow:
336+ case EndStopType::inputPin:
325337 if ( axisEndstops[axis] == nullptr
326- || ( axisEndstops[axis]->GetEndstopType () != EndStopInputType::activeHigh && axisEndstops[axis]-> GetEndstopType () != EndStopInputType::activeLow)
338+ || axisEndstops[axis]->GetEndstopType () != EndStopType::inputPin
327339 )
328340 {
329341 // Asking for a switch endstop but we don't already have one, so we don't know what pin number(s) it should use
@@ -332,7 +344,7 @@ GCodeResult EndstopsManager::HandleM574(GCodeBuffer& gb, const StringRef& reply)
332344 }
333345 else
334346 {
335- ((SwitchEndstop *)axisEndstops[axis])-> Reconfigure (pos, inputType);
347+ // Nothing to do because there are no parameters we can change except the port number
336348 }
337349 break ;
338350
@@ -356,7 +368,7 @@ EndStopPosition EndstopsManager::GetEndStopPosition(size_t axis) const pre(axis
356368// Return true if we are using a bed probe to home Z
357369bool EndstopsManager::HomingZWithProbe () const
358370{
359- return axisEndstops[Z_AXIS] == nullptr || axisEndstops[Z_AXIS]->GetEndstopType () == EndStopInputType ::zProbeAsEndstop;
371+ return axisEndstops[Z_AXIS] == nullptr || axisEndstops[Z_AXIS]->GetEndstopType () == EndStopType ::zProbeAsEndstop;
360372}
361373
362374EndStopHit EndstopsManager::Stopped (size_t axis) const
0 commit comments