fixed some problems with communication

updated communication shell see
http://www.doodle3d.com/help/api-documentation
This commit is contained in:
casperlamboo 2015-05-07 10:48:24 +02:00
parent 33576ad45b
commit 69e5534d0d
5 changed files with 197 additions and 145 deletions

156
build/d3d.js vendored
View File

@ -1,7 +1,7 @@
/****************************************************** /******************************************************
* *
* Utils * Utils
* requires jQuery, Three.js * requires jQuery, Three.js, Clipper.js
* *
******************************************************/ ******************************************************/
@ -147,6 +147,8 @@ var requestAnimFrame = (function () {
* Box * Box
* Representation of de Doodle3DBox * Representation of de Doodle3DBox
* Handles all communication with the doodle box * Handles all communication with the doodle box
* JavaScript shell for api communication
* Check http://www.doodle3d.com/help/api-documentation
* *
******************************************************/ ******************************************************/
@ -237,12 +239,12 @@ D3D.Box.prototype.printBatch = function () {
var gcode = this.printBatches.shift(); var gcode = this.printBatches.shift();
sendAPI(this.api + "printer/print", { sendAPI(this.api + "printer/print", {
"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.join("\n") "gcode": gcode.join("\n")
}, function (data) { }, function (data) {
console.log("batch sent: " + self.currentBatch, data); console.log("batch sent: " + self.currentBatch, data);
if (self.printBatches.length > 0) { if (self.printBatches.length > 0) {
//sent new batch //sent new batch
self.currentBatch ++; self.currentBatch ++;
@ -254,7 +256,7 @@ D3D.Box.prototype.printBatch = function () {
self.updateState(); self.updateState();
}); });
}; };
D3D.Box.prototype.stop = function () { D3D.Box.prototype.stopPrint = function () {
"use strict"; "use strict";
this.printBatches = []; this.printBatches = [];
@ -275,140 +277,160 @@ D3D.Box.prototype.stop = function () {
sendAPI(this.api + "printer/stop", { sendAPI(this.api + "printer/stop", {
"gcode": finishMove.join("\n") "gcode": finishMove.join("\n")
//"gcode": {}
}, function (data) { }, function (data) {
console.log("Printer stop command sent"); console.log("Printer stop command sent");
}); });
return this; return this;
}; };
D3D.Box.prototype.setConfig = function (data) { D3D.Box.prototype.setConfig = function (data, callback) {
//works
"use strict"; "use strict";
sendAPI(this.api + "config", data); sendAPI(this.api + "config", data, callback);
return this; return this;
}; };
D3D.Box.prototype.getInfoLog = function (callback) { D3D.Box.prototype.getInfo = function (callback) {
//works
"use strict"; "use strict";
getAPI(self.api + "info/logfiles", function (data) { getAPI(this.api + "info", callback);
if (callback !== undefined) { };
callback(data); D3D.Box.prototype.downloadInfoLog = function (callback) {
} //works in google chrome... not tested in other browsers
}); //some browsers may redirect using this code
"use strict";
return this; window.location = this.api + "info/logfiles";
}; };
D3D.Box.prototype.getInfoAcces = function (callback) { D3D.Box.prototype.getInfoAcces = function (callback) {
//works
"use strict"; "use strict";
getAPI(self.api + "info/acces", function (data) { getAPI(this.api + "info/access", callback);
if (callback !== undefined) {
callback(data);
}
});
return this; return this;
}; };
D3D.Box.prototype.getNetwerkScan = function (callback) { D3D.Box.prototype.getNetworkScan = function (callback) {
//works
"use strict"; "use strict";
getAPI(self.api + "network/scan", function (data) { getAPI(this.api + "network/scan", callback);
if (callback !== undefined) {
callback(data);
}
});
return this; return this;
}; };
D3D.Box.prototype.getNetworkKnown = function (callback) { D3D.Box.prototype.getNetworkKnown = function (callback) {
//works
"use strict"; "use strict";
getAPI(self.api + "network/known", function (data) { getAPI(this.api + "network/known", callback);
if (callback !== undefined) {
callback(data);
}
});
return this; return this;
}; };
D3D.Box.prototype.getNetworkStatus = function (callback) { D3D.Box.prototype.getNetworkStatus = function (callback) {
//works
"use strict"; "use strict";
getAPI(self.api + "network/status", function (data) { getAPI(this.api + "network/status", callback);
if (callback !== undefined) {
callback(data);
}
});
return this; return this;
}; };
D3D.Box.prototype.setNetworkAssosiate = function (data) { D3D.Box.prototype.setNetworkAssosiate = function (data, callback) {
//works
"use strict"; "use strict";
sendAPI(self.api + "network/assosiate", data); sendAPI(this.api + "network/associate", data, callback);
return this; return this;
}; };
D3D.Box.prototype.setNetworkDisassosiate = function (data) { D3D.Box.prototype.setNetworkDisassosiate = function (callback) {
//not tested
"use strict"; "use strict";
sendAPI(self.api + "network/displayassosiate", data); sendAPI(this.api + "network/disassociate", {}, callback);
return this; return this;
}; };
D3D.Box.prototype.setNetworkOpenap = function (data) { D3D.Box.prototype.setNetworkOpenAP = function (callback) {
//not tested
"use strict"; "use strict";
sendAPI(self.api + "network/openap", data); sendAPI(this.api + "network/openap", {}, callback);
return this; return this;
}; };
D3D.Box.prototype.setNetworkRemove = function (ssid) { D3D.Box.prototype.setNetworkRemove = function (ssid, callback) {
//works
"use strict"; "use strict";
sendAPI(self.api + "network/displayassosiate", {ssid: ssid}); sendAPI(this.api + "network/remove", {
ssid: ssid
}, callback);
return this; return this;
}; };
D3D.Box.prototype.getNetworkAlive = function (callback) { D3D.Box.prototype.getNetworkAlive = function (callback) {
//works but returns empty array
"use strict"; "use strict";
getAPI(self.api + "network/alive", function (data) { getAPI(this.api + "network/alive", callback);
if (callback !== undefined) {
callback(data);
}
});
return this; return this;
}; };
D3D.Box.prototype.getPrinterListAll = function (callback) { D3D.Box.prototype.getPrinterListAll = function (callback) {
//works
"use strict"; "use strict";
getAPI(self.api + "printer/listall", function (data) { getAPI(this.api + "printer/listall", callback);
if (callback !== undefined) {
callback(data);
}
});
return this; return this;
}; };
D3D.Box.prototype.setPrinterHeatup = function (data) { D3D.Box.prototype.setPrinterHeatup = function (callback) {
//works
"use strict"; "use strict";
sendAPI(self.api + "printer/heatup", data); sendAPI(this.api + "printer/heatup", {}, callback);
return this; return this;
}; };
D3D.Box.prototype.getVersion = function (data) { D3D.Box.prototype.getSystemVersions = function (callback) {
//works
"use strict"; "use strict";
getAPI(self.api + "system/fwversion", function (data) { getAPI(this.api + "system/fwversions", callback);
if (callback !== undefined) {
callback(data); return this;
} };
}); D3D.Box.prototype.getUpdateStatus = function (callback) {
//not tested
"use strict";
getAPI(this.api + "update/status", callback);
return this;
};
D3D.Box.prototype.setUpdateDownload = function (callback) {
//not tested
"use strict";
sendAPI(this.api + "update/download", {}, callback);
return this;
};
D3D.Box.prototype.setUpdateInstall = function (callback) {
//not tested
"use strict";
sendAPI(this.api + "update/install", {}, callback);
return this;
};
D3D.Box.prototype.setUpdateClear = function (callback) {
//not tested
"use strict";
sendAPI(this.api + "update/clear", {}, callback);
return this; return this;
}; };
@ -499,7 +521,11 @@ D3D.Slicer = function () {
D3D.Slicer.prototype.setGeometry = function (geometry) { D3D.Slicer.prototype.setGeometry = function (geometry) {
"use strict"; "use strict";
this.geometry = geometry; if (geometry instanceof THREE.BufferGeometry) {
geometry = new THREE.Geometry().fromBufferGeometry(geometry);
}
this.geometry = geometry.clone();
this.geometry.mergeVertices(); this.geometry.mergeVertices();
this.createLines(); this.createLines();
@ -909,11 +935,11 @@ D3D.Slicer.prototype.drawPaths = function (printer, min, max) {
for (var i = 0; i < paths.length; i ++) { for (var i = 0; i < paths.length; i ++) {
var path = paths[i]; var path = paths[i];
context.moveTo((path[0].X- 100) * 6.0 + 200, (path[0].Y- 100) * 6.0 + 200); context.moveTo((path[0].X * 2), (path[0].Y * 2));
for (var j = 0; j < path.length; j ++) { for (var j = 0; j < path.length; j ++) {
var point = path[j]; var point = path[j];
context.lineTo((point.X- 100) * 6.0 + 200, (point.Y- 100) * 6.0 + 200); context.lineTo((point.X * 2), (point.Y * 2));
} }
//context.closePath(); //context.closePath();
} }

2
build/d3d.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -23,19 +23,23 @@ $(document).ready(function () {
listDoodle.append("<li><a href='doodle.html#192.168.5.1'>Wired Printer</a></li>"); listDoodle.append("<li><a href='doodle.html#192.168.5.1'>Wired Printer</a></li>");
listSliceTest.append("<li><a href='slice_test.html#192.168.5.1'>Wired Printer</a></li>"); listSliceTest.append("<li><a href='slice_test.html#192.168.5.1'>Wired Printer</a></li>");
/*printers.push({ /*
printers.push({
name: "wired box", name: "wired box",
d3dbox: new D3D.Box("192.168.5.1") d3dbox: new D3D.Box("192.168.5.1")
});*/ });
*/
getAPI(api + "list.php", function (boxes) { getAPI(api + "list.php", function (boxes) {
for (var i = 0; i < boxes.length; i ++) { for (var i = 0; i < boxes.length; i ++) {
var box = boxes[i]; var box = boxes[i];
/*printers.push({ /*
printers.push({
name: box.wifiboxid, name: box.wifiboxid,
d3dbox: new D3D.Box(box.localip) d3dbox: new D3D.Box(box.localip)
});*/ });
*/
listDoodle.append("<li><a href='doodle.html#" + box.localip + "'>" + box.wifiboxid + "</a></li>"); listDoodle.append("<li><a href='doodle.html#" + box.localip + "'>" + box.wifiboxid + "</a></li>");
listSliceTest.append("<li><a href='slice_test.html#" + box.localip + "'>" + box.wifiboxid + "</a></li>"); listSliceTest.append("<li><a href='slice_test.html#" + box.localip + "'>" + box.wifiboxid + "</a></li>");
@ -49,7 +53,8 @@ $(document).ready(function () {
<p>Slice Test</p> <p>Slice Test</p>
<ul id="printers-slicetest"></ul> <ul id="printers-slicetest"></ul>
<!--<table> <!--
<table>
<tr> <tr>
<th>localip</th> <th>localip</th>
<th>wifiboxid</th> <th>wifiboxid</th>
@ -60,7 +65,7 @@ $(document).ready(function () {
<td>wifiboxid</td> <td>wifiboxid</td>
<td>date</td> <td>date</td>
</tr> </tr>
</table>--> </table>
-->
</body> </body>
</html> </html>

View File

@ -87,7 +87,7 @@ var geometry = (function () {
var hole = new THREE.Path(); var hole = new THREE.Path();
hole.absarc(0, 0, 5, 0, Math.PI*2, true ); hole.absarc(0, 0, 5, 0, Math.PI*2, true );
//circle.holes.push(hole); circle.holes.push(hole);
var matrix = new THREE.Matrix4(); var matrix = new THREE.Matrix4();
matrix.makeRotationX(Math.PI*1.5); matrix.makeRotationX(Math.PI*1.5);
@ -123,7 +123,8 @@ var layer = 149;
var img = slicer.drawPaths(printer, layer, layer + 1); var img = slicer.drawPaths(printer, layer, layer + 1);
context.drawImage(img, 0, 0); context.drawImage(img, 0, 0);
/*var loader = new THREE.STLLoader(); /*
var loader = new THREE.STLLoader();
loader.load('stl/overhang_test.stl', function (geometry) { loader.load('stl/overhang_test.stl', function (geometry) {
var matrix = new THREE.Matrix4(); var matrix = new THREE.Matrix4();
@ -140,8 +141,14 @@ loader.load('stl/overhang_test.stl', function (geometry) {
var slicer = new D3D.Slicer().setGeometry(geometry); var slicer = new D3D.Slicer().setGeometry(geometry);
//gcode = slicer.getGcode(printer); var layer = 149;
});*/ var img = slicer.drawPaths(printer, layer, layer + 1);
context.drawImage(img, 0, 0);
var gcode = slicer.getGcode(printer);
console.log(gcode);
});
*/
(function animate () { (function animate () {
"use strict"; "use strict";

View File

@ -3,6 +3,8 @@
* Box * Box
* Representation of de Doodle3DBox * Representation of de Doodle3DBox
* Handles all communication with the doodle box * Handles all communication with the doodle box
* JavaScript shell for api communication
* Check http://www.doodle3d.com/help/api-documentation
* *
******************************************************/ ******************************************************/
@ -93,12 +95,12 @@ D3D.Box.prototype.printBatch = function () {
var gcode = this.printBatches.shift(); var gcode = this.printBatches.shift();
sendAPI(this.api + "printer/print", { sendAPI(this.api + "printer/print", {
"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.join("\n") "gcode": gcode.join("\n")
}, function (data) { }, function (data) {
console.log("batch sent: " + self.currentBatch, data); console.log("batch sent: " + self.currentBatch, data);
if (self.printBatches.length > 0) { if (self.printBatches.length > 0) {
//sent new batch //sent new batch
self.currentBatch ++; self.currentBatch ++;
@ -110,7 +112,7 @@ D3D.Box.prototype.printBatch = function () {
self.updateState(); self.updateState();
}); });
}; };
D3D.Box.prototype.stop = function () { D3D.Box.prototype.stopPrint = function () {
"use strict"; "use strict";
this.printBatches = []; this.printBatches = [];
@ -131,148 +133,160 @@ D3D.Box.prototype.stop = function () {
sendAPI(this.api + "printer/stop", { sendAPI(this.api + "printer/stop", {
"gcode": finishMove.join("\n") "gcode": finishMove.join("\n")
//"gcode": {}
}, function (data) { }, function (data) {
console.log("Printer stop command sent"); console.log("Printer stop command sent");
}); });
return this; return this;
}; };
D3D.Box.prototype.setConfig = function (data) { D3D.Box.prototype.setConfig = function (data, callback) {
//works
"use strict"; "use strict";
sendAPI(this.api + "config", data); sendAPI(this.api + "config", data, callback);
return this; return this;
}; };
D3D.Box.prototype.getInfoLog = function (callback) { D3D.Box.prototype.getInfo = function (callback) {
//works
"use strict"; "use strict";
getAPI(this.api + "info/logfiles", function (data) { getAPI(this.api + "info", callback);
if (callback !== undefined) { };
callback(data); D3D.Box.prototype.downloadInfoLog = function (callback) {
} //works in google chrome... not tested in other browsers
}); //some browsers may redirect using this code
"use strict";
return this; window.location = this.api + "info/logfiles";
}; };
D3D.Box.prototype.getInfoAcces = function (callback) { D3D.Box.prototype.getInfoAcces = function (callback) {
//works
"use strict"; "use strict";
//error getAPI(this.api + "info/access", callback);
//cannot call function or module 'info/acces' ('module/function 'info/acces' does not exist')
getAPI(this.api + "info/acces", function (data) {
if (callback !== undefined) {
callback(data);
}
});
return this; return this;
}; };
D3D.Box.prototype.getNetwerkScan = function (callback) { D3D.Box.prototype.getNetworkScan = function (callback) {
//works
"use strict"; "use strict";
getAPI(this.api + "network/scan", function (data) { getAPI(this.api + "network/scan", callback);
if (callback !== undefined) {
callback(data);
}
});
return this; return this;
}; };
D3D.Box.prototype.getNetworkKnown = function (callback) { D3D.Box.prototype.getNetworkKnown = function (callback) {
//works
"use strict"; "use strict";
getAPI(this.api + "network/known", function (data) { getAPI(this.api + "network/known", callback);
if (callback !== undefined) {
callback(data);
}
});
return this; return this;
}; };
D3D.Box.prototype.getNetworkStatus = function (callback) { D3D.Box.prototype.getNetworkStatus = function (callback) {
//works
"use strict"; "use strict";
getAPI(this.api + "network/status", function (data) { getAPI(this.api + "network/status", callback);
if (callback !== undefined) {
callback(data);
}
});
return this; return this;
}; };
D3D.Box.prototype.setNetworkAssosiate = function (data) { D3D.Box.prototype.setNetworkAssosiate = function (data, callback) {
//works
"use strict"; "use strict";
sendAPI(this.api + "network/assosiate", data); sendAPI(this.api + "network/associate", data, callback);
return this; return this;
}; };
D3D.Box.prototype.setNetworkDisassosiate = function (data) { D3D.Box.prototype.setNetworkDisassosiate = function (callback) {
//not tested
"use strict"; "use strict";
sendAPI(this.api + "network/displayassosiate", data); sendAPI(this.api + "network/disassociate", {}, callback);
return this; return this;
}; };
D3D.Box.prototype.setNetworkOpenap = function (data) { D3D.Box.prototype.setNetworkOpenAP = function (callback) {
//not tested
"use strict"; "use strict";
sendAPI(this.api + "network/openap", data); sendAPI(this.api + "network/openap", {}, callback);
return this; return this;
}; };
D3D.Box.prototype.setNetworkRemove = function (ssid) { D3D.Box.prototype.setNetworkRemove = function (ssid, callback) {
//works
"use strict"; "use strict";
sendAPI(this.api + "network/displayassosiate", {ssid: ssid}); sendAPI(this.api + "network/remove", {
ssid: ssid
}, callback);
return this; return this;
}; };
D3D.Box.prototype.getNetworkAlive = function (callback) { D3D.Box.prototype.getNetworkAlive = function (callback) {
//works but returns empty array
"use strict"; "use strict";
//emty? getAPI(this.api + "network/alive", callback);
getAPI(this.api + "network/alive", function (data) {
if (callback !== undefined) {
callback(data);
}
});
return this; return this;
}; };
D3D.Box.prototype.getPrinterListAll = function (callback) { D3D.Box.prototype.getPrinterListAll = function (callback) {
//works
"use strict"; "use strict";
getAPI(this.api + "printer/listall", function (data) { getAPI(this.api + "printer/listall", callback);
if (callback !== undefined) {
callback(data);
}
});
return this; return this;
}; };
D3D.Box.prototype.setPrinterHeatup = function (data) { D3D.Box.prototype.setPrinterHeatup = function (callback) {
//works
"use strict"; "use strict";
sendAPI(this.api + "printer/heatup", data); sendAPI(this.api + "printer/heatup", {}, callback);
return this; return this;
}; };
D3D.Box.prototype.getVersion = function (data) { D3D.Box.prototype.getSystemVersions = function (callback) {
//works
"use strict"; "use strict";
//error getAPI(this.api + "system/fwversions", callback);
//cannot call function or module 'system/fwversion' ('module/function 'system/fwversion' does not exist')
return this;
getAPI(this.api + "system/fwversion", function (data) { };
if (callback !== undefined) { D3D.Box.prototype.getUpdateStatus = function (callback) {
callback(data); //not tested
} "use strict";
});
getAPI(this.api + "update/status", callback);
return this;
};
D3D.Box.prototype.setUpdateDownload = function (callback) {
//not tested
"use strict";
sendAPI(this.api + "update/download", {}, callback);
return this;
};
D3D.Box.prototype.setUpdateInstall = function (callback) {
//not tested
"use strict";
sendAPI(this.api + "update/install", {}, callback);
return this;
};
D3D.Box.prototype.setUpdateClear = function (callback) {
//not tested
"use strict";
sendAPI(this.api + "update/clear", {}, callback);
return this; return this;
}; };