Explorar el Código

Numerous UBL-related changes:

* relocated ubl state to config. store:
 * removed a number of ubl state variables and padding which were largely unused - saved 58 bytes of both SRAM and EEPROM;
 * modified ubl sanity_check - no longer checks removed state variables that were otherwise unused, where checking didn't seem to accomplish anything, ultimately;
 * removed pre_initialized state, saving 64 bytes of SRAM;
 * removed automatic saving of UBL state after UBL activation/deactivation;
* consolidated multiple GRID_MAX_POINTS_X/Y to 'Global Leveling' section of EEPROM;
* minor update to G29 Sx notes/instructions;
* renamed mesh load and save parameter to 'slot' from 'm' for clarity;
Brian hace 7 años
padre
commit
f41fb2b635
Se han modificado 6 ficheros con 67 adiciones y 121 borrados
  1. 4
    0
      Marlin/Configuration_adv.h
  2. 0
    1
      Marlin/Marlin_main.cpp
  3. 46
    24
      Marlin/configuration_store.cpp
  4. 12
    62
      Marlin/ubl.cpp
  5. 3
    25
      Marlin/ubl.h
  6. 2
    9
      Marlin/ubl_G29.cpp

+ 4
- 0
Marlin/Configuration_adv.h Ver fichero

@@ -666,6 +666,10 @@
666 666
   #define UBL_MESH_MAX_X (X_MAX_POS - (UBL_MESH_INSET))
667 667
   #define UBL_MESH_MIN_Y (Y_MIN_POS + UBL_MESH_INSET)
668 668
   #define UBL_MESH_MAX_Y (Y_MAX_POS - (UBL_MESH_INSET))
669
+
670
+  // If this is defined, the currently active mesh will be saved in the
671
+  // current slot on M500.
672
+  #define UBL_SAVE_ACTIVE_ON_M500
669 673
 #endif
670 674
 
671 675
 // @section extras

+ 0
- 1
Marlin/Marlin_main.cpp Ver fichero

@@ -8282,7 +8282,6 @@ void quickstop_stepper() {
8282 8282
         }
8283 8283
 
8284 8284
         ubl.load_mesh(storage_slot);
8285
-        if (storage_slot != ubl.state.eeprom_storage_slot) ubl.store_state();
8286 8285
         ubl.state.eeprom_storage_slot = storage_slot;
8287 8286
       }
8288 8287
     #endif // AUTO_BED_LEVELING_UBL

+ 46
- 24
Marlin/configuration_store.cpp Ver fichero

@@ -36,7 +36,7 @@
36 36
  *
37 37
  */
38 38
 
39
-#define EEPROM_VERSION "V35"
39
+#define EEPROM_VERSION "V36"
40 40
 
41 41
 // Change EEPROM version if these are changed:
42 42
 #define EEPROM_OFFSET 100
@@ -72,7 +72,7 @@
72 72
  *  224            mbl.z_offset                     (float)
73 73
  *  228            GRID_MAX_POINTS_X                (uint8_t)
74 74
  *  229            GRID_MAX_POINTS_Y                (uint8_t)
75
- *  230 G29 S3 XYZ z_values[][]                     (float x9, up to float x 81) +288
75
+ *  230 G29 S3 XYZ z_values[][]                     (float x9, up to float x81) +288
76 76
  *
77 77
  * HAS_BED_PROBE:                                   4 bytes
78 78
  *  266  M851      zprobe_zoffset                   (float)
@@ -87,6 +87,11 @@
87 87
  *  312  G29 L F   bilinear_start                   (int x2)
88 88
  *  316            z_values[][]                     (float x9, up to float x256) +988
89 89
  *
90
+ * AUTO_BED_LEVELING_UBL:                           6 bytes
91
+ *  324  G29 A     ubl.state.active                 (bool)
92
+ *  325  G29 Z     ubl.state.z_offset               (float)
93
+ *  329  G29 S     ubl.state.eeprom_storage_slot    (int8_t)
94
+ *
90 95
  * DELTA:                                           48 bytes
91 96
  *  348  M666 XYZ  endstop_adj                      (float x3)
92 97
  *  360  M665 R    delta_radius                     (float)
@@ -322,15 +327,15 @@ void MarlinSettings::postprocess() {
322 327
     #endif
323 328
 
324 329
     //
325
-    // General Leveling
330
+    // Global Leveling
326 331
     //
327 332
 
328 333
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
329
-      EEPROM_WRITE(planner.z_fade_height);
334
+      const float zfh = planner.z_fade_height;
330 335
     #else
331
-      dummy = 10.0;
332
-      EEPROM_WRITE(dummy);
336
+      const float zfh = 10.0;
333 337
     #endif
338
+    EEPROM_WRITE(zfh);
334 339
 
335 340
     //
336 341
     // Mesh Bed Leveling
@@ -349,8 +354,7 @@ void MarlinSettings::postprocess() {
349 354
       EEPROM_WRITE(mesh_num_x);
350 355
       EEPROM_WRITE(mesh_num_y);
351 356
       EEPROM_WRITE(mbl.z_values);
352
-    #else
353
-      // For disabled MBL write a default mesh
357
+    #else // For disabled MBL write a default mesh
354 358
       const bool leveling_is_on = false;
355 359
       dummy = 0.0f;
356 360
       const uint8_t mesh_num_x = 3, mesh_num_y = 3;
@@ -405,6 +409,19 @@ void MarlinSettings::postprocess() {
405 409
       for (uint16_t q = grid_max_x * grid_max_y; q--;) EEPROM_WRITE(dummy);
406 410
     #endif // AUTO_BED_LEVELING_BILINEAR
407 411
 
412
+    #if ENABLED(AUTO_BED_LEVELING_UBL)
413
+      EEPROM_WRITE(ubl.state.active);
414
+      EEPROM_WRITE(ubl.state.z_offset);
415
+      EEPROM_WRITE(ubl.state.eeprom_storage_slot);
416
+    #else
417
+      const bool ubl_active = 0;
418
+      dummy = 0.0f;
419
+      const int8_t eeprom_slot = -1;
420
+      EEPROM_WRITE(ubl_active);
421
+      EEPROM_WRITE(dummy);
422
+      EEPROM_WRITE(eeprom_slot);
423
+    #endif //AUTO_BED_LEVELING_UBL
424
+
408 425
     // 9 floats for DELTA / Z_DUAL_ENDSTOPS
409 426
     #if ENABLED(DELTA)
410 427
       EEPROM_WRITE(endstop_adj);               // 3 floats
@@ -608,8 +625,7 @@ void MarlinSettings::postprocess() {
608 625
       SERIAL_ECHOLNPGM(" bytes)");
609 626
     }
610 627
 
611
-    #if ENABLED(AUTO_BED_LEVELING_UBL)
612
-      ubl.store_state();
628
+    #if ENABLED(UBL_SAVE_ACTIVE_ON_M500)
613 629
       if (ubl.state.eeprom_storage_slot >= 0)
614 630
         ubl.store_mesh(ubl.state.eeprom_storage_slot);
615 631
     #endif
@@ -693,7 +709,7 @@ void MarlinSettings::postprocess() {
693 709
       #endif
694 710
 
695 711
       //
696
-      // General Leveling
712
+      // Global Leveling
697 713
       //
698 714
 
699 715
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
@@ -769,6 +785,18 @@ void MarlinSettings::postprocess() {
769 785
           for (uint16_t q = grid_max_x * grid_max_y; q--;) EEPROM_READ(dummy);
770 786
         }
771 787
 
788
+      #if ENABLED(AUTO_BED_LEVELING_UBL)
789
+        EEPROM_READ(ubl.state.active);
790
+        EEPROM_READ(ubl.state.z_offset);
791
+        EEPROM_READ(ubl.state.eeprom_storage_slot);
792
+      #else
793
+        bool dummyb;
794
+        uint8_t dummyui8;
795
+        EEPROM_READ(dummyb);
796
+        EEPROM_READ(dummy);
797
+        EEPROM_READ(dummyui8);
798
+      #endif //AUTO_BED_LEVELING_UBL
799
+
772 800
       #if ENABLED(DELTA)
773 801
         EEPROM_READ(endstop_adj);               // 3 floats
774 802
         EEPROM_READ(delta_radius);              // 1 float
@@ -951,27 +979,16 @@ void MarlinSettings::postprocess() {
951 979
         ubl.eeprom_start = (eeprom_index + 32) & 0xFFF8; // Pad the end of configuration data so it
952 980
                                                          // can float up or down a little bit without
953 981
                                                          // disrupting the Unified Bed Leveling data
954
-        ubl.load_state();
955
-
956 982
         SERIAL_ECHOPGM(" UBL ");
957 983
         if (!ubl.state.active) SERIAL_ECHO("not ");
958 984
         SERIAL_ECHOLNPGM("active!");
959 985
 
960 986
         if (!ubl.sanity_check()) {
961
-          int tmp_mesh;                                // We want to preserve whether the UBL System is Active
962
-          bool tmp_active;                             // If it is, we want to preserve the Mesh that is being used.
963
-          tmp_mesh = ubl.state.eeprom_storage_slot;
964
-          tmp_active = ubl.state.active;
965
-          SERIAL_ECHOLNPGM("\nInitializing Bed Leveling State to current firmware settings.\n");
966
-          ubl.state = ubl.pre_initialized;             // Initialize with the pre_initialized data structure
967
-          ubl.state.eeprom_storage_slot = tmp_mesh;    // But then restore some data we don't want mangled
968
-          ubl.state.active = tmp_active;
987
+          SERIAL_ECHOLNPGM("\nUnified Bed Leveling system initialized.\n");
969 988
         }
970 989
         else {
971
-          SERIAL_PROTOCOLPGM("?Unable to enable Unified Bed Leveling.\n");
972
-          ubl.state = ubl.pre_initialized;
990
+          SERIAL_PROTOCOLPGM("?Unable to enable Unified Bed Leveling system.\n");
973 991
           ubl.reset();
974
-          ubl.store_state();
975 992
         }
976 993
 
977 994
         if (ubl.state.eeprom_storage_slot >= 0) {
@@ -985,6 +1002,7 @@ void MarlinSettings::postprocess() {
985 1002
         }
986 1003
       #endif
987 1004
     }
1005
+
988 1006
     #if ENABLED(EEPROM_CHITCHAT)
989 1007
       report();
990 1008
     #endif
@@ -1190,6 +1208,10 @@ void MarlinSettings::reset() {
1190 1208
     planner.advance_ed_ratio = LIN_ADVANCE_E_D_RATIO;
1191 1209
   #endif
1192 1210
 
1211
+  #if ENABLED(AUTO_BED_LEVELING_UBL)
1212
+    ubl.reset();
1213
+  #endif
1214
+
1193 1215
   postprocess();
1194 1216
 
1195 1217
   SERIAL_ECHO_START;

+ 12
- 62
Marlin/ubl.cpp Ver fichero

@@ -57,7 +57,7 @@
57 57
     }
58 58
   }
59 59
 
60
-  ubl_state unified_bed_leveling::state, unified_bed_leveling::pre_initialized;
60
+  ubl_state unified_bed_leveling::state;
61 61
 
62 62
   float unified_bed_leveling::z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y],
63 63
         unified_bed_leveling::last_specified_z;
@@ -78,59 +78,46 @@
78 78
     reset();
79 79
   }
80 80
 
81
-  void unified_bed_leveling::store_state() {
82
-    const uint16_t i = UBL_LAST_EEPROM_INDEX;
83
-    eeprom_write_block((void *)&ubl.state, (void *)i, sizeof(state));
84
-  }
85
-
86
-  void unified_bed_leveling::load_state() {
87
-    const uint16_t i = UBL_LAST_EEPROM_INDEX;
88
-    eeprom_read_block((void *)&ubl.state, (void *)i, sizeof(state));
89
-
90
-    if (sanity_check())
91
-      SERIAL_PROTOCOLLNPGM("?In load_state() sanity_check() failed.\n");
92
-  }
93
-
94
-  void unified_bed_leveling::load_mesh(const int16_t m) {
81
+  void unified_bed_leveling::load_mesh(const int16_t slot) {
95 82
     int16_t j = (UBL_LAST_EEPROM_INDEX - eeprom_start) / sizeof(z_values);
96 83
 
97
-    if (m == -1) {
84
+    if (slot == -1) {
98 85
       SERIAL_PROTOCOLLNPGM("?No mesh saved in EEPROM. Zeroing mesh in memory.\n");
99 86
       reset();
100 87
       return;
101 88
     }
102 89
 
103
-    if (!WITHIN(m, 0, j - 1) || eeprom_start <= 0) {
90
+    if (!WITHIN(slot, 0, j - 1) || eeprom_start <= 0) {
104 91
       SERIAL_PROTOCOLLNPGM("?EEPROM storage not available to load mesh.\n");
105 92
       return;
106 93
     }
107 94
 
108
-    j = UBL_LAST_EEPROM_INDEX - (m + 1) * sizeof(z_values);
95
+    j = UBL_LAST_EEPROM_INDEX - (slot + 1) * sizeof(z_values);
109 96
     eeprom_read_block((void *)&z_values, (void *)j, sizeof(z_values));
110 97
 
111
-    SERIAL_PROTOCOLPAIR("Mesh loaded from slot ", m);
98
+    SERIAL_PROTOCOLPAIR("Mesh loaded from slot ", slot);
112 99
     SERIAL_PROTOCOLLNPAIR(" at offset ", hex_address((void*)j));
113 100
   }
114 101
 
115
-  void unified_bed_leveling::store_mesh(const int16_t m) {
102
+  void unified_bed_leveling::store_mesh(const int16_t slot) {
116 103
     int16_t j = (UBL_LAST_EEPROM_INDEX - eeprom_start) / sizeof(z_values);
117 104
 
118
-    if (!WITHIN(m, 0, j - 1) || eeprom_start <= 0) {
105
+    if (!WITHIN(slot, 0, j - 1) || eeprom_start <= 0) {
119 106
       SERIAL_PROTOCOLLNPGM("?EEPROM storage not available to load mesh.\n");
120
-      SERIAL_PROTOCOL(m);
107
+      SERIAL_PROTOCOL(slot);
121 108
       SERIAL_PROTOCOLLNPGM(" mesh slots available.\n");
122 109
       SERIAL_PROTOCOLLNPAIR("E2END     : ", E2END);
123 110
       SERIAL_PROTOCOLLNPAIR("k         : ", (int)UBL_LAST_EEPROM_INDEX);
124 111
       SERIAL_PROTOCOLLNPAIR("j         : ", j);
125
-      SERIAL_PROTOCOLLNPAIR("m         : ", m);
112
+      SERIAL_PROTOCOLLNPAIR("m         : ", slot);
126 113
       SERIAL_EOL;
127 114
       return;
128 115
     }
129 116
 
130
-    j = UBL_LAST_EEPROM_INDEX - (m + 1) * sizeof(z_values);
117
+    j = UBL_LAST_EEPROM_INDEX - (slot + 1) * sizeof(z_values);
131 118
     eeprom_write_block((const void *)&z_values, (void *)j, sizeof(z_values));
132 119
 
133
-    SERIAL_PROTOCOLPAIR("Mesh saved in slot ", m);
120
+    SERIAL_PROTOCOLPAIR("Mesh saved in slot ", slot);
134 121
     SERIAL_PROTOCOLLNPAIR(" at offset ", hex_address((void*)j));
135 122
   }
136 123
 
@@ -227,49 +214,12 @@
227 214
   bool unified_bed_leveling::sanity_check() {
228 215
     uint8_t error_flag = 0;
229 216
 
230
-    if (state.n_x != GRID_MAX_POINTS_X) {
231
-      SERIAL_PROTOCOLLNPGM("?GRID_MAX_POINTS_X set wrong\n");
232
-      error_flag++;
233
-    }
234
-    if (state.n_y != GRID_MAX_POINTS_Y) {
235
-      SERIAL_PROTOCOLLNPGM("?GRID_MAX_POINTS_Y set wrong\n");
236
-      error_flag++;
237
-    }
238
-    if (state.mesh_x_min != UBL_MESH_MIN_X) {
239
-      SERIAL_PROTOCOLLNPGM("?UBL_MESH_MIN_X set wrong\n");
240
-      error_flag++;
241
-    }
242
-    if (state.mesh_y_min != UBL_MESH_MIN_Y) {
243
-      SERIAL_PROTOCOLLNPGM("?UBL_MESH_MIN_Y set wrong\n");
244
-      error_flag++;
245
-    }
246
-    if (state.mesh_x_max != UBL_MESH_MAX_X) {
247
-      SERIAL_PROTOCOLLNPGM("?UBL_MESH_MAX_X set wrong\n");
248
-      error_flag++;
249
-    }
250
-    if (state.mesh_y_max != UBL_MESH_MAX_Y) {
251
-      SERIAL_PROTOCOLLNPGM("?UBL_MESH_MAX_Y set wrong\n");
252
-      error_flag++;
253
-    }
254
-    if (state.mesh_x_dist != MESH_X_DIST) {
255
-      SERIAL_PROTOCOLLNPGM("?MESH_X_DIST set wrong\n");
256
-      error_flag++;
257
-    }
258
-    if (state.mesh_y_dist != MESH_Y_DIST) {
259
-      SERIAL_PROTOCOLLNPGM("?MESH_Y_DIST set wrong\n");
260
-      error_flag++;
261
-    }
262
-
263 217
     const int j = (UBL_LAST_EEPROM_INDEX - eeprom_start) / sizeof(z_values);
264 218
     if (j < 1) {
265 219
       SERIAL_PROTOCOLLNPGM("?No EEPROM storage available for a mesh of this size.\n");
266 220
       error_flag++;
267 221
     }
268 222
 
269
-    //  SERIAL_PROTOCOLPGM("?sanity_check() return value: ");
270
-    //  SERIAL_PROTOCOL(error_flag);
271
-    //  SERIAL_EOL;
272
-
273 223
     return !!error_flag;
274 224
   }
275 225
 

+ 3
- 25
Marlin/ubl.h Ver fichero

@@ -87,27 +87,7 @@
87 87
   typedef struct {
88 88
     bool active = false;
89 89
     float z_offset = 0.0;
90
-    int8_t eeprom_storage_slot = -1,
91
-           n_x = GRID_MAX_POINTS_X,
92
-           n_y = GRID_MAX_POINTS_Y;
93
-
94
-    float mesh_x_min = UBL_MESH_MIN_X,
95
-          mesh_y_min = UBL_MESH_MIN_Y,
96
-          mesh_x_max = UBL_MESH_MAX_X,
97
-          mesh_y_max = UBL_MESH_MAX_Y,
98
-          mesh_x_dist = MESH_X_DIST,
99
-          mesh_y_dist = MESH_Y_DIST;
100
-
101
-    // If you change this struct, adjust TOTAL_STRUCT_SIZE
102
-
103
-    #define TOTAL_STRUCT_SIZE 32 // Total size of the above fields
104
-
105
-    // padding provides space to add state variables without
106
-    // changing the location of data structures in the EEPROM.
107
-    // This is for compatibility with future versions to keep
108
-    // users from having to regenerate their mesh data.
109
-    unsigned char padding[64 - TOTAL_STRUCT_SIZE];
110
-
90
+    int8_t eeprom_storage_slot = -1;
111 91
   } ubl_state;
112 92
 
113 93
   class unified_bed_leveling {
@@ -117,7 +97,7 @@
117 97
 
118 98
     public:
119 99
 
120
-      static ubl_state state, pre_initialized;
100
+      static ubl_state state;
121 101
 
122 102
       static float z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
123 103
 
@@ -156,8 +136,6 @@
156 136
       static void reset();
157 137
       static void invalidate();
158 138
 
159
-      static void store_state();
160
-      static void load_state();
161 139
       static void store_mesh(const int16_t);
162 140
       static void load_mesh(const int16_t);
163 141
 
@@ -351,7 +329,7 @@
351 329
 
352 330
   extern unified_bed_leveling ubl;
353 331
 
354
-  #define UBL_LAST_EEPROM_INDEX (E2END - sizeof(unified_bed_leveling::state))
332
+  #define UBL_LAST_EEPROM_INDEX E2END
355 333
 
356 334
 #endif // AUTO_BED_LEVELING_UBL
357 335
 #endif // UNIFIED_BED_LEVELING_H

+ 2
- 9
Marlin/ubl_G29.cpp Ver fichero

@@ -247,8 +247,8 @@
247 247
    *                    current state of the Unified Bed Leveling system in the EEPROM.
248 248
    *
249 249
    *   S #   Store      Store the current Mesh at the specified location in EEPROM. Activate this location
250
-   *                    for subsequent Load and Store operations. It will also store the current state of
251
-   *                    the Unified Bed Leveling system in the EEPROM.
250
+   *                    for subsequent Load and Store operations. Valid storage slot numbers begin at 0 and
251
+   *                    extend to a limit related to the available EEPROM storage.
252 252
    *
253 253
    *   S -1  Store      Store the current Mesh as a print out that is suitable to be feed back into the system
254 254
    *                    at a later date. The GCode output can be saved and later replayed by the host software
@@ -574,8 +574,6 @@
574 574
       }
575 575
       ubl.load_mesh(storage_slot);
576 576
       ubl.state.eeprom_storage_slot = storage_slot;
577
-      if (storage_slot != ubl.state.eeprom_storage_slot)
578
-        ubl.store_state();
579 577
       SERIAL_PROTOCOLLNPGM("Done.\n");
580 578
     }
581 579
 
@@ -609,9 +607,6 @@
609 607
       }
610 608
       ubl.store_mesh(storage_slot);
611 609
       ubl.state.eeprom_storage_slot = storage_slot;
612
-      //
613
-      //  if (storage_slot != ubl.state.eeprom_storage_slot)
614
-      ubl.store_state();    // Always save an updated copy of the UBL State info
615 610
 
616 611
       SERIAL_PROTOCOLLNPGM("Done.\n");
617 612
     }
@@ -1048,7 +1043,6 @@
1048 1043
     if (code_seen('A')) {     // Activate the Unified Bed Leveling System
1049 1044
       ubl.state.active = 1;
1050 1045
       SERIAL_PROTOCOLLNPGM("Unified Bed Leveling System activated.\n");
1051
-      ubl.store_state();
1052 1046
     }
1053 1047
 
1054 1048
     c_flag = code_seen('C') && code_has_value();
@@ -1057,7 +1051,6 @@
1057 1051
     if (code_seen('D')) {     // Disable the Unified Bed Leveling System
1058 1052
       ubl.state.active = 0;
1059 1053
       SERIAL_PROTOCOLLNPGM("Unified Bed Leveling System de-activated.\n");
1060
-      ubl.store_state();
1061 1054
     }
1062 1055
 
1063 1056
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)

Loading…
Cancelar
Guardar