Browse Source

Merge pull request #1423 from MoonCactus/Development

Multi-line G-code commands
pull/1/head
Scott Lahteine 10 years ago
parent
commit
8cfdd3e8a4
  1. 5
      Marlin/Marlin.h
  2. 82
      Marlin/Marlin_main.cpp
  3. 4
      Marlin/cardreader.cpp
  4. 25
      Marlin/ultralcd.cpp

5
Marlin/Marlin.h

@ -201,8 +201,9 @@ void Stop();
bool IsStopped(); bool IsStopped();
void enquecommand(const char *cmd); //put an ASCII command at the end of the current buffer. bool enquecommand(const char *cmd); //put a single ASCII command at the end of the current buffer or return false when it is full
void enquecommand_P(const char *cmd); //put an ASCII command at the end of the current buffer, read from flash void enquecommands_P(const char *cmd); //put one or many ASCII commands at the end of the current buffer, read from flash
void prepare_arc_move(char isclockwise); void prepare_arc_move(char isclockwise);
void clamp_to_software_endstops(float target[3]); void clamp_to_software_endstops(float target[3]);

82
Marlin/Marlin_main.cpp

@ -385,6 +385,8 @@ static int serial_count = 0;
static boolean comment_mode = false; static boolean comment_mode = false;
static char *strchr_pointer; ///< A pointer to find chars in the command string (X, Y, Z, E, etc.) static char *strchr_pointer; ///< A pointer to find chars in the command string (X, Y, Z, E, etc.)
const char* queued_commands_P= NULL; /* pointer to the current line in the active sequence of commands, or NULL when none */
const int sensitive_pins[] = SENSITIVE_PINS; ///< Sensitive pin list for M42 const int sensitive_pins[] = SENSITIVE_PINS; ///< Sensitive pin list for M42
// Inactivity shutdown // Inactivity shutdown
@ -448,39 +450,64 @@ void serial_echopair_P(const char *s_P, unsigned long v)
} }
#endif //!SDSUPPORT #endif //!SDSUPPORT
//adds an command to the main command buffer //Injects the next command from the pending sequence of commands, when possible
//thats really done in a non-safe way. //Return false if and only if no command was pending
//needs overworking someday static bool drain_queued_commands_P()
void enquecommand(const char *cmd)
{ {
if(buflen < BUFSIZE) char cmd[30];
if(!queued_commands_P)
return false;
// Get the next 30 chars from the sequence of gcodes to run
strncpy_P(cmd, queued_commands_P, sizeof(cmd)-1);
cmd[sizeof(cmd)-1]= 0;
// Look for the end of line, or the end of sequence
size_t i= 0;
char c;
while( (c= cmd[i]) && c!='\n' )
++i; // look for the end of this gcode command
cmd[i]= 0;
if(enquecommand(cmd)) // buffer was not full (else we will retry later)
{ {
//this is dangerous if a mixing of serial and this happens if(c)
strcpy(&(cmdbuffer[bufindw][0]),cmd); queued_commands_P+= i+1; // move to next command
SERIAL_ECHO_START; else
SERIAL_ECHOPGM(MSG_Enqueing); queued_commands_P= NULL; // will have no more commands in the sequence
SERIAL_ECHO(cmdbuffer[bufindw]);
SERIAL_ECHOLNPGM("\"");
bufindw= (bufindw + 1)%BUFSIZE;
buflen += 1;
} }
return true;
} }
void enquecommand_P(const char *cmd) //Record one or many commands to run from program memory.
//Aborts the current queue, if any.
//Note: drain_queued_commands_P() must be called repeatedly to drain the commands afterwards
void enquecommands_P(const char* pgcode)
{ {
if(buflen < BUFSIZE) queued_commands_P= pgcode;
{ drain_queued_commands_P(); // first command exectuted asap (when possible)
//this is dangerous if a mixing of serial and this happens
strcpy_P(&(cmdbuffer[bufindw][0]),cmd);
SERIAL_ECHO_START;
SERIAL_ECHOPGM(MSG_Enqueing);
SERIAL_ECHO(cmdbuffer[bufindw]);
SERIAL_ECHOLNPGM("\"");
bufindw= (bufindw + 1)%BUFSIZE;
buflen += 1;
}
} }
//adds a single command to the main command buffer, from RAM
//that is really done in a non-safe way.
//needs overworking someday
//Returns false if it failed to do so
bool enquecommand(const char *cmd)
{
if(*cmd==';')
return false;
if(buflen >= BUFSIZE)
return false;
//this is dangerous if a mixing of serial and this happens
strcpy(&(cmdbuffer[bufindw][0]),cmd);
SERIAL_ECHO_START;
SERIAL_ECHOPGM(MSG_Enqueing);
SERIAL_ECHO(cmdbuffer[bufindw]);
SERIAL_ECHOLNPGM("\"");
bufindw= (bufindw + 1)%BUFSIZE;
buflen += 1;
return true;
}
void setup_killpin() void setup_killpin()
{ {
#if defined(KILL_PIN) && KILL_PIN > -1 #if defined(KILL_PIN) && KILL_PIN > -1
@ -684,6 +711,9 @@ void loop()
void get_command() void get_command()
{ {
if(drain_queued_commands_P()) // priority is given to non-serial commands
return;
while( MYSERIAL.available() > 0 && buflen < BUFSIZE) { while( MYSERIAL.available() > 0 && buflen < BUFSIZE) {
serial_char = MYSERIAL.read(); serial_char = MYSERIAL.read();
if(serial_char == '\n' || if(serial_char == '\n' ||
@ -4459,7 +4489,7 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) //default argument s
{ {
if (homeDebounceCount == 0) if (homeDebounceCount == 0)
{ {
enquecommand_P((PSTR("G28"))); enquecommands_P((PSTR("G28")));
homeDebounceCount++; homeDebounceCount++;
LCD_ALERTMESSAGEPGM(MSG_AUTO_HOME); LCD_ALERTMESSAGEPGM(MSG_AUTO_HOME);
} }

4
Marlin/cardreader.cpp

@ -532,7 +532,7 @@ void CardReader::checkautostart(bool force)
sprintf_P(cmd, PSTR("M23 %s"), autoname); sprintf_P(cmd, PSTR("M23 %s"), autoname);
enquecommand(cmd); enquecommand(cmd);
enquecommand_P(PSTR("M24")); enquecommands_P(PSTR("M24"));
found=true; found=true;
} }
} }
@ -637,7 +637,7 @@ void CardReader::printingHasFinished()
if(SD_FINISHED_STEPPERRELEASE) if(SD_FINISHED_STEPPERRELEASE)
{ {
//finishAndDisableSteppers(); //finishAndDisableSteppers();
enquecommand_P(PSTR(SD_FINISHED_RELEASECOMMAND)); enquecommands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
} }
autotempShutdown(); autotempShutdown();
} }

25
Marlin/ultralcd.cpp

@ -324,7 +324,7 @@ static void lcd_sdcard_stop()
quickStop(); quickStop();
if(SD_FINISHED_STEPPERRELEASE) if(SD_FINISHED_STEPPERRELEASE)
{ {
enquecommand_P(PSTR(SD_FINISHED_RELEASECOMMAND)); enquecommands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
} }
autotempShutdown(); autotempShutdown();
@ -347,6 +347,7 @@ static void lcd_main_menu()
MENU_ITEM(submenu, MSG_DELTA_CALIBRATE, lcd_delta_calibrate_menu); MENU_ITEM(submenu, MSG_DELTA_CALIBRATE, lcd_delta_calibrate_menu);
#endif // DELTA_CALIBRATION_MENU #endif // DELTA_CALIBRATION_MENU
} }
/*JFR TEST*/ MENU_ITEM(gcode, "test multiline", PSTR("G4 S3\nM104 S50\nG4 S1\nM104 S200\nG4 S2\nM104 S0")); // SD-card changed by user
MENU_ITEM(submenu, MSG_CONTROL, lcd_control_menu); MENU_ITEM(submenu, MSG_CONTROL, lcd_control_menu);
#ifdef SDSUPPORT #ifdef SDSUPPORT
if (card.cardOK) if (card.cardOK)
@ -394,8 +395,7 @@ void lcd_set_home_offsets()
plan_set_position(0.0, 0.0, 0.0, current_position[E_AXIS]); plan_set_position(0.0, 0.0, 0.0, current_position[E_AXIS]);
// Audio feedback // Audio feedback
enquecommand_P(PSTR("M300 S659 P200")); enquecommands_P(PSTR("M300 S659 P200\nM300 S698 P200"));
enquecommand_P(PSTR("M300 S698 P200"));
lcd_return_to_status(); lcd_return_to_status();
} }
@ -677,6 +677,13 @@ static void lcd_prepare_menu()
} }
#endif #endif
MENU_ITEM(submenu, MSG_MOVE_AXIS, lcd_move_menu); MENU_ITEM(submenu, MSG_MOVE_AXIS, lcd_move_menu);
// JFR for RMud delta printer
MENU_ITEM(gcode, "Calibrate bed", PSTR("M702\nG28\nG1 X-77.94 Y-45 Z36 F8000\nG4 S3\nM701 P0\nG1 X77.94 Y-45 Z36\nG4 S3\nM701 P1\nG1 X0 Y90 Z36\nG4 S3\nM701 P2\nM700\nG1 X0 Y0 Z100 F8000"));
MENU_ITEM(gcode, "Check level", PSTR("G28\nG1 X0 Y0 Z1 F4000\nG1 X-77.94 Y-45 Z1\nG1 X77.94 Y-45\nG1 X0 Y90\nG1 X-77.94 Y-45\nG4 S2\nG1 X-77.94 Y-45 Z0.3 F2000\nG1 X-77.94 Y-45\nG1 X77.94 Y-45\nG1 X0 Y90\nG1 X-77.94 Y-45\nG1 X0 Y0 Z0"));
MENU_ITEM(gcode, "Retract filament", PSTR("M302\nM82\nG92 E0\nG1 F4000 E-800"));
MENU_ITEM(gcode, "Insert filament", PSTR("M302\nM82\nG92 E0\nG1 F4000 E60"));
MENU_ITEM(gcode, "Finalize filament", PSTR("G1 F4000 E790"));
END_MENU(); END_MENU();
} }
@ -1148,7 +1155,7 @@ menu_edit_type(unsigned long, long5, ftostr5, 0.01)
lcd_move_y(); lcd_move_y();
} }
static void reprapworld_keypad_move_home() { static void reprapworld_keypad_move_home() {
enquecommand_P((PSTR("G28"))); // move all axis home enquecommands_P((PSTR("G28"))); // move all axis home
} }
#endif #endif
@ -1164,7 +1171,13 @@ static void lcd_quick_feedback()
/** Menu action functions **/ /** Menu action functions **/
static void menu_action_back(menuFunc_t data) { lcd_goto_menu(data); } static void menu_action_back(menuFunc_t data) { lcd_goto_menu(data); }
static void menu_action_submenu(menuFunc_t data) { lcd_goto_menu(data); } static void menu_action_submenu(menuFunc_t data) { lcd_goto_menu(data); }
static void menu_action_gcode(const char* pgcode) { enquecommand_P(pgcode); }
static void menu_action_gcode(const char* pgcode)
{
enquecommands_P(pgcode);
}
static void menu_action_function(menuFunc_t data) { (*data)(); } static void menu_action_function(menuFunc_t data) { (*data)(); }
static void menu_action_sdfile(const char* filename, char* longFilename) static void menu_action_sdfile(const char* filename, char* longFilename)
{ {
@ -1174,7 +1187,7 @@ static void menu_action_sdfile(const char* filename, char* longFilename)
for(c = &cmd[4]; *c; c++) for(c = &cmd[4]; *c; c++)
*c = tolower(*c); *c = tolower(*c);
enquecommand(cmd); enquecommand(cmd);
enquecommand_P(PSTR("M24")); enquecommands_P(PSTR("M24"));
lcd_return_to_status(); lcd_return_to_status();
} }
static void menu_action_sddirectory(const char* filename, char* longFilename) static void menu_action_sddirectory(const char* filename, char* longFilename)

Loading…
Cancel
Save