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

PrintMonitor.h « src - github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e4fa7ff63a557e8069e8c58b20cdbadd87dcf04c (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/****************************************************************************************************

RepRapFirmware - PrintMonitor

This class provides methods to obtain print end-time estimations and file information from generated
G-Code files, which may be reported to auxiliary devices and to the web interface using status responses.

-----------------------------------------------------------------------------------------------------

Version 0.1

Created on: Feb 24, 2015

Christian Hammacher

Licence: GPL

****************************************************************************************************/

#ifndef PRINTMONITOR_H
#define PRINTMONITOR_H

#include <RepRapFirmware.h>
#include <GCodes/GCodeResult.h>
#include <GCodes/GCodeFileInfo.h>
#include <ObjectModel/ObjectModel.h>

enum PrintEstimationMethod
{
	filamentBased,
	fileBased,
	slicerBased
};

class PrintMonitor INHERIT_OBJECT_MODEL
{
public:
	PrintMonitor(Platform& p, GCodes& gc) noexcept;
	void Spin() noexcept;
	void Init() noexcept;

	bool IsPrinting() const noexcept;						// Is a file being printed?
	void StartingPrint(const char *filename) noexcept;		// Called to indicate a file will be printed (see M23)
	void StartedPrint() noexcept;							// Called whenever a new live print starts (see M24)
	void StoppedPrint() noexcept;							// Called whenever a file print has stopped
	void SetLayerNumber(uint32_t layerNumber) noexcept;		// Set the current layer number
	void SetLayerZ(float layerZ) noexcept;					// Set the printing height of the new layer
	float FractionOfFilePrinted() const noexcept;			// Return the fraction printed (0..1)

	// Return an estimate in seconds based on a specific estimation method
	float EstimateTimeLeft(PrintEstimationMethod method) const noexcept;

	// Provide some information about the file being printed
	unsigned int GetCurrentLayer() const noexcept;
	float GetCurrentLayerTime() const noexcept;				// Return the number of seconds printing the current layer
	float GetPrintDuration() const noexcept;
	float GetWarmUpDuration() const noexcept;
	float GetPauseDuration() const noexcept;

	const char *GetPrintingFilename() const noexcept { return (isPrinting) ? filenameBeingPrinted.c_str() : nullptr; }
	bool GetPrintingFileInfo(GCodeFileInfo& info) noexcept;
	void SetPrintingFileInfo(const char *filename, GCodeFileInfo& info) noexcept;

	GCodeResult ProcessM73(GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeException);

protected:
	DECLARE_OBJECT_MODEL
	OBJECT_MODEL_ARRAY(filament)

private:
	static constexpr float MinFilamentUsageForEstimation = 0.01;	// Minimum per cent of filament to be printed before the filament-based estimation returns values
	static constexpr uint32_t UpdateIntervalMillis = 200;			// Update interval in milliseconds
	static constexpr uint32_t SnapshotIntervalSeconds = 30;			// Snapshot interval in seconds

	void Reset() noexcept;
	void UpdatePrintingFileInfo() noexcept;

#if SUPPORT_OBJECT_MODEL
	ExpressionValue EstimateTimeLeftAsExpression(PrintEstimationMethod method) const noexcept;
	int32_t GetPrintOrSimulatedDuration() const noexcept;
#endif

	Platform& platform;
	GCodes& gCodes;
	uint32_t lastUpdateTime;

	bool isPrinting;
	bool heatingUp;
	bool paused;

	uint64_t printStartTime;
	uint64_t heatingStartedTime;
	uint64_t warmUpDuration, printDuration;
	uint64_t pauseStartTime, totalPauseTime;
	uint64_t lastSnapshotTime;
	uint64_t lastSnapshotNonPrintingTime;
	uint64_t lastLayerChangeTime;
	uint64_t lastLayerChangeNonPrintingTime;
	uint64_t whenSlicerTimeLeftSet;

	uint32_t lastLayerDuration;

	unsigned int currentLayer;
	float lastSnapshotFileFraction, lastSnapshotFilamentUsed;
	float fileProgressRate, filamentProgressRate;
	float totalFilamentNeeded;
	float slicerTimeLeft;						// time left in seconds as reported by slicer

	unsigned int lastLayerNumberNotified;
	float lastLayerStartHeightNotified;

	static ReadWriteLock printMonitorLock;

	bool printingFileParsed;
	GCodeFileInfo printingFileInfo;
	String<MaxFilenameLength> filenameBeingPrinted;
};

inline bool PrintMonitor::IsPrinting() const noexcept { return isPrinting; }
inline unsigned int PrintMonitor::GetCurrentLayer() const noexcept { return currentLayer; }

#endif /* PRINTMONITOR_H */

// vim: ts=4:sw=4