diff --git a/Gruntfile.js b/Gruntfile.js index 4a33db7..4c6bdea 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -16,7 +16,7 @@ module.exports = function(grunt) { }, js: { src: [ - 'js/api/*.js', + //'js/api/*.js', 'js/settings/FormPanel.js', 'js/settings/*.js', 'js/*.js', @@ -24,6 +24,10 @@ module.exports = function(grunt) { '!js/main.js', 'js/main.js', ], dest: 'www/js/<%= pkg.name %>.js' + }, + api: { + src: [ 'js/api/*.js'], + dest: 'www/js/doodle3d-api.js' } }, uglify: { @@ -37,7 +41,8 @@ module.exports = function(grunt) { }, js: { files: { - 'www/js/<%= pkg.name %>.min.js' : ['www/js/<%= pkg.name %>.js'] + 'www/js/<%= pkg.name %>.min.js' : ['www/js/<%= pkg.name %>.js'], + 'www/js/doodle3d-api.min.js' : ['www/js/doodle3d-api.js'] } }, jslibs: { @@ -91,7 +96,7 @@ module.exports = function(grunt) { watch: { javascript: { files: ["js/**", '!www/js/<%= pkg.name %>.min.js', '!www/js/<%= pkg.name %>.js'], - tasks: ["concat:js", "uglify:js"] + tasks: ["concat:api", "concat:js", "uglify:js"], // tasks: ["jshint", "concat", "uglify"] }, javascriptLibs: { diff --git a/js/api/API.js b/js/api/API.js new file mode 100644 index 0000000..fcaff8e --- /dev/null +++ b/js/api/API.js @@ -0,0 +1,64 @@ +/* + * This file is part of the Doodle3D project (http://doodle3d.com). + * + * Copyright (c) 2013, Doodle3D + * This software is licensed under the terms of the GNU GPL v2 or later. + * See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details. + */ + +var API = function() { + + var _wifiboxURL = 'http://192.168.5.1/d3dapi/'; + var _wifiboxCGIBinURL = 'http://192.168.5.1/cgi-bin/d3dapi/'; + var _timeoutTime = 10000; + + function post(cmd,data,success,fail) { + $.ajax({ + url: _wifiboxURL + cmd, + type: "POST", + data: data, + dataType: 'json', + timeout: _timeoutTime, + success: function(response){ + if(response.status == "error" || response.status == "fail") { + console.log('API.post fail',cmd) + if (fail) fail(response); + } else { + if (success) success(response.data); + else console.log('API.post:',cmd,'success cb undefined') + } + } + }).fail(function(jqXHR, textStatus) { + console.log('API.post fail',cmd,jqXHR,textStatus); + if (fail) fail(jqXHR,textStatus); + }); + } + + function get(cmd,success,fail) { + $.ajax({ + url: _wifiboxURL + cmd, + type: "GET", + dataType: 'json', + timeout: _timeoutTime, + success: function(response){ + if (response.status == "error" || response.status == "fail") { + console.log('API.get fail',cmd,response); + if (fail) fail(response); + } else { + if (success) success(response.data); + else console.log('API.get:',cmd,'success cb undefined') + } + } + }).fail(function() { + console.log('API.get fail',cmd); + if (fail) fail(); + }); + } + + return { + get: get, + post: post + } + +}(); + diff --git a/js/api/ConfigAPI.js b/js/api/ConfigAPI.js index c6feb94..c40ec70 100644 --- a/js/api/ConfigAPI.js +++ b/js/api/ConfigAPI.js @@ -8,92 +8,77 @@ function ConfigAPI() { - var _wifiboxURL; - var _wifiboxCGIBinURL; - var _timeoutTime = 3000; - var _saveSettingsTimeoutTime = 8000; - - var _self = this; + function loadAll(success,fail) { + API.get('config/all',success,fail); + }; - this.init = function(wifiboxURL,wifiboxCGIBinURL) { - //console.log("ConfigAPI:init"); - - _wifiboxURL = wifiboxURL; - _wifiboxCGIBinURL = wifiboxCGIBinURL; + function load(key,success,fail) { + API.get('config/?'+key+'=',success,fail) + }; + + function save(newSettings,success,fail) { + API.post('config',{data:newSettings},success,fail); + }; + + function resetAll(success,fail) { + API.post('config/resetall',{},success,fail) + }; + + function getSetting(key,success,fail) { + API.get('config/?'+key+'=',function(response) { + if (success) success(response[key]); + },fail); + } + + function getStartCode(success,fail) { + loadAll(function(data) { + var startcode = subsituteVariables(data['printer.startcode'],data); + if (success) success(startcode); + },fail); + } + + function getEndCode(success,fail) { + loadAll(function(data) { + var endcode = subsituteVariables(data['printer.endcode'],data); + if (success) success(endcode); + },fail); + } + + function subsituteVariables(gcode,settings) { + //,temperature,bedTemperature,preheatTemperature,preheatBedTemperature + var temperature = settings["printer.temperature"]; + var bedTemperature = settings["printer.bed.temperature"]; + var preheatTemperature = settings["printer.heatup.temperature"]; + var preheatBedTemperature = settings["printer.heatup.bed.temperature"]; + var printerType = settings["printer.type"]; + var heatedbed = settings["printer.heatedbed"]; + + switch (printerType) { + case "makerbot_replicator2": printerType = "r2"; break; + case "makerbot_replicator2x": printerType = "r2x"; break; + case "makerbot_thingomatic": printerType = "t6"; break; + case "makerbot_generic": printerType = "r2"; break; + case "_3Dison_plus": printerType = "r2"; break; + } + var heatedBedReplacement = (heatedbed)? "" : ";"; + + gcode = gcode.replace(/{printingTemp}/gi ,temperature); + gcode = gcode.replace(/{printingBedTemp}/gi ,bedTemperature); + gcode = gcode.replace(/{preheatTemp}/gi ,preheatTemperature); + gcode = gcode.replace(/{preheatBedTemp}/gi ,preheatBedTemperature); + gcode = gcode.replace(/{printerType}/gi ,printerType); + gcode = gcode.replace(/{if heatedBed}/gi ,heatedBedReplacement); + + return gcode; + } + + return { + loadAll: loadAll, + load: load, + save: save, + resetAll: resetAll, + getSetting: getSetting, + getStartCode: getStartCode, + getEndCode: getEndCode, } - this.loadAll = function(completeHandler,failedHandler) { - //console.log("ConfigAPI:loadAll"); - $.ajax({ - url: _wifiboxURL + "/config/all", - type: "GET", - dataType: 'json', - timeout: _timeoutTime, - success: function(response){ - if(response.status == "error" || response.status == "fail") { - if(failedHandler) failedHandler(response); - } else { - completeHandler(response.data); - } - } - }).fail(function() { - if(failedHandler) failedHandler(); - }); - }; - this.load = function(targetSettings,completeHandler,failedHandler) { - //console.log("ConfigAPI:load"); - $.ajax({ - url: _wifiboxURL + "/config/", - type: "GET", - dataType: 'json', - data: targetSettings, - timeout: _timeoutTime, - success: function(response){ - if(response.status == "error" || response.status == "fail") { - if(failedHandler) failedHandler(response); - } else { - completeHandler(response.data); - } - } - }).fail(function() { - if(failedHandler) failedHandler(); - }); - }; - this.save = function(newSettings,completeHandler,failedHandler) { - //console.log("ConfigAPI:save"); - $.ajax({ - url: _wifiboxCGIBinURL + "/config", - type: "POST", - data: newSettings, - dataType: 'json', - timeout: _saveSettingsTimeoutTime, - success: function(response){ - //console.log("ConfigAPI:save response: ",response); - if(response.status == "error" || response.status == "fail") { - if(failedHandler) failedHandler(response); - } else { - completeHandler(response.data); - } - } - }).fail(function() { - if(failedHandler) failedHandler(); - }); - }; - this.resetAll = function(completeHandler,failedHandler) { - //console.log("ConfigAPI:resetAll"); - $.ajax({ - url: _wifiboxCGIBinURL + "/config/resetall", - type: "POST", - dataType: 'json', - timeout: _timeoutTime, - success: function(response){ - if(response.status == "error" || response.status == "fail") { - if(failedHandler) failedHandler(response); - } else { - completeHandler(response.data); - } - } - }).fail(function() { - if(failedHandler) failedHandler(); - }); - }; } \ No newline at end of file diff --git a/js/api/InfoAPI.js b/js/api/InfoAPI.js new file mode 100644 index 0000000..80fdd3d --- /dev/null +++ b/js/api/InfoAPI.js @@ -0,0 +1,14 @@ +/* + * This file is part of the Doodle3D project (http://doodle3d.com). + * + * Copyright (c) 2013, Doodle3D + * This software is licensed under the terms of the GNU GPL v2 or later. + * See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details. + */ +function InfoAPI() { + + this.status = function(success,fail) { + API.get('info/status',success,fail); + }; + +} \ No newline at end of file diff --git a/js/api/PrinterAPI.js b/js/api/PrinterAPI.js index fe96d23..58ebc49 100644 --- a/js/api/PrinterAPI.js +++ b/js/api/PrinterAPI.js @@ -5,42 +5,84 @@ * This software is licensed under the terms of the GNU GPL v2 or later. * See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details. */ -function PrinterAPI() { - - var _wifiboxURL; - var _wifiboxCGIBinURL; - var _timeoutTime = 3000; - - var _self = this; - this.init = function(wifiboxURL,wifiboxCGIBinURL) { - //console.log("PrinterAPI:init"); - //console.log(" wifiboxURL: ",wifiboxURL); - //console.log(" wifiboxCGIBinURL: ",wifiboxCGIBinURL); - _wifiboxURL = wifiboxURL; - _wifiboxCGIBinURL = wifiboxCGIBinURL; - } +function PrinterAPI() { + + this.remainingLines = []; + this.totalLinesAtStart = 0; + + this.state = function(success,fail) { + API.get('printer/state',success,fail); + }; - this.listAll = function(completeHandler,failedHandler) { - //console.log("PrinterAPI:listAll"); - //console.log(" _wifiboxURL: ",_wifiboxURL); - $.ajax({ - url: _wifiboxURL + "/printer/listall", - type: "GET", - dataType: 'json', - timeout: _timeoutTime, - success: function(response){ - //console.log("PrinterAPI response: ",response); - if(response.status == "error" || response.status == "fail") { - //console.log("PrinterAPI:listAll failed: ",response); - if(failedHandler) failedHandler(response); - } else { - completeHandler(response.data); - } + this.listAll = function(success,fail) { + API.get('printer/listall',success,fail); + }; + + this.temperature = function(success,fail) { + API.get('printer/temperature',success,fail); + }; + + this.progress = function(success,fail) { + API.get('printer/progress',success,fail); + } + + function _printPartPost(lines,data,cb) { + + API.post('printer/print',data,function(response) { + console.log('print part success',response); + setTimeout(function() { + _printPart(lines,false,false,cb); + },10); + + },function(jqXHR,textStatus) { + console.log('print fail jqHXR:',jqXHR,"textStatus:",textStatus); + if (textStatus=="timeout") { + console.log('TIMEOUT, waiting to try again'); + setTimeout(function() { + console.log('now try again'); + _printPartPost(lines,data,cb); + },5000); + } else { + console.log("_printPartPost FATAL error:",textStatus); } - }).fail(function() { - //console.log("PrinterAPI:listAll failed"); - if(failedHandler) failedHandler(); + }); + } + + function _printPart(lines,first,start,cb) { + var chunk = lines.splice(0,500); + console.log('printPart',chunk.length,lines.length); + + if (chunk.length>0) { + var data = {gcode: chunk.join("\n"), first: first, start: start}; + + _printPartPost(lines,data,function() { + console.log('_printPartPost cb'); + cb(); //??? needed + }); + + } else { + console.log('no more print parts'); + cb(); //finished + } + } + + this.print = function(gcode,start,first,success,fail) { + //need a check here for state?? + this.remainingLines = gcode.split("\n"); + this.totalLinesAtStart = this.remainingLines.length; + // console.log('remainingLines.length',this.remainingLines.length); + _printPart(this.remainingLines,true,true,function() { + console.log('done sending'); }); }; + + this.stop = function(endcode,success,fail) { + //need a check here for state?? + // console.log('remainingLines',this.remainingLines.length); + this.remainingLines.length = 0; //clear array + totalLinesAtStart = 0; + API.post('printer/stop',{gcode:endcode},success,fail); + } + } \ No newline at end of file diff --git a/js/api/SketchAPI.js b/js/api/SketchAPI.js new file mode 100644 index 0000000..c02c33c --- /dev/null +++ b/js/api/SketchAPI.js @@ -0,0 +1,15 @@ +/* + * This file is part of the Doodle3D project (http://doodle3d.com). + * + * Copyright (c) 2013, Doodle3D + * This software is licensed under the terms of the GNU GPL v2 or later. + * See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details. + */ + +function SketchAPI() { + + this.load = function(id,success,fail) { + API.get('sketch/?id='+id,success,fail); + } + +} \ No newline at end of file diff --git a/js/buttonbehaviors.js b/js/buttonbehaviors.js index 93efa4f..a89ee12 100644 --- a/js/buttonbehaviors.js +++ b/js/buttonbehaviors.js @@ -310,7 +310,6 @@ function oopsUndo() { } function previewUp(redrawLess) { - // console.log("f:previewUp()"); if (numLayers < maxNumLayers) { numLayers++; } diff --git a/www/filemanager/css/style.css b/www/filemanager/css/style.css index 1a91b0b..2a45770 100644 --- a/www/filemanager/css/style.css +++ b/www/filemanager/css/style.css @@ -1,7 +1,6 @@ body { font-family: Helvetica, Abel, Arial; font-size: 1em; - -webkit-user-select: none; /* webkit (safari, chrome) browsers */ -moz-user-select: none; /* mozilla browsers */ -khtml-user-select: none; /* webkit (konqueror) browsers */ @@ -12,7 +11,7 @@ button { font-size: 1em; } -div.item { +.item { width:150px; height:130px; border:1px solid black; @@ -22,14 +21,10 @@ div.item { margin-right: 5px; } -div.item.selected { +.item.selected { background-color: #7cf; } -div.item input[type='checkbox'] { - position: absolute; -} - #frmUpload { display: inline; } @@ -41,9 +36,11 @@ input[type='file'] { #txtInfo { float: right; + margin-top: 5px; /*display: inline-block;*/ } img#logo { cursor: pointer; -} \ No newline at end of file +} + diff --git a/www/filemanager/index.html b/www/filemanager/index.html index a55bcf0..2ffee06 100644 --- a/www/filemanager/index.html +++ b/www/filemanager/index.html @@ -6,25 +6,22 @@
+