From 819a91ab1e88d96e7eaae630bc6c9a29a4471007 Mon Sep 17 00:00:00 2001 From: PavelSindler Date: Mon, 11 Mar 2019 12:33:22 +0100 Subject: [PATCH] switching stealth/normal mode for mmu in settings menu and tune menu --- Firmware/mmu.cpp | 27 ++++++++++++++++++++++++--- Firmware/ultralcd.cpp | 30 +++++++++++++++++++++--------- Firmware/ultralcd.h | 1 + 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/Firmware/mmu.cpp b/Firmware/mmu.cpp index 6d5cc514..3e587ce9 100644 --- a/Firmware/mmu.cpp +++ b/Firmware/mmu.cpp @@ -45,6 +45,7 @@ namespace WaitCmd, //!< wait for command response Pause, GetDrvError, //!< get power failures count + SwitchMode //switch mmu between stealth and normal mode }; } @@ -183,9 +184,9 @@ bool check_for_ir_sensor() static bool activate_stealth_mode() { -#if defined (MMU_FORCE_STEALTH_MODE) +#ifdef MMU_FORCE_STEALTH_MODE return true; -#elif +#else return (eeprom_read_byte((uint8_t*)EEPROM_MMU_STEALTH) == 1); #endif } @@ -335,6 +336,12 @@ void mmu_loop(void) mmu_last_cmd = mmu_cmd; mmu_cmd = MmuCmd::None; } + else if ((eeprom_read_byte((uint8_t*)EEPROM_MMU_STEALTH) != SilentModeMenu_MMU) && mmu_ready) { + DEBUG_PRINTF_P(PSTR("MMU <= 'M%d'\n"), SilentModeMenu_MMU); + mmu_printf_P(PSTR("M%d\n"), SilentModeMenu_MMU); + mmu_ready = false; + mmu_state = S::SwitchMode; + } else if ((mmu_last_response + 300) < _millis()) //request every 300ms { #ifndef IR_SENSOR @@ -450,9 +457,23 @@ void mmu_loop(void) mmu_state = S::Idle; } else if ((mmu_last_request + MMU_CMD_TIMEOUT) < _millis()) - { //resend request after timeout (5 min) + { //timeout 45 s mmu_state = S::Idle; } + return; + case S::SwitchMode: + if (mmu_rx_ok() > 0) + { + DEBUG_PRINTF_P(PSTR("MMU => 'ok'\n")); + eeprom_update_byte((uint8_t*)EEPROM_MMU_STEALTH, SilentModeMenu_MMU); + mmu_ready = true; + mmu_state = S::Idle; + } + else if ((mmu_last_request + MMU_CMD_TIMEOUT) < _millis()) + { //timeout 45 s + mmu_state = S::Idle; + } + return; } } diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 169ae143..2627a8aa 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -4516,11 +4516,13 @@ static void lcd_sound_state_set(void) Sound_CycleState(); } +#ifndef MMU_FORCE_STEALTH_MODE static void lcd_silent_mode_mmu_set() { if (SilentModeMenu_MMU == 1) SilentModeMenu_MMU = 0; else SilentModeMenu_MMU = 1; - eeprom_update_byte((uint8_t*)EEPROM_MMU_STEALTH, SilentModeMenu_MMU); + //saving to eeprom is done in mmu_loop() after mmu actually switches state and confirms with "ok" } +#endif //MMU_FORCE_STEALTH_MODE static void lcd_silent_mode_set() { switch (SilentModeMenu) { @@ -5295,17 +5297,26 @@ do\ break; /* (probably) not needed*/\ }\ }\ -#ifndef MMU_FORCE_STEALTH_MODE - if(mmu_enabled)\ - {\ - if (SilentModeMenu_MMU == 0) MENU_ITEM_FUNCTION_P(_i("MMU Mode [Fast]"), lcd_silent_mode_mmu_set);\ - else MENU_ITEM_FUNCTION_P(_i("MMU Mode [Stealth]"), lcd_silent_mode_mmu_set);\ - }\ -#endif //MMU_FORCE_STEALTH_MODE + }\ while (0) #endif //TMC2130 +#ifndef MMU_FORCE_STEALTH_MODE +#define SETTINGS_MMU_MODE \ +do\ +{\ + if (mmu_enabled)\ + {\ + if (SilentModeMenu_MMU == 0) MENU_ITEM_FUNCTION_P(_i("MMU Mode [Fast]"), lcd_silent_mode_mmu_set); \ + else MENU_ITEM_FUNCTION_P(_i("MMU Mode[Stealth]"), lcd_silent_mode_mmu_set); \ + }\ +}\ +while (0) +#else //MMU_FORCE_STEALTH_MODE +#define SETTINGS_MMU_MODE +#endif //MMU_FORCE_STEALTH_MODE + #ifdef SDCARD_SORT_ALPHA #define SETTINGS_SD \ do\ @@ -5410,6 +5421,7 @@ static void lcd_settings_menu() MENU_ITEM_FUNCTION_P(_i("Fans check [off]"), lcd_set_fan_check);////MSG_FANS_CHECK_OFF c=17 r=1 SETTINGS_SILENT_MODE; + SETTINGS_MMU_MODE; MENU_ITEM_SUBMENU_P(_i("Mesh bed leveling"), lcd_mesh_bed_leveling_settings);////MSG_MBL_SETTINGS c=18 r=1 @@ -6626,7 +6638,7 @@ static void lcd_tune_menu() } } #endif //TMC2130 - + SETTINGS_MMU_MODE; switch(eSoundMode) { case e_SOUND_MODE_LOUD: diff --git a/Firmware/ultralcd.h b/Firmware/ultralcd.h index 0b286181..8ed42442 100644 --- a/Firmware/ultralcd.h +++ b/Firmware/ultralcd.h @@ -117,6 +117,7 @@ extern int farm_status; #endif extern int8_t SilentModeMenu; +extern uint8_t SilentModeMenu_MMU; extern bool cancel_heatup; extern bool isPrintPaused;