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

Tool.h « Tools « src - github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 814326d00371c18b17ba0a09b9c41f90967d55b6 (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
/****************************************************************************************************

RepRapFirmware - Tool

This class implements a tool in the RepRap machine, usually (though not necessarily) an extruder.

Tools may have zero or more drives associated with them and zero or more heaters.  There are a fixed number
of tools in a given RepRap, with fixed heaters and drives.  All this is specified on reboot, and cannot
be altered dynamically.  This restriction may be lifted in the future.  Tool descriptions are stored in
GCode macros that are loaded on reboot.

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

Version 0.1

Created on: Apr 11, 2014

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

Licence: GPL

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

#ifndef TOOL_H_
#define TOOL_H_

#include "RepRapFirmware.h"

#undef array
#include <functional>
#define array _ecv_array

constexpr size_t ToolNameLength = 32;						// maximum allowed length for tool names

enum class ToolState : uint8_t
{
	off = 0,
	active,
	standby
};

class Filament;

class Tool
{
public:

	static Tool *Create(unsigned int toolNumber, const char *name, int32_t d[], size_t dCount, int32_t h[], size_t hCount, AxesBitmap xMap, AxesBitmap yMap, FansBitmap fanMap, int filamentDrive, const StringRef& reply) noexcept;
	static void Delete(Tool *t) noexcept;
	static AxesBitmap GetXAxes(const Tool *tool) noexcept;
	static AxesBitmap GetYAxes(const Tool *tool) noexcept;
	static float GetOffset(const Tool *tool, size_t axis) noexcept pre(axis < MaxAxes);

	float GetOffset(size_t axis) const noexcept pre(axis < MaxAxes);
	void SetOffset(size_t axis, float offs, bool byProbing) noexcept pre(axis < MaxAxes);
	AxesBitmap GetAxisOffsetsProbed() const noexcept { return axisOffsetsProbed; }
	size_t DriveCount() const noexcept;
	int Drive(size_t driveNumber) const noexcept;
	bool ToolCanDrive(bool extrude) noexcept;
	size_t HeaterCount() const noexcept;
	int Heater(size_t heaterNumber) const noexcept;
	const char *GetName() const noexcept;
	int Number() const noexcept;
	void DefineMix(const float m[]) noexcept;
	const float* GetMix() const noexcept;
	void Print(const StringRef& reply) const noexcept;
	AxesBitmap GetXAxisMap() const noexcept { return xMapping; }
	AxesBitmap GetYAxisMap() const noexcept { return yMapping; }
	FansBitmap GetFanMapping() const noexcept { return fanMapping; }
	Filament *GetFilament() const noexcept { return filament; }
	Tool *Next() const noexcept { return next; }
	ToolState GetState() const noexcept { return state; }

#if HAS_MASS_STORAGE
	bool WriteSettings(FileStore *f) const noexcept;							// write the tool's settings to file
#endif

	float GetToolHeaterActiveTemperature(size_t heaterNumber) const noexcept;
	float GetToolHeaterStandbyTemperature(size_t heaterNumber) const noexcept;
	void SetToolHeaterActiveTemperature(size_t heaterNumber, float temp) noexcept;
	void SetToolHeaterStandbyTemperature(size_t heaterNumber, float temp) noexcept;

	bool HasTemperatureFault() const noexcept { return heaterFault; }

	void IterateExtruders(std::function<void(unsigned int)> f) const noexcept;
	void IterateHeaters(std::function<void(int)> f) const noexcept;

	friend class RepRap;

protected:
	void Activate() noexcept;
	void Standby() noexcept;
	void FlagTemperatureFault(int8_t dudHeater) noexcept;
	void ClearTemperatureFault(int8_t wasDudHeater) noexcept;
	void UpdateExtruderAndHeaterCount(uint16_t &extruders, uint16_t &heaters) const noexcept;
	bool DisplayColdExtrudeWarning() noexcept;

private:
	static Tool *freelist;

	Tool() noexcept : next(nullptr), filament(nullptr), name(nullptr) { }

	void SetTemperatureFault(int8_t dudHeater) noexcept;
	void ResetTemperatureFault(int8_t wasDudHeater) noexcept;
	bool AllHeatersAtHighTemperature(bool forExtrusion) const noexcept;
	bool UsesHeater(int8_t heater) const noexcept;

	Tool* next;
	Filament *filament;
	const char *name;
	float offset[MaxAxes];
	float mix[MaxExtrudersPerTool];
	float activeTemperatures[MaxHeatersPerTool];
	float standbyTemperatures[MaxHeatersPerTool];
	uint8_t driveCount;
	uint8_t heaterCount;
	uint16_t myNumber;
	AxesBitmap xMapping, yMapping;
	AxesBitmap axisOffsetsProbed;
	FansBitmap fanMapping;
	uint8_t drives[MaxExtrudersPerTool];
	int8_t heaters[MaxHeatersPerTool];

	ToolState state;
	bool heaterFault;
	volatile bool displayColdExtrudeWarning;
};

inline int Tool::Drive(size_t driveNumber) const noexcept
{
	return drives[driveNumber];
}

inline size_t Tool::HeaterCount() const noexcept
{
	return heaterCount;
}

inline int Tool::Heater(size_t heaterNumber) const noexcept
{
	return heaters[heaterNumber];
}

inline const char *Tool::GetName() const noexcept
{
	return (name == nullptr) ? "" : name;
}

inline int Tool::Number() const noexcept
{
	return myNumber;
}

inline const float* Tool::GetMix() const noexcept
{
	return mix;
}

inline size_t Tool::DriveCount() const noexcept
{
	return driveCount;
}

inline float Tool::GetOffset(size_t axis) const noexcept
{
	return offset[axis];
}

#endif /* TOOL_H_ */