Skip to content

Commit

Permalink
Add cutLength register (0x23)
Browse files Browse the repository at this point in the history
  • Loading branch information
D.R.racer authored and DRracer committed Nov 3, 2023
1 parent ce0df08 commit 19a0cd3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/logic/cut_filament.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions src/modules/globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ void Globals::Init() {
ResetIdlerHomingFeedrate();

ResetCutIRunCurrent();
ResetCutLength();
}

uint8_t Globals::ActiveSlot() const {
Expand Down
5 changes: 5 additions & 0 deletions src/modules/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ class Globals {
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
Expand All @@ -132,6 +136,7 @@ class Globals {
uint16_t idlerHomingFeedrate_deg_s;

uint8_t cutIRunCurrent;
uint8_t cutLength_mm;
};

/// The one and only instance of global state variables
Expand Down
9 changes: 8 additions & 1 deletion src/registers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 19a0cd3

Please sign in to comment.