Browse Source

🐛 Fix laser menu enable_state (#24557)

Mike La Spina 1 year ago
parent
commit
e5f2daa001
No account linked to committer's email address
2 changed files with 15 additions and 14 deletions
  1. 13
    12
      Marlin/src/feature/spindle_laser.h
  2. 2
    2
      Marlin/src/lcd/menu/menu_spindle_laser.cpp

+ 13
- 12
Marlin/src/feature/spindle_laser.h View File

@@ -197,7 +197,7 @@ public:
197 197
    *  - For CUTTER_MODE_ERROR set the output enable_state flag directly and set power to 0 for any mode.
198 198
    *    This mode allows a global power shutdown action to occur.
199 199
    */
200
-  static void set_enabled(const bool enable) {
200
+  static void set_enabled(bool enable) {
201 201
     switch (cutter_mode) {
202 202
       case CUTTER_MODE_STANDARD:
203 203
         apply_power(enable ? TERN(SPINDLE_LASER_USE_PWM, (power ?: (unitPower ? upower_to_ocr(cpwr_to_upwr(SPEED_POWER_STARTUP)) : 0)), 255) : 0);
@@ -209,7 +209,7 @@ public:
209 209
         TERN_(LASER_FEATURE, set_inline_enabled(enable));
210 210
         break;
211 211
       case CUTTER_MODE_ERROR: // Error mode, no enable and kill power.
212
-        enable_state = false;
212
+        enable = false;
213 213
         apply_power(0);
214 214
     }
215 215
     #if SPINDLE_LASER_ENA_PIN
@@ -279,13 +279,14 @@ public:
279 279
 
280 280
     #if ENABLED(LASER_FEATURE)
281 281
       // Toggle the laser on/off with menuPower. Apply SPEED_POWER_STARTUP if it was 0 on entry.
282
-      static void laser_menu_toggle(const bool state) {
282
+      static void menu_set_enabled(const bool state) {
283 283
         set_enabled(state);
284 284
         if (state) {
285 285
           if (!menuPower) menuPower = cpwr_to_upwr(SPEED_POWER_STARTUP);
286 286
           power = upower_to_ocr(menuPower);
287 287
           apply_power(power);
288
-        }
288
+        } else 
289
+          apply_power(0);
289 290
       }
290 291
 
291 292
       /**
@@ -295,10 +296,10 @@ public:
295 296
        */
296 297
       static void test_fire_pulse() {
297 298
         BUZZ(30, 3000);
298
-        cutter_mode = CUTTER_MODE_STANDARD;// Menu needs standard mode.
299
-        laser_menu_toggle(true);           // Laser On
300
-        delay(testPulse);                  // Delay for time set by user in pulse ms menu screen.
301
-        laser_menu_toggle(false);          // Laser Off
299
+        cutter_mode = CUTTER_MODE_STANDARD; // Menu needs standard mode.
300
+        menu_set_enabled(true);             // Laser On
301
+        delay(testPulse);                   // Delay for time set by user in pulse ms menu screen.
302
+        menu_set_enabled(false);            // Laser Off
302 303
       }
303 304
     #endif // LASER_FEATURE
304 305
 
@@ -308,14 +309,14 @@ public:
308 309
 
309 310
     // Dynamic mode rate calculation
310 311
     static uint8_t calc_dynamic_power() {
311
-      if (feedrate_mm_m > 65535) return 255;         // Too fast, go always on
312
-      uint16_t rate = uint16_t(feedrate_mm_m);       // 16 bits from the G-code parser float input
313
-      rate >>= 8;                                    // Take the G-code input e.g. F40000 and shift off the lower bits to get an OCR value from 1-255
312
+      if (feedrate_mm_m > 65535) return 255;    // Too fast, go always on
313
+      uint16_t rate = uint16_t(feedrate_mm_m);  // 16 bits from the G-code parser float input
314
+      rate >>= 8;                               // Take the G-code input e.g. F40000 and shift off the lower bits to get an OCR value from 1-255
314 315
       return uint8_t(rate);
315 316
     }
316 317
 
317 318
     // Inline modes of all other functions; all enable planner inline power control
318
-    static void set_inline_enabled(const bool enable) { planner.laser_inline.status.isEnabled = enable;}
319
+    static void set_inline_enabled(const bool enable) { planner.laser_inline.status.isEnabled = enable; }
319 320
 
320 321
     // Set the power for subsequent movement blocks
321 322
     static void inline_power(const cutter_power_t cpwr) {

+ 2
- 2
Marlin/src/lcd/menu/menu_spindle_laser.cpp View File

@@ -48,12 +48,12 @@
48 48
         cutter.mpower_min(), cutter.mpower_max(), cutter.update_from_mpower);
49 49
     #endif
50 50
 
51
-    editable.state = is_enabled;
51
+    editable.state = is_enabled; // State before toggle
52 52
     EDIT_ITEM(bool, MSG_CUTTER(TOGGLE), &is_enabled, []{
53 53
       #if ENABLED(SPINDLE_FEATURE)
54 54
         if (editable.state) cutter.disable(); else cutter.enable_same_dir();
55 55
       #else
56
-        cutter.laser_menu_toggle(!editable.state);
56
+        cutter.menu_set_enabled(!editable.state);
57 57
       #endif
58 58
     });
59 59
 

Loading…
Cancel
Save