SpoolJoin.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include "SpoolJoin.h"
  2. #include "eeprom.h"
  3. namespace SpoolJoin {
  4. SpoolJoin spooljoin;
  5. SpoolJoin::SpoolJoin()
  6. : status(EEPROM::Unknown)
  7. , currentMMUSlot(0)
  8. {
  9. }
  10. void SpoolJoin::updateSpoolJoinStatus(EEPROM newStatus)
  11. {
  12. status = newStatus;
  13. eeprom_write_byte((uint8_t*)EEPROM_AUTO_DEPLETE, (uint8_t)status);
  14. }
  15. void SpoolJoin::initSpoolJoinStatus()
  16. {
  17. EEPROM currentStatus = (EEPROM)eeprom_read_byte((uint8_t*)EEPROM_AUTO_DEPLETE);
  18. if( currentStatus == EEPROM::Empty)
  19. {
  20. // By default SpoolJoin is disabled
  21. updateSpoolJoinStatus(EEPROM::Disabled);
  22. } else {
  23. updateSpoolJoinStatus(currentStatus);
  24. }
  25. }
  26. void SpoolJoin::toggleSpoolJoin()
  27. {
  28. if (eeprom_read_byte((uint8_t*)EEPROM_AUTO_DEPLETE) == (uint8_t)EEPROM::Disabled)
  29. {
  30. eeprom_write_byte((uint8_t*)EEPROM_AUTO_DEPLETE, (uint8_t)EEPROM::Enabled);
  31. } else {
  32. eeprom_write_byte((uint8_t*)EEPROM_AUTO_DEPLETE, (uint8_t)EEPROM::Disabled);
  33. }
  34. }
  35. uint8_t SpoolJoin::isSpoolJoinEnabled()
  36. {
  37. if(eeprom_read_byte((uint8_t*)EEPROM_AUTO_DEPLETE) == (uint8_t)EEPROM::Enabled) {
  38. return 1;
  39. } else {
  40. return 0;
  41. }
  42. }
  43. uint8_t SpoolJoin::nextSlot()
  44. {
  45. if (currentMMUSlot == 4) currentMMUSlot = 0;
  46. else currentMMUSlot++;
  47. return currentMMUSlot;
  48. }
  49. }