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

Duet3DFilamentMonitor.h « FilamentMonitors « src - github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4ed489c3f4e5b66e833aa4325e34b8b35e3d54d6 (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
/*
 * Duet3DFilamentSensor.h
 *
 *  Created on: 20 Jul 2017
 *      Author: David
 *
 *  This is the base class for filament monitors that use the Duet3D protocol for sending 16-bit words to the Duet.
 */

#ifndef SRC_FILAMENTSENSORS_DUET3DFILAMENTMONITOR_H_
#define SRC_FILAMENTSENSORS_DUET3DFILAMENTMONITOR_H_

#include "FilamentMonitor.h"

class Duet3DFilamentMonitor : public FilamentMonitor
{
public:
	Duet3DFilamentMonitor(unsigned int drv, unsigned int monitorType, DriverId did) noexcept;

	bool Interrupt() noexcept override;

protected:
	void InitReceiveBuffer() noexcept;

	enum class PollResult : uint8_t
	{
		incomplete,
		complete,
		error
	};
	PollResult PollReceiveBuffer(uint16_t& measurement) noexcept;
	bool IsReceiving() const noexcept;
	bool IsWaitingForStartBit() const noexcept;

protected:
	uint32_t overrunErrorCount;
	uint32_t polarityErrorCount;

private:
	static constexpr size_t EdgeCaptureBufferSize = 64;				// must be a power of 2

	// Buffer used to capture received data, and associated info
	uint32_t edgeCaptures[EdgeCaptureBufferSize];
	size_t edgeCaptureReadPointer;
	volatile size_t edgeCaptureWritePointer;

	enum class RxdState : uint8_t
	{
		waitingForStartBit = 0,
		waitingForEndOfStartBit,
		waitingForNibble,
		errorRecovery1,
		errorRecovery2,
		errorRecovery3,
		errorRecovery4
	};

	uint32_t startBitLength;
	uint32_t errorRecoveryStartTime;
	size_t lastBitChangeIndex;
	uint16_t valueBeingAssembled;
	uint8_t nibblesAssembled;
	RxdState state;
};

#endif /* SRC_FILAMENTSENSORS_DUET3DFILAMENTMONITOR_H_ */