| 363 |
Kevin |
1 |
#include "PasteController.h"
|
|
|
2 |
|
|
|
3 |
PasteController::PasteController(QWidget *parent) : QWidget(parent)
|
|
|
4 |
{
|
| 364 |
Kevin |
5 |
connected = false;
|
|
|
6 |
hotkeysEnabled = false;
|
|
|
7 |
xPos = yPos = zPos = 0.0;
|
|
|
8 |
X_Incr = X_Decr = Y_Incr = Y_Decr = Z_Incr = Z_Decr = E_Incr = false;
|
|
|
9 |
|
| 372 |
Kevin |
10 |
transmittingData = false;
|
|
|
11 |
queueCmds = new QQueue<QString>();
|
|
|
12 |
|
| 364 |
Kevin |
13 |
tmrUpdate = new QTimer(this);
|
| 372 |
Kevin |
14 |
connect(tmrUpdate, SIGNAL(timeout()), this, SLOT(MoveToolhead()));
|
| 364 |
Kevin |
15 |
|
| 363 |
Kevin |
16 |
QString helpString = "";
|
|
|
17 |
helpString.append("XY Control: Arrow Keys or H/J/K/L\n");
|
|
|
18 |
helpString.append("Z Control: PgUp/PgDown\n");
|
| 372 |
Kevin |
19 |
helpString.append(" - Hold Shift for Slower Movement\n");
|
|
|
20 |
helpString.append("Extruder Trigger: Space");
|
| 363 |
Kevin |
21 |
labelHelp = new QLabel(helpString);
|
|
|
22 |
|
|
|
23 |
QVBoxLayout *helpLayout = new QVBoxLayout();
|
|
|
24 |
helpLayout->addWidget(labelHelp);
|
|
|
25 |
|
|
|
26 |
QGroupBox *helpBox = new QGroupBox("Hotkeys:");
|
|
|
27 |
helpBox->setLayout(helpLayout);
|
|
|
28 |
|
| 364 |
Kevin |
29 |
btnEnableHotkeys = new QPushButton("&Enable Hotkeys");
|
|
|
30 |
connect(btnEnableHotkeys, SIGNAL(clicked()), this, SLOT(ToggleHotkeys()));
|
| 363 |
Kevin |
31 |
|
| 364 |
Kevin |
32 |
btnInit = new QPushButton("&Initialize Printer");
|
| 372 |
Kevin |
33 |
connect(btnInit, SIGNAL(clicked()), this, SLOT(InitializePrinter()));
|
| 364 |
Kevin |
34 |
|
|
|
35 |
btnHome = new QPushButton("&Home Printhead");
|
|
|
36 |
connect(btnHome, SIGNAL(clicked()), this, SLOT(ResetPosition()));
|
|
|
37 |
|
| 363 |
Kevin |
38 |
QVBoxLayout *miscBtnLayout = new QVBoxLayout();
|
| 372 |
Kevin |
39 |
miscBtnLayout->addWidget(btnInit);
|
| 363 |
Kevin |
40 |
miscBtnLayout->addWidget(btnEnableHotkeys);
|
|
|
41 |
miscBtnLayout->addWidget(btnHome);
|
|
|
42 |
|
|
|
43 |
QGroupBox *miscBtnBox = new QGroupBox("Preset Commands");
|
|
|
44 |
miscBtnBox->setLayout(miscBtnLayout);
|
|
|
45 |
miscBtnBox->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Maximum);
|
|
|
46 |
|
|
|
47 |
// Icons from http://ikons.piotrkwiatkowski.co.uk/index.html
|
|
|
48 |
QIcon iconUp(":/External/Resources/arrow_up.png");
|
|
|
49 |
QIcon iconDown(":/External/Resources/arrow_down.png");
|
|
|
50 |
QIcon iconLeft(":/External/Resources/arrow_left.png");
|
|
|
51 |
QIcon iconRight(":/External/Resources/arrow_right.png");
|
|
|
52 |
QIcon iconAdd(":/External/Resources/upload.png");
|
|
|
53 |
QIcon iconRemove(":/External/Resources/download.png");
|
|
|
54 |
QIcon iconDelete(":/External/Resources/close.png");
|
|
|
55 |
|
|
|
56 |
btnForward = new QToolButton();
|
|
|
57 |
btnForward->setIcon(iconUp);
|
|
|
58 |
btnForward->setIconSize(QSize(BTN_ICON_SIZE,BTN_ICON_SIZE));
|
|
|
59 |
btnForward->setAutoRaise(true);
|
| 372 |
Kevin |
60 |
connect(btnForward, SIGNAL(clicked()), this, SLOT(MoveToolheadSingle()));
|
| 363 |
Kevin |
61 |
btnBackward = new QToolButton();
|
|
|
62 |
btnBackward->setIcon(iconDown);
|
|
|
63 |
btnBackward->setIconSize(QSize(BTN_ICON_SIZE,BTN_ICON_SIZE));
|
|
|
64 |
btnBackward->setAutoRaise(true);
|
| 372 |
Kevin |
65 |
connect(btnBackward, SIGNAL(clicked()), this, SLOT(MoveToolheadSingle()));
|
| 363 |
Kevin |
66 |
btnLeft = new QToolButton();
|
|
|
67 |
btnLeft->setIcon(iconLeft);
|
|
|
68 |
btnLeft->setIconSize(QSize(BTN_ICON_SIZE,BTN_ICON_SIZE));
|
|
|
69 |
btnLeft->setAutoRaise(true);
|
| 372 |
Kevin |
70 |
connect(btnLeft, SIGNAL(clicked()), this, SLOT(MoveToolheadSingle()));
|
| 363 |
Kevin |
71 |
btnRight = new QToolButton();
|
|
|
72 |
btnRight->setIcon(iconRight);
|
|
|
73 |
btnRight->setIconSize(QSize(BTN_ICON_SIZE,BTN_ICON_SIZE));
|
|
|
74 |
btnRight->setAutoRaise(true);
|
| 372 |
Kevin |
75 |
connect(btnRight, SIGNAL(clicked()), this, SLOT(MoveToolheadSingle()));
|
| 363 |
Kevin |
76 |
btnUp = new QToolButton();
|
|
|
77 |
btnUp->setIcon(iconAdd);
|
|
|
78 |
btnUp->setIconSize(QSize(BTN_ICON_SIZE,BTN_ICON_SIZE));
|
|
|
79 |
btnUp->setAutoRaise(true);
|
| 372 |
Kevin |
80 |
connect(btnUp, SIGNAL(clicked()), this, SLOT(MoveToolheadSingle()));
|
| 363 |
Kevin |
81 |
btnDown = new QToolButton();
|
|
|
82 |
btnDown->setIcon(iconRemove);
|
|
|
83 |
btnDown->setIconSize(QSize(BTN_ICON_SIZE,BTN_ICON_SIZE));
|
|
|
84 |
btnDown->setAutoRaise(true);
|
| 372 |
Kevin |
85 |
connect(btnDown, SIGNAL(clicked()), this, SLOT(MoveToolheadSingle()));
|
| 363 |
Kevin |
86 |
btnExtrude = new QToolButton();
|
|
|
87 |
btnExtrude->setIcon(iconDelete);
|
|
|
88 |
btnExtrude->setIconSize(QSize(BTN_ICON_SIZE,BTN_ICON_SIZE));
|
|
|
89 |
btnExtrude->setAutoRaise(true);
|
| 372 |
Kevin |
90 |
connect(btnExtrude, SIGNAL(clicked()), this, SLOT(ExtrudeSingle()));
|
| 363 |
Kevin |
91 |
|
|
|
92 |
QGridLayout *btnXYELayout = new QGridLayout();
|
|
|
93 |
btnXYELayout->addWidget(btnForward, 0, 1, 1, 1);
|
|
|
94 |
btnXYELayout->addWidget(btnLeft, 1, 0, 1, 1);
|
|
|
95 |
btnXYELayout->addWidget(btnExtrude, 1, 1, 1, 1);
|
|
|
96 |
btnXYELayout->addWidget(btnRight, 1, 2, 1, 1);
|
|
|
97 |
btnXYELayout->addWidget(btnBackward, 2, 1, 1, 1);
|
|
|
98 |
|
|
|
99 |
QVBoxLayout *btnZLayout = new QVBoxLayout();
|
|
|
100 |
btnZLayout->addWidget(btnUp);
|
|
|
101 |
btnZLayout->addWidget(btnDown);
|
|
|
102 |
|
|
|
103 |
QHBoxLayout *btnNavLayout = new QHBoxLayout();
|
|
|
104 |
btnNavLayout->addLayout(btnXYELayout);
|
|
|
105 |
btnNavLayout->addLayout(btnZLayout);
|
|
|
106 |
|
|
|
107 |
QGroupBox *controlBox = new QGroupBox("Manual Printer Control");
|
|
|
108 |
controlBox->setLayout(btnNavLayout);
|
|
|
109 |
controlBox->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
|
|
|
110 |
|
|
|
111 |
labelXPos = new QLabel("X :");
|
| 364 |
Kevin |
112 |
labelXPos->setFont(QFont("", 14, QFont::Normal));
|
| 363 |
Kevin |
113 |
labelYPos = new QLabel("Y :");
|
| 364 |
Kevin |
114 |
labelYPos->setFont(QFont("", 14, QFont::Normal));
|
| 363 |
Kevin |
115 |
labelZPos = new QLabel("Z :");
|
| 364 |
Kevin |
116 |
labelZPos->setFont(QFont("", 14, QFont::Normal));
|
| 363 |
Kevin |
117 |
textXValue = new QLineEdit();
|
|
|
118 |
textXValue->setReadOnly(true);
|
|
|
119 |
textXValue->setMaximumWidth(60);
|
| 364 |
Kevin |
120 |
textXValue->setFont(QFont("", 10, QFont::Bold));
|
|
|
121 |
textXValue->setAlignment(Qt::AlignCenter);
|
| 372 |
Kevin |
122 |
textXValue->setText(QString::number(xPos, 'f', 2));
|
| 363 |
Kevin |
123 |
textYValue = new QLineEdit();
|
|
|
124 |
textYValue->setReadOnly(true);
|
|
|
125 |
textYValue->setMaximumWidth(60);
|
| 364 |
Kevin |
126 |
textYValue->setFont(QFont("", 10, QFont::Bold));
|
|
|
127 |
textYValue->setAlignment(Qt::AlignCenter);
|
| 372 |
Kevin |
128 |
textYValue->setText(QString::number(yPos, 'f', 2));
|
| 363 |
Kevin |
129 |
textZValue = new QLineEdit();
|
|
|
130 |
textZValue->setReadOnly(true);
|
|
|
131 |
textZValue->setMaximumWidth(60);
|
| 364 |
Kevin |
132 |
textZValue->setFont(QFont("", 10, QFont::Bold));
|
|
|
133 |
textZValue->setAlignment(Qt::AlignCenter);
|
| 372 |
Kevin |
134 |
textZValue->setText(QString::number(zPos, 'f', 2));
|
| 363 |
Kevin |
135 |
|
|
|
136 |
QHBoxLayout *posValueLayout = new QHBoxLayout();
|
|
|
137 |
posValueLayout->addWidget(labelXPos);
|
|
|
138 |
posValueLayout->addWidget(textXValue);
|
|
|
139 |
posValueLayout->addWidget(labelYPos);
|
|
|
140 |
posValueLayout->addWidget(textYValue);
|
|
|
141 |
posValueLayout->addWidget(labelZPos);
|
|
|
142 |
posValueLayout->addWidget(textZValue);
|
|
|
143 |
|
|
|
144 |
QGroupBox *toolheadPosBox = new QGroupBox("Toolhead Position");
|
|
|
145 |
toolheadPosBox->setLayout(posValueLayout);
|
|
|
146 |
toolheadPosBox->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
|
|
|
147 |
|
| 364 |
Kevin |
148 |
labelXYSteps = new QLabel("XY Axis Step (mm):");
|
|
|
149 |
sliderXYSteps = new QSlider(Qt::Horizontal);
|
|
|
150 |
textXYSteps = new QDoubleSpinBox();
|
|
|
151 |
textXYSteps->setMinimumWidth(60);
|
|
|
152 |
labelXYSpeed = new QLabel("XY Axis Speed (mm/s):");
|
| 363 |
Kevin |
153 |
sliderXYSpeed = new QSlider(Qt::Horizontal);
|
|
|
154 |
textXYSpeed = new QSpinBox();
|
|
|
155 |
textXYSpeed->setMinimumWidth(60);
|
| 364 |
Kevin |
156 |
labelZSteps = new QLabel("Z Axis Step (mm):");
|
|
|
157 |
sliderZSteps = new QSlider(Qt::Horizontal);
|
|
|
158 |
textZSteps = new QDoubleSpinBox();
|
|
|
159 |
textZSteps->setMinimumWidth(60);
|
|
|
160 |
labelZSpeed = new QLabel("Z Axis Speed (mm/s):");
|
| 363 |
Kevin |
161 |
sliderZSpeed = new QSlider(Qt::Horizontal);
|
|
|
162 |
textZSpeed = new QSpinBox();
|
|
|
163 |
textZSpeed->setMinimumWidth(60);
|
| 364 |
Kevin |
164 |
labelRepeatDelay = new QLabel("Repeat Delay (ms):");
|
| 363 |
Kevin |
165 |
sliderRepeatDelay = new QSlider(Qt::Horizontal);
|
|
|
166 |
textRepeatDelay = new QSpinBox();
|
|
|
167 |
textRepeatDelay->setMinimumWidth(60);
|
|
|
168 |
|
| 364 |
Kevin |
169 |
labelEForwardSteps = new QLabel("Extrude Step (mm):");
|
|
|
170 |
sliderEForwardSteps = new QSlider(Qt::Horizontal);
|
| 372 |
Kevin |
171 |
textEForwardSteps = new QDoubleSpinBox();
|
| 364 |
Kevin |
172 |
textEForwardSteps->setMinimumWidth(60);
|
|
|
173 |
labelEForwardSpeed = new QLabel("Extrude Speed (mm/s):");
|
|
|
174 |
sliderEForwardSpeed = new QSlider(Qt::Horizontal);
|
|
|
175 |
textEForwardSpeed = new QSpinBox();
|
|
|
176 |
textEForwardSpeed->setMinimumWidth(60);
|
|
|
177 |
labelEBackwardSteps = new QLabel("Retract Step (mm):");
|
|
|
178 |
sliderEBackwardSteps = new QSlider(Qt::Horizontal);
|
| 372 |
Kevin |
179 |
textEBackwardSteps = new QDoubleSpinBox();
|
| 364 |
Kevin |
180 |
textEBackwardSteps->setMinimumWidth(60);
|
|
|
181 |
labelEBackwardSpeed = new QLabel("Retract Speed: (mm/s)");
|
|
|
182 |
sliderEBackwardSpeed = new QSlider(Qt::Horizontal);
|
|
|
183 |
textEBackwardSpeed = new QSpinBox();
|
|
|
184 |
textEBackwardSpeed->setMinimumWidth(60);
|
| 372 |
Kevin |
185 |
labelExtrusionHeight = new QLabel("Extrude Height (mm):");
|
|
|
186 |
sliderExtrusionHeight = new QSlider(Qt::Horizontal);
|
|
|
187 |
textExtrusionHeight = new QDoubleSpinBox();
|
|
|
188 |
textExtrusionHeight->setMinimumWidth(60);
|
| 364 |
Kevin |
189 |
labelEZSteps = new QLabel("Z Axis Step (mm):");
|
|
|
190 |
sliderEZSteps = new QSlider(Qt::Horizontal);
|
|
|
191 |
textEZSteps = new QDoubleSpinBox();
|
|
|
192 |
textEZSteps->setMinimumWidth(60);
|
|
|
193 |
|
|
|
194 |
connect(sliderXYSteps, SIGNAL(valueChanged(int)), this, SLOT(QSliderToQDoubleSpinBox(int)));
|
|
|
195 |
connect(textXYSteps, SIGNAL(valueChanged(double)), this, SLOT(QDoubleSpinBoxToQSlider(double)));
|
| 372 |
Kevin |
196 |
sliderXYSteps->setRange(0, 1000);
|
|
|
197 |
textXYSteps->setRange(0,10);
|
| 364 |
Kevin |
198 |
textXYSteps->setSingleStep(0.1);
|
| 372 |
Kevin |
199 |
textXYSteps->setValue(0.5);
|
| 364 |
Kevin |
200 |
connect(sliderXYSpeed, SIGNAL(valueChanged(int)), textXYSpeed, SLOT(setValue(int)));
|
|
|
201 |
connect(textXYSpeed, SIGNAL(valueChanged(int)), sliderXYSpeed, SLOT(setValue(int)));
|
| 372 |
Kevin |
202 |
sliderXYSpeed->setRange(1, 4000);
|
|
|
203 |
textXYSpeed->setRange(1, 4000);
|
|
|
204 |
textXYSpeed->setSingleStep(100);
|
|
|
205 |
textXYSpeed->setValue(600);
|
| 364 |
Kevin |
206 |
connect(sliderZSteps, SIGNAL(valueChanged(int)), this, SLOT(QSliderToQDoubleSpinBox(int)));
|
|
|
207 |
connect(textZSteps, SIGNAL(valueChanged(double)), this, SLOT(QDoubleSpinBoxToQSlider(double)));
|
| 372 |
Kevin |
208 |
sliderZSteps->setRange(0, 1000);
|
|
|
209 |
textZSteps->setRange(0, 10);
|
| 364 |
Kevin |
210 |
textZSteps->setSingleStep(0.1);
|
| 372 |
Kevin |
211 |
textZSteps->setValue(0.5);
|
| 364 |
Kevin |
212 |
connect(sliderZSpeed, SIGNAL(valueChanged(int)), textZSpeed, SLOT(setValue(int)));
|
|
|
213 |
connect(textZSpeed, SIGNAL(valueChanged(int)), sliderZSpeed, SLOT(setValue(int)));
|
| 372 |
Kevin |
214 |
sliderZSpeed->setRange(1, 1000);
|
|
|
215 |
textZSpeed->setRange(1, 1000);
|
|
|
216 |
textZSpeed->setSingleStep(100);
|
|
|
217 |
textZSpeed->setValue(400);
|
| 364 |
Kevin |
218 |
connect(sliderRepeatDelay, SIGNAL(valueChanged(int)), textRepeatDelay, SLOT(setValue(int)));
|
|
|
219 |
connect(textRepeatDelay, SIGNAL(valueChanged(int)), sliderRepeatDelay, SLOT(setValue(int)));
|
| 372 |
Kevin |
220 |
sliderRepeatDelay->setRange(1, 200);
|
|
|
221 |
textRepeatDelay->setRange(1, 200);
|
|
|
222 |
textRepeatDelay->setValue(45);
|
| 364 |
Kevin |
223 |
|
| 363 |
Kevin |
224 |
QGridLayout *xyRepeatLayout = new QGridLayout();
|
| 364 |
Kevin |
225 |
xyRepeatLayout->addWidget(labelXYSteps, 0, 0);
|
|
|
226 |
xyRepeatLayout->addWidget(sliderXYSteps, 0, 1);
|
|
|
227 |
xyRepeatLayout->addWidget(textXYSteps, 0, 2);
|
| 363 |
Kevin |
228 |
xyRepeatLayout->addWidget(labelXYSpeed, 1, 0);
|
|
|
229 |
xyRepeatLayout->addWidget(sliderXYSpeed, 1, 1);
|
|
|
230 |
xyRepeatLayout->addWidget(textXYSpeed, 1, 2);
|
| 364 |
Kevin |
231 |
xyRepeatLayout->addWidget(labelZSteps, 2, 0);
|
|
|
232 |
xyRepeatLayout->addWidget(sliderZSteps, 2, 1);
|
|
|
233 |
xyRepeatLayout->addWidget(textZSteps, 2, 2);
|
| 363 |
Kevin |
234 |
xyRepeatLayout->addWidget(labelZSpeed, 3, 0);
|
|
|
235 |
xyRepeatLayout->addWidget(sliderZSpeed, 3, 1);
|
|
|
236 |
xyRepeatLayout->addWidget(textZSpeed, 3, 2);
|
|
|
237 |
xyRepeatLayout->addWidget(labelRepeatDelay, 4, 0);
|
|
|
238 |
xyRepeatLayout->addWidget(sliderRepeatDelay, 4, 1);
|
|
|
239 |
xyRepeatLayout->addWidget(textRepeatDelay, 4, 2);
|
|
|
240 |
|
|
|
241 |
QGroupBox *xyRepeatBox = new QGroupBox("Movement Settings");
|
|
|
242 |
xyRepeatBox->setLayout(xyRepeatLayout);
|
|
|
243 |
|
| 372 |
Kevin |
244 |
connect(sliderEForwardSteps, SIGNAL(valueChanged(int)), this, SLOT(QSliderToQDoubleSpinBox(int)));
|
|
|
245 |
connect(textEForwardSteps, SIGNAL(valueChanged(double)), this, SLOT(QDoubleSpinBoxToQSlider(double)));
|
|
|
246 |
sliderEForwardSteps->setRange(0, 10000);
|
|
|
247 |
textEForwardSteps->setRange(0, 100);
|
|
|
248 |
textEForwardSteps->setSingleStep(0.1);
|
|
|
249 |
textEForwardSteps->setValue(8);
|
| 364 |
Kevin |
250 |
connect(sliderEForwardSpeed, SIGNAL(valueChanged(int)), textEForwardSpeed, SLOT(setValue(int)));
|
|
|
251 |
connect(textEForwardSpeed, SIGNAL(valueChanged(int)), sliderEForwardSpeed, SLOT(setValue(int)));
|
|
|
252 |
sliderEForwardSpeed->setRange(1, 10000);
|
|
|
253 |
textEForwardSpeed->setRange(1, 10000);
|
| 372 |
Kevin |
254 |
textEForwardSpeed->setSingleStep(100);
|
|
|
255 |
textEForwardSpeed->setValue(800);
|
|
|
256 |
connect(sliderEBackwardSteps, SIGNAL(valueChanged(int)), this, SLOT(QSliderToQDoubleSpinBox(int)));
|
|
|
257 |
connect(textEBackwardSteps, SIGNAL(valueChanged(double)), this, SLOT(QDoubleSpinBoxToQSlider(double)));
|
|
|
258 |
sliderEBackwardSteps->setRange(0, 10000);
|
|
|
259 |
textEBackwardSteps->setRange(0, 100);
|
|
|
260 |
textEBackwardSteps->setSingleStep(0.1);
|
|
|
261 |
textEBackwardSteps->setValue(2);
|
| 364 |
Kevin |
262 |
connect(sliderEBackwardSpeed, SIGNAL(valueChanged(int)), textEBackwardSpeed, SLOT(setValue(int)));
|
|
|
263 |
connect(textEBackwardSpeed, SIGNAL(valueChanged(int)), sliderEBackwardSpeed, SLOT(setValue(int)));
|
|
|
264 |
sliderEBackwardSpeed->setRange(1, 10000);
|
|
|
265 |
textEBackwardSpeed->setRange(1, 10000);
|
| 372 |
Kevin |
266 |
textEBackwardSpeed->setSingleStep(100);
|
|
|
267 |
textEBackwardSpeed->setValue(1600);
|
|
|
268 |
connect(sliderExtrusionHeight, SIGNAL(valueChanged(int)), this, SLOT(QSliderToQDoubleSpinBox(int)));
|
|
|
269 |
connect(textExtrusionHeight, SIGNAL(valueChanged(double)), this, SLOT(QDoubleSpinBoxToQSlider(double)));
|
|
|
270 |
connect(textExtrusionHeight, SIGNAL(valueChanged(double)), this, SLOT(SetBaseHeight()));
|
|
|
271 |
sliderExtrusionHeight->setRange(0, 400);
|
|
|
272 |
textExtrusionHeight->setRange(0, 4);
|
|
|
273 |
textExtrusionHeight->setSingleStep(0.1);
|
|
|
274 |
textExtrusionHeight->setValue(2);
|
| 364 |
Kevin |
275 |
connect(sliderEZSteps, SIGNAL(valueChanged(int)), this, SLOT(QSliderToQDoubleSpinBox(int)));
|
|
|
276 |
connect(textEZSteps, SIGNAL(valueChanged(double)), this, SLOT(QDoubleSpinBoxToQSlider(double)));
|
| 372 |
Kevin |
277 |
connect(textEZSteps, SIGNAL(valueChanged(double)), this, SLOT(SetBaseHeight()));
|
| 364 |
Kevin |
278 |
sliderEZSteps->setRange(0, 1000);
|
|
|
279 |
textEZSteps->setRange(0, 10);
|
|
|
280 |
textEZSteps->setSingleStep(0.1);
|
|
|
281 |
textEZSteps->setValue(2);
|
| 363 |
Kevin |
282 |
|
|
|
283 |
QGridLayout *extruderLayout = new QGridLayout();
|
| 364 |
Kevin |
284 |
extruderLayout->addWidget(labelEForwardSteps, 0, 0);
|
|
|
285 |
extruderLayout->addWidget(sliderEForwardSteps, 0, 1);
|
|
|
286 |
extruderLayout->addWidget(textEForwardSteps, 0, 2);
|
| 363 |
Kevin |
287 |
extruderLayout->addWidget(labelEForwardSpeed, 1, 0);
|
|
|
288 |
extruderLayout->addWidget(sliderEForwardSpeed, 1, 1);
|
|
|
289 |
extruderLayout->addWidget(textEForwardSpeed, 1, 2);
|
| 364 |
Kevin |
290 |
extruderLayout->addWidget(labelEBackwardSteps, 2, 0);
|
|
|
291 |
extruderLayout->addWidget(sliderEBackwardSteps, 2, 1);
|
|
|
292 |
extruderLayout->addWidget(textEBackwardSteps, 2, 2);
|
| 363 |
Kevin |
293 |
extruderLayout->addWidget(labelEBackwardSpeed, 4, 0);
|
|
|
294 |
extruderLayout->addWidget(sliderEBackwardSpeed, 4, 1);
|
|
|
295 |
extruderLayout->addWidget(textEBackwardSpeed, 4, 2);
|
| 372 |
Kevin |
296 |
extruderLayout->addWidget(labelExtrusionHeight, 5, 0);
|
|
|
297 |
extruderLayout->addWidget(sliderExtrusionHeight, 5, 1);
|
|
|
298 |
extruderLayout->addWidget(textExtrusionHeight, 5, 2);
|
|
|
299 |
extruderLayout->addWidget(labelEZSteps, 6, 0);
|
|
|
300 |
extruderLayout->addWidget(sliderEZSteps, 6, 1);
|
|
|
301 |
extruderLayout->addWidget(textEZSteps, 6, 2);
|
| 363 |
Kevin |
302 |
|
|
|
303 |
QGroupBox *extruderBox = new QGroupBox("Extruder Settings");
|
|
|
304 |
extruderBox->setLayout(extruderLayout);
|
|
|
305 |
|
|
|
306 |
QVBoxLayout *column1Layout = new QVBoxLayout();
|
|
|
307 |
column1Layout->addWidget(controlBox, 0, Qt::AlignTop);
|
|
|
308 |
column1Layout->addWidget(miscBtnBox, 0, Qt::AlignTop);
|
|
|
309 |
column1Layout->addWidget(helpBox, 1, Qt::AlignTop);
|
|
|
310 |
|
|
|
311 |
QVBoxLayout *column2Layout = new QVBoxLayout();
|
|
|
312 |
column2Layout->addWidget(toolheadPosBox);
|
|
|
313 |
column2Layout->addWidget(xyRepeatBox);
|
|
|
314 |
column2Layout->addWidget(extruderBox);
|
|
|
315 |
|
|
|
316 |
QHBoxLayout *mainLayout = new QHBoxLayout();
|
|
|
317 |
mainLayout->addLayout(column1Layout);
|
|
|
318 |
mainLayout->addLayout(column2Layout);
|
|
|
319 |
|
| 372 |
Kevin |
320 |
EnableTransmit(false);
|
|
|
321 |
|
| 363 |
Kevin |
322 |
setLayout(mainLayout);
|
|
|
323 |
setFixedSize(sizeHint());
|
|
|
324 |
}
|
|
|
325 |
|
|
|
326 |
PasteController::~PasteController()
|
|
|
327 |
{
|
|
|
328 |
|
|
|
329 |
}
|
|
|
330 |
|
| 364 |
Kevin |
331 |
void PasteController::EnableTransmit(bool en) {
|
|
|
332 |
connected = en;
|
| 372 |
Kevin |
333 |
btnEnableHotkeys->setEnabled(en);
|
|
|
334 |
btnInit->setEnabled(en);
|
|
|
335 |
btnHome->setEnabled(en);
|
|
|
336 |
btnForward->setEnabled(en);
|
|
|
337 |
btnBackward->setEnabled(en);
|
|
|
338 |
btnLeft->setEnabled(en);
|
|
|
339 |
btnRight->setEnabled(en);
|
|
|
340 |
btnDown->setEnabled(en);
|
|
|
341 |
btnUp->setEnabled(en);
|
|
|
342 |
btnExtrude->setEnabled(en);
|
| 364 |
Kevin |
343 |
}
|
|
|
344 |
|
| 372 |
Kevin |
345 |
void PasteController::InitializePrinter() {
|
|
|
346 |
queueCmds->enqueue("G90\n"); // Absolute positioning
|
|
|
347 |
queueCmds->enqueue("M83\n"); // Relative extrusion
|
|
|
348 |
queueCmds->enqueue("M204 S3000"); // Default acceleration (movement)
|
|
|
349 |
queueCmds->enqueue("M205 X10"); // Maximum XY jerk
|
|
|
350 |
queueCmds->enqueue("M302"); // Allow cold extrusions
|
|
|
351 |
|
|
|
352 |
if (!transmittingData) {
|
|
|
353 |
transmittingData = true;
|
|
|
354 |
emit TransmitData(queueCmds->head().toUtf8());
|
|
|
355 |
}
|
|
|
356 |
|
|
|
357 |
ResetPosition();
|
|
|
358 |
SetBaseHeight();
|
|
|
359 |
}
|
|
|
360 |
|
| 364 |
Kevin |
361 |
void PasteController::ToggleHotkeys() {
|
|
|
362 |
if (hotkeysEnabled) {
|
|
|
363 |
qApp->removeEventFilter(this);
|
|
|
364 |
btnEnableHotkeys->setText("&Enable Hotkeys");
|
|
|
365 |
} else {
|
|
|
366 |
qApp->installEventFilter(this);
|
|
|
367 |
btnEnableHotkeys->setText("&Disable Hotkeys");
|
|
|
368 |
}
|
|
|
369 |
hotkeysEnabled = !hotkeysEnabled;
|
|
|
370 |
}
|
|
|
371 |
|
| 372 |
Kevin |
372 |
void PasteController::MoveToolhead() {
|
|
|
373 |
if (X_Incr && !X_Decr)
|
|
|
374 |
xPos = (xPos + textXYSteps->value() < X_MAX) ? xPos + textXYSteps->value() : X_MAX;
|
|
|
375 |
if (!X_Incr && X_Decr)
|
|
|
376 |
xPos = (xPos - textXYSteps->value() > X_MIN) ? xPos - textXYSteps->value() : X_MIN;
|
|
|
377 |
if (Y_Incr && !Y_Decr)
|
|
|
378 |
yPos = (yPos + textXYSteps->value() < Y_MAX) ? yPos + textXYSteps->value() : Y_MAX;
|
|
|
379 |
if (!Y_Incr && Y_Decr)
|
|
|
380 |
yPos = (yPos - textXYSteps->value() > Y_MIN) ? yPos - textXYSteps->value() : Y_MIN;
|
|
|
381 |
if (Z_Incr && !Z_Decr)
|
|
|
382 |
zPos = (zPos + textZSteps->value() < Z_MAX) ? zPos + textZSteps->value() : Z_MAX;
|
|
|
383 |
if (!Z_Incr && Z_Decr)
|
|
|
384 |
zPos = (zPos - textZSteps->value() > Z_MIN) ? zPos - textZSteps->value() : Z_MIN;
|
| 364 |
Kevin |
385 |
|
| 372 |
Kevin |
386 |
UpdatePosition();
|
|
|
387 |
|
|
|
388 |
QString str;
|
|
|
389 |
QTextStream strIO(&str);
|
|
|
390 |
if (Z_Incr || Z_Decr) {
|
|
|
391 |
strIO << "G0";
|
|
|
392 |
strIO << " Z" << zPos;
|
|
|
393 |
strIO << " F" << textZSpeed->value();
|
|
|
394 |
strIO << "\n";
|
|
|
395 |
} else {
|
|
|
396 |
strIO << "G0";
|
|
|
397 |
strIO << " X" << xPos;
|
|
|
398 |
strIO << " Y" << yPos;
|
|
|
399 |
strIO << " F" << textXYSpeed->value();
|
|
|
400 |
strIO << "\n";
|
|
|
401 |
}
|
|
|
402 |
|
|
|
403 |
queueCmds->enqueue(str);
|
|
|
404 |
if (!transmittingData) {
|
|
|
405 |
transmittingData = true;
|
|
|
406 |
emit TransmitData(queueCmds->head().toUtf8());
|
|
|
407 |
}
|
| 364 |
Kevin |
408 |
}
|
|
|
409 |
|
| 372 |
Kevin |
410 |
void PasteController::MoveToolheadSingle() {
|
| 364 |
Kevin |
411 |
if (QObject::sender() == btnRight) xPos += textXYSteps->value();
|
|
|
412 |
if (QObject::sender() == btnLeft) xPos -= textXYSteps->value();
|
|
|
413 |
if (QObject::sender() == btnForward) yPos += textXYSteps->value();
|
|
|
414 |
if (QObject::sender() == btnBackward) yPos -= textXYSteps->value();
|
|
|
415 |
if (QObject::sender() == btnUp) zPos += textZSteps->value();
|
|
|
416 |
if (QObject::sender() == btnDown) zPos -= textZSteps->value();
|
|
|
417 |
|
| 372 |
Kevin |
418 |
UpdatePosition();
|
|
|
419 |
|
|
|
420 |
QString str;
|
|
|
421 |
QTextStream strIO(&str);
|
|
|
422 |
if (QObject::sender() == btnRight || QObject::sender() == btnLeft ||
|
|
|
423 |
QObject::sender() == btnForward || QObject::sender() == btnBackward) {
|
|
|
424 |
strIO << "G0";
|
|
|
425 |
strIO << " X" << xPos;
|
|
|
426 |
strIO << " Y" << yPos;
|
|
|
427 |
strIO << " F" << textXYSpeed->value();
|
|
|
428 |
strIO << "\n";
|
|
|
429 |
} else if (QObject::sender() == btnUp || QObject::sender() == btnDown) {
|
|
|
430 |
strIO << "G0";
|
|
|
431 |
strIO << " Z" << zPos;
|
|
|
432 |
strIO << " F" << textZSpeed->value();
|
|
|
433 |
strIO << "\n";
|
|
|
434 |
}
|
|
|
435 |
|
|
|
436 |
queueCmds->enqueue(str);
|
|
|
437 |
if (!transmittingData) {
|
|
|
438 |
transmittingData = true;
|
|
|
439 |
emit TransmitData(queueCmds->head().toUtf8());
|
|
|
440 |
}
|
|
|
441 |
}
|
|
|
442 |
|
|
|
443 |
void PasteController::UpdatePosition() {
|
| 364 |
Kevin |
444 |
textXValue->setText(QString::number(xPos, 'f', 2));
|
|
|
445 |
textYValue->setText(QString::number(yPos, 'f', 2));
|
|
|
446 |
textZValue->setText(QString::number(zPos, 'f', 2));
|
|
|
447 |
}
|
|
|
448 |
|
| 372 |
Kevin |
449 |
void PasteController::ExtrudeSingle() {
|
|
|
450 |
QString str;
|
|
|
451 |
// Move printdown down
|
|
|
452 |
str = "G0 Z" + QString::number(textExtrusionHeight->value()) +
|
|
|
453 |
" F" + QString::number(textZSpeed->value()) + "\n";
|
|
|
454 |
zPos = textExtrusionHeight->value();
|
|
|
455 |
queueCmds->enqueue(str);
|
|
|
456 |
|
|
|
457 |
// Extrude paste
|
|
|
458 |
str = "G0 E-" + QString::number(textEForwardSteps->value()) +
|
|
|
459 |
" F" + QString::number(textEForwardSpeed->value()) + "\n";
|
|
|
460 |
queueCmds->enqueue(str);
|
|
|
461 |
|
|
|
462 |
// Retract paste
|
|
|
463 |
str = "G0 E" + QString::number(textEBackwardSteps->value()) +
|
|
|
464 |
" F" + QString::number(textEBackwardSpeed->value()) + "\n";
|
|
|
465 |
queueCmds->enqueue(str);
|
|
|
466 |
|
|
|
467 |
// Move printhead up
|
|
|
468 |
str = "G0 Z" + QString::number(textEZSteps->value() + textExtrusionHeight->value()) +
|
|
|
469 |
" F" + QString::number(textZSpeed->value()) + "\n";
|
|
|
470 |
zPos = textEZSteps->value() + textExtrusionHeight->value();
|
|
|
471 |
queueCmds->enqueue(str);
|
|
|
472 |
|
|
|
473 |
if (!transmittingData) {
|
|
|
474 |
transmittingData = true;
|
|
|
475 |
emit TransmitData(queueCmds->head().toUtf8());
|
|
|
476 |
}
|
| 364 |
Kevin |
477 |
}
|
|
|
478 |
|
| 372 |
Kevin |
479 |
void PasteController::ResetPosition() {
|
|
|
480 |
xPos = yPos = zPos = 0;
|
|
|
481 |
|
|
|
482 |
queueCmds->enqueue("G28\n"); // Home printhead
|
|
|
483 |
if (!transmittingData) {
|
|
|
484 |
transmittingData = true;
|
|
|
485 |
emit TransmitData(queueCmds->head().toUtf8());
|
|
|
486 |
}
|
|
|
487 |
|
|
|
488 |
MoveToolhead();
|
|
|
489 |
}
|
|
|
490 |
|
|
|
491 |
void PasteController::ProcessData(QByteArray data) {
|
|
|
492 |
static QString recvData;
|
|
|
493 |
if (transmittingData) {
|
|
|
494 |
// Need to wait for acknowledgement from the printer after each command
|
|
|
495 |
recvData.append(QString(data));
|
|
|
496 |
while (recvData.indexOf('\n') != -1) {
|
|
|
497 |
QString ret = recvData.left(recvData.indexOf('\n')+1);
|
|
|
498 |
recvData.remove(0, recvData.indexOf('\n')+1);
|
|
|
499 |
bool transmit = false;
|
|
|
500 |
if (ret.startsWith("ok")) {
|
|
|
501 |
// Last command successfully processed
|
|
|
502 |
queueCmds->dequeue();
|
|
|
503 |
transmit = true;
|
|
|
504 |
} else if (ret.startsWith("rs" || ret.startsWith("Resend"))) {
|
|
|
505 |
transmit = true;
|
|
|
506 |
} else if (ret.startsWith("!!" || ret.startsWith("Error"))) {
|
|
|
507 |
emit UpdateStatus("Hardware fault detected!");
|
|
|
508 |
queueCmds->clear();
|
|
|
509 |
} else if (ret.startsWith("echo")) {
|
|
|
510 |
// Ignore anything else sent
|
|
|
511 |
}
|
|
|
512 |
if (transmit && !queueCmds->isEmpty()) {
|
|
|
513 |
emit TransmitData(queueCmds->head().toUtf8());
|
|
|
514 |
} else if (queueCmds->isEmpty()){
|
|
|
515 |
transmittingData = false;
|
|
|
516 |
}
|
|
|
517 |
}
|
|
|
518 |
}
|
|
|
519 |
}
|
|
|
520 |
|
|
|
521 |
void PasteController::SetBaseHeight() {
|
|
|
522 |
if (connected) {
|
|
|
523 |
QString str = "G0 Z" + QString::number(textEZSteps->value() + textExtrusionHeight->value()) +
|
|
|
524 |
" F" + QString::number(textZSpeed->value()) + "\n";
|
|
|
525 |
zPos = textEZSteps->value() + textExtrusionHeight->value();
|
|
|
526 |
queueCmds->enqueue(str);
|
|
|
527 |
|
|
|
528 |
if (!transmittingData) {
|
|
|
529 |
transmittingData = true;
|
|
|
530 |
emit TransmitData(queueCmds->head().toUtf8());
|
|
|
531 |
}
|
|
|
532 |
UpdatePosition();
|
|
|
533 |
}
|
|
|
534 |
}
|
|
|
535 |
|
| 364 |
Kevin |
536 |
void PasteController::QSliderToQDoubleSpinBox(int) {
|
|
|
537 |
textXYSteps->setValue((double)sliderXYSteps->value()/100);
|
|
|
538 |
textZSteps->setValue((double)sliderZSteps->value()/100);
|
|
|
539 |
textEZSteps->setValue((double)sliderEZSteps->value()/100);
|
| 372 |
Kevin |
540 |
textEForwardSteps->setValue((double)sliderEForwardSteps->value()/100);
|
|
|
541 |
textEBackwardSteps->setValue((double)sliderEBackwardSteps->value()/100);
|
|
|
542 |
textExtrusionHeight->setValue((double)sliderExtrusionHeight->value()/100);
|
| 364 |
Kevin |
543 |
}
|
|
|
544 |
|
|
|
545 |
void PasteController::QDoubleSpinBoxToQSlider(double) {
|
|
|
546 |
sliderXYSteps->setValue(textXYSteps->value()*100);
|
|
|
547 |
sliderZSteps->setValue(textZSteps->value()*100);
|
|
|
548 |
sliderEZSteps->setValue(textEZSteps->value()*100);
|
| 372 |
Kevin |
549 |
sliderEForwardSteps->setValue((double)textEForwardSteps->value()*100);
|
|
|
550 |
sliderEBackwardSteps->setValue((double)textEBackwardSteps->value()*100);
|
|
|
551 |
sliderExtrusionHeight->setValue((double)textExtrusionHeight->value()*100);
|
| 364 |
Kevin |
552 |
}
|
|
|
553 |
|
|
|
554 |
bool PasteController::eventFilter(QObject *obj, QEvent *event)
|
|
|
555 |
{
|
|
|
556 |
// Only process keyboard press and release events
|
|
|
557 |
if (event->type() == QEvent::KeyPress) {
|
|
|
558 |
QKeyEvent *keyevent = static_cast<QKeyEvent*>(event);
|
|
|
559 |
// QKeySequence seq = keyevent->modifiers() + keyevent->key();
|
|
|
560 |
|
|
|
561 |
if (hotkeysEnabled) {
|
|
|
562 |
if (keyevent->isAutoRepeat()) return true;
|
|
|
563 |
bool keychange = false;
|
|
|
564 |
if (keyevent->key() == Qt::Key_Left || keyevent->key() == Qt::Key_H) {
|
|
|
565 |
btnLeft->setDown(true);
|
|
|
566 |
X_Decr = keychange = true;
|
|
|
567 |
}
|
|
|
568 |
if (keyevent->key() == Qt::Key_Right || keyevent->key() == Qt::Key_L) {
|
|
|
569 |
btnRight->setDown(true);
|
|
|
570 |
X_Incr = keychange = true;
|
|
|
571 |
}
|
|
|
572 |
if (keyevent->key() == Qt::Key_Up || keyevent->key() == Qt::Key_K) {
|
|
|
573 |
btnForward->setDown(true);
|
|
|
574 |
Y_Incr = keychange = true;
|
|
|
575 |
}
|
|
|
576 |
if (keyevent->key() == Qt::Key_Down || keyevent->key() == Qt::Key_J) {
|
|
|
577 |
btnBackward->setDown(true);
|
|
|
578 |
Y_Decr = keychange = true;
|
|
|
579 |
}
|
|
|
580 |
if (keyevent->key() == Qt::Key_PageDown) {
|
|
|
581 |
btnDown->setDown(true);
|
|
|
582 |
Z_Decr = keychange = true;
|
|
|
583 |
}
|
|
|
584 |
if (keyevent->key() == Qt::Key_PageUp) {
|
|
|
585 |
btnUp->setDown(true);
|
|
|
586 |
Z_Incr = keychange = true;
|
|
|
587 |
}
|
|
|
588 |
if (keyevent->key() == Qt::Key_Space) {
|
|
|
589 |
btnExtrude->setDown(true);
|
|
|
590 |
E_Incr = keychange = true;
|
|
|
591 |
}
|
| 372 |
Kevin |
592 |
if (E_Incr) {
|
|
|
593 |
ExtrudeSingle();
|
|
|
594 |
} else if (X_Incr || X_Decr || Y_Incr || Y_Decr || Z_Incr || Z_Decr) {
|
|
|
595 |
MoveToolhead();
|
|
|
596 |
if (keyevent->modifiers() == Qt::ShiftModifier) {
|
|
|
597 |
tmrUpdate->start(textRepeatDelay->value() * SLOW_MULTIPLIER);
|
|
|
598 |
} else {
|
|
|
599 |
tmrUpdate->start(textRepeatDelay->value());
|
|
|
600 |
}
|
| 364 |
Kevin |
601 |
}
|
|
|
602 |
if (keychange) return true;
|
|
|
603 |
}
|
|
|
604 |
} else if (event->type() == QEvent::KeyRelease) {
|
|
|
605 |
QKeyEvent *keyevent = static_cast<QKeyEvent*>(event);
|
|
|
606 |
// QKeySequence seq = keyevent->modifiers() + keyevent->key();
|
|
|
607 |
|
|
|
608 |
if (hotkeysEnabled) {
|
|
|
609 |
if (keyevent->isAutoRepeat()) return true;
|
|
|
610 |
bool keychange = false;
|
|
|
611 |
if (keyevent->key() == Qt::Key_Left || keyevent->key() == Qt::Key_H) {
|
|
|
612 |
btnLeft->setDown(false);
|
|
|
613 |
X_Decr = keychange = false;
|
|
|
614 |
}
|
|
|
615 |
if (keyevent->key() == Qt::Key_Right || keyevent->key() == Qt::Key_L) {
|
|
|
616 |
btnRight->setDown(false);
|
|
|
617 |
X_Incr = keychange = false;
|
|
|
618 |
}
|
|
|
619 |
if (keyevent->key() == Qt::Key_Up || keyevent->key() == Qt::Key_K) {
|
|
|
620 |
btnForward->setDown(false);
|
|
|
621 |
Y_Incr = keychange = false;
|
|
|
622 |
}
|
|
|
623 |
if (keyevent->key() == Qt::Key_Down || keyevent->key() == Qt::Key_J) {
|
|
|
624 |
btnBackward->setDown(false);
|
|
|
625 |
Y_Decr = keychange = false;
|
|
|
626 |
}
|
|
|
627 |
if (keyevent->key() == Qt::Key_PageDown) {
|
|
|
628 |
btnDown->setDown(false);
|
|
|
629 |
Z_Decr = keychange = false;
|
|
|
630 |
}
|
|
|
631 |
if (keyevent->key() == Qt::Key_PageUp) {
|
|
|
632 |
btnUp->setDown(false);
|
|
|
633 |
Z_Incr = keychange = false;
|
|
|
634 |
}
|
|
|
635 |
if (keyevent->key() == Qt::Key_Space) {
|
|
|
636 |
btnExtrude->setDown(false);
|
|
|
637 |
E_Incr = keychange = false;
|
|
|
638 |
}
|
| 372 |
Kevin |
639 |
if (!X_Incr && !X_Decr && !Y_Incr && !Y_Decr && !Z_Incr && !Z_Decr) {
|
| 364 |
Kevin |
640 |
tmrUpdate->stop();
|
|
|
641 |
}
|
|
|
642 |
if (keychange) return true;
|
|
|
643 |
}
|
|
|
644 |
}
|
|
|
645 |
|
|
|
646 |
return QWidget::eventFilter(obj, event);
|
|
|
647 |
}
|