Multi-printers #32

Open
n07070 wants to merge 80 commits from multi-printers into master
pull from: multi-printers
2 changed files with 14 additions and 7 deletions
Showing only changes of commit d682a18707 - Show all commits

No files matched your search

-1
View File
@@ -493,6 +493,5 @@ def camera_status():
else:
socketio.emit("camera_status", False)
if __name__ == "__main__":
app.run(use_reloader=False, host="0.0.0.0", ssl_context="adhoc")
+14 -6
View File
@@ -198,10 +198,11 @@ function setup_events(){
const data = await take_picture();
if (!data) {
throw new Error("No image was captured");
console.error("Print failed: No image was captured");
} else {
console.log("Printing picture");
const print_status = await print_picture(data);
}
await print_picture(data);
} catch (e) {
console.error("Print failed:", e);
alert(`Failed to print: ${e.message || e}`);
@@ -241,7 +242,8 @@ function take_picture() {
const w = video.videoWidth;
const h = video.videoHeight;
if (!w || !h) {
throw new Error(`Invalid video dimensions: ${w} × ${h}`);
console.log(`Invalid video dimensions: ${w} × ${h}`);
return null;
}
canvas.width = w;
@@ -252,7 +254,8 @@ function take_picture() {
console.log("Captured image:", data.slice(0, 30), "length:", data.length);
if (data.length < 100) {
throw new Error("Captured image is empty");
console.log("Captured image is empty");
return null
}
return data;
}
@@ -272,10 +275,15 @@ async function print_picture(data) {
formData.set("cut", true);
formData.set("process", false);
fetch("/api/print/img", {
const res = await fetch("/api/print/img", {
method: "POST",
body: formData
});
if(!res.ok){
throw new Error("Printing failed" + res.statusText);
} else {
return true;
}
}
function flip_cameras(){