SissiFeng commited on
Commit
11d39fe
·
verified ·
1 Parent(s): 6b3183a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py CHANGED
@@ -47,6 +47,8 @@ latest_data = {
47
  "status": "N/A",
48
  "update_time": "Waiting for data...",
49
  "image_url": "N/A",
 
 
50
  }
51
 
52
  bambu_client = None
@@ -115,6 +117,13 @@ def rpi_on_message(client, userdata, msg):
115
 
116
  if "error" in data:
117
  logger.error(f"Error from RPI: {data['error']}")
 
 
 
 
 
 
 
118
 
119
  except Exception as e:
120
  logger.error(f"Error processing message from RPI: {e}")
@@ -189,6 +198,11 @@ def send_print_parameters(nozzle_temp, bed_temp, print_speed, fan_speed):
189
  logger.error(f"Error sending parameters: {e}")
190
  return f"Error sending parameters: {e}"
191
 
 
 
 
 
 
192
 
193
 
194
  def get_image_base64(image):
@@ -293,6 +307,17 @@ def capture_image(url=None, use_test_image=False, test_image_name=None):
293
  else:
294
  raise Exception("url is 'N/A'")
295
 
 
 
 
 
 
 
 
 
 
 
 
296
 
297
  def health_check():
298
  status = {
@@ -585,6 +610,20 @@ with demo:
585
  api_name="send_print_parameters",
586
  )
587
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
588
  if __name__ == "__main__":
589
  logger.info("Starting Bambu A1 Mini Print Control application")
590
 
 
47
  "status": "N/A",
48
  "update_time": "Waiting for data...",
49
  "image_url": "N/A",
50
+ "progress": 0,
51
+ "message": "",
52
  }
53
 
54
  bambu_client = None
 
117
 
118
  if "error" in data:
119
  logger.error(f"Error from RPI: {data['error']}")
120
+
121
+ if status == "Ready":
122
+ latest_data["progress"] = 0
123
+ latest_data["message"] = "Printer ready"
124
+ elif status == "Processing":
125
+ latest_data["progress"] = 25
126
+ latest_data["message"] = "Processing G-code..."
127
 
128
  except Exception as e:
129
  logger.error(f"Error processing message from RPI: {e}")
 
198
  logger.error(f"Error sending parameters: {e}")
199
  return f"Error sending parameters: {e}"
200
 
201
+
202
+ latest_data["status"] = "Sending"
203
+ latest_data["progress"] = 10
204
+ latest_data["message"] = "Sending parameters to printer..."
205
+
206
 
207
 
208
  def get_image_base64(image):
 
307
  else:
308
  raise Exception("url is 'N/A'")
309
 
310
+ def update_print_status():
311
+ global latest_data
312
+ return (
313
+ latest_data["status"],
314
+ latest_data["nozzle_temperature"],
315
+ latest_data["bed_temperature"],
316
+ latest_data["update_time"],
317
+ latest_data.get("progress", 0),
318
+ latest_data.get("message", ""),
319
+ )
320
+
321
 
322
  def health_check():
323
  status = {
 
610
  api_name="send_print_parameters",
611
  )
612
 
613
+ get_status_api = demo.load(
614
+ fn=health_check,
615
+ inputs=[],
616
+ outputs=[
617
+ gr.Textbox(label="Status"),
618
+ gr.Textbox(label="Nozzle Temperature"),
619
+ gr.Textbox(label="Bed Temperature"),
620
+ gr.Textbox(label="Update Time"),
621
+ gr.Number(label="Progress"),
622
+ gr.Textbox(label="Message"),
623
+ ],
624
+ api_name="get_status",
625
+ )
626
+
627
  if __name__ == "__main__":
628
  logger.info("Starting Bambu A1 Mini Print Control application")
629