Browse Source

Non-reentrant "Moving..." screen to safely wait in LCD

Scott Lahteine 7 years ago
parent
commit
b4dbf4d18a
4 changed files with 71 additions and 50 deletions
  1. 3
    0
      Marlin/language_en.h
  2. 31
    5
      Marlin/ultralcd.cpp
  3. 19
    23
      Marlin/ultralcd_impl_DOGM.h
  4. 18
    22
      Marlin/ultralcd_impl_HD44780.h

+ 3
- 0
Marlin/language_en.h View File

@@ -138,6 +138,9 @@
138 138
 #ifndef MSG_LEVEL_BED
139 139
   #define MSG_LEVEL_BED                       "Level bed"
140 140
 #endif
141
+#ifndef MSG_MOVING
142
+  #define MSG_MOVING                          "Moving..."
143
+#endif
141 144
 #ifndef MSG_MOVE_X
142 145
   #define MSG_MOVE_X                          "Move X"
143 146
 #endif

+ 31
- 5
Marlin/ultralcd.cpp View File

@@ -390,7 +390,7 @@ uint8_t lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; // Set when the LCD needs to
390 390
   bool screen_changed;
391 391
 
392 392
   // LCD and menu clicks
393
-  bool lcd_clicked, wait_for_unclick, defer_return_to_status;
393
+  bool lcd_clicked, wait_for_unclick, defer_return_to_status, no_reentrance;
394 394
 
395 395
   // Variables used when editing values.
396 396
   const char* editLabel;
@@ -422,6 +422,27 @@ uint8_t lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; // Set when the LCD needs to
422 422
     }
423 423
   }
424 424
 
425
+  /**
426
+   * Synchronize safely while holding the current screen
427
+   * This blocks all further screen or stripe updates once called
428
+   */
429
+  inline void lcd_synchronize() {
430
+    lcd_implementation_drawmenu_static(LCD_HEIGHT >= 4 ? 1 : 0, PSTR(MSG_MOVING));
431
+    if (no_reentrance) return;
432
+    no_reentrance = true;
433
+    screenFunc_t old_screen = currentScreen;
434
+    lcd_goto_screen(lcd_synchronize);
435
+    stepper.synchronize();
436
+    no_reentrance = false;
437
+    lcd_goto_screen(old_screen);
438
+  }
439
+
440
+  inline void lcd_wait_for_homing() {
441
+    no_reentrance = true;
442
+    while (!axis_homed[X_AXIS] || !axis_homed[Y_AXIS] || !axis_homed[Z_AXIS]) idle();
443
+    no_reentrance = true;
444
+  }
445
+
425 446
   void lcd_return_to_status() { lcd_goto_screen(lcd_status_screen); }
426 447
 
427 448
   void lcd_save_previous_screen() {
@@ -1063,6 +1084,7 @@ void kill_screen(const char* lcd_msg) {
1063 1084
     // Note: During Manual Bed Leveling the homed Z position is MESH_HOME_SEARCH_Z
1064 1085
     // Z position will be restored with the final action, a G28
1065 1086
     inline void _mbl_goto_xy(float x, float y) {
1087
+      if (no_reentrance) return;
1066 1088
       current_position[Z_AXIS] = LOGICAL_Z_POSITION(MESH_HOME_SEARCH_Z + Z_HOMING_HEIGHT);
1067 1089
       line_to_current(Z_AXIS);
1068 1090
       current_position[X_AXIS] = LOGICAL_X_POSITION(x);
@@ -1072,7 +1094,7 @@ void kill_screen(const char* lcd_msg) {
1072 1094
         current_position[Z_AXIS] = LOGICAL_Z_POSITION(MESH_HOME_SEARCH_Z);
1073 1095
         line_to_current(Z_AXIS);
1074 1096
       #endif
1075
-      stepper.synchronize();
1097
+      lcd_synchronize();
1076 1098
     }
1077 1099
 
1078 1100
     void _lcd_level_goto_next_point();
@@ -1094,6 +1116,8 @@ void kill_screen(const char* lcd_msg) {
1094 1116
     void _lcd_level_bed_get_z() {
1095 1117
       ENCODER_DIRECTION_NORMAL();
1096 1118
 
1119
+      if (no_reentrance) goto KeepDrawing;
1120
+
1097 1121
       // Encoder wheel adjusts the Z position
1098 1122
       if (encoderPosition) {
1099 1123
         refresh_cmd_timeout();
@@ -1121,7 +1145,7 @@ void kill_screen(const char* lcd_msg) {
1121 1145
 
1122 1146
             current_position[Z_AXIS] = MESH_HOME_SEARCH_Z + Z_HOMING_HEIGHT;
1123 1147
             line_to_current(Z_AXIS);
1124
-            stepper.synchronize();
1148
+            lcd_synchronize();
1125 1149
 
1126 1150
             mbl.set_has_mesh(true);
1127 1151
             enqueue_and_echo_commands_P(PSTR("G28"));
@@ -1141,6 +1165,7 @@ void kill_screen(const char* lcd_msg) {
1141 1165
         debounce_click = false;
1142 1166
       }
1143 1167
 
1168
+KeepDrawing:
1144 1169
       // Update on first display, then only on updates to Z position
1145 1170
       // Show message above on clicks instead
1146 1171
       if (lcdDrawUpdate) {
@@ -1215,8 +1240,9 @@ void kill_screen(const char* lcd_msg) {
1215 1240
           LCDVIEW_CALL_NO_REDRAW
1216 1241
         #endif
1217 1242
       ;
1218
-      if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
1219
-        lcd_goto_screen(_lcd_level_bed_homing_done);
1243
+      if (no_reentrance) return;
1244
+      lcd_wait_for_homing();
1245
+      lcd_goto_screen(_lcd_level_bed_homing_done);
1220 1246
     }
1221 1247
 
1222 1248
     /**

+ 19
- 23
Marlin/ultralcd_impl_DOGM.h View File

@@ -656,34 +656,30 @@ static void lcd_implementation_status_screen() {
656 656
     u8g.setPrintPos((START_COL) * (DOG_CHAR_WIDTH), row_y2);
657 657
   }
658 658
 
659
-  #if ENABLED(LCD_INFO_MENU) || ENABLED(FILAMENT_CHANGE_FEATURE)
659
+  // Draw a static line of text in the same idiom as a menu item
660
+  static void lcd_implementation_drawmenu_static(const uint8_t row, const char* pstr, const bool center=true, const bool invert=false, const char* valstr=NULL) {
660 661
 
661
-    // Draw a static line of text in the same idiom as a menu item
662
-    static void lcd_implementation_drawmenu_static(const uint8_t row, const char* pstr, const bool center=true, const bool invert=false, const char* valstr=NULL) {
662
+    lcd_implementation_mark_as_selected(row, invert);
663 663
 
664
-      lcd_implementation_mark_as_selected(row, invert);
665
-
666
-      if (!PAGE_CONTAINS(row_y1, row_y2)) return;
664
+    if (!PAGE_CONTAINS(row_y1, row_y2)) return;
667 665
 
668
-      char c;
669
-      int8_t n = LCD_WIDTH - (START_COL);
666
+    char c;
667
+    int8_t n = LCD_WIDTH - (START_COL);
670 668
 
671
-      if (center && !valstr) {
672
-        int8_t pad = (LCD_WIDTH - lcd_strlen_P(pstr)) / 2;
673
-        while (--pad >= 0) { u8g.print(' '); n--; }
674
-      }
675
-      while (n > 0 && (c = pgm_read_byte(pstr))) {
676
-        n -= lcd_print_and_count(c);
677
-        pstr++;
678
-      }
679
-      if (valstr) while (n > 0 && (c = *valstr)) {
680
-        n -= lcd_print_and_count(c);
681
-        valstr++;
682
-      }
683
-      while (n-- > 0) u8g.print(' ');
669
+    if (center && !valstr) {
670
+      int8_t pad = (LCD_WIDTH - lcd_strlen_P(pstr)) / 2;
671
+      while (--pad >= 0) { u8g.print(' '); n--; }
684 672
     }
685
-
686
-  #endif // LCD_INFO_MENU || FILAMENT_CHANGE_FEATURE
673
+    while (n > 0 && (c = pgm_read_byte(pstr))) {
674
+      n -= lcd_print_and_count(c);
675
+      pstr++;
676
+    }
677
+    if (valstr) while (n > 0 && (c = *valstr)) {
678
+      n -= lcd_print_and_count(c);
679
+      valstr++;
680
+    }
681
+    while (n-- > 0) u8g.print(' ');
682
+  }
687 683
 
688 684
   // Draw a generic menu item
689 685
   static void lcd_implementation_drawmenu_generic(const bool isSelected, const uint8_t row, const char* pstr, const char pre_char, const char post_char) {

+ 18
- 22
Marlin/ultralcd_impl_HD44780.h View File

@@ -792,29 +792,25 @@ static void lcd_implementation_status_screen() {
792 792
 
793 793
 #if ENABLED(ULTIPANEL)
794 794
 
795
-  #if ENABLED(LCD_INFO_MENU) || ENABLED(FILAMENT_CHANGE_FEATURE)
796
-
797
-    static void lcd_implementation_drawmenu_static(const uint8_t row, const char* pstr, const bool center=true, const bool invert=false, const char *valstr=NULL) {
798
-      UNUSED(invert);
799
-      char c;
800
-      int8_t n = LCD_WIDTH;
801
-      lcd.setCursor(0, row);
802
-      if (center && !valstr) {
803
-        int8_t pad = (LCD_WIDTH - lcd_strlen_P(pstr)) / 2;
804
-        while (--pad >= 0) { lcd.print(' '); n--; }
805
-      }
806
-      while (n > 0 && (c = pgm_read_byte(pstr))) {
807
-        n -= charset_mapper(c);
808
-        pstr++;
809
-      }
810
-      if (valstr) while (n > 0 && (c = *valstr)) {
811
-        n -= charset_mapper(c);
812
-        valstr++;
813
-      }
814
-      while (n-- > 0) lcd.print(' ');
795
+  static void lcd_implementation_drawmenu_static(const uint8_t row, const char* pstr, const bool center=true, const bool invert=false, const char *valstr=NULL) {
796
+    UNUSED(invert);
797
+    char c;
798
+    int8_t n = LCD_WIDTH;
799
+    lcd.setCursor(0, row);
800
+    if (center && !valstr) {
801
+      int8_t pad = (LCD_WIDTH - lcd_strlen_P(pstr)) / 2;
802
+      while (--pad >= 0) { lcd.print(' '); n--; }
815 803
     }
816
-
817
-  #endif // LCD_INFO_MENU || FILAMENT_CHANGE_FEATURE
804
+    while (n > 0 && (c = pgm_read_byte(pstr))) {
805
+      n -= charset_mapper(c);
806
+      pstr++;
807
+    }
808
+    if (valstr) while (n > 0 && (c = *valstr)) {
809
+      n -= charset_mapper(c);
810
+      valstr++;
811
+    }
812
+    while (n-- > 0) lcd.print(' ');
813
+  }
818 814
 
819 815
   static void lcd_implementation_drawmenu_generic(const bool sel, const uint8_t row, const char* pstr, const char pre_char, const char post_char) {
820 816
     char c;

Loading…
Cancel
Save