Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Our changes to LaosLaser #8

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 31 additions & 29 deletions laser/LaosMenu/LaosMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,27 @@ void LaosMenu::SetScreen(char *msg) {
Handle();
}

/**
*** Check if cancel button is pressed (should only be used while running jobs!)
**/
void LaosMenu::checkCancel() {
c = dsp->read();
if(c==K_CANCEL || !mot->isStart()/* || mot->endstopReached()*/){
fclose(runfile);
runfile = NULL;
screen = MAIN;
canceled=1;
mot->clearBuffer();
mot->reset();
mot->isHome=false;
printf("cancel pressed!\r\n");
}
if(c==K_FUP){
skipped=1;
}
}


/**
*** Handle menu system
*** Read keys, and plan next action on the screen, output screen if
Expand Down Expand Up @@ -253,27 +274,8 @@ void LaosMenu::Handle() {
break;

case MOVE: // pos xy
mot->getPosition(&x, &y, &z);
xt = x; yt= y;
switch ( c ) {
case K_DOWN: y+=100*speed; break;
case K_UP: y-=100*speed; break;
case K_LEFT: x-=100*speed; break;
case K_RIGHT: x+=100*speed; break;
case K_OK: case K_CANCEL: screen=MAIN; waitup=1; break;
case K_FUP: screen=FOCUS; break;
case K_FDOWN: screen=FOCUS; break;
case K_ORIGIN: screen=ORIGIN; break;
}
if ((mot->queue() < 5) && ( (x!=xt) || (y != yt) )) {
mot->moveTo(x, y, z, speed/2);
printf("Move: %d %d %d %d\n", x,y,z, speed);
} else {
// if (! mot->ready())
// printf("Buffer vol\n");
}
args[0]=x-xoff;
args[1]=y-yoff;
mot->manualMove();
screen=MAIN;
break;

case FOCUS: // focus
Expand Down Expand Up @@ -393,12 +395,6 @@ void LaosMenu::Handle() {

case RUNNING: // Screen while running
switch ( c ) {
/* case K_CANCEL:
while (mot->queue());
mot->reset();
if (runfile != NULL) fclose(runfile);
runfile=NULL; screen=MAIN; menu=MAIN;
break; */
default:
if (runfile == NULL) {
runfile = sd.openfile(jobname, "rb");
Expand All @@ -407,15 +403,21 @@ void LaosMenu::Handle() {
else
mot->reset();
} else {
canceled=0;
#ifdef READ_FILE_DEBUG
printf("Parsing file: \n");
#endif
while ((!feof(runfile)) && mot->ready())
while (!canceled && ((!feof(runfile)) && mot->ready())){
checkCancel();
mot->write(readint(runfile));
}
while(!canceled && mot->queue()>0){
checkCancel();
}
#ifdef READ_FILE_DEBUG
printf("File parsed \n");
#endif
if (feof(runfile) && mot->ready()) {
if (!canceled && feof(runfile) && mot->ready()) {
fclose(runfile);
runfile = NULL;
mot->moveTo(cfg->xrest, cfg->yrest, cfg->zrest);
Expand Down
13 changes: 12 additions & 1 deletion laser/LaosMenu/LaosMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ extern "C" void mbed_reset();

extern void plan_get_current_position_xyz(float *x, float *y, float *z);

extern LaosMotion *mot;

class LaosMenu {
public:
/** Make new LaosMenu object.
Expand All @@ -58,7 +60,8 @@ class LaosMenu {
void SetScreen(int screen);
void SetScreen(char *s);
void SetFileName(char * name);

void checkCancel();

private:
// LaosDisplay *display;
int args[5];
Expand All @@ -67,6 +70,14 @@ class LaosMenu {
int speed;
char jobname[MAXFILESIZE];

// button input character
int c;

// cancel/skip markers
int canceled=0;
int skipped=0;


// menu states
int screen, prevscreen, lastscreen;
unsigned char menu, ipfield, iofield;
Expand Down
Loading