Skip to content

Centralize click-handling in the LCD loop #5089

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Marlin/Marlin.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ extern bool axis_known_position[XYZ]; // axis[n].is_known
extern bool axis_homed[XYZ]; // axis[n].is_homed
extern volatile bool wait_for_heatup;

#if ENABLED(ULTIPANEL) || ENABLED(EMERGENCY_PARSER)
#if ENABLED(EMERGENCY_PARSER) || ENABLED(ULTIPANEL)
extern volatile bool wait_for_user;
#endif

Expand Down
5 changes: 1 addition & 4 deletions Marlin/MarlinSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,10 +508,7 @@ MarlinSerial customizedSerial;
if (c == '\n') {
switch (state) {
case state_M108:
wait_for_heatup = false;
#if DISABLED(ULTIPANEL)
wait_for_user = false;
#endif
wait_for_user = wait_for_heatup = false;
break;
case state_M112:
kill(PSTR(MSG_KILLED));
Expand Down
129 changes: 42 additions & 87 deletions Marlin/Marlin_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,12 @@ inline void get_serial_commands() {

#if DISABLED(EMERGENCY_PARSER)
// If command was e-stop process now
if (strcmp(command, "M108") == 0) wait_for_heatup = false;
if (strcmp(command, "M108") == 0) {
wait_for_heatup = false;
#if ENABLED(ULTIPANEL)
wait_for_user = false;
#endif
}
if (strcmp(command, "M112") == 0) kill(PSTR(MSG_KILLED));
if (strcmp(command, "M410") == 0) { quickstop_stepper(); }
#endif
Expand Down Expand Up @@ -4414,7 +4419,6 @@ inline void gcode_G92() {
dontExpireStatus();
#endif
}
lcd_ignore_click();

#else

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

#endif

#if ENABLED(EMERGENCY_PARSER)
wait_for_user = true;
#endif

wait_for_user = true;
KEEPALIVE_STATE(PAUSED_FOR_USER);

stepper.synchronize();
refresh_cmd_timeout();

#if ENABLED(ULTIPANEL)

#if ENABLED(EMERGENCY_PARSER)
#define M1_WAIT_CONDITION (!lcd_clicked() && wait_for_user)
if (codenum > 0) {
codenum += previous_cmd_ms; // wait until this time for a click
while (PENDING(millis(), codenum) && wait_for_user) idle();
}
else {
#if ENABLED(ULTIPANEL)
if (lcd_detected()) {
while (wait_for_user) idle();
IS_SD_PRINTING ? LCD_MESSAGEPGM(MSG_RESUMING) : LCD_MESSAGEPGM(WELCOME_MSG);
}
#else
#define M1_WAIT_CONDITION !lcd_clicked()
while (wait_for_user) idle();
#endif
}

if (codenum > 0) {
codenum += previous_cmd_ms; // wait until this time for a click
while (PENDING(millis(), codenum) && M1_WAIT_CONDITION) idle();
lcd_ignore_click(false);
}
else if (lcd_detected()) {
while (M1_WAIT_CONDITION) idle();
}
else goto ExitM1;

IS_SD_PRINTING ? LCD_MESSAGEPGM(MSG_RESUMING) : LCD_MESSAGEPGM(WELCOME_MSG);

#else

if (codenum > 0) {
codenum += previous_cmd_ms; // wait until this time for an M108
while (PENDING(millis(), codenum) && wait_for_user) idle();
}
else while (wait_for_user) idle();

#endif

#if ENABLED(ULTIPANEL)
ExitM1:
#endif

#if ENABLED(EMERGENCY_PARSER)
wait_for_user = false;
#endif

wait_for_user = false;
KEEPALIVE_STATE(IN_HANDLER);
}

Expand Down Expand Up @@ -5539,47 +5518,27 @@ inline void gcode_M140() {
* F<fan speed>
*/
inline void gcode_M145() {
int8_t material = code_seen('S') ? (int8_t)code_value_int() : 0;
if (material < 0 || material > 1) {
uint8_t material = code_seen('S') ? (uint8_t)code_value_int() : 0;
if (material >= COUNT(lcd_preheat_hotend_temp)) {
SERIAL_ERROR_START;
SERIAL_ERRORLNPGM(MSG_ERR_MATERIAL_INDEX);
}
else {
int v;
switch (material) {
case 0:
if (code_seen('H')) {
v = code_value_int();
preheatHotendTemp1 = constrain(v, EXTRUDE_MINTEMP, HEATER_0_MAXTEMP - 15);
}
if (code_seen('F')) {
v = code_value_int();
preheatFanSpeed1 = constrain(v, 0, 255);
}
#if TEMP_SENSOR_BED != 0
if (code_seen('B')) {
v = code_value_int();
preheatBedTemp1 = constrain(v, BED_MINTEMP, BED_MAXTEMP - 15);
}
#endif
break;
case 1:
if (code_seen('H')) {
v = code_value_int();
preheatHotendTemp2 = constrain(v, EXTRUDE_MINTEMP, HEATER_0_MAXTEMP - 15);
}
if (code_seen('F')) {
v = code_value_int();
preheatFanSpeed2 = constrain(v, 0, 255);
}
#if TEMP_SENSOR_BED != 0
if (code_seen('B')) {
v = code_value_int();
preheatBedTemp2 = constrain(v, BED_MINTEMP, BED_MAXTEMP - 15);
}
#endif
break;
if (code_seen('H')) {
v = code_value_int();
lcd_preheat_hotend_temp[material] = constrain(v, EXTRUDE_MINTEMP, HEATER_0_MAXTEMP - 15);
}
if (code_seen('F')) {
v = code_value_int();
lcd_preheat_fan_speed[material] = constrain(v, 0, 255);
}
#if TEMP_SENSOR_BED != 0
if (code_seen('B')) {
v = code_value_int();
lcd_preheat_bed_temp[material] = constrain(v, BED_MINTEMP, BED_MAXTEMP - 15);
}
#endif
}
}

Expand All @@ -5590,13 +5549,9 @@ inline void gcode_M140() {
* M149: Set temperature units
*/
inline void gcode_M149() {
if (code_seen('C')) {
set_input_temp_units(TEMPUNIT_C);
} else if (code_seen('K')) {
set_input_temp_units(TEMPUNIT_K);
} else if (code_seen('F')) {
set_input_temp_units(TEMPUNIT_F);
}
if (code_seen('C')) set_input_temp_units(TEMPUNIT_C);
else if (code_seen('K')) set_input_temp_units(TEMPUNIT_K);
else if (code_seen('F')) set_input_temp_units(TEMPUNIT_F);
}
#endif

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

while (!lcd_clicked()) {
// LCD click or M108 will clear this
wait_for_user = true;

while (wait_for_user) {
#if HAS_BUZZER
millis_t ms = millis();
if (ms >= next_buzz) {
Expand All @@ -6884,9 +6842,6 @@ inline void gcode_M503() {
#endif
idle(true);
}
delay(100);
while (lcd_clicked()) idle(true);
delay(100);

// Show load message
lcd_filament_change_show_message(FILAMENT_CHANGE_MESSAGE_LOAD);
Expand Down
63 changes: 26 additions & 37 deletions Marlin/configuration_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,9 @@
* 301 M666 Z z_endstop_adj (float)
*
* ULTIPANEL:
* 305 M145 S0 H preheatHotendTemp1 (int)
* 307 M145 S0 B preheatBedTemp1 (int)
* 309 M145 S0 F preheatFanSpeed1 (int)
* 311 M145 S1 H preheatHotendTemp2 (int)
* 313 M145 S1 B preheatBedTemp2 (int)
* 315 M145 S1 F preheatFanSpeed2 (int)
* 305 M145 S0 H lcd_preheat_hotend_temp (int x2)
* 309 M145 S0 B lcd_preheat_bed_temp (int x2)
* 313 M145 S0 F lcd_preheat_fan_speed (int x2)
*
* PIDTEMP:
* 317 M301 E0 PIDC Kp[0], Ki[0], Kd[0], Kc[0] (float x4)
Expand Down Expand Up @@ -277,16 +274,14 @@ void Config_Postprocess() {
#endif

#if DISABLED(ULTIPANEL)
int preheatHotendTemp1 = PREHEAT_1_TEMP_HOTEND, preheatBedTemp1 = PREHEAT_1_TEMP_BED, preheatFanSpeed1 = PREHEAT_1_FAN_SPEED,
preheatHotendTemp2 = PREHEAT_2_TEMP_HOTEND, preheatBedTemp2 = PREHEAT_2_TEMP_BED, preheatFanSpeed2 = PREHEAT_2_FAN_SPEED;
const int lcd_preheat_hotend_temp[2] = { PREHEAT_1_TEMP_HOTEND, PREHEAT_2_TEMP_HOTEND },
lcd_preheat_bed_temp[2] = { PREHEAT_1_TEMP_BED, PREHEAT_2_TEMP_BED },
lcd_preheat_fan_speed[2] = { PREHEAT_1_FAN_SPEED, PREHEAT_2_FAN_SPEED };
#endif // !ULTIPANEL

EEPROM_WRITE(preheatHotendTemp1);
EEPROM_WRITE(preheatBedTemp1);
EEPROM_WRITE(preheatFanSpeed1);
EEPROM_WRITE(preheatHotendTemp2);
EEPROM_WRITE(preheatBedTemp2);
EEPROM_WRITE(preheatFanSpeed2);
EEPROM_WRITE(lcd_preheat_hotend_temp);
EEPROM_WRITE(lcd_preheat_bed_temp);
EEPROM_WRITE(lcd_preheat_fan_speed);

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

Expand Down Expand Up @@ -465,16 +460,12 @@ void Config_Postprocess() {
#endif

#if DISABLED(ULTIPANEL)
int preheatHotendTemp1, preheatBedTemp1, preheatFanSpeed1,
preheatHotendTemp2, preheatBedTemp2, preheatFanSpeed2;
int lcd_preheat_hotend_temp[2], lcd_preheat_bed_temp[2], lcd_preheat_fan_speed[2];
#endif

EEPROM_READ(preheatHotendTemp1);
EEPROM_READ(preheatBedTemp1);
EEPROM_READ(preheatFanSpeed1);
EEPROM_READ(preheatHotendTemp2);
EEPROM_READ(preheatBedTemp2);
EEPROM_READ(preheatFanSpeed2);
EEPROM_READ(lcd_preheat_hotend_temp);
EEPROM_READ(lcd_preheat_bed_temp);
EEPROM_READ(lcd_preheat_fan_speed);

#if ENABLED(PIDTEMP)
for (uint8_t e = 0; e < MAX_EXTRUDERS; e++) {
Expand Down Expand Up @@ -639,12 +630,12 @@ void Config_ResetDefault() {
#endif

#if ENABLED(ULTIPANEL)
preheatHotendTemp1 = PREHEAT_1_TEMP_HOTEND;
preheatBedTemp1 = PREHEAT_1_TEMP_BED;
preheatFanSpeed1 = PREHEAT_1_FAN_SPEED;
preheatHotendTemp2 = PREHEAT_2_TEMP_HOTEND;
preheatBedTemp2 = PREHEAT_2_TEMP_BED;
preheatFanSpeed2 = PREHEAT_2_FAN_SPEED;
lcd_preheat_hotend_temp[0] = PREHEAT_1_TEMP_HOTEND;
lcd_preheat_hotend_temp[1] = PREHEAT_2_TEMP_HOTEND;
lcd_preheat_bed_temp[0] = PREHEAT_1_TEMP_BED;
lcd_preheat_bed_temp[1] = PREHEAT_2_TEMP_BED;
lcd_preheat_fan_speed[0] = PREHEAT_1_FAN_SPEED;
lcd_preheat_fan_speed[1] = PREHEAT_2_FAN_SPEED;
#endif

#if HAS_LCD_CONTRAST
Expand Down Expand Up @@ -863,15 +854,13 @@ void Config_ResetDefault() {
SERIAL_ECHOLNPGM("Material heatup parameters:");
CONFIG_ECHO_START;
}
SERIAL_ECHOPAIR(" M145 S0 H", preheatHotendTemp1);
SERIAL_ECHOPAIR(" B", preheatBedTemp1);
SERIAL_ECHOPAIR(" F", preheatFanSpeed1);
SERIAL_EOL;
CONFIG_ECHO_START;
SERIAL_ECHOPAIR(" M145 S1 H", preheatHotendTemp2);
SERIAL_ECHOPAIR(" B", preheatBedTemp2);
SERIAL_ECHOPAIR(" F", preheatFanSpeed2);
SERIAL_EOL;
for (uint8_t i = 0; i < COUNT(lcd_preheat_hotend_temp); i++) {
SERIAL_ECHOPAIR(" M145 S", (int)i);
SERIAL_ECHOPAIR(" H", lcd_preheat_hotend_temp[i]);
SERIAL_ECHOPAIR(" B", lcd_preheat_bed_temp[i]);
SERIAL_ECHOPAIR(" F", lcd_preheat_fan_speed[i]);
SERIAL_EOL;
}
#endif // ULTIPANEL

#if HAS_PID_HEATING
Expand Down
16 changes: 8 additions & 8 deletions Marlin/planner.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ class Planner {
* fr_mm_s - (target) speed of the move (mm/s)
* extruder - target extruder
*/
static FORCE_INLINE void buffer_line(ARG_X, ARG_Y, ARG_Z, const float &e, float fr_mm_s, const uint8_t extruder) {
static FORCE_INLINE void buffer_line(ARG_X, ARG_Y, ARG_Z, const float &e, const float &fr_mm_s, const uint8_t extruder) {
#if PLANNER_LEVELING && IS_CARTESIAN
apply_leveling(lx, ly, lz);
#endif
Expand All @@ -280,7 +280,7 @@ class Planner {
* fr_mm_s - (target) speed of the move (mm/s)
* extruder - target extruder
*/
static FORCE_INLINE void buffer_line_kinematic(const float target[XYZE], float fr_mm_s, const uint8_t extruder) {
static FORCE_INLINE void buffer_line_kinematic(const float target[XYZE], const float &fr_mm_s, const uint8_t extruder) {
#if PLANNER_LEVELING
float pos[XYZ] = { target[X_AXIS], target[Y_AXIS], target[Z_AXIS] };
apply_leveling(pos);
Expand Down Expand Up @@ -311,9 +311,9 @@ class Planner {
_set_position_mm(lx, ly, lz, e);
}
static void set_position_mm_kinematic(const float position[NUM_AXIS]);
static void set_position_mm(const AxisEnum axis, const float& v);
static FORCE_INLINE void set_z_position_mm(const float& z) { set_position_mm(Z_AXIS, z); }
static FORCE_INLINE void set_e_position_mm(const float& e) { set_position_mm(E_AXIS, e); }
static void set_position_mm(const AxisEnum axis, const float &v);
static FORCE_INLINE void set_z_position_mm(const float &z) { set_position_mm(Z_AXIS, z); }
static FORCE_INLINE void set_e_position_mm(const float &e) { set_position_mm(E_AXIS, e); }

/**
* Sync from the stepper positions. (e.g., after an interrupted move)
Expand Down Expand Up @@ -369,7 +369,7 @@ class Planner {
* Calculate the distance (not time) it takes to accelerate
* from initial_rate to target_rate using the given acceleration:
*/
static float estimate_acceleration_distance(float initial_rate, float target_rate, float accel) {
static float estimate_acceleration_distance(const float &initial_rate, const float &target_rate, const float &accel) {
if (accel == 0) return 0; // accel was 0, set acceleration distance to 0
return (sq(target_rate) - sq(initial_rate)) / (accel * 2);
}
Expand All @@ -382,7 +382,7 @@ class Planner {
* This is used to compute the intersection point between acceleration and deceleration
* in cases where the "trapezoid" has no plateau (i.e., never reaches maximum speed)
*/
static float intersection_distance(float initial_rate, float final_rate, float accel, float distance) {
static float intersection_distance(const float &initial_rate, const float &final_rate, const float &accel, const float &distance) {
if (accel == 0) return 0; // accel was 0, set intersection distance to 0
return (accel * 2 * distance - sq(initial_rate) + sq(final_rate)) / (accel * 4);
}
Expand All @@ -392,7 +392,7 @@ class Planner {
* to reach 'target_velocity' using 'acceleration' within a given
* 'distance'.
*/
static float max_allowable_speed(float accel, float target_velocity, float distance) {
static float max_allowable_speed(const float &accel, const float &target_velocity, const float &distance) {
return sqrt(sq(target_velocity) - 2 * accel * distance);
}

Expand Down
Loading