2019-02-12 21:55:47 +00:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2020-02-03 14:00:57 +00:00
|
|
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2019-02-12 21:55:47 +00:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-28 04:57:50 +00:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
2019-02-12 21:55:47 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2020-07-23 03:20:14 +00:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2019-02-12 21:55:47 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "../inc/MarlinConfig.h"
|
|
|
|
|
|
|
|
#if ENABLED(HOST_ACTION_COMMANDS)
|
|
|
|
|
|
|
|
//#define DEBUG_HOST_ACTIONS
|
|
|
|
|
2021-10-15 05:24:08 +00:00
|
|
|
#include "host_actions.h"
|
|
|
|
|
2019-02-12 21:55:47 +00:00
|
|
|
#if ENABLED(ADVANCED_PAUSE_FEATURE)
|
|
|
|
#include "pause.h"
|
|
|
|
#include "../gcode/queue.h"
|
|
|
|
#endif
|
|
|
|
|
2019-02-13 02:08:34 +00:00
|
|
|
#if HAS_FILAMENT_SENSOR
|
2019-02-12 21:55:47 +00:00
|
|
|
#include "runout.h"
|
|
|
|
#endif
|
|
|
|
|
2021-10-15 05:24:08 +00:00
|
|
|
HostUI hostui;
|
|
|
|
|
|
|
|
void HostUI::action(FSTR_P const fstr, const bool eol) {
|
2021-03-09 09:20:37 +00:00
|
|
|
PORT_REDIRECT(SerialMask::All);
|
2019-02-12 21:55:47 +00:00
|
|
|
SERIAL_ECHOPGM("//action:");
|
2021-09-27 16:55:08 +00:00
|
|
|
SERIAL_ECHOF(fstr);
|
2019-02-12 21:55:47 +00:00
|
|
|
if (eol) SERIAL_EOL();
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ACTION_ON_KILL
|
2021-10-15 05:24:08 +00:00
|
|
|
void HostUI::kill() { action(F(ACTION_ON_KILL)); }
|
2019-02-12 21:55:47 +00:00
|
|
|
#endif
|
|
|
|
#ifdef ACTION_ON_PAUSE
|
2021-10-15 05:24:08 +00:00
|
|
|
void HostUI::pause(const bool eol/*=true*/) { action(F(ACTION_ON_PAUSE), eol); }
|
2019-02-12 21:55:47 +00:00
|
|
|
#endif
|
|
|
|
#ifdef ACTION_ON_PAUSED
|
2021-10-15 05:24:08 +00:00
|
|
|
void HostUI::paused(const bool eol/*=true*/) { action(F(ACTION_ON_PAUSED), eol); }
|
2019-02-12 21:55:47 +00:00
|
|
|
#endif
|
|
|
|
#ifdef ACTION_ON_RESUME
|
2021-10-15 05:24:08 +00:00
|
|
|
void HostUI::resume() { action(F(ACTION_ON_RESUME)); }
|
2019-02-12 21:55:47 +00:00
|
|
|
#endif
|
|
|
|
#ifdef ACTION_ON_RESUMED
|
2021-10-15 05:24:08 +00:00
|
|
|
void HostUI::resumed() { action(F(ACTION_ON_RESUMED)); }
|
2019-02-12 21:55:47 +00:00
|
|
|
#endif
|
|
|
|
#ifdef ACTION_ON_CANCEL
|
2021-10-15 05:24:08 +00:00
|
|
|
void HostUI::cancel() { action(F(ACTION_ON_CANCEL)); }
|
2019-02-12 21:55:47 +00:00
|
|
|
#endif
|
2020-09-17 11:36:21 +00:00
|
|
|
#ifdef ACTION_ON_START
|
2021-10-15 05:24:08 +00:00
|
|
|
void HostUI::start() { action(F(ACTION_ON_START)); }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(G29_RETRY_AND_RECOVER)
|
|
|
|
#ifdef ACTION_ON_G29_RECOVER
|
|
|
|
void HostUI::g29_recover() { action(F(ACTION_ON_G29_RECOVER)); }
|
|
|
|
#endif
|
|
|
|
#ifdef ACTION_ON_G29_FAILURE
|
|
|
|
void HostUI::g29_failure() { action(F(ACTION_ON_G29_FAILURE)); }
|
|
|
|
#endif
|
2020-09-17 11:36:21 +00:00
|
|
|
#endif
|
2019-02-12 21:55:47 +00:00
|
|
|
|
2021-10-30 05:17:20 +00:00
|
|
|
#ifdef SHUTDOWN_ACTION
|
|
|
|
void HostUI::shutdown() { action(F(SHUTDOWN_ACTION)); }
|
|
|
|
#endif
|
|
|
|
|
2019-02-12 21:55:47 +00:00
|
|
|
#if ENABLED(HOST_PROMPT_SUPPORT)
|
|
|
|
|
2021-10-15 05:24:08 +00:00
|
|
|
PromptReason HostUI::host_prompt_reason = PROMPT_NOT_DEFINED;
|
|
|
|
|
2020-05-06 04:34:04 +00:00
|
|
|
PGMSTR(CONTINUE_STR, "Continue");
|
|
|
|
PGMSTR(DISMISS_STR, "Dismiss");
|
2019-11-29 10:45:07 +00:00
|
|
|
|
2019-08-02 16:34:10 +00:00
|
|
|
#if HAS_RESUME_CONTINUE
|
|
|
|
extern bool wait_for_user;
|
|
|
|
#endif
|
|
|
|
|
2021-10-15 05:24:08 +00:00
|
|
|
void HostUI::notify(const char * const cstr) {
|
2021-03-09 09:20:37 +00:00
|
|
|
PORT_REDIRECT(SerialMask::All);
|
2021-10-15 05:24:08 +00:00
|
|
|
action(F("notification "), false);
|
2021-09-27 16:55:08 +00:00
|
|
|
SERIAL_ECHOLN(cstr);
|
2020-05-11 02:19:23 +00:00
|
|
|
}
|
|
|
|
|
2021-10-15 05:24:08 +00:00
|
|
|
void HostUI::notify_P(PGM_P const pstr) {
|
2021-03-09 09:20:37 +00:00
|
|
|
PORT_REDIRECT(SerialMask::All);
|
2021-10-15 05:24:08 +00:00
|
|
|
action(F("notification "), false);
|
|
|
|
SERIAL_ECHOLNPGM_P(pstr);
|
2019-12-01 23:39:28 +00:00
|
|
|
}
|
|
|
|
|
2021-10-15 05:24:08 +00:00
|
|
|
void HostUI::prompt(FSTR_P const ptype, const bool eol/*=true*/) {
|
2021-03-09 09:20:37 +00:00
|
|
|
PORT_REDIRECT(SerialMask::All);
|
2021-10-15 05:24:08 +00:00
|
|
|
action(F("prompt_"), false);
|
2021-09-27 16:55:08 +00:00
|
|
|
SERIAL_ECHOF(ptype);
|
2019-02-12 21:55:47 +00:00
|
|
|
if (eol) SERIAL_EOL();
|
|
|
|
}
|
|
|
|
|
2021-10-15 05:24:08 +00:00
|
|
|
void HostUI::prompt_plus(FSTR_P const ptype, FSTR_P const fstr, const char extra_char/*='\0'*/) {
|
|
|
|
prompt(ptype, false);
|
2021-03-09 09:20:37 +00:00
|
|
|
PORT_REDIRECT(SerialMask::All);
|
2019-02-12 21:55:47 +00:00
|
|
|
SERIAL_CHAR(' ');
|
2021-09-27 16:55:08 +00:00
|
|
|
SERIAL_ECHOF(fstr);
|
2020-02-14 05:39:27 +00:00
|
|
|
if (extra_char != '\0') SERIAL_CHAR(extra_char);
|
|
|
|
SERIAL_EOL();
|
|
|
|
}
|
2021-10-15 05:24:08 +00:00
|
|
|
void HostUI::prompt_begin(const PromptReason reason, FSTR_P const fstr, const char extra_char/*='\0'*/) {
|
|
|
|
prompt_end();
|
2020-02-14 05:39:27 +00:00
|
|
|
host_prompt_reason = reason;
|
2021-10-15 05:24:08 +00:00
|
|
|
prompt_plus(F("begin"), fstr, extra_char);
|
2019-02-12 21:55:47 +00:00
|
|
|
}
|
2021-10-15 05:24:08 +00:00
|
|
|
void HostUI::prompt_button(FSTR_P const fstr) { prompt_plus(F("button"), fstr); }
|
|
|
|
void HostUI::prompt_end() { prompt(F("end")); }
|
|
|
|
void HostUI::prompt_show() { prompt(F("show")); }
|
|
|
|
|
|
|
|
void HostUI::_prompt_show(FSTR_P const btn1, FSTR_P const btn2) {
|
|
|
|
if (btn1) prompt_button(btn1);
|
|
|
|
if (btn2) prompt_button(btn2);
|
|
|
|
prompt_show();
|
2019-02-12 21:55:47 +00:00
|
|
|
}
|
2021-10-15 05:24:08 +00:00
|
|
|
void HostUI::prompt_do(const PromptReason reason, FSTR_P const fstr, FSTR_P const btn1/*=nullptr*/, FSTR_P const btn2/*=nullptr*/) {
|
|
|
|
prompt_begin(reason, fstr);
|
|
|
|
_prompt_show(btn1, btn2);
|
2020-10-19 05:25:51 +00:00
|
|
|
}
|
2021-10-15 05:24:08 +00:00
|
|
|
void HostUI::prompt_do(const PromptReason reason, FSTR_P const fstr, const char extra_char, FSTR_P const btn1/*=nullptr*/, FSTR_P const btn2/*=nullptr*/) {
|
|
|
|
prompt_begin(reason, fstr, extra_char);
|
|
|
|
_prompt_show(btn1, btn2);
|
2020-10-19 05:25:51 +00:00
|
|
|
}
|
2019-02-12 21:55:47 +00:00
|
|
|
|
2021-10-15 05:24:08 +00:00
|
|
|
#if ENABLED(ADVANCED_PAUSE_FEATURE)
|
|
|
|
void HostUI::filament_load_prompt() {
|
|
|
|
const bool disable_to_continue = TERN0(HAS_FILAMENT_SENSOR, runout.filament_ran_out);
|
|
|
|
prompt_do(PROMPT_FILAMENT_RUNOUT, F("Paused"), F("PurgeMore"),
|
|
|
|
disable_to_continue ? F("DisableRunout") : FPSTR(CONTINUE_STR)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
#endif
|
2019-02-12 21:55:47 +00:00
|
|
|
|
2020-02-14 05:39:27 +00:00
|
|
|
//
|
|
|
|
// Handle responses from the host, such as:
|
|
|
|
// - Filament runout responses: Purge More, Continue
|
|
|
|
// - General "Continue" response
|
|
|
|
// - Resume Print response
|
|
|
|
// - Dismissal of info
|
|
|
|
//
|
2021-10-15 05:24:08 +00:00
|
|
|
void HostUI::handle_response(const uint8_t response) {
|
2019-02-12 21:55:47 +00:00
|
|
|
const PromptReason hpr = host_prompt_reason;
|
2020-02-14 05:39:27 +00:00
|
|
|
host_prompt_reason = PROMPT_NOT_DEFINED; // Reset now ahead of logic
|
2019-02-12 21:55:47 +00:00
|
|
|
switch (hpr) {
|
|
|
|
case PROMPT_FILAMENT_RUNOUT:
|
2020-02-14 05:39:27 +00:00
|
|
|
switch (response) {
|
|
|
|
|
|
|
|
case 0: // "Purge More" button
|
2021-04-22 23:43:28 +00:00
|
|
|
#if BOTH(M600_PURGE_MORE_RESUMABLE, ADVANCED_PAUSE_FEATURE)
|
2020-02-14 05:39:27 +00:00
|
|
|
pause_menu_response = PAUSE_RESPONSE_EXTRUDE_MORE; // Simulate menu selection (menu exits, doesn't extrude more)
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1: // "Continue" / "Disable Runout" button
|
2021-04-22 23:43:28 +00:00
|
|
|
#if BOTH(M600_PURGE_MORE_RESUMABLE, ADVANCED_PAUSE_FEATURE)
|
2020-02-14 05:39:27 +00:00
|
|
|
pause_menu_response = PAUSE_RESPONSE_RESUME_PRINT; // Simulate menu selection
|
|
|
|
#endif
|
2019-02-13 02:08:34 +00:00
|
|
|
#if HAS_FILAMENT_SENSOR
|
2020-02-14 05:39:27 +00:00
|
|
|
if (runout.filament_ran_out) { // Disable a triggered sensor
|
|
|
|
runout.enabled = false;
|
|
|
|
runout.reset();
|
|
|
|
}
|
2019-02-12 21:55:47 +00:00
|
|
|
#endif
|
2020-02-14 05:39:27 +00:00
|
|
|
break;
|
2019-02-12 21:55:47 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PROMPT_USER_CONTINUE:
|
2020-04-22 21:35:03 +00:00
|
|
|
TERN_(HAS_RESUME_CONTINUE, wait_for_user = false);
|
2019-02-12 21:55:47 +00:00
|
|
|
break;
|
|
|
|
case PROMPT_PAUSE_RESUME:
|
2021-02-02 20:30:19 +00:00
|
|
|
#if BOTH(ADVANCED_PAUSE_FEATURE, SDSUPPORT)
|
2019-11-02 04:51:25 +00:00
|
|
|
extern const char M24_STR[];
|
|
|
|
queue.inject_P(M24_STR);
|
2019-07-31 22:21:25 +00:00
|
|
|
#endif
|
2019-02-12 21:55:47 +00:00
|
|
|
break;
|
2019-09-27 22:06:26 +00:00
|
|
|
case PROMPT_INFO:
|
|
|
|
break;
|
2019-02-12 21:55:47 +00:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // HOST_PROMPT_SUPPORT
|
|
|
|
|
|
|
|
#endif // HOST_ACTION_COMMANDS
|