-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathGcodeQueue.h
96 lines (85 loc) · 2.94 KB
/
GcodeQueue.h
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#ifndef _GCODES_H_
#define _GCODES_H_
/* GCode physical parser and queue
* (c) 2011 Christopher "ScribbleJ" Jansen
*
* This class is responsible for recieving Gcode from 'sources' in fragments.
* A source is something on the system that wants to provide Gcode; e.g. the host,
* or the SD Card, or the Control Pad.
* Fragments are a chunk of gcode up to and including a space or carriage return/newline (BUT NO MORE THAN THAT!)
* Callers are presently expected to check isFull() before attempting to send a fragment.
*
*/
#include "RingBuffer.h"
#include "GCode.h"
#include "config.h"
#include "AvrPort.h"
class GcodeQueue
{
public:
// Singleton pattern... only one Gcode queue exists.
static GcodeQueue& Instance() { static GcodeQueue instance; return instance; }
private:
explicit GcodeQueue() :codes(GCODE_BUFSIZE, codes_buf)
#ifdef USE_PRIORITY
, priority_codes(GCODE_PRIORITY_BUFSIZE, priority_buf)
#endif
{
for(int x=0;x<GCODE_SOURCES;x++)
{
sources[x].reset();
crc_state[x] = NOCRC;
crc[x] = 0;
line_number[x] = -1;
chars_in_line[x] = 0;
needserror[x] = false;
ADVANCED_CRC[x] = false;
}
optimize_gcode = false;
pause = false;
}
GcodeQueue(GcodeQueue const&);
void operator=(const GcodeQueue&);
public:
// Should be called often from mainloop; handles gcode dispatch
void handlenext();
// disables inactive axes - not sure why this is here.
void checkaxes();
// Change current line number
void setLineNumber(uint32_t l, uint8_t source);
void setLineNumber(unsigned int l) { setLineNumber(l, 0); }
// Drop a new gcode on the stack
void enqueue(GCode& c,int queue=0);
// Tells us whether queue is full.
bool isFull(int queue=0);
// Decode a (partial) gcode string
void parsebytes(char *bytes, uint8_t numbytes) { parsebytes(bytes, numbytes, 0); }
void parsebytes(char *bytes, uint8_t numbytes, uint8_t source);
// Dump all precalculated data and recompute
void Invalidate();
void enableOptimize() { optimize_gcode = true; };
void disableOptimize() { optimize_gcode = false; };
bool shouldOptimize() { return optimize_gcode; };
void enableADVANCED_CRC(int source) { ADVANCED_CRC[source] = true; }
void disableADVANCED_CRC(int source) { ADVANCED_CRC[source] = false; }
void togglepause() { pause = !pause; }
private:
GCode codes_buf[GCODE_BUFSIZE];
RingBufferT<GCode> codes;
#ifdef USE_PRIORITY
GCode priority_buf[GCODE_PRIORITY_BUFSIZE];
RingBufferT<GCode> priority_codes;
#endif
GCode sources[GCODE_SOURCES];
enum crc_state_t { NOCRC, CRC, CRCCOMPLETE } crc_state[GCODE_SOURCES];
uint8_t crc[GCODE_SOURCES];
int32_t line_number[GCODE_SOURCES];
uint8_t chars_in_line[GCODE_SOURCES];
bool needserror[GCODE_SOURCES];
bool invalidate_codes;
bool pause;
bool optimize_gcode; // WTF is this here? This whole pipeline needs serious refactor.
bool ADVANCED_CRC[GCODE_SOURCES];
};
extern GcodeQueue& GCODES;
#endif // _GCODES_H_