Browse Source

Merge pull request #8966 from thinkyhead/bf2_better_no_reentry

[2.0.x] ultralcd.cpp: Better no_reentry, use in queuing G-code
Scott Lahteine 7 years ago
parent
commit
2b1e6829b3
No account linked to committer's email address

+ 1
- 1
Marlin/src/Marlin.cpp View File

346
 
346
 
347
   // Prevent steppers timing-out in the middle of M600
347
   // Prevent steppers timing-out in the middle of M600
348
   #if ENABLED(ADVANCED_PAUSE_FEATURE) && ENABLED(PAUSE_PARK_NO_STEPPER_TIMEOUT)
348
   #if ENABLED(ADVANCED_PAUSE_FEATURE) && ENABLED(PAUSE_PARK_NO_STEPPER_TIMEOUT)
349
-    #define MOVE_AWAY_TEST !move_away_flag
349
+    #define MOVE_AWAY_TEST !did_pause_print
350
   #else
350
   #else
351
     #define MOVE_AWAY_TEST true
351
     #define MOVE_AWAY_TEST true
352
   #endif
352
   #endif

+ 9
- 10
Marlin/src/feature/pause.cpp View File

54
 
54
 
55
 #if ENABLED(SDSUPPORT)
55
 #if ENABLED(SDSUPPORT)
56
   #include "../sd/cardreader.h"
56
   #include "../sd/cardreader.h"
57
-  static bool sd_print_paused = false;
58
 #endif
57
 #endif
59
 
58
 
60
 #if HAS_BUZZER
59
 #if HAS_BUZZER
107
 
106
 
108
 // public:
107
 // public:
109
 
108
 
110
-bool move_away_flag = false;
109
+uint8_t did_pause_print = 0;
111
 
110
 
112
 bool pause_print(const float &retract, const point_t &park_point, const float &unload_length/*=0*/,
111
 bool pause_print(const float &retract, const point_t &park_point, const float &unload_length/*=0*/,
113
                  const int8_t max_beep_count/*=0*/, const bool show_lcd/*=false*/
112
                  const int8_t max_beep_count/*=0*/, const bool show_lcd/*=false*/
114
 ) {
113
 ) {
115
-  if (move_away_flag) return false; // already paused
114
+  if (did_pause_print) return false; // already paused
116
 
115
 
117
   #ifdef ACTION_ON_PAUSE
116
   #ifdef ACTION_ON_PAUSE
118
     SERIAL_ECHOLNPGM("//action:" ACTION_ON_PAUSE);
117
     SERIAL_ECHOLNPGM("//action:" ACTION_ON_PAUSE);
132
   }
131
   }
133
 
132
 
134
   // Indicate that the printer is paused
133
   // Indicate that the printer is paused
135
-  move_away_flag = true;
134
+  ++did_pause_print;
136
 
135
 
137
   // Pause the print job and timer
136
   // Pause the print job and timer
138
   #if ENABLED(SDSUPPORT)
137
   #if ENABLED(SDSUPPORT)
139
     if (IS_SD_PRINTING) {
138
     if (IS_SD_PRINTING) {
140
       card.pauseSDPrint();
139
       card.pauseSDPrint();
141
-      sd_print_paused = true;
140
+      ++did_pause_print;
142
     }
141
     }
143
   #endif
142
   #endif
144
   print_job_timer.pause();
143
   print_job_timer.pause();
256
 void resume_print(const float &load_length/*=0*/, const float &initial_extrude_length/*=0*/, const int8_t max_beep_count/*=0*/) {
255
 void resume_print(const float &load_length/*=0*/, const float &initial_extrude_length/*=0*/, const int8_t max_beep_count/*=0*/) {
257
   bool nozzle_timed_out = false;
256
   bool nozzle_timed_out = false;
258
 
257
 
259
-  if (!move_away_flag) return;
258
+  if (!did_pause_print) return;
260
 
259
 
261
   // Re-enable the heaters if they timed out
260
   // Re-enable the heaters if they timed out
262
   HOTEND_LOOP() {
261
   HOTEND_LOOP() {
350
     SERIAL_ECHOLNPGM("//action:" ACTION_ON_RESUME);
349
     SERIAL_ECHOLNPGM("//action:" ACTION_ON_RESUME);
351
   #endif
350
   #endif
352
 
351
 
352
+  --did_pause_print;
353
+
353
   #if ENABLED(SDSUPPORT)
354
   #if ENABLED(SDSUPPORT)
354
-    if (sd_print_paused) {
355
+    if (did_pause_print) {
355
       card.startFileprint();
356
       card.startFileprint();
356
-      sd_print_paused = false;
357
+      --did_pause_print;
357
     }
358
     }
358
   #endif
359
   #endif
359
-
360
-  move_away_flag = false;
361
 }
360
 }
362
 
361
 
363
 #endif // ADVANCED_PAUSE_FEATURE || PARK_HEAD_ON_PAUSE
362
 #endif // ADVANCED_PAUSE_FEATURE || PARK_HEAD_ON_PAUSE

+ 1
- 1
Marlin/src/feature/pause.h View File

30
 
30
 
31
 #include "../libs/nozzle.h"
31
 #include "../libs/nozzle.h"
32
 
32
 
33
-extern bool move_away_flag;
33
+extern bool did_pause_print;
34
 
34
 
35
 bool pause_print(const float &retract, const point_t &park_point, const float &unload_length=0,
35
 bool pause_print(const float &retract, const point_t &park_point, const float &unload_length=0,
36
                  const int8_t max_beep_count=0, const bool show_lcd=false
36
                  const int8_t max_beep_count=0, const bool show_lcd=false

+ 2
- 2
Marlin/src/gcode/calibrate/G33.cpp View File

491
 
491
 
492
   // Report settings
492
   // Report settings
493
 
493
 
494
-  const char *checkingac = PSTR("Checking... AC"); // TODO: Make translatable string
494
+  PGM_P checkingac = PSTR("Checking... AC"); // TODO: Make translatable string
495
   serialprintPGM(checkingac);
495
   serialprintPGM(checkingac);
496
   if (verbose_level == 0) SERIAL_PROTOCOLPGM(" (DRY-RUN)");
496
   if (verbose_level == 0) SERIAL_PROTOCOLPGM(" (DRY-RUN)");
497
   SERIAL_EOL();
497
   SERIAL_EOL();
673
       }
673
       }
674
     }
674
     }
675
     else {                                                       // dry run
675
     else {                                                       // dry run
676
-      const char *enddryrun = PSTR("End DRY-RUN");
676
+      PGM_P enddryrun = PSTR("End DRY-RUN");
677
       serialprintPGM(enddryrun);
677
       serialprintPGM(enddryrun);
678
       SERIAL_PROTOCOL_SP(35);
678
       SERIAL_PROTOCOL_SP(35);
679
       SERIAL_PROTOCOLPGM("std dev:");
679
       SERIAL_PROTOCOLPGM("std dev:");

+ 40
- 38
Marlin/src/lcd/ultralcd.cpp View File

164
     extern bool powersupply_on;
164
     extern bool powersupply_on;
165
   #endif
165
   #endif
166
 
166
 
167
+  bool no_reentry = false;
168
+
167
   ////////////////////////////////////////////
169
   ////////////////////////////////////////////
168
   ///////////////// Menu Tree ////////////////
170
   ///////////////// Menu Tree ////////////////
169
   ////////////////////////////////////////////
171
   ////////////////////////////////////////////
572
   // done. ** This blocks the command queue! **
574
   // done. ** This blocks the command queue! **
573
   //
575
   //
574
   void _lcd_synchronize() {
576
   void _lcd_synchronize() {
575
-    static bool no_reentry = false;
576
     if (lcdDrawUpdate) lcd_implementation_drawmenu_static(LCD_HEIGHT >= 4 ? 1 : 0, sync_message);
577
     if (lcdDrawUpdate) lcd_implementation_drawmenu_static(LCD_HEIGHT >= 4 ? 1 : 0, sync_message);
577
     if (no_reentry) return;
578
     if (no_reentry) return;
578
     // Make this the current handler till all moves are done
579
     // Make this the current handler till all moves are done
579
     no_reentry = true;
580
     no_reentry = true;
580
     const screenFunc_t old_screen = currentScreen;
581
     const screenFunc_t old_screen = currentScreen;
581
     lcd_goto_screen(_lcd_synchronize);
582
     lcd_goto_screen(_lcd_synchronize);
582
-    stepper.synchronize();
583
+    stepper.synchronize(); // idle() is called until moves complete
583
     no_reentry = false;
584
     no_reentry = false;
584
     lcd_goto_screen(old_screen);
585
     lcd_goto_screen(old_screen);
585
   }
586
   }
1741
     lcd_return_to_status();
1742
     lcd_return_to_status();
1742
   }
1743
   }
1743
 
1744
 
1745
+  #if ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(PID_AUTOTUNE_MENU) || ENABLED(ADVANCED_PAUSE_FEATURE)
1746
+
1747
+    /**
1748
+     * If the queue is full, the command will fail, so we have to loop
1749
+     * with idle() to make sure the command has been enqueued.
1750
+     */
1751
+    void lcd_enqueue_command_sram(char * const cmd) {
1752
+      no_reentry = true;
1753
+      while (enqueue_and_echo_command(cmd)) idle();
1754
+      no_reentry = false;
1755
+    }
1756
+
1757
+  #endif
1758
+
1744
   #if ENABLED(SDSUPPORT) && ENABLED(MENU_ADDAUTOSTART)
1759
   #if ENABLED(SDSUPPORT) && ENABLED(MENU_ADDAUTOSTART)
1745
 
1760
 
1746
     void lcd_autostart_sd() {
1761
     void lcd_autostart_sd() {
1917
      * Step 5: Initiate a move to the next point
1932
      * Step 5: Initiate a move to the next point
1918
      */
1933
      */
1919
     void _lcd_level_goto_next_point() {
1934
     void _lcd_level_goto_next_point() {
1920
-      // Set the menu to display ahead of blocking call
1921
       lcd_goto_screen(_lcd_level_bed_moving);
1935
       lcd_goto_screen(_lcd_level_bed_moving);
1922
 
1936
 
1923
       // G29 Records Z, moves, and signals when it pauses
1937
       // G29 Records Z, moves, and signals when it pauses
2065
       enqueue_and_echo_commands_P(PSTR("G28"));
2079
       enqueue_and_echo_commands_P(PSTR("G28"));
2066
       #if HAS_TEMP_BED
2080
       #if HAS_TEMP_BED
2067
         sprintf_P(UBL_LCD_GCODE, PSTR("M190 S%i"), custom_bed_temp);
2081
         sprintf_P(UBL_LCD_GCODE, PSTR("M190 S%i"), custom_bed_temp);
2068
-        enqueue_and_echo_command(UBL_LCD_GCODE);
2082
+        lcd_enqueue_command_sram(UBL_LCD_GCODE);
2069
       #endif
2083
       #endif
2070
       sprintf_P(UBL_LCD_GCODE, PSTR("M109 S%i"), custom_hotend_temp);
2084
       sprintf_P(UBL_LCD_GCODE, PSTR("M109 S%i"), custom_hotend_temp);
2071
-      enqueue_and_echo_command(UBL_LCD_GCODE);
2085
+      lcd_enqueue_command_sram(UBL_LCD_GCODE);
2072
       enqueue_and_echo_commands_P(PSTR("G29 P1"));
2086
       enqueue_and_echo_commands_P(PSTR("G29 P1"));
2073
     }
2087
     }
2074
 
2088
 
2099
       const int ind = ubl_height_amount > 0 ? 9 : 10;
2113
       const int ind = ubl_height_amount > 0 ? 9 : 10;
2100
       strcpy_P(UBL_LCD_GCODE, PSTR("G29 P6 C -"));
2114
       strcpy_P(UBL_LCD_GCODE, PSTR("G29 P6 C -"));
2101
       sprintf_P(&UBL_LCD_GCODE[ind], PSTR(".%i"), abs(ubl_height_amount));
2115
       sprintf_P(&UBL_LCD_GCODE[ind], PSTR(".%i"), abs(ubl_height_amount));
2102
-      enqueue_and_echo_command(UBL_LCD_GCODE);
2116
+      lcd_enqueue_command_sram(UBL_LCD_GCODE);
2103
     }
2117
     }
2104
 
2118
 
2105
     /**
2119
     /**
2149
           0
2163
           0
2150
         #endif
2164
         #endif
2151
       ;
2165
       ;
2152
-      sprintf_P(UBL_LCD_GCODE, PSTR("G28\nG26 C B%i H%i P"), temp, custom_hotend_temp);
2153
-      enqueue_and_echo_command(UBL_LCD_GCODE);
2166
+      sprintf_P(UBL_LCD_GCODE, PSTR("G26 C B%i H%i P"), temp, custom_hotend_temp);
2167
+      lcd_enqueue_command_sram("G28");
2168
+      lcd_enqueue_command_sram(UBL_LCD_GCODE);
2154
     }
2169
     }
2155
 
2170
 
2156
     /**
2171
     /**
2183
     void _lcd_ubl_grid_level_cmd() {
2198
     void _lcd_ubl_grid_level_cmd() {
2184
       char UBL_LCD_GCODE[10];
2199
       char UBL_LCD_GCODE[10];
2185
       sprintf_P(UBL_LCD_GCODE, PSTR("G29 J%i"), side_points);
2200
       sprintf_P(UBL_LCD_GCODE, PSTR("G29 J%i"), side_points);
2186
-      enqueue_and_echo_command(UBL_LCD_GCODE);
2201
+      lcd_enqueue_command_sram(UBL_LCD_GCODE);
2187
     }
2202
     }
2188
 
2203
 
2189
     /**
2204
     /**
2224
     void _lcd_ubl_fillin_amount_cmd() {
2239
     void _lcd_ubl_fillin_amount_cmd() {
2225
       char UBL_LCD_GCODE[16];
2240
       char UBL_LCD_GCODE[16];
2226
       sprintf_P(UBL_LCD_GCODE, PSTR("G29 P3 R C.%i"), ubl_fillin_amount);
2241
       sprintf_P(UBL_LCD_GCODE, PSTR("G29 P3 R C.%i"), ubl_fillin_amount);
2227
-      enqueue_and_echo_command(UBL_LCD_GCODE);
2228
-    }
2229
-
2230
-    /**
2231
-     * UBL Smart Fill-in Command
2232
-     */
2233
-    void _lcd_ubl_smart_fillin_cmd() {
2234
-      char UBL_LCD_GCODE[12];
2235
-      sprintf_P(UBL_LCD_GCODE, PSTR("G29 P3 T0"));
2236
-      enqueue_and_echo_command(UBL_LCD_GCODE);
2242
+      lcd_enqueue_command_sram(UBL_LCD_GCODE);
2237
     }
2243
     }
2238
 
2244
 
2239
     /**
2245
     /**
2250
       START_MENU();
2256
       START_MENU();
2251
       MENU_BACK(MSG_UBL_BUILD_MESH_MENU);
2257
       MENU_BACK(MSG_UBL_BUILD_MESH_MENU);
2252
       MENU_ITEM_EDIT_CALLBACK(int3, MSG_UBL_FILLIN_AMOUNT, &ubl_fillin_amount, 0, 9, _lcd_ubl_fillin_amount_cmd);
2258
       MENU_ITEM_EDIT_CALLBACK(int3, MSG_UBL_FILLIN_AMOUNT, &ubl_fillin_amount, 0, 9, _lcd_ubl_fillin_amount_cmd);
2253
-      MENU_ITEM(function, MSG_UBL_SMART_FILLIN, _lcd_ubl_smart_fillin_cmd);
2259
+      MENU_ITEM(gcode, MSG_UBL_SMART_FILLIN, PSTR("G29 P3 T0"));
2254
       MENU_ITEM(gcode, MSG_UBL_MANUAL_FILLIN, PSTR("G29 P2 B T0"));
2260
       MENU_ITEM(gcode, MSG_UBL_MANUAL_FILLIN, PSTR("G29 P2 B T0"));
2255
       MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
2261
       MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
2256
       END_MENU();
2262
       END_MENU();
2323
      * UBL Load Mesh Command
2329
      * UBL Load Mesh Command
2324
      */
2330
      */
2325
     void _lcd_ubl_load_mesh_cmd() {
2331
     void _lcd_ubl_load_mesh_cmd() {
2326
-      char UBL_LCD_GCODE[25];
2332
+      char UBL_LCD_GCODE[10];
2327
       sprintf_P(UBL_LCD_GCODE, PSTR("G29 L%i"), ubl_storage_slot);
2333
       sprintf_P(UBL_LCD_GCODE, PSTR("G29 L%i"), ubl_storage_slot);
2328
-      enqueue_and_echo_command(UBL_LCD_GCODE);
2329
-      sprintf_P(UBL_LCD_GCODE, PSTR("M117 " MSG_MESH_LOADED "."), ubl_storage_slot);
2330
-      enqueue_and_echo_command(UBL_LCD_GCODE);
2334
+      lcd_enqueue_command_sram(UBL_LCD_GCODE);
2335
+      enqueue_and_echo_commands_P(PSTR("M117 " MSG_MESH_LOADED "."));
2331
     }
2336
     }
2332
 
2337
 
2333
     /**
2338
     /**
2334
      * UBL Save Mesh Command
2339
      * UBL Save Mesh Command
2335
      */
2340
      */
2336
     void _lcd_ubl_save_mesh_cmd() {
2341
     void _lcd_ubl_save_mesh_cmd() {
2337
-      char UBL_LCD_GCODE[25];
2342
+      char UBL_LCD_GCODE[10];
2338
       sprintf_P(UBL_LCD_GCODE, PSTR("G29 S%i"), ubl_storage_slot);
2343
       sprintf_P(UBL_LCD_GCODE, PSTR("G29 S%i"), ubl_storage_slot);
2339
-      enqueue_and_echo_command(UBL_LCD_GCODE);
2340
-      sprintf_P(UBL_LCD_GCODE, PSTR("M117 " MSG_MESH_SAVED "."), ubl_storage_slot);
2341
-      enqueue_and_echo_command(UBL_LCD_GCODE);
2344
+      lcd_enqueue_command_sram(UBL_LCD_GCODE);
2345
+      enqueue_and_echo_commands_P(PSTR("M117 " MSG_MESH_SAVED "."));
2342
     }
2346
     }
2343
 
2347
 
2344
     /**
2348
     /**
2384
      * UBL LCD "radar" map point editing
2388
      * UBL LCD "radar" map point editing
2385
      */
2389
      */
2386
     void _lcd_ubl_map_lcd_edit_cmd() {
2390
     void _lcd_ubl_map_lcd_edit_cmd() {
2387
-      char ubl_lcd_gcode [50], str[10], str2[10];
2388
-
2391
+      char UBL_LCD_GCODE[50], str[10], str2[10];
2389
       dtostrf(pgm_read_float(&ubl._mesh_index_to_xpos[x_plot]), 0, 2, str);
2392
       dtostrf(pgm_read_float(&ubl._mesh_index_to_xpos[x_plot]), 0, 2, str);
2390
       dtostrf(pgm_read_float(&ubl._mesh_index_to_ypos[y_plot]), 0, 2, str2);
2393
       dtostrf(pgm_read_float(&ubl._mesh_index_to_ypos[y_plot]), 0, 2, str2);
2391
-      snprintf_P(ubl_lcd_gcode, sizeof(ubl_lcd_gcode), PSTR("G29 P4 X%s Y%s R%i"), str, str2, n_edit_pts);
2392
-      enqueue_and_echo_command(ubl_lcd_gcode);
2394
+      snprintf_P(UBL_LCD_GCODE, sizeof(UBL_LCD_GCODE), PSTR("G29 P4 X%s Y%s R%i"), str, str2, n_edit_pts);
2395
+      lcd_enqueue_command_sram(UBL_LCD_GCODE);
2393
     }
2396
     }
2394
 
2397
 
2395
     /**
2398
     /**
2537
       START_MENU();
2540
       START_MENU();
2538
       MENU_BACK(MSG_UBL_LEVEL_BED);
2541
       MENU_BACK(MSG_UBL_LEVEL_BED);
2539
       MENU_ITEM(gcode, "1 " MSG_UBL_BUILD_COLD_MESH, PSTR("G28\nG29 P1"));
2542
       MENU_ITEM(gcode, "1 " MSG_UBL_BUILD_COLD_MESH, PSTR("G28\nG29 P1"));
2540
-      MENU_ITEM(function, "2 " MSG_UBL_SMART_FILLIN, _lcd_ubl_smart_fillin_cmd);
2543
+      MENU_ITEM(gcode, "2 " MSG_UBL_SMART_FILLIN, PSTR("G29 P3 T0"));
2541
       MENU_ITEM(submenu, "3 " MSG_UBL_VALIDATE_MESH_MENU, _lcd_ubl_validate_mesh);
2544
       MENU_ITEM(submenu, "3 " MSG_UBL_VALIDATE_MESH_MENU, _lcd_ubl_validate_mesh);
2542
       MENU_ITEM(gcode, "4 " MSG_UBL_FINE_TUNE_ALL, PSTR("G29 P4 R999 T"));
2545
       MENU_ITEM(gcode, "4 " MSG_UBL_FINE_TUNE_ALL, PSTR("G29 P4 R999 T"));
2543
       MENU_ITEM(submenu, "5 " MSG_UBL_VALIDATE_MESH_MENU, _lcd_ubl_validate_mesh);
2546
       MENU_ITEM(submenu, "5 " MSG_UBL_VALIDATE_MESH_MENU, _lcd_ubl_validate_mesh);
2979
       #endif
2982
       #endif
2980
 
2983
 
2981
       manual_move_to_current(axis);
2984
       manual_move_to_current(axis);
2982
-
2983
       lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
2985
       lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
2984
     }
2986
     }
2985
     encoderPosition = 0;
2987
     encoderPosition = 0;
2986
-    if (lcdDrawUpdate && !processing_manual_move) {
2988
+    if (lcdDrawUpdate) {
2987
       const float pos = current_position[axis]
2989
       const float pos = current_position[axis]
2988
         #if IS_KINEMATIC
2990
         #if IS_KINEMATIC
2989
           + manual_move_offset
2991
           + manual_move_offset
3019
       }
3021
       }
3020
       encoderPosition = 0;
3022
       encoderPosition = 0;
3021
     }
3023
     }
3022
-    if (lcdDrawUpdate && !processing_manual_move) {
3024
+    if (lcdDrawUpdate) {
3023
       PGM_P pos_label;
3025
       PGM_P pos_label;
3024
       #if E_MANUAL == 1
3026
       #if E_MANUAL == 1
3025
         pos_label = PSTR(MSG_MOVE_E);
3027
         pos_label = PSTR(MSG_MOVE_E);
3283
           autotune_temp[e]
3285
           autotune_temp[e]
3284
         #endif
3286
         #endif
3285
       );
3287
       );
3286
-      enqueue_and_echo_command(cmd);
3288
+      lcd_enqueue_command_sram(cmd);
3287
     }
3289
     }
3288
 
3290
 
3289
   #endif // PID_AUTOTUNE_MENU
3291
   #endif // PID_AUTOTUNE_MENU
4719
     if (UBL_CONDITION && LCD_CLICKED) {
4721
     if (UBL_CONDITION && LCD_CLICKED) {
4720
       if (!wait_for_unclick) {           // If not waiting for a debounce release:
4722
       if (!wait_for_unclick) {           // If not waiting for a debounce release:
4721
         wait_for_unclick = true;         //  Set debounce flag to ignore continous clicks
4723
         wait_for_unclick = true;         //  Set debounce flag to ignore continous clicks
4722
-        lcd_clicked = !wait_for_user;    //  Keep the click if not waiting for a user-click
4724
+        lcd_clicked = !wait_for_user && !no_reentry; // Flag the click if allowed
4723
         wait_for_user = false;           //  Any click clears wait for user
4725
         wait_for_user = false;           //  Any click clears wait for user
4724
         lcd_quick_feedback();            //  Always make a click sound
4726
         lcd_quick_feedback();            //  Always make a click sound
4725
       }
4727
       }

Loading…
Cancel
Save