瀏覽代碼

set homing mode during machine init

the get_machine_steps function now also checks for the $22 setting, that tells if the homing cycle is enabled.
this is saved in the state and used to choose the homing method in the home() function
Fabio De Simone 11 月之前
父節點
當前提交
8a030aca2b
共有 2 個文件被更改,包括 10 次插入8 次删除
  1. 6 8
      dune_weaver_flask/modules/connection/connection_manager.py
  2. 4 0
      dune_weaver_flask/modules/core/state.py

+ 6 - 8
dune_weaver_flask/modules/connection/connection_manager.py

@@ -257,6 +257,11 @@ def get_machine_steps(timeout=10):
                 elif line.startswith("$131="):
                     gear_ratio = float(line.split("=")[1])
                     state.gear_ratio = gear_ratio
+                elif line.startswith("$22="):
+                    # $22 reports if the homing cycle is enabled
+                    # returns 0 if disabled, 1 if enabled
+                    homing = int(line.split('=')[1])
+                    state.homing = homing
             
             # If all parameters are received, exit early
             if x_steps_per_mm is not None and y_steps_per_mm is not None and gear_ratio is not None:
@@ -277,14 +282,7 @@ def home():
     """
     Perform homing by checking device configuration and sending the appropriate commands.
     """
-    try:
-        state.conn.send("$config\n")
-        response = state.conn.readline().strip().lower()
-        logger.debug(f"Config response: {response}")
-    except Exception as e:
-        logger.error(f"Error during homing config: {e}")
-        response = ""
-    if "sensorless" in response:
+    if state.homing:
         logger.info("Using sensorless homing")
         state.conn.send("$H\n")
         state.conn.send("G1 Y0 F100\n")

+ 4 - 0
dune_weaver_flask/modules/core/state.py

@@ -27,6 +27,8 @@ class AppState:
         self.x_steps_per_mm = 0.0
         self.y_steps_per_mm = 0.0
         self.gear_ratio = 10
+        # 0 for crash homing, 1 for auto homing
+        self.homing = 0
         
         self.STATE_FILE = "state.json"
         self.mqtt_handler = None  # Will be set by the MQTT handler
@@ -101,6 +103,7 @@ class AppState:
             "x_steps_per_mm": self.x_steps_per_mm,
             "y_steps_per_mm": self.y_steps_per_mm,
             "gear_ratio": self.gear_ratio,
+            "homing": self.homing,
             "current_playlist": self._current_playlist,
             "current_playlist_index": self.current_playlist_index,
             "playlist_mode": self.playlist_mode,
@@ -123,6 +126,7 @@ class AppState:
         self.x_steps_per_mm = data.get("x_steps_per_mm", 0.0)
         self.y_steps_per_mm = data.get("y_steps_per_mm", 0.0)
         self.gear_ratio = data.get('gear_ratio', 10)
+        self.homing = data.get('homing', 0)
         self._current_playlist = data.get("current_playlist")
         self.current_playlist_index = data.get("current_playlist_index")
         self.playlist_mode = data.get("playlist_mode")