blob: 5e44ce097fc965cf948746aade242e0938a0e8f4 (
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 extruder, unsigned int type);
bool Interrupt() override;
protected:
void InitReceiveBuffer();
enum class PollResult : uint8_t
{
incomplete,
complete,
error
};
PollResult PollReceiveBuffer(uint16_t& measurement);
bool IsReceiving() const;
bool IsWaitingForStartBit() const;
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_ */
|