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

FilamentMonitor.h « FilamentMonitors « src - github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cbd5b6dc170fa351cc4122c483bcebf7ff7c6587 (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
/*
 * FilamentSensor.h
 *
 *  Created on: 20 Jul 2017
 *      Author: David
 */

#ifndef SRC_FILAMENTSENSORS_FILAMENTMONITOR_H_
#define SRC_FILAMENTSENSORS_FILAMENTMONITOR_H_

#include "RepRapFirmware.h"
#include "Hardware/IoPorts.h"
#include "MessageType.h"
#include "GCodes/GCodeResult.h"
#include "RTOSIface/RTOSIface.h"

enum class FilamentSensorStatus : uint8_t
{
	ok,
	noFilament,
	tooLittleMovement,
	tooMuchMovement,
	sensorError
};

class FilamentMonitor
{
public:
	// Configure this sensor, returning true if error and setting 'seen' if we processed any configuration parameters
	virtual bool Configure(GCodeBuffer& gb, const StringRef& reply, bool& seen) = 0;

	// Call the following at intervals to check the status. This is only called when extrusion is in progress or imminent.
	// 'filamentConsumed' is the net amount of extrusion since the last call to this function.
	virtual FilamentSensorStatus Check(bool isPrinting, bool fromIsr, uint32_t isrMillis, float filamentConsumed) = 0;

	// Clear the measurement state - called when we are not printing a file. Return the present/not present status if available.
	virtual FilamentSensorStatus Clear() = 0;

	// Print diagnostic info for this sensor
	virtual void Diagnostics(MessageType mtype, unsigned int extruder) = 0;

	// ISR for when the pin state changes. It should return true if the ISR wants the commanded extrusion to be fetched.
	virtual bool Interrupt() = 0;

	// Call this to disable the interrupt before deleting a filament monitor
	virtual void Disable();

	// Override the virtual destructor if your derived class allocates any dynamic memory
	virtual ~FilamentMonitor();

	// Return the type of this sensor
	unsigned int GetType() const { return type; }

	// Static initialisation
	static void InitStatic();

	// Return an error message corresponding to a status code
	static const char *GetErrorMessage(FilamentSensorStatus f);

	// Poll the filament sensors
	static void Spin();

	// Handle M591
	static GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply, unsigned int extruder)
	pre(extruder < MaxExtruders);

	// Send diagnostics info
	static void Diagnostics(MessageType mtype);

protected:
	FilamentMonitor(unsigned int extruder, unsigned int t) : extruderNumber(extruder), type(t) { }

	bool ConfigurePin(GCodeBuffer& gb, const StringRef& reply, InterruptMode interruptMode, bool& seen);

	const IoPort& GetPort() const { return port; }
	bool HaveIsrStepsCommanded() const { return haveIsrStepsCommanded; }

private:
	// Create a filament sensor returning null if not a valid sensor type
	static FilamentMonitor *Create(unsigned int extruder, unsigned int type);

	static void InterruptEntry(CallbackParameter param);

	static Mutex filamentSensorsMutex;
	static FilamentMonitor *filamentSensors[MaxExtruders];

	int32_t isrExtruderStepsCommanded;
	uint32_t isrMillis;
	unsigned int extruderNumber;
	unsigned int type;
	IoPort port;
	bool isrWasPrinting;
	bool haveIsrStepsCommanded;
};

#endif /* SRC_FILAMENTSENSORS_FILAMENTMONITOR_H_ */