From a43114319ef2f97ee4b45f5d97e8f070946f4e6b Mon Sep 17 00:00:00 2001 From: snacj <0xsnacj@proton.me> Date: Tue, 12 Aug 2025 11:23:46 +0200 Subject: [PATCH] Added Capability checks for moving --- server/src/machines/buffer1/mod.rs | 48 +++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/server/src/machines/buffer1/mod.rs b/server/src/machines/buffer1/mod.rs index 8dd781bb..f674b896 100644 --- a/server/src/machines/buffer1/mod.rs +++ b/server/src/machines/buffer1/mod.rs @@ -173,6 +173,46 @@ impl BufferV1 { self.namespace.emit(BufferV1Events::State(event)); } + /// Can buffer capability check + pub fn can_buffer(&self) -> bool { + // Check if tension arm is zeroed and traverse is homed + self.buffer_lift_controller.is_homed() && !self.buffer_lift_controller.is_going_home() + } + + /// Can go to upper limit capability check + pub fn can_go_up(&self) -> bool { + self.buffer_lift_controller.is_homed() + && self.mode != BufferV1Mode::Standby + && !self.buffer_lift_controller.is_going_up() + && !self.buffer_lift_controller.is_going_home() + && !self.buffer_lift_controller.is_buffering() + && self.mode != BufferV1Mode::Filling + && self.mode != BufferV1Mode::Emptying + } + + /// Can go to lower limit capability check + pub fn can_go_down(&self) -> bool { + self.buffer_lift_controller.is_homed() + && self.mode != BufferV1Mode::Standby + && !self.buffer_lift_controller.is_going_down() + && !self.buffer_lift_controller.is_going_home() + && !self.buffer_lift_controller.is_buffering() + && self.mode != BufferV1Mode::Filling + && self.mode != BufferV1Mode::Emptying + } + + /// Can go home capability check + pub fn can_go_home(&self) -> bool { + // Check if not in standby, not traversing + // Allow going home even when going in or out + self.mode != BufferV1Mode::Standby + && !self.buffer_lift_controller.is_going_home() + && !self.buffer_lift_controller.is_buffering() + && self.mode != BufferV1Mode::Filling + && self.mode != BufferV1Mode::Emptying + } +} + impl BufferV1 { fn fill_buffer(&mut self) { // stop the winder until the buffer is ful @@ -225,7 +265,7 @@ impl BufferV1 { BufferV1Mode::Emptying => {} }; self.mode = BufferV1Mode::Hold; - self.buffer_lift_controller.set_enabled(false); + self.buffer_lift_controller.set_enabled(true); let _ = self.buffer_lift_controller.stepper_driver.set_speed(0.0); self.update_winder2_buffer_state(BufferState::Hold); } @@ -398,21 +438,21 @@ impl BufferV1 { } pub fn lift_goto_limit_top(&mut self) { - if self.can_move() { + if self.can_go_up() { self.buffer_lift_controller.goto_limit_top(); } self.emit_state(); } pub fn lift_goto_limit_bottom(&mut self) { - if self.can_move() { + if self.can_go_down() { self.buffer_lift_controller.goto_limit_bottom(); } self.emit_state(); } pub fn lift_goto_home(&mut self) { - if self.can_move() { + if self.can_go_home() { self.buffer_lift_controller.goto_home(); } self.emit_state();