-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTiny_PCNCcontroller.pde
200 lines (170 loc) · 5.81 KB
/
Tiny_PCNCcontroller.pde
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
//--=-====-=---=-=-=---==-=-=---=-=-=-=-=-=-=-=--
//talk to the TinyG board thru a Processing GUI
//--=-====-=---=-=-=---==-=-=---=-=-=-=-=-=-=-=--
import controlP5.*; //controlp5 lib for gui
import processing.serial.*; //serial library for board-talkin
import javax.swing.*; //java lib for file choosing
//import org.json.*; //json parsing lib for interpreting inter-step position info
import java.awt.datatransfer.*; //libs for clipboard access
import java.awt.Toolkit; //ditto
import unlekker.util.*; //modelbuilder libs for 3D viewing
import unlekker.modelbuilder.*; //ditto
/*
///stuff for custom camera control
import processing.video.*;
Capture myCapture;
PImage camSample = createImage( 2, 2, RGB );
float prevX = 0;
float prevY = 0;
float currentX = 0;
float currentY = 0;
float roundedX;
float roundedY;
float idealStep = (1.0/72.0);
PImage dest = createImage( 1296, 1296, RGB );
int pixIndex = 0;
float[] pixelDists = new float[dest.width*dest.height];
//end stuff for camera control
*/
ControlP5 portControls; //port controls
ControlP5 conDepControls; //controls that depend on a connection
ClipHelper clipBoard = new ClipHelper();
DropdownList portList;
Textarea serialOutput;
Textarea machineState;
Textfield serialInput;
Textfield filePath;
Button submit;
Button paste;
Button eStop;
Button loadFile;
Button runFile;
Button connect;
Button disconnect;
RadioButton unitSelect;
//gcode viewer stuff
MouseNav3D nav;
UVertexList model = new UVertexList();
int renderX = 5;
int renderY = 520;
int renderWd = 400;
int renderHt = 300;
PGraphics renderWindow;
float[] gCodePos = { 0.0, 0.0, 0.0, 0.0 }; //0,1,2,3 corresponds to x,y,z, Gmode (G1, G0, etc)
int lineNum = 0;
CNC myCNC;
void setup() {
frameRate(200);
size( 768, 840 );
myCNC = new CNC(this);
guiSetup();
//3D gcode preview setup
nav=new MouseNav3D(this);
nav.trans.set(width/2, height/2, 0);
//offscreen buffer we'll render the gCode to; this makes it easy to place onscreen w/ other gui stuff
renderWindow = createGraphics(renderWd, renderHt, P3D);
addMouseWheelListener(new java.awt.event.MouseWheelListener() {
public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) {
mouseWheel(evt.getWheelRotation());
}
});
//camera control stuff
// camSetup();
}
void draw() {
background(200);
filePath.setFocus( false );
if( myCNC.readCharacter() ){
updateGUItext();
}
if( myCNC.streaming ) {
myCNC.streamGCode();
}
renderPreview();
//camera control stuff
//camUpdate();
}
void captureEvent(Capture myCapture) {
myCapture.read();
}
//get info from the board when it's available, and update it in display
void serialEvent( Serial p ) {
//myCNC.readString();
//updateGUItext();
}
//keyboard control
//recall previous commands into the text field, jog the machine
void keyPressed() {
//see if this is a jog key; if not, focus on the input box for text typing
if (key == CODED && ( keyCode == UP || keyCode == DOWN || keyCode == RIGHT || keyCode == LEFT ) ) {
//println("keyCode " + keyCode);
if ( keyCode == UP ) {
if( serialInput.isFocus() ){
serialInput.setText( myCNC.lastCommand() );
} else {
println("Y+");
myCNC.jog( "Y", 1, 0.1 );
}
}
else if ( keyCode == DOWN ) {
if( serialInput.isFocus() ) {
serialInput.setText( myCNC.nextCommand() );
} else {
println("Y-");
myCNC.jog( "Y", -1, 0.1 );
}
}
else if ( keyCode == RIGHT ) {
if( !serialInput.isFocus() ) {
println("X+");
myCNC.jog( "X", 1, 0.1 );
}
}
else if ( keyCode == LEFT ) {
if( !serialInput.isFocus() ) {
println("X-");
myCNC.jog( "X", -1, 0.1 );
}
}
}
else if( key == '[' || key == '{' || key == ']' || key == '}' || key == '-' || key == '_' || key == '+' || key == '=' || key == ':' || key == ';' || key == '"' || key == char(39) ) {
//println("key " + key);
if( key == '[' || key == '{' ) {
if( !serialInput.isFocus() ) {
println("Z-");
myCNC.jog( "Z", -1, 0.01 );
}
}
else if( key == ']' || key == '}' ) {
if( !serialInput.isFocus() ) {
println("Z+");
myCNC.jog( "Z", 1, 0.01 );
}
}
else if( key == '-' || key == '_' ) {
if( !serialInput.isFocus() ) {
println("A-");
}
}
else if( key == '+' || key == '=' ) {
if( !serialInput.isFocus() ) {
println("A+");
}
}
else if( key == ':' || key == ';') {
if( !serialInput.isFocus() ) {
println("B-");
}
}
else if( key == '"' || key == char(39) ) {
if( !serialInput.isFocus() ) {
println("B+");
}
}
else if( key == 's' ) {
//dest.save("output.jpg");
}
} else { //text input is coming; automatically put it in the input line
serialInput.setFocus( true );
}
}