SpoolJoin.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. /// @returns true if enabled, false if disabled
  26. bool isSpoolJoinEnabled();
  27. /// @brief Update the saved MMU slot number so SpoolJoin can determine the next slot to use
  28. /// @param slot number of the slot to set
  29. void setSlot(uint8_t slot);
  30. /// @brief Fetch the next slot number should count from 0 to 4.
  31. /// When filament slot 4 is depleted, the next slot should be 0.
  32. /// @returns the next slot, ranges from 0 to 4
  33. uint8_t nextSlot();
  34. private:
  35. /// @brief Update EEPROM
  36. /// @param newStatus Status to write into EEPROM
  37. void updateSpoolJoinStatus(EEPROM newStatus);
  38. /// @brief SpoolJoin status
  39. enum EEPROM status;
  40. /// @brief Currently used slot, ranges from 0 to 4
  41. uint8_t currentMMUSlot;
  42. };
  43. extern SpoolJoin spooljoin;
  44. } // namespace SpoolJoin