🐛 Fix laser menu enable_state (#24557)

This commit is contained in:
Mike La Spina 2022-08-01 01:03:45 -05:00 committed by Scott Lahteine
parent c0cb7e35af
commit c3f2586445
2 changed files with 15 additions and 14 deletions

View File

@ -197,7 +197,7 @@ public:
* - For CUTTER_MODE_ERROR set the output enable_state flag directly and set power to 0 for any mode. * - For CUTTER_MODE_ERROR set the output enable_state flag directly and set power to 0 for any mode.
* This mode allows a global power shutdown action to occur. * This mode allows a global power shutdown action to occur.
*/ */
static void set_enabled(const bool enable) { static void set_enabled(bool enable) {
switch (cutter_mode) { switch (cutter_mode) {
case CUTTER_MODE_STANDARD: case CUTTER_MODE_STANDARD:
apply_power(enable ? TERN(SPINDLE_LASER_USE_PWM, (power ?: (unitPower ? upower_to_ocr(cpwr_to_upwr(SPEED_POWER_STARTUP)) : 0)), 255) : 0); 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:
TERN_(LASER_FEATURE, set_inline_enabled(enable)); TERN_(LASER_FEATURE, set_inline_enabled(enable));
break; break;
case CUTTER_MODE_ERROR: // Error mode, no enable and kill power. case CUTTER_MODE_ERROR: // Error mode, no enable and kill power.
enable_state = false; enable = false;
apply_power(0); apply_power(0);
} }
#if SPINDLE_LASER_ENA_PIN #if SPINDLE_LASER_ENA_PIN
@ -279,13 +279,14 @@ public:
#if ENABLED(LASER_FEATURE) #if ENABLED(LASER_FEATURE)
// Toggle the laser on/off with menuPower. Apply SPEED_POWER_STARTUP if it was 0 on entry. // Toggle the laser on/off with menuPower. Apply SPEED_POWER_STARTUP if it was 0 on entry.
static void laser_menu_toggle(const bool state) { static void menu_set_enabled(const bool state) {
set_enabled(state); set_enabled(state);
if (state) { if (state) {
if (!menuPower) menuPower = cpwr_to_upwr(SPEED_POWER_STARTUP); if (!menuPower) menuPower = cpwr_to_upwr(SPEED_POWER_STARTUP);
power = upower_to_ocr(menuPower); power = upower_to_ocr(menuPower);
apply_power(power); apply_power(power);
} } else
apply_power(0);
} }
/** /**
@ -295,10 +296,10 @@ public:
*/ */
static void test_fire_pulse() { static void test_fire_pulse() {
BUZZ(30, 3000); BUZZ(30, 3000);
cutter_mode = CUTTER_MODE_STANDARD;// Menu needs standard mode. cutter_mode = CUTTER_MODE_STANDARD; // Menu needs standard mode.
laser_menu_toggle(true); // Laser On menu_set_enabled(true); // Laser On
delay(testPulse); // Delay for time set by user in pulse ms menu screen. delay(testPulse); // Delay for time set by user in pulse ms menu screen.
laser_menu_toggle(false); // Laser Off menu_set_enabled(false); // Laser Off
} }
#endif // LASER_FEATURE #endif // LASER_FEATURE
@ -315,7 +316,7 @@ public:
} }
// Inline modes of all other functions; all enable planner inline power control // Inline modes of all other functions; all enable planner inline power control
static void set_inline_enabled(const bool enable) { planner.laser_inline.status.isEnabled = enable;} static void set_inline_enabled(const bool enable) { planner.laser_inline.status.isEnabled = enable; }
// Set the power for subsequent movement blocks // Set the power for subsequent movement blocks
static void inline_power(const cutter_power_t cpwr) { static void inline_power(const cutter_power_t cpwr) {

View File

@ -48,12 +48,12 @@
cutter.mpower_min(), cutter.mpower_max(), cutter.update_from_mpower); cutter.mpower_min(), cutter.mpower_max(), cutter.update_from_mpower);
#endif #endif
editable.state = is_enabled; editable.state = is_enabled; // State before toggle
EDIT_ITEM(bool, MSG_CUTTER(TOGGLE), &is_enabled, []{ EDIT_ITEM(bool, MSG_CUTTER(TOGGLE), &is_enabled, []{
#if ENABLED(SPINDLE_FEATURE) #if ENABLED(SPINDLE_FEATURE)
if (editable.state) cutter.disable(); else cutter.enable_same_dir(); if (editable.state) cutter.disable(); else cutter.enable_same_dir();
#else #else
cutter.laser_menu_toggle(!editable.state); cutter.menu_set_enabled(!editable.state);
#endif #endif
}); });