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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
|
package org.reprap.gui.extruderprofile;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.WindowConstants;
import org.reprap.Preferences;
import org.reprap.comms.Communicator;
import org.reprap.comms.snap.SNAPAddress;
import org.reprap.comms.snap.SNAPCommunicator;
import org.reprap.devices.SNAPExtruder;
/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class Main extends javax.swing.JDialog {
private final static int stablePeriod = 60000;
private JLabel jLabel1;
private JButton startButton;
private JLabel jLabel2;
private JLabel jLabel4;
private JTextField elapsedTime;
private JTextField currentTemp;
private JTextField powerSetting;
private JLabel jLabel3;
private JTextField maxTemp;
private final int localNodeNumber = 0;
private Thread pollThread = null;
private boolean pollThreadExiting = false;
private Communicator communicator;
private SNAPExtruder extruder;
private boolean profileInProgress = false;
private int currentHeaterOutput = -1;
private double previousTemperature;
private long lastChangeTime = 0;
private long segmentStartTime = 0;
private double ambientTemperature;
/**
* Auto-generated main method to display this JDialog
*/
public static void main(String[] args) throws Exception {
JFrame frame = new JFrame();
Main inst = new Main(frame);
inst.setVisible(true);
}
public Main(JFrame frame) throws Exception {
super(frame);
SNAPAddress myAddress = new SNAPAddress(localNodeNumber);
this.setResizable(false);
communicator = new SNAPCommunicator(Preferences.loadGlobalString("Port(name)"),
myAddress);
extruder = new SNAPExtruder(communicator,
new SNAPAddress(Preferences.loadGlobalString("Extruder0_Address")),
Preferences.getGlobalPreferences(), 0);
initGUI();
if (!extruder.isAvailable()) {
startButton.setEnabled(false);
return;
}
pollThread = new Thread() {
public void run() {
Thread.currentThread().setName("GUI Poll");
while(!pollThreadExiting) {
try {
Thread.sleep(500);
RefreshTemperature();
}
catch (InterruptedException ex) {
// This is normal when shutting down, so ignore
}
catch (Exception ex) {
System.err.println("Exception during profiler temperature update: " + ex.getMessage());
}
}
}
};
pollThread.start();
}
protected void RefreshTemperature() throws IOException {
int temperature = (int)Math.round(extruder.getTemperature());
currentTemp.setText(Integer.toString(temperature));
// Decide if we should set a new heater output
if (currentHeaterOutput != -1 && !profileInProgress) {
// Cancel
extruder.setHeater(0, 0);
return;
}
if (!profileInProgress)
return;
if (currentHeaterOutput == -1) {
// Set first level
ambientTemperature = temperature;
System.out.println("Heater output 0, ambient temp is " + ambientTemperature + "C");
currentHeaterOutput = 15;
powerSetting.setText(String.valueOf(currentHeaterOutput));
extruder.setHeater(currentHeaterOutput, Integer.parseInt(maxTemp.getText()));
previousTemperature = temperature;
segmentStartTime = lastChangeTime = System.currentTimeMillis();
return;
}
if (temperature > Integer.parseInt(maxTemp.getText())) {
System.out.println("Reached max temperature -- aborted");
startButtonActionPerformed(null);
return;
}
// If temperature max stable for period, bump up level
// (ie ignore small decreases)
if (temperature > previousTemperature) {
lastChangeTime = System.currentTimeMillis();
previousTemperature = temperature;
} else {
long now = System.currentTimeMillis();
long elapsed = now - lastChangeTime;
elapsedTime.setText(String.valueOf(elapsed));
if (elapsed > stablePeriod) {
long duration = now - segmentStartTime;
System.out.println("Heater output " + currentHeaterOutput + " is " +
previousTemperature + "C after " + duration + "ms");
currentHeaterOutput += 16;
if (currentHeaterOutput > 255) {
startButtonActionPerformed(null);
} else {
powerSetting.setText(String.valueOf(currentHeaterOutput));
extruder.setHeater(currentHeaterOutput, Integer.parseInt(maxTemp.getText()));
previousTemperature = temperature;
segmentStartTime = lastChangeTime = System.currentTimeMillis();
}
}
}
}
public void dispose() {
if (pollThread != null) {
pollThreadExiting = true;
pollThread.interrupt();
}
extruder.dispose();
communicator.dispose();
super.dispose();
}
private void initGUI() {
try {
{
jLabel1 = new JLabel();
getContentPane().add(jLabel1);
jLabel1.setText("Max Temperature");
jLabel1.setBounds(-7, 35, 133, 28);
jLabel1.setHorizontalAlignment(SwingConstants.RIGHT);
}
{
maxTemp = new JTextField();
getContentPane().add(maxTemp);
maxTemp.setText("150");
maxTemp.setBounds(147, 35, 63, 28);
}
{
startButton = new JButton();
getContentPane().add(startButton);
startButton.setText("Profile...");
startButton.setBounds(147, 77, 105, 28);
startButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
startButtonActionPerformed(evt);
}
});
}
{
jLabel2 = new JLabel();
getContentPane().add(jLabel2);
jLabel2.setText("Power setting");
jLabel2.setBounds(7, 126, 119, 28);
jLabel2.setHorizontalAlignment(SwingConstants.RIGHT);
}
{
jLabel3 = new JLabel();
getContentPane().add(jLabel3);
jLabel3.setText("Current temp");
jLabel3.setBounds(7, 154, 119, 28);
jLabel3.setHorizontalAlignment(SwingConstants.RIGHT);
}
{
jLabel4 = new JLabel();
getContentPane().add(jLabel4);
jLabel4.setText("Elapsed Time");
jLabel4.setBounds(7, 182, 119, 28);
jLabel4.setHorizontalAlignment(SwingConstants.RIGHT);
}
{
powerSetting = new JTextField();
getContentPane().add(powerSetting);
powerSetting.setBounds(147, 126, 77, 28);
powerSetting.setEditable(false);
}
{
currentTemp = new JTextField();
getContentPane().add(currentTemp);
currentTemp.setBounds(147, 154, 77, 28);
currentTemp.setEditable(false);
}
{
elapsedTime = new JTextField();
getContentPane().add(elapsedTime);
elapsedTime.setBounds(147, 182, 77, 28);
elapsedTime.setEditable(false);
}
{
this.setTitle("Extruder Heat Profiler");
getContentPane().setLayout(null);
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
}
this.setSize(288, 277);
} catch (Exception e) {
e.printStackTrace();
}
}
private void startButtonActionPerformed(ActionEvent evt) {
if (profileInProgress) {
startButton.setText("Start...");
profileInProgress = false;
} else {
startButton.setText("Cancel");
profileInProgress = true;
}
}
}
|