Skip to content

Commit 0aeb74e

Browse files
D.R.racerDRracer
D.R.racer
authored andcommitted
Intercept M708 A0xb: set ExtraLoadDistance on the printer side too
1 parent b0466ae commit 0aeb74e

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

Firmware/mmu2.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ static constexpr float MMU2_LOAD_TO_NOZZLE_LENGTH = 87.0F + 5.0F;
3939
// - ToolChange shall not try to push filament into the very tip of the nozzle
4040
// to have some space for additional G-code to tune the extruded filament length
4141
// in the profile
42-
// Beware - this value is sent to the MMU upon line up, it is written into its 8bit register 0x0b
42+
// Beware - this value is used to initialize the MMU logic layer - it will be sent to the MMU upon line up (written into its 8bit register 0x0b)
43+
// However - in the G-code we can get a request to set the extra load distance at runtime to something else (M708 A0xb Xsomething).
44+
// The printer intercepts such a call and sets its extra load distance to match the new value as well.
4345
static constexpr uint8_t MMU2_TOOL_CHANGE_LOAD_LENGTH = 5; // mm
4446

4547
static constexpr float MMU2_LOAD_TO_NOZZLE_FEED_RATE = 20.0F; // mm/s
@@ -198,6 +200,12 @@ bool MMU2::ReadRegister(uint8_t address){
198200
bool MMU2::WriteRegister(uint8_t address, uint16_t data){
199201
if( ! WaitForMMUReady())
200202
return false;
203+
204+
// special case - intercept requests of extra loading distance and perform the change even on the printer's side
205+
if( address == 0x0b ){
206+
logic.PlanExtraLoadDistance(data);
207+
}
208+
201209
logic.WriteRegister(address, data); // we may signal the accepted/rejected status of the response as return value of this function
202210
manage_response(false, false);
203211
return true;
@@ -907,8 +915,8 @@ void MMU2::OnMMUProgressMsgSame(ProgressCode pc){
907915
loadFilamentStarted = false;
908916
// After the MMU knows the FSENSOR is triggered it will:
909917
// 1. Push the filament by additional 30mm (see fsensorToNozzle)
910-
// 2. Disengage the idler and push another 5mm.
911-
current_position[E_AXIS] += MMU2_TOOL_CHANGE_LOAD_LENGTH + 2.0f;
918+
// 2. Disengage the idler and push another 2mm.
919+
current_position[E_AXIS] += logic.ExtraLoadDistance() + 2;
912920
plan_buffer_line_curposXYZE(MMU2_LOAD_TO_NOZZLE_FEED_RATE);
913921
break;
914922
case FilamentState::NOT_PRESENT:

Firmware/mmu2_protocol_logic.h

+11
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,17 @@ class ProtocolLogic {
9292
void ReadRegister(uint8_t address);
9393
void WriteRegister(uint8_t address, uint16_t data);
9494

95+
/// Sets the extra load distance to be reported to the MMU.
96+
/// Beware - this call doesn't send anything to the MMU.
97+
/// The MMU gets the newly set value either by a communication restart or via an explicit WriteRegister call
98+
inline void PlanExtraLoadDistance(uint8_t eld_mm){
99+
initRegs8[0] = eld_mm;
100+
}
101+
/// @returns the currently preset extra load distance
102+
inline uint8_t ExtraLoadDistance()const {
103+
return initRegs8[0];
104+
}
105+
95106
/// Step the state machine
96107
StepStatus Step();
97108

0 commit comments

Comments
 (0)