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
|
/*
* Endstop.h
*
* Created on: 3 Apr 2019
* Author: David
*/
#ifndef SRC_ENDSTOPS_ENDSTOPMANAGER_H_
#define SRC_ENDSTOPS_ENDSTOPMANAGER_H_
#include <RepRapFirmware.h>
#include "EndstopDefs.h"
#include <GCodes/GCodeResult.h>
#include <ObjectModel/ObjectModel.h>
#include <RTOSIface/RTOSIface.h>
#if SUPPORT_CAN_EXPANSION
# include "CanId.h"
class CanMessageBuffer;
#endif
class StallDetectionEndstop;
// Endstop manager class
class EndstopsManager INHERIT_OBJECT_MODEL
{
public:
EndstopsManager() noexcept;
void Init() noexcept;
// Set up the active endstop list according to the axes commanded to move in a G0/G1 S1/S3 command returning true if successful
bool EnableAxisEndstops(AxesBitmap axes, bool forHoming) noexcept __attribute__ ((warn_unused_result));
// Set up the active endstops for Z probing returning true if successful
bool EnableZProbe(size_t probeNumber, bool probingAway = false) noexcept __attribute__ ((warn_unused_result));
// Set up the active endstops for Z probing with the current probe
bool EnableCurrentZProbe(bool probingAway = false) noexcept __attribute__ ((warn_unused_result)) { return EnableZProbe(currentZProbeNumber, probingAway); }
// Enable extruder endstops
bool EnableExtruderEndstops(ExtrudersBitmap extruders) noexcept;
// Get the first endstop that has triggered and remove it from the active list if appropriate
EndstopHitDetails CheckEndstops(bool goingSlow) noexcept;
// Configure the endstops in response to M574
GCodeResult HandleM574(GCodeBuffer& gb, const StringRef& reply, OutputBuffer*& outbuf) noexcept;
EndStopPosition GetEndStopPosition(size_t axis) const pre(axis < MaxAxes) noexcept;
bool HomingZWithProbe() const noexcept;
EndStopHit Stopped(size_t axis) const noexcept;
void GetM119report(const StringRef& reply) noexcept;
// Z probe
GCodeResult HandleM558(GCodeBuffer& gb, const StringRef &reply) THROWS_GCODE_EXCEPTION; // M558
GCodeResult HandleG31(GCodeBuffer& gb, const StringRef& reply) THROWS_GCODE_EXCEPTION; // G31
ReadLockedPointer<ZProbe> GetZProbe(size_t index) const noexcept;
size_t GetCurrentZProbeNumber() const noexcept { return currentZProbeNumber; }
ReadLockedPointer<ZProbe> GetCurrentOrDefaultZProbe() const noexcept;
ZProbe& GetCurrentOrDefaultZProbeFromISR() const noexcept;
void SetZProbeDefaults() noexcept;
GCodeResult ProgramZProbe(GCodeBuffer& gb, const StringRef& reply) THROWS_GCODE_EXCEPTION;
#if SUPPORT_CAN_EXPANSION
void HandleRemoteInputChange(CanAddress src, uint8_t handleMajor, uint8_t handleMinor, bool state) noexcept;
void OnEndstopStatesChanged() noexcept;
#endif
#if HAS_MASS_STORAGE
bool WriteZProbeParameters(FileStore *f, bool includingG31) const noexcept;
#endif
protected:
DECLARE_OBJECT_MODEL
OBJECT_MODEL_ARRAY(endstops)
OBJECT_MODEL_ARRAY(probes)
private:
// Add an endstop to the active list
void AddToActive(EndstopOrZProbe& e) noexcept;
#if SUPPORT_OBJECT_MODEL
size_t GetNumProbesToReport() const noexcept;
#endif
// Translate end stop result to text
static const char *TranslateEndStopResult(EndStopHit es, bool atHighEnd) noexcept;
ReadLockedPointer<Endstop> FindEndstop(size_t axis) const noexcept;
static ReadWriteLock endstopsLock;
static ReadWriteLock zProbesLock;
EndstopOrZProbe * volatile activeEndstops; // linked list of endstops and Z probes that are active for the current move
size_t currentZProbeNumber; // which Z probe we are using
Endstop *axisEndstops[MaxAxes]; // the endstops assigned to each axis (each one may have several switches), each may be null
StallDetectionEndstop *extrudersEndstop; // the endstop used for extruder stall detection, one will do for all extruders
ZProbe *zProbes[MaxZProbes]; // the Z probes used. The first one is always non-null.
ZProbe *defaultZProbe;
bool isHomingMove; // true if calls to CheckEndstops are for the purpose of homing
};
#endif /* SRC_ENDSTOPS_ENDSTOPMANAGER_H_ */
|