SpoolJoin.cpp 1.7 KB

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