SpoolJoin.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. Empty = 0xFF ///< EEPROM has not been set before and all bits are 1 (0xFF) - either a new printer or user erased the memory
  15. };
  16. /// @brief Called when EEPROM is ready to be read
  17. void initSpoolJoinStatus();
  18. /// @brief Enable SpoolJoin
  19. inline void enableSpoolJoin() { updateSpoolJoinStatus(EEPROM::Enabled); };
  20. /// @brief Disable SpoolJoin
  21. inline void disableSpoolJoin() { updateSpoolJoinStatus(EEPROM::Disabled); };
  22. /// @brief Toggle SpoolJoin
  23. static void toggleSpoolJoin();
  24. /// @brief Check if SpoolJoin is enabled
  25. uint8_t isSpoolJoinEnabled();
  26. /// @brief Update the saved MMU slot number so SpoolJoin can determine the next slot to use
  27. /// @param slot number of the slot to set
  28. void setSlot(uint8_t slot);
  29. /// @brief Fetch the next slot number should count from 0 to 4.
  30. /// When filament slot 4 is depleted, the next slot should be 0.
  31. /// @returns the next slot, ranges from 0 to 4
  32. uint8_t nextSlot();
  33. private:
  34. /// @brief Update EEPROM
  35. /// @param newStatus Status to write into EEPROM
  36. void updateSpoolJoinStatus(EEPROM newStatus);
  37. /// @brief SpoolJoin status
  38. enum EEPROM status;
  39. /// @brief Currently used slot, ranges from 0 to 4
  40. uint8_t currentMMUSlot;
  41. };
  42. extern SpoolJoin spooljoin;
  43. } // namespace SpoolJoin