Przeglądaj źródła

Allow servo features in combination (#16960)

Scott Lahteine 4 lat temu
rodzic
commit
0a7e7a6fa5
No account linked to committer's email address

+ 0
- 3
Marlin/src/feature/bltouch.h Wyświetl plik

@@ -105,7 +105,4 @@ private:
105 105
   static void mode_conv_proc(const bool M5V);
106 106
 };
107 107
 
108
-// Deploy/stow angles for use by servo.cpp / servo.h
109
-#define BLTOUCH_ANGLES { BLTOUCH_DEPLOY, BLTOUCH_STOW }
110
-
111 108
 extern BLTouch bltouch;

+ 6
- 0
Marlin/src/gcode/config/M281.cpp Wyświetl plik

@@ -30,6 +30,12 @@ void GcodeSuite::M281() {
30 30
   if (!parser.seenval('P')) return;
31 31
   const int servo_index = parser.value_int();
32 32
   if (WITHIN(servo_index, 0, NUM_SERVOS - 1)) {
33
+    #if ENABLED(BLTOUCH)
34
+      if (servo_index == Z_PROBE_SERVO_NR) {
35
+        SERIAL_ERROR_MSG("BLTouch angles can't be changed.");
36
+        return;
37
+      }
38
+    #endif
33 39
     bool angle_change = false;
34 40
     if (parser.seen('L')) {
35 41
       servo_angles[servo_index][0] = parser.value_int();

+ 4
- 0
Marlin/src/inc/Conditionals_LCD.h Wyświetl plik

@@ -502,6 +502,10 @@
502 502
  * Set a flag for a servo probe (or BLTouch)
503 503
  */
504 504
 #define HAS_Z_SERVO_PROBE (defined(Z_PROBE_SERVO_NR) && Z_PROBE_SERVO_NR >= 0)
505
+#define HAS_SERVO_ANGLES (HAS_Z_SERVO_PROBE || EITHER(SWITCHING_EXTRUDER, SWITCHING_NOZZLE))
506
+#if !HAS_SERVO_ANGLES
507
+  #undef EDITABLE_SERVO_ANGLES
508
+#endif
505 509
 
506 510
 /**
507 511
  * Set flags for enabled probes

+ 0
- 10
Marlin/src/inc/Conditionals_post.h Wyświetl plik

@@ -1546,16 +1546,6 @@
1546 1546
 #define HAS_SERVO_3 (PIN_EXISTS(SERVO3) && NUM_SERVOS > 3)
1547 1547
 #define HAS_SERVOS  (NUM_SERVOS > 0)
1548 1548
 
1549
-#if HAS_SERVOS && !defined(Z_PROBE_SERVO_NR)
1550
-  #define Z_PROBE_SERVO_NR -1
1551
-#endif
1552
-
1553
-#define HAS_SERVO_ANGLES (EITHER(SWITCHING_EXTRUDER, SWITCHING_NOZZLE) || (HAS_Z_SERVO_PROBE && defined(Z_PROBE_SERVO_NR)))
1554
-
1555
-#if !HAS_SERVO_ANGLES || ENABLED(BLTOUCH)
1556
-  #undef EDITABLE_SERVO_ANGLES
1557
-#endif
1558
-
1559 1549
 // Sensors
1560 1550
 #define HAS_FILAMENT_WIDTH_SENSOR (PIN_EXISTS(FILWIDTH))
1561 1551
 

+ 2
- 2
Marlin/src/module/configuration_store.cpp Wyświetl plik

@@ -2541,7 +2541,7 @@ void MarlinSettings::reset() {
2541 2541
   //
2542 2542
 
2543 2543
   #if ENABLED(EDITABLE_SERVO_ANGLES)
2544
-    COPY(servo_angles, base_servo_angles);
2544
+    COPY(servo_angles, base_servo_angles);  // When not editable only one copy of servo angles exists
2545 2545
   #endif
2546 2546
 
2547 2547
   //
@@ -3091,7 +3091,7 @@ void MarlinSettings::reset() {
3091 3091
             #endif
3092 3092
           #elif ENABLED(SWITCHING_NOZZLE)
3093 3093
             case SWITCHING_NOZZLE_SERVO_NR:
3094
-          #elif (ENABLED(BLTOUCH) && defined(BLTOUCH_ANGLES)) || (defined(Z_SERVO_ANGLES) && defined(Z_PROBE_SERVO_NR))
3094
+          #elif ENABLED(BLTOUCH) || (HAS_Z_SERVO_PROBE && defined(Z_SERVO_ANGLES))
3095 3095
             case Z_PROBE_SERVO_NR:
3096 3096
           #endif
3097 3097
             CONFIG_ECHO_START();

+ 44
- 25
Marlin/src/module/servo.h Wyświetl plik

@@ -31,46 +31,65 @@
31 31
 #if HAS_SERVO_ANGLES
32 32
 
33 33
   #if ENABLED(SWITCHING_EXTRUDER)
34
-    #ifndef SWITCHING_EXTRUDER_E23_SERVO_NR
35
-      #define SWITCHING_EXTRUDER_E23_SERVO_NR -1
36
-    #endif
34
+    // Switching extruder can have 2 or 4 angles
37 35
     #if EXTRUDERS > 3
38 36
       #define REQ_ANGLES 4
39 37
     #else
40 38
       #define REQ_ANGLES 2
41 39
     #endif
42
-    #define SADATA    SWITCHING_EXTRUDER_SERVO_ANGLES
43
-    #define ASRC(N,E) (SWITCHING_EXTRUDER_SERVO_NR == N ? asrc[E] : SWITCHING_EXTRUDER_E23_SERVO_NR == N ? asrc[E+2] : 0)
44
-  #elif ENABLED(SWITCHING_NOZZLE)
45
-    #define SADATA    SWITCHING_NOZZLE_SERVO_ANGLES
46
-    #define ASRC(N,E) (SWITCHING_NOZZLE_SERVO_NR == N ? asrc[E] : 0)
47
-  #elif defined(Z_PROBE_SERVO_NR)
48
-    #define ASRC(N,E) (Z_PROBE_SERVO_NR == N ? asrc[E] : 0)
40
+    constexpr uint16_t sase[] = SWITCHING_EXTRUDER_SERVO_ANGLES;
41
+    static_assert(COUNT(sase) == REQ_ANGLES, "SWITCHING_EXTRUDER_SERVO_ANGLES needs " STRINGIFY(REQ_ANGLES) " angles.");
42
+  #else
43
+    constexpr uint16_t sase[4] = { 0 };
44
+  #endif
45
+
46
+  #if ENABLED(SWITCHING_NOZZLE)
47
+    constexpr uint16_t sasn[] = SWITCHING_NOZZLE_SERVO_ANGLES;
48
+    static_assert(COUNT(sasn) == 2, "SWITCHING_NOZZLE_SERVO_ANGLES needs 2 angles.");
49
+  #else
50
+    constexpr uint16_t sasn[2] = { 0 };
51
+  #endif
52
+
53
+  #ifdef Z_PROBE_SERVO_NR
49 54
     #if ENABLED(BLTOUCH)
50 55
       #include "../feature/bltouch.h"
56
+      #undef Z_SERVO_ANGLES
57
+      #define Z_SERVO_ANGLES { BLTOUCH_DEPLOY, BLTOUCH_STOW }
51 58
     #endif
52
-    #ifdef BLTOUCH_ANGLES
53
-      #define SADATA  BLTOUCH_ANGLES
54
-    #elif defined(Z_SERVO_ANGLES)
55
-      #define SADATA  Z_SERVO_ANGLES
56
-    #else
57
-      #error "Servo angles are needed!"
58
-    #endif
59
+    constexpr uint16_t sazp[] = Z_SERVO_ANGLES;
60
+    static_assert(COUNT(sazp) == 2, "Z_SERVO_ANGLES needs 2 angles.");
61
+  #else
62
+    constexpr uint16_t sazp[2] = { 0 };
59 63
   #endif
60 64
 
65
+  #ifndef SWITCHING_EXTRUDER_SERVO_NR
66
+    #define SWITCHING_EXTRUDER_SERVO_NR -1
67
+  #endif
68
+  #ifndef SWITCHING_EXTRUDER_E23_SERVO_NR
69
+    #define SWITCHING_EXTRUDER_E23_SERVO_NR -1
70
+  #endif
71
+  #ifndef SWITCHING_NOZZLE_SERVO_NR
72
+    #define SWITCHING_NOZZLE_SERVO_NR -1
73
+  #endif
74
+  #ifndef Z_PROBE_SERVO_NR
75
+    #define Z_PROBE_SERVO_NR -1
76
+  #endif
77
+
78
+  #define ASRC(N,I) (                                  \
79
+      N == SWITCHING_EXTRUDER_SERVO_NR     ? sase[I]   \
80
+    : N == SWITCHING_EXTRUDER_E23_SERVO_NR ? sase[I+2] \
81
+    : N == SWITCHING_NOZZLE_SERVO_NR       ? sasn[I]   \
82
+    : N == Z_PROBE_SERVO_NR                ? sazp[I]   \
83
+    : 0                                                )
84
+
61 85
   #if ENABLED(EDITABLE_SERVO_ANGLES)
62 86
     extern uint16_t servo_angles[NUM_SERVOS][2];
63
-    #define BASE_SERVO_ANGLES base_servo_angles
87
+    #define CONST_SERVO_ANGLES base_servo_angles
64 88
   #else
65
-    #define BASE_SERVO_ANGLES servo_angles
66
-  #endif
67
-
68
-  constexpr uint16_t asrc[] = SADATA;
69
-  #if REQ_ANGLES
70
-    static_assert(COUNT(asrc) == REQ_ANGLES, "SWITCHING_EXTRUDER_SERVO_ANGLES needs " STRINGIFY(REQ_ANGLES) " angles.");
89
+    #define CONST_SERVO_ANGLES servo_angles
71 90
   #endif
72 91
 
73
-  constexpr uint16_t BASE_SERVO_ANGLES [NUM_SERVOS][2] = {
92
+  constexpr uint16_t CONST_SERVO_ANGLES [NUM_SERVOS][2] = {
74 93
       { ASRC(0,0), ASRC(0,1) }
75 94
     #if NUM_SERVOS > 1
76 95
       , { ASRC(1,0), ASRC(1,1) }

Ładowanie…
Anuluj
Zapisz