Skip to content

Commit aec85ad

Browse files
committed
Start of process to get UBL running again.
The wait_for_user change totally broke UBL. But there is stuff wrong now in the thermal code and/or LCD Panel code.
1 parent b47eaf1 commit aec85ad

File tree

3 files changed

+99
-59
lines changed

3 files changed

+99
-59
lines changed

Marlin/G26_Mesh_Validation_Tool.cpp

Lines changed: 51 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@
199199
set_current_to_destination();
200200
}
201201

202+
ubl_has_control_of_lcd_panel = true; // Take control of the LCD Panel!
202203
if (turn_on_heaters()) // Turn on the heaters, leave the command if anything
203204
goto LEAVE; // has gone wrong.
204205

@@ -233,19 +234,30 @@
233234
move_to(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], 0.0);
234235
move_to(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], ooze_amount);
235236

236-
ubl_has_control_of_lcd_panel++; // Take control of the LCD Panel!
237+
ubl_has_control_of_lcd_panel = true; // Take control of the LCD Panel!
237238
debug_current_and_destination((char*)"Starting G26 Mesh Validation Pattern.");
238239

239-
wait_for_user = true;
240+
/**
241+
* Declare and generate a sin() & cos() table to be used during the circle drawing. This will lighten
242+
* the CPU load and make the arc drawing faster and more smooth
243+
*/
244+
float sin_table[360 / 30 + 1], cos_table[360 / 30 + 1];
245+
for (i = 0; i <= 360 / 30; i++) {
246+
cos_table[i] = SIZE_OF_INTERSECTION_CIRCLES * cos(RADIANS(valid_trig_angle(i * 30.0)));
247+
sin_table[i] = SIZE_OF_INTERSECTION_CIRCLES * sin(RADIANS(valid_trig_angle(i * 30.0)));
248+
}
240249

241250
do {
242251

243-
if (!wait_for_user) { // Check if the user wants to stop the Mesh Validation
252+
if (ubl_lcd_clicked()) { // Check if the user wants to stop the Mesh Validation
244253
strcpy(lcd_status_message, "Mesh Validation Stopped."); // We can't do lcd_setstatus() without having it continue;
245254
#if ENABLED(ULTRA_LCD)
246255
lcd_setstatus("Mesh Validation Stopped.", true);
247256
lcd_quick_feedback();
248257
#endif
258+
while (ubl_lcd_clicked()) { // Wait until the user is done pressing the
259+
idle(); // Encoder Wheel if that is why we are leaving
260+
}
249261
goto LEAVE;
250262
}
251263

@@ -309,16 +321,6 @@
309321
end_angle = 360.0;
310322
}
311323

312-
/**
313-
* Declare and generate a sin() & cos() table to be used during the circle drawing. This will lighten
314-
* the CPU load and make the arc drawing faster and more smooth
315-
*/
316-
float sin_table[360 / 30 + 1], cos_table[360 / 30 + 1];
317-
for (i = 0; i <= 360 / 30; i++) {
318-
cos_table[i] = SIZE_OF_INTERSECTION_CIRCLES * cos(RADIANS(valid_trig_angle(i * 30.0)));
319-
sin_table[i] = SIZE_OF_INTERSECTION_CIRCLES * sin(RADIANS(valid_trig_angle(i * 30.0)));
320-
}
321-
322324
for (tmp = start_angle; tmp < end_angle - 0.1; tmp += 30.0) {
323325
int tmp_div_30 = tmp / 30.0;
324326
if (tmp_div_30 < 0) tmp_div_30 += 360 / 30;
@@ -351,35 +353,41 @@
351353
}
352354

353355
print_line_from_here_to_there(x, y, layer_height, xe, ye, layer_height);
356+
354357
}
355-
lcd_init_counter++;
356-
if (lcd_init_counter > 10) {
357-
lcd_init_counter = 0;
358-
lcd_init(); // Some people's LCD Displays are locking up. This might help them
359-
}
358+
// lcd_init_counter++;
359+
// if (lcd_init_counter > 10) {
360+
// lcd_init_counter = 0;
361+
// lcd_init(); // Some people's LCD Displays are locking up. This might help them
362+
// ubl_has_control_of_lcd_panel = true; // Make sure UBL still is controlling the LCD Panel
363+
// }
360364

365+
// If the end point of the line is closer to the nozzle, we are going to
361366
debug_current_and_destination((char*)"Looking for lines to connect.");
362367
look_for_lines_to_connect();
363368
debug_current_and_destination((char*)"Done with line connect.");
364369
}
365370

366371
debug_current_and_destination((char*)"Done with current circle.");
367372

373+
// If the end point of the line is closer to the nozzle, we are going to
374+
368375
}
369376
while (location.x_index >= 0 && location.y_index >= 0);
370377

371378
LEAVE:
372379

373-
wait_for_user = false;
374-
380+
while (ubl_lcd_clicked()) { // Wait until the user is done pressing the
381+
idle(); // Encoder Wheel if that is why we are leaving
382+
}
375383
retract_filament();
376384
destination[Z_AXIS] = Z_CLEARANCE_BETWEEN_PROBES; // Raise the nozzle
377385

378386
debug_current_and_destination((char*)"ready to do Z-Raise.");
379-
move_to( destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], 0); // Raise the nozzle
387+
move_to( destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], 0); // Raise the nozzle
380388
debug_current_and_destination((char*)"done doing Z-Raise.");
381389

382-
destination[X_AXIS] = x_pos; // Move back to the starting position
390+
destination[X_AXIS] = x_pos; // Move back to the starting position
383391
destination[Y_AXIS] = y_pos;
384392
destination[Z_AXIS] = Z_CLEARANCE_BETWEEN_PROBES; // Keep the nozzle where it is
385393

@@ -538,6 +546,8 @@
538546
float feed_value;
539547
static float last_z = -999.99;
540548

549+
550+
541551
bool has_xy_component = (x != current_position[X_AXIS] || y != current_position[Y_AXIS]); // Check if X or Y is involved in the movement.
542552

543553
if (g26_debug_flag) {
@@ -591,6 +601,7 @@
591601

592602
stepper.synchronize();
593603
set_destination_to_current();
604+
594605
}
595606

596607
void retract_filament() {
@@ -658,16 +669,23 @@
658669
if (g26_debug_flag)
659670
SERIAL_ECHOLNPGM(" filament retracted.");
660671
}
672+
// If the end point of the line is closer to the nozzle, we are going to
661673
move_to(sx, sy, sz, 0.0); // Get to the starting point with no extrusion
662674

675+
// If the end point of the line is closer to the nozzle, we are going to
676+
663677
float e_pos_delta = Line_Length * g26_e_axis_feedrate * extrusion_multiplier;
664678

665679
un_retract_filament();
680+
681+
// If the end point of the line is closer to the nozzle, we are going to
666682
if (g26_debug_flag) {
667683
SERIAL_ECHOLNPGM(" doing printing move.");
668684
debug_current_and_destination((char*)"doing final move_to() inside print_line_from_here_to_there()");
669685
}
670686
move_to(ex, ey, ez, e_pos_delta); // Get to the ending point with an appropriate amount of extrusion
687+
688+
// If the end point of the line is closer to the nozzle, we are going to
671689
}
672690

673691
/**
@@ -815,18 +833,18 @@
815833
lcd_setstatus("G26 Heating Bed.", true);
816834
lcd_quick_feedback();
817835
#endif
818-
ubl_has_control_of_lcd_panel++;
836+
ubl_has_control_of_lcd_panel = true;
819837
thermalManager.setTargetBed(bed_temp);
820-
wait_for_user = true;
821838
while (abs(thermalManager.degBed() - bed_temp) > 3) {
822-
if (!wait_for_user) {
839+
if (ubl_lcd_clicked()) {
823840
strcpy(lcd_status_message, "Leaving G26"); // We can't do lcd_setstatus() without having it continue;
824841
lcd_setstatus("Leaving G26", true); // Now we do it right.
842+
while (ubl_lcd_clicked()) // Debounce Encoder Wheel
843+
idle();
825844
return UBL_ERR;
826845
}
827846
idle();
828847
}
829-
wait_for_user = false;
830848
#if ENABLED(ULTRA_LCD)
831849
}
832850
lcd_setstatus("G26 Heating Nozzle.", true);
@@ -836,16 +854,16 @@
836854

837855
// Start heating the nozzle and wait for it to reach temperature.
838856
thermalManager.setTargetHotend(hotend_temp, 0);
839-
wait_for_user = true;
840857
while (abs(thermalManager.degHotend(0) - hotend_temp) > 3) {
841-
if (!wait_for_user) {
858+
if (ubl_lcd_clicked()) {
842859
strcpy(lcd_status_message, "Leaving G26"); // We can't do lcd_setstatus() without having it continue;
843860
lcd_setstatus("Leaving G26", true); // Now we do it right.
861+
while (ubl_lcd_clicked()) // Debounce Encoder Wheel
862+
idle();
844863
return UBL_ERR;
845864
}
846865
idle();
847866
}
848-
wait_for_user = false;
849867

850868
#if ENABLED(ULTRA_LCD)
851869
lcd_setstatus("", true);
@@ -869,9 +887,7 @@
869887
un_retract_filament(); // Lets make sure the G26 command doesn't think the filament is
870888
// retracted(). We are here because we want to prime the nozzle.
871889
// So let's just unretract just to be sure.
872-
873-
wait_for_user = true;
874-
while (wait_for_user) {
890+
while (!ubl_lcd_clicked()) {
875891
chirp_at_user();
876892
destination[E_AXIS] += 0.25;
877893
#ifdef PREVENT_LENGTHY_EXTRUDE
@@ -894,9 +910,10 @@
894910

895911
strcpy(lcd_status_message, "Done Priming"); // We can't do lcd_setstatus() without having it continue;
896912
// So... We cheat to get a message up.
913+
while (ubl_lcd_clicked()) // Debounce Encoder Wheel
914+
idle();
897915

898916
#if ENABLED(ULTRA_LCD)
899-
ubl_has_control_of_lcd_panel = false;
900917
lcd_setstatus("Done Priming", true); // Now we do it right.
901918
lcd_quick_feedback();
902919
#endif
@@ -917,6 +934,7 @@
917934
set_destination_to_current();
918935
retract_filament();
919936
}
937+
920938
return UBL_OK;
921939
}
922940

Marlin/UBL_Bed_Leveling.cpp

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,13 @@
175175
current_xi = ubl.get_cell_index_x(current_position[X_AXIS] + (MESH_X_DIST) / 2.0);
176176
current_yi = ubl.get_cell_index_y(current_position[Y_AXIS] + (MESH_Y_DIST) / 2.0);
177177

178-
for (i = 0; i < UBL_MESH_NUM_X_POINTS - 1; i++)
179-
SERIAL_ECHOPGM(" ");
178+
for (i = 0; i < UBL_MESH_NUM_X_POINTS - 1; i++) {
179+
SERIAL_ECHOPGM(" ");
180+
#if TX_BUFFER_SIZE>0
181+
MYSERIAL.flushTX();
182+
#endif
183+
delay(15);
184+
}
180185

181186
SERIAL_ECHOPAIR("(", UBL_MESH_NUM_X_POINTS - 1);
182187
SERIAL_ECHOPAIR(",", UBL_MESH_NUM_Y_POINTS - 1);
@@ -188,8 +193,13 @@
188193
SERIAL_ECHOPAIR(",", UBL_MESH_MAX_Y);
189194
SERIAL_CHAR(')');
190195

191-
for (i = 0; i < UBL_MESH_NUM_X_POINTS - 1; i++)
192-
SERIAL_ECHOPGM(" ");
196+
for (i = 0; i < UBL_MESH_NUM_X_POINTS - 1; i++) {
197+
SERIAL_ECHOPGM(" ");
198+
#if TX_BUFFER_SIZE>0
199+
MYSERIAL.flushTX();
200+
#endif
201+
delay(15);
202+
}
193203

194204
SERIAL_ECHOPAIR("(", UBL_MESH_MAX_X);
195205
SERIAL_ECHOPAIR(",", UBL_MESH_MAX_Y);
@@ -205,13 +215,17 @@
205215
SERIAL_CHAR(i == current_xi && j == current_yi ? '[' : ' ');
206216

207217
if (isnan(f))
208-
SERIAL_PROTOCOLPGM(" . ");
218+
SERIAL_PROTOCOLPGM(" . ");
209219
else {
210220
// if we don't do this, the columns won't line up nicely
211221
if (f >= 0.0) SERIAL_CHAR(' ');
212-
SERIAL_PROTOCOL_F(f, 5);
222+
SERIAL_PROTOCOL_F(f, 3);
213223
idle();
214224
}
225+
#if TX_BUFFER_SIZE>0
226+
MYSERIAL.flushTX();
227+
#endif
228+
delay(15);
215229
if (i == current_xi && j == current_yi) // is the nozzle here? if so, finish marking the number
216230
SERIAL_CHAR(']');
217231
else
@@ -231,27 +245,34 @@
231245
SERIAL_ECHOPAIR(",", int(UBL_MESH_MIN_Y));
232246
SERIAL_ECHOPGM(") ");
233247

234-
for (i = 0; i < UBL_MESH_NUM_X_POINTS - 1; i++)
235-
SERIAL_ECHOPGM(" ");
248+
for (i = 0; i < UBL_MESH_NUM_X_POINTS - 1; i++) {
249+
SERIAL_ECHOPGM(" ");
250+
#if TX_BUFFER_SIZE>0
251+
MYSERIAL.flushTX();
252+
#endif
253+
delay(15);
254+
}
236255

237256
SERIAL_ECHOPAIR("(", int(UBL_MESH_MAX_X));
238257
SERIAL_ECHOPAIR(",", int(UBL_MESH_MIN_Y));
239258
SERIAL_CHAR(')');
240-
// }
259+
SERIAL_EOL;
241260

242261
SERIAL_ECHOPAIR("(", 0);
243262
SERIAL_ECHOPAIR(",", 0);
244263
SERIAL_ECHOPGM(") ");
245264

246-
for (i = 0; i < UBL_MESH_NUM_X_POINTS - 1; i++)
247-
SERIAL_ECHOPGM(" ");
265+
for (i = 0; i < UBL_MESH_NUM_X_POINTS - 1; i++) {
266+
SERIAL_ECHOPGM(" ");
267+
#if TX_BUFFER_SIZE>0
268+
MYSERIAL.flushTX();
269+
#endif
270+
delay(15);
271+
}
248272

249273
SERIAL_ECHOPAIR("(", UBL_MESH_NUM_X_POINTS-1);
250274
SERIAL_ECHOPAIR(",", 0);
251-
SERIAL_CHAR(')');
252-
253-
SERIAL_CHAR(' ');
254-
SERIAL_EOL;
275+
SERIAL_ECHOLNPGM(")");
255276
}
256277

257278
bool unified_bed_leveling::sanity_check() {

Marlin/UBL_G29.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -594,18 +594,18 @@
594594
save_ubl_active_state_and_disable();
595595
//measured_z = probe_pt(x_pos + X_PROBE_OFFSET_FROM_EXTRUDER, y_pos + Y_PROBE_OFFSET_FROM_EXTRUDER, ProbeDeployAndStow, g29_verbose_level);
596596

597+
ubl_has_control_of_lcd_panel = true;// Grab the LCD Hardware
597598
measured_z = 1.5;
598599
do_blocking_move_to_z(measured_z); // Get close to the bed, but leave some space so we don't damage anything
599600
// The user is not going to be locking in a new Z-Offset very often so
600601
// it won't be that painful to spin the Encoder Wheel for 1.5mm
601602
lcd_implementation_clear();
602603
lcd_z_offset_edit_setup(measured_z);
603-
wait_for_user = true;
604604
do {
605605
measured_z = lcd_z_offset_edit();
606606
idle();
607607
do_blocking_move_to_z(measured_z);
608-
} while (wait_for_user);
608+
} while (!ubl_lcd_clicked());
609609

610610
ubl_has_control_of_lcd_panel++; // There is a race condition for the Encoder Wheel getting clicked.
611611
// It could get detected in lcd_mesh_edit (actually _lcd_mesh_fine_tune)
@@ -707,14 +707,17 @@
707707
save_ubl_active_state_and_disable(); // we don't do bed level correction because we want the raw data when we probe
708708
DEPLOY_PROBE();
709709

710-
wait_for_user = true;
711710
do {
712-
if (!wait_for_user) {
713-
SERIAL_PROTOCOLLNPGM("\nMesh only partially populated.");
711+
if (ubl_lcd_clicked()) {
712+
SERIAL_PROTOCOLLNPGM("\nMesh only partially populated.\n");
714713
lcd_quick_feedback();
715-
ubl_has_control_of_lcd_panel = false;
716714
STOW_PROBE();
715+
while (ubl_lcd_clicked() ) {
716+
idle();
717+
}
718+
ubl_has_control_of_lcd_panel = false;
717719
restore_ubl_active_state_and_leave();
720+
delay(50); // Debounce the Encoder wheel
718721
return;
719722
}
720723

@@ -737,7 +740,6 @@
737740

738741
LEAVE:
739742

740-
wait_for_user = false;
741743
STOW_PROBE();
742744
restore_ubl_active_state_and_leave();
743745

@@ -813,8 +815,7 @@
813815
}
814816

815817
float use_encoder_wheel_to_measure_point() {
816-
wait_for_user = true;
817-
while (wait_for_user) { // we need the loop to move the nozzle based on the encoder wheel here!
818+
while (!ubl_lcd_clicked()) { // we need the loop to move the nozzle based on the encoder wheel here!
818819
idle();
819820
if (ubl_encoderDiff) {
820821
do_blocking_move_to_z(current_position[Z_AXIS] + 0.01 * float(ubl_encoderDiff));
@@ -891,8 +892,8 @@
891892
last_x = xProbe;
892893
last_y = yProbe;
893894

894-
wait_for_user = true;
895-
while (wait_for_user) { // we need the loop to move the nozzle based on the encoder wheel here!
895+
ubl_has_control_of_lcd_panel = true;
896+
while (!ubl_lcd_clicked) { // we need the loop to move the nozzle based on the encoder wheel here!
896897
idle();
897898
if (ubl_encoderDiff) {
898899
do_blocking_move_to_z(current_position[Z_AXIS] + float(ubl_encoderDiff) / 100.0);

0 commit comments

Comments
 (0)