sending gcode now in array

This commit is contained in:
casperlamboo 2015-05-19 19:04:20 +02:00
parent 20e80b390e
commit 173e723656
5 changed files with 29 additions and 14 deletions

View File

@ -44,7 +44,6 @@ var printer = new D3D.Printer({
"printer.heatup.enabled": true, "printer.heatup.enabled": true,
"printer.heatup.temperature": 180, "printer.heatup.temperature": 180,
"printer.retraction.amount": 3, "printer.retraction.amount": 3,
"printer.retraction.enabled": false,
"printer.retraction.minDistance": 5, "printer.retraction.minDistance": 5,
"printer.retraction.speed": 50, "printer.retraction.speed": 50,
"printer.screenToMillimeterScale": 0.3, //???? "printer.screenToMillimeterScale": 0.3, //????
@ -54,6 +53,7 @@ var printer = new D3D.Printer({
"printer.type": "ultimaker", "printer.type": "ultimaker",
"printer.useSubLayers": true, //wat is dit? "printer.useSubLayers": true, //wat is dit?
"printer.retraction.enabled": true,
"printer.speed": 50, "printer.speed": 50,
"printer.wallThickness": 0.4, //nozzle "printer.wallThickness": 0.4, //nozzle
"printer.layerHeight": 0.3, "printer.layerHeight": 0.3,

View File

@ -16,9 +16,8 @@ D3D.Box = function (localIp) {
"use strict"; "use strict";
var self = this; var self = this;
this.batchSize = 1024 * 10; //10kb this.batchSize = 512;
this.maxBufferSize = 1024 * 1024 * 2; //2mb this.maxBufferedLines = 4096;
this.bytesSend = 0;
this.localIp = localIp; this.localIp = localIp;
this.api = "http://" + localIp + "/d3dapi/"; this.api = "http://" + localIp + "/d3dapi/";
@ -61,7 +60,7 @@ D3D.Box.prototype.update = function () {
//Bij error wordt gelijk zelfde data opnieuw gestuurd //Bij error wordt gelijk zelfde data opnieuw gestuurd
//Als DoodleBox ontkoppeld wordt komt er een error in de loop waardoor pagina breekt en ververst moet worden //Als DoodleBox ontkoppeld wordt komt er een error in de loop waardoor pagina breekt en ververst moet worden
if (this.printBatches.length > 0 && (this.status["buffered_lines"]*30 + this.batchSize) <= this.maxBufferSize) { if (this.printBatches.length > 0 && (this.status["buffered_lines"] + this.batchSize) <= this.maxBufferedLines) {
//if (this.printBatches.length > 0 ) { //if (this.printBatches.length > 0 ) {
this.printBatch(); this.printBatch();
} }
@ -89,9 +88,12 @@ D3D.Box.prototype.print = function (gcode) {
this.currentBatch = 0; this.currentBatch = 0;
//clone gcode to remove array links
gcode = gcode.clone();
//gcode split in batches //gcode split in batches
for (var i = 0; i < gcode.length; i += this.batchSize) { while (gcode.length > 0) {
var gcodeBatch = gcode.substring(i, Math.min(i + this.batchSize, gcode.length)); var gcodeBatch = gcode.splice(0, Math.min(this.batchSize, gcode.length));
this.printBatches.push(gcodeBatch); this.printBatches.push(gcodeBatch);
} }
@ -106,7 +108,7 @@ D3D.Box.prototype.printBatch = function () {
this.setPrinterPrint({ this.setPrinterPrint({
"start": ((this.currentBatch === 0) ? true : false), "start": ((this.currentBatch === 0) ? true : false),
"first": ((this.currentBatch === 0) ? true : false), "first": ((this.currentBatch === 0) ? true : false),
"gcode": gcode "gcode": gcode.join("\n")
}, function (data) { }, function (data) {
console.log("batch sent: " + self.currentBatch, data); console.log("batch sent: " + self.currentBatch, data);

View File

@ -29,7 +29,7 @@ D3D.Printer.prototype.getStartCode = function () {
var gcode = this.config["printer.startcode"]; var gcode = this.config["printer.startcode"];
gcode = this.subsituteVariables(gcode); gcode = this.subsituteVariables(gcode);
return gcode; return gcode.split("\n");
}; };
D3D.Printer.prototype.getEndCode = function () { D3D.Printer.prototype.getEndCode = function () {
"use strict"; "use strict";
@ -37,7 +37,7 @@ D3D.Printer.prototype.getEndCode = function () {
var gcode = this.config["printer.endcode"]; var gcode = this.config["printer.endcode"];
gcode = this.subsituteVariables(gcode); gcode = this.subsituteVariables(gcode);
return gcode; return gcode.split("\n");
}; };
D3D.Printer.prototype.subsituteVariables = function (gcode) { D3D.Printer.prototype.subsituteVariables = function (gcode) {
"use strict"; "use strict";

View File

@ -431,8 +431,8 @@ D3D.Slicer.prototype.dataToGcode = function (data, printer) {
} }
} }
else { else {
var a = new THREE.Vector2().set(point.X, point.Y); var a = new THREE.Vector2(point.X, point.Y);
var b = new THREE.Vector2().set(previousPoint.X, previousPoint.Y); var b = new THREE.Vector2(previousPoint.X, previousPoint.Y);
var lineLength = a.distanceTo(b); var lineLength = a.distanceTo(b);
extruder += lineLength * wallThickness * layerHeight / filamentSurfaceArea * flowRate; extruder += lineLength * wallThickness * layerHeight / filamentSurfaceArea * flowRate;
@ -452,7 +452,7 @@ D3D.Slicer.prototype.dataToGcode = function (data, printer) {
return gcode; return gcode;
} }
var gcode = printer.getStartCode().split("\n"); var gcode = printer.getStartCode();
var extruder = 0.0; var extruder = 0.0;
var speed = firstLayerSlow ? (bottomSpeed*60).toFixed(3) : (normalSpeed*60).toFixed(3); var speed = firstLayerSlow ? (bottomSpeed*60).toFixed(3) : (normalSpeed*60).toFixed(3);
@ -480,7 +480,9 @@ D3D.Slicer.prototype.dataToGcode = function (data, printer) {
} }
} }
return gcode.join("\n") + "\n" + printer.getEndCode(); gcode = gcode.concat(printer.getEndCode());
return gcode;
}; };
//only for debug purposes //only for debug purposes
D3D.Slicer.prototype.drawPaths = function (printer, min, max) { D3D.Slicer.prototype.drawPaths = function (printer, min, max) {

View File

@ -68,4 +68,15 @@ function downloadFile (file, data) {
button.download = file; button.download = file;
button.href = window.URL.createObjectURL(blob); button.href = window.URL.createObjectURL(blob);
button.click(); button.click();
}
Array.prototype.clone = function () {
"use strict";
var array = [];
for (var i = 0; i < this.length; i ++) {
array[i] = this[i];
}
return array;
} }