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
7 changed files with 55 additions and 31 deletions

View File

@ -93,7 +93,7 @@ class unified_bed_leveling {
static bool g29_parameter_parsing();
static void find_mean_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_probed_grid(const bool do_ubl_mesh_map);
static void g29_what_command();
@ -117,8 +117,8 @@ class unified_bed_leveling {
static void save_ubl_active_state_and_disable();
static void restore_ubl_active_state_and_leave();
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_furthest_invalid_mesh_point();
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() _O0;
static void reset();
static void invalidate();
static void set_all_mesh_points_to_value(const float);

View File

@ -36,6 +36,7 @@
#include "../../../module/planner.h"
#include "../../../module/probe.h"
#include "../../../gcode/gcode.h"
#include "../../../core/serial.h"
#include "../../../gcode/parser.h"
#include "../../../feature/bedlevel/bedlevel.h"
#include "../../../libs/least_squares_fit.h"
@ -59,8 +60,6 @@
extern float meshedit_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 BIG_RAISE_NOT_NEEDED 0
@ -720,7 +719,7 @@
}
}
}
safe_delay(5);
safe_delay(15);
return false;
}
@ -754,6 +753,7 @@
while (is_lcd_clicked()) idle();
lcd_external_control = false;
restore_ubl_active_state_and_leave();
lcd_quick_feedback(true);
safe_delay(50); // Debounce the Encoder wheel
return;
}
@ -771,6 +771,9 @@
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;
}
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);
@ -853,6 +856,7 @@
do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
lcd_external_control = false;
KEEPALIVE_STATE(IN_HANDLER);
lcd_quick_feedback(true);
ubl.restore_ubl_active_state_and_leave();
}
@ -908,9 +912,12 @@
SERIAL_PROTOCOL_F(z_values[location.x_index][location.y_index], 6);
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);
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();
KEEPALIVE_STATE(IN_HANDLER);
@ -1035,12 +1042,12 @@
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;
#endif
void unified_bed_leveling::save_ubl_active_state_and_disable() {
#ifdef UBL_DEVEL_DEBUGGING
#if ENABLED(UBL_DEVEL_DEBUGGING)
ubl_state_recursion_chk++;
if (ubl_state_recursion_chk != 1) {
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() {
#ifdef UBL_DEVEL_DEBUGGING
#if ENABLED(UBL_DEVEL_DEBUGGING)
if (--ubl_state_recursion_chk) {
SERIAL_ECHOLNPGM("restore_ubl_active_state_and_leave() called too many times.");
#if ENABLED(NEWPANEL)
@ -1110,11 +1117,12 @@
SERIAL_ECHOLNPAIR("MESH_MAX_Y " STRINGIFY(MESH_MAX_Y) "=", MESH_MAX_Y);
safe_delay(50);
SERIAL_ECHOLNPAIR("GRID_MAX_POINTS_X ", GRID_MAX_POINTS_X);
safe_delay(50);
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_Y_DIST ", MESH_Y_DIST);
safe_delay(25);
safe_delay(50);
SERIAL_PROTOCOLPGM("X-Axis Mesh Points at: ");
for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
@ -1139,7 +1147,7 @@
SERIAL_EOL();
safe_delay(50);
#ifdef UBL_DEVEL_DEBUGGING
#if ENABLED(UBL_DEVEL_DEBUGGING)
SERIAL_PROTOCOLLNPAIR("ubl_state_at_invocation :", ubl_state_at_invocation);
SERIAL_EOL();
SERIAL_PROTOCOLLNPAIR("ubl_state_recursion_chk :", ubl_state_recursion_chk);
@ -1352,6 +1360,7 @@
lcd_return_to_status();
do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
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) {
@ -1417,6 +1426,9 @@
do_blocking_move_to_z(h_offset + new_z); // Move the nozzle as the point is edited
#endif
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());
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?
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))
goto FINE_TUNE_EXIT;