Skip to content

Commit

Permalink
Implementation of '// action:command' as described in [1]. Pause, Res…
Browse files Browse the repository at this point in the history
…ume and

Stop are available from the controller menu.
[1]http://reprap.org/wiki/Gcode#Replies_from_the_RepRap_machine_to_the_host_computer
  • Loading branch information
AmedeeBulle committed Mar 5, 2016
1 parent d6410e5 commit 364dd2f
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Marlin/Configuration.h
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions Marlin/Marlin.h
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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];
Expand Down
11 changes: 11 additions & 0 deletions Marlin/Marlin_main.cpp
Expand Up @@ -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};
Expand Down Expand Up @@ -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'))
{
Expand Down
2 changes: 2 additions & 0 deletions Marlin/language.h
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
49 changes: 48 additions & 1 deletion Marlin/ultralcd.cpp
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 () \
{ \
Expand Down

0 comments on commit 364dd2f

Please sign in to comment.