FSensor, code cleaning + optical quality meassurement
This commit is contained in:
parent
5483bee885
commit
fd9b9acf4e
@ -638,7 +638,7 @@ void stop_and_save_print_to_ram(float z_move, float e_move);
|
||||
void restore_print_from_ram_and_continue(float e_move);
|
||||
|
||||
bool fans_check_enabled = true;
|
||||
bool filament_autoload_enabled = true;
|
||||
bool fsensor_autoload_enabled = true;
|
||||
|
||||
|
||||
#ifdef TMC2130
|
||||
@ -1187,7 +1187,7 @@ void setup()
|
||||
tmc2130_current_r[E_AXIS] = 36;
|
||||
#endif //TMC2130
|
||||
//disabled filament autoload (PFW360)
|
||||
filament_autoload_enabled = false;
|
||||
fsensor_autoload_enabled = false;
|
||||
eeprom_update_byte((uint8_t*)EEPROM_FSENS_AUTOLOAD_ENABLED, 0);
|
||||
}
|
||||
MYSERIAL.begin(BAUDRATE);
|
||||
@ -1766,38 +1766,6 @@ void setup()
|
||||
#endif //WATCHDOG
|
||||
}
|
||||
|
||||
#ifdef PAT9125
|
||||
void fsensor_init() {
|
||||
int pat9125 = pat9125_init();
|
||||
printf_P(_N("PAT9125_init:%d\n"), pat9125);
|
||||
uint8_t fsensor = eeprom_read_byte((uint8_t*)EEPROM_FSENSOR);
|
||||
filament_autoload_enabled=eeprom_read_byte((uint8_t*)EEPROM_FSENS_AUTOLOAD_ENABLED);
|
||||
if (!pat9125)
|
||||
{
|
||||
fsensor = 0; //disable sensor
|
||||
fsensor_not_responding = true;
|
||||
}
|
||||
else {
|
||||
fsensor_not_responding = false;
|
||||
}
|
||||
puts_P(PSTR("FSensor "));
|
||||
if (fsensor)
|
||||
{
|
||||
puts_P(PSTR("ENABLED\n"));
|
||||
fsensor_enable();
|
||||
}
|
||||
else
|
||||
{
|
||||
puts_P(PSTR("DISABLED\n"));
|
||||
fsensor_disable();
|
||||
}
|
||||
#ifdef DEBUG_DISABLE_FSENSORCHECK
|
||||
filament_autoload_enabled = false;
|
||||
fsensor_disable();
|
||||
#endif //DEBUG_DISABLE_FSENSORCHECK
|
||||
}
|
||||
|
||||
#endif //PAT9125
|
||||
|
||||
void trace();
|
||||
|
||||
@ -3121,7 +3089,7 @@ void gcode_M701()
|
||||
fsensor_st_sum = 0;
|
||||
fsensor_yd_sum = 0;
|
||||
fsensor_er_sum = 0;
|
||||
fsensor_yd_min = 255;
|
||||
fsensor_yd_min = 65535;
|
||||
fsensor_yd_max = 0;
|
||||
|
||||
lcd_setstatuspgm(_T(MSG_LOADING_FILAMENT));
|
||||
@ -6556,14 +6524,14 @@ Sigma_Exit:
|
||||
KEEPALIVE_STATE(PAUSED_FOR_USER);
|
||||
|
||||
#ifdef PAT9125
|
||||
if (filament_autoload_enabled && (old_fsensor_enabled || !fsensor_watch_runout)) fsensor_autoload_check_start();
|
||||
if (fsensor_autoload_enabled && (old_fsensor_enabled || !fsensor_watch_runout)) fsensor_autoload_check_start();
|
||||
#endif //PAT9125
|
||||
while(!lcd_clicked())
|
||||
{
|
||||
manage_heater();
|
||||
manage_inactivity(true);
|
||||
#ifdef PAT9125
|
||||
if (filament_autoload_enabled && (old_fsensor_enabled || !fsensor_watch_runout) && fsensor_check_autoload())
|
||||
if (fsensor_autoload_enabled && (old_fsensor_enabled || !fsensor_watch_runout) && fsensor_check_autoload())
|
||||
{
|
||||
tone(BEEPER, 1000);
|
||||
delay_keep_alive(50);
|
||||
@ -6579,7 +6547,7 @@ Sigma_Exit:
|
||||
|
||||
}
|
||||
#ifdef PAT9125
|
||||
if (filament_autoload_enabled && (old_fsensor_enabled || !fsensor_watch_runout)) fsensor_autoload_check_stop();
|
||||
if (fsensor_autoload_enabled && (old_fsensor_enabled || !fsensor_watch_runout)) fsensor_autoload_check_stop();
|
||||
#endif //PAT9125
|
||||
//WRITE(BEEPER, LOW);
|
||||
KEEPALIVE_STATE(IN_HANDLER);
|
||||
@ -7673,9 +7641,9 @@ static void handleSafetyTimer()
|
||||
void manage_inactivity(bool ignore_stepper_queue/*=false*/) //default argument set in Marlin.h
|
||||
{
|
||||
#ifdef PAT9125
|
||||
if (fsensor_enabled && filament_autoload_enabled && fsensor_watch_runout && !moves_planned() && !IS_SD_PRINTING && !is_usb_printing && (lcd_commands_type != LCD_COMMAND_V2_CAL))
|
||||
if (fsensor_enabled && fsensor_autoload_enabled && fsensor_watch_runout && !moves_planned() && !IS_SD_PRINTING && !is_usb_printing && (lcd_commands_type != LCD_COMMAND_V2_CAL))
|
||||
{
|
||||
if (fsensor_autoload_enabled)
|
||||
if (fsensor_watch_autoload)
|
||||
{
|
||||
if (fsensor_check_autoload())
|
||||
{
|
||||
@ -7708,7 +7676,7 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) //default argument s
|
||||
fsensor_autoload_check_start();
|
||||
}
|
||||
else
|
||||
if (fsensor_autoload_enabled)
|
||||
if (fsensor_watch_autoload)
|
||||
fsensor_autoload_check_stop();
|
||||
#endif //PAT9125
|
||||
|
||||
|
@ -21,12 +21,43 @@ extern void stop_and_save_print_to_ram(float z_move, float e_move);
|
||||
extern void restore_print_from_ram_and_continue(float e_move);
|
||||
extern int8_t FSensorStateMenu;
|
||||
|
||||
void fsensor_stop_and_save_print()
|
||||
void fsensor_init(void)
|
||||
{
|
||||
int pat9125 = pat9125_init();
|
||||
printf_P(_N("PAT9125_init:%d\n"), pat9125);
|
||||
uint8_t fsensor = eeprom_read_byte((uint8_t*)EEPROM_FSENSOR);
|
||||
fsensor_autoload_enabled=eeprom_read_byte((uint8_t*)EEPROM_FSENS_AUTOLOAD_ENABLED);
|
||||
if (!pat9125)
|
||||
{
|
||||
fsensor = 0; //disable sensor
|
||||
fsensor_not_responding = true;
|
||||
}
|
||||
else {
|
||||
fsensor_not_responding = false;
|
||||
}
|
||||
puts_P(PSTR("FSensor "));
|
||||
if (fsensor)
|
||||
{
|
||||
puts_P(PSTR("ENABLED\n"));
|
||||
fsensor_enable();
|
||||
}
|
||||
else
|
||||
{
|
||||
puts_P(PSTR("DISABLED\n"));
|
||||
fsensor_disable();
|
||||
}
|
||||
#ifdef DEBUG_DISABLE_FSENSORCHECK
|
||||
fsensor_autoload_enabled = false;
|
||||
fsensor_disable();
|
||||
#endif //DEBUG_DISABLE_FSENSORCHECK
|
||||
}
|
||||
|
||||
void fsensor_stop_and_save_print(void)
|
||||
{
|
||||
stop_and_save_print_to_ram(0, 0); //XYZE - no change
|
||||
}
|
||||
|
||||
void fsensor_restore_print_and_continue()
|
||||
void fsensor_restore_print_and_continue(void)
|
||||
{
|
||||
restore_print_from_ram_and_continue(0); //XYZ = orig, E - no change
|
||||
}
|
||||
@ -46,7 +77,7 @@ int16_t fsensor_st_cnt = 0;
|
||||
uint8_t fsensor_log = 1;
|
||||
|
||||
//autoload enable/disable flag
|
||||
bool fsensor_autoload_enabled = false;
|
||||
bool fsensor_watch_autoload = false;
|
||||
uint16_t fsensor_autoload_y = 0;
|
||||
uint8_t fsensor_autoload_c = 0;
|
||||
uint32_t fsensor_autoload_last_millis = 0;
|
||||
@ -55,10 +86,10 @@ uint8_t fsensor_autoload_sum = 0;
|
||||
uint32_t fsensor_st_sum = 0;
|
||||
uint32_t fsensor_yd_sum = 0;
|
||||
uint32_t fsensor_er_sum = 0;
|
||||
uint8_t fsensor_yd_min = 255;
|
||||
uint8_t fsensor_yd_max = 0;
|
||||
uint16_t fsensor_yd_min = 65535;
|
||||
uint16_t fsensor_yd_max = 0;
|
||||
|
||||
bool fsensor_enable()
|
||||
bool fsensor_enable(void)
|
||||
{
|
||||
// puts_P(PSTR("fsensor_enable\n"));
|
||||
int pat9125 = pat9125_init();
|
||||
@ -81,7 +112,7 @@ bool fsensor_enable()
|
||||
return fsensor_enabled;
|
||||
}
|
||||
|
||||
void fsensor_disable()
|
||||
void fsensor_disable(void)
|
||||
{
|
||||
// puts_P(PSTR("fsensor_disable\n"));
|
||||
fsensor_enabled = false;
|
||||
@ -91,8 +122,8 @@ void fsensor_disable()
|
||||
|
||||
void fsensor_autoload_set(bool State)
|
||||
{
|
||||
filament_autoload_enabled = State;
|
||||
eeprom_update_byte((unsigned char *)EEPROM_FSENS_AUTOLOAD_ENABLED, filament_autoload_enabled);
|
||||
fsensor_autoload_enabled = State;
|
||||
eeprom_update_byte((unsigned char *)EEPROM_FSENS_AUTOLOAD_ENABLED, fsensor_autoload_enabled);
|
||||
}
|
||||
|
||||
void pciSetup(byte pin)
|
||||
@ -102,19 +133,6 @@ void pciSetup(byte pin)
|
||||
PCICR |= bit (digitalPinToPCICRbit(pin)); // enable interrupt for the group
|
||||
}
|
||||
|
||||
void fsensor_setup_interrupt()
|
||||
{
|
||||
// uint8_t fsensor_int_pin = FSENSOR_INT_PIN;
|
||||
// uint8_t fsensor_int_pcmsk = digitalPinToPCMSKbit(pin);
|
||||
// uint8_t fsensor_int_pcicr = digitalPinToPCICRbit(pin);
|
||||
|
||||
pinMode(FSENSOR_INT_PIN, OUTPUT);
|
||||
digitalWrite(FSENSOR_INT_PIN, LOW);
|
||||
fsensor_int_pin_old = 0;
|
||||
|
||||
pciSetup(FSENSOR_INT_PIN);
|
||||
}
|
||||
|
||||
void fsensor_autoload_check_start(void)
|
||||
{
|
||||
// puts_P(PSTR("fsensor_autoload_check_start\n"));
|
||||
@ -123,14 +141,14 @@ void fsensor_autoload_check_start(void)
|
||||
printf_P(ERRMSG_PAT9125_NOT_RESP, 3);
|
||||
fsensor_disable();
|
||||
fsensor_not_responding = true;
|
||||
fsensor_autoload_enabled = false;
|
||||
fsensor_watch_autoload = false;
|
||||
return;
|
||||
}
|
||||
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_watch_autoload = true;
|
||||
fsensor_err_cnt = 0;
|
||||
}
|
||||
|
||||
@ -138,7 +156,7 @@ void fsensor_autoload_check_stop(void)
|
||||
{
|
||||
// puts_P(PSTR("fsensor_autoload_check_stop\n"));
|
||||
fsensor_autoload_sum = 0;
|
||||
fsensor_autoload_enabled = false;
|
||||
fsensor_watch_autoload = false;
|
||||
fsensor_err_cnt = 0;
|
||||
}
|
||||
|
||||
@ -208,8 +226,8 @@ ISR(PCINT2_vect)
|
||||
fsensor_err_cnt--;
|
||||
if (st_cnt == FSENSOR_CHUNK_LEN)
|
||||
{
|
||||
if (fsensor_yd_min > pat9125_y) fsensor_yd_min = pat9125_y;
|
||||
if (fsensor_yd_max < pat9125_y) fsensor_yd_max = pat9125_y;
|
||||
if (fsensor_yd_min > pat9125_y) fsensor_yd_min = (fsensor_yd_min + pat9125_y) / 2;
|
||||
if (fsensor_yd_max < pat9125_y) fsensor_yd_max = (fsensor_yd_max + pat9125_y) / 2;
|
||||
}
|
||||
}
|
||||
fsensor_st_sum += st_cnt;
|
||||
@ -262,7 +280,7 @@ void fsensor_st_block_chunk(block_t* bl, int cnt)
|
||||
// _WRITE(fsensor_int_pin, LOW);
|
||||
}
|
||||
|
||||
void fsensor_update()
|
||||
void fsensor_update(void)
|
||||
{
|
||||
if (fsensor_enabled && fsensor_watch_runout)
|
||||
if (fsensor_err_cnt > FSENSOR_ERR_MAX)
|
||||
@ -295,4 +313,18 @@ void fsensor_update()
|
||||
}
|
||||
}
|
||||
|
||||
void fsensor_setup_interrupt(void)
|
||||
{
|
||||
// uint8_t fsensor_int_pin = FSENSOR_INT_PIN;
|
||||
// uint8_t fsensor_int_pcmsk = digitalPinToPCMSKbit(pin);
|
||||
// uint8_t fsensor_int_pcicr = digitalPinToPCICRbit(pin);
|
||||
|
||||
pinMode(FSENSOR_INT_PIN, OUTPUT);
|
||||
digitalWrite(FSENSOR_INT_PIN, LOW);
|
||||
fsensor_int_pin_old = 0;
|
||||
|
||||
pciSetup(FSENSOR_INT_PIN);
|
||||
}
|
||||
|
||||
|
||||
#endif //PAT9125
|
||||
|
@ -7,21 +7,23 @@
|
||||
#define FSENSOR_CHUNK_LEN 180 //filament sensor chunk length in steps - 0.64mm
|
||||
|
||||
//save restore printing
|
||||
extern void fsensor_stop_and_save_print();
|
||||
extern void fsensor_restore_print_and_continue();
|
||||
extern void fsensor_stop_and_save_print(void);
|
||||
extern void fsensor_restore_print_and_continue(void);
|
||||
|
||||
extern void fsensor_init(void);
|
||||
|
||||
//enable/disable
|
||||
extern bool fsensor_enable();
|
||||
extern void fsensor_disable();
|
||||
extern bool fsensor_enable(void);
|
||||
extern void fsensor_disable(void);
|
||||
|
||||
extern bool filament_autoload_enabled;
|
||||
extern bool fsensor_autoload_enabled;
|
||||
extern void fsensor_autoload_set(bool State);
|
||||
|
||||
//update (perform M600 on filament runout)
|
||||
extern void fsensor_update();
|
||||
extern void fsensor_update(void);
|
||||
|
||||
//setup pin-change interrupt
|
||||
extern void fsensor_setup_interrupt();
|
||||
extern void fsensor_setup_interrupt(void);
|
||||
|
||||
//
|
||||
extern void fsensor_autoload_check_start(void);
|
||||
@ -48,13 +50,13 @@ extern bool fsensor_not_responding;
|
||||
extern uint8_t fsensor_err_cnt;
|
||||
|
||||
//autoload enable/disable flag
|
||||
extern bool fsensor_autoload_enabled;
|
||||
extern bool fsensor_watch_autoload;
|
||||
|
||||
|
||||
extern uint32_t fsensor_st_sum;
|
||||
extern uint32_t fsensor_yd_sum;
|
||||
extern uint32_t fsensor_er_sum;
|
||||
extern uint8_t fsensor_yd_min;
|
||||
extern uint8_t fsensor_yd_max;
|
||||
extern uint16_t fsensor_yd_min;
|
||||
extern uint16_t fsensor_yd_max;
|
||||
|
||||
#endif //FSENSOR_H
|
||||
|
@ -38,7 +38,7 @@
|
||||
|
||||
extern int lcd_change_fil_state;
|
||||
extern bool fans_check_enabled;
|
||||
extern bool filament_autoload_enabled;
|
||||
extern bool fsensor_autoload_enabled;
|
||||
|
||||
#ifdef PAT9125
|
||||
extern bool fsensor_not_responding;
|
||||
@ -2280,7 +2280,7 @@ void lcd_set_fan_check() {
|
||||
}
|
||||
|
||||
void lcd_set_filament_autoload() {
|
||||
fsensor_autoload_set(!filament_autoload_enabled);
|
||||
fsensor_autoload_set(!fsensor_autoload_enabled);
|
||||
}
|
||||
|
||||
void lcd_unLoadFilament()
|
||||
@ -4102,7 +4102,7 @@ static void lcd_fsensor_state_set()
|
||||
FSensorStateMenu = !FSensorStateMenu; //set also from fsensor_enable() and fsensor_disable()
|
||||
if (!FSensorStateMenu) {
|
||||
fsensor_disable();
|
||||
if (filament_autoload_enabled)
|
||||
if (fsensor_autoload_enabled)
|
||||
menu_submenu(lcd_filament_autoload_info);
|
||||
}else{
|
||||
fsensor_enable();
|
||||
@ -4609,7 +4609,7 @@ static void lcd_settings_menu()
|
||||
MENU_ITEM_FUNCTION_P(_T(MSG_FSENSOR_ON), lcd_fsensor_state_set);
|
||||
|
||||
|
||||
if (filament_autoload_enabled) {
|
||||
if (fsensor_autoload_enabled) {
|
||||
MENU_ITEM_FUNCTION_P(_i("F. autoload [on]"), lcd_set_filament_autoload);////MSG_FSENS_AUTOLOAD_ON c=17 r=1
|
||||
}
|
||||
else {
|
||||
@ -5948,7 +5948,7 @@ static void lcd_main_menu()
|
||||
|
||||
#else
|
||||
#ifdef PAT9125
|
||||
if ( ((filament_autoload_enabled == true) && (fsensor_enabled == true)))
|
||||
if ( ((fsensor_autoload_enabled == true) && (fsensor_enabled == true)))
|
||||
MENU_ITEM_SUBMENU_P(_i("AutoLoad filament"), lcd_menu_AutoLoadFilament);////MSG_AUTOLOAD_FILAMENT c=17 r=0
|
||||
else
|
||||
#endif //PAT9125
|
||||
|
Loading…
Reference in New Issue
Block a user