M600: lcd_change_fil_state does not need to be global

Refactor lcd_alright() to save flash

Change in memory:
Flash: -98 bytes
SRAM: -1 bytes
This commit is contained in:
Guðni Már Gilbert 2022-09-03 12:16:35 +00:00 committed by D.R.racer
parent 2216ba9fbf
commit f297131792
4 changed files with 53 additions and 72 deletions

View File

@ -281,7 +281,6 @@ extern float max_pos[3];
extern bool axis_known_position[3];
extern int fanSpeed;
extern uint8_t newFanSpeed;
extern int8_t lcd_change_fil_state;
extern float default_retraction;
void get_coordinates();

View File

@ -189,8 +189,6 @@ int extruder_multiply[EXTRUDERS] = {100
bool homing_flag = false;
int8_t lcd_change_fil_state = 0;
unsigned long pause_time = 0;
unsigned long start_pause_print = _millis();
unsigned long t_fan_rising_edge = _millis();
@ -3566,8 +3564,6 @@ static void gcode_M600(bool automatic, float x_position, float y_position, float
if (!MMU2::mmu2.Enabled())
M600_wait_for_user(HotendTempBckp);
lcd_change_fil_state = 0;
// Unload filament
if (MMU2::mmu2.Enabled())
mmu_M600_unload_filament();
@ -3579,9 +3575,9 @@ static void gcode_M600(bool automatic, float x_position, float y_position, float
if (!MMU2::mmu2.Enabled()) {
KEEPALIVE_STATE(PAUSED_FOR_USER);
lcd_change_fil_state =
uint8_t choice =
lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Was filament unload successful?"), false, LCD_LEFT_BUTTON_CHOICE); ////MSG_UNLOAD_SUCCESSFUL c=20 r=2
if (lcd_change_fil_state == LCD_MIDDLE_BUTTON_CHOICE) {
if (choice == LCD_MIDDLE_BUTTON_CHOICE) {
lcd_clear();
lcd_puts_at_P(0, 2, _T(MSG_PLEASE_WAIT));
current_position[X_AXIS] -= 100;
@ -11505,14 +11501,13 @@ void load_filament_final_feed()
//! @par nozzle_temp nozzle temperature to load filament
void M600_check_state(float nozzle_temp)
{
lcd_change_fil_state = 0;
while (lcd_change_fil_state != 1)
uint8_t lcd_change_filament_state = 0;
while (lcd_change_filament_state != 1)
{
lcd_change_fil_state = 0;
KEEPALIVE_STATE(PAUSED_FOR_USER);
lcd_alright();
lcd_change_filament_state = lcd_alright();
KEEPALIVE_STATE(IN_HANDLER);
switch(lcd_change_fil_state)
switch(lcd_change_filament_state)
{
// Filament failed to load so load it again
case 2:

View File

@ -2255,74 +2255,61 @@ void lcd_loading_filament() {
void lcd_alright() {
int enc_dif = 0;
int cursor_pos = 1;
uint8_t lcd_alright() {
int8_t enc_dif = 0;
uint8_t cursor_pos = 1;
lcd_clear();
lcd_puts_at_P(0, 0, _i("Changed correctly?"));////MSG_CORRECTLY c=20
lcd_puts_at_P(1, 1, _T(MSG_YES));
lcd_puts_at_P(1, 2, _i("Filament not loaded"));////MSG_NOT_LOADED c=19
lcd_puts_at_P(1, 3, _i("Color not correct"));////MSG_NOT_COLOR c=19
lcd_putc_at(0, 1, '>');
enc_dif = lcd_encoder_diff;
lcd_consume_click();
while (1)
{
manage_heater();
manage_inactivity(true);
if (abs(enc_dif - lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP)
{
lcd_clear();
if (enc_dif > lcd_encoder_diff ) {
// Rotating knob counter clockwise
cursor_pos--;
} else if (enc_dif < lcd_encoder_diff) {
// Rotating knob clockwise
cursor_pos++;
}
if (cursor_pos > 3) {
cursor_pos = 3;
Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
} else if (cursor_pos < 1) {
cursor_pos = 1;
Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
}
lcd_puts_at_P(0, 0, _i("Changed correctly?"));////MSG_CORRECTLY c=20
lcd_puts_at_P(1, 1, _T(MSG_YES));
lcd_puts_at_P(1, 2, _i("Filament not loaded"));////MSG_NOT_LOADED c=19
lcd_puts_at_P(1, 3, _i("Color not correct"));////MSG_NOT_COLOR c=19
lcd_putc_at(0, 1, '>');
// Update '>' render only
lcd_puts_at_P(0, 1, PSTR(" \n \n "));
lcd_putc_at(0, cursor_pos, '>');
enc_dif = lcd_encoder_diff;
lcd_consume_click();
while (lcd_change_fil_state == 0) {
manage_heater();
manage_inactivity(true);
if ( abs((enc_dif - lcd_encoder_diff)) > 4 ) {
if ( (abs(enc_dif - lcd_encoder_diff)) > 1 ) {
if (enc_dif > lcd_encoder_diff ) {
cursor_pos --;
// Consume rotation event and make feedback sound
enc_dif = lcd_encoder_diff;
Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
_delay(100);
}
if (enc_dif < lcd_encoder_diff ) {
cursor_pos ++;
if (lcd_clicked())
{
Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
lcd_clear();
lcd_return_to_status();
return cursor_pos;
}
if (cursor_pos > 3) {
cursor_pos = 3;
Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
}
if (cursor_pos < 1) {
cursor_pos = 1;
Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
}
lcd_puts_at_P(0, 1, PSTR(" \n \n "));
lcd_putc_at(0, cursor_pos, '>');
enc_dif = lcd_encoder_diff;
Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
_delay(100);
}
}
if (lcd_clicked()) {
Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
lcd_change_fil_state = cursor_pos;
_delay(500);
}
};
lcd_clear();
lcd_return_to_status();
};
}
void show_preheat_nozzle_warning()

View File

@ -36,7 +36,7 @@ void lcd_reset_alert_level();
void lcd_adjust_z();
void lcd_pick_babystep();
void lcd_alright();
uint8_t lcd_alright();
void show_preheat_nozzle_warning();
void lcd_wait_interact();
void lcd_loading_filament();