🎨 Refactor Host Actions as singleton
This commit is contained in:
		
				
					committed by
					
						
						Scott Lahteine
					
				
			
			
				
	
			
			
			
						parent
						
							1ead7ce681
						
					
				
				
					commit
					f80bcdcc5c
				
			@@ -2363,7 +2363,7 @@ void HMI_PauseOrStop() {
 | 
			
		||||
        card.abortFilePrintSoon();                     // Let the main loop handle SD abort
 | 
			
		||||
        dwin_abort_flag = true;                        // Reset feedrate, return to Home
 | 
			
		||||
        #ifdef ACTION_ON_CANCEL
 | 
			
		||||
          host_action_cancel();
 | 
			
		||||
          hostui.cancel();
 | 
			
		||||
        #endif
 | 
			
		||||
        Popup_Window_Home(true);
 | 
			
		||||
        if (HMI_flag.home_flag) planner.synchronize(); // Wait for planner moves to finish!
 | 
			
		||||
 
 | 
			
		||||
@@ -1391,7 +1391,7 @@ void HMI_PauseOrStop() {
 | 
			
		||||
        card.abortFilePrintSoon();                     // Let the main loop handle SD abort
 | 
			
		||||
        dwin_abort_flag = true;                        // Reset feedrate, return to Home
 | 
			
		||||
        #ifdef ACTION_ON_CANCEL
 | 
			
		||||
          host_action_cancel();
 | 
			
		||||
          hostui.cancel();
 | 
			
		||||
        #endif
 | 
			
		||||
        DWIN_Draw_Popup(ICON_BLTouch, F("Stopping...") , F("Please wait until done."));
 | 
			
		||||
      }
 | 
			
		||||
 
 | 
			
		||||
@@ -4503,7 +4503,7 @@ void CrealityDWINClass::Print_Screen_Control() {
 | 
			
		||||
            #endif
 | 
			
		||||
          }
 | 
			
		||||
          else {
 | 
			
		||||
            TERN_(HOST_ACTION_COMMANDS, host_action_resume());
 | 
			
		||||
            TERN_(HOST_ACTION_COMMANDS, hostui.resume());
 | 
			
		||||
          }
 | 
			
		||||
          Draw_Print_Screen();
 | 
			
		||||
        }
 | 
			
		||||
@@ -4553,7 +4553,7 @@ void CrealityDWINClass::Popup_Control() {
 | 
			
		||||
            #endif
 | 
			
		||||
          }
 | 
			
		||||
          else {
 | 
			
		||||
            TERN_(HOST_ACTION_COMMANDS, host_action_pause());
 | 
			
		||||
            TERN_(HOST_ACTION_COMMANDS, hostui.pause());
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
        Draw_Print_Screen();
 | 
			
		||||
@@ -4566,7 +4566,7 @@ void CrealityDWINClass::Popup_Control() {
 | 
			
		||||
            thermalManager.disable_all_heaters();
 | 
			
		||||
          }
 | 
			
		||||
          else {
 | 
			
		||||
            TERN_(HOST_ACTION_COMMANDS, host_action_cancel());
 | 
			
		||||
            TERN_(HOST_ACTION_COMMANDS, hostui.cancel());
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
 
 | 
			
		||||
@@ -242,7 +242,7 @@ bool StatusScreen::onTouchEnd(uint8_t tag) {
 | 
			
		||||
      if (ExtUI::isPrintingFromMedia())
 | 
			
		||||
        ExtUI::pausePrint();
 | 
			
		||||
      #ifdef ACTION_ON_PAUSE
 | 
			
		||||
        else host_action_pause();
 | 
			
		||||
        else hostui.pause();
 | 
			
		||||
      #endif
 | 
			
		||||
      GOTO_SCREEN(StatusScreen);
 | 
			
		||||
      break;
 | 
			
		||||
@@ -251,7 +251,7 @@ bool StatusScreen::onTouchEnd(uint8_t tag) {
 | 
			
		||||
      if (ExtUI::isPrintingFromMedia())
 | 
			
		||||
        ExtUI::resumePrint();
 | 
			
		||||
      #ifdef ACTION_ON_RESUME
 | 
			
		||||
        else host_action_resume();
 | 
			
		||||
        else hostui.resume();
 | 
			
		||||
      #endif
 | 
			
		||||
      GOTO_SCREEN(StatusScreen);
 | 
			
		||||
      break;
 | 
			
		||||
 
 | 
			
		||||
@@ -41,7 +41,7 @@ bool ConfirmAbortPrintDialogBox::onTouchEnd(uint8_t tag) {
 | 
			
		||||
      if (ExtUI::isPrintingFromMedia())
 | 
			
		||||
         ExtUI::stopPrint();
 | 
			
		||||
      #ifdef ACTION_ON_CANCEL
 | 
			
		||||
        else host_action_cancel();
 | 
			
		||||
        else hostui.cancel();
 | 
			
		||||
      #endif
 | 
			
		||||
      return true;
 | 
			
		||||
    default:
 | 
			
		||||
 
 | 
			
		||||
@@ -138,7 +138,7 @@ void TuneMenu::pausePrint() {
 | 
			
		||||
  if (ExtUI::isPrintingFromMedia())
 | 
			
		||||
    ExtUI::pausePrint();
 | 
			
		||||
  #ifdef ACTION_ON_PAUSE
 | 
			
		||||
    else host_action_pause();
 | 
			
		||||
    else hostui.pause();
 | 
			
		||||
  #endif
 | 
			
		||||
  GOTO_SCREEN(StatusScreen);
 | 
			
		||||
}
 | 
			
		||||
@@ -150,7 +150,7 @@ void TuneMenu::resumePrint() {
 | 
			
		||||
  else if (ExtUI::isPrintingFromMedia())
 | 
			
		||||
    ExtUI::resumePrint();
 | 
			
		||||
  #ifdef ACTION_ON_RESUME
 | 
			
		||||
    else host_action_resume();
 | 
			
		||||
    else hostui.resume();
 | 
			
		||||
  #endif
 | 
			
		||||
  GOTO_SCREEN(StatusScreen);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -918,7 +918,7 @@ namespace ExtUI {
 | 
			
		||||
  #endif // HAS_LEVELING
 | 
			
		||||
 | 
			
		||||
  #if ENABLED(HOST_PROMPT_SUPPORT)
 | 
			
		||||
    void setHostResponse(const uint8_t response) { host_response_handler(response); }
 | 
			
		||||
    void setHostResponse(const uint8_t response) { hostui.handle_response(response); }
 | 
			
		||||
  #endif
 | 
			
		||||
 | 
			
		||||
  #if ENABLED(PRINTCOUNTER)
 | 
			
		||||
 
 | 
			
		||||
@@ -1355,7 +1355,7 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
 | 
			
		||||
  void MarlinUI::set_status(const char * const cstr, const bool persist) {
 | 
			
		||||
    if (alert_level) return;
 | 
			
		||||
 | 
			
		||||
    TERN_(HOST_PROMPT_SUPPORT, host_action_notify(cstr));
 | 
			
		||||
    TERN_(HOST_PROMPT_SUPPORT, hostui.notify(cstr));
 | 
			
		||||
 | 
			
		||||
    // Here we have a problem. The message is encoded in UTF8, so
 | 
			
		||||
    // arbitrarily cutting it will be a problem. We MUST be sure
 | 
			
		||||
@@ -1427,7 +1427,7 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
 | 
			
		||||
    if (level < alert_level) return;
 | 
			
		||||
    alert_level = level;
 | 
			
		||||
 | 
			
		||||
    TERN_(HOST_PROMPT_SUPPORT, host_action_notify(fstr));
 | 
			
		||||
    TERN_(HOST_PROMPT_SUPPORT, hostui.notify(fstr));
 | 
			
		||||
 | 
			
		||||
    // Since the message is encoded in UTF8 it must
 | 
			
		||||
    // only be cut on a character boundary.
 | 
			
		||||
@@ -1533,10 +1533,10 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
 | 
			
		||||
      card.abortFilePrintSoon();
 | 
			
		||||
    #endif
 | 
			
		||||
    #ifdef ACTION_ON_CANCEL
 | 
			
		||||
      host_action_cancel();
 | 
			
		||||
      hostui.cancel();
 | 
			
		||||
    #endif
 | 
			
		||||
    IF_DISABLED(SDSUPPORT, print_job_timer.stop());
 | 
			
		||||
    TERN_(HOST_PROMPT_SUPPORT, host_prompt_open(PROMPT_INFO, F("UI Aborted"), FPSTR(DISMISS_STR)));
 | 
			
		||||
    TERN_(HOST_PROMPT_SUPPORT, hostui.prompt_open(PROMPT_INFO, F("UI Aborted"), FPSTR(DISMISS_STR)));
 | 
			
		||||
    LCD_MESSAGE(MSG_PRINT_ABORTED);
 | 
			
		||||
    TERN_(HAS_LCD_MENU, return_to_status());
 | 
			
		||||
  }
 | 
			
		||||
@@ -1565,7 +1565,7 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
 | 
			
		||||
    #endif
 | 
			
		||||
 | 
			
		||||
    TERN_(HAS_TOUCH_SLEEP, wakeup_screen());
 | 
			
		||||
    TERN_(HOST_PROMPT_SUPPORT, host_prompt_open(PROMPT_PAUSE_RESUME, F("UI Pause"), F("Resume")));
 | 
			
		||||
    TERN_(HOST_PROMPT_SUPPORT, hostui.prompt_open(PROMPT_PAUSE_RESUME, F("UI Pause"), F("Resume")));
 | 
			
		||||
 | 
			
		||||
    LCD_MESSAGE(MSG_PRINT_PAUSED);
 | 
			
		||||
 | 
			
		||||
@@ -1575,7 +1575,7 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
 | 
			
		||||
    #elif ENABLED(SDSUPPORT)
 | 
			
		||||
      queue.inject(F("M25"));
 | 
			
		||||
    #elif defined(ACTION_ON_PAUSE)
 | 
			
		||||
      host_action_pause();
 | 
			
		||||
      hostui.pause();
 | 
			
		||||
    #endif
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -1584,7 +1584,7 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
 | 
			
		||||
    TERN_(PARK_HEAD_ON_PAUSE, wait_for_heatup = wait_for_user = false);
 | 
			
		||||
    TERN_(SDSUPPORT, if (IS_SD_PAUSED()) queue.inject_P(M24_STR));
 | 
			
		||||
    #ifdef ACTION_ON_RESUME
 | 
			
		||||
      host_action_resume();
 | 
			
		||||
      hostui.resume();
 | 
			
		||||
    #endif
 | 
			
		||||
    print_job_timer.start(); // Also called by M24
 | 
			
		||||
  }
 | 
			
		||||
@@ -1639,13 +1639,13 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
 | 
			
		||||
  // Send the status line as a host notification
 | 
			
		||||
  //
 | 
			
		||||
  void MarlinUI::set_status(const char * const cstr, const bool) {
 | 
			
		||||
    TERN(HOST_PROMPT_SUPPORT, host_action_notify(cstr), UNUSED(cstr));
 | 
			
		||||
    TERN(HOST_PROMPT_SUPPORT, hostui.notify(cstr), UNUSED(cstr));
 | 
			
		||||
  }
 | 
			
		||||
  void MarlinUI::set_status(FSTR_P const fstr, const int8_t) {
 | 
			
		||||
    TERN(HOST_PROMPT_SUPPORT, host_action_notify(fstr), UNUSED(fstr));
 | 
			
		||||
    TERN(HOST_PROMPT_SUPPORT, hostui.notify(fstr), UNUSED(fstr));
 | 
			
		||||
  }
 | 
			
		||||
  void MarlinUI::status_printf(const uint8_t, FSTR_P const fstr, ...) {
 | 
			
		||||
    TERN(HOST_PROMPT_SUPPORT, host_action_notify(fstr), UNUSED(fstr));
 | 
			
		||||
    TERN(HOST_PROMPT_SUPPORT, hostui.notify(fstr), UNUSED(fstr));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
#endif // !HAS_DISPLAY && !HAS_STATUS_MESSAGE
 | 
			
		||||
 
 | 
			
		||||
@@ -58,13 +58,13 @@ void _man_probe_pt(const xy_pos_t &xy) {
 | 
			
		||||
    #include "../../MarlinCore.h" // for wait_for_user_response()
 | 
			
		||||
  #endif
 | 
			
		||||
  #if ENABLED(HOST_PROMPT_SUPPORT)
 | 
			
		||||
    #include "../../feature/host_actions.h" // for host_prompt_do
 | 
			
		||||
    #include "../../feature/host_actions.h" // for hostui.prompt_do
 | 
			
		||||
  #endif
 | 
			
		||||
 | 
			
		||||
  float lcd_probe_pt(const xy_pos_t &xy) {
 | 
			
		||||
    _man_probe_pt(xy);
 | 
			
		||||
    ui.defer_status_screen();
 | 
			
		||||
    TERN_(HOST_PROMPT_SUPPORT, host_prompt_do(PROMPT_USER_CONTINUE, F("Delta Calibration in progress"), FPSTR(CONTINUE_STR)));
 | 
			
		||||
    TERN_(HOST_PROMPT_SUPPORT, hostui.prompt_do(PROMPT_USER_CONTINUE, F("Delta Calibration in progress"), FPSTR(CONTINUE_STR)));
 | 
			
		||||
    TERN_(EXTENSIBLE_UI, ExtUI::onUserConfirmRequired(F("Delta Calibration in progress")));
 | 
			
		||||
    TERN_(HAS_RESUME_CONTINUE, wait_for_user_response());
 | 
			
		||||
    ui.goto_previous_screen_no_defer();
 | 
			
		||||
 
 | 
			
		||||
@@ -301,7 +301,7 @@ void menu_main() {
 | 
			
		||||
      ACTION_ITEM(MSG_RESUME_PRINT, ui.resume_print);
 | 
			
		||||
 | 
			
		||||
    #if ENABLED(HOST_START_MENU_ITEM) && defined(ACTION_ON_START)
 | 
			
		||||
      ACTION_ITEM(MSG_HOST_START_PRINT, host_action_start);
 | 
			
		||||
      ACTION_ITEM(MSG_HOST_START_PRINT, hostui.start);
 | 
			
		||||
    #endif
 | 
			
		||||
 | 
			
		||||
    #if ENABLED(PREHEAT_SHORTCUT_MENU_ITEM)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user