Skip to content

Commit 3c3fe1a

Browse files
authored
Merge pull request #5089 from thinkyhead/rc_break_m1_fix
Centralize click-handling in the LCD loop
2 parents 47ad97c + 396434a commit 3c3fe1a

File tree

7 files changed

+174
-269
lines changed

7 files changed

+174
-269
lines changed

Marlin/Marlin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ extern bool axis_known_position[XYZ]; // axis[n].is_known
270270
extern bool axis_homed[XYZ]; // axis[n].is_homed
271271
extern volatile bool wait_for_heatup;
272272

273-
#if ENABLED(ULTIPANEL) || ENABLED(EMERGENCY_PARSER)
273+
#if ENABLED(EMERGENCY_PARSER) || ENABLED(ULTIPANEL)
274274
extern volatile bool wait_for_user;
275275
#endif
276276

Marlin/MarlinSerial.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -508,10 +508,7 @@ MarlinSerial customizedSerial;
508508
if (c == '\n') {
509509
switch (state) {
510510
case state_M108:
511-
wait_for_heatup = false;
512-
#if DISABLED(ULTIPANEL)
513-
wait_for_user = false;
514-
#endif
511+
wait_for_user = wait_for_heatup = false;
515512
break;
516513
case state_M112:
517514
kill(PSTR(MSG_KILLED));

Marlin/Marlin_main.cpp

Lines changed: 42 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,12 @@ inline void get_serial_commands() {
10461046

10471047
#if DISABLED(EMERGENCY_PARSER)
10481048
// If command was e-stop process now
1049-
if (strcmp(command, "M108") == 0) wait_for_heatup = false;
1049+
if (strcmp(command, "M108") == 0) {
1050+
wait_for_heatup = false;
1051+
#if ENABLED(ULTIPANEL)
1052+
wait_for_user = false;
1053+
#endif
1054+
}
10501055
if (strcmp(command, "M112") == 0) kill(PSTR(MSG_KILLED));
10511056
if (strcmp(command, "M410") == 0) { quickstop_stepper(); }
10521057
#endif
@@ -4414,7 +4419,6 @@ inline void gcode_G92() {
44144419
dontExpireStatus();
44154420
#endif
44164421
}
4417-
lcd_ignore_click();
44184422

44194423
#else
44204424

@@ -4425,53 +4429,28 @@ inline void gcode_G92() {
44254429

44264430
#endif
44274431

4428-
#if ENABLED(EMERGENCY_PARSER)
4429-
wait_for_user = true;
4430-
#endif
4431-
4432+
wait_for_user = true;
44324433
KEEPALIVE_STATE(PAUSED_FOR_USER);
44334434

44344435
stepper.synchronize();
44354436
refresh_cmd_timeout();
44364437

4437-
#if ENABLED(ULTIPANEL)
4438-
4439-
#if ENABLED(EMERGENCY_PARSER)
4440-
#define M1_WAIT_CONDITION (!lcd_clicked() && wait_for_user)
4438+
if (codenum > 0) {
4439+
codenum += previous_cmd_ms; // wait until this time for a click
4440+
while (PENDING(millis(), codenum) && wait_for_user) idle();
4441+
}
4442+
else {
4443+
#if ENABLED(ULTIPANEL)
4444+
if (lcd_detected()) {
4445+
while (wait_for_user) idle();
4446+
IS_SD_PRINTING ? LCD_MESSAGEPGM(MSG_RESUMING) : LCD_MESSAGEPGM(WELCOME_MSG);
4447+
}
44414448
#else
4442-
#define M1_WAIT_CONDITION !lcd_clicked()
4449+
while (wait_for_user) idle();
44434450
#endif
4451+
}
44444452

4445-
if (codenum > 0) {
4446-
codenum += previous_cmd_ms; // wait until this time for a click
4447-
while (PENDING(millis(), codenum) && M1_WAIT_CONDITION) idle();
4448-
lcd_ignore_click(false);
4449-
}
4450-
else if (lcd_detected()) {
4451-
while (M1_WAIT_CONDITION) idle();
4452-
}
4453-
else goto ExitM1;
4454-
4455-
IS_SD_PRINTING ? LCD_MESSAGEPGM(MSG_RESUMING) : LCD_MESSAGEPGM(WELCOME_MSG);
4456-
4457-
#else
4458-
4459-
if (codenum > 0) {
4460-
codenum += previous_cmd_ms; // wait until this time for an M108
4461-
while (PENDING(millis(), codenum) && wait_for_user) idle();
4462-
}
4463-
else while (wait_for_user) idle();
4464-
4465-
#endif
4466-
4467-
#if ENABLED(ULTIPANEL)
4468-
ExitM1:
4469-
#endif
4470-
4471-
#if ENABLED(EMERGENCY_PARSER)
4472-
wait_for_user = false;
4473-
#endif
4474-
4453+
wait_for_user = false;
44754454
KEEPALIVE_STATE(IN_HANDLER);
44764455
}
44774456

@@ -5539,47 +5518,27 @@ inline void gcode_M140() {
55395518
* F<fan speed>
55405519
*/
55415520
inline void gcode_M145() {
5542-
int8_t material = code_seen('S') ? (int8_t)code_value_int() : 0;
5543-
if (material < 0 || material > 1) {
5521+
uint8_t material = code_seen('S') ? (uint8_t)code_value_int() : 0;
5522+
if (material >= COUNT(lcd_preheat_hotend_temp)) {
55445523
SERIAL_ERROR_START;
55455524
SERIAL_ERRORLNPGM(MSG_ERR_MATERIAL_INDEX);
55465525
}
55475526
else {
55485527
int v;
5549-
switch (material) {
5550-
case 0:
5551-
if (code_seen('H')) {
5552-
v = code_value_int();
5553-
preheatHotendTemp1 = constrain(v, EXTRUDE_MINTEMP, HEATER_0_MAXTEMP - 15);
5554-
}
5555-
if (code_seen('F')) {
5556-
v = code_value_int();
5557-
preheatFanSpeed1 = constrain(v, 0, 255);
5558-
}
5559-
#if TEMP_SENSOR_BED != 0
5560-
if (code_seen('B')) {
5561-
v = code_value_int();
5562-
preheatBedTemp1 = constrain(v, BED_MINTEMP, BED_MAXTEMP - 15);
5563-
}
5564-
#endif
5565-
break;
5566-
case 1:
5567-
if (code_seen('H')) {
5568-
v = code_value_int();
5569-
preheatHotendTemp2 = constrain(v, EXTRUDE_MINTEMP, HEATER_0_MAXTEMP - 15);
5570-
}
5571-
if (code_seen('F')) {
5572-
v = code_value_int();
5573-
preheatFanSpeed2 = constrain(v, 0, 255);
5574-
}
5575-
#if TEMP_SENSOR_BED != 0
5576-
if (code_seen('B')) {
5577-
v = code_value_int();
5578-
preheatBedTemp2 = constrain(v, BED_MINTEMP, BED_MAXTEMP - 15);
5579-
}
5580-
#endif
5581-
break;
5528+
if (code_seen('H')) {
5529+
v = code_value_int();
5530+
lcd_preheat_hotend_temp[material] = constrain(v, EXTRUDE_MINTEMP, HEATER_0_MAXTEMP - 15);
5531+
}
5532+
if (code_seen('F')) {
5533+
v = code_value_int();
5534+
lcd_preheat_fan_speed[material] = constrain(v, 0, 255);
55825535
}
5536+
#if TEMP_SENSOR_BED != 0
5537+
if (code_seen('B')) {
5538+
v = code_value_int();
5539+
lcd_preheat_bed_temp[material] = constrain(v, BED_MINTEMP, BED_MAXTEMP - 15);
5540+
}
5541+
#endif
55835542
}
55845543
}
55855544

@@ -5590,13 +5549,9 @@ inline void gcode_M140() {
55905549
* M149: Set temperature units
55915550
*/
55925551
inline void gcode_M149() {
5593-
if (code_seen('C')) {
5594-
set_input_temp_units(TEMPUNIT_C);
5595-
} else if (code_seen('K')) {
5596-
set_input_temp_units(TEMPUNIT_K);
5597-
} else if (code_seen('F')) {
5598-
set_input_temp_units(TEMPUNIT_F);
5599-
}
5552+
if (code_seen('C')) set_input_temp_units(TEMPUNIT_C);
5553+
else if (code_seen('K')) set_input_temp_units(TEMPUNIT_K);
5554+
else if (code_seen('F')) set_input_temp_units(TEMPUNIT_F);
56005555
}
56015556
#endif
56025557

@@ -6874,7 +6829,10 @@ inline void gcode_M503() {
68746829
// Wait for filament insert by user and press button
68756830
lcd_filament_change_show_message(FILAMENT_CHANGE_MESSAGE_INSERT);
68766831

6877-
while (!lcd_clicked()) {
6832+
// LCD click or M108 will clear this
6833+
wait_for_user = true;
6834+
6835+
while (wait_for_user) {
68786836
#if HAS_BUZZER
68796837
millis_t ms = millis();
68806838
if (ms >= next_buzz) {
@@ -6884,9 +6842,6 @@ inline void gcode_M503() {
68846842
#endif
68856843
idle(true);
68866844
}
6887-
delay(100);
6888-
while (lcd_clicked()) idle(true);
6889-
delay(100);
68906845

68916846
// Show load message
68926847
lcd_filament_change_show_message(FILAMENT_CHANGE_MESSAGE_LOAD);

Marlin/configuration_store.cpp

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,9 @@
8686
* 301 M666 Z z_endstop_adj (float)
8787
*
8888
* ULTIPANEL:
89-
* 305 M145 S0 H preheatHotendTemp1 (int)
90-
* 307 M145 S0 B preheatBedTemp1 (int)
91-
* 309 M145 S0 F preheatFanSpeed1 (int)
92-
* 311 M145 S1 H preheatHotendTemp2 (int)
93-
* 313 M145 S1 B preheatBedTemp2 (int)
94-
* 315 M145 S1 F preheatFanSpeed2 (int)
89+
* 305 M145 S0 H lcd_preheat_hotend_temp (int x2)
90+
* 309 M145 S0 B lcd_preheat_bed_temp (int x2)
91+
* 313 M145 S0 F lcd_preheat_fan_speed (int x2)
9592
*
9693
* PIDTEMP:
9794
* 317 M301 E0 PIDC Kp[0], Ki[0], Kd[0], Kc[0] (float x4)
@@ -277,16 +274,14 @@ void Config_Postprocess() {
277274
#endif
278275

279276
#if DISABLED(ULTIPANEL)
280-
int preheatHotendTemp1 = PREHEAT_1_TEMP_HOTEND, preheatBedTemp1 = PREHEAT_1_TEMP_BED, preheatFanSpeed1 = PREHEAT_1_FAN_SPEED,
281-
preheatHotendTemp2 = PREHEAT_2_TEMP_HOTEND, preheatBedTemp2 = PREHEAT_2_TEMP_BED, preheatFanSpeed2 = PREHEAT_2_FAN_SPEED;
277+
const int lcd_preheat_hotend_temp[2] = { PREHEAT_1_TEMP_HOTEND, PREHEAT_2_TEMP_HOTEND },
278+
lcd_preheat_bed_temp[2] = { PREHEAT_1_TEMP_BED, PREHEAT_2_TEMP_BED },
279+
lcd_preheat_fan_speed[2] = { PREHEAT_1_FAN_SPEED, PREHEAT_2_FAN_SPEED };
282280
#endif // !ULTIPANEL
283281

284-
EEPROM_WRITE(preheatHotendTemp1);
285-
EEPROM_WRITE(preheatBedTemp1);
286-
EEPROM_WRITE(preheatFanSpeed1);
287-
EEPROM_WRITE(preheatHotendTemp2);
288-
EEPROM_WRITE(preheatBedTemp2);
289-
EEPROM_WRITE(preheatFanSpeed2);
282+
EEPROM_WRITE(lcd_preheat_hotend_temp);
283+
EEPROM_WRITE(lcd_preheat_bed_temp);
284+
EEPROM_WRITE(lcd_preheat_fan_speed);
290285

291286
for (uint8_t e = 0; e < MAX_EXTRUDERS; e++) {
292287

@@ -465,16 +460,12 @@ void Config_Postprocess() {
465460
#endif
466461

467462
#if DISABLED(ULTIPANEL)
468-
int preheatHotendTemp1, preheatBedTemp1, preheatFanSpeed1,
469-
preheatHotendTemp2, preheatBedTemp2, preheatFanSpeed2;
463+
int lcd_preheat_hotend_temp[2], lcd_preheat_bed_temp[2], lcd_preheat_fan_speed[2];
470464
#endif
471465

472-
EEPROM_READ(preheatHotendTemp1);
473-
EEPROM_READ(preheatBedTemp1);
474-
EEPROM_READ(preheatFanSpeed1);
475-
EEPROM_READ(preheatHotendTemp2);
476-
EEPROM_READ(preheatBedTemp2);
477-
EEPROM_READ(preheatFanSpeed2);
466+
EEPROM_READ(lcd_preheat_hotend_temp);
467+
EEPROM_READ(lcd_preheat_bed_temp);
468+
EEPROM_READ(lcd_preheat_fan_speed);
478469

479470
#if ENABLED(PIDTEMP)
480471
for (uint8_t e = 0; e < MAX_EXTRUDERS; e++) {
@@ -639,12 +630,12 @@ void Config_ResetDefault() {
639630
#endif
640631

641632
#if ENABLED(ULTIPANEL)
642-
preheatHotendTemp1 = PREHEAT_1_TEMP_HOTEND;
643-
preheatBedTemp1 = PREHEAT_1_TEMP_BED;
644-
preheatFanSpeed1 = PREHEAT_1_FAN_SPEED;
645-
preheatHotendTemp2 = PREHEAT_2_TEMP_HOTEND;
646-
preheatBedTemp2 = PREHEAT_2_TEMP_BED;
647-
preheatFanSpeed2 = PREHEAT_2_FAN_SPEED;
633+
lcd_preheat_hotend_temp[0] = PREHEAT_1_TEMP_HOTEND;
634+
lcd_preheat_hotend_temp[1] = PREHEAT_2_TEMP_HOTEND;
635+
lcd_preheat_bed_temp[0] = PREHEAT_1_TEMP_BED;
636+
lcd_preheat_bed_temp[1] = PREHEAT_2_TEMP_BED;
637+
lcd_preheat_fan_speed[0] = PREHEAT_1_FAN_SPEED;
638+
lcd_preheat_fan_speed[1] = PREHEAT_2_FAN_SPEED;
648639
#endif
649640

650641
#if HAS_LCD_CONTRAST
@@ -863,15 +854,13 @@ void Config_ResetDefault() {
863854
SERIAL_ECHOLNPGM("Material heatup parameters:");
864855
CONFIG_ECHO_START;
865856
}
866-
SERIAL_ECHOPAIR(" M145 S0 H", preheatHotendTemp1);
867-
SERIAL_ECHOPAIR(" B", preheatBedTemp1);
868-
SERIAL_ECHOPAIR(" F", preheatFanSpeed1);
869-
SERIAL_EOL;
870-
CONFIG_ECHO_START;
871-
SERIAL_ECHOPAIR(" M145 S1 H", preheatHotendTemp2);
872-
SERIAL_ECHOPAIR(" B", preheatBedTemp2);
873-
SERIAL_ECHOPAIR(" F", preheatFanSpeed2);
874-
SERIAL_EOL;
857+
for (uint8_t i = 0; i < COUNT(lcd_preheat_hotend_temp); i++) {
858+
SERIAL_ECHOPAIR(" M145 S", (int)i);
859+
SERIAL_ECHOPAIR(" H", lcd_preheat_hotend_temp[i]);
860+
SERIAL_ECHOPAIR(" B", lcd_preheat_bed_temp[i]);
861+
SERIAL_ECHOPAIR(" F", lcd_preheat_fan_speed[i]);
862+
SERIAL_EOL;
863+
}
875864
#endif // ULTIPANEL
876865

877866
#if HAS_PID_HEATING

Marlin/planner.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ class Planner {
264264
* fr_mm_s - (target) speed of the move (mm/s)
265265
* extruder - target extruder
266266
*/
267-
static FORCE_INLINE void buffer_line(ARG_X, ARG_Y, ARG_Z, const float &e, float fr_mm_s, const uint8_t extruder) {
267+
static FORCE_INLINE void buffer_line(ARG_X, ARG_Y, ARG_Z, const float &e, const float &fr_mm_s, const uint8_t extruder) {
268268
#if PLANNER_LEVELING && IS_CARTESIAN
269269
apply_leveling(lx, ly, lz);
270270
#endif
@@ -280,7 +280,7 @@ class Planner {
280280
* fr_mm_s - (target) speed of the move (mm/s)
281281
* extruder - target extruder
282282
*/
283-
static FORCE_INLINE void buffer_line_kinematic(const float target[XYZE], float fr_mm_s, const uint8_t extruder) {
283+
static FORCE_INLINE void buffer_line_kinematic(const float target[XYZE], const float &fr_mm_s, const uint8_t extruder) {
284284
#if PLANNER_LEVELING
285285
float pos[XYZ] = { target[X_AXIS], target[Y_AXIS], target[Z_AXIS] };
286286
apply_leveling(pos);
@@ -311,9 +311,9 @@ class Planner {
311311
_set_position_mm(lx, ly, lz, e);
312312
}
313313
static void set_position_mm_kinematic(const float position[NUM_AXIS]);
314-
static void set_position_mm(const AxisEnum axis, const float& v);
315-
static FORCE_INLINE void set_z_position_mm(const float& z) { set_position_mm(Z_AXIS, z); }
316-
static FORCE_INLINE void set_e_position_mm(const float& e) { set_position_mm(E_AXIS, e); }
314+
static void set_position_mm(const AxisEnum axis, const float &v);
315+
static FORCE_INLINE void set_z_position_mm(const float &z) { set_position_mm(Z_AXIS, z); }
316+
static FORCE_INLINE void set_e_position_mm(const float &e) { set_position_mm(E_AXIS, e); }
317317

318318
/**
319319
* Sync from the stepper positions. (e.g., after an interrupted move)
@@ -369,7 +369,7 @@ class Planner {
369369
* Calculate the distance (not time) it takes to accelerate
370370
* from initial_rate to target_rate using the given acceleration:
371371
*/
372-
static float estimate_acceleration_distance(float initial_rate, float target_rate, float accel) {
372+
static float estimate_acceleration_distance(const float &initial_rate, const float &target_rate, const float &accel) {
373373
if (accel == 0) return 0; // accel was 0, set acceleration distance to 0
374374
return (sq(target_rate) - sq(initial_rate)) / (accel * 2);
375375
}
@@ -382,7 +382,7 @@ class Planner {
382382
* This is used to compute the intersection point between acceleration and deceleration
383383
* in cases where the "trapezoid" has no plateau (i.e., never reaches maximum speed)
384384
*/
385-
static float intersection_distance(float initial_rate, float final_rate, float accel, float distance) {
385+
static float intersection_distance(const float &initial_rate, const float &final_rate, const float &accel, const float &distance) {
386386
if (accel == 0) return 0; // accel was 0, set intersection distance to 0
387387
return (accel * 2 * distance - sq(initial_rate) + sq(final_rate)) / (accel * 4);
388388
}
@@ -392,7 +392,7 @@ class Planner {
392392
* to reach 'target_velocity' using 'acceleration' within a given
393393
* 'distance'.
394394
*/
395-
static float max_allowable_speed(float accel, float target_velocity, float distance) {
395+
static float max_allowable_speed(const float &accel, const float &target_velocity, const float &distance) {
396396
return sqrt(sq(target_velocity) - 2 * accel * distance);
397397
}
398398

0 commit comments

Comments
 (0)