Browse Source

Get G29's P1 (Automated Probing) working again.

Incorrect optimizations of data types and ternary operators caused some
issues.
Roxy-3D 7 years ago
parent
commit
d8724bb546
2 changed files with 34 additions and 27 deletions
  1. 13
    16
      Marlin/UBL_G29.cpp
  2. 21
    11
      Marlin/ultralcd.cpp

+ 13
- 16
Marlin/UBL_G29.cpp View File

@@ -33,7 +33,7 @@
33 33
   #include "planner.h"
34 34
   #include "ultralcd.h"
35 35
 
36
-  #include <avr/io.h>
36
+  #include <math.h>
37 37
 
38 38
   void lcd_babystep_z();
39 39
   void lcd_return_to_status();
@@ -300,7 +300,7 @@
300 300
 
301 301
   int ubl_eeprom_start = -1;
302 302
   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
304 304
 
305 305
   // The simple parameter flags and values are 'static' so parameter parsing can be in a support routine.
306 306
   static int g29_verbose_level = 0, phase_value = -1, repetition_cnt = 1,
@@ -496,7 +496,7 @@
496 496
           SERIAL_ECHO_START;
497 497
           SERIAL_ECHOLNPGM("Checking G29 has control of LCD Panel:");
498 498
           wait_for_user = true;
499
-          while (wait_for_user) {
499
+          while (!ubl_lcd_clicked()) {
500 500
             safe_delay(250);
501 501
             SERIAL_ECHO((int)ubl_encoderDiff);
502 502
             ubl_encoderDiff = 0;
@@ -1310,7 +1310,7 @@
1310 1310
 
1311 1311
 	  if (far_flag) {                                    // If doing the far_flag action, we want to be as far as possible
1312 1312
             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
1314 1314
                 if ( !isnan(z_values[k][l])) {               // in the mesh.   So we add in some of the distance to every probed 
1315 1315
                   distance += (i-k)*(i-k)*MESH_X_DIST*.05;   // point we can find.
1316 1316
                   distance += (j-l)*(j-l)*MESH_Y_DIST*.05;
@@ -1366,15 +1366,12 @@
1366 1366
 
1367 1367
       do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);    // Move the nozzle to where we are going to edit
1368 1368
       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
1373 1372
       new_z = float(round_off) / 1000.0;
1374 1373
 
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;
1378 1375
 
1379 1376
       lcd_implementation_clear();
1380 1377
       lcd_mesh_edit_setup(new_z);
@@ -1383,20 +1380,20 @@
1383 1380
       do {
1384 1381
         new_z = lcd_mesh_edit();
1385 1382
         idle();
1386
-      } while (wait_for_user);
1383
+      } while (!ubl_lcd_clicked());
1387 1384
 
1388 1385
       lcd_return_to_status();
1389 1386
 
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.
1393 1390
 
1394 1391
       const millis_t nxt = millis() + 1500UL;
1395 1392
       while (ubl_lcd_clicked()) { // debounce and watch for abort
1396 1393
         idle();
1397 1394
         if (ELAPSED(millis(), nxt)) {
1398 1395
           lcd_return_to_status();
1399
-          SERIAL_PROTOCOLLNPGM("\nFine Tuning of Mesh Stopped.");
1396
+//        SERIAL_PROTOCOLLNPGM("\nFine Tuning of Mesh Stopped.");
1400 1397
           do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
1401 1398
           lcd_setstatus("Mesh Editing Stopped", true);
1402 1399
 

+ 21
- 11
Marlin/ultralcd.cpp View File

@@ -125,7 +125,7 @@ uint16_t max_display_update_time = 0;
125 125
 
126 126
   #if ENABLED(AUTO_BED_LEVELING_UBL)
127 127
     extern bool ubl_has_control_of_lcd_panel;
128
-    extern uint8_t ubl_encoderDiff;
128
+    extern int8_t ubl_encoderDiff;
129 129
   #endif
130 130
 
131 131
   #if HAS_POWER_SWITCH
@@ -859,21 +859,23 @@ void kill_screen(const char* lcd_msg) {
859 859
     static int ubl_encoderPosition = 0;
860 860
 
861 861
     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
863 864
       int16_t last_digit;
864 865
       int32_t rounded;
865 866
 
866 867
       defer_return_to_status = true;
867 868
       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
+        }
872 874
 
873 875
         ubl_encoderDiff = 0;
874
-        next_click = millis() + 200L;
876
+//      next_click = millis();
875 877
 
876
-        mesh_edit_accumulator += float((int32_t)ubl_encoderPosition) * .005 / 2.0;
878
+        mesh_edit_accumulator += ( (float) (ubl_encoderPosition)) * .005 / 2.0 ;
877 879
         mesh_edit_value = mesh_edit_accumulator;
878 880
         encoderPosition = 0;
879 881
         lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
@@ -881,7 +883,6 @@ void kill_screen(const char* lcd_msg) {
881 883
         rounded = (int32_t)(mesh_edit_value * 1000.0);
882 884
         last_digit = rounded % 5L; //10L;
883 885
         rounded -= last_digit;
884
-        last_digit = rounded % 5L; //10L;
885 886
         mesh_edit_value = float(rounded) / 1000.0;
886 887
       }
887 888
 
@@ -890,19 +891,28 @@ void kill_screen(const char* lcd_msg) {
890 891
     }
891 892
 
892 893
 
894
+    void _lcd_mesh_edit_NOP() {
895
+      defer_return_to_status = true;
896
+    }
897
+
898
+
893 899
     void _lcd_mesh_edit() {
894 900
       _lcd_mesh_fine_tune(PSTR("Mesh Editor: "));
895 901
       defer_return_to_status = true;
896 902
     }
897 903
 
898 904
     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;
900 908
       return mesh_edit_value;
901 909
     }
902 910
 
903 911
     void lcd_mesh_edit_setup(float initial) {
904 912
       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; 
906 916
     }
907 917
 
908 918
     void _lcd_z_offset_edit() {

Loading…
Cancel
Save