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

TemperatureSensor.h « Sensors « Heating « src - github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a68a99eab6f53eb8c7d3d4e57090c6bba82c6535 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#ifndef TEMPERATURESENSOR_H
#define TEMPERATURESENSOR_H

#include "RepRapFirmware.h"
#include "Heating/TemperatureError.h"		// for result codes
#include "Hardware/IoPorts.h"
#include "GCodes/GCodeResult.h"

class GCodeBuffer;
struct CanSensorReport;

class TemperatureSensor
{
public:
	TemperatureSensor(unsigned int sensorNum, const char *type);

	// Virtual destructor
	virtual ~TemperatureSensor();

	// Try to get a temperature reading
	virtual TemperatureError GetLatestTemperature(float& t, uint8_t outputNumber = 0);

	// How many additional outputs does this sensor have
	virtual const uint8_t GetNumAdditionalOutputs() const { return 0; }

	// Get the most recent reading without checking for timeout
	float GetStoredReading() const { return lastTemperature; }

	// Configure the sensor from M308 parameters.
	// If we find any parameters, process them, if successful then initialise the sensor and return GCodeResult::ok.
	// If an error occurs while processing the parameters, return GCodeResult::error and write an error message to 'reply.
	// if we find no relevant parameters, report the current parameters to 'reply' and return 'false'.
	virtual GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply);

	// Return the sensor type
	const char *GetSensorType() const { return sensorType; }

	// Return the sensor number
	unsigned int GetSensorNumber() const { return sensorNumber; }

	// Return the code for the most recent error
	TemperatureError GetLastError() const { return lastRealError; }

	// Configure the sensor name, if it is provided
	void TryConfigureSensorName(GCodeBuffer& gb, bool& seen);

	// Set the name - normally called only once
	void SetSensorName(const char *newName);

	// Get the name. Returns nullptr if no name has been assigned.
	const char *GetSensorName() const { return sensorName; }

	// Copy the basic details to the reply buffer
	void CopyBasicDetails(const StringRef& reply) const;

	// Get/set the next sensor in the linked list
	TemperatureSensor *GetNext() const { return next; }
	void SetNext(TemperatureSensor *n) { next = n; }

	// Get the smart drivers channel that this sensor monitors, or -1 if it doesn't
	virtual int GetSmartDriversChannel() const { return -1; }

#if SUPPORT_CAN_EXPANSION
	// Get the expansion board address. Overridden for remote sensors.
	virtual CanAddress GetBoardAddress() const;

	// Update the temperature, if it is a remote sensor. Overridden in class RemoteSensor.
	virtual void UpdateRemoteTemperature(CanAddress src, const CanSensorReport& report);
#endif

	// Factory method
#if SUPPORT_CAN_EXPANSION
	static TemperatureSensor *Create(unsigned int sensorNum, CanAddress boardAddress, const char *typeName, const StringRef& reply);
#else
	static TemperatureSensor *Create(unsigned int sensorNum, const char *typeName, const StringRef& reply);
#endif

	// Try to get a temperature reading
	virtual void Poll() = 0;
	virtual bool PollInTask() { return false; };		// Classes implementing this method need to also call Heat::EnsureSensorsTask() after succesful configuration

protected:
	void SetResult(float t, TemperatureError rslt);
	void SetResult(TemperatureError rslt);

	static TemperatureError GetPT100Temperature(float& t, uint16_t ohmsx100);		// shared function used by two derived classes

private:
	static constexpr uint32_t TemperatureReadingTimeout = 2000;			// any reading older than this number of milliseconds is considered unreliable

	TemperatureSensor *next;
	unsigned int sensorNumber;											// the number of this sensor
	const char * const sensorType;
	const char *sensorName;
	float lastTemperature;
	uint32_t whenLastRead;
	TemperatureError lastResult, lastRealError;
};

#endif // TEMPERATURESENSOR_H