-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCNCGUI.pde
More file actions
122 lines (114 loc) · 2.9 KB
/
CNCGUI.pde
File metadata and controls
122 lines (114 loc) · 2.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import processing.serial.*;
import geomerative.*;
Serial arduino;
boolean arduinoConnected = true;
Simulator cnc;
boolean keymap[];
ArrayList<Command> toolpath;
svgParser parser;
String input;
void loadSVG(){
selectInput("Select a file to process:", "svgFileSelected");
}
void svgFileSelected(File selection) {
if (selection == null) {
println("Window was closed or the user hit cancel.");
} else {
if(selection.getAbsolutePath().indexOf(".svg")>0){ // check if the path ends in ".svg"
println("SVG file selected!");
parser = new svgParser(selection);
toolpath = parser.getPath();
/*for(int i = 1; i<toolpath.size(); i++){
if(arduinoConnected)toolpath.get(i).sendCommand(arduino);
toolpath.get(i).print();
delay(100);
}*/
}else{
println("not a SVG file selected");
}
}
}
void setup(){
size(768,512,P3D);
RG.init(this);
parser = new svgParser();
cnc = new Simulator(arduino);//give it a port to arduino
keymap = new boolean[4];//0,1,2,3 - left, right, up, down
if(arduinoConnected)arduino = new Serial(this, "COM3", 9600); //on my computer the arduino creates the COM3 port
}
void draw(){
/*if(arduinoConnected){
while( arduino.available() > 0)
{ // If data is available,
input = arduino.readString(); // read it and store it in val
if(input!=null)println(input);
}
}*/
background(13,13,25);
cnc.drawCNC();
//cnc.printPosition();
if(keymap[0]){cnc.stepMotor('y',1);}
if(keymap[1]){cnc.stepMotor('y',-1);}
if(keymap[2]){
cnc.stepMotor('z',1);
}
if(keymap[3]){
cnc.stepMotor('z', -1);
}
}
void keyPressed(){
if(key == 'p' && toolpath.size()>0 && arduinoConnected){
for(int i = 1; i<toolpath.size(); i++){
if(arduinoConnected)toolpath.get(i).sendCommand(arduino);
toolpath.get(i).print();
delay(70);
}
}
if(key == CODED){
switch(keyCode){
case LEFT:
keymap[0]=true;
break;
case RIGHT:
keymap[1]=true;
break;
case UP:
if(arduinoConnected){
Command com = new Command((byte)'l',(byte)'u');
com.print();
com.sendCommand(arduino);
}
keymap[2]=true;
break;
case DOWN:
if(arduinoConnected){
Command com = new Command((byte)'l',(byte)'d');
com.print();
com.sendCommand(arduino);
}
keymap[3]=true;
break;
}
}else if(key=='o'){
loadSVG();
}else if(key=='m'){
}
}
void keyReleased(){
if(key == CODED){
switch(keyCode){
case LEFT:
keymap[0]=false;
break;
case RIGHT:
keymap[1]=false;
break;
case UP:
keymap[2]=false;
break;
case DOWN:
keymap[3]=false;
break;
}
}
}