Browse Source

final touch up

Tuan Nguyen 1 year ago
parent
commit
a94e326932
5 changed files with 170 additions and 5 deletions
  1. 3 1
      app.py
  2. 31 2
      arduino_code/arduino_code.ino
  3. 2 1
      arduino_code_TMC2209/arduino_code_TMC2209.ino
  4. 29 1
      esp32/esp32.ino
  5. 105 0
      static/style.css

+ 3 - 1
app.py

@@ -334,7 +334,7 @@ def upload_theta_rho():
 @app.route('/run_theta_rho', methods=['POST'])
 def run_theta_rho():
     file_name = request.json.get('file_name')
-    pre_execution = request.json.get('pre_execution')  # 'clear_in', 'clear_out', or 'none'
+    pre_execution = request.json.get('pre_execution')  # 'clear_in', 'clear_out', 'clear_sideway', or 'none'
 
     if not file_name:
         return jsonify({'error': 'No file name provided'}), 400
@@ -732,4 +732,6 @@ def set_speed():
         return jsonify({"success": False, "error": str(e)}), 500
 
 if __name__ == '__main__':
+    # Auto-connect to serial
+    connect_to_serial()
     app.run(debug=True, host='0.0.0.0', port=8080)

+ 31 - 2
arduino_code/arduino_code.ino

@@ -180,9 +180,38 @@ void appMode()
         String input = Serial.readStringUntil('\n');
 
         // Ignore invalid messages
-        if (input != "HOME" && input != "RESET_THETA" && !input.endsWith(";"))
+        if (input != "HOME" && input != "RESET_THETA" && !input.startsWith("SET_SPEED") && !input.endsWith(";"))
         {
-            Serial.println("IGNORED");
+            Serial.print("IGNORED: ");
+            Serial.println(input);
+            return;
+        }
+
+        if (input.startsWith("SET_SPEED"))
+        {
+            // Parse and set the speed
+            int spaceIndex = input.indexOf(' ');
+            if (spaceIndex != -1)
+            {
+                String speedStr = input.substring(spaceIndex + 1);
+                float speed = speedStr.toFloat();
+
+                if (speed > 0) // Ensure valid speed
+                {
+                    rotStepper.setMaxSpeed(speed);
+                    inOutStepper.setMaxSpeed(speed);
+                    Serial.println("SPEED_SET");
+                    Serial.println("R");
+                }
+                else
+                {
+                    Serial.println("INVALID_SPEED");
+                }
+            }
+            else
+            {
+                Serial.println("INVALID_COMMAND");
+            }
             return;
         }
 

+ 2 - 1
arduino_code_TMC2209/arduino_code_TMC2209.ino

@@ -183,7 +183,8 @@ void appMode()
         // Ignore invalid messages
         if (input != "HOME" && input != "RESET_THETA" && !input.startsWith("SET_SPEED") && !input.endsWith(";"))
         {
-            Serial.println("IGNORED");
+            Serial.print("IGNORED: ");
+            Serial.println(input);
             return;
         }
 

+ 29 - 1
esp32/esp32.ino

@@ -75,12 +75,40 @@ void loop()
         String input = Serial.readStringUntil('\n');
 
         // Ignore invalid messages
-        if (input != "HOME" && input != "RESET_THETA" && !input.endsWith(";"))
+        if (input != "HOME" && input != "RESET_THETA" && !input.startsWith("SET_SPEED") && !input.endsWith(";"))
         {
             Serial.println("IGNORED");
             return;
         }
 
+        if (input.startsWith("SET_SPEED"))
+        {
+            // Parse and set the speed
+            int spaceIndex = input.indexOf(' ');
+            if (spaceIndex != -1)
+            {
+                String speedStr = input.substring(spaceIndex + 1);
+                double speed = speedStr.toDouble();
+
+                if (speed > 0) // Ensure valid speed
+                {
+                    rotStepper.setMaxSpeed(speed);
+                    inOutStepper.setMaxSpeed(speed);
+                    Serial.println("SPEED_SET");
+                    Serial.println("R");
+                }
+                else
+                {
+                    Serial.println("INVALID_SPEED");
+                }
+            }
+            else
+            {
+                Serial.println("INVALID_COMMAND");
+            }
+            return;
+        }
+
         if (input == "HOME")
         {
             homing();

+ 105 - 0
static/style.css

@@ -255,6 +255,111 @@ input[type="radio"]:checked {
     width: 80px;
 }
 
+/* Speed Control Section */
+.speed-control {
+    display: flex;
+    align-items: center;
+    gap: 15px;
+    margin-top: 10px;
+    background: #fff; /* Matches section background */
+    border: 1px solid #ddd;
+    border-radius: 8px;
+    padding: 15px;
+    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
+}
+
+.speed-control label {
+    font-weight: bold;
+    font-size: 1rem;
+    color: #333;
+    flex-shrink: 0;
+}
+
+.speed-control input[type="number"] {
+    width: 100px; /* Consistent input width */
+    padding: 8px;
+    font-size: 1rem;
+    border: 1px solid #ddd;
+    border-radius: 5px;
+    outline: none;
+    transition: all 0.3s ease;
+}
+
+.speed-control input[type="number"]:focus {
+    border-color: #4A90E2; /* Highlighted border */
+    box-shadow: 0 0 5px rgba(74, 144, 226, 0.5);
+}
+
+.speed-control button {
+    background: #4A90E2;
+    color: #fff;
+    padding: 10px 15px;
+    font-size: 1rem;
+    border: none;
+    border-radius: 5px;
+    cursor: pointer;
+    transition: all 0.3s ease;
+}
+
+.speed-control button:hover {
+    background: #357ABD;
+}
+
+#speed_status {
+    margin-top: 10px;
+    font-size: 0.9rem;
+    color: #444;
+}
+
+#serial_ports_container > * {
+    display: inline-block;
+}
+
+#serial_ports_container select {
+    margin: 10px;
+    flex-basis: 100px;
+    flex-grow: 0;
+}
+
+#serial_ports {
+    width: auto;
+    min-width: 200px;
+}
+
+#serial_status_container,
+#serial_ports_buttons {
+    display: inline-block;
+}
+
+.status.connected {
+    color: #4CAF50;
+    font-weight: bold;
+}
+
+.status.not-connected {
+    color: #E53935;
+    font-weight: bold;
+}
+
+.footer {
+    align-items: center;
+    display: flex;
+    flex-wrap: wrap;
+    justify-content: space-between;
+    margin-bottom: 20px;
+    width: 100%;
+}
+
+.footer #github {
+    align-content: center;
+    display: flex;
+    font-size: 0.8em;
+}
+
+.footer #github img {
+    margin: 0 5px
+}
+
 /* Responsive Layout for Small Screens */
 @media (max-width: 768px) {
     body {