MCPcopy Create free account
hub / github.com/Duet3D/RepRapFirmware / Check

Method Check

src/GCodes/TriggerItem.cpp:36–106  ·  view source on GitHub ↗

Check whether this trigger is active and update the input states. This is called in a polling loop, so it needs to be fast. TODO when we switch to interrupt-driven endstops, make this interrupt-driven instead

Source from the content-addressed store, hash-verified

34// Check whether this trigger is active and update the input states. This is called in a polling loop, so it needs to be fast.
35// TODO when we switch to interrupt-driven endstops, make this interrupt-driven instead
36bool TriggerItem::Check() noexcept
37{
38 bool triggered = false;
39
40 // Check the endstops
41 const AxesBitmap endstopsMonitored = highLevelEndstops | lowLevelEndstops;
42 if (endstopsMonitored.IsNonEmpty())
43 {
44 EndstopsManager& endstops = reprap.GetPlatform().GetEndstops();
45 endstopsMonitored.Iterate([this, &endstops, &triggered](unsigned int axis, unsigned int) noexcept
46 {
47 const bool stopped = endstops.Stopped(axis);
48 if (stopped != endstopStates.IsBitSet(axis))
49 {
50 if (stopped)
51 {
52 endstopStates.SetBit(axis);
53 if (highLevelEndstops.IsBitSet(axis))
54 {
55 triggered = true;
56 }
57 }
58 else
59 {
60 endstopStates.ClearBit(axis);
61 if (lowLevelEndstops.IsBitSet(axis))
62 {
63 triggered = true;
64 }
65 }
66 }
67 }
68 );
69 }
70
71 const InputPortsBitmap portsMonitored = highLevelInputs | lowLevelInputs;
72 if (portsMonitored.IsNonEmpty())
73 {
74 Platform& platform = reprap.GetPlatform();
75 portsMonitored.Iterate([this, &platform, &triggered](unsigned int inPort, unsigned int) noexcept
76 {
77 const bool isActive = reprap.GetPlatform().GetGpInPort(inPort).GetState();
78 if (isActive != inputStates.IsBitSet(inPort))
79 {
80 if (isActive)
81 {
82 inputStates.SetBit(inPort);
83 if (highLevelInputs.IsBitSet(inPort))
84 {
85 triggered = true;
86 }
87 }
88 else
89 {
90 inputStates.ClearBit(inPort);
91 if (lowLevelInputs.IsBitSet(inPort))
92 {
93 triggered = true;

Callers 1

CheckTriggersMethod · 0.45

Calls 3

IsPrintingMethod · 0.80
StoppedMethod · 0.45
GetStateMethod · 0.45

Tested by

no test coverage detected