Browse Source

UBL implementation

Scott Lahteine 7 years ago
parent
commit
fb60aa3736

+ 3
- 25
Marlin/M100_Free_Mem_Chk.cpp View File

35
  * M100 C x Corrupts x locations within the free memory block.   This is useful to check the
35
  * M100 C x Corrupts x locations within the free memory block.   This is useful to check the
36
  *    correctness of the M100 F and M100 D commands.
36
  *    correctness of the M100 F and M100 D commands.
37
  *
37
  *
38
- * Initial version by Roxy-3DPrintBoard
38
+ * Initial version by Roxy-3D
39
  */
39
  */
40
 #define M100_FREE_MEMORY_DUMPER     // Comment out to remove Dump sub-command
40
 #define M100_FREE_MEMORY_DUMPER     // Comment out to remove Dump sub-command
41
 #define M100_FREE_MEMORY_CORRUPTOR    // Comment out to remove Corrupt sub-command
41
 #define M100_FREE_MEMORY_CORRUPTOR    // Comment out to remove Corrupt sub-command
51
 // Utility functions used by M100 to get its work done.
51
 // Utility functions used by M100 to get its work done.
52
 //
52
 //
53
 
53
 
54
+#include "hex_print_routines.h"
55
+
54
 char* top_of_stack();
56
 char* top_of_stack();
55
-void prt_hex_nibble(unsigned int);
56
-void prt_hex_byte(unsigned int);
57
-void prt_hex_word(unsigned int);
58
 int how_many_E5s_are_here(char*);
57
 int how_many_E5s_are_here(char*);
59
 
58
 
60
 void gcode_M100() {
59
 void gcode_M100() {
211
   return &x + 1; // x is pulled on return;
210
   return &x + 1; // x is pulled on return;
212
 }
211
 }
213
 
212
 
214
-//
215
-// 3 support routines to print hex numbers.  We can print a nibble, byte and word
216
-//
217
-
218
-void prt_hex_nibble(unsigned int n) {
219
-  if (n <= 9)
220
-    SERIAL_ECHO(n);
221
-  else
222
-    SERIAL_ECHO((char)('A' + n - 10));
223
-}
224
-
225
-void prt_hex_byte(unsigned int b) {
226
-  prt_hex_nibble((b & 0xf0) >> 4);
227
-  prt_hex_nibble(b & 0x0f);
228
-}
229
-
230
-void prt_hex_word(unsigned int w) {
231
-  prt_hex_byte((w & 0xff00) >> 8);
232
-  prt_hex_byte(w & 0x0ff);
233
-}
234
-
235
 // how_many_E5s_are_here() is a utility function to easily find out how many 0xE5's are
213
 // how_many_E5s_are_here() is a utility function to easily find out how many 0xE5's are
236
 // at the specified location.  Having this logic as a function simplifies the search code.
214
 // at the specified location.  Having this logic as a function simplifies the search code.
237
 //
215
 //

+ 3
- 0
Marlin/Marlin.h View File

40
 #include "fastio.h"
40
 #include "fastio.h"
41
 #include "utility.h"
41
 #include "utility.h"
42
 
42
 
43
+
43
 #ifdef USBCON
44
 #ifdef USBCON
44
   #include "HardwareSerial.h"
45
   #include "HardwareSerial.h"
45
   #if ENABLED(BLUETOOTH)
46
   #if ENABLED(BLUETOOTH)
82
 #define SERIAL_ECHOLNPGM(x)            SERIAL_PROTOCOLLNPGM(x)
83
 #define SERIAL_ECHOLNPGM(x)            SERIAL_PROTOCOLLNPGM(x)
83
 #define SERIAL_ECHOPAIR(name,value)    SERIAL_PROTOCOLPAIR(name, value)
84
 #define SERIAL_ECHOPAIR(name,value)    SERIAL_PROTOCOLPAIR(name, value)
84
 #define SERIAL_ECHOLNPAIR(name, value) SERIAL_PROTOCOLLNPAIR(name, value)
85
 #define SERIAL_ECHOLNPAIR(name, value) SERIAL_PROTOCOLLNPAIR(name, value)
86
+#define SERIAL_ECHO_F(x,y)             SERIAL_PROTOCOL_F(x,y)
85
 
87
 
86
 #define SERIAL_ERROR_START            (serialprintPGM(errormagic))
88
 #define SERIAL_ERROR_START            (serialprintPGM(errormagic))
87
 #define SERIAL_ERROR(x)                SERIAL_PROTOCOL(x)
89
 #define SERIAL_ERROR(x)                SERIAL_PROTOCOL(x)
95
 void serial_echopair_P(const char* s_P, long v);
97
 void serial_echopair_P(const char* s_P, long v);
96
 void serial_echopair_P(const char* s_P, float v);
98
 void serial_echopair_P(const char* s_P, float v);
97
 void serial_echopair_P(const char* s_P, double v);
99
 void serial_echopair_P(const char* s_P, double v);
100
+void serial_echopair_P(const char* s_P, unsigned int v);
98
 void serial_echopair_P(const char* s_P, unsigned long v);
101
 void serial_echopair_P(const char* s_P, unsigned long v);
99
 FORCE_INLINE void serial_echopair_P(const char* s_P, uint8_t v) { serial_echopair_P(s_P, (int)v); }
102
 FORCE_INLINE void serial_echopair_P(const char* s_P, uint8_t v) { serial_echopair_P(s_P, (int)v); }
100
 FORCE_INLINE void serial_echopair_P(const char* s_P, uint16_t v) { serial_echopair_P(s_P, (int)v); }
103
 FORCE_INLINE void serial_echopair_P(const char* s_P, uint16_t v) { serial_echopair_P(s_P, (int)v); }

+ 54
- 10
Marlin/Marlin_main.cpp View File

1
 /**
1
 /**
2
  * Marlin 3D Printer Firmware
2
  * Marlin 3D Printer Firmware
3
- * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
3
+ * Copyright (C) 2016, 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
  *
4
  *
5
  * Based on Sprinter and grbl.
5
  * Based on Sprinter and grbl.
6
  * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
6
  * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
234
 #include "duration_t.h"
234
 #include "duration_t.h"
235
 #include "types.h"
235
 #include "types.h"
236
 
236
 
237
+#if ENABLED(AUTO_BED_LEVELING_UBL)
238
+  #include "UBL.h"
239
+#endif
240
+
237
 #if HAS_ABL
241
 #if HAS_ABL
238
   #include "vector_3.h"
242
   #include "vector_3.h"
239
   #if ENABLED(AUTO_BED_LEVELING_LINEAR)
243
   #if ENABLED(AUTO_BED_LEVELING_LINEAR)
297
        G38_endstop_hit = false;
301
        G38_endstop_hit = false;
298
 #endif
302
 #endif
299
 
303
 
304
+#if ENABLED(AUTO_BED_LEVELING_UBL)
305
+  bed_leveling blm;
306
+#endif
307
+
300
 bool Running = true;
308
 bool Running = true;
301
 
309
 
302
 uint8_t marlin_debug_flags = DEBUG_NONE;
310
 uint8_t marlin_debug_flags = DEBUG_NONE;
315
  *   Set with 'gcode_get_destination' or 'set_destination_to_current'.
323
  *   Set with 'gcode_get_destination' or 'set_destination_to_current'.
316
  *   'line_to_destination' sets 'current_position' to 'destination'.
324
  *   'line_to_destination' sets 'current_position' to 'destination'.
317
  */
325
  */
318
-static float destination[XYZE] = { 0.0 };
326
+float destination[XYZE] = { 0.0 };
319
 
327
 
320
 /**
328
 /**
321
  * axis_homed
329
  * axis_homed
1760
 #endif //HAS_BED_PROBE
1768
 #endif //HAS_BED_PROBE
1761
 
1769
 
1762
 #if ENABLED(Z_PROBE_ALLEN_KEY) || ENABLED(Z_PROBE_SLED) || HAS_PROBING_PROCEDURE || HOTENDS > 1 || ENABLED(NOZZLE_CLEAN_FEATURE) || ENABLED(NOZZLE_PARK_FEATURE)
1770
 #if ENABLED(Z_PROBE_ALLEN_KEY) || ENABLED(Z_PROBE_SLED) || HAS_PROBING_PROCEDURE || HOTENDS > 1 || ENABLED(NOZZLE_CLEAN_FEATURE) || ENABLED(NOZZLE_PARK_FEATURE)
1763
-  static bool axis_unhomed_error(const bool x, const bool y, const bool z) {
1771
+  bool axis_unhomed_error(const bool x, const bool y, const bool z) {
1764
     const bool xx = x && !axis_homed[X_AXIS],
1772
     const bool xx = x && !axis_homed[X_AXIS],
1765
                yy = y && !axis_homed[Y_AXIS],
1773
                yy = y && !axis_homed[Y_AXIS],
1766
                zz = z && !axis_homed[Z_AXIS];
1774
                zz = z && !axis_homed[Z_AXIS];
2009
   #endif
2017
   #endif
2010
 
2018
 
2011
   // returns false for ok and true for failure
2019
   // returns false for ok and true for failure
2012
-  static bool set_probe_deployed(bool deploy) {
2020
+  bool set_probe_deployed(bool deploy) {
2013
 
2021
 
2014
     #if ENABLED(DEBUG_LEVELING_FEATURE)
2022
     #if ENABLED(DEBUG_LEVELING_FEATURE)
2015
       if (DEBUGGING(LEVELING)) {
2023
       if (DEBUGGING(LEVELING)) {
2184
   //   - Raise to the BETWEEN height
2192
   //   - Raise to the BETWEEN height
2185
   // - Return the probed Z position
2193
   // - Return the probed Z position
2186
   //
2194
   //
2187
-  static float probe_pt(const float &x, const float &y, const bool stow = true, const int verbose_level = 1) {
2195
+//float probe_pt(const float &x, const float &y, const bool stow = true, const int verbose_level = 1) {
2196
+  float probe_pt(const float x, const float y, const bool stow, const int verbose_level) {
2188
     #if ENABLED(DEBUG_LEVELING_FEATURE)
2197
     #if ENABLED(DEBUG_LEVELING_FEATURE)
2189
       if (DEBUGGING(LEVELING)) {
2198
       if (DEBUGGING(LEVELING)) {
2190
         SERIAL_ECHOPAIR(">>> probe_pt(", x);
2199
         SERIAL_ECHOPAIR(">>> probe_pt(", x);
3279
         SERIAL_ECHOPGM("BILINEAR");
3288
         SERIAL_ECHOPGM("BILINEAR");
3280
       #elif ENABLED(AUTO_BED_LEVELING_3POINT)
3289
       #elif ENABLED(AUTO_BED_LEVELING_3POINT)
3281
         SERIAL_ECHOPGM("3POINT");
3290
         SERIAL_ECHOPGM("3POINT");
3291
+      #elif ENABLED(AUTO_BED_LEVELING_UBL)
3292
+        SERIAL_ECHOPGM("UBL");
3282
       #endif
3293
       #endif
3283
       if (planner.abl_enabled) {
3294
       if (planner.abl_enabled) {
3284
         SERIAL_ECHOLNPGM(" (enabled)");
3295
         SERIAL_ECHOLNPGM(" (enabled)");
3285
-        #if ENABLED(AUTO_BED_LEVELING_LINEAR) || ENABLED(AUTO_BED_LEVELING_3POINT)
3296
+        #if ENABLED(AUTO_BED_LEVELING_LINEAR) || ENABLED(AUTO_BED_LEVELING_3POINT) || ENABLED(AUTO_BED_LEVELING_UBL)
3286
           float diff[XYZ] = {
3297
           float diff[XYZ] = {
3287
             stepper.get_axis_position_mm(X_AXIS) - current_position[X_AXIS],
3298
             stepper.get_axis_position_mm(X_AXIS) - current_position[X_AXIS],
3288
             stepper.get_axis_position_mm(Y_AXIS) - current_position[Y_AXIS],
3299
             stepper.get_axis_position_mm(Y_AXIS) - current_position[Y_AXIS],
3830
     report_current_position();
3841
     report_current_position();
3831
   }
3842
   }
3832
 
3843
 
3833
-#elif HAS_ABL
3844
+#elif HAS_ABL && DISABLED(AUTO_BED_LEVELING_UBL)
3834
 
3845
 
3835
   /**
3846
   /**
3836
    * G29: Detailed Z probe, probes the bed at 3 or more points.
3847
    * G29: Detailed Z probe, probes the bed at 3 or more points.
4383
       SYNC_PLAN_POSITION_KINEMATIC();
4394
       SYNC_PLAN_POSITION_KINEMATIC();
4384
   }
4395
   }
4385
 
4396
 
4386
-#endif // HAS_ABL
4397
+#endif // HAS_ABL && DISABLED(AUTO_BED_LEVELING_UBL)
4387
 
4398
 
4388
 #if HAS_BED_PROBE
4399
 #if HAS_BED_PROBE
4389
 
4400
 
6993
             bed_level_virt_print();
7004
             bed_level_virt_print();
6994
           #endif
7005
           #endif
6995
         }
7006
         }
7007
+      #elif ENABLED(AUTO_BED_LEVELING_UBL)
7008
+        blm.display_map(0);  // Right now, we only support one type of map
6996
       #elif ENABLED(MESH_BED_LEVELING)
7009
       #elif ENABLED(MESH_BED_LEVELING)
6997
         if (mbl.has_mesh()) {
7010
         if (mbl.has_mesh()) {
6998
           SERIAL_ECHOLNPGM("Mesh Bed Level data:");
7011
           SERIAL_ECHOLNPGM("Mesh Bed Level data:");
8303
           break;
8316
           break;
8304
       #endif // INCH_MODE_SUPPORT
8317
       #endif // INCH_MODE_SUPPORT
8305
 
8318
 
8319
+      #if ENABLED(AUTO_BED_LEVELING_UBL)
8320
+        case 26: // G26: Mesh Validation Pattern generation
8321
+          gcode_G26();
8322
+          break;
8323
+      #endif // AUTO_BED_LEVELING_UBL
8324
+
8306
       #if ENABLED(NOZZLE_PARK_FEATURE)
8325
       #if ENABLED(NOZZLE_PARK_FEATURE)
8307
         case 27: // G27: Nozzle Park
8326
         case 27: // G27: Nozzle Park
8308
           gcode_G27();
8327
           gcode_G27();
8314
         break;
8333
         break;
8315
 
8334
 
8316
       #if PLANNER_LEVELING
8335
       #if PLANNER_LEVELING
8317
-        case 29: // G29 Detailed Z probe, probes the bed at 3 or more points.
8336
+        case 29: // G29 Detailed Z probe, probes the bed at 3 or more points,
8337
+                 // or provides access to the UBL System if enabled.
8318
           gcode_G29();
8338
           gcode_G29();
8319
           break;
8339
           break;
8320
       #endif // PLANNER_LEVELING
8340
       #endif // PLANNER_LEVELING
8421
           gcode_M43(); break;
8441
           gcode_M43(); break;
8422
       #endif
8442
       #endif
8423
 
8443
 
8444
+
8424
       #if ENABLED(Z_MIN_PROBE_REPEATABILITY_TEST)
8445
       #if ENABLED(Z_MIN_PROBE_REPEATABILITY_TEST)
8425
         case 48: // M48: Z probe repeatability test
8446
         case 48: // M48: Z probe repeatability test
8426
           gcode_M48();
8447
           gcode_M48();
8427
           break;
8448
           break;
8428
       #endif // Z_MIN_PROBE_REPEATABILITY_TEST
8449
       #endif // Z_MIN_PROBE_REPEATABILITY_TEST
8429
 
8450
 
8451
+      #if ENABLED(AUTO_BED_LEVELING_UBL)
8452
+        case 49: // M49: Turn on or off G26_Debug_flag for verbose output
8453
+    if (G26_Debug_flag) {
8454
+            SERIAL_PROTOCOLPGM("UBL Debug Flag turned off.\n");
8455
+            G26_Debug_flag = 0; }
8456
+    else {
8457
+            SERIAL_PROTOCOLPGM("UBL Debug Flag turned on.\n");
8458
+            G26_Debug_flag++; }
8459
+          break;
8460
+      #endif // Z_MIN_PROBE_REPEATABILITY_TEST
8461
+
8430
       case 75: // M75: Start print timer
8462
       case 75: // M75: Start print timer
8431
         gcode_M75(); break;
8463
         gcode_M75(); break;
8432
       case 76: // M76: Pause print timer
8464
       case 76: // M76: Pause print timer
9066
       SERIAL_ECHOLNPAIR(" offset=", offset);
9098
       SERIAL_ECHOLNPAIR(" offset=", offset);
9067
     }
9099
     }
9068
     last_offset = offset;
9100
     last_offset = offset;
9069
-    //*/
9101
+    */
9070
 
9102
 
9071
     return offset;
9103
     return offset;
9072
   }
9104
   }
9552
           return false;
9584
           return false;
9553
         }
9585
         }
9554
         else
9586
         else
9587
+      #elif ENABLED(AUTO_BED_LEVELING_UBL)
9588
+        if (blm.state.active) {
9589
+
9590
+//        UBL_line_to_destination(MMS_SCALED(feedrate_mm_s));
9591
+
9592
+          UBL_line_to_destination(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS],
9593
+//                      (feedrate*(1.0/60.0))*(feedrate_percentage*(1.0/100.0) ), active_extruder);
9594
+                      MMS_SCALED(feedrate_mm_s), active_extruder);
9595
+
9596
+          return false;
9597
+        }
9598
+        else
9555
       #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
9599
       #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
9556
         if (planner.abl_enabled) {
9600
         if (planner.abl_enabled) {
9557
           bilinear_line_to_destination(MMS_SCALED(feedrate_mm_s));
9601
           bilinear_line_to_destination(MMS_SCALED(feedrate_mm_s));

+ 83
- 1
Marlin/configuration_store.cpp View File

164
   #include "stepper_indirection.h"
164
   #include "stepper_indirection.h"
165
 #endif
165
 #endif
166
 
166
 
167
+#if ENABLED(AUTO_BED_LEVELING_UBL)
168
+  #include "UBL.h"
169
+#endif
170
+
167
 #if ENABLED(ABL_BILINEAR_SUBDIVISION)
171
 #if ENABLED(ABL_BILINEAR_SUBDIVISION)
168
   extern void bed_level_virt_interpolate();
172
   extern void bed_level_virt_interpolate();
169
 #endif
173
 #endif
534
       SERIAL_ECHOPAIR("Settings Stored (", eeprom_size - (EEPROM_OFFSET));
538
       SERIAL_ECHOPAIR("Settings Stored (", eeprom_size - (EEPROM_OFFSET));
535
       SERIAL_ECHOLNPGM(" bytes)");
539
       SERIAL_ECHOLNPGM(" bytes)");
536
     }
540
     }
541
+    #if ENABLED(AUTO_BED_LEVELING_UBL)
542
+      blm.store_state();
543
+      if (blm.state.EEPROM_storage_slot >= 0)
544
+        blm.store_mesh(blm.state.EEPROM_storage_slot);
545
+    #endif
537
   }
546
   }
538
 
547
 
539
   /**
548
   /**
832
         SERIAL_ERRORLNPGM("EEPROM checksum mismatch");
841
         SERIAL_ERRORLNPGM("EEPROM checksum mismatch");
833
         Config_ResetDefault();
842
         Config_ResetDefault();
834
       }
843
       }
835
-   }
836
 
844
 
845
+      #if ENABLED(AUTO_BED_LEVELING_UBL)
846
+        Unified_Bed_Leveling_EEPROM_start = (eeprom_index + 32) & 0xFFF8; // Pad the end of configuration data so it
847
+                                                                          // can float up or down a little bit without
848
+                                                                          // disrupting the Unified Bed Leveling data
849
+        blm.load_state();
850
+
851
+        SERIAL_ECHOPGM(" UBL ");
852
+        if (!blm.state.active) SERIAL_ECHO("not ");
853
+        SERIAL_ECHOLNPGM("active!");
854
+
855
+        if (!blm.sanity_check()) {
856
+          int tmp_mesh;                                // We want to preserve whether the UBL System is Active
857
+          bool tmp_active;                             // If it is, we want to preserve the Mesh that is being used.
858
+          tmp_mesh = blm.state.EEPROM_storage_slot;
859
+          tmp_active = blm.state.active;
860
+          SERIAL_ECHOLNPGM("\nInitializing Bed Leveling State to current firmware settings.\n");
861
+          blm.state = blm.pre_initialized;             // Initialize with the pre_initialized data structure
862
+          blm.state.EEPROM_storage_slot = tmp_mesh;    // But then restore some data we don't want mangled
863
+          blm.state.active = tmp_active;
864
+        }
865
+        else {
866
+          SERIAL_PROTOCOLPGM("?Unable to enable Unified Bed Leveling.\n");
867
+          blm.state = blm.pre_initialized;
868
+          blm.reset();
869
+          blm.store_state();
870
+        }
871
+
872
+        if (blm.state.EEPROM_storage_slot >= 0)  {
873
+          blm.load_mesh(blm.state.EEPROM_storage_slot);
874
+          SERIAL_ECHOPAIR("Mesh ", blm.state.EEPROM_storage_slot);
875
+          SERIAL_ECHOLNPGM(" loaded from storage.");
876
+        }
877
+        else {
878
+          blm.reset();
879
+          SERIAL_ECHOPGM("UBL System reset() \n");
880
+        }
881
+      #endif
882
+    }
837
     #if ENABLED(EEPROM_CHITCHAT)
883
     #if ENABLED(EEPROM_CHITCHAT)
838
       Config_PrintSettings();
884
       Config_PrintSettings();
839
     #endif
885
     #endif
1126
       SERIAL_ECHOPAIR(" Z", home_offset[Z_AXIS]);
1172
       SERIAL_ECHOPAIR(" Z", home_offset[Z_AXIS]);
1127
       SERIAL_EOL;
1173
       SERIAL_EOL;
1128
     #endif
1174
     #endif
1175
+  #if ENABLED(AUTO_BED_LEVELING_UBL)
1176
+    SERIAL_ECHOLNPGM("Unified Bed Leveling:");
1177
+    CONFIG_ECHO_START;
1178
+
1179
+    SERIAL_ECHOPGM("System is: ");
1180
+    if (blm.state.active)
1181
+       SERIAL_ECHOLNPGM("Active\n");
1182
+    else
1183
+       SERIAL_ECHOLNPGM("Deactive\n");
1184
+
1185
+    SERIAL_ECHOPAIR("Active Mesh Slot: ", blm.state.EEPROM_storage_slot);
1186
+    SERIAL_EOL;
1187
+
1188
+    SERIAL_ECHOPGM("z_offset: ");
1189
+    SERIAL_ECHO_F(blm.state.z_offset, 6);
1190
+    SERIAL_EOL;
1191
+
1192
+    SERIAL_ECHOPAIR("EEPROM can hold ", (int)((E2END - sizeof(blm.state) - Unified_Bed_Leveling_EEPROM_start) / sizeof(z_values)));
1193
+    SERIAL_ECHOLNPGM(" meshes. \n");
1194
+
1195
+    SERIAL_ECHOPAIR("\nUBL_MESH_NUM_X_POINTS  ", UBL_MESH_NUM_X_POINTS);
1196
+    SERIAL_ECHOPAIR("\nUBL_MESH_NUM_Y_POINTS  ", UBL_MESH_NUM_Y_POINTS);
1197
+
1198
+    SERIAL_ECHOPAIR("\nUBL_MESH_MIN_X         ", UBL_MESH_MIN_X);
1199
+    SERIAL_ECHOPAIR("\nUBL_MESH_MIN_Y         ", UBL_MESH_MIN_Y);
1200
+
1201
+    SERIAL_ECHOPAIR("\nUBL_MESH_MAX_X         ", UBL_MESH_MAX_X);
1202
+    SERIAL_ECHOPAIR("\nUBL_MESH_MAX_Y         ", UBL_MESH_MAX_Y);
1203
+
1204
+    SERIAL_ECHOPGM("\nMESH_X_DIST        ");
1205
+    SERIAL_ECHO_F(MESH_X_DIST, 6);
1206
+    SERIAL_ECHOPGM("\nMESH_Y_DIST        ");
1207
+    SERIAL_ECHO_F(MESH_Y_DIST, 6);
1208
+    SERIAL_EOL;
1209
+    SERIAL_EOL;
1210
+  #endif
1129
 
1211
 
1130
     #if HOTENDS > 1
1212
     #if HOTENDS > 1
1131
       CONFIG_ECHO_START;
1213
       CONFIG_ECHO_START;

+ 123
- 3
Marlin/ultralcd.cpp View File

30
 #include "configuration_store.h"
30
 #include "configuration_store.h"
31
 #include "utility.h"
31
 #include "utility.h"
32
 
32
 
33
+extern float zprobe_zoffset;
34
+
33
 #if HAS_BUZZER && DISABLED(LCD_USE_I2C_BUZZER)
35
 #if HAS_BUZZER && DISABLED(LCD_USE_I2C_BUZZER)
34
   #include "buzzer.h"
36
   #include "buzzer.h"
35
 #endif
37
 #endif
121
   bool encoderRateMultiplierEnabled;
123
   bool encoderRateMultiplierEnabled;
122
   int32_t lastEncoderMovementMillis;
124
   int32_t lastEncoderMovementMillis;
123
 
125
 
126
+  #if ENABLED(AUTO_BED_LEVELING_UBL)
127
+  extern int UBL_has_control_of_LCD_Panel;
128
+  extern int G29_encoderDiff;
129
+  #endif
130
+
124
   #if HAS_POWER_SWITCH
131
   #if HAS_POWER_SWITCH
125
     extern bool powersupply;
132
     extern bool powersupply;
126
   #endif
133
   #endif
801
 
808
 
802
   #endif //BABYSTEPPING
809
   #endif //BABYSTEPPING
803
 
810
 
811
+  #if ENABLED(AUTO_BED_LEVELING_UBL)
812
+
813
+    float Mesh_Edit_Value, Mesh_Edit_Accumulator; // We round Mesh_Edit_Value to 2.5 decimal places.  So we keep a
814
+                                                  // seperate value that doesn't lose precision.
815
+    static int loop_cnt=0, last_seen_bits;
816
+
817
+    static void _lcd_mesh_fine_tune( const char* msg) {
818
+      static unsigned long last_click=0;
819
+      int  last_digit, movement;
820
+      long int rounded;
821
+
822
+      defer_return_to_status = true;
823
+      if (encoderPosition) {                     // If moving the Encoder wheel very slowly, we just go
824
+        if ( (millis() - last_click) > 500L) {   // up or down by 1 position
825
+          if ( ((int32_t)encoderPosition) > 0 ) {
826
+            encoderPosition = 1;
827
+          }
828
+          else {
829
+            encoderPosition = (uint32_t) -1;
830
+          }
831
+        }
832
+        last_click = millis();
833
+
834
+        Mesh_Edit_Accumulator += ( (float) ((int32_t)encoderPosition)) * .005 / 2.0 ;
835
+        Mesh_Edit_Value       = Mesh_Edit_Accumulator;
836
+        encoderPosition       = 0;
837
+        lcdDrawUpdate       = LCDVIEW_REDRAW_NOW;
838
+
839
+        rounded    = (long int) (Mesh_Edit_Value * 1000.0);
840
+        last_digit = rounded % 5L; //10L;
841
+        rounded    = rounded - last_digit;
842
+        last_digit = rounded % 5L; //10L;
843
+        Mesh_Edit_Value  = ((float) rounded) / 1000.0;
844
+      }
845
+
846
+      if (lcdDrawUpdate) {
847
+        lcd_implementation_drawedit(msg, ftostr43sign( (float) Mesh_Edit_Value  ));
848
+      }
849
+
850
+      if ( !UBL_has_control_of_LCD_Panel && LCD_CLICKED ) {
851
+        UBL_has_control_of_LCD_Panel=1;   // We need to lock the normal LCD Panel System outbecause G29 (and G26) are looking for
852
+        lcd_return_to_status();           // long presses of the Encoder Wheel and the LCD System goes spastic when that happens.
853
+                                          // We will give back control from those routines when the switch is debounced.
854
+      }
855
+    }
856
+
857
+
858
+    void _lcd_mesh_edit() {
859
+      _lcd_mesh_fine_tune( PSTR("Mesh Editor: "));
860
+    }
861
+
862
+    float lcd_mesh_edit() {
863
+      lcd_goto_screen(_lcd_mesh_edit);
864
+      return Mesh_Edit_Value;
865
+    }
866
+
867
+    void lcd_mesh_edit_setup(float inital) {
868
+      Mesh_Edit_Value       = inital;
869
+      Mesh_Edit_Accumulator = inital;
870
+      lcd_goto_screen(_lcd_mesh_edit);
871
+      return ;
872
+    }
873
+
874
+    void _lcd_z_offset_edit() {
875
+      _lcd_mesh_fine_tune( PSTR("Z-Offset: "));
876
+    }
877
+
878
+    float lcd_z_offset_edit() {
879
+      lcd_goto_screen(_lcd_z_offset_edit);
880
+      return Mesh_Edit_Value;
881
+    }
882
+
883
+    void lcd_z_offset_edit_setup(float inital) {
884
+      Mesh_Edit_Value       = inital;
885
+      Mesh_Edit_Accumulator = inital;
886
+      lcd_goto_screen(_lcd_z_offset_edit);
887
+      return ;
888
+    }
889
+
890
+
891
+  #endif // AUTO_BED_LEVELING_UBL
892
+
893
+
804
   /**
894
   /**
805
    * Watch temperature callbacks
895
    * Watch temperature callbacks
806
    */
896
    */
1307
     void _lcd_level_bed_moving() {
1397
     void _lcd_level_bed_moving() {
1308
       if (lcdDrawUpdate) {
1398
       if (lcdDrawUpdate) {
1309
         char msg[10];
1399
         char msg[10];
1310
-        sprintf_P(msg, PSTR("%i / %u"), (int)(manual_probe_index + 1), (MESH_NUM_X_POINTS) * (MESH_NUM_Y_POINTS));
1400
+        #if ENABLED(MESH_BED_LEVELING)
1401
+          sprintf_P(msg, PSTR("%i / %u"), (int)(manual_probe_index + 1), (MESH_NUM_X_POINTS) * (MESH_NUM_Y_POINTS));
1402
+        #elif ENABLED(AUTO_BED_LEVELING_UBL)
1403
+          sprintf_P(msg, PSTR("%i / %u"), (int)(manual_probe_index + 1), (UBL_MESH_NUM_X_POINTS) * (UBL_MESH_NUM_Y_POINTS));
1404
+        #endif
1311
         lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_NEXT_POINT), msg);
1405
         lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_NEXT_POINT), msg);
1312
       }
1406
       }
1313
 
1407
 
3110
 
3204
 
3111
     lcd_buttons_update();
3205
     lcd_buttons_update();
3112
 
3206
 
3207
+    #if ENABLED(AUTO_BED_LEVELING_UBL)
3208
+      const bool UBL_CONDITION = !UBL_has_control_of_LCD_Panel;
3209
+    #else
3210
+      constexpr bool UBL_CONDITION = true;
3211
+    #endif
3212
+
3113
     // If the action button is pressed...
3213
     // If the action button is pressed...
3114
-    if (LCD_CLICKED) {
3214
+    if (UBL_CONDITION && LCD_CLICKED) {
3115
       if (!wait_for_unclick) {           // If not waiting for a debounce release:
3215
       if (!wait_for_unclick) {           // If not waiting for a debounce release:
3116
         wait_for_unclick = true;         //  Set debounce flag to ignore continous clicks
3216
         wait_for_unclick = true;         //  Set debounce flag to ignore continous clicks
3117
         lcd_clicked = !wait_for_user;    //  Keep the click if not waiting for a user-click
3217
         lcd_clicked = !wait_for_user;    //  Keep the click if not waiting for a user-click
3520
         case encrot2: ENCODER_SPIN(encrot1, encrot3); break;
3620
         case encrot2: ENCODER_SPIN(encrot1, encrot3); break;
3521
         case encrot3: ENCODER_SPIN(encrot2, encrot0); break;
3621
         case encrot3: ENCODER_SPIN(encrot2, encrot0); break;
3522
       }
3622
       }
3623
+      #if ENABLED(AUTO_BED_LEVELING_UBL)
3624
+        if (UBL_has_control_of_LCD_Panel) {
3625
+          G29_encoderDiff = encoderDiff;    // Make the encoder's rotation available to G29's Mesh Editor
3626
+          encoderDiff = 0;                  // We are going to lie to the LCD Panel and claim the encoder
3627
+                                            // wheel has not turned.
3628
+        }
3629
+      #endif
3630
+      lastEncoderBits = enc;
3523
     }
3631
     }
3524
-    lastEncoderBits = enc;
3525
   }
3632
   }
3526
 
3633
 
3527
   #if (ENABLED(LCD_I2C_TYPE_MCP23017) || ENABLED(LCD_I2C_TYPE_MCP23008)) && ENABLED(DETECT_DEVICE)
3634
   #if (ENABLED(LCD_I2C_TYPE_MCP23017) || ENABLED(LCD_I2C_TYPE_MCP23008)) && ENABLED(DETECT_DEVICE)
3530
     bool lcd_detected() { return true; }
3637
     bool lcd_detected() { return true; }
3531
   #endif
3638
   #endif
3532
 
3639
 
3640
+  #if ENABLED(AUTO_BED_LEVELING_UBL)
3641
+    void chirp_at_user() {
3642
+      #if ENABLED(LCD_USE_I2C_BUZZER)
3643
+        lcd.buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
3644
+      #elif PIN_EXISTS(BEEPER)
3645
+        buzzer.tone(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
3646
+      #endif
3647
+    }
3648
+
3649
+    bool G29_lcd_clicked() { return LCD_CLICKED; }
3650
+
3651
+  #endif
3652
+
3533
 #endif // ULTIPANEL
3653
 #endif // ULTIPANEL
3534
 
3654
 
3535
 #endif // ULTRA_LCD
3655
 #endif // ULTRA_LCD

+ 1
- 1
Marlin/ultralcd_impl_DOGM.h View File

320
   lcd_printPGM(PSTR(MSG_PLEASE_RESET));
320
   lcd_printPGM(PSTR(MSG_PLEASE_RESET));
321
 }
321
 }
322
 
322
 
323
-static void lcd_implementation_clear() { } // Automatically cleared by Picture Loop
323
+void lcd_implementation_clear() { } // Automatically cleared by Picture Loop
324
 
324
 
325
 //
325
 //
326
 // Status Screen
326
 // Status Screen

+ 1
- 1
Marlin/ultralcd_impl_HD44780.h View File

378
   lcd.clear();
378
   lcd.clear();
379
 }
379
 }
380
 
380
 
381
-static void lcd_implementation_clear() { lcd.clear(); }
381
+void lcd_implementation_clear() { lcd.clear(); }
382
 
382
 
383
 /* Arduino < 1.0.0 is missing a function to print PROGMEM strings, so we need to implement our own */
383
 /* Arduino < 1.0.0 is missing a function to print PROGMEM strings, so we need to implement our own */
384
 void lcd_printPGM(const char *str) {
384
 void lcd_printPGM(const char *str) {

Loading…
Cancel
Save