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

Trigger.cpp « GCodes « src - github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7b193655357f22482465151bca11edf7558a67c3 (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
/*
 * Trigger.cpp
 *
 *  Created on: 6 Jun 2019
 *      Author: David
 */

#include "Trigger.h"
#include "RepRap.h"
#include "PrintMonitor.h"

Trigger::Trigger() noexcept
{
	condition = 0;
}

// Initialise the trigger
void Trigger::Init() noexcept
{
	for (IoPort& port : ports)
	{
		port.Release();
	}
	condition = 0;
}

// Return true if this trigger is unused, i.e. it doesn't watch any pins
bool Trigger::IsUnused() const noexcept
{
	for (const IoPort& port : ports)
	{
		if (port.IsValid())
		{
			return false;
		}
	}
	return true;
}

// Check whether this trigger is active and update the input states
bool Trigger::Check() noexcept
{
	bool triggered = false;
	for (unsigned int i = 0; i < ARRAY_SIZE(ports); ++i)
	{
		if (!ports[i].IsValid())					// reached the end of the used ports
		{
			break;
		}
		const bool b = ports[i].Read();
		if (b != inputStates.IsBitSet(i))			// if the input level has changed
		{
			if (b)
			{
				inputStates.SetBit(i);
				triggered = true;
			}
			else
			{
				inputStates.ClearBit(i);
			}
		}
	}
	return triggered && (condition == 0 || (condition == 1 && reprap.GetPrintMonitor().IsPrinting()));
}

// End