forked from Duet3D/RepRapFirmware
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLine.h
More file actions
63 lines (50 loc) · 1.46 KB
/
Line.h
File metadata and controls
63 lines (50 loc) · 1.46 KB
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
// This class handles serial I/O - typically via USB
#ifndef LINE_H
#define LINE_H
#include "Arduino.h"
// Input and output - these are ORed into a uint8_t
// By the Status() functions of the IO classes.
enum class IOStatus
{
nothing = 0,
byteAvailable = 1,
atEoF = 2,
clientLive = 4,
clientConnected = 8
};
const uint16_t lineInBufsize = 256; // use a power of 2 for good performance
const uint16_t lineOutBufSize = 2048; // ideally this should be large enough to hold the results of an M503 command,
// but could be reduced if we ever need the memory
class Line
{
public:
uint8_t Status() const; // Returns OR of IOStatus
int Read(char& b);
void Write(char b, bool important = false);
void Write(const char* s, bool important = false);
void Flush();
friend class Platform;
friend class RepRap;
protected:
Line(Stream& p_iface);
void Init();
void Spin();
void InjectString(char* string);
unsigned int GetOutputColumn() const { return outputColumn; }
private:
void TryFlushOutput();
// Although the sam3x usb interface code already has a 512-byte buffer, adding this extra 256-byte buffer
// increases the speed of uploading to the SD card by 10%
char inBuffer[lineInBufsize];
char outBuffer[lineOutBufSize];
uint16_t inputGetIndex;
uint16_t inputNumChars;
uint16_t outputGetIndex;
uint16_t outputNumChars;
uint32_t timeLastCharWritten;
uint8_t inWrite;
bool ignoringOutputLine;
unsigned int outputColumn;
Stream& iface;
};
#endif