Skip to content
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

IFNDEF more code that is releated to Filament Autoload #1

Closed
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
22 changes: 18 additions & 4 deletions Firmware/Filament_sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
#ifdef FILAMENT_SENSOR
FSensorBlockRunout::FSensorBlockRunout() {
fsensor.setRunoutEnabled(false); //suppress filament runouts while loading filament.
#ifndef REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
fsensor.setAutoLoadEnabled(false); //suppress filament autoloads while loading filament.
#endif //NOT REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
#if (FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
fsensor.setJamDetectionEnabled(false); //suppress filament jam detection while loading filament.
#endif //(FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
Expand Down Expand Up @@ -50,12 +52,14 @@ void Filament_sensor::setEnabled(bool enabled) {
}
}

#ifndef REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
void Filament_sensor::setAutoLoadEnabled(bool state, bool updateEEPROM) {
autoLoadEnabled = state;
if (updateEEPROM) {
eeprom_update_byte_notify((uint8_t *)EEPROM_FSENS_AUTOLOAD_ENABLED, state);
}
}
#endif //NOT REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY

void Filament_sensor::setRunoutEnabled(bool state, bool updateEEPROM) {
runoutEnabled = state;
Expand All @@ -77,7 +81,9 @@ void Filament_sensor::settings_init_common() {
state = enabled ? State::initializing : State::disabled;
}

#ifndef REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
autoLoadEnabled = eeprom_read_byte((uint8_t *)EEPROM_FSENS_AUTOLOAD_ENABLED);
#endif //NOT REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
runoutEnabled = eeprom_read_byte((uint8_t *)EEPROM_FSENS_RUNOUT_ENABLED);
sensorActionOnError = (SensorActionOnError)eeprom_read_byte((uint8_t *)EEPROM_FSENSOR_ACTION_NA);
if (sensorActionOnError == SensorActionOnError::_Undef) {
Expand All @@ -96,19 +102,22 @@ bool Filament_sensor::checkFilamentEvents() {
if (oldFilamentPresent != newFilamentPresent) {
oldFilamentPresent = newFilamentPresent;
eventBlankingTimer.start();
if (newFilamentPresent) { // filament insertion
if (!newFilamentPresent) { // filament removed
// puts_P(PSTR("filament removed"));
triggerFilamentRemoved();
#ifndef REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
} else { // filament removal
// puts_P(PSTR("filament inserted"));
triggerFilamentInserted();
postponedLoadEvent = true;
} else { // filament removal
// puts_P(PSTR("filament removed"));
triggerFilamentRemoved();
#endif //NOT REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
}
return true;
}
return false;
}

#ifndef REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
void Filament_sensor::triggerFilamentInserted() {
if (autoLoadEnabled
&& (eFilamentAction == FilamentAction::None)
Expand All @@ -123,6 +132,7 @@ void Filament_sensor::triggerFilamentInserted() {
menu_submenu(lcd_AutoLoadFilament, true);
}
}
#endif //NOT REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY

void Filament_sensor::triggerFilamentRemoved() {
// SERIAL_ECHOLNPGM("triggerFilamentRemoved");
Expand Down Expand Up @@ -151,7 +161,9 @@ void Filament_sensor::filRunout() {
// SERIAL_ECHOLNPGM("filRunout");
sendHostNotification_P(MSG_FILAMENT_RUNOUT_DETECTED);
runoutEnabled = false;
#ifndef REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
autoLoadEnabled = false;
#endif //NOT REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
stop_and_save_print_to_ram(0, 0);
restore_print_from_ram_and_continue(0);
eeprom_increment_byte((uint8_t *)EEPROM_FERROR_COUNT);
Expand Down Expand Up @@ -455,7 +467,9 @@ void PAT9125_sensor::resetStepCount() {

void PAT9125_sensor::filJam() {
runoutEnabled = false;
#ifndef REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
autoLoadEnabled = false;
#endif //NOT REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
jamDetection = false;
stop_and_save_print_to_ram(0, 0);
restore_print_from_ram_and_continue(0);
Expand Down
6 changes: 6 additions & 0 deletions Firmware/Filament_sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ class Filament_sensor {

static void setEnabled(bool enabled);

#ifndef REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
void setAutoLoadEnabled(bool state, bool updateEEPROM = false);
bool getAutoLoadEnabled() const { return autoLoadEnabled; }
#endif //NOT REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
Comment on lines +49 to +52
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is the correct approach, you're disabling too much. These functions are not just used for the Autoload menu item. It's used by triggerFilamentInserted() too for normal autoload functionality.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually these shouldn't be used when autoload is disabled. There in the 3rd commit I removed even more code and tested it with MK404

  • MK3S
  • MK3S + MMU
  • MK2.5S


void setRunoutEnabled(bool state, bool updateEEPROM = false);
bool getRunoutEnabled() const { return runoutEnabled; }
Expand All @@ -66,7 +68,9 @@ class Filament_sensor {

bool checkFilamentEvents();

#ifndef REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
void triggerFilamentInserted();
#endif //NOT REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY

void triggerFilamentRemoved();

Expand All @@ -75,7 +79,9 @@ class Filament_sensor {
void triggerError();

State state;
#ifndef REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
bool autoLoadEnabled;
#endif //NOT REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
bool runoutEnabled;
bool oldFilamentPresent; //for creating filament presence switching events.
bool postponedLoadEvent; //this event lasts exactly one update cycle. It is long enough to be able to do polling for load event.
Expand Down
4 changes: 4 additions & 0 deletions Firmware/Marlin_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,9 @@ void debug_printer_states()
printf_P(PSTR("DBG:fsensor.getFilamentPresent() = %d\n"), (int)fsensor.getFilamentPresent());
printf_P(PSTR("DBG:MMU CUTTER ENABLED = %d\n"), (int)eeprom_read_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED));
printf_P(PSTR("DBG:fsensor.isEnabled() = %d\n"), (int)fsensor.isEnabled());
#ifndef REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
printf_P(PSTR("DBG:fsensor.getAutoLoadEnabled() = %d\n"), (int)fsensor.getAutoLoadEnabled());
#endif //NOT REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
printf_P(PSTR("DBG:custom_message_type = %d\n"), (int)custom_message_type);
printf_P(PSTR("DBG:uvlo_auto_recovery_ready = %d\n"), (int)uvlo_auto_recovery_ready);
SERIAL_ECHOLN("");
Expand Down Expand Up @@ -769,7 +771,9 @@ static void factory_reset(char level)

#ifdef FILAMENT_SENSOR
fsensor.setEnabled(true);
#ifndef REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
fsensor.setAutoLoadEnabled(true, true);
#endif //NOT REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
fsensor.setRunoutEnabled(true, true);
#if (FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
fsensor.setJamDetectionEnabled(true, true);
Expand Down
2 changes: 2 additions & 0 deletions Firmware/Prusa_farm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,9 @@ void farm_mode_init() {
#ifdef FILAMENT_SENSOR
//to be converted to Filament_sensor.h...
//disabled filament autoload (PFW360)
#ifndef REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
fsensor.setAutoLoadEnabled(false);
#endif //NOT REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
#endif //FILAMENT_SENSOR
// ~ FanCheck -> on
eeprom_update_byte_notify((uint8_t*)EEPROM_FAN_CHECK_ENABLED, true);
Expand Down
2 changes: 1 addition & 1 deletion Firmware/messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ extern const char MSG_NOT_LOADED [] PROGMEM_I1 = ISTR("Filament not loaded"); //
extern const char MSG_NOT_COLOR [] PROGMEM_I1 = ISTR("Color not correct"); ////MSG_NOT_COLOR c=19
#ifndef REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
extern const char MSG_AUTOLOADING_ENABLED [] PROGMEM_I1 = ISTR("Autoloading filament is active, just press the knob and insert filament..."); ////MSG_AUTOLOADING_ENABLED c=20 r=4
#endif //REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
#endif //NOT REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
extern const char MSG_FILAMENT_USED [] PROGMEM_I1 = ISTR("Filament used"); ////MSG_FILAMENT_USED c=19
extern const char MSG_PRINT_TIME [] PROGMEM_I1 = ISTR("Print time"); ////MSG_PRINT_TIME c=19
extern const char MSG_TOTAL_FILAMENT [] PROGMEM_I1 = ISTR("Total filament"); ////MSG_TOTAL_FILAMENT c=19
Expand Down
2 changes: 1 addition & 1 deletion Firmware/messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ extern const char MSG_NOT_LOADED [];
extern const char MSG_NOT_COLOR [];
#ifndef REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
extern const char MSG_AUTOLOADING_ENABLED [];
#endif //REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
#endif //NOT REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
extern const char MSG_FILAMENT_USED [];
extern const char MSG_PRINT_TIME [];
extern const char MSG_TOTAL_FILAMENT [];
Expand Down
48 changes: 34 additions & 14 deletions Firmware/ultralcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1772,7 +1772,9 @@ bool shouldPreheatOnlyNozzle() {

switch(eFilamentAction) {
case FilamentAction::Load:
#ifndef REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
case FilamentAction::AutoLoad:
#endif //NOT REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
case FilamentAction::UnLoad:
case FilamentAction::MmuLoad:
case FilamentAction::MmuUnLoad:
Expand Down Expand Up @@ -1804,7 +1806,9 @@ static void mFilamentPrompt() {
lcd_set_cursor(0,2);
switch(eFilamentAction) {
case FilamentAction::Load:
#ifndef REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
case FilamentAction::AutoLoad:
#endif //NOT REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
case FilamentAction::MmuLoad:
case FilamentAction::MmuLoadingTest:
lcd_puts_P(_T(MSG_TO_LOAD_FIL));
Expand All @@ -1824,15 +1828,21 @@ static void mFilamentPrompt() {
if(lcd_clicked()
#ifdef FILAMENT_SENSOR
/// @todo leptun - add this as a specific retest item
|| (((eFilamentAction == FilamentAction::Load) || (eFilamentAction == FilamentAction::AutoLoad)) && fsensor.getFilamentLoadEvent())
|| (((eFilamentAction == FilamentAction::Load)
#ifndef REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
|| (eFilamentAction == FilamentAction::AutoLoad)
#endif //NOT REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
) && fsensor.getFilamentLoadEvent())
#endif //FILAMENT_SENSOR
) {
menu_back(bFilamentPreheatState ? 2 : 3);
switch(eFilamentAction) {
#ifndef REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
case FilamentAction::AutoLoad:
// loading no longer cancellable
eFilamentAction = FilamentAction::Load;
[[fallthrough]];
#endif //NOT REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
case FilamentAction::Load:
enquecommand_P(MSG_M701); // load filament
break;
Expand Down Expand Up @@ -1901,17 +1911,20 @@ void mFilamentItem(uint16_t nTemp, uint16_t nTempBed)
switch (eFilamentAction)
{
case FilamentAction::Load:
#ifndef REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
case FilamentAction::AutoLoad:
#endif //NOT REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
case FilamentAction::UnLoad:
if (bFilamentWaitingFlag) menu_submenu(mFilamentPrompt, true);
else
{
mFilamentResetMenuStack();
#ifndef REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
if (eFilamentAction == FilamentAction::AutoLoad) {
// loading no longer cancellable
eFilamentAction = FilamentAction::Load;
}

#endif //NOT REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
if (eFilamentAction == FilamentAction::Load)
enquecommand_P(MSG_M701); // load filament
else if (eFilamentAction == FilamentAction::UnLoad)
Expand Down Expand Up @@ -1983,7 +1996,9 @@ void mFilamentItem(uint16_t nTemp, uint16_t nTempBed)
switch (eFilamentAction)
{
case FilamentAction::Load:
#ifndef REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
case FilamentAction::AutoLoad:
#endif //NOT REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
case FilamentAction::MmuLoad:
case FilamentAction::MmuLoadingTest:
lcd_puts_P(_T(MSG_PREHEATING_TO_LOAD));
Expand Down Expand Up @@ -2145,9 +2160,9 @@ void lcd_wait_interact(const char* filament_name) {
lcd_print(filament_name);
lcd_set_cursor(0, 2);
}
#ifdef FILAMENT_SENSOR
#if defined FILAMENT_SENSOR && !defined(REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY)
if (!fsensor.getAutoLoadEnabled())
#endif //FILAMENT_SENSOR
#endif //FILAMENT_SENSOR AND NOT REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
{
lcd_puts_P(_T(MSG_PRESS));
}
Expand Down Expand Up @@ -2308,10 +2323,11 @@ static void lcd_LoadFilament()
preheat_or_continue(FilamentAction::Load);
}

#ifndef REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
void lcd_AutoLoadFilament() {
preheat_or_continue(FilamentAction::AutoLoad);
}

#endif //NOT REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY

//! @brief Show filament used a print time
//!
Expand Down Expand Up @@ -4024,9 +4040,11 @@ static void lcd_fsensor_runout_set() {
fsensor.setRunoutEnabled(!fsensor.getRunoutEnabled(), true);
}

#ifndef REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
static void lcd_fsensor_autoload_set() {
fsensor.setAutoLoadEnabled(!fsensor.getAutoLoadEnabled(), true);
}
#endif //NOT REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY

#if FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125
static void lcd_fsensor_jam_detection_set() {
Expand Down Expand Up @@ -4066,7 +4084,9 @@ static void lcd_fsensor_settings_menu() {
}
else {
MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_RUNOUT), fsensor.getRunoutEnabled() ? _T(MSG_ON) : _T(MSG_OFF), lcd_fsensor_runout_set);
#ifndef REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_AUTOLOAD), fsensor.getAutoLoadEnabled() ? _T(MSG_ON) : _T(MSG_OFF), lcd_fsensor_autoload_set);
#endif //NOT REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
#if defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_JAM_DETECTION), fsensor.getJamDetectionEnabled() ? _T(MSG_ON) : _T(MSG_OFF), lcd_fsensor_jam_detection_set);
#endif //defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
Expand Down Expand Up @@ -5318,19 +5338,19 @@ static void lcd_main_menu()
} else {
#ifdef FILAMENT_SENSOR
if (fsensor.isEnabled()) {
if (!fsensor.getAutoLoadEnabled()) {
MENU_ITEM_SUBMENU_P(_T(MSG_LOAD_FILAMENT), lcd_LoadFilament);
}
if (fsensor.getFilamentPresent()) {
MENU_ITEM_SUBMENU_P(_T(MSG_UNLOAD_FILAMENT), lcd_unLoadFilament);
}
if (!fsensor.getFilamentPresent()) {
#ifndef REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
else {
if (fsensor.getAutoLoadEnabled()) {
MENU_ITEM_SUBMENU_P(_T(MSG_AUTOLOAD_FILAMENT), lcd_menu_AutoLoadFilament);
}
} else {
#endif //NOT REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
MENU_ITEM_SUBMENU_P(_T(MSG_LOAD_FILAMENT), lcd_LoadFilament);
#ifndef REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
}
#endif //NOT REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
} else {
MENU_ITEM_SUBMENU_P(_T(MSG_UNLOAD_FILAMENT), lcd_unLoadFilament);
}
#endif //REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
} else {
#endif //FILAMENT_SENSOR
MENU_ITEM_SUBMENU_P(_T(MSG_LOAD_FILAMENT), lcd_LoadFilament);
Expand Down
5 changes: 4 additions & 1 deletion Firmware/ultralcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ enum class FilamentAction : uint_least8_t
{
None, // no filament action is taking place
Load,
#ifndef REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
AutoLoad, // triggered by insertion, cancellable until it transitions to Load
#endif //NOT REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
UnLoad,
MmuLoad,
MmuUnLoad,
Expand All @@ -197,8 +199,9 @@ extern FilamentAction eFilamentAction;
void mFilamentItem(uint16_t nTemp,uint16_t nTempBed);
void lcd_generic_preheat_menu();
void unload_filament(float unloadLength);
#ifndef REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
void lcd_AutoLoadFilament();

#endif //NOT REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY

void lcd_wait_for_heater();
void lcd_wait_for_cool_down();
Expand Down
2 changes: 1 addition & 1 deletion Firmware/variants/MK3S.h
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,6 @@
*------------------------------------*/

//Uncomment to remove the "AutoLoad filament" LCD menu entry if autoload is enabled.
//#define REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY
#define REMOVE_AUTOLOAD_FILAMENT_MENU_ENTRY

#endif //__CONFIGURATION_PRUSA_H