Skip to content

Commit d8724bb

Browse files
committed
Get G29's P1 (Automated Probing) working again.
Incorrect optimizations of data types and ternary operators caused some issues.
1 parent 8d53298 commit d8724bb

File tree

2 files changed

+34
-27
lines changed

2 files changed

+34
-27
lines changed

Marlin/UBL_G29.cpp

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include "planner.h"
3434
#include "ultralcd.h"
3535

36-
#include <avr/io.h>
36+
#include <math.h>
3737

3838
void lcd_babystep_z();
3939
void lcd_return_to_status();
@@ -300,7 +300,7 @@
300300

301301
int ubl_eeprom_start = -1;
302302
bool ubl_has_control_of_lcd_panel = false;
303-
volatile uint8_t ubl_encoderDiff = 0; // Volatile because it's changed by Temperature ISR button update
303+
volatile int8_t ubl_encoderDiff = 0; // Volatile because it's changed by Temperature ISR button update
304304

305305
// The simple parameter flags and values are 'static' so parameter parsing can be in a support routine.
306306
static int g29_verbose_level = 0, phase_value = -1, repetition_cnt = 1,
@@ -496,7 +496,7 @@
496496
SERIAL_ECHO_START;
497497
SERIAL_ECHOLNPGM("Checking G29 has control of LCD Panel:");
498498
wait_for_user = true;
499-
while (wait_for_user) {
499+
while (!ubl_lcd_clicked()) {
500500
safe_delay(250);
501501
SERIAL_ECHO((int)ubl_encoderDiff);
502502
ubl_encoderDiff = 0;
@@ -1310,7 +1310,7 @@
13101310

13111311
if (far_flag) { // If doing the far_flag action, we want to be as far as possible
13121312
for (k = 0; k < UBL_MESH_NUM_X_POINTS; k++) { // from the starting point and from any other probed points. We
1313-
for (l = 0; j < UBL_MESH_NUM_Y_POINTS; l++) { // want the next point spread out and filling in any blank spaces
1313+
for (l = 0; l < UBL_MESH_NUM_Y_POINTS; l++) { // want the next point spread out and filling in any blank spaces
13141314
if ( !isnan(z_values[k][l])) { // in the mesh. So we add in some of the distance to every probed
13151315
distance += (i-k)*(i-k)*MESH_X_DIST*.05; // point we can find.
13161316
distance += (j-l)*(j-l)*MESH_Y_DIST*.05;
@@ -1366,15 +1366,12 @@
13661366

13671367
do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE); // Move the nozzle to where we are going to edit
13681368
do_blocking_move_to_xy(xProbe, yProbe);
1369-
float new_z = z_values[location.x_index][location.y_index] + 0.001;
1370-
1371-
round_off = (int32_t)(new_z * 1000.0 + 2.5); // we chop off the last digits just to be clean. We are rounding to the
1372-
round_off -= (round_off % 5L); // closest 0 or 5 at the 3rd decimal place.
1369+
float new_z = z_values[location.x_index][location.y_index];
1370+
1371+
round_off = (int32_t)(new_z * 1000.0); // we chop off the last digits just to be clean. We are rounding to the
13731372
new_z = float(round_off) / 1000.0;
13741373

1375-
//SERIAL_ECHOPGM("Mesh Point Currently At: ");
1376-
//SERIAL_PROTOCOL_F(new_z, 6);
1377-
//SERIAL_EOL;
1374+
ubl_has_control_of_lcd_panel = true;
13781375

13791376
lcd_implementation_clear();
13801377
lcd_mesh_edit_setup(new_z);
@@ -1383,20 +1380,20 @@
13831380
do {
13841381
new_z = lcd_mesh_edit();
13851382
idle();
1386-
} while (wait_for_user);
1383+
} while (!ubl_lcd_clicked());
13871384

13881385
lcd_return_to_status();
13891386

1390-
ubl_has_control_of_lcd_panel++; // There is a race condition for the Encoder Wheel getting clicked.
1391-
// It could get detected in lcd_mesh_edit (actually _lcd_mesh_fine_tune)
1392-
// or here.
1387+
ubl_has_control_of_lcd_panel = true; // There is a race condition for the Encoder Wheel getting clicked.
1388+
// It could get detected in lcd_mesh_edit (actually _lcd_mesh_fine_tune)
1389+
// or here.
13931390

13941391
const millis_t nxt = millis() + 1500UL;
13951392
while (ubl_lcd_clicked()) { // debounce and watch for abort
13961393
idle();
13971394
if (ELAPSED(millis(), nxt)) {
13981395
lcd_return_to_status();
1399-
SERIAL_PROTOCOLLNPGM("\nFine Tuning of Mesh Stopped.");
1396+
// SERIAL_PROTOCOLLNPGM("\nFine Tuning of Mesh Stopped.");
14001397
do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
14011398
lcd_setstatus("Mesh Editing Stopped", true);
14021399

Marlin/ultralcd.cpp

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ uint16_t max_display_update_time = 0;
125125

126126
#if ENABLED(AUTO_BED_LEVELING_UBL)
127127
extern bool ubl_has_control_of_lcd_panel;
128-
extern uint8_t ubl_encoderDiff;
128+
extern int8_t ubl_encoderDiff;
129129
#endif
130130

131131
#if HAS_POWER_SWITCH
@@ -859,29 +859,30 @@ void kill_screen(const char* lcd_msg) {
859859
static int ubl_encoderPosition = 0;
860860

861861
static void _lcd_mesh_fine_tune(const char* msg) {
862-
static millis_t next_click = 0;
862+
// static millis_t next_click = 0; // We are going to accelerate the number speed when the wheel
863+
// // turns fast. But that isn't implemented yet
863864
int16_t last_digit;
864865
int32_t rounded;
865866

866867
defer_return_to_status = true;
867868
if (ubl_encoderDiff) {
868-
// If moving the Encoder wheel very slowly, move by just 1 position
869-
ubl_encoderPosition = ELAPSED(millis(), next_click)
870-
? ubl_encoderDiff > 0 ? 1 : -1
871-
: ubl_encoderDiff * 2;
869+
if ( ubl_encoderDiff > 0 )
870+
ubl_encoderPosition = 1;
871+
else {
872+
ubl_encoderPosition = -1;
873+
}
872874

873875
ubl_encoderDiff = 0;
874-
next_click = millis() + 200L;
876+
// next_click = millis();
875877

876-
mesh_edit_accumulator += float((int32_t)ubl_encoderPosition) * .005 / 2.0;
878+
mesh_edit_accumulator += ( (float) (ubl_encoderPosition)) * .005 / 2.0 ;
877879
mesh_edit_value = mesh_edit_accumulator;
878880
encoderPosition = 0;
879881
lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
880882

881883
rounded = (int32_t)(mesh_edit_value * 1000.0);
882884
last_digit = rounded % 5L; //10L;
883885
rounded -= last_digit;
884-
last_digit = rounded % 5L; //10L;
885886
mesh_edit_value = float(rounded) / 1000.0;
886887
}
887888

@@ -890,19 +891,28 @@ void kill_screen(const char* lcd_msg) {
890891
}
891892

892893

894+
void _lcd_mesh_edit_NOP() {
895+
defer_return_to_status = true;
896+
}
897+
898+
893899
void _lcd_mesh_edit() {
894900
_lcd_mesh_fine_tune(PSTR("Mesh Editor: "));
895901
defer_return_to_status = true;
896902
}
897903

898904
float lcd_mesh_edit() {
899-
lcd_goto_screen(_lcd_mesh_edit);
905+
lcd_goto_screen(_lcd_mesh_edit_NOP);
906+
_lcd_mesh_fine_tune(PSTR("Mesh Editor: "));
907+
defer_return_to_status = true;
900908
return mesh_edit_value;
901909
}
902910

903911
void lcd_mesh_edit_setup(float initial) {
904912
mesh_edit_value = mesh_edit_accumulator = initial;
905-
lcd_goto_screen(_lcd_mesh_edit);
913+
lcd_goto_screen(_lcd_mesh_edit_NOP);
914+
mesh_edit_value = mesh_edit_accumulator = initial;
915+
defer_return_to_status = true;
906916
}
907917

908918
void _lcd_z_offset_edit() {

0 commit comments

Comments
 (0)