Tuan Nguyen пре 1 година
родитељ
комит
8c31dcaf88

+ 9 - 9
dune_weaver_flask/app.py

@@ -70,8 +70,8 @@ def restart():
         return jsonify({'error': 'No port provided'}), 400
 
     try:
-        logger.info(f"Restarting serial connection on port {port}")
-        connection_manager.restart_connection(port)
+        logger.info(f"Restarting connection on port {port}")
+        connection_manager.restart_connection()
         return jsonify({'success': True})
     except Exception as e:
         logger.error(f"Failed to restart serial on port {port}: {str(e)}")
@@ -170,8 +170,8 @@ def move_to_center():
     global current_theta
     try:
         if not state.conn.is_connected():
-            logger.warning("Attempted to move to center without serial connection")
-            return jsonify({"success": False, "error": "Serial connection not established"}), 400
+            logger.warning("Attempted to move to center without connection")
+            return jsonify({"success": False, "error": "Connection not established"}), 400
 
         logger.info("Moving device to center position")
         pattern_manager.reset_theta()
@@ -186,8 +186,8 @@ def move_to_perimeter():
     global current_theta
     try:
         if not state.conn.is_connected():
-            logger.warning("Attempted to move to perimeter without serial connection")
-            return jsonify({"success": False, "error": "Serial connection not established"}), 400
+            logger.warning("Attempted to move to perimeter without connection")
+            return jsonify({"success": False, "error": "Connection not established"}), 400
         pattern_manager.reset_theta()
         pattern_manager.move_polar(0,1)
         return jsonify({"success": True})
@@ -217,8 +217,8 @@ def preview_thr():
 @app.route('/send_coordinate', methods=['POST'])
 def send_coordinate():
     if not state.conn.is_connected():
-        logger.warning("Attempted to send coordinate without serial connection")
-        return jsonify({"success": False, "error": "Serial connection not established"}), 400
+        logger.warning("Attempted to send coordinate without connection")
+        return jsonify({"success": False, "error": "connection not established"}), 400
 
     try:
         data = request.json
@@ -419,7 +419,7 @@ def update_software():
 
 def on_exit():
     """Function to execute on application shutdown."""
-    logger.info("Shutting down gracefully, please wait for executiong to complete")
+    logger.info("Shutting down gracefully, please wait for execution to complete")
     pattern_manager.stop_actions()
     state.save()
     mqtt.cleanup_mqtt()

+ 5 - 11
dune_weaver_flask/modules/connection/connection_manager.py

@@ -134,13 +134,14 @@ def device_init():
         pass
 
     machine_x, machine_y = get_machine_position()
-    if not machine_x or not machine_y or machine_x != state.machine_x or machine_y != state.machine_y:
+    if machine_x != state.machine_x or machine_y != state.machine_y:
         logger.info(f'x, y; {machine_x}, {machine_y}')
         logger.info(f'State x, y; {state.machine_x}, {state.machine_y}')
         home()
     else:
         logger.info('Machine position known, skipping home')
         logger.info(f'Theta: {state.current_theta}, rho: {state.current_rho}')
+        logger.info(f'x, y; {machine_x}, {machine_y}')
         logger.info(f'State x, y; {state.machine_x}, {state.machine_y}')
 
     time.sleep(2)  # Allow time for the connection to establish
@@ -267,7 +268,7 @@ def get_machine_steps(timeout=10):
     return False
 
 
-def home(retry=0):
+def home():
     """
     Perform homing by checking device configuration and sending the appropriate commands.
     """
@@ -283,16 +284,9 @@ def home(retry=0):
         logger.info("Using sensorless homing")
         state.conn.send("$H\n")
         state.conn.send("G1 Y0 F100\n")
-    elif "filename" in response or "error:3" in response:
-        logger.info("Using crash homing")
-        send_grbl_coordinates(0, -110/5, 300, home=True)
     else:
-        if retry < 3:
-            time.sleep(1)
-            home(retry + 1)
-            return
-        else:
-            raise Exception("Couldn't get a valid response for homing after 3 retries")
+        logger.info("Sensorless homing not supported. Using crash homing")
+        send_grbl_coordinates(0, -110/5, state.speed, home=True)
     state.current_theta = state.current_rho = 0
     update_machine_position()
 

+ 5 - 5
dune_weaver_flask/static/js/main.js

@@ -559,7 +559,7 @@ async function runFile(fileName) {
     }
 }
 
-// Serial Connection Status
+// Connection Status
 async function checkSerialStatus() {
     const response = await fetch('/serial_status');
     const status = await response.json();
@@ -599,7 +599,7 @@ async function checkSerialStatus() {
         statusElement.textContent = 'Not connected';
         statusElement.classList.add('not-connected');
         statusElement.classList.remove('connected');
-        logMessage('No active serial connection.');
+        logMessage('No active connection.');
 
         // Update header status
         statusHeaderElement.classList.add('not-connected');
@@ -670,11 +670,11 @@ async function restartSerial() {
     const result = await response.json();
     if (result.success) {
         document.getElementById('serial_status').textContent = `Restarted connection to ${port}`;
-        logMessage('Serial connection restarted.', LOG_TYPE.SUCCESS);
+        logMessage('Connection restarted.', LOG_TYPE.SUCCESS);
 
         // No need to change visibility for restart
     } else {
-        logMessage(`Error restarting serial connection: ${result.error}`, LOG_TYPE.ERROR);
+        logMessage(`Error restarting Connection: ${result.error}`, LOG_TYPE.ERROR);
     }
 }
 
@@ -1700,7 +1700,7 @@ document.addEventListener("visibilitychange", handleVisibilityChange);
 document.addEventListener('DOMContentLoaded', () => {
     const activeTab = getCookie('activeTab') || 'patterns'; // Default to 'patterns' tab
     switchTab(activeTab); // Load the active tab
-    checkSerialStatus(); // Check serial connection status
+    checkSerialStatus(); // Check connection status
     loadThetaRhoFiles(); // Load files on page load
     loadAllPlaylists(); // Load all playlists on page load
     attachSettingsSaveListeners(); // Attach event listeners to save changes

+ 1 - 1
dune_weaver_flask/templates/index.html

@@ -312,7 +312,7 @@
             </div>
             <section>
                 <div class="header">
-                    <h2>Serial Connection</h2>
+                    <h2>Device Connection</h2>
                 </div>
                 <div id="serial_status_container">Status: <span id="serial_status" class="status"> Not connected</span></div>
                 <div id="serial_ports_container">