@@ -19,6 +19,10 @@ const uint8_t ProtocolLogic::regs16Addrs[ProtocolLogic::regs16Count] PROGMEM = {
19
19
0x1a , // Pulley position [mm]
20
20
};
21
21
22
+ const uint8_t ProtocolLogic::initRegs8Addrs[ProtocolLogic::initRegs8Count] PROGMEM = {
23
+ 0x0b , // extra load distance
24
+ };
25
+
22
26
void ProtocolLogic::CheckAndReportAsyncEvents () {
23
27
// even when waiting for a query period, we need to report a change in filament sensor's state
24
28
// - 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
65
69
return ScopeState::Reading16bitRegisters;
66
70
}
67
71
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
+
68
87
void ProtocolLogic::SendAndUpdateFilamentSensor () {
69
88
SendMsg (RequestMsg (RequestMsgCodes::FilamentSensor, lastFSensor = (uint8_t )WhereIsFilament ()));
70
89
scopeState = ScopeState::FilamentSensorStateSent;
@@ -262,9 +281,12 @@ StepStatus ProtocolLogic::StartSeqStep() {
262
281
SendVersion (3 );
263
282
} else {
264
283
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 () ){
268
290
SendAndUpdateFilamentSensor ();
269
291
}
270
292
return Processing;
@@ -465,7 +487,7 @@ StepStatus ProtocolLogic::IdleStep() {
465
487
return Finished;
466
488
}
467
489
468
- ProtocolLogic::ProtocolLogic (MMU2Serial *uart)
490
+ ProtocolLogic::ProtocolLogic (MMU2Serial *uart, uint8_t extraLoadDistance )
469
491
: currentScope(Scope::Stopped)
470
492
, scopeState(ScopeState::Ready)
471
493
, plannedRq(RequestMsgCodes::unknown, 0 )
@@ -481,6 +503,7 @@ ProtocolLogic::ProtocolLogic(MMU2Serial *uart)
481
503
, lastFSensor((uint8_t )WhereIsFilament())
482
504
, regs8 { 0 , 0 , 0 }
483
505
, regs16 { 0 , 0 }
506
+ , initRegs8 { extraLoadDistance }
484
507
, regIndex(0 )
485
508
, mmuFwVersion { 0 , 0 , 0 }
486
509
{}
0 commit comments