From 852ca37e8fa41ef9aa5a042fd2df6150e53ad0bf Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Thu, 2 Sep 2021 08:50:25 +0200 Subject: [PATCH] Add stealtMode flag into the global storage hive May be used elsewhere to return to the desired motors' mode e.g. after homing (which requires switching to normal mode) --- src/main.cpp | 3 +++ src/modules/globals.cpp | 5 +++++ src/modules/globals.h | 10 ++++++++++ 3 files changed, 18 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index b39469a..9429e5d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -272,6 +272,9 @@ void PlanCommand(const mp::RequestMsg &rq) { } void SetMode(uint8_t m) { + mg::globals.SetMotorsMode(m != 0); // remember the last mode set + + // distribute the mode to all motors immediately mm::MotorMode mode = (m == 0) ? mm::Normal : mm::Stealth; mm::motion.SetMode(mm::Pulley, mode); mm::motion.SetMode(mm::Selector, mode); diff --git a/src/modules/globals.cpp b/src/modules/globals.cpp index 1314742..8ccef09 100644 --- a/src/modules/globals.cpp +++ b/src/modules/globals.cpp @@ -36,5 +36,10 @@ void Globals::IncDriveErrors() { mps::DriveError::increment(); } +void Globals::SetMotorsMode(bool stealth) { + stealthMode = stealth; + // @@TODO store into EEPROM +} + } // namespace globals } // namespace modules diff --git a/src/modules/globals.h b/src/modules/globals.h index 0f0f8db..f45db13 100644 --- a/src/modules/globals.h +++ b/src/modules/globals.h @@ -40,9 +40,19 @@ public: /// Increment MMU errors by 1 void IncDriveErrors(); + /// Set normal or stealth mode for all of the motors + /// Used to keep track of the last set mode to be able to return to it properly + /// after homing sequences and/or after restarting the MMU + /// @param stealth true means use stealth mode, false means use normal mode + void SetMotorsMode(bool stealth); + + /// @returns true if the motors are to be operated in stealth mode + bool MotorsStealth() const { return stealthMode; } + private: uint8_t activeSlot; bool filamentLoaded; + bool stealthMode; }; /// The one and only instance of global state variables