Просмотр исходного кода

🩹 Fix non-PWM cutter compile (#23169)

Mike La Spina 3 лет назад
Родитель
Сommit
ea0d0e8e8b
Аккаунт пользователя с таким Email не найден

+ 4
- 8
Marlin/src/feature/spindle_laser.h Просмотреть файл

41
 #define PCT_TO_PWM(X) ((X) * 255 / 100)
41
 #define PCT_TO_PWM(X) ((X) * 255 / 100)
42
 #define PCT_TO_SERVO(X) ((X) * 180 / 100)
42
 #define PCT_TO_SERVO(X) ((X) * 180 / 100)
43
 
43
 
44
-#ifndef SPEED_POWER_INTERCEPT
45
-  #define SPEED_POWER_INTERCEPT 0
46
-#endif
47
-
48
 // #define _MAP(N,S1,S2,D1,D2) ((N)*_MAX((D2)-(D1),0)/_MAX((S2)-(S1),1)+(D1))
44
 // #define _MAP(N,S1,S2,D1,D2) ((N)*_MAX((D2)-(D1),0)/_MAX((S2)-(S1),1)+(D1))
49
 
45
 
50
 class SpindleLaser {
46
 class SpindleLaser {
51
 public:
47
 public:
52
-  static constexpr float
53
-    min_pct = TERN(CUTTER_POWER_RELATIVE, 0, TERN(SPINDLE_FEATURE, round(100.0f * (SPEED_POWER_MIN) / (SPEED_POWER_MAX)), SPEED_POWER_MIN)),
54
-    max_pct = TERN(SPINDLE_FEATURE, 100, SPEED_POWER_MAX);
55
-
56
   static const inline uint8_t pct_to_ocr(const_float_t pct) { return uint8_t(PCT_TO_PWM(pct)); }
48
   static const inline uint8_t pct_to_ocr(const_float_t pct) { return uint8_t(PCT_TO_PWM(pct)); }
57
 
49
 
58
   // cpower = configured values (e.g., SPEED_POWER_MAX)
50
   // cpower = configured values (e.g., SPEED_POWER_MAX)
158
     }
150
     }
159
 
151
 
160
     static inline cutter_power_t power_to_range(const cutter_power_t pwr, const uint8_t pwrUnit) {
152
     static inline cutter_power_t power_to_range(const cutter_power_t pwr, const uint8_t pwrUnit) {
153
+      static constexpr float
154
+        min_pct = TERN(CUTTER_POWER_RELATIVE, 0, TERN(SPINDLE_FEATURE, round(100.0f * (SPEED_POWER_MIN) / (SPEED_POWER_MAX)), SPEED_POWER_MIN)),
155
+        max_pct = TERN(SPINDLE_FEATURE, 100, SPEED_POWER_MAX);
161
       if (pwr <= 0) return 0;
156
       if (pwr <= 0) return 0;
162
       cutter_power_t upwr;
157
       cutter_power_t upwr;
163
       switch (pwrUnit) {
158
       switch (pwrUnit) {
186
       }
181
       }
187
       return upwr;
182
       return upwr;
188
     }
183
     }
184
+
189
   #endif // SPINDLE_LASER_USE_PWM
185
   #endif // SPINDLE_LASER_USE_PWM
190
 
186
 
191
   /**
187
   /**

+ 23
- 1
Marlin/src/feature/spindle_laser_types.h Просмотреть файл

28
 
28
 
29
 #include "../inc/MarlinConfigPre.h"
29
 #include "../inc/MarlinConfigPre.h"
30
 
30
 
31
+#define MSG_CUTTER(M) _MSG_CUTTER(M)
32
+
33
+#ifndef SPEED_POWER_INTERCEPT
34
+  #define SPEED_POWER_INTERCEPT 0
35
+#endif
31
 #if ENABLED(SPINDLE_FEATURE)
36
 #if ENABLED(SPINDLE_FEATURE)
32
   #define _MSG_CUTTER(M) MSG_SPINDLE_##M
37
   #define _MSG_CUTTER(M) MSG_SPINDLE_##M
38
+  #ifndef SPEED_POWER_MIN
39
+    #define SPEED_POWER_MIN      5000
40
+  #endif
41
+  #ifndef SPEED_POWER_MAX
42
+    #define SPEED_POWER_MAX     30000
43
+  #endif
44
+  #ifndef SPEED_POWER_STARTUP
45
+    #define SPEED_POWER_STARTUP 25000
46
+  #endif
33
 #else
47
 #else
34
   #define _MSG_CUTTER(M) MSG_LASER_##M
48
   #define _MSG_CUTTER(M) MSG_LASER_##M
49
+  #ifndef SPEED_POWER_MIN
50
+    #define SPEED_POWER_MIN         0
51
+  #endif
52
+  #ifndef SPEED_POWER_MAX
53
+    #define SPEED_POWER_MAX       255
54
+  #endif
55
+  #ifndef SPEED_POWER_STARTUP
56
+    #define SPEED_POWER_STARTUP   255
57
+  #endif
35
 #endif
58
 #endif
36
-#define MSG_CUTTER(M) _MSG_CUTTER(M)
37
 
59
 
38
 typedef IF<(SPEED_POWER_MAX > 255), uint16_t, uint8_t>::type cutter_cpower_t;
60
 typedef IF<(SPEED_POWER_MAX > 255), uint16_t, uint8_t>::type cutter_cpower_t;
39
 
61
 

+ 17
- 15
Marlin/src/gcode/control/M3-M5.cpp Просмотреть файл

66
  *  PWM duty cycle goes from 0 (off) to 255 (always on).
66
  *  PWM duty cycle goes from 0 (off) to 255 (always on).
67
  */
67
  */
68
 void GcodeSuite::M3_M4(const bool is_M4) {
68
 void GcodeSuite::M3_M4(const bool is_M4) {
69
-  auto get_s_power = [] {
70
-    if (parser.seenval('S')) {
71
-      const float spwr = parser.value_float();
72
-      #if ENABLED(SPINDLE_SERVO)
73
-        cutter.unitPower = spwr;
74
-      #else
75
-        cutter.unitPower = TERN(SPINDLE_LASER_USE_PWM,
76
-                              cutter.power_to_range(cutter_power_t(round(spwr))),
77
-                              spwr > 0 ? 255 : 0);
78
-      #endif
79
-    }
80
-    else
81
-      cutter.unitPower = cutter.cpwr_to_upwr(SPEED_POWER_STARTUP);
82
-    return cutter.unitPower;
83
-  };
69
+  #if EITHER(SPINDLE_LASER_USE_PWM, SPINDLE_SERVO)
70
+    auto get_s_power = [] {
71
+      if (parser.seenval('S')) {
72
+        const float spwr = parser.value_float();
73
+        #if ENABLED(SPINDLE_SERVO)
74
+          cutter.unitPower = spwr;
75
+        #else
76
+          cutter.unitPower = TERN(SPINDLE_LASER_USE_PWM,
77
+                                cutter.power_to_range(cutter_power_t(round(spwr))),
78
+                                spwr > 0 ? 255 : 0);
79
+        #endif
80
+      }
81
+      else
82
+        cutter.unitPower = cutter.cpwr_to_upwr(SPEED_POWER_STARTUP);
83
+      return cutter.unitPower;
84
+    };
85
+  #endif
84
 
86
 
85
   #if ENABLED(LASER_POWER_INLINE)
87
   #if ENABLED(LASER_POWER_INLINE)
86
     if (parser.seen('I') == DISABLED(LASER_POWER_INLINE_INVERT)) {
88
     if (parser.seen('I') == DISABLED(LASER_POWER_INLINE_INVERT)) {

+ 6
- 0
buildroot/tests/mega1280 Просмотреть файл

28
 exec_test $1 $2 "Spindle, MESH_BED_LEVELING, closed loop, Power Monitor, and LCD" "$3"
28
 exec_test $1 $2 "Spindle, MESH_BED_LEVELING, closed loop, Power Monitor, and LCD" "$3"
29
 
29
 
30
 #
30
 #
31
+# ...and without PWM
32
+#
33
+opt_disable SPINDLE_LASER_USE_PWM
34
+exec_test $1 $2 "(No PWM)" "$3"
35
+
36
+#
31
 # Test DUAL_X_CARRIAGE
37
 # Test DUAL_X_CARRIAGE
32
 #
38
 #
33
 restore_configs
39
 restore_configs

Загрузка…
Отмена
Сохранить