Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add en- and disable MMU to M709 #4474

Merged
merged 5 commits into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 35 additions & 4 deletions Firmware/Marlin_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,7 @@ void setup()
if (eeprom_init_default_byte((uint8_t *)EEPROM_MMU_ENABLED, 0)) {
MMU2::mmu2.Start();
}
MMU2::mmu2.Status();
SpoolJoin::spooljoin.initSpoolJoinStatus();

//SERIAL_ECHOPAIR("Active sheet before:", static_cast<unsigned long int>(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet))));
Expand Down Expand Up @@ -8581,24 +8582,50 @@ SERIAL_PROTOCOLPGM("\n\n");
} break;

/*!
### M709 - MMU reset <a href="https://reprap.org/wiki/G-code#M709:_MMU_reset">M709: MMU reset</a>
The MK3S cannot not power off the MMU, for that reason the functionality is not supported.
### M709 - MMU power & reset <a href="https://reprap.org/wiki/G-code#M709:_MMU_power_&_reset">M709: MMU power & reset</a>
The MK3S cannot not power off the MMU, but we can en- and disable the MMU.

The new state of the MMU is stored in printer's EEPROM - i.e. if you disable the MMU via M709, it will not be activated after the printer resets.
#### Usage

M709 [ X ]
M709 [ S | X ]

#### Parameters
- `X` - Reset MMU (0:soft reset | 1:hardware reset)
- `X` - Reset MMU (0:soft reset | 1:hardware reset | 42: erase MMU eeprom)
- `S` - En-/disable the MMU (0:off | 1:on)

#### Example

M709 X0 - issue an X0 command via communication into the MMU (soft reset)

M709 X1 - toggle the MMU's reset pin (hardware reset)

M709 X42 - erase MMU EEPROM

M709 S1 - enable MMU

M709 S0 - disable MMU

M709 - Serial message if en- or disabled
*/
case 709:
{
if (code_seen('S'))
{
switch (code_value_uint8())
{
case 0:
eeprom_update_byte((uint8_t *)EEPROM_MMU_ENABLED, false);
MMU2::mmu2.Stop();
break;
case 1:
eeprom_update_byte((uint8_t *)EEPROM_MMU_ENABLED, true);
MMU2::mmu2.Start();
break;
default:
break;
}
}
if (MMU2::mmu2.Enabled() && code_seen('X'))
{
switch (code_value_uint8())
Expand All @@ -8609,10 +8636,14 @@ SERIAL_PROTOCOLPGM("\n\n");
case 1:
MMU2::mmu2.Reset(MMU2::MMU2::ResetPin);
break;
case 42:
MMU2::mmu2.Reset(MMU2::MMU2::EraseEEPROM);
break;
default:
break;
}
}
MMU2::mmu2.Status();
}
break;

Expand Down
14 changes: 14 additions & 0 deletions Firmware/mmu2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#include "strlen_cx.h"
#include "SpoolJoin.h"

#include "messages.h"
#include "language.h"

#ifdef __AVR__
// As of FW 3.12 we only support building the FW with only one extruder, all the multi-extruder infrastructure will be removed.
// Saves at least 800B of code size
Expand Down Expand Up @@ -52,6 +55,17 @@ MMU2::MMU2()
, tmcFailures(0) {
}

void MMU2::Status() {
// Useful information to see during bootup and change state
SERIAL_ECHOPGM("MMU is ");
uint8_t status = eeprom_init_default_byte((uint8_t*)EEPROM_MMU_ENABLED, 0);
if (status == 1) {
SERIAL_ECHOLNRPGM(_O(MSG_ON));
} else {
SERIAL_ECHOLNRPGM(_O(MSG_OFF));
}
}

void MMU2::Start() {
mmu2Serial.begin(MMU_BAUD);

Expand Down
3 changes: 3 additions & 0 deletions Firmware/mmu2.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class MMU2 {
/// Stops the protocol logic, closes the UART, powers OFF the MMU
void Stop();

/// Serial output of MMU state
void Status();

inline xState State() const { return state; }

inline bool Enabled() const { return State() == xState::Active; }
Expand Down
1 change: 1 addition & 0 deletions Firmware/mmu2_reporting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ void TryLoadUnloadReporter::DumpToSerial(){
/// Disables MMU in EEPROM
void DisableMMUInSettings() {
eeprom_update_byte((uint8_t *)EEPROM_MMU_ENABLED, false);
mmu2.Status();
}

void IncrementLoadFails(){
Expand Down
1 change: 1 addition & 0 deletions Firmware/ultralcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4093,6 +4093,7 @@ static void mmu_enable_switch()
}

eeprom_toggle((uint8_t *)EEPROM_MMU_ENABLED);
MMU2::mmu2.Status();
}

static void SETTINGS_SILENT_MODE()
Expand Down
Loading