Firmware2/Marlin/src/feature/host_actions.cpp

188 lines
6.1 KiB
C++
Raw Normal View History

2019-02-12 22:55:47 +01:00
/**
* Marlin 3D Printer Firmware
2020-02-03 15:00:57 +01:00
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
2019-02-12 22:55:47 +01:00
*
* Based on Sprinter and grbl.
2019-06-28 06:57:50 +02:00
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
2019-02-12 22:55:47 +01: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 05:20:14 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2019-02-12 22:55:47 +01:00
*
*/
#include "../inc/MarlinConfig.h"
#if ENABLED(HOST_ACTION_COMMANDS)
#include "host_actions.h"
//#define DEBUG_HOST_ACTIONS
#if ENABLED(ADVANCED_PAUSE_FEATURE)
#include "pause.h"
#include "../gcode/queue.h"
#endif
2019-02-13 03:08:34 +01:00
#if HAS_FILAMENT_SENSOR
2019-02-12 22:55:47 +01:00
#include "runout.h"
#endif
void host_action(PGM_P const pstr, const bool eol) {
PORT_REDIRECT(SerialMask::All);
2019-02-12 22:55:47 +01:00
SERIAL_ECHOPGM("//action:");
2021-03-01 02:43:46 +01:00
SERIAL_ECHOPGM_P(pstr);
2019-02-12 22:55:47 +01:00
if (eol) SERIAL_EOL();
}
#ifdef ACTION_ON_KILL
void host_action_kill() { host_action(PSTR(ACTION_ON_KILL)); }
#endif
#ifdef ACTION_ON_PAUSE
void host_action_pause(const bool eol/*=true*/) { host_action(PSTR(ACTION_ON_PAUSE), eol); }
#endif
#ifdef ACTION_ON_PAUSED
void host_action_paused(const bool eol/*=true*/) { host_action(PSTR(ACTION_ON_PAUSED), eol); }
#endif
#ifdef ACTION_ON_RESUME
void host_action_resume() { host_action(PSTR(ACTION_ON_RESUME)); }
#endif
#ifdef ACTION_ON_RESUMED
void host_action_resumed() { host_action(PSTR(ACTION_ON_RESUMED)); }
#endif
#ifdef ACTION_ON_CANCEL
void host_action_cancel() { host_action(PSTR(ACTION_ON_CANCEL)); }
#endif
2020-09-17 13:36:21 +02:00
#ifdef ACTION_ON_START
void host_action_start() { host_action(PSTR(ACTION_ON_START)); }
#endif
2019-02-12 22:55:47 +01:00
#if ENABLED(HOST_PROMPT_SUPPORT)
2020-05-06 06:34:04 +02:00
PGMSTR(CONTINUE_STR, "Continue");
PGMSTR(DISMISS_STR, "Dismiss");
2019-08-02 18:34:10 +02:00
#if HAS_RESUME_CONTINUE
extern bool wait_for_user;
#endif
2019-02-12 22:55:47 +01:00
PromptReason host_prompt_reason = PROMPT_NOT_DEFINED;
void host_action_notify(const char * const message) {
PORT_REDIRECT(SerialMask::All);
host_action(PSTR("notification "), false);
2020-07-16 02:58:32 +02:00
SERIAL_ECHOLN(message);
}
void host_action_notify_P(PGM_P const message) {
PORT_REDIRECT(SerialMask::All);
host_action(PSTR("notification "), false);
2021-03-01 02:43:46 +01:00
SERIAL_ECHOLNPGM_P(message);
}
void host_action_prompt(PGM_P const ptype, const bool eol=true) {
PORT_REDIRECT(SerialMask::All);
2019-02-12 22:55:47 +01:00
host_action(PSTR("prompt_"), false);
2021-03-01 02:43:46 +01:00
SERIAL_ECHOPGM_P(ptype);
2019-02-12 22:55:47 +01:00
if (eol) SERIAL_EOL();
}
void host_action_prompt_plus(PGM_P const ptype, PGM_P const pstr, const char extra_char='\0') {
2019-02-12 22:55:47 +01:00
host_action_prompt(ptype, false);
PORT_REDIRECT(SerialMask::All);
2019-02-12 22:55:47 +01:00
SERIAL_CHAR(' ');
2021-03-01 02:43:46 +01:00
SERIAL_ECHOPGM_P(pstr);
2020-02-14 06:39:27 +01:00
if (extra_char != '\0') SERIAL_CHAR(extra_char);
SERIAL_EOL();
}
void host_action_prompt_begin(const PromptReason reason, PGM_P const pstr, const char extra_char/*='\0'*/) {
2020-02-14 06:39:27 +01:00
host_action_prompt_end();
host_prompt_reason = reason;
host_action_prompt_plus(PSTR("begin"), pstr, extra_char);
2019-02-12 22:55:47 +01:00
}
void host_action_prompt_button(PGM_P const pstr) { host_action_prompt_plus(PSTR("button"), pstr); }
2019-02-12 22:55:47 +01:00
void host_action_prompt_end() { host_action_prompt(PSTR("end")); }
void host_action_prompt_show() { host_action_prompt(PSTR("show")); }
2020-10-19 07:25:51 +02:00
void _host_prompt_show(PGM_P const btn1/*=nullptr*/, PGM_P const btn2/*=nullptr*/) {
2020-02-14 06:39:27 +01:00
if (btn1) host_action_prompt_button(btn1);
if (btn2) host_action_prompt_button(btn2);
2019-02-12 22:55:47 +01:00
host_action_prompt_show();
}
2020-10-19 07:25:51 +02:00
void host_prompt_do(const PromptReason reason, PGM_P const pstr, PGM_P const btn1/*=nullptr*/, PGM_P const btn2/*=nullptr*/) {
host_action_prompt_begin(reason, pstr);
_host_prompt_show(btn1, btn2);
}
void host_prompt_do(const PromptReason reason, PGM_P const pstr, const char extra_char, PGM_P const btn1/*=nullptr*/, PGM_P const btn2/*=nullptr*/) {
host_action_prompt_begin(reason, pstr, extra_char);
_host_prompt_show(btn1, btn2);
}
2019-02-12 22:55:47 +01:00
2020-02-14 06:39:27 +01:00
void filament_load_host_prompt() {
2020-04-22 23:35:03 +02:00
const bool disable_to_continue = TERN0(HAS_FILAMENT_SENSOR, runout.filament_ran_out);
2020-02-14 06:39:27 +01:00
host_prompt_do(PROMPT_FILAMENT_RUNOUT, PSTR("Paused"), PSTR("PurgeMore"),
disable_to_continue ? PSTR("DisableRunout") : CONTINUE_STR
);
2019-02-12 22:55:47 +01:00
}
2020-02-14 06:39:27 +01:00
//
// Handle responses from the host, such as:
// - Filament runout responses: Purge More, Continue
// - General "Continue" response
// - Resume Print response
// - Dismissal of info
//
2019-02-12 22:55:47 +01:00
void host_response_handler(const uint8_t response) {
const PromptReason hpr = host_prompt_reason;
2020-02-14 06:39:27 +01:00
host_prompt_reason = PROMPT_NOT_DEFINED; // Reset now ahead of logic
2019-02-12 22:55:47 +01:00
switch (hpr) {
case PROMPT_FILAMENT_RUNOUT:
2020-02-14 06:39:27 +01:00
switch (response) {
case 0: // "Purge More" button
#if BOTH(M600_PURGE_MORE_RESUMABLE, ADVANCED_PAUSE_FEATURE)
2020-02-14 06:39:27 +01: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
#if BOTH(M600_PURGE_MORE_RESUMABLE, ADVANCED_PAUSE_FEATURE)
2020-02-14 06:39:27 +01:00
pause_menu_response = PAUSE_RESPONSE_RESUME_PRINT; // Simulate menu selection
#endif
2019-02-13 03:08:34 +01:00
#if HAS_FILAMENT_SENSOR
2020-02-14 06:39:27 +01:00
if (runout.filament_ran_out) { // Disable a triggered sensor
runout.enabled = false;
runout.reset();
}
2019-02-12 22:55:47 +01:00
#endif
2020-02-14 06:39:27 +01:00
break;
2019-02-12 22:55:47 +01:00
}
break;
case PROMPT_USER_CONTINUE:
2020-04-22 23:35:03 +02:00
TERN_(HAS_RESUME_CONTINUE, wait_for_user = false);
2019-02-12 22:55:47 +01:00
break;
case PROMPT_PAUSE_RESUME:
#if BOTH(ADVANCED_PAUSE_FEATURE, SDSUPPORT)
2019-11-02 05:51:25 +01:00
extern const char M24_STR[];
queue.inject_P(M24_STR);
#endif
2019-02-12 22:55:47 +01:00
break;
2019-09-28 00:06:26 +02:00
case PROMPT_INFO:
break;
2019-02-12 22:55:47 +01:00
default: break;
}
}
#endif // HOST_PROMPT_SUPPORT
#endif // HOST_ACTION_COMMANDS