filament autoload - better detection algorithm, autoload in M600 from menu

unload menu always visible
This commit is contained in:
Robert Pelnar 2017-12-22 20:14:26 +01:00
parent 33d715616f
commit 6abba7bfe9
3 changed files with 29 additions and 18 deletions

View File

@ -5600,15 +5600,21 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp
//load_filament_time = millis();
KEEPALIVE_STATE(PAUSED_FOR_USER);
#ifdef PAT9125
if (filament_autoload_enabled && fsensor_M600) fsensor_autoload_check_start();
if (filament_autoload_enabled && (old_fsensor_enabled || fsensor_M600)) fsensor_autoload_check_start();
#endif //PAT9125
// printf_P(PSTR("M600 PAT9125 filament_autoload_enabled=%d, old_fsensor_enabled=%d, fsensor_M600=%d"), filament_autoload_enabled, old_fsensor_enabled, fsensor_M600);
while(!lcd_clicked())
{
manage_heater();
manage_inactivity(true);
#ifdef PAT9125
if (filament_autoload_enabled && fsensor_M600 && fsensor_check_autoload())
if (filament_autoload_enabled && (old_fsensor_enabled || fsensor_M600) && fsensor_check_autoload())
{
tone(BEEPER, 1000);
delay_keep_alive(50);
noTone(BEEPER);
break;
}
#endif //PAT9125
/*#ifdef SNMM
target[E_AXIS] += 0.002;
@ -5618,7 +5624,7 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp
}
#ifdef PAT9125
if (filament_autoload_enabled && fsensor_M600) fsensor_autoload_check_stop();
if (filament_autoload_enabled && (old_fsensor_enabled || fsensor_M600)) fsensor_autoload_check_stop();
#endif //PAT9125
//WRITE(BEEPER, LOW);
KEEPALIVE_STATE(IN_HANDLER);
@ -6400,6 +6406,9 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) //default argument s
if (fsensor_check_autoload())
{
fsensor_autoload_check_stop();
tone(BEEPER, 1000);
delay_keep_alive(50);
noTone(BEEPER);
enquecommand_front_P((PSTR("M701")));
}
}

View File

@ -46,6 +46,7 @@ bool fsensor_autoload_enabled = false;
uint16_t fsensor_autoload_y = 0;
uint8_t fsensor_autoload_c = 0;
uint32_t fsensor_autoload_last_millis = 0;
uint8_t fsensor_autoload_sum = 0;
void fsensor_block()
{
@ -108,6 +109,7 @@ void fsensor_autoload_check_start(void)
pat9125_update_y(); //update sensor
fsensor_autoload_y = pat9125_y; //save current y value
fsensor_autoload_c = 0; //reset number of changes counter
fsensor_autoload_sum = 0;
fsensor_autoload_last_millis = millis();
fsensor_autoload_enabled = true;
fsensor_err_cnt = 0;
@ -116,36 +118,36 @@ void fsensor_autoload_check_start(void)
void fsensor_autoload_check_stop(void)
{
puts_P(PSTR("fsensor_autoload_check_stop\n"));
fsensor_autoload_sum = 0;
fsensor_autoload_enabled = false;
fsensor_err_cnt = 0;
}
bool fsensor_check_autoload(void)
{
if ((millis() - fsensor_autoload_last_millis) < 50) return false;
uint8_t fsensor_autoload_c_old = fsensor_autoload_c;
if ((millis() - fsensor_autoload_last_millis) < 25) return false;
fsensor_autoload_last_millis = millis();
pat9125_update_y(); //update sensor
uint16_t dy = fsensor_autoload_y - pat9125_y;
int16_t dy = fsensor_autoload_y - pat9125_y;
if (dy) //? y value is different
{
if (dy > 0) //? delta-y value is positive (inserting)
if (dy < 0) //? delta-y value is positive (inserting)
{
fsensor_autoload_c+=3; //increment change counter
// printf_P(PSTR("fsensor_check_autoload dy=%d c=%d\n"), dy, fsensor_autoload_c);
}
else if (fsensor_autoload_c > 0)
{
fsensor_autoload_c--;
// printf_P(PSTR("fsensor_check_autoload dy=%d c=%d\n"), dy, fsensor_autoload_c);
fsensor_autoload_sum -= dy;
fsensor_autoload_c += 3; //increment change counter by 3
}
else if (fsensor_autoload_c > 1)
fsensor_autoload_c -= 2; //decrement change counter by 2
fsensor_autoload_y = pat9125_y; //save current value
if (fsensor_autoload_c > 10) return true; //number of positive changes > 10, start loading
}
else if (fsensor_autoload_c > 0)
{
fsensor_autoload_c--;
// printf_P(PSTR("fsensor_check_autoload dy=%d c=%d\n"), dy, fsensor_autoload_c);
}
if (fsensor_autoload_c == 0) fsensor_autoload_sum = 0;
// if (fsensor_autoload_c != fsensor_autoload_c_old)
// printf_P(PSTR("fsensor_check_autoload dy=%d c=%d sum=%d\n"), dy, fsensor_autoload_c, fsensor_autoload_sum);
if ((fsensor_autoload_c >= 15) && (fsensor_autoload_sum > 30))
return true;
return false;
}

View File

@ -5027,8 +5027,8 @@ static void lcd_main_menu()
if (!filament_autoload_enabled)
{
MENU_ITEM(function, MSG_LOAD_FILAMENT, lcd_LoadFilament);
MENU_ITEM(function, MSG_UNLOAD_FILAMENT, lcd_unLoadFilament);
}
MENU_ITEM(function, MSG_UNLOAD_FILAMENT, lcd_unLoadFilament);
#endif
#ifdef SNMM
MENU_ITEM(submenu, MSG_LOAD_FILAMENT, fil_load_menu);