From 0d4ff0c48b7dfe6909f4fe73db45aadd3e3c8aca Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 5 Jul 2016 16:12:31 -0700 Subject: [PATCH 1/2] Allow the queue to be cleared from within commands --- Marlin/Marlin_main.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 4409a36df..100d56dd4 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -990,8 +990,11 @@ void loop() { #endif // SDSUPPORT - commands_in_queue--; - cmd_queue_index_r = (cmd_queue_index_r + 1) % BUFSIZE; + // The queue may be reset by a command handler or by code invoked by idle() within a handler + if (commands_in_queue) { + --commands_in_queue; + cmd_queue_index_r = (cmd_queue_index_r + 1) % BUFSIZE; + } } endstops.report_state(); idle(); From b114b6a0b3cea2ad9e031ac2473381f9b2d37df8 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 5 Jul 2016 16:29:28 -0700 Subject: [PATCH 2/2] Save 152 bytes using uint8_t for command indices --- Marlin/Marlin_main.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 100d56dd4..c31002bca 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -284,11 +284,11 @@ bool axis_homed[3] = { false }; static long gcode_N, gcode_LastN, Stopped_gcode_LastN = 0; -static char* current_command, *current_command_args; -static int cmd_queue_index_r = 0; -static int cmd_queue_index_w = 0; -static int commands_in_queue = 0; static char command_queue[BUFSIZE][MAX_CMD_SIZE]; +static char* current_command, *current_command_args; +static uint8_t cmd_queue_index_r = 0, + cmd_queue_index_w = 0, + commands_in_queue = 0; #if ENABLED(INCH_MODE_SUPPORT) float linear_unit_factor = 1.0;