瀏覽代碼

Merge branch 'Development' into config_testing

Latest upstream commits
Scott Lahteine 10 年之前
父節點
當前提交
15eb5d35a2

+ 17
- 0
Marlin/Configuration.h 查看文件

371
 //#define ENDSTOPPULLUP_FIL_RUNOUT // Uncomment to use internal pullup for filament runout pins if the sensor is defined.
371
 //#define ENDSTOPPULLUP_FIL_RUNOUT // Uncomment to use internal pullup for filament runout pins if the sensor is defined.
372
 
372
 
373
 //===========================================================================
373
 //===========================================================================
374
+//============================ Manual Bed Leveling ==========================
375
+//===========================================================================
376
+
377
+// #define MANUAL_BED_LEVELING  // Add display menu option for bed leveling
378
+// #define MESH_BED_LEVELING    // Enable mesh bed leveling
379
+
380
+#if defined(MESH_BED_LEVELING)
381
+  #define MESH_MIN_X 10
382
+  #define MESH_MAX_X (X_MAX_POS - MESH_MIN_X)
383
+  #define MESH_MIN_Y 10
384
+  #define MESH_MAX_Y (Y_MAX_POS - MESH_MIN_Y)
385
+  #define MESH_NUM_X_POINTS 3  // Don't use more than 7 points per axis, implementation limited
386
+  #define MESH_NUM_Y_POINTS 3
387
+  #define MESH_HOME_SEARCH_Z 4  // Z after Home, bed somewhere below but above 0.0
388
+#endif  // MESH_BED_LEVELING
389
+
390
+//===========================================================================
374
 //============================= Bed Auto Leveling ===========================
391
 //============================= Bed Auto Leveling ===========================
375
 //===========================================================================
392
 //===========================================================================
376
 
393
 

+ 63
- 2
Marlin/ConfigurationStore.cpp 查看文件

20
  *  max_e_jerk
20
  *  max_e_jerk
21
  *  add_homing (x3)
21
  *  add_homing (x3)
22
  *
22
  *
23
+ * Mesh bed leveling:
24
+ *  active
25
+ *  mesh_num_x
26
+ *  mesh_num_y
27
+ *  z_values[][]
28
+ *
23
  * DELTA:
29
  * DELTA:
24
  *  endstop_adj (x3)
30
  *  endstop_adj (x3)
25
  *  delta_radius
31
  *  delta_radius
69
 #include "ultralcd.h"
75
 #include "ultralcd.h"
70
 #include "ConfigurationStore.h"
76
 #include "ConfigurationStore.h"
71
 
77
 
78
+#if defined(MESH_BED_LEVELING)
79
+   #include "mesh_bed_leveling.h"
80
+#endif  // MESH_BED_LEVELING
81
+
72
 void _EEPROM_writeData(int &pos, uint8_t* value, uint8_t size) {
82
 void _EEPROM_writeData(int &pos, uint8_t* value, uint8_t size) {
73
   uint8_t c;
83
   uint8_t c;
74
   while(size--) {
84
   while(size--) {
105
 // wrong data being written to the variables.
115
 // wrong data being written to the variables.
106
 // ALSO:  always make sure the variables in the Store and retrieve sections are in the same order.
116
 // ALSO:  always make sure the variables in the Store and retrieve sections are in the same order.
107
 
117
 
108
-#define EEPROM_VERSION "V16"
118
+#define EEPROM_VERSION "V17"
109
 
119
 
110
 #ifdef EEPROM_SETTINGS
120
 #ifdef EEPROM_SETTINGS
111
 
121
 
128
   EEPROM_WRITE_VAR(i, max_e_jerk);
138
   EEPROM_WRITE_VAR(i, max_e_jerk);
129
   EEPROM_WRITE_VAR(i, add_homing);
139
   EEPROM_WRITE_VAR(i, add_homing);
130
 
140
 
141
+  uint8_t mesh_num_x = 3;
142
+  uint8_t mesh_num_y = 3;
143
+  #if defined(MESH_BED_LEVELING)
144
+    // Compile time test that sizeof(mbl.z_values) is as expected
145
+    typedef char c_assert[(sizeof(mbl.z_values) == MESH_NUM_X_POINTS*MESH_NUM_Y_POINTS*sizeof(dummy)) ? 1 : -1];
146
+    mesh_num_x = MESH_NUM_X_POINTS;
147
+    mesh_num_y = MESH_NUM_Y_POINTS;
148
+    EEPROM_WRITE_VAR(i, mbl.active);
149
+    EEPROM_WRITE_VAR(i, mesh_num_x);
150
+    EEPROM_WRITE_VAR(i, mesh_num_y);
151
+    EEPROM_WRITE_VAR(i, mbl.z_values);
152
+  #else
153
+    uint8_t dummy_uint8 = 0;
154
+    EEPROM_WRITE_VAR(i, dummy_uint8);
155
+    EEPROM_WRITE_VAR(i, mesh_num_x);
156
+    EEPROM_WRITE_VAR(i, mesh_num_y);
157
+    dummy = 0.0f;
158
+    for (int q=0; q<mesh_num_x*mesh_num_y; q++) {
159
+      EEPROM_WRITE_VAR(i, dummy);
160
+    }
161
+  #endif  // MESH_BED_LEVELING
162
+
131
   #ifdef DELTA
163
   #ifdef DELTA
132
     EEPROM_WRITE_VAR(i, endstop_adj);               // 3 floats
164
     EEPROM_WRITE_VAR(i, endstop_adj);               // 3 floats
133
     EEPROM_WRITE_VAR(i, delta_radius);              // 1 float
165
     EEPROM_WRITE_VAR(i, delta_radius);              // 1 float
250
     EEPROM_READ_VAR(i, max_feedrate);
282
     EEPROM_READ_VAR(i, max_feedrate);
251
     EEPROM_READ_VAR(i, max_acceleration_units_per_sq_second);
283
     EEPROM_READ_VAR(i, max_acceleration_units_per_sq_second);
252
 
284
 
253
-        // steps per sq second need to be updated to agree with the units per sq second (as they are what is used in the planner)
285
+    // steps per sq second need to be updated to agree with the units per sq second (as they are what is used in the planner)
254
     reset_acceleration_rates();
286
     reset_acceleration_rates();
255
 
287
 
256
     EEPROM_READ_VAR(i, acceleration);
288
     EEPROM_READ_VAR(i, acceleration);
264
     EEPROM_READ_VAR(i, max_e_jerk);
296
     EEPROM_READ_VAR(i, max_e_jerk);
265
     EEPROM_READ_VAR(i, add_homing);
297
     EEPROM_READ_VAR(i, add_homing);
266
 
298
 
299
+    uint8_t mesh_num_x = 0;
300
+    uint8_t mesh_num_y = 0;
301
+    #if defined(MESH_BED_LEVELING)
302
+      EEPROM_READ_VAR(i, mbl.active);
303
+      EEPROM_READ_VAR(i, mesh_num_x);
304
+      EEPROM_READ_VAR(i, mesh_num_y);
305
+      if (mesh_num_x != MESH_NUM_X_POINTS ||
306
+          mesh_num_y != MESH_NUM_Y_POINTS) {
307
+        mbl.reset();
308
+        for (int q=0; q<mesh_num_x*mesh_num_y; q++) {
309
+          EEPROM_READ_VAR(i, dummy);
310
+        }
311
+      } else {
312
+        EEPROM_READ_VAR(i, mbl.z_values);
313
+      }
314
+    #else
315
+      uint8_t dummy_uint8 = 0;
316
+      EEPROM_READ_VAR(i, dummy_uint8);
317
+      EEPROM_READ_VAR(i, mesh_num_x);
318
+      EEPROM_READ_VAR(i, mesh_num_y);
319
+      for (int q=0; q<mesh_num_x*mesh_num_y; q++) {
320
+        EEPROM_READ_VAR(i, dummy);
321
+      }
322
+    #endif  // MESH_BED_LEVELING
323
+
267
     #ifdef DELTA
324
     #ifdef DELTA
268
       EEPROM_READ_VAR(i, endstop_adj);                // 3 floats
325
       EEPROM_READ_VAR(i, endstop_adj);                // 3 floats
269
       EEPROM_READ_VAR(i, delta_radius);               // 1 float
326
       EEPROM_READ_VAR(i, delta_radius);               // 1 float
392
   max_e_jerk = DEFAULT_EJERK;
449
   max_e_jerk = DEFAULT_EJERK;
393
   add_homing[X_AXIS] = add_homing[Y_AXIS] = add_homing[Z_AXIS] = 0;
450
   add_homing[X_AXIS] = add_homing[Y_AXIS] = add_homing[Z_AXIS] = 0;
394
 
451
 
452
+  #if defined(MESH_BED_LEVELING)
453
+    mbl.active = 0;
454
+  #endif  // MESH_BED_LEVELING
455
+
395
   #ifdef DELTA
456
   #ifdef DELTA
396
     endstop_adj[X_AXIS] = endstop_adj[Y_AXIS] = endstop_adj[Z_AXIS] = 0;
457
     endstop_adj[X_AXIS] = endstop_adj[Y_AXIS] = endstop_adj[Z_AXIS] = 0;
397
     delta_radius =  DELTA_RADIUS;
458
     delta_radius =  DELTA_RADIUS;

+ 197
- 3
Marlin/Marlin_main.cpp 查看文件

38
 
38
 
39
 #define SERVO_LEVELING defined(ENABLE_AUTO_BED_LEVELING) && PROBE_SERVO_DEACTIVATION_DELAY > 0
39
 #define SERVO_LEVELING defined(ENABLE_AUTO_BED_LEVELING) && PROBE_SERVO_DEACTIVATION_DELAY > 0
40
 
40
 
41
+#if defined(MESH_BED_LEVELING)
42
+  #include "mesh_bed_leveling.h"
43
+#endif  // MESH_BED_LEVELING
44
+
41
 #include "ultralcd.h"
45
 #include "ultralcd.h"
42
 #include "planner.h"
46
 #include "planner.h"
43
 #include "stepper.h"
47
 #include "stepper.h"
1727
     #endif
1731
     #endif
1728
   #endif
1732
   #endif
1729
 
1733
 
1734
+  #if defined(MESH_BED_LEVELING)
1735
+    uint8_t mbl_was_active = mbl.active;
1736
+    mbl.active = 0;
1737
+  #endif  // MESH_BED_LEVELING
1738
+
1730
   saved_feedrate = feedrate;
1739
   saved_feedrate = feedrate;
1731
   saved_feedmultiply = feedmultiply;
1740
   saved_feedmultiply = feedmultiply;
1732
   feedmultiply = 100;
1741
   feedmultiply = 100;
1941
     enable_endstops(false);
1950
     enable_endstops(false);
1942
   #endif
1951
   #endif
1943
 
1952
 
1953
+  #if defined(MESH_BED_LEVELING)
1954
+    if (mbl_was_active) {
1955
+      current_position[X_AXIS] = mbl.get_x(0);
1956
+      current_position[Y_AXIS] = mbl.get_y(0);
1957
+      destination[X_AXIS] = current_position[X_AXIS];
1958
+      destination[Y_AXIS] = current_position[Y_AXIS];
1959
+      destination[Z_AXIS] = current_position[Z_AXIS];
1960
+      destination[E_AXIS] = current_position[E_AXIS];
1961
+      feedrate = homing_feedrate[X_AXIS];
1962
+      plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate, active_extruder);
1963
+      st_synchronize();
1964
+      current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
1965
+      plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
1966
+      mbl.active = 1;
1967
+    }
1968
+  #endif
1969
+
1944
   feedrate = saved_feedrate;
1970
   feedrate = saved_feedrate;
1945
   feedmultiply = saved_feedmultiply;
1971
   feedmultiply = saved_feedmultiply;
1946
   previous_millis_cmd = millis();
1972
   previous_millis_cmd = millis();
1947
   endstops_hit_on_purpose();
1973
   endstops_hit_on_purpose();
1948
 }
1974
 }
1949
 
1975
 
1976
+#if defined(MESH_BED_LEVELING)
1977
+
1978
+  inline void gcode_G29() {
1979
+    static int probe_point = -1;
1980
+    int state = 0;
1981
+    if (code_seen('S') || code_seen('s')) {
1982
+      state = code_value_long();
1983
+      if (state < 0 || state > 2) {
1984
+        SERIAL_PROTOCOLPGM("S out of range (0-2).\n");
1985
+        return;
1986
+      }
1987
+    }
1988
+
1989
+    if (state == 0) { // Dump mesh_bed_leveling
1990
+      if (mbl.active) {
1991
+        SERIAL_PROTOCOLPGM("Num X,Y: ");
1992
+        SERIAL_PROTOCOL(MESH_NUM_X_POINTS);
1993
+        SERIAL_PROTOCOLPGM(",");
1994
+        SERIAL_PROTOCOL(MESH_NUM_Y_POINTS);
1995
+        SERIAL_PROTOCOLPGM("\nZ search height: ");
1996
+        SERIAL_PROTOCOL(MESH_HOME_SEARCH_Z);
1997
+        SERIAL_PROTOCOLPGM("\nMeasured points:\n");              
1998
+        for (int y=0; y<MESH_NUM_Y_POINTS; y++) {
1999
+          for (int x=0; x<MESH_NUM_X_POINTS; x++) {
2000
+            SERIAL_PROTOCOLPGM("  ");              
2001
+            SERIAL_PROTOCOL_F(mbl.z_values[y][x], 5);
2002
+          }
2003
+          SERIAL_EOL;
2004
+        }
2005
+      } else {
2006
+        SERIAL_PROTOCOLPGM("Mesh bed leveling not active.\n");
2007
+      }
2008
+
2009
+    } else if (state == 1) { // Begin probing mesh points
2010
+
2011
+      mbl.reset();
2012
+      probe_point = 0;
2013
+      enquecommands_P(PSTR("G28"));
2014
+      enquecommands_P(PSTR("G29 S2"));
2015
+
2016
+    } else if (state == 2) { // Goto next point
2017
+
2018
+      if (probe_point < 0) {
2019
+        SERIAL_PROTOCOLPGM("Mesh probing not started.\n");
2020
+        return;
2021
+      }
2022
+      int ix, iy;
2023
+      if (probe_point == 0) {
2024
+        current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
2025
+        plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
2026
+      } else {
2027
+        ix = (probe_point-1) % MESH_NUM_X_POINTS;
2028
+        iy = (probe_point-1) / MESH_NUM_X_POINTS;
2029
+        if (iy&1) { // Zig zag
2030
+          ix = (MESH_NUM_X_POINTS - 1) - ix;
2031
+        }
2032
+        mbl.set_z(ix, iy, current_position[Z_AXIS]);
2033
+        current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
2034
+        plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], homing_feedrate[X_AXIS]/60, active_extruder);
2035
+        st_synchronize();
2036
+      }
2037
+      if (probe_point == MESH_NUM_X_POINTS*MESH_NUM_Y_POINTS) {
2038
+        SERIAL_PROTOCOLPGM("Mesh done.\n");
2039
+        probe_point = -1;
2040
+        mbl.active = 1;
2041
+        enquecommands_P(PSTR("G28"));
2042
+        return;
2043
+      }
2044
+      ix = probe_point % MESH_NUM_X_POINTS;
2045
+      iy = probe_point / MESH_NUM_X_POINTS;
2046
+      if (iy&1) { // Zig zag
2047
+        ix = (MESH_NUM_X_POINTS - 1) - ix;
2048
+      }
2049
+      current_position[X_AXIS] = mbl.get_x(ix);
2050
+      current_position[Y_AXIS] = mbl.get_y(iy);
2051
+      plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], homing_feedrate[X_AXIS]/60, active_extruder);
2052
+      st_synchronize();
2053
+      probe_point++;
2054
+    }
2055
+  }
2056
+
2057
+#endif
2058
+
1950
 #ifdef ENABLE_AUTO_BED_LEVELING
2059
 #ifdef ENABLE_AUTO_BED_LEVELING
1951
 
2060
 
1952
   /**
2061
   /**
4613
       gcode_G28();
4722
       gcode_G28();
4614
       break;
4723
       break;
4615
 
4724
 
4725
+    #if defined(MESH_BED_LEVELING)
4726
+      case 29: // G29 Handle mesh based leveling
4727
+        gcode_G29();
4728
+        break;
4729
+    #endif
4730
+
4616
     #ifdef ENABLE_AUTO_BED_LEVELING
4731
     #ifdef ENABLE_AUTO_BED_LEVELING
4617
 
4732
 
4618
       case 29: // G29 Detailed Z-Probe, probes the bed at 3 or more points.
4733
       case 29: // G29 Detailed Z-Probe, probes the bed at 3 or more points.
5232
 }
5347
 }
5233
 #endif //DELTA
5348
 #endif //DELTA
5234
 
5349
 
5350
+#if defined(MESH_BED_LEVELING)
5351
+#if !defined(MIN)
5352
+#define MIN(_v1, _v2) (((_v1) < (_v2)) ? (_v1) : (_v2))
5353
+#endif  // ! MIN
5354
+// This function is used to split lines on mesh borders so each segment is only part of one mesh area
5355
+void mesh_plan_buffer_line(float x, float y, float z, const float e, float feed_rate, const uint8_t &extruder, uint8_t x_splits=0xff, uint8_t y_splits=0xff)
5356
+{
5357
+  if (!mbl.active) {
5358
+    plan_buffer_line(x, y, z, e, feed_rate, extruder);
5359
+    for(int8_t i=0; i < NUM_AXIS; i++) {
5360
+      current_position[i] = destination[i];
5361
+    }
5362
+    return;
5363
+  }
5364
+  int pix = mbl.select_x_index(current_position[X_AXIS]);
5365
+  int piy = mbl.select_y_index(current_position[Y_AXIS]);
5366
+  int ix = mbl.select_x_index(x);
5367
+  int iy = mbl.select_y_index(y);
5368
+  pix = MIN(pix, MESH_NUM_X_POINTS-2);
5369
+  piy = MIN(piy, MESH_NUM_Y_POINTS-2);
5370
+  ix = MIN(ix, MESH_NUM_X_POINTS-2);
5371
+  iy = MIN(iy, MESH_NUM_Y_POINTS-2);
5372
+  if (pix == ix && piy == iy) {
5373
+    // Start and end on same mesh square
5374
+    plan_buffer_line(x, y, z, e, feed_rate, extruder);
5375
+    for(int8_t i=0; i < NUM_AXIS; i++) {
5376
+      current_position[i] = destination[i];
5377
+    }
5378
+    return;
5379
+  }
5380
+  float nx, ny, ne, normalized_dist;
5381
+  if (ix > pix && (x_splits) & BIT(ix)) {
5382
+    nx = mbl.get_x(ix);
5383
+    normalized_dist = (nx - current_position[X_AXIS])/(x - current_position[X_AXIS]);
5384
+    ny = current_position[Y_AXIS] + (y - current_position[Y_AXIS]) * normalized_dist;
5385
+    ne = current_position[E_AXIS] + (e - current_position[E_AXIS]) * normalized_dist;
5386
+    x_splits ^= BIT(ix);
5387
+  } else if (ix < pix && (x_splits) & BIT(pix)) {
5388
+    nx = mbl.get_x(pix);
5389
+    normalized_dist = (nx - current_position[X_AXIS])/(x - current_position[X_AXIS]);
5390
+    ny = current_position[Y_AXIS] + (y - current_position[Y_AXIS]) * normalized_dist;
5391
+    ne = current_position[E_AXIS] + (e - current_position[E_AXIS]) * normalized_dist;
5392
+    x_splits ^= BIT(pix);
5393
+  } else if (iy > piy && (y_splits) & BIT(iy)) {
5394
+    ny = mbl.get_y(iy);
5395
+    normalized_dist = (ny - current_position[Y_AXIS])/(y - current_position[Y_AXIS]);
5396
+    nx = current_position[X_AXIS] + (x - current_position[X_AXIS]) * normalized_dist;
5397
+    ne = current_position[E_AXIS] + (e - current_position[E_AXIS]) * normalized_dist;
5398
+    y_splits ^= BIT(iy);
5399
+  } else if (iy < piy && (y_splits) & BIT(piy)) {
5400
+    ny = mbl.get_y(piy);
5401
+    normalized_dist = (ny - current_position[Y_AXIS])/(y - current_position[Y_AXIS]);
5402
+    nx = current_position[X_AXIS] + (x - current_position[X_AXIS]) * normalized_dist;
5403
+    ne = current_position[E_AXIS] + (e - current_position[E_AXIS]) * normalized_dist;
5404
+    y_splits ^= BIT(piy);
5405
+  } else {
5406
+    // Already split on a border
5407
+    plan_buffer_line(x, y, z, e, feed_rate, extruder);
5408
+    for(int8_t i=0; i < NUM_AXIS; i++) {
5409
+      current_position[i] = destination[i];
5410
+    }
5411
+    return;
5412
+  }
5413
+  // Do the split and look for more borders
5414
+  destination[X_AXIS] = nx;
5415
+  destination[Y_AXIS] = ny;
5416
+  destination[E_AXIS] = ne;
5417
+  mesh_plan_buffer_line(nx, ny, z, ne, feed_rate, extruder, x_splits, y_splits);
5418
+  destination[X_AXIS] = x;
5419
+  destination[Y_AXIS] = y;
5420
+  destination[E_AXIS] = e;
5421
+  mesh_plan_buffer_line(x, y, z, e, feed_rate, extruder, x_splits, y_splits);
5422
+}
5423
+#endif  // MESH_BED_LEVELING
5424
+
5235
 void prepare_move()
5425
 void prepare_move()
5236
 {
5426
 {
5237
   clamp_to_software_endstops(destination);
5427
   clamp_to_software_endstops(destination);
5347
 #if ! (defined DELTA || defined SCARA)
5537
 #if ! (defined DELTA || defined SCARA)
5348
   // Do not use feedmultiply for E or Z only moves
5538
   // Do not use feedmultiply for E or Z only moves
5349
   if( (current_position[X_AXIS] == destination [X_AXIS]) && (current_position[Y_AXIS] == destination [Y_AXIS])) {
5539
   if( (current_position[X_AXIS] == destination [X_AXIS]) && (current_position[Y_AXIS] == destination [Y_AXIS])) {
5350
-      plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
5351
-  }
5352
-  else {
5540
+    plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
5541
+  } else {
5542
+#if defined(MESH_BED_LEVELING)
5543
+    mesh_plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate*feedmultiply/60/100.0, active_extruder);
5544
+    return;
5545
+#else
5353
     plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate*feedmultiply/60/100.0, active_extruder);
5546
     plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate*feedmultiply/60/100.0, active_extruder);
5547
+#endif  // MESH_BED_LEVELING
5354
   }
5548
   }
5355
 #endif // !(DELTA || SCARA)
5549
 #endif // !(DELTA || SCARA)
5356
 
5550
 

+ 3
- 0
Marlin/language_en.h 查看文件

95
 #ifndef MSG_MOVE_AXIS
95
 #ifndef MSG_MOVE_AXIS
96
 #define MSG_MOVE_AXIS                       "Move axis"
96
 #define MSG_MOVE_AXIS                       "Move axis"
97
 #endif
97
 #endif
98
+#ifndef MSG_LEVEL_BED
99
+#define MSG_LEVEL_BED                       "Level bed"
100
+#endif
98
 #ifndef MSG_MOVE_X
101
 #ifndef MSG_MOVE_X
99
 #define MSG_MOVE_X                          "Move X"
102
 #define MSG_MOVE_X                          "Move X"
100
 #endif
103
 #endif

+ 20
- 0
Marlin/mesh_bed_leveling.cpp 查看文件

1
+#include "mesh_bed_leveling.h"
2
+
3
+#if defined(MESH_BED_LEVELING)
4
+
5
+mesh_bed_leveling mbl;
6
+
7
+mesh_bed_leveling::mesh_bed_leveling() {
8
+    reset();
9
+}
10
+    
11
+void mesh_bed_leveling::reset() {
12
+    for (int y=0; y<MESH_NUM_Y_POINTS; y++) {
13
+        for (int x=0; x<MESH_NUM_X_POINTS; x++) {
14
+            z_values[y][x] = 0;
15
+        }
16
+    }
17
+    active = 0;
18
+}
19
+
20
+#endif  // MESH_BED_LEVELING

+ 61
- 0
Marlin/mesh_bed_leveling.h 查看文件

1
+#include "Marlin.h"
2
+
3
+#if defined(MESH_BED_LEVELING)
4
+
5
+#define MESH_X_DIST ((MESH_MAX_X - MESH_MIN_X)/(MESH_NUM_X_POINTS - 1))
6
+#define MESH_Y_DIST ((MESH_MAX_Y - MESH_MIN_Y)/(MESH_NUM_Y_POINTS - 1))
7
+
8
+class mesh_bed_leveling {
9
+public:
10
+    uint8_t active;
11
+    float z_values[MESH_NUM_Y_POINTS][MESH_NUM_X_POINTS];
12
+    
13
+    mesh_bed_leveling();
14
+    
15
+    void reset();
16
+    
17
+    float get_x(int i) { return MESH_MIN_X + MESH_X_DIST*i; }
18
+    float get_y(int i) { return MESH_MIN_Y + MESH_Y_DIST*i; }
19
+    void set_z(int ix, int iy, float z) { z_values[iy][ix] = z; }
20
+    
21
+    int select_x_index(float x) {
22
+        int i = 1;
23
+        while (x > get_x(i) && i < MESH_NUM_X_POINTS-1) {
24
+            i++;
25
+        }
26
+        return i-1;
27
+    }
28
+    
29
+    int select_y_index(float y) {
30
+        int i = 1;
31
+        while (y > get_y(i) && i < MESH_NUM_Y_POINTS-1) {
32
+            i++;
33
+        }
34
+        return i-1;
35
+    }
36
+    
37
+    float calc_z0(float a0, float a1, float z1, float a2, float z2) {
38
+        float delta_z = (z2 - z1)/(a2 - a1);
39
+        float delta_a = a0 - a1;
40
+        return z1 + delta_a * delta_z;
41
+    }
42
+    
43
+    float get_z(float x0, float y0) {
44
+        int x_index = select_x_index(x0);
45
+        int y_index = select_y_index(y0);
46
+        float z1 = calc_z0(x0,
47
+                           get_x(x_index), z_values[y_index][x_index],
48
+                           get_x(x_index+1), z_values[y_index][x_index+1]);
49
+        float z2 = calc_z0(x0,
50
+                           get_x(x_index), z_values[y_index+1][x_index],
51
+                           get_x(x_index+1), z_values[y_index+1][x_index+1]);
52
+        float z0 = calc_z0(y0,
53
+                           get_y(y_index), z1,
54
+                           get_y(y_index+1), z2);
55
+        return z0;
56
+    }
57
+};
58
+
59
+extern mesh_bed_leveling mbl;
60
+
61
+#endif  // MESH_BED_LEVELING

+ 20
- 5
Marlin/planner.cpp 查看文件

58
 #include "ultralcd.h"
58
 #include "ultralcd.h"
59
 #include "language.h"
59
 #include "language.h"
60
 
60
 
61
+#if defined(MESH_BED_LEVELING)
62
+  #include "mesh_bed_leveling.h"
63
+#endif  // MESH_BED_LEVELING
64
+
61
 //===========================================================================
65
 //===========================================================================
62
 //============================= public variables ============================
66
 //============================= public variables ============================
63
 //===========================================================================
67
 //===========================================================================
530
 // Add a new linear movement to the buffer. steps_x, _y and _z is the absolute position in 
534
 // Add a new linear movement to the buffer. steps_x, _y and _z is the absolute position in 
531
 // mm. Microseconds specify how many microseconds the move should take to perform. To aid acceleration
535
 // mm. Microseconds specify how many microseconds the move should take to perform. To aid acceleration
532
 // calculation the caller must also provide the physical length of the line in millimeters.
536
 // calculation the caller must also provide the physical length of the line in millimeters.
533
-#ifdef ENABLE_AUTO_BED_LEVELING
537
+#if defined(ENABLE_AUTO_BED_LEVELING) || defined(MESH_BED_LEVELING)
534
 void plan_buffer_line(float x, float y, float z, const float &e, float feed_rate, const uint8_t &extruder)
538
 void plan_buffer_line(float x, float y, float z, const float &e, float feed_rate, const uint8_t &extruder)
535
 #else
539
 #else
536
 void plan_buffer_line(const float &x, const float &y, const float &z, const float &e, float feed_rate, const uint8_t &extruder)
540
 void plan_buffer_line(const float &x, const float &y, const float &z, const float &e, float feed_rate, const uint8_t &extruder)
548
     lcd_update();
552
     lcd_update();
549
   }
553
   }
550
 
554
 
555
+#if defined(MESH_BED_LEVELING)
556
+  if (mbl.active) {
557
+    z += mbl.get_z(x, y);
558
+  }
559
+#endif  // MESH_BED_LEVELING
560
+
551
 #ifdef ENABLE_AUTO_BED_LEVELING
561
 #ifdef ENABLE_AUTO_BED_LEVELING
552
   apply_rotation_xyz(plan_bed_level_matrix, x, y, z);
562
   apply_rotation_xyz(plan_bed_level_matrix, x, y, z);
553
 #endif // ENABLE_AUTO_BED_LEVELING
563
 #endif // ENABLE_AUTO_BED_LEVELING
1078
 }
1088
 }
1079
 #endif // ENABLE_AUTO_BED_LEVELING
1089
 #endif // ENABLE_AUTO_BED_LEVELING
1080
 
1090
 
1081
-#ifdef ENABLE_AUTO_BED_LEVELING
1091
+#if defined(ENABLE_AUTO_BED_LEVELING) || defined(MESH_BED_LEVELING)
1082
 void plan_set_position(float x, float y, float z, const float &e)
1092
 void plan_set_position(float x, float y, float z, const float &e)
1083
-{
1084
-  apply_rotation_xyz(plan_bed_level_matrix, x, y, z);
1085
 #else
1093
 #else
1086
 void plan_set_position(const float &x, const float &y, const float &z, const float &e)
1094
 void plan_set_position(const float &x, const float &y, const float &z, const float &e)
1095
+#endif  // ENABLE_AUTO_BED_LEVELING || MESH_BED_LEVELING
1087
 {
1096
 {
1088
-#endif // ENABLE_AUTO_BED_LEVELING
1097
+#if defined(ENABLE_AUTO_BED_LEVELING)
1098
+  apply_rotation_xyz(plan_bed_level_matrix, x, y, z);
1099
+#elif defined(MESH_BED_LEVELING)
1100
+  if (mbl.active) {
1101
+    z += mbl.get_z(x, y);
1102
+  }
1103
+#endif  // ENABLE_AUTO_BED_LEVELING
1089
 
1104
 
1090
   position[X_AXIS] = lround(x*axis_steps_per_unit[X_AXIS]);
1105
   position[X_AXIS] = lround(x*axis_steps_per_unit[X_AXIS]);
1091
   position[Y_AXIS] = lround(y*axis_steps_per_unit[Y_AXIS]);
1106
   position[Y_AXIS] = lround(y*axis_steps_per_unit[Y_AXIS]);

+ 6
- 5
Marlin/planner.h 查看文件

82
 // Add a new linear movement to the buffer. x, y and z is the signed, absolute target position in 
82
 // Add a new linear movement to the buffer. x, y and z is the signed, absolute target position in 
83
 // millimaters. Feed rate specifies the speed of the motion.
83
 // millimaters. Feed rate specifies the speed of the motion.
84
 
84
 
85
-#ifdef ENABLE_AUTO_BED_LEVELING
85
+#if defined(ENABLE_AUTO_BED_LEVELING) || defined(MESH_BED_LEVELING)
86
 void plan_buffer_line(float x, float y, float z, const float &e, float feed_rate, const uint8_t &extruder);
86
 void plan_buffer_line(float x, float y, float z, const float &e, float feed_rate, const uint8_t &extruder);
87
-
87
+#if defined(ENABLE_AUTO_BED_LEVELING)
88
   #ifndef DELTA
88
   #ifndef DELTA
89
   // Get the position applying the bed level matrix if enabled
89
   // Get the position applying the bed level matrix if enabled
90
   vector_3 plan_get_position();
90
   vector_3 plan_get_position();
91
   #endif
91
   #endif
92
+#endif  // ENABLE_AUTO_BED_LEVELING
92
 #else
93
 #else
93
 void plan_buffer_line(const float &x, const float &y, const float &z, const float &e, float feed_rate, const uint8_t &extruder);
94
 void plan_buffer_line(const float &x, const float &y, const float &z, const float &e, float feed_rate, const uint8_t &extruder);
94
-#endif // ENABLE_AUTO_BED_LEVELING
95
+#endif  // ENABLE_AUTO_BED_LEVELING || MESH_BED_LEVELING
95
 
96
 
96
 // Set position. Used for G92 instructions.
97
 // Set position. Used for G92 instructions.
97
-#ifdef ENABLE_AUTO_BED_LEVELING
98
+#if defined(ENABLE_AUTO_BED_LEVELING) || defined(MESH_BED_LEVELING)
98
 void plan_set_position(float x, float y, float z, const float &e);
99
 void plan_set_position(float x, float y, float z, const float &e);
99
 #else
100
 #else
100
 void plan_set_position(const float &x, const float &y, const float &z, const float &e);
101
 void plan_set_position(const float &x, const float &y, const float &z, const float &e);
101
-#endif // ENABLE_AUTO_BED_LEVELING
102
+#endif // ENABLE_AUTO_BED_LEVELING || MESH_BED_LEVELING
102
 
103
 
103
 void plan_set_e_position(const float &e);
104
 void plan_set_e_position(const float &e);
104
 
105
 

+ 67
- 34
Marlin/temperature.cpp 查看文件

109
   static float temp_iState_min_bed;
109
   static float temp_iState_min_bed;
110
   static float temp_iState_max_bed;
110
   static float temp_iState_max_bed;
111
 #else //PIDTEMPBED
111
 #else //PIDTEMPBED
112
-	static unsigned long  previous_millis_bed_heater;
112
+  static unsigned long  previous_millis_bed_heater;
113
 #endif //PIDTEMPBED
113
 #endif //PIDTEMPBED
114
   static unsigned char soft_pwm[EXTRUDERS];
114
   static unsigned char soft_pwm[EXTRUDERS];
115
 
115
 
207
     SERIAL_ECHOLN(MSG_PID_BAD_EXTRUDER_NUM);
207
     SERIAL_ECHOLN(MSG_PID_BAD_EXTRUDER_NUM);
208
     return;
208
     return;
209
   }
209
   }
210
-	
210
+  
211
   SERIAL_ECHOLN(MSG_PID_AUTOTUNE_START);
211
   SERIAL_ECHOLN(MSG_PID_AUTOTUNE_START);
212
 
212
 
213
   disable_heater(); // switch off all heaters.
213
   disable_heater(); // switch off all heaters.
670
   #ifdef FILAMENT_SENSOR
670
   #ifdef FILAMENT_SENSOR
671
     if (filament_sensor) {
671
     if (filament_sensor) {
672
       meas_shift_index = delay_index1 - meas_delay_cm;
672
       meas_shift_index = delay_index1 - meas_delay_cm;
673
-		  if (meas_shift_index < 0) meas_shift_index += MAX_MEASUREMENT_DELAY + 1;  //loop around buffer if needed
674
-		  
673
+      if (meas_shift_index < 0) meas_shift_index += MAX_MEASUREMENT_DELAY + 1;  //loop around buffer if needed
674
+      
675
       // Get the delayed info and add 100 to reconstitute to a percent of
675
       // Get the delayed info and add 100 to reconstitute to a percent of
676
       // the nominal filament diameter then square it to get an area
676
       // the nominal filament diameter then square it to get an area
677
       meas_shift_index = constrain(meas_shift_index, 0, MAX_MEASUREMENT_DELAY);
677
       meas_shift_index = constrain(meas_shift_index, 0, MAX_MEASUREMENT_DELAY);
1174
 ISR(TIMER0_COMPB_vect) {
1174
 ISR(TIMER0_COMPB_vect) {
1175
   //these variables are only accesible from the ISR, but static, so they don't lose their value
1175
   //these variables are only accesible from the ISR, but static, so they don't lose their value
1176
   static unsigned char temp_count = 0;
1176
   static unsigned char temp_count = 0;
1177
-  static unsigned long raw_temp_0_value = 0;
1178
-  static unsigned long raw_temp_1_value = 0;
1179
-  static unsigned long raw_temp_2_value = 0;
1180
-  static unsigned long raw_temp_3_value = 0;
1177
+  static unsigned long raw_temp_value[EXTRUDERS] = { 0 };
1181
   static unsigned long raw_temp_bed_value = 0;
1178
   static unsigned long raw_temp_bed_value = 0;
1182
   static TempState temp_state = StartupDelay;
1179
   static TempState temp_state = StartupDelay;
1183
   static unsigned char pwm_count = BIT(SOFT_PWM_SCALE);
1180
   static unsigned char pwm_count = BIT(SOFT_PWM_SCALE);
1389
       break;
1386
       break;
1390
     case MeasureTemp_0:
1387
     case MeasureTemp_0:
1391
       #if HAS_TEMP_0
1388
       #if HAS_TEMP_0
1392
-        raw_temp_0_value += ADC;
1389
+        raw_temp_value[0] += ADC;
1393
       #endif
1390
       #endif
1394
       temp_state = PrepareTemp_BED;
1391
       temp_state = PrepareTemp_BED;
1395
       break;
1392
       break;
1415
       break;
1412
       break;
1416
     case MeasureTemp_1:
1413
     case MeasureTemp_1:
1417
       #if HAS_TEMP_1
1414
       #if HAS_TEMP_1
1418
-        raw_temp_1_value += ADC;
1415
+        raw_temp_value[1] += ADC;
1419
       #endif
1416
       #endif
1420
       temp_state = PrepareTemp_2;
1417
       temp_state = PrepareTemp_2;
1421
       break;
1418
       break;
1428
       break;
1425
       break;
1429
     case MeasureTemp_2:
1426
     case MeasureTemp_2:
1430
       #if HAS_TEMP_2
1427
       #if HAS_TEMP_2
1431
-        raw_temp_2_value += ADC;
1428
+        raw_temp_value[2] += ADC;
1432
       #endif
1429
       #endif
1433
       temp_state = PrepareTemp_3;
1430
       temp_state = PrepareTemp_3;
1434
       break;
1431
       break;
1441
       break;
1438
       break;
1442
     case MeasureTemp_3:
1439
     case MeasureTemp_3:
1443
       #if HAS_TEMP_3
1440
       #if HAS_TEMP_3
1444
-        raw_temp_3_value += ADC;
1441
+        raw_temp_value[3] += ADC;
1445
       #endif
1442
       #endif
1446
       temp_state = Prepare_FILWIDTH;
1443
       temp_state = Prepare_FILWIDTH;
1447
       break;
1444
       break;
1476
   if (temp_count >= OVERSAMPLENR) { // 10 * 16 * 1/(16000000/64/256)  = 164ms.
1473
   if (temp_count >= OVERSAMPLENR) { // 10 * 16 * 1/(16000000/64/256)  = 164ms.
1477
     if (!temp_meas_ready) { //Only update the raw values if they have been read. Else we could be updating them during reading.
1474
     if (!temp_meas_ready) { //Only update the raw values if they have been read. Else we could be updating them during reading.
1478
       #ifndef HEATER_0_USES_MAX6675
1475
       #ifndef HEATER_0_USES_MAX6675
1479
-        current_temperature_raw[0] = raw_temp_0_value;
1476
+        current_temperature_raw[0] = raw_temp_value[0];
1480
       #endif
1477
       #endif
1481
       #if EXTRUDERS > 1
1478
       #if EXTRUDERS > 1
1482
-        current_temperature_raw[1] = raw_temp_1_value;
1479
+        current_temperature_raw[1] = raw_temp_value[1];
1483
         #if EXTRUDERS > 2
1480
         #if EXTRUDERS > 2
1484
-          current_temperature_raw[2] = raw_temp_2_value;
1481
+          current_temperature_raw[2] = raw_temp_value[2];
1485
           #if EXTRUDERS > 3
1482
           #if EXTRUDERS > 3
1486
-            current_temperature_raw[3] = raw_temp_3_value;
1483
+            current_temperature_raw[3] = raw_temp_value[3];
1487
           #endif
1484
           #endif
1488
         #endif
1485
         #endif
1489
       #endif
1486
       #endif
1490
       #ifdef TEMP_SENSOR_1_AS_REDUNDANT
1487
       #ifdef TEMP_SENSOR_1_AS_REDUNDANT
1491
-        redundant_temperature_raw = raw_temp_1_value;
1488
+        redundant_temperature_raw = raw_temp_value[1];
1492
       #endif
1489
       #endif
1493
       current_temperature_bed_raw = raw_temp_bed_value;
1490
       current_temperature_bed_raw = raw_temp_bed_value;
1494
     } //!temp_meas_ready
1491
     } //!temp_meas_ready
1500
     
1497
     
1501
     temp_meas_ready = true;
1498
     temp_meas_ready = true;
1502
     temp_count = 0;
1499
     temp_count = 0;
1503
-    raw_temp_0_value = 0;
1504
-    raw_temp_1_value = 0;
1505
-    raw_temp_2_value = 0;
1506
-    raw_temp_3_value = 0;
1500
+    for (int i = 0; i < EXTRUDERS; i++) raw_temp_value[i] = 0;
1507
     raw_temp_bed_value = 0;
1501
     raw_temp_bed_value = 0;
1508
 
1502
 
1509
     #if HEATER_0_RAW_LO_TEMP > HEATER_0_RAW_HI_TEMP
1503
     #if HEATER_0_RAW_LO_TEMP > HEATER_0_RAW_HI_TEMP
1510
-      #define MAXTEST <=
1511
-      #define MINTEST >=
1504
+      #define GE0 <=
1505
+      #define LE0 >=
1512
     #else
1506
     #else
1513
-      #define MAXTEST >=
1514
-      #define MINTEST <=
1507
+      #define GE0 >=
1508
+      #define LE0 <=
1515
     #endif
1509
     #endif
1510
+    if (current_temperature_raw[0] GE0 maxttemp_raw[0]) max_temp_error(0);
1511
+    if (current_temperature_raw[0] LE0 minttemp_raw[0]) min_temp_error(0);
1512
+
1513
+    #if EXTRUDERS > 1
1514
+      #if HEATER_1_RAW_LO_TEMP > HEATER_1_RAW_HI_TEMP
1515
+        #define GE1 <=
1516
+        #define LE1 >=
1517
+      #else
1518
+        #define GE1 >=
1519
+        #define LE1 <=
1520
+      #endif
1521
+      if (current_temperature_raw[1] GE1 maxttemp_raw[1]) max_temp_error(1);
1522
+      if (current_temperature_raw[1] LE1 minttemp_raw[1]) min_temp_error(1);
1523
+      #if EXTRUDERS > 2
1524
+        #if HEATER_2_RAW_LO_TEMP > HEATER_2_RAW_HI_TEMP
1525
+          #define GE2 <=
1526
+          #define LE2 >=
1527
+        #else
1528
+          #define GE2 >=
1529
+          #define LE2 <=
1530
+        #endif
1531
+        if (current_temperature_raw[2] GE2 maxttemp_raw[2]) max_temp_error(2);
1532
+        if (current_temperature_raw[2] LE2 minttemp_raw[2]) min_temp_error(2);
1533
+        #if EXTRUDERS > 3
1534
+          #if HEATER_3_RAW_LO_TEMP > HEATER_3_RAW_HI_TEMP
1535
+            #define GE3 <=
1536
+            #define LE3 >=
1537
+          #else
1538
+            #define GE3 >=
1539
+            #define LE3 <=
1540
+          #endif
1541
+          if (current_temperature_raw[3] GE3 maxttemp_raw[3]) max_temp_error(3);
1542
+          if (current_temperature_raw[3] LE3 minttemp_raw[3]) min_temp_error(3);
1543
+        #endif // EXTRUDERS > 3
1544
+      #endif // EXTRUDERS > 2
1545
+    #endif // EXTRUDERS > 1
1516
 
1546
 
1517
-    for (int i=0; i<EXTRUDERS; i++) {
1518
-      if (current_temperature_raw[i] MAXTEST maxttemp_raw[i]) max_temp_error(i);
1519
-      else if (current_temperature_raw[i] MINTEST minttemp_raw[i]) min_temp_error(i);
1520
-    }
1521
-    /* No bed MINTEMP error? */
1522
     #if defined(BED_MAXTEMP) && (TEMP_SENSOR_BED != 0)
1547
     #if defined(BED_MAXTEMP) && (TEMP_SENSOR_BED != 0)
1523
-      if (current_temperature_bed_raw MAXTEST bed_maxttemp_raw) {
1524
-          target_temperature_bed = 0;
1525
-          bed_max_temp_error();
1526
-        }
1548
+      #if HEATER_BED_RAW_LO_TEMP > HEATER_BED_RAW_HI_TEMP
1549
+        #define GEBED <=
1550
+        #define LEBED >=
1551
+      #else
1552
+        #define GEBED >=
1553
+        #define LEBED <=
1554
+      #endif
1555
+      if (current_temperature_bed_raw GEBED bed_maxttemp_raw) {
1556
+        target_temperature_bed = 0;
1557
+        bed_max_temp_error();
1558
+      }
1527
     #endif
1559
     #endif
1560
+
1528
   } // temp_count >= OVERSAMPLENR
1561
   } // temp_count >= OVERSAMPLENR
1529
 
1562
 
1530
   #ifdef BABYSTEPPING
1563
   #ifdef BABYSTEPPING

+ 88
- 1
Marlin/ultralcd.cpp 查看文件

69
 static void lcd_delta_calibrate_menu();
69
 static void lcd_delta_calibrate_menu();
70
 #endif // DELTA_CALIBRATION_MENU
70
 #endif // DELTA_CALIBRATION_MENU
71
 
71
 
72
+#if defined(MANUAL_BED_LEVELING)
73
+#include "mesh_bed_leveling.h"
74
+static void _lcd_level_bed();
75
+static void _lcd_level_bed_homing();
76
+static void lcd_level_bed();
77
+#endif  // MANUAL_BED_LEVELING
78
+
72
 static void lcd_quick_feedback();//Cause an LCD refresh, and give the user visual or audible feedback that something has happened
79
 static void lcd_quick_feedback();//Cause an LCD refresh, and give the user visual or audible feedback that something has happened
73
 
80
 
74
 /* Different types of actions that can be used in menu items. */
81
 /* Different types of actions that can be used in menu items. */
629
     }
636
     }
630
   #endif
637
   #endif
631
   MENU_ITEM(submenu, MSG_MOVE_AXIS, lcd_move_menu);
638
   MENU_ITEM(submenu, MSG_MOVE_AXIS, lcd_move_menu);
639
+
640
+  #if defined(MANUAL_BED_LEVELING)
641
+    MENU_ITEM(submenu, MSG_LEVEL_BED, lcd_level_bed);
642
+  #endif
632
 	
643
 	
633
   END_MENU();
644
   END_MENU();
634
 }
645
 }
1336
     #endif
1347
     #endif
1337
 
1348
 
1338
     #ifdef ULTIPANEL
1349
     #ifdef ULTIPANEL
1339
-      if (currentMenu != lcd_status_screen && millis() > timeoutToStatus) {
1350
+      if (currentMenu != lcd_status_screen &&
1351
+        #if defined(MANUAL_BED_LEVELING)
1352
+          currentMenu != _lcd_level_bed && 
1353
+          currentMenu != _lcd_level_bed_homing && 
1354
+        #endif  // MANUAL_BED_LEVELING
1355
+          millis() > timeoutToStatus) {
1340
         lcd_return_to_status();
1356
         lcd_return_to_status();
1341
         lcdDrawUpdate = 2;
1357
         lcdDrawUpdate = 2;
1342
       }
1358
       }
1755
   return conv;
1771
   return conv;
1756
 }
1772
 }
1757
 
1773
 
1774
+#if defined(MANUAL_BED_LEVELING)
1775
+static int _lcd_level_bed_position;
1776
+static void _lcd_level_bed()
1777
+{
1778
+  if (encoderPosition != 0) {
1779
+    refresh_cmd_timeout();
1780
+    current_position[Z_AXIS] += float((int)encoderPosition) * 0.05;
1781
+    if (min_software_endstops && current_position[Z_AXIS] < Z_MIN_POS) current_position[Z_AXIS] = Z_MIN_POS;
1782
+    if (max_software_endstops && current_position[Z_AXIS] > Z_MAX_POS) current_position[Z_AXIS] = Z_MAX_POS;
1783
+    encoderPosition = 0;
1784
+    plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[Z_AXIS]/60, active_extruder);
1785
+    lcdDrawUpdate = 1;
1786
+  }
1787
+  if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR("Z"), ftostr32(current_position[Z_AXIS]));
1788
+  static bool debounce_click = false;
1789
+  if (LCD_CLICKED) {
1790
+    if (!debounce_click) {
1791
+      debounce_click = true;
1792
+      int ix = _lcd_level_bed_position % MESH_NUM_X_POINTS;
1793
+      int iy = _lcd_level_bed_position / MESH_NUM_X_POINTS;
1794
+      mbl.set_z(ix, iy, current_position[Z_AXIS]);
1795
+      _lcd_level_bed_position++;
1796
+      if (_lcd_level_bed_position == MESH_NUM_X_POINTS*MESH_NUM_Y_POINTS) {
1797
+        current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
1798
+        plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[X_AXIS]/60, active_extruder);
1799
+        mbl.active = 1;
1800
+        enquecommands_P(PSTR("G28"));
1801
+        lcd_return_to_status();
1802
+      } else {
1803
+        current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
1804
+        plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[X_AXIS]/60, active_extruder);
1805
+        ix = _lcd_level_bed_position % MESH_NUM_X_POINTS;
1806
+        iy = _lcd_level_bed_position / MESH_NUM_X_POINTS;
1807
+        if (iy&1) { // Zig zag
1808
+          ix = (MESH_NUM_X_POINTS - 1) - ix;
1809
+        }
1810
+        current_position[X_AXIS] = mbl.get_x(ix);
1811
+        current_position[Y_AXIS] = mbl.get_y(iy);
1812
+        plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[X_AXIS]/60, active_extruder);
1813
+        lcdDrawUpdate = 1;
1814
+      }
1815
+    }
1816
+  } else {
1817
+    debounce_click = false;
1818
+  }
1819
+}
1820
+static void _lcd_level_bed_homing()
1821
+{
1822
+  if (axis_known_position[X_AXIS] &&
1823
+      axis_known_position[Y_AXIS] &&
1824
+      axis_known_position[Z_AXIS]) {
1825
+    current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
1826
+    plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
1827
+    current_position[X_AXIS] = MESH_MIN_X;
1828
+    current_position[Y_AXIS] = MESH_MIN_Y;
1829
+    plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[X_AXIS]/60, active_extruder);
1830
+    _lcd_level_bed_position = 0;
1831
+    lcd_goto_menu(_lcd_level_bed);
1832
+  }
1833
+}
1834
+static void lcd_level_bed()
1835
+{
1836
+  axis_known_position[X_AXIS] = false;
1837
+  axis_known_position[Y_AXIS] = false;
1838
+  axis_known_position[Z_AXIS] = false;
1839
+  mbl.reset();
1840
+  enquecommands_P(PSTR("G28"));
1841
+  lcd_goto_menu(_lcd_level_bed_homing);
1842
+}
1843
+#endif  // MANUAL_BED_LEVELING
1844
+
1758
 #endif //ULTRA_LCD
1845
 #endif //ULTRA_LCD

Loading…
取消
儲存