Serial buffer over run work around for v2.0.0 (#9236)

* Work around for serial buffer over run

PronterFace sends a lot of M105 commands.  During long operations such
as UBL's G29 P1, G29 P2, G29 P4 and G26 this can over run the serial
buffer.   This results (very often) in a M1 (actually a M1M105) ending
up in the command queue.

Until we figure out a better way to resolve this issue, this will keep
the UBL commands from experiencing bogus commands at thier completion.
This commit is contained in:
Roxy-3D 2018-01-18 19:57:18 -06:00 committed by GitHub
parent 9d0cf02fef
commit bfd9728cf4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 55 additions and 31 deletions

View File

@ -69,6 +69,8 @@
uint8_t xon_xoff_state = XON_XOFF_CHAR_SENT | XON_CHAR; uint8_t xon_xoff_state = XON_XOFF_CHAR_SENT | XON_CHAR;
#endif #endif
void clear_command_queue();
#if ENABLED(SERIAL_STATS_DROPPED_RX) #if ENABLED(SERIAL_STATS_DROPPED_RX)
uint8_t rx_dropped_bytes = 0; uint8_t rx_dropped_bytes = 0;
#endif #endif
@ -388,7 +390,8 @@
// reading rx_buffer_head and updating rx_buffer_tail, the previous rx_buffer_head // reading rx_buffer_head and updating rx_buffer_tail, the previous rx_buffer_head
// may be written to rx_buffer_tail, making the buffer appear full rather than empty. // may be written to rx_buffer_tail, making the buffer appear full rather than empty.
CRITICAL_SECTION_START; CRITICAL_SECTION_START;
rx_buffer.head = rx_buffer.tail; rx_buffer.head = rx_buffer.tail = 0;
clear_command_queue();
CRITICAL_SECTION_END; CRITICAL_SECTION_END;
#if ENABLED(SERIAL_XON_XOFF) #if ENABLED(SERIAL_XON_XOFF)

View File

@ -555,7 +555,7 @@
* Override with M203 * Override with M203
* X, Y, Z, E0 [, E1[, E2[, E3[, E4]]]] * X, Y, Z, E0 [, E1[, E2[, E3[, E4]]]]
*/ */
#define DEFAULT_MAX_FEEDRATE { 250, 250, 2, 17 } #define DEFAULT_MAX_FEEDRATE { 250, 250, 4, 17 }
/** /**
* Default Max Acceleration (change/s) change = mm/s * Default Max Acceleration (change/s) change = mm/s
@ -587,7 +587,7 @@
*/ */
#define DEFAULT_XJERK 8.5 #define DEFAULT_XJERK 8.5
#define DEFAULT_YJERK 8.5 #define DEFAULT_YJERK 8.5
#define DEFAULT_ZJERK 0.3 #define DEFAULT_ZJERK 0.75
#define DEFAULT_EJERK 4.0 #define DEFAULT_EJERK 4.0
//=========================================================================== //===========================================================================
@ -916,7 +916,7 @@
/** /**
* Enable the G26 Mesh Validation Pattern tool. * Enable the G26 Mesh Validation Pattern tool.
*/ */
//#define G26_MESH_VALIDATION #define G26_MESH_VALIDATION
#if ENABLED(G26_MESH_VALIDATION) #if ENABLED(G26_MESH_VALIDATION)
#define MESH_TEST_NOZZLE_SIZE 0.4 // (mm) Diameter of primary nozzle. #define MESH_TEST_NOZZLE_SIZE 0.4 // (mm) Diameter of primary nozzle.
#define MESH_TEST_LAYER_HEIGHT 0.2 // (mm) Default layer height for the G26 Mesh Validation Tool. #define MESH_TEST_LAYER_HEIGHT 0.2 // (mm) Default layer height for the G26 Mesh Validation Tool.

View File

@ -1562,7 +1562,7 @@
* Fully assembled MAX7219 boards can be found on the internet for under $2(US). * Fully assembled MAX7219 boards can be found on the internet for under $2(US).
* For example, see https://www.ebay.com/sch/i.html?_nkw=332349290049 * For example, see https://www.ebay.com/sch/i.html?_nkw=332349290049
*/ */
//#define MAX7219_DEBUG #define MAX7219_DEBUG
#if ENABLED(MAX7219_DEBUG) #if ENABLED(MAX7219_DEBUG)
//#define MAX7219_CLK_PIN 64 // on RAMPS // Configuration of the 3 pins to control the display //#define MAX7219_CLK_PIN 64 // on RAMPS // Configuration of the 3 pins to control the display
//#define MAX7219_DIN_PIN 57 // on RAMPS //#define MAX7219_DIN_PIN 57 // on RAMPS

View File

@ -93,7 +93,7 @@ class unified_bed_leveling {
static bool g29_parameter_parsing(); static bool g29_parameter_parsing();
static void find_mean_mesh_height(); static void find_mean_mesh_height();
static void shift_mesh_height(); static void shift_mesh_height();
static void probe_entire_mesh(const float &rx, const float &ry, const bool do_ubl_mesh_map, const bool stow_probe, bool do_furthest); static void probe_entire_mesh(const float &rx, const float &ry, const bool do_ubl_mesh_map, const bool stow_probe, bool do_furthest) _O0;
static void tilt_mesh_based_on_3pts(const float &z1, const float &z2, const float &z3); static void tilt_mesh_based_on_3pts(const float &z1, const float &z2, const float &z3);
static void tilt_mesh_based_on_probed_grid(const bool do_ubl_mesh_map); static void tilt_mesh_based_on_probed_grid(const bool do_ubl_mesh_map);
static void g29_what_command(); static void g29_what_command();
@ -117,8 +117,8 @@ class unified_bed_leveling {
static void save_ubl_active_state_and_disable(); static void save_ubl_active_state_and_disable();
static void restore_ubl_active_state_and_leave(); static void restore_ubl_active_state_and_leave();
static void display_map(const int); static void display_map(const int);
static mesh_index_pair find_closest_mesh_point_of_type(const MeshPointType, const float&, const float&, const bool, uint16_t[16]); static mesh_index_pair find_closest_mesh_point_of_type(const MeshPointType, const float&, const float&, const bool, uint16_t[16]) _O0;
static mesh_index_pair find_furthest_invalid_mesh_point(); static mesh_index_pair find_furthest_invalid_mesh_point() _O0;
static void reset(); static void reset();
static void invalidate(); static void invalidate();
static void set_all_mesh_points_to_value(const float); static void set_all_mesh_points_to_value(const float);

View File

@ -36,6 +36,7 @@
#include "../../../module/planner.h" #include "../../../module/planner.h"
#include "../../../module/probe.h" #include "../../../module/probe.h"
#include "../../../gcode/gcode.h" #include "../../../gcode/gcode.h"
#include "../../../core/serial.h"
#include "../../../gcode/parser.h" #include "../../../gcode/parser.h"
#include "../../../feature/bedlevel/bedlevel.h" #include "../../../feature/bedlevel/bedlevel.h"
#include "../../../libs/least_squares_fit.h" #include "../../../libs/least_squares_fit.h"
@ -59,8 +60,6 @@
extern float meshedit_done; extern float meshedit_done;
extern long babysteps_done; extern long babysteps_done;
//extern bool set_probe_deployed(bool);
//extern void set_bed_leveling_enabled(bool);
#define SIZE_OF_LITTLE_RAISE 1 #define SIZE_OF_LITTLE_RAISE 1
#define BIG_RAISE_NOT_NEEDED 0 #define BIG_RAISE_NOT_NEEDED 0
@ -720,7 +719,7 @@
} }
} }
} }
safe_delay(5); safe_delay(15);
return false; return false;
} }
@ -754,6 +753,7 @@
while (is_lcd_clicked()) idle(); while (is_lcd_clicked()) idle();
lcd_external_control = false; lcd_external_control = false;
restore_ubl_active_state_and_leave(); restore_ubl_active_state_and_leave();
lcd_quick_feedback(true);
safe_delay(50); // Debounce the Encoder wheel safe_delay(50); // Debounce the Encoder wheel
return; return;
} }
@ -771,6 +771,9 @@
const float measured_z = probe_pt(rawx, rawy, stow_probe, g29_verbose_level); // TODO: Needs error handling const float measured_z = probe_pt(rawx, rawy, stow_probe, g29_verbose_level); // TODO: Needs error handling
z_values[location.x_index][location.y_index] = measured_z; z_values[location.x_index][location.y_index] = measured_z;
} }
MYSERIAL0.flush(); // G29 P2's take a long time to complete. PronterFace can
// over run the serial character buffer with M105's without
// this fix
} while (location.x_index >= 0 && --max_iterations); } while (location.x_index >= 0 && --max_iterations);
@ -853,6 +856,7 @@
do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE); do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
lcd_external_control = false; lcd_external_control = false;
KEEPALIVE_STATE(IN_HANDLER); KEEPALIVE_STATE(IN_HANDLER);
lcd_quick_feedback(true);
ubl.restore_ubl_active_state_and_leave(); ubl.restore_ubl_active_state_and_leave();
} }
@ -908,9 +912,12 @@
SERIAL_PROTOCOL_F(z_values[location.x_index][location.y_index], 6); SERIAL_PROTOCOL_F(z_values[location.x_index][location.y_index], 6);
SERIAL_EOL(); SERIAL_EOL();
} }
MYSERIAL0.flush(); // G29 P2's take a long time to complete. PronterFace can
// over run the serial character buffer with M105's without
// this fix
} while (location.x_index >= 0 && location.y_index >= 0); } while (location.x_index >= 0 && location.y_index >= 0);
if (do_ubl_mesh_map) display_map(g29_map_type); if (do_ubl_mesh_map) display_map(g29_map_type); // show user where we're probing
restore_ubl_active_state_and_leave(); restore_ubl_active_state_and_leave();
KEEPALIVE_STATE(IN_HANDLER); KEEPALIVE_STATE(IN_HANDLER);
@ -1035,12 +1042,12 @@
static uint8_t ubl_state_at_invocation = 0; static uint8_t ubl_state_at_invocation = 0;
#ifdef UBL_DEVEL_DEBUGGING #if ENABLED(UBL_DEVEL_DEBUGGING)
static uint8_t ubl_state_recursion_chk = 0; static uint8_t ubl_state_recursion_chk = 0;
#endif #endif
void unified_bed_leveling::save_ubl_active_state_and_disable() { void unified_bed_leveling::save_ubl_active_state_and_disable() {
#ifdef UBL_DEVEL_DEBUGGING #if ENABLED(UBL_DEVEL_DEBUGGING)
ubl_state_recursion_chk++; ubl_state_recursion_chk++;
if (ubl_state_recursion_chk != 1) { if (ubl_state_recursion_chk != 1) {
SERIAL_ECHOLNPGM("save_ubl_active_state_and_disabled() called multiple times in a row."); SERIAL_ECHOLNPGM("save_ubl_active_state_and_disabled() called multiple times in a row.");
@ -1056,7 +1063,7 @@
} }
void unified_bed_leveling::restore_ubl_active_state_and_leave() { void unified_bed_leveling::restore_ubl_active_state_and_leave() {
#ifdef UBL_DEVEL_DEBUGGING #if ENABLED(UBL_DEVEL_DEBUGGING)
if (--ubl_state_recursion_chk) { if (--ubl_state_recursion_chk) {
SERIAL_ECHOLNPGM("restore_ubl_active_state_and_leave() called too many times."); SERIAL_ECHOLNPGM("restore_ubl_active_state_and_leave() called too many times.");
#if ENABLED(NEWPANEL) #if ENABLED(NEWPANEL)
@ -1110,11 +1117,12 @@
SERIAL_ECHOLNPAIR("MESH_MAX_Y " STRINGIFY(MESH_MAX_Y) "=", MESH_MAX_Y); SERIAL_ECHOLNPAIR("MESH_MAX_Y " STRINGIFY(MESH_MAX_Y) "=", MESH_MAX_Y);
safe_delay(50); safe_delay(50);
SERIAL_ECHOLNPAIR("GRID_MAX_POINTS_X ", GRID_MAX_POINTS_X); SERIAL_ECHOLNPAIR("GRID_MAX_POINTS_X ", GRID_MAX_POINTS_X);
safe_delay(50);
SERIAL_ECHOLNPAIR("GRID_MAX_POINTS_Y ", GRID_MAX_POINTS_Y); SERIAL_ECHOLNPAIR("GRID_MAX_POINTS_Y ", GRID_MAX_POINTS_Y);
safe_delay(25); safe_delay(50);
SERIAL_ECHOLNPAIR("MESH_X_DIST ", MESH_X_DIST); SERIAL_ECHOLNPAIR("MESH_X_DIST ", MESH_X_DIST);
SERIAL_ECHOLNPAIR("MESH_Y_DIST ", MESH_Y_DIST); SERIAL_ECHOLNPAIR("MESH_Y_DIST ", MESH_Y_DIST);
safe_delay(25); safe_delay(50);
SERIAL_PROTOCOLPGM("X-Axis Mesh Points at: "); SERIAL_PROTOCOLPGM("X-Axis Mesh Points at: ");
for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) { for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
@ -1139,7 +1147,7 @@
SERIAL_EOL(); SERIAL_EOL();
safe_delay(50); safe_delay(50);
#ifdef UBL_DEVEL_DEBUGGING #if ENABLED(UBL_DEVEL_DEBUGGING)
SERIAL_PROTOCOLLNPAIR("ubl_state_at_invocation :", ubl_state_at_invocation); SERIAL_PROTOCOLLNPAIR("ubl_state_at_invocation :", ubl_state_at_invocation);
SERIAL_EOL(); SERIAL_EOL();
SERIAL_PROTOCOLLNPAIR("ubl_state_recursion_chk :", ubl_state_recursion_chk); SERIAL_PROTOCOLLNPAIR("ubl_state_recursion_chk :", ubl_state_recursion_chk);
@ -1352,6 +1360,7 @@
lcd_return_to_status(); lcd_return_to_status();
do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES); do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
LCD_MESSAGEPGM(MSG_EDITING_STOPPED); LCD_MESSAGEPGM(MSG_EDITING_STOPPED);
lcd_quick_feedback(true);
} }
void unified_bed_leveling::fine_tune_mesh(const float &rx, const float &ry, const bool do_ubl_mesh_map) { void unified_bed_leveling::fine_tune_mesh(const float &rx, const float &ry, const bool do_ubl_mesh_map) {
@ -1417,6 +1426,9 @@
do_blocking_move_to_z(h_offset + new_z); // Move the nozzle as the point is edited do_blocking_move_to_z(h_offset + new_z); // Move the nozzle as the point is edited
#endif #endif
idle(); idle();
MYSERIAL0.flush(); // G29 P2's take a long time to complete. PronterFace can
// over run the serial character buffer with M105's without
// this fix
} while (!is_lcd_clicked()); } while (!is_lcd_clicked());
if (!lcd_map_control) lcd_return_to_status(); if (!lcd_map_control) lcd_return_to_status();
@ -1426,9 +1438,6 @@
// Let's work on specifying a proper API for the LCD ASAP, OK? // Let's work on specifying a proper API for the LCD ASAP, OK?
lcd_external_control = true; lcd_external_control = true;
// this sequence to detect an is_lcd_clicked() debounce it and leave if it is
// a Press and Hold is repeated in a lot of places (including G26_Mesh_Validation.cpp). This
// should be redone and compressed.
if (click_and_hold(abort_fine_tune)) if (click_and_hold(abort_fine_tune))
goto FINE_TUNE_EXIT; goto FINE_TUNE_EXIT;

View File

@ -437,6 +437,9 @@ inline bool turn_on_heaters() {
SERIAL_EOL(); SERIAL_EOL();
} }
idle(); idle();
MYSERIAL0.flush(); // G26 takes a long time to complete. PronterFace can
// over run the serial character buffer with M105's without
// this fix
} }
#if ENABLED(ULTRA_LCD) #if ENABLED(ULTRA_LCD)
} }
@ -459,6 +462,10 @@ inline bool turn_on_heaters() {
SERIAL_EOL(); SERIAL_EOL();
} }
idle(); idle();
MYSERIAL0.flush(); // G26 takes a long time to complete. PronterFace can
// over run the serial character buffer with M105's without
// this fix
} }
#if ENABLED(ULTRA_LCD) #if ENABLED(ULTRA_LCD)
@ -680,12 +687,12 @@ void GcodeSuite::G26() {
set_bed_leveling_enabled(!parser.seen('D')); set_bed_leveling_enabled(!parser.seen('D'));
if (current_position[Z_AXIS] < Z_CLEARANCE_BETWEEN_PROBES) { if (current_position[Z_AXIS] < Z_CLEARANCE_BETWEEN_PROBES) {
SERIAL_PROTOCOLLNPGM("! move nozzle to Z_CLEARANCE_BETWEEN_PROBES height."); // SERIAL_PROTOCOLLNPGM("! move nozzle to Z_CLEARANCE_BETWEEN_PROBES height.");
SERIAL_ECHOLNPAIR(" Z at:", current_position[Z_AXIS]); // SERIAL_ECHOLNPAIR(" Z at:", current_position[Z_AXIS]);
do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES); do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
stepper.synchronize(); stepper.synchronize();
set_current_from_destination(); set_current_from_destination();
SERIAL_ECHOLNPAIR(" Z now at:", current_position[Z_AXIS]); // SERIAL_ECHOLNPAIR(" Z now at:", current_position[Z_AXIS]);
} }
if (turn_on_heaters() != G26_OK) goto LEAVE; if (turn_on_heaters() != G26_OK) goto LEAVE;
@ -711,14 +718,14 @@ SERIAL_ECHOLNPAIR(" Z now at:", current_position[Z_AXIS]);
// Move nozzle to the specified height for the first layer // Move nozzle to the specified height for the first layer
set_destination_from_current(); set_destination_from_current();
SERIAL_PROTOCOLLNPGM("! moving nozzle to 1st layer height."); //SERIAL_PROTOCOLLNPGM("! moving nozzle to 1st layer height.");
SERIAL_ECHOLNPAIR(" Z1 at:", current_position[Z_AXIS]); //SERIAL_ECHOLNPAIR(" Z1 at:", current_position[Z_AXIS]);
destination[Z_AXIS] = g26_layer_height; destination[Z_AXIS] = g26_layer_height;
move_to(destination, 0.0); move_to(destination, 0.0);
stepper.synchronize(); //stepper.synchronize();
set_destination_from_current(); //set_destination_from_current();
SERIAL_ECHOLNPAIR(" Z2 at:", current_position[Z_AXIS]); //SERIAL_ECHOLNPAIR(" Z2 at:", current_position[Z_AXIS]);
move_to(destination, g26_ooze_amount); move_to(destination, g26_ooze_amount);
#if ENABLED(ULTRA_LCD) #if ENABLED(ULTRA_LCD)
@ -823,11 +830,17 @@ SERIAL_ECHOLNPAIR(" Z2 at:", current_position[Z_AXIS]);
//} //}
print_line_from_here_to_there(rx, ry, g26_layer_height, xe, ye, g26_layer_height); print_line_from_here_to_there(rx, ry, g26_layer_height, xe, ye, g26_layer_height);
MYSERIAL0.flush(); // G26 takes a long time to complete. PronterFace can
// over run the serial character buffer with M105's without
// this fix
} }
if (look_for_lines_to_connect()) if (look_for_lines_to_connect())
goto LEAVE; goto LEAVE;
} }
MYSERIAL0.flush(); // G26 takes a long time to complete. PronterFace can
// over run the serial character buffer with M105's without
// this fix
} while (--g26_repeats && location.x_index >= 0 && location.y_index >= 0); } while (--g26_repeats && location.x_index >= 0 && location.y_index >= 0);
LEAVE: LEAVE:

View File

@ -90,8 +90,7 @@ void queue_setup() {
* Clear the Marlin command queue * Clear the Marlin command queue
*/ */
void clear_command_queue() { void clear_command_queue() {
cmd_queue_index_r = cmd_queue_index_w; cmd_queue_index_r = cmd_queue_index_w = commands_in_queue = 0;
commands_in_queue = 0;
} }
/** /**