Skip to content

Commit

Permalink
v2.1x1 Basic version for Windows and Linux with flow control fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zapmaker committed Oct 6, 2012
1 parent 05f6f27 commit 424534b
Show file tree
Hide file tree
Showing 26 changed files with 525 additions and 1,736 deletions.
11 changes: 11 additions & 0 deletions .gitignore
@@ -0,0 +1,11 @@
GcodeSenderGUIthreads.pro.user
Makefile
Makefile.Debug
Makefile.Release
debug/
release/
favs.txt
object_script.GcodeSenderGUI.Debug
object_script.GcodeSenderGUI.Release
settings
ui_*.h
1 change: 1 addition & 0 deletions GrblController.qrc
Expand Up @@ -5,5 +5,6 @@
<file>img/logotiny.PNG</file>
<file>img/right.PNG</file>
<file>img/up.PNG</file>
<file>img/zapmaker-logo-130.png</file>
</qresource>
</RCC>
36 changes: 36 additions & 0 deletions README
@@ -1,5 +1,41 @@
Gcode sender, monitor and homing tool for GRBL for Windows and Linux systems.

Enhanced by Zapmaker. Kosme did a great deal of excellent foundation work on this
project - my hat is off to him. Now we take this code to the next level.

The current code was tested with real milling projects using the Shapeoko and works
pretty well, it gets the job done. There are a number of enhancements I would like
to add. See file TODO for this list.

Before you can do anything:
1. Download Qt Creator (http://qt-project.org/downloads)
2. Open the project file ending with .pro
3. Build the executable (Windows and Linux)

V2.1x1

NOTE: Changes were only focused on Arduino GRBL capabilities with the Shapeoko, so
things like Tool Change were not tested.

Enhancements
- Improved handling of response code - this is the most significant change as it
ensures reliable send/response handling when sending a file to the Grbl processor.
- Manual command now allows hitting return and command is sent. No need to press Go.
- Default job step size changed from 0.01 to 1 mm
- Compiles and runs under Linux now (tested with Debian and latest Qt)
- Works with old 168 Arduino processor (except that old code is buggy and not recommended)
- Disabled "go to home at end of job". The arduino code doesn't handle it correctly
and mills straight back into and through your work. Checkbox in settings has no effect.

Bug fixes
- Fixed crash when options file is not present the first time run
- Fixed crash when trying to get GRBL settings from device
- Settings work with 168 (8 settings) and 328 processors (10 settings)
- Fixed Stop to call proper routine stopsig - now Stop button works correctly

-------------------------------------------------------------
Fork by Zapmaker at this rev
-------------------------------------------------------------
v2.1a

Bug fixes
Expand Down
22 changes: 22 additions & 0 deletions TODO
@@ -0,0 +1,22 @@
This file contains enhancements the developer would like to implement:

- Ensure that output window shows all text
- Fix default go to home on completion issue (right now that is commented out to prevent destroying work/bit)
- Strange bug when using Z jog after completing file run - the command spins up the z motor speed quite a lot
- Consolidate duplicated waitForPrompt code
- Provide means to handle max timeout (i.e. timed out waiting popup - ok to quit or continue waiting?)
- Setting for default wait timeout
- Handle "error" response and display error message
- Handle 0.5 168 processor bug: binary response garbage causes failure (ignore and resend?)
- Store last good port used and display at startup so you don't have to pick it
- Show only available com ports
- Add option to auto connect to last port
- Verify that entering x/y/z move commands are absolute and not relative
- Find way to remote reset grbl controller with button added so don't have to physically reset arduino
- Fix enabling Begin button when already started
- Provide diagnostic response view
- Provide counter showing time waiting for a response if time > 5s
- Remove radio buttons - allow user to do any of the three operations without special mode state requirement
- Popup dialog when successful send is complete
- Print current GRBL settings
- Compile for Mac
24 changes: 20 additions & 4 deletions about.ui
Expand Up @@ -52,7 +52,7 @@
<property name="geometry">
<rect>
<x>180</x>
<y>70</y>
<y>60</y>
<width>201</width>
<height>91</height>
</rect>
Expand All @@ -68,7 +68,7 @@
<property name="geometry">
<rect>
<x>180</x>
<y>40</y>
<y>30</y>
<width>211</width>
<height>31</height>
</rect>
Expand All @@ -81,7 +81,7 @@
</font>
</property>
<property name="text">
<string>Grbl Controller 2.1</string>
<string>Grbl Controller 2.1x1</string>
</property>
</widget>
<widget class="QLabel" name="label_2">
Expand All @@ -94,7 +94,23 @@
</rect>
</property>
<property name="text">
<string>Build 290312</string>
<string/>
</property>
</widget>
<widget class="QLabel" name="label_iconZ">
<property name="geometry">
<rect>
<x>20</x>
<y>110</y>
<width>130</width>
<height>33</height>
</rect>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="GrblController.qrc">:/img/zapmaker-logo-130.png</pixmap>
</property>
</widget>
</widget>
Expand Down
194 changes: 129 additions & 65 deletions grbldialog.cpp
Expand Up @@ -28,69 +28,74 @@ void GrblDialog::setSettings()
change[i]=false;
}
//ui->tableWidget->item(0,1)->setFlags(Qt::NoItemFlags);
QTableWidgetItem *param0 = new QTableWidgetItem;
QTableWidgetItem *param1 = new QTableWidgetItem;
QTableWidgetItem *param2 = new QTableWidgetItem;
QTableWidgetItem *param3 = new QTableWidgetItem;
QTableWidgetItem *param4 = new QTableWidgetItem;
QTableWidgetItem *param5 = new QTableWidgetItem;
QTableWidgetItem *param6 = new QTableWidgetItem;
QTableWidgetItem *param7 = new QTableWidgetItem;
QTableWidgetItem *param8 = new QTableWidgetItem;
QTableWidgetItem *param9 = new QTableWidgetItem;
ui->tableWidget->setItem(0,0,param0);
ui->tableWidget->setItem(1,0,param1);
ui->tableWidget->setItem(2,0,param2);
ui->tableWidget->setItem(3,0,param3);
ui->tableWidget->setItem(4,0,param4);
ui->tableWidget->setItem(5,0,param5);
ui->tableWidget->setItem(6,0,param6);
ui->tableWidget->setItem(7,0,param7);
ui->tableWidget->setItem(8,0,param8);
ui->tableWidget->setItem(9,0,param9);

i=0;
#ifndef DISCONNECTED
QTableWidgetItem * params[10];
for (i = 0; i < 10; i++)
{
params[i] = new QTableWidgetItem;
ui->tableWidget->setItem(i,0,params[i]);
}

char buf[]="$\r";
port.SendBuf(port_nr,buf,2);
#define BUF_SIZE 300
#define RESPONSE_EXPECT "ok\r\n"
char tmp[BUF_SIZE + 1] = {0};
int count = 0;
bool status = true;
QString result;
while (!result.contains(RESPONSE_EXPECT))
{
int n = port.PollComport(port_nr, tmp, BUF_SIZE);
if (n == 0)
{
count++;
#ifdef Q_WS_X11
usleep(100000);
usleep(100000); // sleep for 100 milliSeconds
#else
Sleep(100);
#endif
}
else
{
tmp[n] = 0;
result.append(tmp);
//printf("GOT:%s\n", tmp); fflush(stdout);
count = 0;
}
#ifdef Q_WS_X11
usleep(100000); // sleep for 100 milliSeconds
#else
Sleep(100);
#endif
QString linea="";
char buf[]="$\r";
char read[223];
int n=0;
//while(n==0)
// n=RS232().PollComport(port_nr,read,50);
//n=port.PollComport(port_nr,read,50);
port.SendBuf(port_nr,buf,2);
while(i<10)
if (count > 50)
{\
status = false;
break;
}
}

if (status)
{
for (i = 0; i < 10; i++)
{
n=port.PollComport(port_nr,read,223);
linea.append(read);
while(linea.contains(QRegExp("\\$\\d = ")))
if (!result.contains(QRegExp("\\$\\d = ")))
{
ui->tableWidget->item(i,0)->setFont(QFont("Tahoma",10,87,false));
linea = linea.mid(linea.indexOf("$")+5,-1);
values[i++]=linea.mid(0,linea.indexOf(" ")).toFloat();
}
if(i>=10)
// only collect as many as provided up to 10
break;
}

ui->tableWidget->item(i,0)->setFont(QFont("Tahoma",10,87,false));
result = result.mid(result.indexOf(QRegExp("\\$\\d = "))+5,-1);
values[i]=result.mid(0,result.indexOf(" ")).toFloat();
}

for (int j = 0; j < i; j++)
{
params[j]->setText(QString::number(values[j]));
}
#endif
i=0;
param0->setText(QString::number(values[i++]));
param1->setText(QString::number(values[i++]));
param2->setText(QString::number(values[i++]));
param3->setText(QString::number(values[i++]));
param4->setText(QString::number(values[i++]));
param5->setText(QString::number(values[i++]));
param6->setText(QString::number(values[i++]));
param7->setText(QString::number(values[i++]));
param8->setText(QString::number(values[i++]));
param9->setText(QString::number(values[i++]));
ui->tableWidget->setColumnWidth(0,60);
//for(i=0;i<10;i++)

ui->tableWidget->setColumnWidth(0,60);
}

connect(ui->tableWidget,SIGNAL(cellChanged(int,int)),this,SLOT(changeValues(int,int)));
}
Expand All @@ -104,7 +109,8 @@ void GrblDialog::Cancel()

void GrblDialog::changeValues(int row, int col)
{
if(ui->tableWidget->item(row,0)->text()!=QString::number(values[row]))
if ((ui->tableWidget->item(row,0)->text() != QString::number(values[row]))
&& ui->tableWidget->item(row,0)->text().length() > 0)
{
change[row]=true;
}
Expand All @@ -116,18 +122,76 @@ void GrblDialog::Ok()
char line[20];
int j;
QString strline;
for(i=0;i<10;i++)
for(i=0;i<10;i++)
{
if(change[i])
{
if(change[i])
{
strline="$";
strline.append(QString::number(i)).append("=").append(ui->tableWidget->item(i,0)->text()).append('\r');
for(j=0;j<strline.length();j++)
line[j]=strline.at(j).toAscii();
strline="$";
strline.append(QString::number(i)).append("=").append(ui->tableWidget->item(i,0)->text()).append('\r');
for(j=0;j<strline.length();j++)
line[j]=strline.at(j).toAscii();
#ifndef DISCONNECTED
port.SendBuf(this->port_nr,line,j);
#endif
port.SendBuf(this->port_nr,line,j);
if (!waitForOk())
{
break;
}
#endif
}
}
this->close();
}

bool GrblDialog::waitForOk()
{
#define RESPONSE_EXPECT "ok\r\n"
char tmp[BUF_SIZE + 1] = {0};
int count = 0;
bool status = true;
QString result;
while (!result.contains(RESPONSE_EXPECT))
{
#ifndef DISCONNECTED
int n = port.PollComport(port_nr, tmp, BUF_SIZE);
if (n == 0)
{
count++;
#ifdef Q_WS_X11
usleep(500000); // sleep for 100 milliSeconds
#else
Sleep(500);
#endif
}
else
{
tmp[n] = 0;
result.append(tmp);
//printf("GOT:%s\n", tmp); fflush(stdout);
count = 0;
}
#else
result = RESPONSE_EXPECT;
#endif
#ifdef Q_WS_X11
usleep(100000); // sleep for 100 milliSeconds
#else
Sleep(100);
#endif
if (count > 50)
{\
status = false;
break;
}
}

if (status)
{
#ifdef Q_WS_X11
usleep(200000); // sleep for 200 millseconds
#else
Sleep(200);
#endif
}

return status;
}
2 changes: 2 additions & 0 deletions grbldialog.h
Expand Up @@ -35,6 +35,8 @@ public slots:
void changeValues(int row, int col);

private:
bool waitForOk();

Ui::GrblDialog *ui;

};
Expand Down

0 comments on commit 424534b

Please sign in to comment.