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
 #ifndef MSG_LEVEL_BED
138
 #ifndef MSG_LEVEL_BED
139
   #define MSG_LEVEL_BED                       "Level bed"
139
   #define MSG_LEVEL_BED                       "Level bed"
140
 #endif
140
 #endif
141
+#ifndef MSG_MOVING
142
+  #define MSG_MOVING                          "Moving..."
143
+#endif
141
 #ifndef MSG_MOVE_X
144
 #ifndef MSG_MOVE_X
142
   #define MSG_MOVE_X                          "Move X"
145
   #define MSG_MOVE_X                          "Move X"
143
 #endif
146
 #endif

+ 31
- 5
Marlin/ultralcd.cpp View File

390
   bool screen_changed;
390
   bool screen_changed;
391
 
391
 
392
   // LCD and menu clicks
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
   // Variables used when editing values.
395
   // Variables used when editing values.
396
   const char* editLabel;
396
   const char* editLabel;
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
   void lcd_return_to_status() { lcd_goto_screen(lcd_status_screen); }
446
   void lcd_return_to_status() { lcd_goto_screen(lcd_status_screen); }
426
 
447
 
427
   void lcd_save_previous_screen() {
448
   void lcd_save_previous_screen() {
1063
     // Note: During Manual Bed Leveling the homed Z position is MESH_HOME_SEARCH_Z
1084
     // Note: During Manual Bed Leveling the homed Z position is MESH_HOME_SEARCH_Z
1064
     // Z position will be restored with the final action, a G28
1085
     // Z position will be restored with the final action, a G28
1065
     inline void _mbl_goto_xy(float x, float y) {
1086
     inline void _mbl_goto_xy(float x, float y) {
1087
+      if (no_reentrance) return;
1066
       current_position[Z_AXIS] = LOGICAL_Z_POSITION(MESH_HOME_SEARCH_Z + Z_HOMING_HEIGHT);
1088
       current_position[Z_AXIS] = LOGICAL_Z_POSITION(MESH_HOME_SEARCH_Z + Z_HOMING_HEIGHT);
1067
       line_to_current(Z_AXIS);
1089
       line_to_current(Z_AXIS);
1068
       current_position[X_AXIS] = LOGICAL_X_POSITION(x);
1090
       current_position[X_AXIS] = LOGICAL_X_POSITION(x);
1072
         current_position[Z_AXIS] = LOGICAL_Z_POSITION(MESH_HOME_SEARCH_Z);
1094
         current_position[Z_AXIS] = LOGICAL_Z_POSITION(MESH_HOME_SEARCH_Z);
1073
         line_to_current(Z_AXIS);
1095
         line_to_current(Z_AXIS);
1074
       #endif
1096
       #endif
1075
-      stepper.synchronize();
1097
+      lcd_synchronize();
1076
     }
1098
     }
1077
 
1099
 
1078
     void _lcd_level_goto_next_point();
1100
     void _lcd_level_goto_next_point();
1094
     void _lcd_level_bed_get_z() {
1116
     void _lcd_level_bed_get_z() {
1095
       ENCODER_DIRECTION_NORMAL();
1117
       ENCODER_DIRECTION_NORMAL();
1096
 
1118
 
1119
+      if (no_reentrance) goto KeepDrawing;
1120
+
1097
       // Encoder wheel adjusts the Z position
1121
       // Encoder wheel adjusts the Z position
1098
       if (encoderPosition) {
1122
       if (encoderPosition) {
1099
         refresh_cmd_timeout();
1123
         refresh_cmd_timeout();
1121
 
1145
 
1122
             current_position[Z_AXIS] = MESH_HOME_SEARCH_Z + Z_HOMING_HEIGHT;
1146
             current_position[Z_AXIS] = MESH_HOME_SEARCH_Z + Z_HOMING_HEIGHT;
1123
             line_to_current(Z_AXIS);
1147
             line_to_current(Z_AXIS);
1124
-            stepper.synchronize();
1148
+            lcd_synchronize();
1125
 
1149
 
1126
             mbl.set_has_mesh(true);
1150
             mbl.set_has_mesh(true);
1127
             enqueue_and_echo_commands_P(PSTR("G28"));
1151
             enqueue_and_echo_commands_P(PSTR("G28"));
1141
         debounce_click = false;
1165
         debounce_click = false;
1142
       }
1166
       }
1143
 
1167
 
1168
+KeepDrawing:
1144
       // Update on first display, then only on updates to Z position
1169
       // Update on first display, then only on updates to Z position
1145
       // Show message above on clicks instead
1170
       // Show message above on clicks instead
1146
       if (lcdDrawUpdate) {
1171
       if (lcdDrawUpdate) {
1215
           LCDVIEW_CALL_NO_REDRAW
1240
           LCDVIEW_CALL_NO_REDRAW
1216
         #endif
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
     u8g.setPrintPos((START_COL) * (DOG_CHAR_WIDTH), row_y2);
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
   // Draw a generic menu item
684
   // Draw a generic menu item
689
   static void lcd_implementation_drawmenu_generic(const bool isSelected, const uint8_t row, const char* pstr, const char pre_char, const char post_char) {
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
 
792
 
793
 #if ENABLED(ULTIPANEL)
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
   static void lcd_implementation_drawmenu_generic(const bool sel, const uint8_t row, const char* pstr, const char pre_char, const char post_char) {
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
     char c;
816
     char c;

Loading…
Cancel
Save