Skip to content

Commit c20e825

Browse files
committed
[MMU3] Addressed review comments.
1 parent 8387437 commit c20e825

40 files changed

+6724
-5752
lines changed
Lines changed: 85 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,89 @@
1+
/**
2+
* Marlin 3D Printer Firmware
3+
* Copyright (c) 2024 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4+
*
5+
* Based on Sprinter and grbl.
6+
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
23+
/**
24+
* SpoolJoin.cpp
25+
*/
26+
127
#include "src/MarlinCore.h"
228
#if HAS_PRUSA_MMU3
3-
#include "SpoolJoin.h"
4-
#include "src/module/settings.h"
5-
#include "messages.h"
6-
#include "src/core/language.h"
7-
8-
9-
namespace SpoolJoin {
10-
11-
SpoolJoin spooljoin;
12-
bool SpoolJoin::enabled; // Initialized by settings.load
13-
int SpoolJoin::epprom_addr; // Initialized by settings.load
14-
15-
SpoolJoin::SpoolJoin()
16-
: currentMMUSlot(0)
17-
{
18-
}
19-
20-
void SpoolJoin::initSpoolJoinStatus()
21-
{
22-
// Useful information to see during bootup
23-
if (enabled){
24-
SERIAL_ECHOLNPGM("SpoolJoin is On");
25-
} else {
26-
SERIAL_ECHOLNPGM("SpoolJoin is Off");
29+
#include "SpoolJoin.h"
30+
#include "src/module/settings.h"
31+
#include "messages.h"
32+
#include "src/core/language.h"
33+
34+
35+
namespace SpoolJoin {
36+
37+
SpoolJoin spooljoin;
38+
bool SpoolJoin::enabled; // Initialized by settings.load
39+
int SpoolJoin::epprom_addr; // Initialized by settings.load
40+
41+
SpoolJoin::SpoolJoin()
42+
: currentMMUSlot(0) {
43+
}
44+
45+
void SpoolJoin::initSpoolJoinStatus() {
46+
// Useful information to see during bootup
47+
if (enabled)
48+
SERIAL_ECHOLNPGM("SpoolJoin is On");
49+
else
50+
SERIAL_ECHOLNPGM("SpoolJoin is Off");
51+
}
52+
53+
void SpoolJoin::toggleSpoolJoin() {
54+
// Toggle enabled value.
55+
enabled = !enabled;
56+
57+
// Following Prusa's implementation let's save the value to the EEPROM
58+
#if ENABLED(EEPROM_SETTINGS)
59+
persistentStore.access_start();
60+
persistentStore.write_data(epprom_addr, enabled);
61+
persistentStore.access_finish();
62+
settings.save();
63+
#endif
64+
}
65+
66+
bool SpoolJoin::isSpoolJoinEnabled() {
67+
// the enable var is initialized by settings.load()
68+
return enabled;
69+
}
70+
71+
void SpoolJoin::setSlot(uint8_t slot) {
72+
currentMMUSlot = slot;
73+
}
74+
75+
uint8_t SpoolJoin::nextSlot() {
76+
SERIAL_ECHOPGM("SpoolJoin: ");
77+
SERIAL_ECHO((int)currentMMUSlot);
78+
79+
if (currentMMUSlot >= 4) currentMMUSlot = 0;
80+
else currentMMUSlot++;
81+
82+
SERIAL_ECHOPGM(" -> ");
83+
SERIAL_ECHOLN((int)currentMMUSlot);
84+
85+
return currentMMUSlot;
86+
}
87+
2788
}
28-
}
29-
30-
void SpoolJoin::toggleSpoolJoin()
31-
{
32-
// Toggle enabled value.
33-
enabled = !enabled;
34-
35-
// Following Prusa's implementation let's save the value to the EEPROM
36-
#if ENABLED(EEPROM_SETTINGS)
37-
persistentStore.access_start();
38-
persistentStore.write_data(epprom_addr, enabled);
39-
persistentStore.access_finish();
40-
settings.save();
41-
#endif
42-
}
43-
44-
bool SpoolJoin::isSpoolJoinEnabled()
45-
{
46-
// the enable var is initialized by settings.load()
47-
return enabled;
48-
}
49-
50-
void SpoolJoin::setSlot(uint8_t slot)
51-
{
52-
currentMMUSlot = slot;
53-
}
54-
55-
uint8_t SpoolJoin::nextSlot()
56-
{
57-
SERIAL_ECHOPGM("SpoolJoin: ");
58-
SERIAL_ECHO((int)currentMMUSlot);
59-
60-
if (currentMMUSlot >= 4) currentMMUSlot = 0;
61-
else currentMMUSlot++;
62-
63-
SERIAL_ECHOPGM(" -> ");
64-
SERIAL_ECHOLN((int)currentMMUSlot);
65-
66-
return currentMMUSlot;
67-
}
68-
69-
}
7089
#endif // HAS_PRUSA_MMU3
Lines changed: 58 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,77 @@
1-
/// @file
1+
/**
2+
* Marlin 3D Printer Firmware
3+
* Copyright (c) 2024 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4+
*
5+
* Based on Sprinter and grbl.
6+
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
23+
/**
24+
* SpoolJoin.h
25+
*/
26+
227
#pragma once
328
#include <stdint.h>
429
#include "src/MarlinCore.h"
530
#if HAS_PRUSA_MMU3
6-
// See documentation here: https://help.prusa3d.com/article/spooljoin-mmu2s_134252
31+
// See documentation here: https://help.prusa3d.com/article/spooljoin-mmu2s_134252
732

8-
namespace SpoolJoin {
33+
namespace SpoolJoin {
934

10-
class SpoolJoin {
35+
class SpoolJoin {
1136
public:
12-
SpoolJoin();
37+
SpoolJoin();
1338

14-
enum class EEPROM : uint8_t {
15-
Unknown, ///< SpoolJoin is unknown while printer is booting up
16-
Enabled, ///< SpoolJoin is enabled in EEPROM
17-
Disabled, ///< SpoolJoin is disabled in EEPROM
18-
Empty = 0xFF ///< EEPROM has not been set before and all bits are 1 (0xFF) - either a new printer or user erased the memory
19-
};
39+
enum class EEPROM : uint8_t {
40+
Unknown, ///< SpoolJoin is unknown while printer is booting up
41+
Enabled, ///< SpoolJoin is enabled in EEPROM
42+
Disabled, ///< SpoolJoin is disabled in EEPROM
43+
Empty = 0xFF ///< EEPROM has not been set before and all bits are 1 (0xFF) - either a new printer or user erased the memory
44+
};
2045

21-
// @brief Contrary to Prusa's implementation we store the enabled status in a variable
22-
static int epprom_addr;
23-
static bool enabled;
46+
// @brief Contrary to Prusa's implementation we store the enabled status in a variable
47+
static int epprom_addr;
48+
static bool enabled;
2449

25-
/// @brief Called when EEPROM is ready to be read
26-
void initSpoolJoinStatus();
50+
/// @brief Called when EEPROM is ready to be read
51+
void initSpoolJoinStatus();
2752

28-
/// @brief Toggle SpoolJoin
29-
static void toggleSpoolJoin();
53+
/// @brief Toggle SpoolJoin
54+
static void toggleSpoolJoin();
3055

31-
/// @brief Check if SpoolJoin is enabled
32-
/// @returns true if enabled, false if disabled
33-
bool isSpoolJoinEnabled();
56+
/// @brief Check if SpoolJoin is enabled
57+
/// @returns true if enabled, false if disabled
58+
bool isSpoolJoinEnabled();
3459

35-
/// @brief Update the saved MMU slot number so SpoolJoin can determine the next slot to use
36-
/// @param slot number of the slot to set
37-
void setSlot(uint8_t slot);
60+
/// @brief Update the saved MMU slot number so SpoolJoin can determine the next slot to use
61+
/// @param slot number of the slot to set
62+
void setSlot(uint8_t slot);
3863

39-
/// @brief Fetch the next slot number should count from 0 to 4.
40-
/// When filament slot 4 is depleted, the next slot should be 0.
41-
/// @returns the next slot, ranges from 0 to 4
42-
uint8_t nextSlot();
64+
/// @brief Fetch the next slot number should count from 0 to 4.
65+
/// When filament slot 4 is depleted, the next slot should be 0.
66+
/// @returns the next slot, ranges from 0 to 4
67+
uint8_t nextSlot();
4368

4469
private:
45-
/// @brief Currently used slot, ranges from 0 to 4
46-
uint8_t currentMMUSlot;
47-
};
70+
/// @brief Currently used slot, ranges from 0 to 4
71+
uint8_t currentMMUSlot;
72+
};
4873

49-
extern SpoolJoin spooljoin;
74+
extern SpoolJoin spooljoin;
5075

51-
} // namespace SpoolJoin
76+
} // namespace SpoolJoin
5277
#endif // HAS_PRUSA_MMU3

0 commit comments

Comments
 (0)