/
cntrol.pde
186 lines (180 loc) · 4.87 KB
/
cntrol.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
import processing.serial.*;
import java.awt.Label;
import java.awt.Choice;
import java.awt.Button;
import java.awt.Checkbox;
import java.awt.TextField;
class Control extends ExtraWindow {
PApplet apa;
Choice comSelect, howToPrint;
Label temp;
TextField tempT;
boolean serialReady=false;
Checkbox support;
Control(PApplet theApplet, final String theName,final String comPort){
super(theApplet, theName, 0, 0, 400, 150);
apa=theApplet;
autoConnectPrinter(comPort);
}
Control(PApplet theApplet, final String theName) {
super(theApplet, theName, 0, 0, 400, 150);
apa=theApplet;
}
void windowClosing(WindowEvent e) {
apa.exit();
super.windowClosing(e);
}
void setup() {
comSelect=new Choice();
serialListLength=Serial.list().length;
comSelect.removeAll();
for (String com : Serial.list ()) {
comSelect.add(com);
}
add(comSelect);
Button connectButton=new Button("接続");
connectButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
connectPrinter();
}
}
);
add(connectButton);
Checkbox heat = new Checkbox("set");
heat.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
setHeater(e.getStateChange() == ItemEvent.SELECTED);
}
}
);
add(heat);
tempT=new TextField("200");
add(tempT);
temp=new Label("------℃");
add(temp);
howToPrint=new Choice();
howToPrint.add("サポート無し");
howToPrint.add("サポートあり");
howToPrint.add("0.1mmピッチ");
howToPrint.select(1);
add(howToPrint);
}
GCode saveAndCreateGCode() {
String stlpath=apa.dataPath("tmp.stl");
String gcodepath=apa.dataPath("tmp.gcode");
//STL.saveBin(stlpath, m);
int time=slice(stlpath, gcodepath);
GCode gcode=new GCode(gcodepath);
gcode.setTime(time);
return gcode;
}
int slice(String input, String output) {
String ini=apa.dataPath("fast-cura.ini");
switch(control.howToPrint.getSelectedIndex()) {
case 0:
ini=apa.dataPath("fast-cura.ini");
break;
case 1:
ini=apa.dataPath("cura-support.ini");
break;
case 2:
ini=apa.dataPath("cura01.ini");
break;
}
String curaPath=System.getenv("curaEngine");
if (curaPath==null) {
curaPath="D:/Program Files/Repetier-Host/plugins/CuraEngine/CuraEngine.exe";
} else {
curaPath=""+curaPath+"\\CuraEngine.exe";
}
Cura cura = new Cura(curaPath, ini, input, output);
int time=-1;
try {
cura.exe();
time =cura.getTime();
}
catch(Exception e) {
e.printStackTrace();
}
//exit();
return time;
}
void startPrint() {
if (gcode==null) {
println("slice");
gcode=saveAndCreateGCode();
}
if (gcode.printing) {
println("pause");
gcode.pausePrinting();
} else {
if (printer!=null) {
println("start printing");
gcode.printAll(printer);
}
}
}
void autoConnectPrinter(String comPort){
println("auto connect");
Serial tmp=new Serial(apa, comPort, 250000);
try {
Thread.sleep(3000);
}
catch(Exception e) {
}
tmp.write("G28\n");//現在地をホームポジションに戻す
println("send to pinter: G28");
tmp.write("G0 X0 Y0 Z30\n");//Z30
println("send to pinter: G0 X0 Y130 Z30");
tmp.write("M104 S220\n");//トルクロックを切る
tmp.write("M109 S220\n");//トルクロックを切る
printer=tmp;
}
void connectPrinter(){
connectPrinter(comSelect.getSelectedItem());
}
void connectPrinter(String comPort) {
Serial tmp=new Serial(apa, comPort, 250000);
try {
Thread.sleep(3000);
}
catch(Exception e) {
}
tmp.write("G28\n");//現在地をホームポジションに戻す
println("send to pinter: G28");
tmp.write("G0 X0 Y130 Z30\n");//Z30
println("send to pinter: G0 X0 Y130 Z30");
tmp.write("M84\n");//トルクロックを切る
println("send to pinter: M84");
printer=tmp;
}
void setHeater(boolean on) {
printer.write((on)?("M104 S"+tempT.getText()+"\n"):"M104 S0\n");
println("send to pinter: "+((on)?"M104 S200":"M104 S0"));
}
int serialListLength=0;
void draw() {
background(200);
if (serialListLength!=Serial.list().length) {
serialListLength=Serial.list().length;
comSelect.removeAll();
for (String com : Serial.list ()) {
comSelect.add(com);
}
}
if (gcode!=null&&gcode.printing) {
fill(255, 0, 0);
text(gcode.getTimeString(), 10, 50);
return;
}
if (printer==null||!serialReady) {
return;
}
//printer.write("M114\n");//現在地確認
//println("send to pinter: M114");
if (frameCount%10==0) {
printer.write("M105\n");//温度確認
//println("send to pinter: M105");
}
}
}