clean up code

This commit is contained in:
casperlamboo 2015-05-07 14:09:36 +02:00
parent 624409aa30
commit 5e43789f82
6 changed files with 341 additions and 139 deletions

201
build/d3d.js vendored
View File

@ -172,14 +172,9 @@ D3D.Box = function (localIp) {
this.currentBatch = 0; this.currentBatch = 0;
this.loaded = false; this.loaded = false;
this.onload;
getAPI(self.api + "config/all", function (data) { this.getConfigAll(function (data) {
for (var i in data) { self.updateConfig(data);
if (i.indexOf("doodle3d") === 0) {
self.config[i] = data[i];
}
}
self.printer = new D3D.Printer(data); self.printer = new D3D.Printer(data);
self.update(); self.update();
@ -190,6 +185,17 @@ D3D.Box = function (localIp) {
} }
}); });
}; };
D3D.Box.prototype.updateConfig = function (config) {
"use strict";
for (var i in config) {
if (i.indexOf("doodle3d") === 0) {
this.config[i] = config[i];
}
}
return this;
};
D3D.Box.prototype.update = function () { D3D.Box.prototype.update = function () {
"use strict"; "use strict";
//TODO //TODO
@ -206,13 +212,17 @@ D3D.Box.prototype.update = function () {
} }
}; };
D3D.Box.prototype.updateState = function () { D3D.Box.prototype.updateState = function () {
//que api calls so they don't overload the d3d box
"use strict"; "use strict";
var self = this; var self = this;
//que api calls so they don't overload the d3d box this.getInfoStatus(function (data) {
getAPI(this.api + "info/status", function (data) {
self.printer.status = data; self.printer.status = data;
if (self.onupdate !== undefined) {
self.onupdate(data);
}
self.update(); self.update();
}); });
}; };
@ -238,7 +248,7 @@ D3D.Box.prototype.printBatch = function () {
var gcode = this.printBatches.shift(); var gcode = this.printBatches.shift();
sendAPI(this.api + "printer/print", { 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.join("\n") "gcode": gcode.join("\n")
@ -250,7 +260,7 @@ D3D.Box.prototype.printBatch = function () {
self.currentBatch ++; self.currentBatch ++;
} }
else { else {
//finish printing //finish sending
} }
self.updateState(); self.updateState();
@ -275,7 +285,7 @@ D3D.Box.prototype.stopPrint = function () {
"M117 Done ;display message (20 characters to clear whole screen)" "M117 Done ;display message (20 characters to clear whole screen)"
]; ];
sendAPI(this.api + "printer/stop", { this.setPrinterStop({
"gcode": finishMove.join("\n") "gcode": finishMove.join("\n")
}, function (data) { }, function (data) {
console.log("Printer stop command sent"); console.log("Printer stop command sent");
@ -283,11 +293,39 @@ D3D.Box.prototype.stopPrint = function () {
return this; return this;
}; };
D3D.Box.prototype.setConfig = function (data, callback) {
//COMMUNICATION SHELL
//see http://www.doodle3d.com/help/api-documentation
D3D.Box.prototype.getConfig = function (keys, callback) {
//works //works
"use strict"; "use strict";
sendAPI(this.api + "config", data, callback); getAPI(this.api + "config/?" + keys.join("=&") + "=", callback);
};
D3D.Box.prototype.getConfigAll = function (callback) {
//works
"use strict";
getAPI(this.api + "config/all", callback);
};
D3D.Box.prototype.setConfig = function (data, callback) {
//works
"use strict";
var self = this;
sendAPI(this.api + "config", data, function (response) {
for (var i in response.validation) {
if (response.validation[i] !== "ok") {
delete data[i];
}
}
self.updateConfig(data);
self.printer.updateConfig(data);
if (callback !== undefined) {
callback(response);
}
});
return this; return this;
}; };
@ -297,7 +335,15 @@ D3D.Box.prototype.getInfo = function (callback) {
getAPI(this.api + "info", callback); getAPI(this.api + "info", callback);
}; };
D3D.Box.prototype.downloadInfoLog = function (callback) { D3D.Box.prototype.getInfoStatus = function (callback) {
//works
"use strict";
getAPI(this.api + "info/status", callback);
return this;
};
D3D.Box.prototype.downloadInfoLogFiles = function () {
//works in google chrome... not tested in other browsers //works in google chrome... not tested in other browsers
//some browsers may redirect using this code //some browsers may redirect using this code
"use strict"; "use strict";
@ -370,6 +416,14 @@ D3D.Box.prototype.setNetworkRemove = function (ssid, callback) {
return this; return this;
}; };
D3D.Box.prototype.getNetworkSignin = function (callback) {
//works
"use strict";
getAPI(this.api + "network/signin", callback);
return this;
};
D3D.Box.prototype.getNetworkAlive = function (callback) { D3D.Box.prototype.getNetworkAlive = function (callback) {
//works but returns empty array //works but returns empty array
"use strict"; "use strict";
@ -378,6 +432,30 @@ D3D.Box.prototype.getNetworkAlive = function (callback) {
return this; return this;
}; };
D3D.Box.prototype.getPrinterTemperature = function (callback) {
//works
"use strict";
getAPI(this.api + "printer/temperature", callback);
return this;
};
D3D.Box.prototype.getPrinterProgress = function (callback) {
//works
"use strict";
getAPI(this.api + "printer/progress", callback);
return this;
};
D3D.Box.prototype.getPrinterState = function (callback) {
//works
"use strict";
getAPI(this.api + "printer/state", callback);
return this;
};
D3D.Box.prototype.getPrinterListAll = function (callback) { D3D.Box.prototype.getPrinterListAll = function (callback) {
//works //works
"use strict"; "use strict";
@ -394,6 +472,56 @@ D3D.Box.prototype.setPrinterHeatup = function (callback) {
return this; return this;
}; };
D3D.Box.prototype.setPrinterPrint = function (data, callback) {
//works
"use strict";
sendAPI(this.api + "printer/print", data, callback);
return this;
};
D3D.Box.prototype.setPrinterStop = function (data, callback) {
//works
"use strict";
sendAPI(this.api + "printer/stop", data, callback);
return this;
};
D3D.Box.prototype.getSketch = function (id, callback) {
//works
"use strict";
getAPI(this.api + "sketch/?id=" + id, callback);
return this;
};
D3D.Box.prototype.setSketch = function (data, callback) {
//works
"use strict";
sendAPI(this.api + "sketch", {
"data": data
}, callback);
return this;
};
D3D.Box.prototype.getSketchStatus = function (callback) {
//works
"use strict";
getAPI(this.api + "sketch/status", callback);
return this;
};
D3D.Box.prototype.setSketchClear = function (callback) {
//works
"use strict";
sendAPI(this.api + "sketch/clear", callback);
return this;
};
D3D.Box.prototype.getSystemVersions = function (callback) { D3D.Box.prototype.getSystemVersions = function (callback) {
//works //works
"use strict"; "use strict";
@ -402,46 +530,14 @@ D3D.Box.prototype.getSystemVersions = function (callback) {
return this; return this;
}; };
D3D.Box.prototype.getSketch = function (id, callback) {
//not tested
"use strict";
getAPI(this.api + "sketch/status/?id=" + id, callback);
return this;
};
D3D.Box.prototype.getSketchStatus = function (callback) {
//not tested
"use strict";
getAPI(this.api + "sketch/status", callback);
return this;
};
D3D.Box.prototype.getUpdateStatus = function (callback) { D3D.Box.prototype.getUpdateStatus = function (callback) {
//not tested //works
"use strict"; "use strict";
getAPI(this.api + "update/status", callback); getAPI(this.api + "update/status", callback);
return this; return this;
}; };
D3D.Box.prototype.setSketch = function (data, callback) {
//not tested
"use strict";
sendAPI(this.api + "sketch", data, callback);
return this;
};
D3D.Box.prototype.setSketchClear = function (callback) {
//not tested
"use strict";
sendAPI(this.api + "sketch/clear", callback);
return this;
};
D3D.Box.prototype.setUpdateDownload = function (callback) { D3D.Box.prototype.setUpdateDownload = function (callback) {
//not tested //not tested
"use strict"; "use strict";
@ -479,11 +575,18 @@ D3D.Printer = function (config) {
this.status = {}; this.status = {};
this.config = {}; this.config = {};
this.updateConfig(config);
};
D3D.Printer.prototype.updateConfig = function (config) {
"use strict";
for (var i in config) { for (var i in config) {
if (i.indexOf("printer") === 0) { if (i.indexOf("printer") === 0) {
this.config[i] = config[i]; this.config[i] = config[i];
} }
} }
return this;
}; };
D3D.Printer.prototype.getStartCode = function () { D3D.Printer.prototype.getStartCode = function () {
"use strict"; "use strict";
@ -546,8 +649,6 @@ D3D.Printer.prototype.subsituteVariables = function (gcode) {
D3D.Slicer = function () { D3D.Slicer = function () {
"use strict"; "use strict";
this.geometry;
this.lines = []; this.lines = [];
}; };
D3D.Slicer.prototype.setGeometry = function (geometry) { D3D.Slicer.prototype.setGeometry = function (geometry) {

2
build/d3d.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -28,14 +28,9 @@ D3D.Box = function (localIp) {
this.currentBatch = 0; this.currentBatch = 0;
this.loaded = false; this.loaded = false;
this.onload;
getAPI(self.api + "config/all", function (data) { this.getConfigAll(function (data) {
for (var i in data) { self.updateConfig(data);
if (i.indexOf("doodle3d") === 0) {
self.config[i] = data[i];
}
}
self.printer = new D3D.Printer(data); self.printer = new D3D.Printer(data);
self.update(); self.update();
@ -46,6 +41,17 @@ D3D.Box = function (localIp) {
} }
}); });
}; };
D3D.Box.prototype.updateConfig = function (config) {
"use strict";
for (var i in config) {
if (i.indexOf("doodle3d") === 0) {
this.config[i] = config[i];
}
}
return this;
};
D3D.Box.prototype.update = function () { D3D.Box.prototype.update = function () {
"use strict"; "use strict";
//TODO //TODO
@ -62,13 +68,17 @@ D3D.Box.prototype.update = function () {
} }
}; };
D3D.Box.prototype.updateState = function () { D3D.Box.prototype.updateState = function () {
//que api calls so they don't overload the d3d box
"use strict"; "use strict";
var self = this; var self = this;
//que api calls so they don't overload the d3d box this.getInfoStatus(function (data) {
getAPI(this.api + "info/status", function (data) {
self.printer.status = data; self.printer.status = data;
if (self.onupdate !== undefined) {
self.onupdate(data);
}
self.update(); self.update();
}); });
}; };
@ -94,7 +104,7 @@ D3D.Box.prototype.printBatch = function () {
var gcode = this.printBatches.shift(); var gcode = this.printBatches.shift();
sendAPI(this.api + "printer/print", { 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.join("\n") "gcode": gcode.join("\n")
@ -106,7 +116,7 @@ D3D.Box.prototype.printBatch = function () {
self.currentBatch ++; self.currentBatch ++;
} }
else { else {
//finish printing //finish sending
} }
self.updateState(); self.updateState();
@ -131,7 +141,7 @@ D3D.Box.prototype.stopPrint = function () {
"M117 Done ;display message (20 characters to clear whole screen)" "M117 Done ;display message (20 characters to clear whole screen)"
]; ];
sendAPI(this.api + "printer/stop", { this.setPrinterStop({
"gcode": finishMove.join("\n") "gcode": finishMove.join("\n")
}, function (data) { }, function (data) {
console.log("Printer stop command sent"); console.log("Printer stop command sent");
@ -139,11 +149,39 @@ D3D.Box.prototype.stopPrint = function () {
return this; return this;
}; };
D3D.Box.prototype.setConfig = function (data, callback) {
//COMMUNICATION SHELL
//see http://www.doodle3d.com/help/api-documentation
D3D.Box.prototype.getConfig = function (keys, callback) {
//works //works
"use strict"; "use strict";
sendAPI(this.api + "config", data, callback); getAPI(this.api + "config/?" + keys.join("=&") + "=", callback);
};
D3D.Box.prototype.getConfigAll = function (callback) {
//works
"use strict";
getAPI(this.api + "config/all", callback);
};
D3D.Box.prototype.setConfig = function (data, callback) {
//works
"use strict";
var self = this;
sendAPI(this.api + "config", data, function (response) {
for (var i in response.validation) {
if (response.validation[i] !== "ok") {
delete data[i];
}
}
self.updateConfig(data);
self.printer.updateConfig(data);
if (callback !== undefined) {
callback(response);
}
});
return this; return this;
}; };
@ -153,7 +191,15 @@ D3D.Box.prototype.getInfo = function (callback) {
getAPI(this.api + "info", callback); getAPI(this.api + "info", callback);
}; };
D3D.Box.prototype.downloadInfoLog = function (callback) { D3D.Box.prototype.getInfoStatus = function (callback) {
//works
"use strict";
getAPI(this.api + "info/status", callback);
return this;
};
D3D.Box.prototype.downloadInfoLogFiles = function () {
//works in google chrome... not tested in other browsers //works in google chrome... not tested in other browsers
//some browsers may redirect using this code //some browsers may redirect using this code
"use strict"; "use strict";
@ -226,6 +272,14 @@ D3D.Box.prototype.setNetworkRemove = function (ssid, callback) {
return this; return this;
}; };
D3D.Box.prototype.getNetworkSignin = function (callback) {
//works
"use strict";
getAPI(this.api + "network/signin", callback);
return this;
};
D3D.Box.prototype.getNetworkAlive = function (callback) { D3D.Box.prototype.getNetworkAlive = function (callback) {
//works but returns empty array //works but returns empty array
"use strict"; "use strict";
@ -234,6 +288,30 @@ D3D.Box.prototype.getNetworkAlive = function (callback) {
return this; return this;
}; };
D3D.Box.prototype.getPrinterTemperature = function (callback) {
//works
"use strict";
getAPI(this.api + "printer/temperature", callback);
return this;
};
D3D.Box.prototype.getPrinterProgress = function (callback) {
//works
"use strict";
getAPI(this.api + "printer/progress", callback);
return this;
};
D3D.Box.prototype.getPrinterState = function (callback) {
//works
"use strict";
getAPI(this.api + "printer/state", callback);
return this;
};
D3D.Box.prototype.getPrinterListAll = function (callback) { D3D.Box.prototype.getPrinterListAll = function (callback) {
//works //works
"use strict"; "use strict";
@ -250,6 +328,56 @@ D3D.Box.prototype.setPrinterHeatup = function (callback) {
return this; return this;
}; };
D3D.Box.prototype.setPrinterPrint = function (data, callback) {
//works
"use strict";
sendAPI(this.api + "printer/print", data, callback);
return this;
};
D3D.Box.prototype.setPrinterStop = function (data, callback) {
//works
"use strict";
sendAPI(this.api + "printer/stop", data, callback);
return this;
};
D3D.Box.prototype.getSketch = function (id, callback) {
//works
"use strict";
getAPI(this.api + "sketch/?id=" + id, callback);
return this;
};
D3D.Box.prototype.setSketch = function (data, callback) {
//works
"use strict";
sendAPI(this.api + "sketch", {
"data": data
}, callback);
return this;
};
D3D.Box.prototype.getSketchStatus = function (callback) {
//works
"use strict";
getAPI(this.api + "sketch/status", callback);
return this;
};
D3D.Box.prototype.setSketchClear = function (callback) {
//works
"use strict";
sendAPI(this.api + "sketch/clear", callback);
return this;
};
D3D.Box.prototype.getSystemVersions = function (callback) { D3D.Box.prototype.getSystemVersions = function (callback) {
//works //works
"use strict"; "use strict";
@ -258,46 +386,14 @@ D3D.Box.prototype.getSystemVersions = function (callback) {
return this; return this;
}; };
D3D.Box.prototype.getSketch = function (id, callback) {
//not tested
"use strict";
getAPI(this.api + "sketch/status/?id=" + id, callback);
return this;
};
D3D.Box.prototype.getSketchStatus = function (callback) {
//not tested
"use strict";
getAPI(this.api + "sketch/status", callback);
return this;
};
D3D.Box.prototype.getUpdateStatus = function (callback) { D3D.Box.prototype.getUpdateStatus = function (callback) {
//not tested //works
"use strict"; "use strict";
getAPI(this.api + "update/status", callback); getAPI(this.api + "update/status", callback);
return this; return this;
}; };
D3D.Box.prototype.setSketch = function (data, callback) {
//not tested
"use strict";
sendAPI(this.api + "sketch", data, callback);
return this;
};
D3D.Box.prototype.setSketchClear = function (callback) {
//not tested
"use strict";
sendAPI(this.api + "sketch/clear", callback);
return this;
};
D3D.Box.prototype.setUpdateDownload = function (callback) { D3D.Box.prototype.setUpdateDownload = function (callback) {
//not tested //not tested
"use strict"; "use strict";

View File

@ -11,11 +11,18 @@ D3D.Printer = function (config) {
this.status = {}; this.status = {};
this.config = {}; this.config = {};
this.updateConfig(config);
};
D3D.Printer.prototype.updateConfig = function (config) {
"use strict";
for (var i in config) { for (var i in config) {
if (i.indexOf("printer") === 0) { if (i.indexOf("printer") === 0) {
this.config[i] = config[i]; this.config[i] = config[i];
} }
} }
return this;
}; };
D3D.Printer.prototype.getStartCode = function () { D3D.Printer.prototype.getStartCode = function () {
"use strict"; "use strict";

View File

@ -15,8 +15,6 @@
D3D.Slicer = function () { D3D.Slicer = function () {
"use strict"; "use strict";
this.geometry;
this.lines = []; this.lines = [];
}; };
D3D.Slicer.prototype.setGeometry = function (geometry) { D3D.Slicer.prototype.setGeometry = function (geometry) {