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

Commit dc9a019

Browse files
committed
Final (?) changes to 3.0RC1
Removed M574 S0 option Fix truncation of M574 report Unconfigured fans report fanPercent -1 instead of -100
1 parent 8ab811c commit dc9a019

File tree

11 files changed

+56
-73
lines changed

11 files changed

+56
-73
lines changed

src/Endstops/Endstop.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ inline void EndstopOrZProbe::UpdateStalledDrivers(uint32_t driverMask, bool isSt
5656
class Endstop : public EndstopOrZProbe
5757
{
5858
public:
59-
virtual EndStopInputType GetEndstopType() const = 0;
59+
virtual EndStopType GetEndstopType() const = 0;
6060
virtual bool Prime(const Kinematics& kin, const AxisDriversConfig& axisDrivers) = 0;
6161
virtual void AppendDetails(const StringRef& str) = 0;
6262

src/Endstops/EndstopDefs.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ enum class EndStopPosition : unsigned int
5353
};
5454

5555
// Type of an endstop input - values must tally with the M574 command S parameter
56-
enum class EndStopInputType : unsigned int
56+
enum class EndStopType : unsigned int
5757
{
58-
activeLow = 0,
59-
activeHigh = 1,
58+
unused_wasActiveLow = 0,
59+
inputPin = 1,
6060
zProbeAsEndstop = 2,
6161
motorStallAny = 3,
6262
motorStallIndividual = 4,

src/Endstops/EndstopsManager.cpp

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
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
357369
bool 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

362374
EndStopHit EndstopsManager::Stopped(size_t axis) const

src/Endstops/EndstopsManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class EndstopsManager
4444
EndstopHitDetails CheckEndstops(bool goingSlow);
4545

4646
// Configure the endstops in response to M574
47-
GCodeResult HandleM574(GCodeBuffer& gb, const StringRef& reply);
47+
GCodeResult HandleM574(GCodeBuffer& gb, const StringRef& reply, OutputBuffer*& outbuf);
4848

4949
EndStopPosition GetEndStopPosition(size_t axis) const pre(axis < MaxAxes);
5050
bool HomingZWithProbe() const;

src/Endstops/StallDetectionEndstop.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class StallDetectionEndstop final : public Endstop
2020
StallDetectionEndstop(uint8_t axis, EndStopPosition pos, bool p_individualMotors); // for creating axis endstops
2121
StallDetectionEndstop(); // for creating the single extruders endstop
2222

23-
EndStopInputType GetEndstopType() const override { return (individualMotors) ? EndStopInputType::motorStallIndividual : EndStopInputType::motorStallAny; }
23+
EndStopType GetEndstopType() const override { return (individualMotors) ? EndStopType::motorStallIndividual : EndStopType::motorStallAny; }
2424
EndStopHit Stopped() const override;
2525
bool Prime(const Kinematics& kin, const AxisDriversConfig& axisDrivers) override;
2626
EndstopHitDetails CheckTriggered(bool goingSlow) override;

src/Endstops/SwitchEndstop.cpp

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void SwitchEndstop::ReleasePorts()
5353
}
5454
}
5555

56-
GCodeResult SwitchEndstop::Configure(GCodeBuffer& gb, const StringRef& reply, EndStopInputType inputType)
56+
GCodeResult SwitchEndstop::Configure(GCodeBuffer& gb, const StringRef& reply)
5757
{
5858
String<StringLength50> portNames;
5959
if (!gb.GetReducedString(portNames.GetRef()))
@@ -62,17 +62,13 @@ GCodeResult SwitchEndstop::Configure(GCodeBuffer& gb, const StringRef& reply, En
6262
return GCodeResult::error;
6363
}
6464

65-
return Configure(portNames.c_str(), reply, inputType);
65+
return Configure(portNames.c_str(), reply);
6666
}
6767

68-
GCodeResult SwitchEndstop::Configure(const char *pinNames, const StringRef& reply, EndStopInputType inputType)
68+
GCodeResult SwitchEndstop::Configure(const char *pinNames, const StringRef& reply)
6969
{
7070
ReleasePorts();
7171

72-
#if SUPPORT_CAN_EXPANSION
73-
activeLow = (inputType == EndStopInputType::activeLow);
74-
#endif
75-
7672
// Parse the string into individual port names
7773
size_t index = 0;
7874
while (numPortsUsed < MaxDriversPerAxis)
@@ -108,7 +104,6 @@ GCodeResult SwitchEndstop::Configure(const char *pinNames, const StringRef& repl
108104
ReleasePorts();
109105
return GCodeResult::error;
110106
}
111-
ports[numPortsUsed].SetInvert(inputType == EndStopInputType::activeLow);
112107
}
113108

114109
++numPortsUsed;
@@ -121,27 +116,9 @@ GCodeResult SwitchEndstop::Configure(const char *pinNames, const StringRef& repl
121116
return GCodeResult::ok;
122117
}
123118

124-
void SwitchEndstop::Reconfigure(EndStopPosition pos, EndStopInputType inputType)
125-
{
126-
SetAtHighEnd(pos == EndStopPosition::highEndStop);
127-
128-
#if SUPPORT_CAN_EXPANSION
129-
activeLow = (inputType == EndStopInputType::activeLow);
130-
#endif
131-
132-
for (IoPort& pp : ports)
133-
{
134-
pp.SetInvert(inputType == EndStopInputType::activeLow);
135-
}
136-
}
137-
138-
EndStopInputType SwitchEndstop::GetEndstopType() const
119+
EndStopType SwitchEndstop::GetEndstopType() const
139120
{
140-
#if SUPPORT_CAN_EXPANSION
141-
return (activeLow)? EndStopInputType::activeLow : EndStopInputType::activeHigh;
142-
#else
143-
return (ports[0].GetInvert()) ? EndStopInputType::activeLow : EndStopInputType::activeHigh;
144-
#endif
121+
return EndStopType::inputPin;
145122
}
146123

147124
// Test whether we are at or near the stop
@@ -258,13 +235,7 @@ bool SwitchEndstop::Acknowledge(EndstopHitDetails what)
258235

259236
void SwitchEndstop::AppendDetails(const StringRef& str)
260237
{
261-
str.catf("%s on pin(s)",
262-
#if SUPPORT_CAN_EXPANSION
263-
(activeLow)
264-
#else
265-
(ports[0].GetInvert())
266-
#endif
267-
? "active low switch" : "active high switch");
238+
str.catf((numPortsUsed == 1) ? "switch connected to pin" : "switches connected to pins");
268239

269240
for (size_t i = 0; i < numPortsUsed; ++i)
270241
{
@@ -282,7 +253,7 @@ void SwitchEndstop::AppendDetails(const StringRef& str)
282253
{
283254
reply.cat('\n');
284255
reprap.GetPlatform().Message(ErrorMessage, reply.c_str());
285-
str.catf("%u.???", boardNumbers[i]);
256+
str.catf("%u.unknown", boardNumbers[i]);
286257
}
287258
}
288259
else

src/Endstops/SwitchEndstop.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class SwitchEndstop : public Endstop
2222

2323
SwitchEndstop(uint8_t axis, EndStopPosition pos);
2424

25-
EndStopInputType GetEndstopType() const override;
25+
EndStopType GetEndstopType() const override;
2626
EndStopHit Stopped() const override;
2727
bool Prime(const Kinematics& kin, const AxisDriversConfig& axisDrivers) override;
2828
EndstopHitDetails CheckTriggered(bool goingSlow) override;
@@ -34,9 +34,8 @@ class SwitchEndstop : public Endstop
3434
void HandleRemoteInputChange(CanAddress src, uint8_t handleMinor, bool state) override;
3535
#endif
3636

37-
GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply, EndStopInputType inputType);
38-
GCodeResult Configure(const char *pinNames, const StringRef& reply, EndStopInputType inputType);
39-
void Reconfigure(EndStopPosition pos, EndStopInputType inputType);
37+
GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply);
38+
GCodeResult Configure(const char *pinNames, const StringRef& reply);
4039

4140
private:
4241
typedef uint16_t PortsBitmap;
@@ -46,7 +45,7 @@ class SwitchEndstop : public Endstop
4645
inline bool IsTriggered(size_t index) const
4746
{
4847
#if SUPPORT_CAN_EXPANSION
49-
return (boardNumbers[index] == CanId::MasterAddress) ? ports[index].Read() : states[index] != activeLow;
48+
return (boardNumbers[index] == CanId::MasterAddress) ? ports[index].Read() : states[index];
5049
#else
5150
return ports[index].Read();
5251
#endif
@@ -60,7 +59,6 @@ class SwitchEndstop : public Endstop
6059
#if SUPPORT_CAN_EXPANSION
6160
CanAddress boardNumbers[MaxDriversPerAxis];
6261
bool states[MaxDriversPerAxis];
63-
bool activeLow;
6462
#endif
6563
size_t numPortsUsed;
6664
PortsBitmap portsLeftToTrigger;

src/Endstops/ZProbeEndstop.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ZProbeEndstop final : public Endstop
1818

1919
ZProbeEndstop(uint8_t axis, EndStopPosition pos);
2020

21-
EndStopInputType GetEndstopType() const override { return EndStopInputType::zProbeAsEndstop; }
21+
EndStopType GetEndstopType() const override { return EndStopType::zProbeAsEndstop; }
2222
EndStopHit Stopped() const override;
2323
bool Prime(const Kinematics& kin, const AxisDriversConfig& axisDrivers) override;
2424
EndstopHitDetails CheckTriggered(bool goingSlow) override;

src/GCodes/GCodes2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3454,7 +3454,7 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply)
34543454
{
34553455
return false;
34563456
}
3457-
result = platform.GetEndstops().HandleM574(gb, reply);
3457+
result = platform.GetEndstops().HandleM574(gb, reply, outBuf);
34583458
break;
34593459

34603460
case 575: // Set communications parameters

src/RepRap.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,8 @@ OutputBuffer *RepRap::GetStatusResponse(uint8_t type, ResponseSource source) noe
941941
ch = '[';
942942
for (size_t i = 0; i <= highestFan; i++)
943943
{
944-
response->catf("%c%d", ch, (int)lrintf(fansManager->GetFanValue(i) * 100.0));
944+
const float fanValue = fansManager->GetFanValue(i);
945+
response->catf("%c%d", ch, (fanValue < 0.0) ? -1 : (int)lrintf(fanValue * 100.0));
945946
ch = ',';
946947
}
947948
response->cat((ch == '[') ? "[]" : "]");
@@ -1734,7 +1735,8 @@ OutputBuffer *RepRap::GetLegacyStatusResponse(uint8_t type, int seq) noexcept
17341735
response->catf(",\"fanPercent\":[%.1f", (double)(gCodes->GetMappedFanSpeed() * 100.0));
17351736
for (size_t i = 0; i < MaxFans; ++i)
17361737
{
1737-
response->catf(",%.1f", (double)(fansManager->GetFanValue(i) * 100.0));
1738+
const float fanValue = fansManager->GetFanValue(i);
1739+
response->catf(",%d", (fanValue < 0.0) ? -1 : (int)lrintf(fanValue * 100.0));
17381740
}
17391741
response->cat(']');
17401742

0 commit comments

Comments
 (0)