diff options
author | David Crocker <dcrocker@eschertech.com> | 2020-01-05 16:33:42 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2020-01-05 16:33:42 +0300 |
commit | 4f1c0947b1a0680679d8e8468f3e2e47be2bfc44 (patch) | |
tree | 7d1133120bc31d32e2b2282e81ce6ad09faf77cd /src/Endstops | |
parent | 5bd28a1aea25e83e6e1d7a0ca50cd000e7baf1a7 (diff) |
Various
Fixed M917
Improved handling of G31 temperature compensation parameters
Added conditional expressions
Diffstat (limited to 'src/Endstops')
-rw-r--r-- | src/Endstops/ZProbe.cpp | 58 |
1 files changed, 42 insertions, 16 deletions
diff --git a/src/Endstops/ZProbe.cpp b/src/Endstops/ZProbe.cpp index 7f223c30..63b22930 100644 --- a/src/Endstops/ZProbe.cpp +++ b/src/Endstops/ZProbe.cpp @@ -173,17 +173,8 @@ GCodeResult ZProbe::HandleG31(GCodeBuffer& gb, const StringRef& reply) { GCodeResult err = GCodeResult::ok; bool seen = false; - const char* axisLetters = reprap.GetGCodes().GetAxisLetters(); - - gb.TryGetFValue(axisLetters[X_AXIS], xOffset, seen); - gb.TryGetFValue(axisLetters[Y_AXIS], yOffset, seen); - gb.TryGetFValue(axisLetters[Z_AXIS], triggerHeight, seen); - if (gb.Seen('P')) - { - seen = true; - adcValue = gb.GetIValue(); - } + // Do the temperature coefficient first because it may return notFinished if (gb.Seen('H')) { seen = true; @@ -193,16 +184,51 @@ GCodeResult ZProbe::HandleG31(GCodeBuffer& gb, const StringRef& reply) if (gb.Seen('C')) { seen = true; + temperatureCoefficient = gb.GetFValue(); + calibTemperature = DefaultZProbeTemperature; + TemperatureError terr; - float currentTemperature = reprap.GetHeat().GetSensorTemperature(sensor, terr); - if (terr != TemperatureError::success) + const float currentTemperature = reprap.GetHeat().GetSensorTemperature(sensor, terr); + if (terr == TemperatureError::unknownSensor) { - reply.copy("Cannot set a temperature coefficient without a valid heater number"); + reply.copy("Cannot set a temperature coefficient without a valid sensor number"); + temperatureCoefficient = 0.0; err = GCodeResult::error; - currentTemperature = DefaultZProbeTemperature; } - temperatureCoefficient = gb.GetFValue(); - calibTemperature = (gb.Seen('S')) ? gb.GetFValue() : currentTemperature; + else if (gb.Seen('S')) + { + calibTemperature = gb.GetFValue(); + } + else if (terr == TemperatureError::success) + { + calibTemperature = currentTemperature; + } + else if (!gb.IsTimerRunning()) // the sensor may have only just been configured, so give it 500ms to produce a reading + { + gb.StartTimer(); + return GCodeResult::notFinished; + } + else if (millis() - gb.WhenTimerStarted() < 500) + { + return GCodeResult::notFinished; + } + else + { + gb.StopTimer(); + reply.printf("Sensor %d did not provide a valid temperature reading", sensor); + err = GCodeResult::warning; + } + } + + const char* axisLetters = reprap.GetGCodes().GetAxisLetters(); + + gb.TryGetFValue(axisLetters[X_AXIS], xOffset, seen); + gb.TryGetFValue(axisLetters[Y_AXIS], yOffset, seen); + gb.TryGetFValue(axisLetters[Z_AXIS], triggerHeight, seen); + if (gb.Seen('P')) + { + seen = true; + adcValue = gb.GetIValue(); } if (seen) |