2013-07-26 22:39:28 +02:00
|
|
|
var sendIndex;
|
|
|
|
var sendLength;
|
|
|
|
|
2013-07-29 16:48:13 +02:00
|
|
|
var data = "";
|
|
|
|
function startPrint(gcode) {
|
|
|
|
console.log("f:startPrint()");
|
|
|
|
console.log("total # of lines: " + gcode.length);
|
|
|
|
data = gcode;
|
2013-08-01 20:01:52 +02:00
|
|
|
|
|
|
|
for (i = 0; i < data.length; i++) {
|
|
|
|
data[i] += " (" + i + ")";
|
|
|
|
}
|
2013-07-29 16:48:13 +02:00
|
|
|
|
|
|
|
sendIndex = 0;
|
|
|
|
sendLength = 2000; // 2000 regels
|
|
|
|
sendGCodeSlice(sendIndex, sendLength);
|
2013-07-26 22:39:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function sendGCodeSlice(startIndex, sendAmt) {
|
2013-07-29 16:48:13 +02:00
|
|
|
console.log("f:sendGCodeSlice >> startIndex:" + startIndex + ", sendAmt:" + sendAmt);
|
2013-07-26 22:39:28 +02:00
|
|
|
|
|
|
|
if (typeof startIndex == "number" && typeof sendAmt == "number") {
|
|
|
|
var lastOne = false;
|
|
|
|
if (data.length < (startIndex + sendAmt)) {
|
|
|
|
console.log("f:senGCodeSlice >> not enough data left for full slice, sending smaller (and last) one");
|
|
|
|
sendAmt = data.length - startIndex;
|
|
|
|
lastOne = true;
|
|
|
|
}
|
|
|
|
var _tmp = data.slice(startIndex, startIndex+sendAmt);
|
|
|
|
// console.log("f:senGCodeSlice >> _tmp.length:" + _tmp.length);
|
|
|
|
|
2013-07-29 16:48:13 +02:00
|
|
|
// $.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) {
|
2013-07-26 22:39:28 +02:00
|
|
|
console.log("sendBoy callback: " + e);
|
|
|
|
// console.log(e);
|
|
|
|
// console.log("e.success: " + e.success);
|
|
|
|
if (e.success = true) {
|
|
|
|
if (lastOne) {
|
|
|
|
console.log("f:sendGCodeSlice >> DONE!");
|
|
|
|
} else {
|
|
|
|
sendGCodeSlice(startIndex + sendAmt, sendAmt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
console.log(" something wrong");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function sendBoy(sendObj, callback) {
|
2013-07-29 16:48:13 +02:00
|
|
|
console.log("f:sendBoy() (dummy kastje) >> data length: " + sendObj.data.length + ", lastOne: " + sendObj.last);
|
2013-07-26 22:39:28 +02:00
|
|
|
console.log("");
|
|
|
|
if (callback != undefined) callback({success:true});
|
|
|
|
}
|