From 8af9f788220e09fe97e43c88e095e95aa734760e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Mon, 26 Jul 2021 16:31:34 +0000 Subject: [PATCH 1/4] Optimize farm_mode init in setup() This saves 28 bytes of flash memory --- Firmware/Marlin_main.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 023b646fa..5ae899c97 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -1101,8 +1101,10 @@ void setup() setup_powerhold(); farm_mode = eeprom_read_byte((uint8_t*)EEPROM_FARM_MODE); - if (farm_mode == 0xFF) + if (farm_mode == 0xFF) { farm_mode = false; //if farm_mode has not been stored to eeprom yet and farm number is set to zero or EEPROM is fresh, deactivate farm mode + eeprom_update_byte((uint8_t*)EEPROM_FARM_MODE, farm_mode); + } if (farm_mode) { no_response = true; //we need confirmation by recieving PRUSA thx @@ -1440,13 +1442,6 @@ void setup() enable_z(); #endif - farm_mode = eeprom_read_byte((uint8_t*)EEPROM_FARM_MODE); - if (farm_mode == 0xFF) farm_mode = false; //if farm_mode has not been stored to eeprom yet and farm number is set to zero or EEPROM is fresh, deactivate farm mode - if (farm_mode) - { - prusa_statistics(8); - } - // Enable Toshiba FlashAir SD card / WiFi enahanced card. card.ToshibaFlashAir_enable(eeprom_read_byte((unsigned char*)EEPROM_TOSHIBA_FLASH_AIR_COMPATIBLITY) == 1); From 19dc05597dc113ae6acd84f7b19d2aeb6e0fb5fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sat, 5 Feb 2022 11:24:04 +0000 Subject: [PATCH 2/4] Fix identation in PR Also combined the if statements that check farm_mode If farm_mode is 0xFF then we can skip the next if statment. No change in memory footprint --- Firmware/Marlin_main.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 5ae899c97..23c517982 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -1103,10 +1103,8 @@ void setup() farm_mode = eeprom_read_byte((uint8_t*)EEPROM_FARM_MODE); if (farm_mode == 0xFF) { farm_mode = false; //if farm_mode has not been stored to eeprom yet and farm number is set to zero or EEPROM is fresh, deactivate farm mode - eeprom_update_byte((uint8_t*)EEPROM_FARM_MODE, farm_mode); - } - if (farm_mode) - { + eeprom_update_byte((uint8_t*)EEPROM_FARM_MODE, farm_mode); + } else if (farm_mode) { no_response = true; //we need confirmation by recieving PRUSA thx important_status = 8; prusa_statistics(8); @@ -1118,9 +1116,9 @@ void setup() //disabled filament autoload (PFW360) fsensor_autoload_set(false); #endif //FILAMENT_SENSOR - // ~ FanCheck -> on - if(!(eeprom_read_byte((uint8_t*)EEPROM_FAN_CHECK_ENABLED))) - eeprom_update_byte((unsigned char *)EEPROM_FAN_CHECK_ENABLED,true); + // ~ FanCheck -> on + if(!(eeprom_read_byte((uint8_t*)EEPROM_FAN_CHECK_ENABLED))) + eeprom_update_byte((uint8_t*)EEPROM_FAN_CHECK_ENABLED,true); } #ifdef TMC2130 From caf496e9961f0d37c95b5e7fb9d785b9609c44f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Wed, 9 Feb 2022 07:26:34 +0000 Subject: [PATCH 3/4] Optimise FanCheck initialisation when farm mode is on Saves 12 bytes of flash memory (Arduino IDE 1.8.19) --- Firmware/Marlin_main.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 23c517982..4351311e5 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -1117,8 +1117,7 @@ void setup() fsensor_autoload_set(false); #endif //FILAMENT_SENSOR // ~ FanCheck -> on - if(!(eeprom_read_byte((uint8_t*)EEPROM_FAN_CHECK_ENABLED))) - eeprom_update_byte((uint8_t*)EEPROM_FAN_CHECK_ENABLED,true); + eeprom_update_byte((uint8_t*)EEPROM_FAN_CHECK_ENABLED, true); } #ifdef TMC2130 From c4f102392427dd1573a75e705dcad698e8975140 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Wed, 9 Feb 2022 07:30:50 +0000 Subject: [PATCH 4/4] Add back second call to prusa_statistics(8) when farm_mode is enabled. Adds 18 bytes of flash --- Firmware/Marlin_main.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 4351311e5..53f80a9b5 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -1439,6 +1439,12 @@ void setup() enable_z(); #endif + if (farm_mode) { + // The farm monitoring SW may accidentally expect + // 2 messages of "printer started" to consider a printer working. + prusa_statistics(8); + } + // Enable Toshiba FlashAir SD card / WiFi enahanced card. card.ToshibaFlashAir_enable(eeprom_read_byte((unsigned char*)EEPROM_TOSHIBA_FLASH_AIR_COMPATIBLITY) == 1);