AutoDeplete.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /// @file
  2. #pragma once
  3. #include <stdint.h>
  4. #include "eeprom.h"
  5. // See documentation here: https://help.prusa3d.com/article/spooljoin-mmu2s_134252
  6. namespace SpoolJoin {
  7. class SpoolJoin {
  8. public:
  9. SpoolJoin();
  10. enum class EEPROM : uint8_t {
  11. Unknown, ///< SpoolJoin is unknown while printer is booting up
  12. Enabled, ///< SpoolJoin is enabled in EEPROM
  13. Disabled, ///< SpoolJoin is disabled in EEPROM
  14. NA, ///< SpoolJoin is 'Not Applicable' when Fsensor is faulty
  15. Empty = 0xFF ///< EEPROM has not been set before and all bits are 1 (0xFF) - either a new printer or user erased the memory
  16. };
  17. /// @brief Called when EEPROM is ready to be read
  18. void initSpoolJoinStatus();
  19. /// @brief Enable SpoolJoin
  20. inline void enableSpoolJoin() { updateSpoolJoinStatus(EEPROM::Enabled); };
  21. /// @brief Disable SpoolJoin
  22. inline void disableSpoolJoin() { updateSpoolJoinStatus(EEPROM::Disabled); };
  23. /// @brief Toggle SpoolJoin
  24. static void toggleSpoolJoin();
  25. /// @brief Check if SpoolJoin is enabled
  26. uint8_t isSpoolJoinEnabled();
  27. /// @brief Fetch the next slot number should count from 0 to 4.
  28. /// When filament slot 4 is depleted, the next slot should be 0.
  29. /// @returns the next slot, ranges from 0 to 4
  30. uint8_t nextSlot();
  31. private:
  32. /// @brief Update EEPROM
  33. /// @param newStatus Status to write into EEPROM
  34. void updateSpoolJoinStatus(EEPROM newStatus);
  35. /// @brief SpoolJoin status
  36. enum EEPROM status;
  37. /// @brief Currently used slot, ranges from 0 to 4
  38. uint8_t currentMMUSlot;
  39. };
  40. extern SpoolJoin spooljoin;
  41. } // namespace SpoolJoin