-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathGCode_Interpreter.ino
More file actions
88 lines (74 loc) · 1.9 KB
/
GCode_Interpreter.ino
File metadata and controls
88 lines (74 loc) · 1.9 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
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
#include "GCode_Interpreter.h"
#define COMMAND_SIZE 128
char command[COMMAND_SIZE];
byte serial_count;
int no_data = 0;
long idle_time;
boolean comment = false;
boolean bytes_received = false;
long current_steps[3];
Move move_queue[2];
volatile Move *current_move_ptr, *next_move_ptr;
// Following all need to be volatile because they are
// being both read and set by the main and interrupt handler routines
volatile bool have_next_move = false;
volatile bool move_queue_lock_main = false;
volatile bool moving = false;
volatile bool move_finished = true;
unsigned int timer1LoadValue, nextTimer1LoadValue;
void setup()
{
Serial.begin(38400); // Don't need to give a baud rate because it is fixed at 19200 in our optimised version
init_steppers();
init_extruder();
init_process_string();
calculateAccelConstants();
SetupTimer1();
println("start");
}
void loop()
{
char c;
//keep it hot!
extruder_manage_temperature();
//read in characters if we got them.
if (Serial.available() > 0)
{
c = Serial.read();
no_data = 0;
//newlines are ends of commands.
if (c != '\n')
{
// Start of comment - ignore any bytes received from now on
if (c == '(')
comment = true;
// If we're not in comment mode, add it to our array.
if (!comment)
{
command[serial_count] = c;
serial_count++;
}
if (c == ')')
comment = false; // End of comment - start listening again
}
bytes_received = true;
idle_time = millis();
}
//mark no data if nothing heard for 100 milliseconds
else
{
if ((millis() - idle_time) >= 100)
{
no_data++;
idle_time = millis();
}
}
//if theres a pause or we got a real command, do it
if (bytes_received && (c == '\n' || no_data ))
{
//process our command!
process_string(command, serial_count);
//clear command.
init_process_string();
}
}