Browse Source

Support more filament runout sensors in M119 (#11851)

Scott Lahteine 6 years ago
parent
commit
09a2bee8aa
No account linked to committer's email address
3 changed files with 84 additions and 25 deletions
  1. 16
    16
      Marlin/src/core/language.h
  2. 53
    9
      Marlin/src/module/endstops.cpp
  3. 15
    0
      Marlin/src/pins/pinsDebug_list.h

+ 16
- 16
Marlin/src/core/language.h View File

@@ -139,25 +139,25 @@
139 139
 #define MSG_RESEND                          "Resend: "
140 140
 #define MSG_UNKNOWN_COMMAND                 "Unknown command: \""
141 141
 #define MSG_ACTIVE_EXTRUDER                 "Active Extruder: "
142
-#define MSG_X_MIN                           "x_min: "
143
-#define MSG_X_MAX                           "x_max: "
144
-#define MSG_X2_MIN                          "x2_min: "
145
-#define MSG_X2_MAX                          "x2_max: "
146
-#define MSG_Y_MIN                           "y_min: "
147
-#define MSG_Y_MAX                           "y_max: "
148
-#define MSG_Y2_MIN                          "y2_min: "
149
-#define MSG_Y2_MAX                          "y2_max: "
150
-#define MSG_Z_MIN                           "z_min: "
151
-#define MSG_Z_MAX                           "z_max: "
152
-#define MSG_Z2_MIN                          "z2_min: "
153
-#define MSG_Z2_MAX                          "z2_max: "
154
-#define MSG_Z3_MIN                          "z3_min: "
155
-#define MSG_Z3_MAX                          "z3_max: "
156
-#define MSG_Z_PROBE                         "z_probe: "
142
+#define MSG_X_MIN                           "x_min"
143
+#define MSG_X_MAX                           "x_max"
144
+#define MSG_X2_MIN                          "x2_min"
145
+#define MSG_X2_MAX                          "x2_max"
146
+#define MSG_Y_MIN                           "y_min"
147
+#define MSG_Y_MAX                           "y_max"
148
+#define MSG_Y2_MIN                          "y2_min"
149
+#define MSG_Y2_MAX                          "y2_max"
150
+#define MSG_Z_MIN                           "z_min"
151
+#define MSG_Z_MAX                           "z_max"
152
+#define MSG_Z2_MIN                          "z2_min"
153
+#define MSG_Z2_MAX                          "z2_max"
154
+#define MSG_Z3_MIN                          "z3_min"
155
+#define MSG_Z3_MAX                          "z3_max"
156
+#define MSG_Z_PROBE                         "z_probe"
157
+#define MSG_FILAMENT_RUNOUT_SENSOR          "filament"
157 158
 #define MSG_PROBE_Z_OFFSET                  "Probe Z Offset"
158 159
 #define MSG_SKEW_MIN                        "min_skew_factor: "
159 160
 #define MSG_SKEW_MAX                        "max_skew_factor: "
160
-#define MSG_FILAMENT_RUNOUT_SENSOR          "filament: "
161 161
 #define MSG_ERR_MATERIAL_INDEX              "M145 S<index> out of range (0-1)"
162 162
 #define MSG_ERR_M355_NONE                   "No case light"
163 163
 #define MSG_ERR_M421_PARAMETERS             "M421 incorrect parameter usage"

+ 53
- 9
Marlin/src/module/endstops.cpp View File

@@ -358,12 +358,16 @@ void Endstops::event_handler() {
358 358
   prev_hit_state = hit_state;
359 359
 } // Endstops::report_state
360 360
 
361
-void Endstops::M119() {
361
+static void print_es_state(const bool is_hit, const char * const label=NULL) {
362
+  if (label) serialprintPGM(label);
363
+  SERIAL_PROTOCOLPGM(": ");
364
+  serialprintPGM(is_hit ? PSTR(MSG_ENDSTOP_HIT) : PSTR(MSG_ENDSTOP_OPEN));
365
+  SERIAL_EOL();
366
+}
367
+
368
+void _O2 Endstops::M119() {
362 369
   SERIAL_PROTOCOLLNPGM(MSG_M119_REPORT);
363
-  #define ES_REPORT(AXIS) do{ \
364
-    SERIAL_PROTOCOLPGM(MSG_##AXIS); \
365
-    SERIAL_PROTOCOLLN(((READ(AXIS##_PIN)^AXIS##_ENDSTOP_INVERTING) ? MSG_ENDSTOP_HIT : MSG_ENDSTOP_OPEN)); \
366
-  }while(0)
370
+  #define ES_REPORT(S) print_es_state(READ(S##_PIN) == S##_ENDSTOP_INVERTING, PSTR(MSG_##S))
367 371
   #if HAS_X_MIN
368 372
     ES_REPORT(X_MIN);
369 373
   #endif
@@ -407,12 +411,52 @@ void Endstops::M119() {
407 411
     ES_REPORT(Z3_MAX);
408 412
   #endif
409 413
   #if ENABLED(Z_MIN_PROBE_ENDSTOP)
410
-    SERIAL_PROTOCOLPGM(MSG_Z_PROBE);
411
-    SERIAL_PROTOCOLLN(((READ(Z_MIN_PROBE_PIN)^Z_MIN_PROBE_ENDSTOP_INVERTING) ? MSG_ENDSTOP_HIT : MSG_ENDSTOP_OPEN));
414
+    print_es_state(READ(Z_MIN_PROBE_PIN) == Z_MIN_PROBE_ENDSTOP_INVERTING, PSTR(MSG_Z_PROBE));
412 415
   #endif
413 416
   #if ENABLED(FILAMENT_RUNOUT_SENSOR)
414
-    SERIAL_PROTOCOLPGM(MSG_FILAMENT_RUNOUT_SENSOR);
415
-    SERIAL_PROTOCOLLN(((READ(FIL_RUNOUT_PIN)^FIL_RUNOUT_INVERTING) ? MSG_ENDSTOP_HIT : MSG_ENDSTOP_OPEN));
417
+    #define FRS_COUNT (1 + PIN_EXISTS(FIL_RUNOUT2) + PIN_EXISTS(FIL_RUNOUT3) + PIN_EXISTS(FIL_RUNOUT4) + PIN_EXISTS(FIL_RUNOUT5) + PIN_EXISTS(FIL_RUNOUT6))
418
+    #if FRS_COUNT == 1
419
+      print_es_state(READ(FIL_RUNOUT_PIN) == FIL_RUNOUT_INVERTING, MSG_FILAMENT_RUNOUT_SENSOR);
420
+    #else
421
+      for (uint8_t i = 1; i <=
422
+        #if   FRS_COUNT == 6
423
+          6
424
+        #elif FRS_COUNT == 5
425
+          5
426
+        #elif FRS_COUNT == 4
427
+          4
428
+        #elif FRS_COUNT == 3
429
+          3
430
+        #elif FRS_COUNT == 2
431
+          2
432
+        #endif
433
+        ; i++
434
+      ) {
435
+        pin_t pin;
436
+        switch (i) {
437
+          default: continue;
438
+          case 1: pin = FIL_RUNOUT_PIN; break;
439
+          #if PIN_EXISTS(FIL_RUNOUT2)
440
+            case 2: pin = FIL_RUNOUT2_PIN; break;
441
+          #endif
442
+          #if PIN_EXISTS(FIL_RUNOUT3)
443
+            case 3: pin = FIL_RUNOUT3_PIN; break;
444
+          #endif
445
+          #if PIN_EXISTS(FIL_RUNOUT4)
446
+            case 4: pin = FIL_RUNOUT4_PIN; break;
447
+          #endif
448
+          #if PIN_EXISTS(FIL_RUNOUT5)
449
+            case 5: pin = FIL_RUNOUT5_PIN; break;
450
+          #endif
451
+          #if PIN_EXISTS(FIL_RUNOUT6)
452
+            case 6: pin = FIL_RUNOUT6_PIN; break;
453
+          #endif
454
+        }
455
+        SERIAL_PROTOCOLPGM(MSG_FILAMENT_RUNOUT_SENSOR);
456
+        if (i > 1) { SERIAL_CHAR(' '); SERIAL_CHAR('0' + i); }
457
+        print_es_state(digitalRead(pin) == FIL_RUNOUT_INVERTING);
458
+      }
459
+    #endif
416 460
   #endif
417 461
 } // Endstops::M119
418 462
 

+ 15
- 0
Marlin/src/pins/pinsDebug_list.h View File

@@ -467,6 +467,21 @@
467 467
 #if PIN_EXISTS(FIL_RUNOUT)
468 468
   REPORT_NAME_DIGITAL(__LINE__, FIL_RUNOUT_PIN)
469 469
 #endif
470
+#if PIN_EXISTS(FIL_RUNOUT2)
471
+  REPORT_NAME_DIGITAL(__LINE__, FIL_RUNOUT2_PIN)
472
+#endif
473
+#if PIN_EXISTS(FIL_RUNOUT3)
474
+  REPORT_NAME_DIGITAL(__LINE__, FIL_RUNOUT3_PIN)
475
+#endif
476
+#if PIN_EXISTS(FIL_RUNOUT4)
477
+  REPORT_NAME_DIGITAL(__LINE__, FIL_RUNOUT4_PIN)
478
+#endif
479
+#if PIN_EXISTS(FIL_RUNOUT5)
480
+  REPORT_NAME_DIGITAL(__LINE__, FIL_RUNOUT5_PIN)
481
+#endif
482
+#if PIN_EXISTS(FIL_RUNOUT6)
483
+  REPORT_NAME_DIGITAL(__LINE__, FIL_RUNOUT6_PIN)
484
+#endif
470 485
 #if PIN_EXISTS(HEATER_0)
471 486
   REPORT_NAME_DIGITAL(__LINE__, HEATER_0_PIN)
472 487
 #endif

Loading…
Cancel
Save