diff options
author | David Crocker <dcrocker@eschertech.com> | 2022-07-01 15:45:12 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2022-07-01 15:45:12 +0300 |
commit | fe0b4766b0c74368f810e79cb7530a74e5b1ff4f (patch) | |
tree | 476e90805e7ac7fb8c82686adc407f08346a9d2b | |
parent | 58fb28175de1f75661aefa114f444cdbabafce34 (diff) |
Allow MAX31865 M308 R parameter to have fractional parts (3.4.2beta1)
-rw-r--r-- | src/Heating/Sensors/RtdSensor31865.cpp | 12 | ||||
-rw-r--r-- | src/Heating/Sensors/RtdSensor31865.h | 2 |
2 files changed, 7 insertions, 7 deletions
diff --git a/src/Heating/Sensors/RtdSensor31865.cpp b/src/Heating/Sensors/RtdSensor31865.cpp index 6f8a4034..81475821 100644 --- a/src/Heating/Sensors/RtdSensor31865.cpp +++ b/src/Heating/Sensors/RtdSensor31865.cpp @@ -40,11 +40,11 @@ const uint32_t MinimumReadInterval = 100; // minimum interval between reads, in const uint8_t DefaultCr0 = 0b11000011; const uint8_t Cr0ReadMask = 0b11011101; // bits 1 and 5 auto clear, so ignore the value read -const uint16_t DefaultRef = 400; +const uint32_t DefaultRef = 400; RtdSensor31865::RtdSensor31865(unsigned int sensorNum) noexcept : SpiTemperatureSensor(sensorNum, "PT100 (MAX31865)", MAX31865_SpiMode, MAX31865_Frequency), - rref(DefaultRef), cr0(DefaultCr0) + rrefTimes100(DefaultRef * 100), cr0(DefaultCr0) { } @@ -85,7 +85,7 @@ GCodeResult RtdSensor31865::Configure(GCodeBuffer& gb, const StringRef& reply, b if (gb.Seen('R')) { changed = true; - rref = (uint16_t)gb.GetUIValue(); + rrefTimes100 = lrintf(gb.GetFValue() * 100); } return FinishConfiguring(changed, reply); @@ -133,7 +133,7 @@ GCodeResult RtdSensor31865::Configure(const CanMessageGenericParser& parser, con if (parser.GetFloatParam('R', paramR)) { seen = true; - rref = (uint16_t)paramR; + rrefTimes100 = lrintf(paramR * 100); } return FinishConfiguring(seen, reply); @@ -172,7 +172,7 @@ GCodeResult RtdSensor31865::FinishConfiguring(bool changed, const StringRef& rep else { CopyBasicDetails(reply); - reply.catf(", %s wires, reject %dHz, reference resistor %u ohms", (cr0 & 0x10) ? "3" : "2/4", (cr0 & 0x01) ? 50 : 60, (unsigned int)rref); + reply.catf(", %s wires, reject %dHz, reference resistor %.2f ohms", (cr0 & 0x10) ? "3" : "2/4", (cr0 & 0x01) ? 50 : 60, (double)((float)rrefTimes100 * 0.01)); } return GCodeResult::ok; } @@ -233,7 +233,7 @@ void RtdSensor31865::Poll() noexcept } else { - const uint16_t ohmsx100 = (uint16_t)((((rawVal >> 1) & 0x7FFF) * rref * 100) >> 15); + const uint16_t ohmsx100 = (uint16_t)((((rawVal >> 1) & 0x7FFF) * rrefTimes100) >> 15); float t; sts = GetPT100Temperature(t, ohmsx100); SetResult(t, sts); diff --git a/src/Heating/Sensors/RtdSensor31865.h b/src/Heating/Sensors/RtdSensor31865.h index ea2cc11e..eefef2c0 100644 --- a/src/Heating/Sensors/RtdSensor31865.h +++ b/src/Heating/Sensors/RtdSensor31865.h @@ -32,7 +32,7 @@ private: TemperatureError TryInitRtd() const noexcept; GCodeResult FinishConfiguring(bool changed, const StringRef& reply) noexcept; - uint16_t rref; // reference resistor in ohms + uint32_t rrefTimes100; // reference resistor in units of 0.01 ohms uint8_t cr0; }; |