Skip to content

Commit b0466ae

Browse files
D.R.racerDRracer
D.R.racer
authored andcommitted
Add infrastructure for MMU parametrization after comm start
For now, only the Extra loading distance is being sent, but the infrastructure can be easily extended for other registers as well.
1 parent c7e4c9c commit b0466ae

File tree

3 files changed

+41
-7
lines changed

3 files changed

+41
-7
lines changed

Firmware/mmu2.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ 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-
static constexpr float MMU2_TOOL_CHANGE_LOAD_LENGTH = 5.0F;//30.0F;
42+
// Beware - this value is sent to the MMU upon line up, it is written into its 8bit register 0x0b
43+
static constexpr uint8_t MMU2_TOOL_CHANGE_LOAD_LENGTH = 5; // mm
4344

4445
static constexpr float MMU2_LOAD_TO_NOZZLE_FEED_RATE = 20.0F; // mm/s
4546
static constexpr float MMU2_UNLOAD_TO_FINDA_FEED_RATE = 120.0F; // mm/s
@@ -102,7 +103,7 @@ MMU2 mmu2;
102103

103104
MMU2::MMU2()
104105
: is_mmu_error_monitor_active(false)
105-
, logic(&mmu2Serial)
106+
, logic(&mmu2Serial, MMU2_TOOL_CHANGE_LOAD_LENGTH)
106107
, extruder(MMU2_NO_TOOL)
107108
, tool_change_extruder(MMU2_NO_TOOL)
108109
, resume_position()

Firmware/mmu2_protocol_logic.cpp

+27-4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ const uint8_t ProtocolLogic::regs16Addrs[ProtocolLogic::regs16Count] PROGMEM = {
1919
0x1a, // Pulley position [mm]
2020
};
2121

22+
const uint8_t ProtocolLogic::initRegs8Addrs[ProtocolLogic::initRegs8Count] PROGMEM = {
23+
0x0b, // extra load distance
24+
};
25+
2226
void ProtocolLogic::CheckAndReportAsyncEvents() {
2327
// even when waiting for a query period, we need to report a change in filament sensor's state
2428
// - it is vital for a precise synchronization of moves of the printer and the MMU
@@ -65,6 +69,21 @@ ProtocolLogic::ScopeState __attribute__((noinline)) ProtocolLogic::ProcessRead16
6569
return ScopeState::Reading16bitRegisters;
6670
}
6771

72+
void ProtocolLogic::StartWritingInitRegisters() {
73+
regIndex = 0;
74+
SendWriteRegister(pgm_read_byte(initRegs8Addrs + regIndex), initRegs8[regIndex], ScopeState::WritingInitRegisters);
75+
}
76+
77+
bool __attribute__((noinline)) ProtocolLogic::ProcessWritingInitRegister(){
78+
++regIndex;
79+
if(regIndex >= initRegs8Count){
80+
return true;
81+
} else {
82+
SendWriteRegister(pgm_read_byte(initRegs8Addrs + regIndex), initRegs8[regIndex], ScopeState::WritingInitRegisters);
83+
}
84+
return false;
85+
}
86+
6887
void ProtocolLogic::SendAndUpdateFilamentSensor() {
6988
SendMsg(RequestMsg(RequestMsgCodes::FilamentSensor, lastFSensor = (uint8_t)WhereIsFilament()));
7089
scopeState = ScopeState::FilamentSensorStateSent;
@@ -262,9 +281,12 @@ StepStatus ProtocolLogic::StartSeqStep() {
262281
SendVersion(3);
263282
} else {
264283
mmuFwVersionBuild = rsp.paramValue; // just register the build number
265-
// Start General Interrogation after line up.
266-
// For now we just send the state of the filament sensor, but we may request
267-
// data point states from the MMU as well. TBD in the future, especially with another protocol
284+
// Start General Interrogation after line up - initial parametrization is started
285+
StartWritingInitRegisters();
286+
}
287+
return Processing;
288+
case ScopeState::WritingInitRegisters:
289+
if( ProcessWritingInitRegister() ){
268290
SendAndUpdateFilamentSensor();
269291
}
270292
return Processing;
@@ -465,7 +487,7 @@ StepStatus ProtocolLogic::IdleStep() {
465487
return Finished;
466488
}
467489

468-
ProtocolLogic::ProtocolLogic(MMU2Serial *uart)
490+
ProtocolLogic::ProtocolLogic(MMU2Serial *uart, uint8_t extraLoadDistance)
469491
: currentScope(Scope::Stopped)
470492
, scopeState(ScopeState::Ready)
471493
, plannedRq(RequestMsgCodes::unknown, 0)
@@ -481,6 +503,7 @@ ProtocolLogic::ProtocolLogic(MMU2Serial *uart)
481503
, lastFSensor((uint8_t)WhereIsFilament())
482504
, regs8 { 0, 0, 0 }
483505
, regs16 { 0, 0 }
506+
, initRegs8 { extraLoadDistance }
484507
, regIndex(0)
485508
, mmuFwVersion { 0, 0, 0 }
486509
{}

Firmware/mmu2_protocol_logic.h

+11-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class DropOutFilter {
7171
/// Logic layer of the MMU vs. printer communication protocol
7272
class ProtocolLogic {
7373
public:
74-
ProtocolLogic(MMU2Serial *uart);
74+
ProtocolLogic(MMU2Serial *uart, uint8_t extraLoadDistance);
7575

7676
/// Start/Enable communication with the MMU
7777
void Start();
@@ -190,6 +190,7 @@ class ProtocolLogic {
190190
FilamentSensorStateSent,
191191
Reading8bitRegisters,
192192
Reading16bitRegisters,
193+
WritingInitRegisters,
193194
ButtonSent,
194195
ReadRegisterSent, // standalone requests for reading registers - from higher layers
195196
WriteRegisterSent,
@@ -222,6 +223,9 @@ class ProtocolLogic {
222223
void ProcessRead8bitRegister();
223224
void StartReading16bitRegisters();
224225
ScopeState ProcessRead16bitRegister(ProtocolLogic::ScopeState stateAtEnd);
226+
void StartWritingInitRegisters();
227+
/// @returns true when all registers have been written into the MMU
228+
bool ProcessWritingInitRegister();
225229
void SendAndUpdateFilamentSensor();
226230
void SendButton(uint8_t btn);
227231
void SendVersion(uint8_t stage);
@@ -306,6 +310,12 @@ class ProtocolLogic {
306310
static const uint8_t regs16Addrs[regs16Count] PROGMEM;
307311
uint16_t regs16[regs16Count];
308312

313+
// 8bit init values to be sent to the MMU after line up
314+
static constexpr uint8_t initRegs8Count = 1;
315+
static_assert(initRegs8Count > 0); // code is not ready for empty lists of registers
316+
static const uint8_t initRegs8Addrs[initRegs8Count] PROGMEM;
317+
uint8_t initRegs8[initRegs8Count];
318+
309319
uint8_t regIndex;
310320

311321
uint8_t mmuFwVersion[3];

0 commit comments

Comments
 (0)