Browse Source

Merge pull request #4214 from thinkyhead/fix_clear_command_queue

Allow the command queue to be cleared by commands, lcd menus
Scott Lahteine 8 years ago
parent
commit
90d8bb53e8
1 changed files with 9 additions and 6 deletions
  1. 9
    6
      Marlin/Marlin_main.cpp

+ 9
- 6
Marlin/Marlin_main.cpp View File

@@ -284,11 +284,11 @@ bool axis_homed[3] = { false };
284 284
 
285 285
 static long gcode_N, gcode_LastN, Stopped_gcode_LastN = 0;
286 286
 
287
-static char* current_command, *current_command_args;
288
-static int cmd_queue_index_r = 0;
289
-static int cmd_queue_index_w = 0;
290
-static int commands_in_queue = 0;
291 287
 static char command_queue[BUFSIZE][MAX_CMD_SIZE];
288
+static char* current_command, *current_command_args;
289
+static uint8_t cmd_queue_index_r = 0,
290
+               cmd_queue_index_w = 0,
291
+               commands_in_queue = 0;
292 292
 
293 293
 #if ENABLED(INCH_MODE_SUPPORT)
294 294
   float linear_unit_factor = 1.0;
@@ -990,8 +990,11 @@ void loop() {
990 990
 
991 991
     #endif // SDSUPPORT
992 992
 
993
-    commands_in_queue--;
994
-    cmd_queue_index_r = (cmd_queue_index_r + 1) % BUFSIZE;
993
+    // The queue may be reset by a command handler or by code invoked by idle() within a handler
994
+    if (commands_in_queue) {
995
+      --commands_in_queue;
996
+      cmd_queue_index_r = (cmd_queue_index_r + 1) % BUFSIZE;
997
+    }
995 998
   }
996 999
   endstops.report_state();
997 1000
   idle();

Loading…
Cancel
Save