2019-02-12 22:55:47 +01:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2019-06-28 06:57:50 +02:00
|
|
|
* Copyright (c) 2019 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
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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(const char * const pstr, const bool eol) {
|
|
|
|
SERIAL_ECHOPGM("//action:");
|
|
|
|
serialprintPGM(pstr);
|
|
|
|
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
|
|
|
|
|
|
|
|
#if ENABLED(HOST_PROMPT_SUPPORT)
|
|
|
|
|
2019-11-29 11:45:07 +01:00
|
|
|
const char CONTINUE_STR[] PROGMEM = "Continue";
|
|
|
|
|
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;
|
|
|
|
|
2019-12-02 00:39:28 +01:00
|
|
|
void host_action_notify(const char * const message) {
|
|
|
|
host_action(PSTR("notification "), false);
|
|
|
|
serialprintPGM(message);
|
|
|
|
SERIAL_EOL();
|
|
|
|
}
|
|
|
|
|
2019-02-12 22:55:47 +01:00
|
|
|
void host_action_prompt(const char * const ptype, const bool eol=true) {
|
|
|
|
host_action(PSTR("prompt_"), false);
|
|
|
|
serialprintPGM(ptype);
|
|
|
|
if (eol) SERIAL_EOL();
|
|
|
|
}
|
|
|
|
|
|
|
|
void host_action_prompt_plus(const char * const ptype, const char * const pstr, const bool eol=true) {
|
|
|
|
host_action_prompt(ptype, false);
|
|
|
|
SERIAL_CHAR(' ');
|
|
|
|
serialprintPGM(pstr);
|
|
|
|
if (eol) SERIAL_EOL();
|
|
|
|
}
|
|
|
|
void host_action_prompt_begin(const char * const pstr, const bool eol/*=true*/) { host_action_prompt_plus(PSTR("begin"), pstr, eol); }
|
|
|
|
void host_action_prompt_button(const char * const pstr) { host_action_prompt_plus(PSTR("button"), pstr); }
|
|
|
|
void host_action_prompt_end() { host_action_prompt(PSTR("end")); }
|
|
|
|
void host_action_prompt_show() { host_action_prompt(PSTR("show")); }
|
2019-05-09 18:45:55 +02:00
|
|
|
void host_prompt_do(const PromptReason reason, const char * const pstr, const char * const pbtn/*=nullptr*/) {
|
2019-02-12 22:55:47 +01:00
|
|
|
host_prompt_reason = reason;
|
|
|
|
host_action_prompt_end();
|
|
|
|
host_action_prompt_begin(pstr);
|
|
|
|
if (pbtn) host_action_prompt_button(pbtn);
|
|
|
|
host_action_prompt_show();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void say_m876_response(const char * const pstr) {
|
|
|
|
SERIAL_ECHOPGM("M876 Responding PROMPT_");
|
|
|
|
serialprintPGM(pstr);
|
|
|
|
SERIAL_EOL();
|
|
|
|
}
|
|
|
|
|
|
|
|
void host_response_handler(const uint8_t response) {
|
|
|
|
#ifdef DEBUG_HOST_ACTIONS
|
2019-10-18 23:47:07 +02:00
|
|
|
SERIAL_ECHOLNPAIR("M876 Handle Reason: ", host_prompt_reason);
|
|
|
|
SERIAL_ECHOLNPAIR("M876 Handle Response: ", response);
|
2019-02-12 22:55:47 +01:00
|
|
|
#endif
|
|
|
|
const char *msg = PSTR("UNKNOWN STATE");
|
|
|
|
const PromptReason hpr = host_prompt_reason;
|
|
|
|
host_prompt_reason = PROMPT_NOT_DEFINED;
|
|
|
|
switch (hpr) {
|
|
|
|
case PROMPT_FILAMENT_RUNOUT:
|
|
|
|
msg = PSTR("FILAMENT_RUNOUT");
|
|
|
|
if (response == 0) {
|
2019-08-01 00:21:25 +02:00
|
|
|
#if ENABLED(ADVANCED_PAUSE_FEATURE)
|
|
|
|
pause_menu_response = PAUSE_RESPONSE_EXTRUDE_MORE;
|
|
|
|
#endif
|
2019-02-12 22:55:47 +01:00
|
|
|
host_action_prompt_end(); // Close current prompt
|
|
|
|
host_action_prompt_begin(PSTR("Paused"));
|
|
|
|
host_action_prompt_button(PSTR("Purge More"));
|
|
|
|
if (false
|
2019-02-13 03:08:34 +01:00
|
|
|
#if HAS_FILAMENT_SENSOR
|
2019-02-12 22:55:47 +01:00
|
|
|
|| runout.filament_ran_out
|
|
|
|
#endif
|
|
|
|
)
|
|
|
|
host_action_prompt_button(PSTR("DisableRunout"));
|
|
|
|
else {
|
|
|
|
host_prompt_reason = PROMPT_FILAMENT_RUNOUT;
|
2019-11-29 11:45:07 +01:00
|
|
|
host_action_prompt_button(CONTINUE_STR);
|
2019-02-12 22:55:47 +01:00
|
|
|
}
|
|
|
|
host_action_prompt_show();
|
|
|
|
}
|
|
|
|
else if (response == 1) {
|
2019-02-13 03:08:34 +01:00
|
|
|
#if HAS_FILAMENT_SENSOR
|
2019-02-12 22:55:47 +01:00
|
|
|
if (runout.filament_ran_out) {
|
|
|
|
runout.enabled = false;
|
|
|
|
runout.reset();
|
|
|
|
}
|
|
|
|
#endif
|
2019-08-01 00:21:25 +02:00
|
|
|
#if ENABLED(ADVANCED_PAUSE_FEATURE)
|
|
|
|
pause_menu_response = PAUSE_RESPONSE_RESUME_PRINT;
|
|
|
|
#endif
|
2019-02-12 22:55:47 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PROMPT_USER_CONTINUE:
|
2019-08-02 18:34:10 +02:00
|
|
|
#if HAS_RESUME_CONTINUE
|
|
|
|
wait_for_user = false;
|
|
|
|
#endif
|
2019-02-12 22:55:47 +01:00
|
|
|
msg = PSTR("FILAMENT_RUNOUT_CONTINUE");
|
|
|
|
break;
|
|
|
|
case PROMPT_PAUSE_RESUME:
|
|
|
|
msg = PSTR("LCD_PAUSE_RESUME");
|
2019-08-01 00:21:25 +02:00
|
|
|
#if ENABLED(ADVANCED_PAUSE_FEATURE)
|
2019-11-02 05:51:25 +01:00
|
|
|
extern const char M24_STR[];
|
|
|
|
queue.inject_P(M24_STR);
|
2019-08-01 00:21:25 +02:00
|
|
|
#endif
|
2019-02-12 22:55:47 +01:00
|
|
|
break;
|
2019-09-28 00:06:26 +02:00
|
|
|
case PROMPT_INFO:
|
|
|
|
msg = PSTR("GCODE_INFO");
|
|
|
|
break;
|
2019-02-12 22:55:47 +01:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
say_m876_response(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // HOST_PROMPT_SUPPORT
|
|
|
|
|
|
|
|
#endif // HOST_ACTION_COMMANDS
|