Browse Source

Added suport for multiline G-code commands in the LCD menus

Jérémie FRANCOIS 10 years ago
parent
commit
dd301be52d
3 changed files with 43 additions and 4 deletions
  1. 1
    1
      Marlin/Marlin.h
  2. 6
    2
      Marlin/Marlin_main.cpp
  3. 36
    1
      Marlin/ultralcd.cpp

+ 1
- 1
Marlin/Marlin.h View File

@@ -199,7 +199,7 @@ void Stop();
199 199
 
200 200
 bool IsStopped();
201 201
 
202
-void enquecommand(const char *cmd); //put an ASCII command at the end of the current buffer.
202
+bool enquecommand(const char *cmd); //put an ASCII command at the end of the current buffer or return false when it is full
203 203
 void enquecommand_P(const char *cmd); //put an ASCII command at the end of the current buffer, read from flash
204 204
 void prepare_arc_move(char isclockwise);
205 205
 void clamp_to_software_endstops(float target[3]);

+ 6
- 2
Marlin/Marlin_main.cpp View File

@@ -454,9 +454,12 @@ void serial_echopair_P(const char *s_P, unsigned long v)
454 454
 //adds an command to the main command buffer
455 455
 //thats really done in a non-safe way.
456 456
 //needs overworking someday
457
-void enquecommand(const char *cmd)
457
+//(or return false if it failed to do so)
458
+bool enquecommand(const char *cmd)
458 459
 {
459
-  if(buflen < BUFSIZE)
460
+  if(buflen >= BUFSIZE)
461
+    return false;
462
+  else
460 463
   {
461 464
     //this is dangerous if a mixing of serial and this happens
462 465
     strcpy(&(cmdbuffer[bufindw][0]),cmd);
@@ -466,6 +469,7 @@ void enquecommand(const char *cmd)
466 469
     SERIAL_ECHOLNPGM("\"");
467 470
     bufindw= (bufindw + 1)%BUFSIZE;
468 471
     buflen += 1;
472
+    return true;
469 473
   }
470 474
 }
471 475
 

+ 36
- 1
Marlin/ultralcd.cpp View File

@@ -10,6 +10,8 @@
10 10
 
11 11
 int8_t encoderDiff; /* encoderDiff is updated from interrupt context and added to encoderPosition every LCD update */
12 12
 
13
+const char* pgcode_seq= NULL; /* pointer to the current line in the active sequence of commands, or NULL when none */
14
+
13 15
 /* Configuration settings */
14 16
 int plaPreheatHotendTemp;
15 17
 int plaPreheatHPBTemp;
@@ -76,6 +78,7 @@ static void lcd_quick_feedback();//Cause an LCD refresh, and give the user visua
76 78
 static void menu_action_back(menuFunc_t data);
77 79
 static void menu_action_submenu(menuFunc_t data);
78 80
 static void menu_action_gcode(const char* pgcode);
81
+static void menu_action_gcode_next();
79 82
 static void menu_action_function(menuFunc_t data);
80 83
 static void menu_action_sdfile(const char* filename, char* longFilename);
81 84
 static void menu_action_sddirectory(const char* filename, char* longFilename);
@@ -1164,7 +1167,37 @@ static void lcd_quick_feedback()
1164 1167
 /** Menu action functions **/
1165 1168
 static void menu_action_back(menuFunc_t data) { lcd_goto_menu(data); }
1166 1169
 static void menu_action_submenu(menuFunc_t data) { lcd_goto_menu(data); }
1167
-static void menu_action_gcode(const char* pgcode) { enquecommand_P(pgcode); }
1170
+
1171
+static void menu_action_gcode(const char* pgcode)
1172
+{
1173
+	// No more calling enquecommand_P(pgcode) as it allows only one command!
1174
+	pgcode_seq= pgcode;
1175
+	menu_action_gcode_next();
1176
+}
1177
+
1178
+static void menu_action_gcode_next()
1179
+{
1180
+	// Inject the next command from the pending sequence, when not empty.
1181
+	char cmd[30];
1182
+	if(!pgcode_seq) return;
1183
+        // Get the next 30 chars from the sequence of gcodes to run
1184
+        strncpy_P(cmd, pgcode_seq, sizeof(cmd)-1);
1185
+        cmd[sizeof(cmd)-1]= 0;
1186
+        // Look for the end of line, or the end of sequence
1187
+	size_t i= 0;
1188
+        char c;
1189
+        while( (c= cmd[i]) && c!='\n' )
1190
+          ++i; // look for the end of this gcode command
1191
+ 	cmd[i]= 0;
1192
+        if(!enquecommand(cmd)) // buffer was full, will retry later
1193
+          return;
1194
+        if(c)
1195
+          pgcode_seq+= i+1; // move to next command
1196
+        else
1197
+          pgcode_seq= NULL; // mark the end of the sequence of gcodes
1198
+}
1199
+
1200
+
1168 1201
 static void menu_action_function(menuFunc_t data) { (*data)(); }
1169 1202
 static void menu_action_sdfile(const char* filename, char* longFilename)
1170 1203
 {
@@ -1257,6 +1290,8 @@ void lcd_update()
1257 1290
 
1258 1291
     lcd_buttons_update();
1259 1292
 
1293
+    menu_action_gcode_next(); // inject the next pending command in the pending sequence (if any)
1294
+
1260 1295
     #if (SDCARDDETECT > 0)
1261 1296
     if((IS_SD_INSERTED != lcd_oldcardstatus && lcd_detected()))
1262 1297
     {

Loading…
Cancel
Save