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

RepRap.h « src - github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a2f7675571b37226949ce1c9ce5acac430137af1 (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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/****************************************************************************************************

RepRapFirmware - Reprap

RepRap is a simple class that acts as a container for an instance of all the others.

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

Version 0.1

21 May 2013

Adrian Bowyer
RepRap Professional Ltd
http://reprappro.com

Licence: GPL

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

#ifndef REPRAP_H
#define REPRAP_H

#include "RepRapFirmware.h"
#include "MessageType.h"
#include "RTOSIface.h"

enum class ResponseSource
{
	HTTP,
	AUX,
	Generic
};

class RepRap
{
public:
	RepRap();
	void EmergencyStop();
	void Init();
	void Spin();
	void Exit();
	void Diagnostics(MessageType mtype);
	void DeferredDiagnostics(MessageType mtype) { diagnosticsDestination = mtype; }
	void Timing(MessageType mtype);

	bool Debug(Module module) const;
	void SetDebug(Module m, bool enable);
	void SetDebug(bool enable);
	void PrintDebug();
	Module GetSpinningModule() const;

	const char *GetName() const;
	void SetName(const char* nm);
	bool NoPasswordSet() const;
	bool CheckPassword(const char* pw) const;
	void SetPassword(const char* pw);

	void AddTool(Tool* t);
	void DeleteTool(Tool* t);
	void SelectTool(int toolNumber, bool simulating);
	void StandbyTool(int toolNumber, bool simulating);
	Tool* GetCurrentTool() const;
	int GetCurrentToolNumber() const;
	Tool* GetTool(int toolNumber) const;
	Tool* GetCurrentOrDefaultTool() const;
	const Tool* GetFirstTool() const { return toolList; }				// Return the lowest-numbered tool
	uint32_t GetCurrentXAxes() const;									// Get the current axes used as X axes
	uint32_t GetCurrentYAxes() const;									// Get the current axes used as Y axes
	void SetToolVariables(int toolNumber, const float* standbyTemperatures, const float* activeTemperatures);
	bool IsHeaterAssignedToTool(int8_t heater) const;
	unsigned int GetNumberOfContiguousTools() const;

	unsigned int GetProhibitedExtruderMovements(unsigned int extrusions, unsigned int retractions);
	void PrintTool(int toolNumber, const StringRef& reply) const;
	void FlagTemperatureFault(int8_t dudHeater);
	void ClearTemperatureFault(int8_t wasDudHeater);

	Platform& GetPlatform() const;
	Move& GetMove() const;
	Heat& GetHeat() const;
	GCodes& GetGCodes() const;
	Network& GetNetwork() const;
	Roland& GetRoland() const;
	Scanner& GetScanner() const;
	PrintMonitor& GetPrintMonitor() const;

#if SUPPORT_IOBITS
 	PortControl& GetPortControl() const;
#endif
#if SUPPORT_12864_LCD
 	Display& GetDisplay() const;
#endif

	void Tick();
	bool SpinTimeoutImminent() const;
	bool IsStopped() const;

	uint16_t GetExtrudersInUse() const;
	uint16_t GetToolHeatersInUse() const;

	OutputBuffer *GetStatusResponse(uint8_t type, ResponseSource source);
	OutputBuffer *GetConfigResponse();
	OutputBuffer *GetLegacyStatusResponse(uint8_t type, int seq);
	OutputBuffer *GetFilesResponse(const char* dir, bool flagsDirs);
	OutputBuffer *GetFilelistResponse(const char* dir);
	bool GetFileInfoResponse(const char *filename, OutputBuffer *&response, bool quitEarly);

	void Beep(unsigned int freq, unsigned int ms);
	void SetMessage(const char *msg);
	void SetAlert(const char *msg, const char *title, int mode, float timeout, AxesBitmap controls);
	void ClearAlert();

	bool WriteToolSettings(FileStore *f) const;				// save some information for the resume file
	bool WriteToolParameters(FileStore *f) const;			// save some information in config-override.g

	void ReportInternalError(const char *file, const char *func, int line) const;	// Report an internal error

	static uint32_t DoDivide(uint32_t a, uint32_t b);		// helper function for diagnostic tests

private:
	static void EncodeString(StringRef& response, const char* src, size_t spaceToLeave, bool allowControlChars = false, char prefix = 0);

	char GetStatusCharacter() const;

	static constexpr uint32_t MaxTicksInSpinState = 20000;	// timeout before we reset the processor
	static constexpr uint32_t HighTicksInSpinState = 16000;	// how long before we warn that timeout is approaching

	Platform* platform;
	Network* network;
	Move* move;
	Heat* heat;
	GCodes* gCodes;
	Roland* roland;
	Scanner* scanner;
 	PrintMonitor* printMonitor;

#if SUPPORT_IOBITS
 	PortControl *portControl;
#endif

#if SUPPORT_12864_LCD
 	Display *display;
#endif

 	Mutex toolListMutex, messageBoxMutex;
	Tool* toolList;								// the tool list is sorted in order of increasing tool number
	Tool* currentTool;
	uint32_t lastWarningMillis;					// When we last sent a warning message for things that can happen very often

	uint16_t activeExtruders;
	uint16_t activeToolHeaters;

	uint16_t ticksInSpinState;
	Module spinningModule;
	uint32_t fastLoop, slowLoop;
	uint32_t lastTime;

	uint32_t debug;
	bool stopped;
	bool active;
	bool resetting;
	bool processingConfig;

	String<PASSWORD_LENGTH> password;
	String<MACHINE_NAME_LENGTH> myName;

	unsigned int beepFrequency, beepDuration;
	char message[MaxMessageLength + 1];

	// Message box data
	bool displayMessageBox;
	String<MaxMessageLength> boxMessage, boxTitle;
	int boxMode;
	uint32_t boxSeq;
	uint32_t boxTimer, boxTimeout;
	AxesBitmap boxControls;

	// Deferred diagnostics
	MessageType diagnosticsDestination;
};

inline Platform& RepRap::GetPlatform() const { return *platform; }
inline Move& RepRap::GetMove() const { return *move; }
inline Heat& RepRap::GetHeat() const { return *heat; }
inline GCodes& RepRap::GetGCodes() const { return *gCodes; }
inline Network& RepRap::GetNetwork() const { return *network; }
inline Roland& RepRap::GetRoland() const { return *roland; }
inline Scanner& RepRap::GetScanner() const { return *scanner; }
inline PrintMonitor& RepRap::GetPrintMonitor() const { return *printMonitor; }

#if SUPPORT_IOBITS
inline PortControl& RepRap::GetPortControl() const { return *portControl; }
#endif

#if SUPPORT_12864_LCD
inline Display& RepRap::GetDisplay() const { return *display; }
#endif

inline bool RepRap::Debug(Module m) const { return debug & (1 << m); }
inline Module RepRap::GetSpinningModule() const { return spinningModule; }

inline Tool* RepRap::GetCurrentTool() const { return currentTool; }
inline uint16_t RepRap::GetExtrudersInUse() const { return activeExtruders; }
inline uint16_t RepRap::GetToolHeatersInUse() const { return activeToolHeaters; }
inline bool RepRap::IsStopped() const { return stopped; }

#define INTERNAL_ERROR do { reprap.ReportInternalError((__FILE__), (__func__), (__LINE__)); } while(0)

#endif