ソースを参照

Clean up host actions code (#16856)

Scott Lahteine 4年前
コミット
00ba053c90
コミッターのメールアドレスに関連付けられたアカウントが存在しません

+ 53
- 43
Marlin/src/feature/host_actions.cpp ファイルの表示

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

+ 6
- 4
Marlin/src/feature/host_actions.h ファイルの表示

@@ -61,13 +61,15 @@ void host_action(const char * const pstr, const bool eol=true);
61 61
 
62 62
   void host_response_handler(const uint8_t response);
63 63
   void host_action_notify(const char * const message);
64
-  void host_action_prompt_begin(const char * const pstr, const bool eol=true);
64
+  void host_action_prompt_begin(const PromptReason reason, const char * const pstr, const char extra_char='\0');
65 65
   void host_action_prompt_button(const char * const pstr);
66 66
   void host_action_prompt_end();
67 67
   void host_action_prompt_show();
68
-  void host_prompt_do(const PromptReason type, const char * const pstr, const char * const pbtn=nullptr);
69
-  inline void host_prompt_open(const PromptReason reason, const char * const pstr, const char * const pbtn=nullptr) {
70
-    if (host_prompt_reason == PROMPT_NOT_DEFINED) host_prompt_do(reason, pstr, pbtn);
68
+  void host_prompt_do(const PromptReason reason, const char * const pstr, const char * const btn1=nullptr, const char * const btn2=nullptr);
69
+  inline void host_prompt_open(const PromptReason reason, const char * const pstr, const char * const btn1=nullptr, const char * const btn2=nullptr) {
70
+    if (host_prompt_reason == PROMPT_NOT_DEFINED) host_prompt_do(reason, pstr, btn1, btn2);
71 71
   }
72 72
 
73
+  void filament_load_host_prompt();
74
+
73 75
 #endif

+ 14
- 27
Marlin/src/feature/pause.cpp ファイルの表示

@@ -67,9 +67,10 @@
67 67
 
68 68
 static xyze_pos_t resume_position;
69 69
 
70
-PauseMode pause_mode = PAUSE_MODE_PAUSE_PRINT;
71
-
72
-PauseMenuResponse pause_menu_response;
70
+#if HAS_LCD_MENU
71
+  PauseMenuResponse pause_menu_response;
72
+  PauseMode pause_mode = PAUSE_MODE_PAUSE_PRINT;
73
+#endif
73 74
 
74 75
 fil_change_settings_t fc_settings[EXTRUDERS];
75 76
 
@@ -85,7 +86,11 @@ fil_change_settings_t fc_settings[EXTRUDERS];
85 86
 
86 87
 #if HAS_BUZZER
87 88
   static void filament_change_beep(const int8_t max_beep_count, const bool init=false) {
88
-    if (pause_mode == PAUSE_MODE_PAUSE_PRINT) return;
89
+
90
+    #if HAS_LCD_MENU
91
+      if (pause_mode == PAUSE_MODE_PAUSE_PRINT) return;
92
+    #endif
93
+
89 94
     static millis_t next_buzz = 0;
90 95
     static int8_t runout_beep = 0;
91 96
 
@@ -186,11 +191,7 @@ bool load_filament(const float &slow_load_length/*=0*/, const float &fast_load_l
186 191
           + active_extruder
187 192
         #endif
188 193
       ;
189
-      host_prompt_reason = PROMPT_USER_CONTINUE;
190
-      host_action_prompt_end();
191
-      host_action_prompt_begin(PSTR("Load Filament T"), false);
192
-      SERIAL_CHAR(tool);
193
-      SERIAL_EOL();
194
+      host_action_prompt_begin(PROMPT_USER_CONTINUE, PSTR("Load Filament T"), tool);
194 195
       host_action_prompt_button(CONTINUE_STR);
195 196
       host_action_prompt_show();
196 197
     #endif
@@ -247,10 +248,10 @@ bool load_filament(const float &slow_load_length/*=0*/, const float &fast_load_l
247 248
 
248 249
     wait_for_user = true;
249 250
     #if ENABLED(HOST_PROMPT_SUPPORT)
250
-      host_prompt_do(PROMPT_USER_CONTINUE, PSTR("Filament Purge Running..."), CONTINUE_STR);
251
+      host_prompt_do(PROMPT_USER_CONTINUE, PSTR("Filament Purging..."), CONTINUE_STR);
251 252
     #endif
252 253
     #if ENABLED(EXTENSIBLE_UI)
253
-      ExtUI::onUserConfirmRequired_P(PSTR("Filament Purge Running..."));
254
+      ExtUI::onUserConfirmRequired_P(PSTR("Filament Purging..."));
254 255
     #endif
255 256
     for (float purge_count = purge_length; purge_count > 0 && wait_for_user; --purge_count)
256 257
       do_pause_e_move(1, ADVANCED_PAUSE_PURGE_FEEDRATE);
@@ -269,27 +270,13 @@ bool load_filament(const float &slow_load_length/*=0*/, const float &fast_load_l
269 270
         do_pause_e_move(purge_length, ADVANCED_PAUSE_PURGE_FEEDRATE);
270 271
       }
271 272
 
272
-      // Show "Purge More" / "Resume" menu and wait for reply
273 273
       #if ENABLED(HOST_PROMPT_SUPPORT)
274
-        host_prompt_reason = PROMPT_FILAMENT_RUNOUT;
275
-        host_action_prompt_end();   // Close current prompt
276
-        host_action_prompt_begin(PSTR("Paused"));
277
-        host_action_prompt_button(PSTR("PurgeMore"));
278
-        if (false
279
-          #if HAS_FILAMENT_SENSOR
280
-            || runout.filament_ran_out
281
-          #endif
282
-        )
283
-          host_action_prompt_button(PSTR("DisableRunout"));
284
-        else {
285
-          host_prompt_reason = PROMPT_FILAMENT_RUNOUT;
286
-          host_action_prompt_button(CONTINUE_STR);
287
-        }
288
-        host_action_prompt_show();
274
+        filament_load_host_prompt();  // Initiate another host prompt. (NOTE: host_response_handler may also do this!)
289 275
       #endif
290 276
 
291 277
       #if HAS_LCD_MENU
292 278
         if (show_lcd) {
279
+          // Show "Purge More" / "Resume" menu and wait for reply
293 280
           KEEPALIVE_STATE(PAUSED_FOR_USER);
294 281
           wait_for_user = false;
295 282
           lcd_pause_show_message(PAUSE_MESSAGE_OPTION);

+ 9
- 8
Marlin/src/feature/pause.h ファイルの表示

@@ -59,14 +59,15 @@ enum PauseMessage : char {
59 59
   PAUSE_MESSAGE_HEATING
60 60
 };
61 61
 
62
-enum PauseMenuResponse : char {
63
-  PAUSE_RESPONSE_WAIT_FOR,
64
-  PAUSE_RESPONSE_EXTRUDE_MORE,
65
-  PAUSE_RESPONSE_RESUME_PRINT
66
-};
67
-
68
-extern PauseMode pause_mode;
69
-extern PauseMenuResponse pause_menu_response;
62
+#if HAS_LCD_MENU
63
+  enum PauseMenuResponse : char {
64
+    PAUSE_RESPONSE_WAIT_FOR,
65
+    PAUSE_RESPONSE_EXTRUDE_MORE,
66
+    PAUSE_RESPONSE_RESUME_PRINT
67
+  };
68
+  extern PauseMenuResponse pause_menu_response;
69
+  extern PauseMode pause_mode;
70
+#endif
70 71
 
71 72
 extern fil_change_settings_t fc_settings[EXTRUDERS];
72 73
 

+ 1
- 5
Marlin/src/feature/runout.cpp ファイルの表示

@@ -92,11 +92,7 @@ void event_filament_runout() {
92 92
 
93 93
   //action:out_of_filament
94 94
   #if ENABLED(HOST_PROMPT_SUPPORT)
95
-    host_prompt_reason = PROMPT_FILAMENT_RUNOUT;
96
-    host_action_prompt_end();
97
-    host_action_prompt_begin(PSTR("FilamentRunout T"), false);
98
-    SERIAL_CHAR(tool);
99
-    SERIAL_EOL();
95
+    host_action_prompt_begin(PROMPT_FILAMENT_RUNOUT, PSTR("FilamentRunout T"), tool);
100 96
     host_action_prompt_show();
101 97
   #endif
102 98
 

+ 2
- 0
Marlin/src/gcode/host/M876.cpp ファイルの表示

@@ -31,7 +31,9 @@
31 31
  * M876: Handle Prompt Response
32 32
  */
33 33
 void GcodeSuite::M876() {
34
+
34 35
   if (parser.seenval('S')) host_response_handler((uint8_t)parser.value_int());
36
+
35 37
 }
36 38
 
37 39
 #endif // HOST_PROMPT_SUPPORT && !EMERGENCY_PARSER

読み込み中…
キャンセル
保存