Add Host Prompt Notification Method (#15942)

This commit is contained in:
InsanityAutomation 2019-12-01 18:39:28 -05:00 committed by Scott Lahteine
parent c061656659
commit 7126a5e5a7
4 changed files with 58 additions and 9 deletions

View file

@ -72,6 +72,12 @@ void host_action(const char * const pstr, const bool eol) {
PromptReason host_prompt_reason = PROMPT_NOT_DEFINED; PromptReason host_prompt_reason = PROMPT_NOT_DEFINED;
void host_action_notify(const char * const message) {
host_action(PSTR("notification "), false);
serialprintPGM(message);
SERIAL_EOL();
}
void host_action_prompt(const char * const ptype, const bool eol=true) { void host_action_prompt(const char * const ptype, const bool eol=true) {
host_action(PSTR("prompt_"), false); host_action(PSTR("prompt_"), false);
serialprintPGM(ptype); serialprintPGM(ptype);

View file

@ -60,6 +60,7 @@ void host_action(const char * const pstr, const bool eol=true);
extern PromptReason host_prompt_reason; extern PromptReason host_prompt_reason;
void host_response_handler(const uint8_t response); void host_response_handler(const uint8_t response);
void host_action_notify(const char * const message);
void host_action_prompt_begin(const char * const pstr, const bool eol=true); void host_action_prompt_begin(const char * const pstr, const bool eol=true);
void host_action_prompt_button(const char * const pstr); void host_action_prompt_button(const char * const pstr);
void host_action_prompt_end(); void host_action_prompt_end();

View file

@ -26,19 +26,21 @@
#include "../feature/leds/leds.h" #include "../feature/leds/leds.h"
#endif #endif
#if ENABLED(HOST_ACTION_COMMANDS)
#include "../feature/host_actions.h"
#endif
#include "ultralcd.h"
MarlinUI ui;
// All displays share the MarlinUI class // All displays share the MarlinUI class
#if HAS_DISPLAY #if HAS_DISPLAY
#include "../gcode/queue.h" #include "../gcode/queue.h"
#include "ultralcd.h"
#include "fontutils.h" #include "fontutils.h"
MarlinUI ui;
#include "../sd/cardreader.h" #include "../sd/cardreader.h"
#if ENABLED(EXTENSIBLE_UI) #if ENABLED(EXTENSIBLE_UI)
#define START_OF_UTF8_CHAR(C) (((C) & 0xC0u) != 0x80u) #define START_OF_UTF8_CHAR(C) (((C) & 0xC0u) != 0x80u)
#endif #endif
#if ENABLED(HOST_ACTION_COMMANDS)
#include "../feature/host_actions.h"
#endif
#endif #endif
#if HAS_SPI_LCD #if HAS_SPI_LCD
@ -1369,6 +1371,10 @@ void MarlinUI::update() {
void MarlinUI::set_status(const char * const message, const bool persist) { void MarlinUI::set_status(const char * const message, const bool persist) {
if (alert_level) return; if (alert_level) return;
#if ENABLED(HOST_PROMPT_SUPPORT)
host_action_notify(message);
#endif
// Here we have a problem. The message is encoded in UTF8, so // Here we have a problem. The message is encoded in UTF8, so
// arbitrarily cutting it will be a problem. We MUST be sure // arbitrarily cutting it will be a problem. We MUST be sure
// that there is no cutting in the middle of a multibyte character! // that there is no cutting in the middle of a multibyte character!
@ -1408,6 +1414,10 @@ void MarlinUI::update() {
if (level < alert_level) return; if (level < alert_level) return;
alert_level = level; alert_level = level;
#if ENABLED(HOST_PROMPT_SUPPORT)
host_action_notify(message);
#endif
// Since the message is encoded in UTF8 it must // Since the message is encoded in UTF8 it must
// only be cut on a character boundary. // only be cut on a character boundary.
@ -1568,4 +1578,34 @@ void MarlinUI::update() {
#endif #endif
#endif // HAS_DISPLAY #else // !HAS_DISPLAY
//
// Send the status line as a host notification
//
void MarlinUI::set_status(const char * const message, const bool) {
#if ENABLED(HOST_PROMPT_SUPPORT)
host_action_notify(message);
#else
UNUSED(message);
#endif
}
void MarlinUI::set_status_P(PGM_P message, const int8_t) {
#if ENABLED(HOST_PROMPT_SUPPORT)
host_action_notify(message);
#else
UNUSED(message);
#endif
}
void MarlinUI::status_printf_P(const uint8_t, PGM_P const message, ...) {
#if ENABLED(HOST_PROMPT_SUPPORT)
host_action_notify(message);
#else
UNUSED(message);
#endif
}
#endif // !HAS_DISPLAY

View file

@ -406,14 +406,16 @@ public:
#else // No LCD #else // No LCD
// Send status to host as a notification
void set_status(const char* message, const bool=false);
void set_status_P(PGM_P message, const int8_t=0);
void status_printf_P(const uint8_t, PGM_P message, ...);
static inline void init() {} static inline void init() {}
static inline void update() {} static inline void update() {}
static inline void refresh() {} static inline void refresh() {}
static inline void return_to_status() {} static inline void return_to_status() {}
static inline void set_alert_status_P(PGM_P const) {} static inline void set_alert_status_P(PGM_P const) {}
static inline void set_status(const char* const, const bool=false) {}
static inline void set_status_P(PGM_P const, const int8_t=0) {}
static inline void status_printf_P(const uint8_t, PGM_P const, ...) {}
static inline void reset_status() {} static inline void reset_status() {}
static inline void reset_alert_level() {} static inline void reset_alert_level() {}
static constexpr bool has_status() { return false; } static constexpr bool has_status() { return false; }