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: 373295d5526a15f04581f271ce968efe3192a80c (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
/*
 * FilamentSensor.h
 *
 *  Created on: 20 Jul 2017
 *      Author: David
 */

#ifndef SRC_FILAMENTSENSORS_FILAMENTMONITOR_H_
#define SRC_FILAMENTSENSORS_FILAMENTMONITOR_H_

#include "RepRapFirmware.h"
#include "MessageType.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, 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 full, bool hadNonPrintingMove, 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(bool full) = 0;

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

	// ISR for when the pin state changes
	virtual void Interrupt() = 0;

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

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

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

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

	// Return the filament sensor associated with a particular extruder
	static FilamentMonitor *GetFilamentSensor(unsigned int extruder);

	// Set the filament sensor associated with a particular extruder
	static bool SetFilamentSensorType(unsigned int extruder, int newSensorType);

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

protected:
	FilamentMonitor(int t) : type(t), pin(NoPin) { }

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

	int GetEndstopNumber() const { return endstopNumber; }

	Pin GetPin() const { return pin; }

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

	static void InterruptEntry(CallbackParameter param);

	static FilamentMonitor *filamentSensors[MaxExtruders];

	int type;
	int endstopNumber;
	Pin pin;
};

#endif /* SRC_FILAMENTSENSORS_FILAMENTMONITOR_H_ */