Преглед изворни кода

Make KEEPALIVE_STATE a scoped auto-restore (#14446)

Scott Lahteine пре 6 година
родитељ
комит
d16954dc88
No account linked to committer's email address

+ 3
- 20
Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp Прегледај датотеку

@@ -768,8 +768,7 @@
768 768
             ui.wait_for_release();
769 769
             ui.quick_feedback();
770 770
             ui.release();
771
-            restore_ubl_active_state_and_leave();
772
-            return;
771
+            return restore_ubl_active_state_and_leave();
773 772
           }
774 773
         #endif
775 774
 
@@ -844,7 +843,6 @@
844 843
     float unified_bed_leveling::measure_point_with_encoder() {
845 844
       KEEPALIVE_STATE(PAUSED_FOR_USER);
846 845
       move_z_with_encoder(0.01f);
847
-      KEEPALIVE_STATE(IN_HANDLER);
848 846
       return current_position[Z_AXIS];
849 847
     }
850 848
 
@@ -889,15 +887,6 @@
889 887
       return thickness;
890 888
     }
891 889
 
892
-    void abort_manual_probe_remaining_mesh() {
893
-      SERIAL_ECHOLNPGM("\nMesh only partially populated.");
894
-      do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
895
-      ui.release();
896
-      KEEPALIVE_STATE(IN_HANDLER);
897
-      ui.quick_feedback();
898
-      ubl.restore_ubl_active_state_and_leave();
899
-    }
900
-
901 890
     void unified_bed_leveling::manually_probe_remaining_mesh(const float &rx, const float &ry, const float &z_clearance, const float &thick, const bool do_ubl_mesh_map) {
902 891
 
903 892
       ui.capture();
@@ -939,9 +928,7 @@
939 928
           SERIAL_ECHOLNPGM("\nMesh only partially populated.");
940 929
           do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
941 930
           ui.release();
942
-          KEEPALIVE_STATE(IN_HANDLER);
943
-          restore_ubl_active_state_and_leave();
944
-          return;
931
+          return restore_ubl_active_state_and_leave();
945 932
         }
946 933
 
947 934
         z_values[location.x_index][location.y_index] = current_position[Z_AXIS] - thick;
@@ -957,7 +944,6 @@
957 944
       if (do_ubl_mesh_map) display_map(g29_map_type);  // show user where we're probing
958 945
 
959 946
       restore_ubl_active_state_and_leave();
960
-      KEEPALIVE_STATE(IN_HANDLER);
961 947
       do_blocking_move_to(rx, ry, Z_CLEARANCE_DEPLOY_PROBE);
962 948
     }
963 949
 
@@ -1046,7 +1032,7 @@
1046 1032
 
1047 1033
         if (!lcd_map_control) ui.return_to_status();                // Just editing a single point? Return to status
1048 1034
 
1049
-        if (click_and_hold(abort_fine_tune)) goto FINE_TUNE_EXIT;   // If the click is held down, abort editing
1035
+        if (click_and_hold(abort_fine_tune)) break;                 // Button held down? Abort editing
1050 1036
 
1051 1037
         z_values[location.x_index][location.y_index] = new_z;       // Save the updated Z value
1052 1038
         #if ENABLED(EXTENSIBLE_UI)
@@ -1058,10 +1044,7 @@
1058 1044
 
1059 1045
       } while (location.x_index >= 0 && --g29_repetition_cnt > 0);
1060 1046
 
1061
-      FINE_TUNE_EXIT:
1062
-
1063 1047
       ui.release();
1064
-      KEEPALIVE_STATE(IN_HANDLER);
1065 1048
 
1066 1049
       if (do_ubl_mesh_map) display_map(g29_map_type);
1067 1050
       restore_ubl_active_state_and_leave();

+ 0
- 3
Marlin/src/feature/pause.cpp Прегледај датотеку

@@ -189,7 +189,6 @@ bool load_filament(const float &slow_load_length/*=0*/, const float &fast_load_l
189 189
       #endif
190 190
       idle(true);
191 191
     }
192
-    KEEPALIVE_STATE(IN_HANDLER);
193 192
   }
194 193
 
195 194
   #if HAS_LCD_MENU
@@ -278,7 +277,6 @@ bool load_filament(const float &slow_load_length/*=0*/, const float &fast_load_l
278 277
           wait_for_user = false;
279 278
           lcd_pause_show_message(PAUSE_MESSAGE_OPTION);
280 279
           while (pause_menu_response == PAUSE_RESPONSE_WAIT_FOR) idle(true);
281
-          KEEPALIVE_STATE(IN_HANDLER);
282 280
         }
283 281
       #endif
284 282
 
@@ -580,7 +578,6 @@ void wait_for_confirmation(const bool is_reload/*=false*/, const int8_t max_beep
580 578
     extruder_duplication_enabled = saved_ext_dup_mode;
581 579
     stepper.set_directions();
582 580
   #endif
583
-  KEEPALIVE_STATE(IN_HANDLER);
584 581
 }
585 582
 
586 583
 /**

+ 8
- 43
Marlin/src/feature/prusa_MMU2/mmu2.cpp Прегледај датотеку

@@ -47,8 +47,8 @@ MMU2 mmu2;
47 47
 
48 48
 #define MMU_TODELAY 100
49 49
 #define MMU_TIMEOUT 10
50
-#define MMU_CMD_TIMEOUT 60000ul //5min timeout for mmu commands (except P0)
51
-#define MMU_P0_TIMEOUT 3000ul //timeout for P0 command: 3seconds
50
+#define MMU_CMD_TIMEOUT 60000ul // 5min timeout for mmu commands (except P0)
51
+#define MMU_P0_TIMEOUT 3000ul   // Timeout for P0 command: 3seconds
52 52
 
53 53
 #define MMU_CMD_NONE 0
54 54
 #define MMU_CMD_T0   0x10
@@ -327,7 +327,6 @@ void MMU2::mmu_loop() {
327 327
   }
328 328
 }
329 329
 
330
-
331 330
 /**
332 331
  * Check if MMU was started
333 332
  */
@@ -340,7 +339,6 @@ bool MMU2::rx_start() {
340 339
   return false;
341 340
 }
342 341
 
343
-
344 342
 /**
345 343
  * Check if the data received ends with the given string.
346 344
  */
@@ -373,7 +371,6 @@ bool MMU2::rx_str_P(const char* str) {
373 371
   return true;
374 372
 }
375 373
 
376
-
377 374
 /**
378 375
  * Transfer data to MMU, no argument
379 376
  */
@@ -385,7 +382,6 @@ void MMU2::tx_str_P(const char* str) {
385 382
   last_request = millis();
386 383
 }
387 384
 
388
-
389 385
 /**
390 386
  * Transfer data to MMU, single argument
391 387
  */
@@ -397,7 +393,6 @@ void MMU2::tx_printf_P(const char* format, int argument = -1) {
397 393
   last_request = millis();
398 394
 }
399 395
 
400
-
401 396
 /**
402 397
  * Transfer data to MMU, two arguments
403 398
  */
@@ -409,7 +404,6 @@ void MMU2::tx_printf_P(const char* format, int argument1, int argument2) {
409 404
   last_request = millis();
410 405
 }
411 406
 
412
-
413 407
 /**
414 408
  * Empty the rx buffer
415 409
  */
@@ -418,7 +412,6 @@ void MMU2::clear_rx_buffer() {
418 412
   rx_buffer[0] = '\0';
419 413
 }
420 414
 
421
-
422 415
 /**
423 416
  * Check if we received 'ok' from MMU
424 417
  */
@@ -430,7 +423,6 @@ bool MMU2::rx_ok() {
430 423
   return false;
431 424
 }
432 425
 
433
-
434 426
 /**
435 427
  * Check if MMU has compatible firmware
436 428
  */
@@ -443,7 +435,6 @@ void MMU2::check_version() {
443 435
   }
444 436
 }
445 437
 
446
-
447 438
 /**
448 439
  * Handle tool change
449 440
  */
@@ -455,14 +446,12 @@ void MMU2::tool_change(uint8_t index) {
455 446
 
456 447
   if (index != extruder) {
457 448
 
458
-    KEEPALIVE_STATE(IN_HANDLER);
459 449
     disable_E0();
460 450
     ui.status_printf_P(0, PSTR(MSG_MMU2_LOADING_FILAMENT), int(index + 1));
461 451
 
462 452
     command(MMU_CMD_T0 + index);
463 453
 
464 454
     manage_response(true, true);
465
-    KEEPALIVE_STATE(IN_HANDLER);
466 455
 
467 456
     command(MMU_CMD_C0);
468 457
     extruder = index; //filament change is finished
@@ -474,13 +463,11 @@ void MMU2::tool_change(uint8_t index) {
474 463
     SERIAL_ECHOLNPAIR(MSG_ACTIVE_EXTRUDER, int(extruder));
475 464
 
476 465
     ui.reset_status();
477
-    KEEPALIVE_STATE(NOT_BUSY);
478 466
   }
479 467
 
480 468
   set_runout_valid(true);
481 469
 }
482 470
 
483
-
484 471
 /**
485 472
  *
486 473
  * Handle special T?/Tx/Tc commands
@@ -497,7 +484,6 @@ void MMU2::tool_change(const char* special) {
497 484
   #if ENABLED(MMU2_MENUS)
498 485
 
499 486
     set_runout_valid(false);
500
-    KEEPALIVE_STATE(IN_HANDLER);
501 487
 
502 488
     switch (*special) {
503 489
       case '?': {
@@ -526,14 +512,11 @@ void MMU2::tool_change(const char* special) {
526 512
       } break;
527 513
     }
528 514
 
529
-    KEEPALIVE_STATE(NOT_BUSY);
530
-
531 515
     set_runout_valid(true);
532 516
 
533 517
   #endif
534 518
 }
535 519
 
536
-
537 520
 /**
538 521
  * Set next command
539 522
  */
@@ -543,7 +526,6 @@ void MMU2::command(const uint8_t mmu_cmd) {
543 526
   ready = false;
544 527
 }
545 528
 
546
-
547 529
 /**
548 530
  * Wait for response from MMU
549 531
  */
@@ -561,11 +543,10 @@ bool MMU2::get_response(void) {
561 543
   return ret;
562 544
 }
563 545
 
564
-
565 546
 /**
566 547
  * Wait for response and deal with timeout if nexcessary
567 548
  */
568
-void MMU2::manage_response(bool move_axes, bool turn_off_nozzle) {
549
+void MMU2::manage_response(const bool move_axes, const bool turn_off_nozzle) {
569 550
 
570 551
   bool response = false;
571 552
   mmu_print_saved = false;
@@ -573,12 +554,14 @@ void MMU2::manage_response(bool move_axes, bool turn_off_nozzle) {
573 554
   float resume_position[XYZE];
574 555
   int16_t resume_hotend_temp;
575 556
 
557
+  KEEPALIVE_STATE(PAUSED_FOR_USER);
558
+
576 559
   while (!response) {
577 560
 
578
-    response = get_response(); //wait for "ok" from mmu
561
+    response = get_response(); // wait for "ok" from mmu
579 562
 
580
-    if (!response) { //no "ok" was received in reserved time frame, user will fix the issue on mmu unit
581
-      if (!mmu_print_saved) { //first occurence, we are saving current position, park print head in certain position and disable nozzle heater
563
+    if (!response) {          // No "ok" was received in reserved time frame, user will fix the issue on mmu unit
564
+      if (!mmu_print_saved) { // First occurrence. Save current position, park print head, disable nozzle heater.
582 565
 
583 566
         planner.synchronize();
584 567
 
@@ -600,13 +583,10 @@ void MMU2::manage_response(bool move_axes, bool turn_off_nozzle) {
600 583
         BUZZ(100, 659);
601 584
         BUZZ(300, 440);
602 585
         BUZZ(100, 659);
603
-
604
-        KEEPALIVE_STATE(PAUSED_FOR_USER);
605 586
       }
606 587
     }
607 588
     else if (mmu_print_saved) {
608 589
       SERIAL_ECHOLNPGM("MMU starts responding\n");
609
-      KEEPALIVE_STATE(IN_HANDLER);
610 590
 
611 591
       if (turn_off_nozzle && resume_hotend_temp) {
612 592
         thermalManager.setTargetHotend(resume_hotend_temp, active_extruder);
@@ -639,14 +619,10 @@ void MMU2::manage_response(bool move_axes, bool turn_off_nozzle) {
639 619
 void MMU2::set_filament_type(uint8_t index, uint8_t filamentType) {
640 620
   if (!enabled) return;
641 621
 
642
-  KEEPALIVE_STATE(IN_HANDLER);
643
-
644 622
   cmd_arg = filamentType;
645 623
   command(MMU_CMD_F0 + index);
646 624
 
647 625
   manage_response(true, true);
648
-
649
-  KEEPALIVE_STATE(NOT_BUSY);
650 626
 }
651 627
 
652 628
 void MMU2::filament_runout() {
@@ -679,8 +655,6 @@ void MMU2::filament_runout() {
679 655
       return false;
680 656
     }
681 657
     else {
682
-      KEEPALIVE_STATE(IN_HANDLER);
683
-
684 658
       command(MMU_CMD_T0 + index);
685 659
       manage_response(true, true);
686 660
       command(MMU_CMD_C0);
@@ -692,8 +666,6 @@ void MMU2::filament_runout() {
692 666
       load_to_nozzle();
693 667
 
694 668
       BUZZ(200, 404);
695
-
696
-      KEEPALIVE_STATE(NOT_BUSY);
697 669
       return true;
698 670
     }
699 671
   }
@@ -721,7 +693,6 @@ void MMU2::filament_runout() {
721 693
       return false;
722 694
     }
723 695
 
724
-    KEEPALIVE_STATE(IN_HANDLER);
725 696
     LCD_MESSAGEPGM(MSG_MMU2_EJECTING_FILAMENT);
726 697
     const bool saved_e_relative_mode = gcode.axis_relative_modes[E_AXIS];
727 698
     gcode.axis_relative_modes[E_AXIS] = true;
@@ -757,8 +728,6 @@ void MMU2::filament_runout() {
757 728
 
758 729
     BUZZ(200, 404);
759 730
 
760
-    KEEPALIVE_STATE(NOT_BUSY);
761
-
762 731
     gcode.axis_relative_modes[E_AXIS] = saved_e_relative_mode;
763 732
 
764 733
     disable_E0();
@@ -781,8 +750,6 @@ void MMU2::filament_runout() {
781 750
       return false;
782 751
     }
783 752
 
784
-    KEEPALIVE_STATE(IN_HANDLER);
785
-
786 753
     filament_ramming();
787 754
 
788 755
     command(MMU_CMD_U0);
@@ -795,8 +762,6 @@ void MMU2::filament_runout() {
795 762
 
796 763
     set_runout_valid(false);
797 764
 
798
-    KEEPALIVE_STATE(NOT_BUSY);
799
-
800 765
     return true;
801 766
   }
802 767
 

+ 1
- 1
Marlin/src/feature/prusa_MMU2/mmu2.h Прегледај датотеку

@@ -63,7 +63,7 @@ private:
63 63
 
64 64
   static void command(const uint8_t cmd);
65 65
   static bool get_response(void);
66
-  static void manage_response(bool move_axes, bool turn_off_nozzle);
66
+  static void manage_response(const bool move_axes, const bool turn_off_nozzle);
67 67
 
68 68
   #if HAS_LCD_MENU && ENABLED(MMU2_MENUS)
69 69
     static void load_to_nozzle();

+ 0
- 2
Marlin/src/gcode/bedlevel/abl/G29.cpp Прегледај датотеку

@@ -978,8 +978,6 @@ G29_TYPE GcodeSuite::G29() {
978 978
 
979 979
   if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< G29");
980 980
 
981
-  KEEPALIVE_STATE(IN_HANDLER);
982
-
983 981
   if (planner.leveling_active)
984 982
     sync_plan_position();
985 983
 

+ 2
- 2
Marlin/src/gcode/config/M43.cpp Прегледај датотеку

@@ -320,11 +320,11 @@ void GcodeSuite::M43() {
320 320
     }
321 321
 
322 322
     #if HAS_RESUME_CONTINUE
323
+      KEEPALIVE_STATE(PAUSED_FOR_USER);
323 324
       wait_for_user = true;
324 325
       #if ENABLED(HOST_PROMPT_SUPPORT)
325 326
         host_prompt_do(PROMPT_USER_CONTINUE, PSTR("M43 Wait Called"), PSTR("Continue"));
326 327
       #endif
327
-      KEEPALIVE_STATE(PAUSED_FOR_USER);
328 328
     #endif
329 329
 
330 330
     for (;;) {
@@ -346,7 +346,7 @@ void GcodeSuite::M43() {
346 346
       }
347 347
 
348 348
       #if HAS_RESUME_CONTINUE
349
-        if (!wait_for_user) { KEEPALIVE_STATE(IN_HANDLER); break; }
349
+        if (!wait_for_user) break;
350 350
       #endif
351 351
 
352 352
       safe_delay(200);

+ 1
- 3
Marlin/src/gcode/gcode.cpp Прегледај датотеку

@@ -430,7 +430,7 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
430 430
         //case 191: M191(); break;                                // M191: Wait for chamber temperature to reach target
431 431
       #endif
432 432
 
433
-      case 105: M105(); KEEPALIVE_STATE(NOT_BUSY); return;        // M105: Report Temperatures (and say "ok")
433
+      case 105: M105(); return;                                   // M105: Report Temperatures (and say "ok")
434 434
 
435 435
       #if ENABLED(AUTO_REPORT_TEMPERATURES) && HAS_TEMP_SENSOR
436 436
         case 155: M155(); break;                                  // M155: Set temperature auto-report interval
@@ -796,8 +796,6 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
796 796
     default: parser.unknown_command_error();
797 797
   }
798 798
 
799
-  KEEPALIVE_STATE(NOT_BUSY);
800
-
801 799
   if (!no_ok) queue.ok_to_send();
802 800
 }
803 801
 

+ 2
- 2
Marlin/src/gcode/gcode.h Прегледај датотеку

@@ -339,9 +339,9 @@ public:
339 339
 
340 340
     static void host_keepalive();
341 341
 
342
-    #define KEEPALIVE_STATE(n) gcode.busy_state = gcode.n
342
+    #define KEEPALIVE_STATE(N) REMEMBER(_KA_, gcode.busy_state, gcode.N)
343 343
   #else
344
-    #define KEEPALIVE_STATE(n) NOOP
344
+    #define KEEPALIVE_STATE(N) NOOP
345 345
   #endif
346 346
 
347 347
   static void dwell(millis_t time);

+ 0
- 1
Marlin/src/gcode/lcd/M0_M1.cpp Прегледај датотеку

@@ -118,7 +118,6 @@ void GcodeSuite::M0_M1() {
118 118
   #endif
119 119
 
120 120
   wait_for_user = false;
121
-  KEEPALIVE_STATE(IN_HANDLER);
122 121
 }
123 122
 
124 123
 #endif // HAS_RESUME_CONTINUE

+ 0
- 4
Marlin/src/gcode/temperature/M303.cpp Прегледај датотеку

@@ -62,10 +62,6 @@ void GcodeSuite::M303() {
62 62
   #endif
63 63
 
64 64
   thermalManager.PID_autotune(temp, e, c, u);
65
-
66
-  #if DISABLED(BUSY_WHILE_HEATING)
67
-    KEEPALIVE_STATE(IN_HANDLER);
68
-  #endif
69 65
 }
70 66
 
71 67
 #endif // HAS_PID_HEATING

+ 0
- 1
Marlin/src/lcd/menu/menu_delta_calibrate.cpp Прегледај датотеку

@@ -56,7 +56,6 @@ void _man_probe_pt(const float &rx, const float &ry) {
56 56
       host_prompt_do(PROMPT_USER_CONTINUE, PSTR("Delta Calibration in progress"), PSTR("Continue"));
57 57
     #endif
58 58
     while (wait_for_user) idle();
59
-    KEEPALIVE_STATE(IN_HANDLER);
60 59
     ui.goto_previous_screen_no_defer();
61 60
     return current_position[Z_AXIS];
62 61
   }

+ 1
- 1
Marlin/src/module/probe.cpp Прегледај датотеку

@@ -355,7 +355,7 @@ FORCE_INLINE void probe_specific_action(const bool deploy) {
355 355
       #endif
356 356
       while (wait_for_user) idle();
357 357
       ui.reset_status();
358
-      KEEPALIVE_STATE(IN_HANDLER);
358
+
359 359
     } while(
360 360
       #if ENABLED(PAUSE_PROBE_DEPLOY_WHEN_TRIGGERED)
361 361
         true

+ 0
- 15
Marlin/src/module/temperature.cpp Прегледај датотеку

@@ -2925,7 +2925,6 @@ void Temperature::isr() {
2925 2925
       #endif
2926 2926
 
2927 2927
       #if DISABLED(BUSY_WHILE_HEATING) && ENABLED(HOST_KEEPALIVE_FEATURE)
2928
-        const GcodeSuite::MarlinBusyState old_busy_state = gcode.busy_state;
2929 2928
         KEEPALIVE_STATE(NOT_BUSY);
2930 2929
       #endif
2931 2930
 
@@ -3019,10 +3018,6 @@ void Temperature::isr() {
3019 3018
         #endif
3020 3019
       }
3021 3020
 
3022
-      #if DISABLED(BUSY_WHILE_HEATING) && ENABLED(HOST_KEEPALIVE_FEATURE)
3023
-        gcode.busy_state = old_busy_state;
3024
-      #endif
3025
-
3026 3021
       return wait_for_heatup;
3027 3022
     }
3028 3023
 
@@ -3058,7 +3053,6 @@ void Temperature::isr() {
3058 3053
       millis_t now, next_temp_ms = 0, next_cool_check_ms = 0;
3059 3054
 
3060 3055
       #if DISABLED(BUSY_WHILE_HEATING) && ENABLED(HOST_KEEPALIVE_FEATURE)
3061
-        const GcodeSuite::MarlinBusyState old_busy_state = gcode.busy_state;
3062 3056
         KEEPALIVE_STATE(NOT_BUSY);
3063 3057
       #endif
3064 3058
 
@@ -3145,10 +3139,6 @@ void Temperature::isr() {
3145 3139
 
3146 3140
       if (wait_for_heatup) ui.reset_status();
3147 3141
 
3148
-      #if DISABLED(BUSY_WHILE_HEATING) && ENABLED(HOST_KEEPALIVE_FEATURE)
3149
-        gcode.busy_state = old_busy_state;
3150
-      #endif
3151
-
3152 3142
       return wait_for_heatup;
3153 3143
     }
3154 3144
 
@@ -3179,7 +3169,6 @@ void Temperature::isr() {
3179 3169
       millis_t now, next_temp_ms = 0, next_cool_check_ms = 0;
3180 3170
 
3181 3171
       #if DISABLED(BUSY_WHILE_HEATING) && ENABLED(HOST_KEEPALIVE_FEATURE)
3182
-        const GcodeSuite::MarlinBusyState old_busy_state = gcode.busy_state;
3183 3172
         KEEPALIVE_STATE(NOT_BUSY);
3184 3173
       #endif
3185 3174
 
@@ -3247,10 +3236,6 @@ void Temperature::isr() {
3247 3236
 
3248 3237
       if (wait_for_heatup) ui.reset_status();
3249 3238
 
3250
-      #if DISABLED(BUSY_WHILE_HEATING) && ENABLED(HOST_KEEPALIVE_FEATURE)
3251
-        gcode.busy_state = old_busy_state;
3252
-      #endif
3253
-
3254 3239
       return wait_for_heatup;
3255 3240
     }
3256 3241
 

Loading…
Откажи
Сачувај