Browse Source

Fix broken enqueue_P

Scott Lahteine 4 years ago
parent
commit
4e3a793f1e
3 changed files with 23 additions and 8 deletions
  1. 2
    2
      Marlin/src/MarlinCore.cpp
  2. 15
    0
      Marlin/src/gcode/queue.cpp
  3. 6
    6
      Marlin/src/gcode/queue.h

+ 2
- 2
Marlin/src/MarlinCore.cpp View File

@@ -423,14 +423,14 @@ void startOrResumeJob() {
423 423
 
424 424
       #if HAS_RESUME_CONTINUE                   // Display "Click to Continue..."
425 425
         case 1:                                 // 30 min timeout with LCD, 1 min without
426
-          did_state = queue.enqueue_P(PSTR("M0Q1S" TERN(HAS_LCD_MENU, "1800", "60")));
426
+          did_state = queue.enqueue_one_P(PSTR("M0Q1S" TERN(HAS_LCD_MENU, "1800", "60")));
427 427
           break;
428 428
       #endif
429 429
 
430 430
       case 2: print_job_timer.stop(); break;
431 431
 
432 432
       case 3:
433
-        did_state = print_job_timer.duration() < 60 || queue.enqueue_P(PSTR("M31"));
433
+        did_state = print_job_timer.duration() < 60 || queue.enqueue_one_P(PSTR("M31"));
434 434
         break;
435 435
 
436 436
       case 4:

+ 15
- 0
Marlin/src/gcode/queue.cpp View File

@@ -210,6 +210,21 @@ void GCodeQueue::inject_P(PGM_P const pgcode) { injected_commands_P = pgcode; }
210 210
 void GCodeQueue::enqueue_one_now(const char* cmd) { while (!enqueue_one(cmd)) idle(); }
211 211
 
212 212
 /**
213
+ * Attempt to enqueue a single G-code command
214
+ * and return 'true' if successful.
215
+ */
216
+bool GCodeQueue::enqueue_one_P(PGM_P const pgcode) {
217
+  size_t i = 0;
218
+  PGM_P p = pgcode;
219
+  char c;
220
+  while ((c = pgm_read_byte(&p[i])) && c != '\n') i++;
221
+  char cmd[i + 1];
222
+  memcpy_P(cmd, p, i);
223
+  cmd[i] = '\0';
224
+  return _enqueue(cmd);
225
+}
226
+
227
+/**
213 228
  * Enqueue from program memory and return only when commands are actually enqueued
214 229
  * Never call this from a G-code handler!
215 230
  */

+ 6
- 6
Marlin/src/gcode/queue.h View File

@@ -78,6 +78,12 @@ public:
78 78
   static void enqueue_one_now(const char* cmd);
79 79
 
80 80
   /**
81
+   * Attempt to enqueue a single G-code command
82
+   * and return 'true' if successful.
83
+   */
84
+  static bool enqueue_one_P(PGM_P const pgcode);
85
+
86
+  /**
81 87
    * Enqueue from program memory and return only when commands are actually enqueued
82 88
    */
83 89
   static void enqueue_now_P(PGM_P const cmd);
@@ -117,12 +123,6 @@ public:
117 123
    */
118 124
   static void flush_and_request_resend();
119 125
 
120
-  /**
121
-   * Attempt to enqueue a single G-code command
122
-   * and return 'true' if successful.
123
-   */
124
-  FORCE_INLINE static bool enqueue_P(const char* cmd) { return _enqueue(cmd); }
125
-
126 126
 private:
127 127
 
128 128
   static uint8_t index_w;  // Ring buffer write position

Loading…
Cancel
Save