Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Crocker <dcrocker@eschertech.com>2020-12-28 00:55:11 +0300
committerDavid Crocker <dcrocker@eschertech.com>2020-12-28 00:55:11 +0300
commitf6b6be2b85b4cf83a366ffe56de89a1cbdc2a2de (patch)
treecbe987a15a1e8677875d5e683afb124113d7c12c /src/Heating
parentda82dde770eeabb2f1adceb108d333f7c4102369 (diff)
Support remote configuration of PT100 and thermocouple sensors
Diffstat (limited to 'src/Heating')
-rw-r--r--src/Heating/Sensors/RtdSensor31865.cpp62
-rw-r--r--src/Heating/Sensors/RtdSensor31865.h7
-rw-r--r--src/Heating/Sensors/SpiTemperatureSensor.cpp11
-rw-r--r--src/Heating/Sensors/SpiTemperatureSensor.h6
-rw-r--r--src/Heating/Sensors/TemperatureSensor.cpp2
-rw-r--r--src/Heating/Sensors/TemperatureSensor.h2
-rw-r--r--src/Heating/Sensors/Thermistor.cpp2
-rw-r--r--src/Heating/Sensors/Thermistor.h2
-rw-r--r--src/Heating/Sensors/ThermocoupleSensor31855.cpp23
-rw-r--r--src/Heating/Sensors/ThermocoupleSensor31855.h8
-rw-r--r--src/Heating/Sensors/ThermocoupleSensor31856.cpp55
-rw-r--r--src/Heating/Sensors/ThermocoupleSensor31856.h6
12 files changed, 179 insertions, 7 deletions
diff --git a/src/Heating/Sensors/RtdSensor31865.cpp b/src/Heating/Sensors/RtdSensor31865.cpp
index 87e43361..6b8a1760 100644
--- a/src/Heating/Sensors/RtdSensor31865.cpp
+++ b/src/Heating/Sensors/RtdSensor31865.cpp
@@ -10,6 +10,10 @@
#include "Platform.h"
#include "GCodes/GCodeBuffer/GCodeBuffer.h"
+#if SUPPORT_REMOTE_COMMANDS
+# include <CanMessageGenericParser.h>
+#endif
+
const uint32_t MAX31865_Frequency = 4000000; // maximum for MAX31865 is 5MHz
// SPI modes:
@@ -81,6 +85,61 @@ GCodeResult RtdSensor31865::Configure(GCodeBuffer& gb, const StringRef& reply, b
rref = (uint16_t)gb.GetUIValue();
}
+ return FinishConfiguring(changed, reply);
+}
+
+#if SUPPORT_REMOTE_COMMANDS
+
+GCodeResult RtdSensor31865::Configure(const CanMessageGenericParser& parser, const StringRef& reply) noexcept
+{
+ bool seen = false;
+ if (!ConfigurePort(parser, reply, seen))
+ {
+ return GCodeResult::error;
+ }
+
+ uint8_t paramF;
+ if (parser.GetUintParam('F', paramF))
+ {
+ seen = true;
+ if (paramF == 60)
+ {
+ cr0 &= ~0x01; // set 60Hz rejection
+ }
+ else
+ {
+ cr0 |= 0x01; // default to 50Hz rejection
+ }
+ }
+
+ uint8_t paramW;
+ if (parser.GetUintParam('W', paramW))
+ {
+ seen = true;
+ if (paramW == 3)
+ {
+ cr0 |= 0x10; // 3 wire configuration
+ }
+ else
+ {
+ cr0 &= ~0x10; // 2 or 4 wire configuration
+ }
+ }
+
+ float paramR;
+ if (parser.GetFloatParam('R', paramR))
+ {
+ seen = true;
+ rref = (uint16_t)paramR;
+ }
+
+ return FinishConfiguring(seen, reply);
+}
+
+#endif
+
+GCodeResult RtdSensor31865::FinishConfiguring(bool changed, const StringRef& reply) noexcept
+{
if (changed)
{
// Initialise the sensor
@@ -103,9 +162,8 @@ GCodeResult RtdSensor31865::Configure(GCodeBuffer& gb, const StringRef& reply, b
if (rslt != TemperatureError::success)
{
- reprap.GetPlatform().MessageF(ErrorMessage, "Failed to initialise RTD: %s\n", TemperatureErrorString(rslt));
+ reply.printf("Failed to initialise RTD: %s\n", TemperatureErrorString(rslt));
}
-
}
else
{
diff --git a/src/Heating/Sensors/RtdSensor31865.h b/src/Heating/Sensors/RtdSensor31865.h
index 70ad7897..18c242cd 100644
--- a/src/Heating/Sensors/RtdSensor31865.h
+++ b/src/Heating/Sensors/RtdSensor31865.h
@@ -14,7 +14,13 @@ class RtdSensor31865 : public SpiTemperatureSensor
{
public:
RtdSensor31865(unsigned int sensorNum) noexcept;
+
GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply, bool& changed) override THROWS(GCodeException);
+
+#if SUPPORT_REMOTE_COMMANDS
+ GCodeResult Configure(const CanMessageGenericParser& parser, const StringRef& reply) noexcept override; // configure the sensor from M308 parameters
+#endif
+
void Poll() noexcept override;
const char *GetShortSensorType() const noexcept override { return TypeName; }
@@ -22,6 +28,7 @@ public:
private:
TemperatureError TryInitRtd() const noexcept;
+ GCodeResult FinishConfiguring(bool changed, const StringRef& reply) noexcept;
uint16_t rref; // reference resistor in ohms
uint8_t cr0;
diff --git a/src/Heating/Sensors/SpiTemperatureSensor.cpp b/src/Heating/Sensors/SpiTemperatureSensor.cpp
index 696fdc19..f3395e3e 100644
--- a/src/Heating/Sensors/SpiTemperatureSensor.cpp
+++ b/src/Heating/Sensors/SpiTemperatureSensor.cpp
@@ -26,6 +26,17 @@ bool SpiTemperatureSensor::ConfigurePort(GCodeBuffer& gb, const StringRef& reply
return ret;
}
+#if SUPPORT_REMOTE_COMMANDS
+
+bool SpiTemperatureSensor::ConfigurePort(const CanMessageGenericParser& parser, const StringRef& reply, bool& seen) noexcept
+{
+ const bool ret = SensorWithPort::ConfigurePort(parser, reply, PinAccess::write1, seen);
+ device.SetCsPin(port.GetPin());
+ return ret;
+}
+
+#endif
+
void SpiTemperatureSensor::InitSpi() noexcept
{
lastReadingTime = millis();
diff --git a/src/Heating/Sensors/SpiTemperatureSensor.h b/src/Heating/Sensors/SpiTemperatureSensor.h
index b13aeb90..5f555479 100644
--- a/src/Heating/Sensors/SpiTemperatureSensor.h
+++ b/src/Heating/Sensors/SpiTemperatureSensor.h
@@ -15,7 +15,13 @@ class SpiTemperatureSensor : public SensorWithPort
{
protected:
SpiTemperatureSensor(unsigned int sensorNum, const char *name, SpiMode spiMode, uint32_t clockFrequency) noexcept;
+
bool ConfigurePort(GCodeBuffer& gb, const StringRef& reply, bool& seen);
+
+#if SUPPORT_REMOTE_COMMANDS
+ bool ConfigurePort(const CanMessageGenericParser& parser, const StringRef& reply, bool& seen) noexcept;
+#endif
+
void InitSpi() noexcept;
TemperatureError DoSpiTransaction(const uint8_t dataOut[], size_t nbytes, uint32_t& rslt) const noexcept
pre(nbytes <= 8);
diff --git a/src/Heating/Sensors/TemperatureSensor.cpp b/src/Heating/Sensors/TemperatureSensor.cpp
index aad12922..fee02dd5 100644
--- a/src/Heating/Sensors/TemperatureSensor.cpp
+++ b/src/Heating/Sensors/TemperatureSensor.cpp
@@ -106,7 +106,7 @@ GCodeResult TemperatureSensor::Configure(GCodeBuffer& gb, const StringRef& reply
#if SUPPORT_REMOTE_COMMANDS
// Default implementation of Configure, for sensors that have no configurable parameters
-GCodeResult TemperatureSensor::Configure(const CanMessageGenericParser& parser, const StringRef& reply)
+GCodeResult TemperatureSensor::Configure(const CanMessageGenericParser& parser, const StringRef& reply) noexcept
{
if (!parser.HasParameter('Y'))
{
diff --git a/src/Heating/Sensors/TemperatureSensor.h b/src/Heating/Sensors/TemperatureSensor.h
index f8d71ebc..2c9dcea4 100644
--- a/src/Heating/Sensors/TemperatureSensor.h
+++ b/src/Heating/Sensors/TemperatureSensor.h
@@ -39,7 +39,7 @@ public:
// Configure the sensor from M308 parameters.
// If we find any parameters, process them and return true. If an error occurs while processing them, return error and write an error message to 'reply.
// If we find no relevant parameters, report the current parameters to 'reply' and return ok.
- virtual GCodeResult Configure(const CanMessageGenericParser& parser, const StringRef& reply);
+ virtual GCodeResult Configure(const CanMessageGenericParser& parser, const StringRef& reply) noexcept;
#endif
#if SUPPORT_OBJECT_MODEL
diff --git a/src/Heating/Sensors/Thermistor.cpp b/src/Heating/Sensors/Thermistor.cpp
index 43870c1f..709cee0a 100644
--- a/src/Heating/Sensors/Thermistor.cpp
+++ b/src/Heating/Sensors/Thermistor.cpp
@@ -275,7 +275,7 @@ GCodeResult Thermistor::Configure(GCodeBuffer& gb, const StringRef& reply, bool&
#if SUPPORT_REMOTE_COMMANDS
// Configure the temperature sensor
-GCodeResult Thermistor::Configure(const CanMessageGenericParser& parser, const StringRef& reply)
+GCodeResult Thermistor::Configure(const CanMessageGenericParser& parser, const StringRef& reply) noexcept
{
bool changed = false;
if (!ConfigurePort(parser, reply, PinAccess::readAnalog, changed))
diff --git a/src/Heating/Sensors/Thermistor.h b/src/Heating/Sensors/Thermistor.h
index ce1b0e01..5d55dfdf 100644
--- a/src/Heating/Sensors/Thermistor.h
+++ b/src/Heating/Sensors/Thermistor.h
@@ -26,7 +26,7 @@ public:
GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply, bool& changed) override THROWS(GCodeException); // configure the sensor from M308 parameters
#if SUPPORT_REMOTE_COMMANDS
- GCodeResult Configure(const CanMessageGenericParser& parser, const StringRef& reply) override; // configure the sensor from M308 parameters
+ GCodeResult Configure(const CanMessageGenericParser& parser, const StringRef& reply) noexcept override; // configure the sensor from M308 parameters
#endif
void Poll() noexcept override;
diff --git a/src/Heating/Sensors/ThermocoupleSensor31855.cpp b/src/Heating/Sensors/ThermocoupleSensor31855.cpp
index 8c4fd955..775d1503 100644
--- a/src/Heating/Sensors/ThermocoupleSensor31855.cpp
+++ b/src/Heating/Sensors/ThermocoupleSensor31855.cpp
@@ -50,6 +50,10 @@
#include "Platform.h"
#include "GCodes/GCodeBuffer/GCodeBuffer.h"
+#if SUPPORT_REMOTE_COMMANDS
+# include <CanMessageGenericParser.h>
+#endif
+
const uint32_t MAX31855_Frequency = 4000000; // maximum for MAX31855 is 5MHz
// SPI modes:
@@ -75,7 +79,26 @@ GCodeResult ThermocoupleSensor31855::Configure(GCodeBuffer& gb, const StringRef&
}
TryConfigureSensorName(gb, changed);
+ return FinishConfiguring(changed, reply);
+}
+
+#if SUPPORT_REMOTE_COMMANDS
+
+GCodeResult ThermocoupleSensor31855::Configure(const CanMessageGenericParser& parser, const StringRef& reply) noexcept
+{
+ bool seen = false;
+ if (!ConfigurePort(parser, reply, seen))
+ {
+ return GCodeResult::error;
+ }
+
+ return FinishConfiguring(seen, reply);
+}
+
+#endif
+GCodeResult ThermocoupleSensor31855::FinishConfiguring(bool changed, const StringRef& reply) noexcept
+{
if (changed)
{
// Initialise the sensor
diff --git a/src/Heating/Sensors/ThermocoupleSensor31855.h b/src/Heating/Sensors/ThermocoupleSensor31855.h
index 14609c2d..b5d62444 100644
--- a/src/Heating/Sensors/ThermocoupleSensor31855.h
+++ b/src/Heating/Sensors/ThermocoupleSensor31855.h
@@ -15,10 +15,18 @@ class ThermocoupleSensor31855 : public SpiTemperatureSensor
public:
ThermocoupleSensor31855(unsigned int sensorNum) noexcept;
GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply, bool& changed) override THROWS(GCodeException);
+
+#if SUPPORT_REMOTE_COMMANDS
+ GCodeResult Configure(const CanMessageGenericParser& parser, const StringRef& reply) noexcept override; // configure the sensor from M308 parameters
+#endif
+
void Poll() noexcept override;
const char *GetShortSensorType() const noexcept override { return TypeName; }
static constexpr const char *TypeName = "thermocouplemax31855";
+
+private:
+ GCodeResult FinishConfiguring(bool changed, const StringRef& reply) noexcept;
};
#endif /* SRC_HEATING_THERMOCOUPLESENSOR31855_H_ */
diff --git a/src/Heating/Sensors/ThermocoupleSensor31856.cpp b/src/Heating/Sensors/ThermocoupleSensor31856.cpp
index 87d5f1f9..d21eb066 100644
--- a/src/Heating/Sensors/ThermocoupleSensor31856.cpp
+++ b/src/Heating/Sensors/ThermocoupleSensor31856.cpp
@@ -10,6 +10,10 @@
#include "Platform.h"
#include "GCodes/GCodeBuffer/GCodeBuffer.h"
+#if SUPPORT_REMOTE_COMMANDS
+# include <CanMessageGenericParser.h>
+#endif
+
const uint32_t MAX31856_Frequency = 4000000; // maximum for MAX31865 is 5MHz
static const char * const TypeLetters = "BEJKNRST"; // MAX31856 mapping of AVGSEWL bits to thermocouple types
@@ -95,6 +99,56 @@ GCodeResult ThermocoupleSensor31856::Configure(GCodeBuffer& gb, const StringRef&
}
}
+ return FinishConfiguring(changed, reply);
+}
+
+#if SUPPORT_REMOTE_COMMANDS
+
+GCodeResult ThermocoupleSensor31856::Configure(const CanMessageGenericParser& parser, const StringRef& reply) noexcept
+{
+ bool seen = false;
+ if (!ConfigurePort(parser, reply, seen))
+ {
+ return GCodeResult::error;
+ }
+
+ uint8_t paramF;
+ if (parser.GetUintParam('F', paramF))
+ {
+ seen = true;
+ if (paramF == 60)
+ {
+ cr0 &= ~0x01; // set 60Hz rejection
+ }
+ else
+ {
+ cr0 |= 0x01; // default to 50Hz rejection
+ }
+ }
+
+ char paramK;
+ if (parser.GetCharParam('K', paramK))
+ {
+ seen = true;
+ const char *p;
+ if ((p = strchr(TypeLetters, toupper(paramK))) != nullptr)
+ {
+ thermocoupleType = p - TypeLetters;
+ }
+ else
+ {
+ reply.copy("Bad thermocouple type letter in M305 command");
+ return GCodeResult::error;
+ }
+ }
+
+ return FinishConfiguring(seen, reply);
+}
+
+#endif
+
+GCodeResult ThermocoupleSensor31856::FinishConfiguring(bool changed, const StringRef& reply) noexcept
+{
if (changed)
{
// Initialise the sensor
@@ -119,7 +173,6 @@ GCodeResult ThermocoupleSensor31856::Configure(GCodeBuffer& gb, const StringRef&
{
reprap.GetPlatform().MessageF(ErrorMessage, "Failed to initialise thermocouple: %s\n", TemperatureErrorString(rslt));
}
-
}
else
{
diff --git a/src/Heating/Sensors/ThermocoupleSensor31856.h b/src/Heating/Sensors/ThermocoupleSensor31856.h
index f1c59e5c..5633309c 100644
--- a/src/Heating/Sensors/ThermocoupleSensor31856.h
+++ b/src/Heating/Sensors/ThermocoupleSensor31856.h
@@ -15,6 +15,11 @@ class ThermocoupleSensor31856 : public SpiTemperatureSensor
public:
ThermocoupleSensor31856(unsigned int sensorNum) noexcept;
GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply, bool& changed) override THROWS(GCodeException);
+
+#if SUPPORT_REMOTE_COMMANDS
+ GCodeResult Configure(const CanMessageGenericParser& parser, const StringRef& reply) noexcept override; // configure the sensor from M308 parameters
+#endif
+
void Poll() noexcept override;
const char *GetShortSensorType() const noexcept override { return TypeName; }
@@ -22,6 +27,7 @@ public:
private:
TemperatureError TryInitThermocouple() const noexcept;
+ GCodeResult FinishConfiguring(bool changed, const StringRef& reply) noexcept;
uint8_t cr0;
uint8_t thermocoupleType;