@@ -64,7 +64,8 @@ void host_action(const char * const pstr, const bool eol) {
64
64
65
65
#if ENABLED(HOST_PROMPT_SUPPORT)
66
66
67
- const char CONTINUE_STR[] PROGMEM = " Continue" ;
67
+ const char CONTINUE_STR[] PROGMEM = " Continue" ,
68
+ DISMISS_STR[] PROGMEM = " Dismiss" ;
68
69
69
70
#if HAS_RESUME_CONTINUE
70
71
extern bool wait_for_user;
@@ -84,70 +85,78 @@ void host_action(const char * const pstr, const bool eol) {
84
85
if (eol) SERIAL_EOL ();
85
86
}
86
87
87
- void host_action_prompt_plus (const char * const ptype, const char * const pstr, const bool eol= true ) {
88
+ void host_action_prompt_plus (const char * const ptype, const char * const pstr, const char extra_char= ' \0 ' ) {
88
89
host_action_prompt (ptype, false );
89
90
SERIAL_CHAR (' ' );
90
91
serialprintPGM (pstr);
91
- if (eol) SERIAL_EOL ();
92
+ if (extra_char != ' \0 ' ) SERIAL_CHAR (extra_char);
93
+ SERIAL_EOL ();
94
+ }
95
+ void host_action_prompt_begin (const PromptReason reason, const char * const pstr, const char extra_char/* ='\0'*/ ) {
96
+ host_action_prompt_end ();
97
+ host_prompt_reason = reason;
98
+ host_action_prompt_plus (PSTR (" begin" ), pstr, extra_char);
92
99
}
93
- void host_action_prompt_begin (const char * const pstr, const bool eol/* =true*/ ) { host_action_prompt_plus (PSTR (" begin" ), pstr, eol); }
94
100
void host_action_prompt_button (const char * const pstr) { host_action_prompt_plus (PSTR (" button" ), pstr); }
95
101
void host_action_prompt_end () { host_action_prompt (PSTR (" end" )); }
96
102
void host_action_prompt_show () { host_action_prompt (PSTR (" show" )); }
97
- void host_prompt_do (const PromptReason reason, const char * const pstr, const char * const pbtn/* =nullptr*/ ) {
98
- host_prompt_reason = reason;
99
- host_action_prompt_end ();
100
- host_action_prompt_begin (pstr);
101
- if (pbtn) host_action_prompt_button (pbtn);
103
+ void host_prompt_do (const PromptReason reason, const char * const pstr, const char * const btn1/* =nullptr*/ , const char * const btn2/* =nullptr*/ ) {
104
+ host_action_prompt_begin (reason, pstr);
105
+ if (btn1) host_action_prompt_button (btn1);
106
+ if (btn2) host_action_prompt_button (btn2);
102
107
host_action_prompt_show ();
103
108
}
104
109
105
- inline void say_m876_response (const char * const pstr) {
106
- SERIAL_ECHOPGM (" M876 Responding PROMPT_" );
107
- serialprintPGM (pstr);
108
- SERIAL_EOL ();
110
+ void filament_load_host_prompt () {
111
+ const bool disable_to_continue = (false
112
+ #if HAS_FILAMENT_SENSOR
113
+ || runout.filament_ran_out
114
+ #endif
115
+ );
116
+ host_prompt_do (PROMPT_FILAMENT_RUNOUT, PSTR (" Paused" ), PSTR (" PurgeMore" ),
117
+ disable_to_continue ? PSTR (" DisableRunout" ) : CONTINUE_STR
118
+ );
109
119
}
110
120
121
+ //
122
+ // Handle responses from the host, such as:
123
+ // - Filament runout responses: Purge More, Continue
124
+ // - General "Continue" response
125
+ // - Resume Print response
126
+ // - Dismissal of info
127
+ //
111
128
void host_response_handler (const uint8_t response) {
112
129
#ifdef DEBUG_HOST_ACTIONS
113
- SERIAL_ECHOLNPAIR (" M876 Handle Reason: " , host_prompt_reason);
114
- SERIAL_ECHOLNPAIR (" M876 Handle Response: " , response);
130
+ static const char m876_prefix[] PROGMEM = " M876 Handle Re" ;
131
+ serialprintPGM (m876_prefix); SERIAL_ECHOLNPAIR (" ason: " , host_prompt_reason);
132
+ serialprintPGM (m876_prefix); SERIAL_ECHOLNPAIR (" sponse: " , response);
115
133
#endif
116
134
const char *msg = PSTR (" UNKNOWN STATE" );
117
135
const PromptReason hpr = host_prompt_reason;
118
- host_prompt_reason = PROMPT_NOT_DEFINED;
136
+ host_prompt_reason = PROMPT_NOT_DEFINED; // Reset now ahead of logic
119
137
switch (hpr) {
120
138
case PROMPT_FILAMENT_RUNOUT:
121
139
msg = PSTR (" FILAMENT_RUNOUT" );
122
- if (response == 0 ) {
123
- #if ENABLED(ADVANCED_PAUSE_FEATURE)
124
- pause_menu_response = PAUSE_RESPONSE_EXTRUDE_MORE;
125
- #endif
126
- host_action_prompt_end (); // Close current prompt
127
- host_action_prompt_begin (PSTR (" Paused" ));
128
- host_action_prompt_button (PSTR (" Purge More" ));
129
- if (false
140
+ switch (response) {
141
+
142
+ case 0 : // "Purge More" button
143
+ #if HAS_LCD_MENU && ENABLED(ADVANCED_PAUSE_FEATURE)
144
+ pause_menu_response = PAUSE_RESPONSE_EXTRUDE_MORE; // Simulate menu selection (menu exits, doesn't extrude more)
145
+ #endif
146
+ filament_load_host_prompt (); // Initiate another host prompt. (NOTE: The loop in load_filament may also do this!)
147
+ break ;
148
+
149
+ case 1 : // "Continue" / "Disable Runout" button
150
+ #if HAS_LCD_MENU && ENABLED(ADVANCED_PAUSE_FEATURE)
151
+ pause_menu_response = PAUSE_RESPONSE_RESUME_PRINT; // Simulate menu selection
152
+ #endif
130
153
#if HAS_FILAMENT_SENSOR
131
- || runout.filament_ran_out
154
+ if (runout.filament_ran_out ) { // Disable a triggered sensor
155
+ runout.enabled = false ;
156
+ runout.reset ();
157
+ }
132
158
#endif
133
- )
134
- host_action_prompt_button (PSTR (" DisableRunout" ));
135
- else {
136
- host_prompt_reason = PROMPT_FILAMENT_RUNOUT;
137
- host_action_prompt_button (CONTINUE_STR);
138
- }
139
- host_action_prompt_show ();
140
- }
141
- else if (response == 1 ) {
142
- #if HAS_FILAMENT_SENSOR
143
- if (runout.filament_ran_out ) {
144
- runout.enabled = false ;
145
- runout.reset ();
146
- }
147
- #endif
148
- #if ENABLED(ADVANCED_PAUSE_FEATURE)
149
- pause_menu_response = PAUSE_RESPONSE_RESUME_PRINT;
150
- #endif
159
+ break ;
151
160
}
152
161
break ;
153
162
case PROMPT_USER_CONTINUE:
@@ -168,7 +177,9 @@ void host_action(const char * const pstr, const bool eol) {
168
177
break ;
169
178
default : break ;
170
179
}
171
- say_m876_response (msg);
180
+ SERIAL_ECHOPGM (" M876 Responding PROMPT_" );
181
+ serialprintPGM (msg);
182
+ SERIAL_EOL ();
172
183
}
173
184
174
185
#endif // HOST_PROMPT_SUPPORT
0 commit comments