Skip to content

Commit

Permalink
"Abort" button added.
Browse files Browse the repository at this point in the history
Button added to interrupt to send a G-code file.
  • Loading branch information
Denvi committed Oct 27, 2015
1 parent 17ae986 commit 59ded8c
Show file tree
Hide file tree
Showing 8 changed files with 348 additions and 276 deletions.
Binary file added bin/grblControl.exe
Binary file not shown.
59 changes: 49 additions & 10 deletions frmmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ void frmMain::updateControlsState() {
ui->cmdFileReset->setEnabled(!m_transferringFile && m_programModel.rowCount() > 1);
ui->cmdFileSend->setEnabled(portOpened && !m_transferringFile && m_programModel.rowCount() > 1);
ui->cmdFilePause->setEnabled(m_transferringFile);
ui->cmdFileAbort->setEnabled(m_transferringFile);
ui->actFileOpen->setEnabled(!m_transferringFile);
ui->mnuRecent->setEnabled(!m_transferringFile && ((m_recentFiles.count() > 0 && !m_heightMapMode)
|| (m_recentHeightmaps.count() > 0 && m_heightMapMode)));
Expand Down Expand Up @@ -539,6 +540,8 @@ void frmMain::sendCommand(QString command, int tableIndex)

void frmMain::grblReset()
{
qDebug() << "grbl reset";

m_serialPort.write(QByteArray(1, (char)24));
m_serialPort.flush();

Expand Down Expand Up @@ -600,6 +603,14 @@ void frmMain::onSerialPortReadyRead()
if (data[0] == '<') {
int statusIndex = -1;

// Update machine coordinates
QRegExp mpx("MPos:([^,]*),([^,]*),([^,^>]*)");
if (mpx.indexIn(data) != -1) {
ui->txtMPosX->setText(mpx.cap(1));
ui->txtMPosY->setText(mpx.cap(2));
ui->txtMPosZ->setText(mpx.cap(3));
}

// Status
QRegExp stx("<([^,^>]*)");
if (stx.indexIn(data) != -1) {
Expand Down Expand Up @@ -634,7 +645,9 @@ void frmMain::onSerialPortReadyRead()
}

// Test for job complete
if (m_transferCompleted && (statusIndex == 0 || statusIndex == 6) && m_fileCommandIndex == m_currentModel->rowCount() - 1 && m_transferringFile) {
if (m_transferCompleted && (statusIndex == 0 || statusIndex == 6) /*&& m_fileCommandIndex == m_currentModel->rowCount() - 1*/ && m_transferringFile) {
qDebug() << "job completed:" << m_fileCommandIndex << m_currentModel->rowCount() - 1;

GcodeViewParse *parser = m_currentDrawer->viewParser();

m_transferringFile = false;
Expand Down Expand Up @@ -664,8 +677,29 @@ void frmMain::onSerialPortReadyRead()
m_timerConnection.start();
m_timerStateQuery.start();
}

// Abort
if (m_aborting) {
switch (statusIndex) {
case 0: // Idle
if (!m_transferringFile && m_resetCompleted) {
m_aborting = false;
sendCommand(QString("G92X%1Y%2Z%3").arg(ui->txtMPosX->text().toDouble() - m_storedX)
.arg(ui->txtMPosY->text().toDouble() - m_storedY)
.arg(ui->txtMPosZ->text().toDouble() - m_storedZ));
if (!m_storedParserStatus.isEmpty()) sendCommand(m_storedParserStatus);
return;
}
break;
case 4: // Hold
Util::waitEvents(250);
grblReset();
break;
}
}
}

// Update work coordinates
QRegExp wpx("WPos:([^,]*),([^,]*),([^,^>]*)");
if (wpx.indexIn(data) != -1)
{
Expand Down Expand Up @@ -713,12 +747,6 @@ void frmMain::onSerialPortReadyRead()
}
}

QRegExp mpx("MPos:([^,]*),([^,]*),([^,^>]*)");
if (mpx.indexIn(data) != -1) {
ui->txtMPosX->setText(mpx.cap(1));
ui->txtMPosY->setText(mpx.cap(2));
ui->txtMPosZ->setText(mpx.cap(3));
}
} else if (data.length() > 0) {

// Processed commands
Expand Down Expand Up @@ -748,6 +776,9 @@ void frmMain::onSerialPortReadyRead()
// Update status in visualizer window
ui->glwVisualizer->setParserStatus(response.left(response.indexOf("; ")));

// Store parser status
if (m_transferringFile) m_storedParserStatus = ui->glwVisualizer->parserStatus().remove(QRegExp("\\[|\\]|M[034]+\\s"));

// Process spindle state
if (!response.contains("M5")) {
m_spindleCW = response.contains("M3");
Expand Down Expand Up @@ -1352,10 +1383,12 @@ void frmMain::on_cmdFileSend_clicked()
m_startTime.start();

m_transferCompleted = false;
m_transferringFile = true;
m_storedKeyboardControl = ui->chkKeyboardControl->isChecked();
m_transferringFile = true;
m_storedKeyboardControl = ui->chkKeyboardControl->isChecked();
ui->chkKeyboardControl->setChecked(false);

m_storedParserStatus = ui->glwVisualizer->parserStatus().remove(QRegExp("\\[|\\]|M[034]+\\s"));

#ifdef WINDOWS
if (QSysInfo::windowsVersion() >= QSysInfo::WV_WINDOWS7) {
if (m_taskBarProgress) {
Expand All @@ -1367,10 +1400,16 @@ void frmMain::on_cmdFileSend_clicked()
#endif

updateControlsState();
ui->cmdFilePause->setFocus();
ui->cmdFilePause->setFocus();
sendNextFileCommands();
}

void frmMain::on_cmdFileAbort_clicked()
{
m_serialPort.write("!");
m_aborting = true;
}

void frmMain::sendNextFileCommands() {

if (m_queue.length() > 0) return;
Expand Down
6 changes: 6 additions & 0 deletions frmmain.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ private slots:
void on_cmdHeightMapMode_clicked(bool checked);
void on_cmdHeightMapBorderAuto_clicked();

void on_cmdFileAbort_clicked();

protected:
void showEvent(QShowEvent *se);
void hideEvent(QHideEvent *he);
Expand Down Expand Up @@ -212,6 +214,8 @@ private slots:
double m_storedX = 0;
double m_storedY = 0;
double m_storedZ = 0;
QString m_storedParserStatus;

double m_safeZ = 0;
double m_rapidSpeed = 0;

Expand All @@ -238,6 +242,8 @@ private slots:
bool m_reseting = false;
bool m_resetCompleted = true;

bool m_aborting = false;

bool m_keyPressed = false;
bool m_jogBlock = false;
bool m_absoluteCoordinates;
Expand Down
15 changes: 11 additions & 4 deletions frmmain.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>870</width>
<height>826</height>
<height>845</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -1095,6 +1095,13 @@ QToolButton:checked { /* all types of tool button */
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cmdFileAbort">
<property name="text">
<string>Abort</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
Expand Down Expand Up @@ -1568,8 +1575,8 @@ QToolButton:checked { /* all types of tool button */
<rect>
<x>0</x>
<y>0</y>
<width>228</width>
<height>609</height>
<width>231</width>
<height>644</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -2627,7 +2634,7 @@ QDoubleSpinBox:focus {
<x>0</x>
<y>0</y>
<width>870</width>
<height>21</height>
<height>26</height>
</rect>
</property>
<widget class="QMenu" name="mnuFile">
Expand Down
Loading

0 comments on commit 59ded8c

Please sign in to comment.