Skip to content

Commit

Permalink
Intercept M0/M1 command when printing from SD card on TFT controller (#…
Browse files Browse the repository at this point in the history
…297)

* Intercept M0/M1 command when printing from SD card on TFT controller
* fix for M108 command
* intercept 'paused for user' message and force M108 command on resume
  • Loading branch information
guruathwal authored and bigtreetech committed Jan 16, 2020
1 parent 3521e7e commit 5777f41
Show file tree
Hide file tree
Showing 22 changed files with 75 additions and 7 deletions.
14 changes: 14 additions & 0 deletions TFT/src/User/API/Language/Language.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ const char *const en_pack[LABEL_NUM]={
EN_INVERT_ZAXIS,
EN_MOVE_SPEED,
EN_KNOB_LED,
EN_M0_PAUSE,
};

const char *const cn_pack[LABEL_NUM]={
Expand Down Expand Up @@ -319,6 +320,7 @@ const char *const cn_pack[LABEL_NUM]={
CN_INVERT_ZAXIS,
CN_MOVE_SPEED,
CN_KNOB_LED,
CN_M0_PAUSE,
};

const char *const ru_pack[LABEL_NUM]={
Expand Down Expand Up @@ -472,6 +474,7 @@ const char *const ru_pack[LABEL_NUM]={
RU_INVERT_ZAXIS,
RU_MOVE_SPEED,
RU_KNOB_LED,
RU_M0_PAUSE,
};

const char *const jp_pack[LABEL_NUM]={
Expand Down Expand Up @@ -625,6 +628,7 @@ const char *const jp_pack[LABEL_NUM]={
JP_INVERT_ZAXIS,
JP_MOVE_SPEED,
JP_KNOB_LED,
JP_M0_PAUSE,
};

const char *const am_pack[LABEL_NUM]={
Expand Down Expand Up @@ -778,6 +782,7 @@ const char *const am_pack[LABEL_NUM]={
AM_INVERT_ZAXIS,
AM_MOVE_SPEED,
AM_KNOB_LED,
AM_M0_PAUSE,
};

const char *const de_pack[LABEL_NUM]={
Expand Down Expand Up @@ -931,6 +936,7 @@ const char *const de_pack[LABEL_NUM]={
DE_INVERT_ZAXIS,
DE_MOVE_SPEED,
DE_KNOB_LED,
DE_M0_PAUSE,
};

const char *const cz_pack[LABEL_NUM]={
Expand Down Expand Up @@ -1084,6 +1090,7 @@ const char *const cz_pack[LABEL_NUM]={
CZ_INVERT_ZAXIS,
CZ_MOVE_SPEED,
CZ_KNOB_LED,
CZ_M0_PAUSE,
};

const char *const es_pack[LABEL_NUM]={
Expand Down Expand Up @@ -1237,6 +1244,7 @@ const char *const es_pack[LABEL_NUM]={
ES_INVERT_ZAXIS,
ES_MOVE_SPEED,
ES_KNOB_LED,
ES_M0_PAUSE,
};

const char *const fr_pack[LABEL_NUM]={
Expand Down Expand Up @@ -1390,6 +1398,7 @@ const char *const fr_pack[LABEL_NUM]={
FR_INVERT_ZAXIS,
FR_MOVE_SPEED,
FR_KNOB_LED,
FR_M0_PAUSE,
};

const char *const pt_pack[LABEL_NUM]={
Expand Down Expand Up @@ -1543,6 +1552,7 @@ const char *const pt_pack[LABEL_NUM]={
PT_INVERT_ZAXIS,
PT_MOVE_SPEED,
PT_KNOB_LED,
PT_M0_PAUSE,
};

const char *const it_pack[LABEL_NUM]={
Expand Down Expand Up @@ -1696,6 +1706,7 @@ const char *const it_pack[LABEL_NUM]={
IT_INVERT_ZAXIS,
IT_MOVE_SPEED,
IT_KNOB_LED,
IT_M0_PAUSE,
};

const char *const pl_pack[LABEL_NUM]={
Expand Down Expand Up @@ -1849,6 +1860,7 @@ const char *const pl_pack[LABEL_NUM]={
PL_INVERT_ZAXIS,
PL_MOVE_SPEED,
PL_KNOB_LED,
PL_M0_PAUSE,
};

const char *const sk_pack[LABEL_NUM]={
Expand Down Expand Up @@ -2002,6 +2014,7 @@ const char *const sk_pack[LABEL_NUM]={
SK_INVERT_ZAXIS,
SK_MOVE_SPEED,
SK_KNOB_LED,
SK_M0_PAUSE,
};

const char *const du_pack[LABEL_NUM]={
Expand Down Expand Up @@ -2155,6 +2168,7 @@ const char *const du_pack[LABEL_NUM]={
DU_INVERT_ZAXIS,
DU_MOVE_SPEED,
DU_KNOB_LED,
DU_M0_PAUSE,
};

u8 * textSelect(u8 sel)
Expand Down
1 change: 1 addition & 0 deletions TFT/src/User/API/Language/Language.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ enum
LABEL_INVERT_ZAXIS,
LABEL_MOVE_SPEED,
LABEL_KNOB_LED,
LABEL_M0_PAUSE,

//add new keywords above this line only
//keep the following always at the end of this list
Expand Down
1 change: 1 addition & 0 deletions TFT/src/User/API/Language/language_am.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,6 @@
#define AM_INVERT_ZAXIS "Invert Z Axis"
#define AM_MOVE_SPEED "Move speed(X Y Z)"
#define AM_KNOB_LED "Rotary Knob LED"
#define AM_M0_PAUSE "Paused by M0 command"

#endif
1 change: 1 addition & 0 deletions TFT/src/User/API/Language/language_cn.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,6 @@
#define CN_INVERT_ZAXIS "Invert Z Axis"
#define CN_MOVE_SPEED "Move speed(X Y Z)"
#define CN_KNOB_LED "Rotary Knob LED"
#define CN_M0_PAUSE "Paused by M0 command"

#endif
1 change: 1 addition & 0 deletions TFT/src/User/API/Language/language_cz.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,6 @@
#define CZ_INVERT_ZAXIS "Invert Z Axis"
#define CZ_MOVE_SPEED "Move speed(X Y Z)"
#define CZ_KNOB_LED "Rotary Knob LED"
#define CZ_M0_PAUSE "Paused by M0 command"

#endif
1 change: 1 addition & 0 deletions TFT/src/User/API/Language/language_de.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,6 @@
#define DE_INVERT_ZAXIS "Invert Z Axis"
#define DE_MOVE_SPEED "Move speed(X Y Z)"
#define DE_KNOB_LED "Rotary Knob LED"
#define DE_M0_PAUSE "Paused by M0 command"

#endif
1 change: 1 addition & 0 deletions TFT/src/User/API/Language/language_du.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,6 @@
#define DU_INVERT_ZAXIS "Inverteer Z Axis"
#define DU_MOVE_SPEED "Bewegingssnelheid(X Y Z)"
#define DU_KNOB_LED "Rotary Knob LED"
#define DU_M0_PAUSE "Paused by M0 command"

#endif
1 change: 1 addition & 0 deletions TFT/src/User/API/Language/language_en.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,6 @@
#define EN_INVERT_ZAXIS "Invert Z Axis"
#define EN_MOVE_SPEED "Move speed(X Y Z)"
#define EN_KNOB_LED "Rotary Knob LED"
#define EN_M0_PAUSE "Paused by M0 command"

#endif
1 change: 1 addition & 0 deletions TFT/src/User/API/Language/language_es.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,6 @@
#define ES_INVERT_ZAXIS "Invert Z Axis"
#define ES_MOVE_SPEED "Move speed(X Y Z)"
#define ES_KNOB_LED "Rotary Knob LED"
#define ES_M0_PAUSE "Paused by M0 command"

#endif
1 change: 1 addition & 0 deletions TFT/src/User/API/Language/language_fr.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,6 @@
#define FR_INVERT_ZAXIS "Inverser Axe Z"
#define FR_MOVE_SPEED "Vitesse de déplacement (X Y Z)"
#define FR_KNOB_LED "Rotary Knob LED"
#define FR_M0_PAUSE "Paused by M0 command"

#endif
1 change: 1 addition & 0 deletions TFT/src/User/API/Language/language_it.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,6 @@
#define IT_INVERT_ZAXIS "Invert Z Axis"
#define IT_MOVE_SPEED "Move speed(X Y Z)"
#define IT_KNOB_LED "Rotary Knob LED"
#define IT_M0_PAUSE "Paused by M0 command"

#endif
1 change: 1 addition & 0 deletions TFT/src/User/API/Language/language_jp.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,6 @@
#define JP_INVERT_ZAXIS "Invert Z Axis"
#define JP_MOVE_SPEED "Move speed(X Y Z)"
#define JP_KNOB_LED "Rotary Knob LED"
#define JP_M0_PAUSE "Paused by M0 command"

#endif
1 change: 1 addition & 0 deletions TFT/src/User/API/Language/language_pl.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,6 @@
#define PL_INVERT_ZAXIS "Invert Z Axis"
#define PL_MOVE_SPEED "Move speed(X Y Z)"
#define PL_KNOB_LED "Rotary Knob LED"
#define PL_M0_PAUSE "Paused by M0 command"

#endif
1 change: 1 addition & 0 deletions TFT/src/User/API/Language/language_pt.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,6 @@
#define PT_INVERT_ZAXIS "Invert Z Axis"
#define PT_MOVE_SPEED "Move speed(X Y Z)"
#define PT_KNOB_LED "Rotary Knob LED"
#define PT_M0_PAUSE "Paused by M0 command"

#endif
1 change: 1 addition & 0 deletions TFT/src/User/API/Language/language_ru.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,6 @@
#define RU_INVERT_ZAXIS "Инверсия оси Z"
#define RU_MOVE_SPEED "Скорость (X Y Z)"
#define RU_KNOB_LED "Rotary Knob LED"
#define RU_M0_PAUSE "Paused by M0 command"

#endif
1 change: 1 addition & 0 deletions TFT/src/User/API/Language/language_sk.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,6 @@
#define SK_INVERT_ZAXIS "Invert Z Axis"
#define SK_MOVE_SPEED "Move speed(X Y Z)"
#define SK_KNOB_LED "Rotary Knob LED"
#define SK_M0_PAUSE "Paused by M0 command"

#endif
2 changes: 1 addition & 1 deletion TFT/src/User/API/extend.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ void loopFILRunoutDetect(void)
if (!FIL_IsRunout()) return; // Filament not runout yet, need constant scanning to filter interference
if (!isPrinting() || isPause()) return; // No printing or printing paused

if (setPrintPause(true))
if (setPrintPause(true,false))
{
popupReminder(textSelect(LABEL_WARNING), textSelect(LABEL_FILAMENT_RUNOUT));
}
Expand Down
10 changes: 10 additions & 0 deletions TFT/src/User/API/interfaceCmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@ void sendQueueCmd(void)
cmd=strtol(&infoCmd.queue[infoCmd.index_r].gcode[1],NULL,10);
switch(cmd)
{
case 0:
if (isPrinting()) {
setPrintPause(true,true);
}
break;
case 1:
if (isPrinting()) {
setPrintPause(true,true);
}
break;
case 18: //M18/M84 disable steppers
case 84:
coordinateSetClear(false);
Expand Down
4 changes: 4 additions & 0 deletions TFT/src/User/API/parseACK.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ void parseACK(void)
{
busyIndicator(STATUS_BUSY);
}
else if(ack_seen(echomagic) && ack_seen(busymagic) && ack_seen("paused for user"))
{
goto parse_end;
}
else if(ack_seen("X driver current: "))
{
Get_parameter_value[0] = ack_value();
Expand Down
2 changes: 1 addition & 1 deletion TFT/src/User/Menu/More.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void menuIsPause(void)
switch(key_num)
{
case KEY_POPUP_CONFIRM:
if(setPrintPause(true))
if(setPrintPause(true,false))
infoMenu.menu[infoMenu.cur]=menuExtrude;
break;

Expand Down
30 changes: 26 additions & 4 deletions TFT/src/User/Menu/Printing.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ static bool update_waiting = M27_WATCH_OTHER_SOURCES;
static bool update_waiting = false;
#endif


//
bool isPrinting(void)
{
Expand All @@ -52,6 +51,11 @@ bool isPause(void)
return infoPrinting.pause;
}

bool isM0_Pause(void)
{
return infoPrinting.m0_pause;
}

//
void setPrintingTime(u32 RTtime)
{
Expand Down Expand Up @@ -198,7 +202,11 @@ void resumeToPause(bool is_pause)
menuDrawItem(&itemIsPause[is_pause],0);
}

bool setPrintPause(bool is_pause)
void setM0Pause(bool m0_pause){
infoPrinting.m0_pause = m0_pause;
}

bool setPrintPause(bool is_pause, bool is_m0pause)
{
static bool pauseLock = false;
if(pauseLock) return false;
Expand All @@ -219,16 +227,25 @@ bool setPrintPause(bool is_pause)

case TFT_UDISK:
case TFT_SD:
infoPrinting.pause = is_pause;
if(infoPrinting.pause == true && is_m0pause == false){
while (infoCmd.count != 0) {loopProcess();}
}

bool isCoorRelative = coorGetRelative();
bool isExtrudeRelative = eGetRelative();
static COORDINATE tmp;

infoPrinting.pause = is_pause;
if(infoPrinting.pause)
{
//restore status before pause
//if pause was triggered through M0/M1 then break
if(is_m0pause == true) {
setM0Pause(is_m0pause);
popupReminder(textSelect(LABEL_PAUSE), textSelect(LABEL_M0_PAUSE));
break;
}

coordinateGetAll(&tmp);
if (isCoorRelative == true) mustStoreCmd("G90\n");
if (isExtrudeRelative == true) mustStoreCmd("M82\n");
Expand All @@ -246,6 +263,11 @@ bool setPrintPause(bool is_pause)
}
else
{
if(isM0_Pause() == true) {
setM0Pause(is_m0pause);
Serial_Puts(SERIAL_PORT, "M108\n");
break;
}
if (isCoorRelative == true) mustStoreCmd("G90\n");
if (isExtrudeRelative == true) mustStoreCmd("M82\n");

Expand Down Expand Up @@ -404,7 +426,7 @@ void menuPrinting(void)
switch(key_num)
{
case KEY_ICON_0:
setPrintPause(!isPause());
setPrintPause(!isPause(),false);
break;

case KEY_ICON_3:
Expand Down
5 changes: 4 additions & 1 deletion TFT/src/User/Menu/Printing.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@ typedef struct
u8 progress;
bool printing; // 1 means printing, 0 means idle
bool pause; //1 means paused
bool m0_pause; //pause triggered through M0/M1 gcode
}PRINTING;

void exitPrinting(void);
void endPrinting(void);
void completePrinting(void);
void abortPrinting(void);

bool setPrintPause(bool is_pause);
void setM0Pause(bool m0_pause);
bool setPrintPause(bool is_pause,bool is_m0pause);

bool isPrinting(void);
bool isPause(void);
bool isM0_Pause(void);
void setPrintingTime(u32 RTtime);

void setPrintSize(u32 size);
Expand Down

0 comments on commit 5777f41

Please sign in to comment.