Przeglądaj źródła

🐛 Fix laser menu enable_state (#24557)

Mike La Spina 2 lat temu
rodzic
commit
e5f2daa001
No account linked to committer's email address

+ 13
- 12
Marlin/src/feature/spindle_laser.h Wyświetl plik

197
    *  - For CUTTER_MODE_ERROR set the output enable_state flag directly and set power to 0 for any mode.
197
    *  - For CUTTER_MODE_ERROR set the output enable_state flag directly and set power to 0 for any mode.
198
    *    This mode allows a global power shutdown action to occur.
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
     switch (cutter_mode) {
201
     switch (cutter_mode) {
202
       case CUTTER_MODE_STANDARD:
202
       case CUTTER_MODE_STANDARD:
203
         apply_power(enable ? TERN(SPINDLE_LASER_USE_PWM, (power ?: (unitPower ? upower_to_ocr(cpwr_to_upwr(SPEED_POWER_STARTUP)) : 0)), 255) : 0);
203
         apply_power(enable ? TERN(SPINDLE_LASER_USE_PWM, (power ?: (unitPower ? upower_to_ocr(cpwr_to_upwr(SPEED_POWER_STARTUP)) : 0)), 255) : 0);
209
         TERN_(LASER_FEATURE, set_inline_enabled(enable));
209
         TERN_(LASER_FEATURE, set_inline_enabled(enable));
210
         break;
210
         break;
211
       case CUTTER_MODE_ERROR: // Error mode, no enable and kill power.
211
       case CUTTER_MODE_ERROR: // Error mode, no enable and kill power.
212
-        enable_state = false;
212
+        enable = false;
213
         apply_power(0);
213
         apply_power(0);
214
     }
214
     }
215
     #if SPINDLE_LASER_ENA_PIN
215
     #if SPINDLE_LASER_ENA_PIN
279
 
279
 
280
     #if ENABLED(LASER_FEATURE)
280
     #if ENABLED(LASER_FEATURE)
281
       // Toggle the laser on/off with menuPower. Apply SPEED_POWER_STARTUP if it was 0 on entry.
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
         set_enabled(state);
283
         set_enabled(state);
284
         if (state) {
284
         if (state) {
285
           if (!menuPower) menuPower = cpwr_to_upwr(SPEED_POWER_STARTUP);
285
           if (!menuPower) menuPower = cpwr_to_upwr(SPEED_POWER_STARTUP);
286
           power = upower_to_ocr(menuPower);
286
           power = upower_to_ocr(menuPower);
287
           apply_power(power);
287
           apply_power(power);
288
-        }
288
+        } else 
289
+          apply_power(0);
289
       }
290
       }
290
 
291
 
291
       /**
292
       /**
295
        */
296
        */
296
       static void test_fire_pulse() {
297
       static void test_fire_pulse() {
297
         BUZZ(30, 3000);
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
     #endif // LASER_FEATURE
304
     #endif // LASER_FEATURE
304
 
305
 
308
 
309
 
309
     // Dynamic mode rate calculation
310
     // Dynamic mode rate calculation
310
     static uint8_t calc_dynamic_power() {
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
       return uint8_t(rate);
315
       return uint8_t(rate);
315
     }
316
     }
316
 
317
 
317
     // Inline modes of all other functions; all enable planner inline power control
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
     // Set the power for subsequent movement blocks
321
     // Set the power for subsequent movement blocks
321
     static void inline_power(const cutter_power_t cpwr) {
322
     static void inline_power(const cutter_power_t cpwr) {

+ 2
- 2
Marlin/src/lcd/menu/menu_spindle_laser.cpp Wyświetl plik

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

Ładowanie…
Anuluj
Zapisz