SpoolJoin.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #include "SpoolJoin.h"
  2. #include "Marlin.h"
  3. #include "eeprom.h"
  4. #include "messages.h"
  5. #include "language.h"
  6. namespace SpoolJoin {
  7. SpoolJoin spooljoin;
  8. SpoolJoin::SpoolJoin()
  9. : status(EEPROM::Unknown)
  10. , currentMMUSlot(0)
  11. {
  12. }
  13. void SpoolJoin::updateSpoolJoinStatus(EEPROM newStatus)
  14. {
  15. status = newStatus;
  16. eeprom_write_byte((uint8_t*)EEPROM_AUTO_DEPLETE, (uint8_t)status);
  17. }
  18. void SpoolJoin::initSpoolJoinStatus()
  19. {
  20. EEPROM currentStatus = (EEPROM)eeprom_read_byte((uint8_t*)EEPROM_AUTO_DEPLETE);
  21. if( currentStatus == EEPROM::Empty)
  22. {
  23. // By default SpoolJoin is disabled
  24. updateSpoolJoinStatus(EEPROM::Disabled);
  25. } else {
  26. updateSpoolJoinStatus(currentStatus);
  27. }
  28. // Useful information to see during bootup
  29. SERIAL_ECHOPGM("SpoolJoin is ");
  30. if (isSpoolJoinEnabled())
  31. {
  32. SERIAL_ECHOLNRPGM(_O(MSG_ON));
  33. } else {
  34. SERIAL_ECHOLNRPGM(_O(MSG_OFF));
  35. }
  36. }
  37. void SpoolJoin::toggleSpoolJoin()
  38. {
  39. if (eeprom_read_byte((uint8_t*)EEPROM_AUTO_DEPLETE) == (uint8_t)EEPROM::Disabled)
  40. {
  41. eeprom_write_byte((uint8_t*)EEPROM_AUTO_DEPLETE, (uint8_t)EEPROM::Enabled);
  42. } else {
  43. eeprom_write_byte((uint8_t*)EEPROM_AUTO_DEPLETE, (uint8_t)EEPROM::Disabled);
  44. }
  45. }
  46. bool SpoolJoin::isSpoolJoinEnabled()
  47. {
  48. if(eeprom_read_byte((uint8_t*)EEPROM_AUTO_DEPLETE) == (uint8_t)EEPROM::Enabled) {
  49. return true;
  50. } else {
  51. return false;
  52. }
  53. }
  54. void SpoolJoin::setSlot(uint8_t slot)
  55. {
  56. currentMMUSlot = slot;
  57. }
  58. uint8_t SpoolJoin::nextSlot()
  59. {
  60. SERIAL_ECHOPGM("SpoolJoin: ");
  61. SERIAL_ECHO((int)currentMMUSlot);
  62. if (currentMMUSlot >= 4) currentMMUSlot = 0;
  63. else currentMMUSlot++;
  64. SERIAL_ECHOPGM(" -> ");
  65. SERIAL_ECHOLN((int)currentMMUSlot);
  66. return currentMMUSlot;
  67. }
  68. }