From 19a0cd3ebb3c1d401508cc0c9bef3161f164d75b Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Tue, 31 Oct 2023 11:42:04 +0100 Subject: [PATCH] Add cutLength register (0x23) --- src/logic/cut_filament.cpp | 2 +- src/modules/globals.cpp | 1 + src/modules/globals.h | 5 +++++ src/registers.cpp | 9 ++++++++- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/logic/cut_filament.cpp b/src/logic/cut_filament.cpp index cda1e35..7db8e78 100644 --- a/src/logic/cut_filament.cpp +++ b/src/logic/cut_filament.cpp @@ -94,7 +94,7 @@ bool CutFilament::StepInner() { case ProgressCode::PreparingBlade: if (ms::selector.Slot() == cutSlot + 1) { state = ProgressCode::PushingFilament; - mpu::pulley.PlanMove(config::cutLength + config::cuttingEdgeRetract, config::pulleySlowFeedrate); + mpu::pulley.PlanMove(mg::globals.CutLength() + config::cuttingEdgeRetract, config::pulleySlowFeedrate); } break; case ProgressCode::PushingFilament: diff --git a/src/modules/globals.cpp b/src/modules/globals.cpp index 8ec5488..e52c2d1 100644 --- a/src/modules/globals.cpp +++ b/src/modules/globals.cpp @@ -36,6 +36,7 @@ void Globals::Init() { ResetIdlerHomingFeedrate(); ResetCutIRunCurrent(); + ResetCutLength(); } uint8_t Globals::ActiveSlot() const { diff --git a/src/modules/globals.h b/src/modules/globals.h index 701f4be..5b823e1 100644 --- a/src/modules/globals.h +++ b/src/modules/globals.h @@ -109,6 +109,10 @@ public: void ResetCutIRunCurrent() { cutIRunCurrent = config::selectorCutIRun; } void SetCutIRunCurrent(uint8_t v) { cutIRunCurrent = v; } + config::U_mm CutLength() const { return config::U_mm({ (long double)cutLength_mm }); } + void ResetCutLength() { cutLength_mm = config::cutLength.v; } + void SetCutLength(uint8_t v) { cutLength_mm = v; } + private: /// Sets the active slot, usually after some command/operation. /// Also updates the EEPROM records accordingly @@ -132,6 +136,7 @@ private: uint16_t idlerHomingFeedrate_deg_s; uint8_t cutIRunCurrent; + uint8_t cutLength_mm; }; /// The one and only instance of global state variables diff --git a/src/registers.cpp b/src/registers.cpp index 180990d..58512d2 100644 --- a/src/registers.cpp +++ b/src/registers.cpp @@ -166,6 +166,7 @@ | 0x20h 32 | uint16 | Set/Get Idler iRun current | 0-31 | 1fh 31 | 31->530mA: see TMC2130 current conversion| Read / Write | M707 A0x20 | M708 A0x20 Xn | 0x21h 33 | uint16 | Reserved for internal use | 225 | | N/A | N/A | N/A | N/A | 0x22h 34 | uint16 | Bowden length | 341-1000 | 168h 360 | unit mm | Read / Write Persistent | M707 A0x22 | M708 A0x22 Xn +| 0x23h 35 | uint8 | Cut length | 0-255 | 8 | unit mm | Read / Write | M707 A0x23 | M708 A0x23 Xn */ struct __attribute__((packed)) RegisterFlags { @@ -437,10 +438,16 @@ static const RegisterRec registers[] PROGMEM = { []() -> uint16_t { return mps::BowdenLength::Get(); }, [](uint16_t d) { mps::BowdenLength::Set(d); }, 2), + + // 0x23 Cut length + RegisterRec( + []() -> uint16_t { return mg::globals.CutLength().v; }, + [](uint16_t d) { mg::globals.SetCutLength(d); }, + 2), }; static constexpr uint8_t registersSize = sizeof(registers) / sizeof(RegisterRec); -static_assert(registersSize == 35); +static_assert(registersSize == 36); bool ReadRegister(uint8_t address, uint16_t &value) { if (address >= registersSize) {