blob: bbfb7874e22a8a5a17a10827ad69ebeed9dad671 (
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
|
/*
* LocalSwitchEndstop.h
*
* Created on: 15 Sep 2019
* Author: David
*/
#ifndef SRC_ENDSTOPS_SWITCHENDSTOP_H_
#define SRC_ENDSTOPS_SWITCHENDSTOP_H_
#include "Endstop.h"
#include "GCodes/GCodeResult.h"
// Switch-type endstop, either on the main board or on a CAN-connected board
class SwitchEndstop : public Endstop
{
public:
void* operator new(size_t sz) noexcept { return FreelistManager::Allocate<SwitchEndstop>(); }
void operator delete(void* p) noexcept { FreelistManager::Release<SwitchEndstop>(p); }
~SwitchEndstop() noexcept override;
SwitchEndstop(uint8_t axis, EndStopPosition pos) noexcept;
EndStopType GetEndstopType() const noexcept override;
EndStopHit Stopped() const noexcept override;
bool Prime(const Kinematics& kin, const AxisDriversConfig& axisDrivers) noexcept override;
EndstopHitDetails CheckTriggered(bool goingSlow) noexcept override;
bool Acknowledge(EndstopHitDetails what) noexcept override;
void AppendDetails(const StringRef& str) noexcept override;
#if SUPPORT_CAN_EXPANSION
// Process a remote endstop input change that relates to this endstop. Return true if the buffer has been freed.
void HandleRemoteInputChange(CanAddress src, uint8_t handleMinor, bool state) noexcept override;
#endif
GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply) THROWS_GCODE_EXCEPTION;
GCodeResult Configure(const char *pinNames, const StringRef& reply) noexcept;
private:
typedef uint16_t PortsBitmap;
void ReleasePorts() noexcept;
inline bool IsTriggered(size_t index) const noexcept
{
#if SUPPORT_CAN_EXPANSION
return (boardNumbers[index] == CanId::MasterAddress) ? ports[index].Read() : states[index];
#else
return ports[index].Read();
#endif
}
#if SUPPORT_CAN_EXPANSION
static constexpr uint16_t MinimumSwitchReportInterval = 30;
#endif
IoPort ports[MaxDriversPerAxis];
#if SUPPORT_CAN_EXPANSION
CanAddress boardNumbers[MaxDriversPerAxis];
bool states[MaxDriversPerAxis];
#endif
size_t numPortsUsed;
PortsBitmap portsLeftToTrigger;
size_t numPortsLeftToTrigger;
bool stopAll;
};
#endif /* SRC_ENDSTOPS_SWITCHENDSTOP_H_ */
|