From 364dd2fdc1df4fd997e28a7d89463ca887eb3233 Mon Sep 17 00:00:00 2001 From: Philippe Vanhaesendonck Date: Sat, 5 Mar 2016 16:06:29 +0100 Subject: [PATCH] Implementation of '// action:command' as described in [1]. Pause, Resume and Stop are available from the controller menu. [1]http://reprap.org/wiki/Gcode#Replies_from_the_RepRap_machine_to_the_host_computer --- Marlin/Configuration.h | 4 ++++ Marlin/Marlin.h | 15 +++++++++++++ Marlin/Marlin_main.cpp | 11 ++++++++++ Marlin/language.h | 2 ++ Marlin/ultralcd.cpp | 49 +++++++++++++++++++++++++++++++++++++++++- 5 files changed, 80 insertions(+), 1 deletion(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 86528f9713c5..7ce411dd02e2 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -770,6 +770,10 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of //define BlinkM/CyzRgb Support //#define BLINKM +// Implement action:command as described http://reprap.org/wiki/Gcode#Replies_from_the_RepRap_machine_to_the_host_computer +// This allows to pause/resume print when printing from USB with Pronterface/OctoPrint +//#define ACTION_COMMAND + /*********************************************************************\ * R/C SERVO support * Sponsored by TrinityLabs, Reworked by codexmas diff --git a/Marlin/Marlin.h b/Marlin/Marlin.h index 0a5637572d1a..c0a9cea2a067 100644 --- a/Marlin/Marlin.h +++ b/Marlin/Marlin.h @@ -68,6 +68,9 @@ const char errormagic[] PROGMEM ="Error:"; const char echomagic[] PROGMEM ="echo:"; +#ifdef ACTION_COMMAND +const char actionmagic[] PROGMEM ="// action:"; +#endif #define SERIAL_ERROR_START (serialprintPGM(errormagic)) #define SERIAL_ERROR(x) SERIAL_PROTOCOL(x) #define SERIAL_ERRORPGM(x) SERIAL_PROTOCOLPGM(x) @@ -86,6 +89,13 @@ void serial_echopair_P(const char *s_P, float v); void serial_echopair_P(const char *s_P, double v); void serial_echopair_P(const char *s_P, unsigned long v); +#ifdef ACTION_COMMAND +#define SERIAL_ACTION_START (serialprintPGM(actionmagic)) +#define SERIAL_ACTION(x) SERIAL_PROTOCOL(x) +#define SERIAL_ACTIONPGM(x) SERIAL_PROTOCOLPGM(x) +#define SERIAL_ACTIONNL(x) SERIAL_PROTOCOLLN(x) +#define SERIAL_ACTIONNLPGM(x) SERIAL_PROTOCOLLNPGM(x) +#endif //Things to write to serial from Program memory. Saves 400 to 2k of RAM. FORCE_INLINE void serialprintPGM(const char *str) @@ -252,6 +262,11 @@ extern void digipot_i2c_init(); extern int ledPwm; #endif +// Serial flag +#ifdef ACTION_COMMAND + extern bool serial_active; +#endif + // Motor current #ifdef MOTOR_CURRENT_PWM_XY_PIN extern int motor_current_setting[3]; diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index d4fb22bee127..c9c4d30420d0 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -263,6 +263,10 @@ int EtoPPressure=0; int ledPwm=0; #endif +// Serial flag +#ifdef ACTION_COMMAND + bool serial_active = false; +#endif #ifdef DELTA float delta[3] = {0.0, 0.0, 0.0}; @@ -1158,6 +1162,13 @@ void process_commands() char *starpos = NULL; #ifdef ENABLE_AUTO_BED_LEVELING float x_tmp, y_tmp, z_tmp, real_z; +#endif +#ifdef ACTION_COMMAND // Toggle serial_active once we get a command from the serial interface. +#ifdef SDSUPPORT + if(!card.sdprinting) serial_active = true; +#else + serial_active = true; +#endif #endif if(code_seen('G')) { diff --git a/Marlin/language.h b/Marlin/language.h index 61e3fba4c7c7..e67fc15c6a4a 100644 --- a/Marlin/language.h +++ b/Marlin/language.h @@ -191,6 +191,7 @@ #define MSG_MOTOR_CURRENT "Motors current" #define MSG_CURRENT "Current " #define MSG_XY "xy" + #define MSG_ACTION_COMMAND "Serial action" // Serial Console Messages @@ -597,6 +598,7 @@ #define MSG_MOTOR_CURRENT "Courrant moteurs" #define MSG_CURRENT "Courrant " #define MSG_XY "xy" + #define MSG_ACTION_COMMAND "Action port serie" // Serial Console Messages diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp index fba15d1b070a..67d852eb6426 100644 --- a/Marlin/ultralcd.cpp +++ b/Marlin/ultralcd.cpp @@ -73,6 +73,9 @@ static void lcd_set_contrast(); static void lcd_control_retract_menu(); static void lcd_control_version_menu(); static void lcd_sdcard_menu(); +#ifdef ACTION_COMMAND +static void lcd_action_menu(); +#endif static void lcd_quick_feedback();//Cause an LCD refresh, and give the user visual or audible feedback that something has happened @@ -307,7 +310,11 @@ static void lcd_main_menu() #endif } #endif - END_MENU(); +#ifdef ACTION_COMMAND + if (serial_active) + MENU_ITEM(submenu, MSG_ACTION_COMMAND, lcd_action_menu); +#endif + END_MENU(); } #ifdef SDSUPPORT @@ -1069,6 +1076,46 @@ void lcd_sdcard_menu() END_MENU(); } +#ifdef ACTION_COMMAND +static void lcd_action_pause() +{ + SERIAL_ACTION_START; + SERIAL_ACTIONNLPGM("pause"); + LCD_MESSAGEPGM(MSG_USERWAIT); + lcd_return_to_status(); +} + +void lcd_action_resume() +{ + SERIAL_ACTION_START; + SERIAL_ACTIONNLPGM("resume"); + LCD_MESSAGEPGM(MSG_RESUMING); + lcd_return_to_status(); +} + +void lcd_action_disconnect() +{ + SERIAL_ACTION_START; + SERIAL_ACTIONNLPGM("disconnect"); + quickStop(); + if(SD_FINISHED_STEPPERRELEASE) + enquecommand_P(PSTR(SD_FINISHED_RELEASECOMMAND)); + autotempShutdown(); + LCD_MESSAGEPGM(MSG_STOPPED); + lcd_return_to_status(); +} + +static void lcd_action_menu() +{ + START_MENU(); + MENU_ITEM(back, MSG_MAIN, lcd_main_menu); + MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_action_pause); + MENU_ITEM(function, MSG_RESUME_PRINT, lcd_action_resume); + MENU_ITEM(function, MSG_STOP_PRINT, lcd_action_disconnect); + END_MENU(); +} +#endif + #define menu_edit_type(_type, _name, _strFunc, scale) \ void menu_edit_ ## _name () \ { \