From 7972273e27ab524ba0dedf88cb7ff68a565831b3 Mon Sep 17 00:00:00 2001 From: Wouter R Date: Mon, 29 Jul 2013 16:48:13 +0200 Subject: [PATCH] Enable sending gcode. It prints! --- js/buttonbehaviors.js | 48 +++++++++++++++++++-------------------- js/doodlePrintCode.js | 46 ++++++++++++++++--------------------- js/gcodeGenerating_v01.js | 2 +- 3 files changed, 44 insertions(+), 52 deletions(-) diff --git a/js/buttonbehaviors.js b/js/buttonbehaviors.js index d7a461f..bdbe429 100644 --- a/js/buttonbehaviors.js +++ b/js/buttonbehaviors.js @@ -213,36 +213,34 @@ function nextDoodle(e) { } function print(e) { - console.log("f:print()"); + console.log("f:print()"); - $("#textdump").text(""); - if (_points.length > 2) { - //* - // generate_gcode(); - var gencode = generate_gcode(); - startPrint(); + $("#textdump").text(""); + if (_points.length > 2) { + var gencode = generate_gcode(); + startPrint(gencode); -// console.log(""); -// console.log(""); -// console.log("-------------------------------------------------"); -// console.log("generated gcode:"); -// console.log(gencode); -// console.log("-------------------------------------------------"); -// console.log(""); -// console.log(""); -// console.log(""); +// console.log(""); +// console.log(""); +// console.log("-------------------------------------------------"); +// console.log("generated gcode:"); +// console.log(gencode); +// console.log("-------------------------------------------------"); +// console.log(""); +// console.log(""); +// console.log(""); - $("#textdump").text(gencode); - // copyToClipboard(gencode); - //*/ - } else { - console.log("f:print >> not enough points!"); - } + $("#textdump").text(gencode.join("\n")); + // copyToClipboard(gencode); + //*/ + } else { + console.log("f:print >> not enough points!"); + } -// $.post("/doodle3d.of", { data:output }, function(data) { -// btnPrint.disabled = false; -// }); +// $.post("/doodle3d.of", { data:output }, function(data) { +// btnPrint.disabled = false; +// }); } diff --git a/js/doodlePrintCode.js b/js/doodlePrintCode.js index bbd9708..84da0de 100644 --- a/js/doodlePrintCode.js +++ b/js/doodlePrintCode.js @@ -5,32 +5,20 @@ var sendLength; var kastjeURL = "http://192.168.5.1/cgi-bin/d3dapi/"; -var mydata = ""; -function startPrint() { - console.log("f:startPrint()"); +var data = ""; +function startPrint(gcode) { + console.log("f:startPrint()"); + console.log("total # of lines: " + gcode.length); + data = gcode; -// sendIndex = 0; -// sendLength = 2000; // 2000 regels -// sendGCodeSlice(sendIndex, sendLength); - - // 2013-07-28 tot hier en niet verder... de GCODE kan al wel worden gegenereerd, maar we sturen het nu niet naar het kastje. - /* - $.post(kastjeURL + "test/" + "write/", { data: "test"}, function(data) { - console.log("returned data: " + JSON.stringify(data)); - data = JSON.parse(data); - console.log(" data.msg: " + data.msg); - console.log(" data.status: " + data.status); - // console.log(" status: " + data["status"]); - // btnPrint.disabled = false; - }); - //*/ - - //http://192.168.10.1/cgi-bin/d3dapi/write + sendIndex = 0; + sendLength = 2000; // 2000 regels + sendGCodeSlice(sendIndex, sendLength); } function sendGCodeSlice(startIndex, sendAmt) { - console.log("f:senGCodeSlice >> startIndex:" + startIndex + ", sendAmt:" + sendAmt); + console.log("f:sendGCodeSlice >> startIndex:" + startIndex + ", sendAmt:" + sendAmt); if (typeof startIndex == "number" && typeof sendAmt == "number") { var lastOne = false; @@ -42,10 +30,16 @@ function sendGCodeSlice(startIndex, sendAmt) { var _tmp = data.slice(startIndex, startIndex+sendAmt); // console.log("f:senGCodeSlice >> _tmp.length:" + _tmp.length); - $.post("/doodle3d.of", { data:output }, function(data) { - btnPrint.disabled = false; - }); - sendBoy( { data: _tmp, lastOne: lastOne} , function(e) { +// $.post("/doodle3d.of", { data:data }, function(data) { +// btnPrint.disabled = false; +// }); + + var firstOne = false; + if (startIndex == 0) { firstOne = true; } + + var postData = { id: 0, gcode: _tmp.join("\n"), first: firstOne, last: lastOne}; + + $.post( wifiboxURL + "/printer/print", postData , function(e) { console.log("sendBoy callback: " + e); // console.log(e); // console.log("e.success: " + e.success); @@ -63,7 +57,7 @@ function sendGCodeSlice(startIndex, sendAmt) { } function sendBoy(sendObj, callback) { - console.log("f:sendBoy() (dummy kastje) >> data length: " + sendObj.data.length + ", lastOne: " + sendObj.lastOne); + console.log("f:sendBoy() (dummy kastje) >> data length: " + sendObj.data.length + ", lastOne: " + sendObj.last); console.log(""); if (callback != undefined) callback({success:true}); } \ No newline at end of file diff --git a/js/gcodeGenerating_v01.js b/js/gcodeGenerating_v01.js index 05d8cd0..65fbaa4 100644 --- a/js/gcodeGenerating_v01.js +++ b/js/gcodeGenerating_v01.js @@ -155,7 +155,7 @@ function generate_gcode(callback) { // Return the gcode array, joined to one string with '\n' (line break) as the join parameter // This should result in a nice long string with line breaks if (callback == undefined) { - return gcode.join("\n"); + return gcode; } else { // post }