diff --git a/index.html b/index.html index c9ab7ab..44bc04d 100644 --- a/index.html +++ b/index.html @@ -149,6 +149,7 @@
Speeds
+
@@ -191,8 +192,11 @@
Speeds
--> + + - + diff --git a/js/initialize_ready.js b/js/initialize_ready.js index 8da18d8..c86612f 100644 --- a/js/initialize_ready.js +++ b/js/initialize_ready.js @@ -6,8 +6,6 @@ let cmds = []; $(document).ready(function() { - // Set and try to maintain focus in Command Input box - $("#cmd-input").focus(); $(document).foundation({ // Start and customize foundation tooltip: { disable_for_touch: true @@ -23,9 +21,9 @@ $(document).ready(function() { let pathname = window.location.pathname; // Returns path only (/path/example.html) let url = window.location.href; // Returns full URL (https://example.com/path/example.html) let origin = window.location.origin; // Returns base URL (https://example.com) - console.log("pathname- " + pathname); - console.log("url- " + url); - console.log("origin- " + origin); + //console.log("pathname- " + pathname); + //console.log("url- " + url); + //console.log("origin- " + origin); $("#copyright").append(" [" + origin + "]"); // *** Get MENUs Items from JSON file @initial load *** @@ -174,9 +172,8 @@ $(document).ready(function() { let curFilename, curFile let lines = new Array() $('#file').change(function(evt) { - //document.getElementById('file').addEventListener('input', function(evt) { - event.preventDefault(); + evt.preventDefault(); console.log("got entry"); console.log(evt); console.log("file- " + curFile); @@ -215,40 +212,43 @@ $(document).ready(function() { }); }); $("#btn_cmd_quit").click(function(event) { // QUIT - console.log("Not Run"); - $('#myModal').foundation('reveal', 'close'); - curFile = ""; - curFilename=""; - $("#curfilename").text(""); - $('#file').val(''); - }); - $("#btn_prev_file").click(function(event) { // PREVIEW - console.log("Not Run"); - $('#myModal').foundation('reveal', 'close'); - curFile = ""; - curFilename=""; - $("#curfilename").text(""); + console.log("Not Run"); + $('#myModal').foundation('reveal', 'close'); + curFile = ""; + curFilename=""; + $("#curfilename").text(""); }); - $("#btn_edit_file").click(function(event) { // EDIT - console.log("Not Run"); - $('#myModal').foundation('reveal', 'close'); - curFile = ""; - curFilename=""; - $("#curfilename").text(""); + $("#btn_prev_file").click(function(event) { // ADVANCED + console.log("Advanced - curFilename"); + $('#myModal').foundation('reveal', 'close'); + fabmo.clearJobQueue(function (err, data) { + if (err) { + cosole.log(err); + } else { + job = curFilename.replace('.sbp', ''); + fabmo.submitJob({ + file: curFile, + filename: curFilename, + name: job, + description: '... called from Sb4' + }); + } + }); }); // ** STATUS: Report Ongoing and Clear Command Line after a status report is recieved ## Need a clear after esc too fabmo.on('status', function(status) { console.log(status.state); +console.log(status.nb_lines) + const dispLen = 50; let lineDisplay = ""; - if (status.nb_lines > 0) { // If we're running a file ... - lineDisplay = "Running: " + curFilename + '\n' - //lineDisplay += "-----------------------------------" + '\n' - lineDisplay += " " + (status.line - 2) + " " + lines[status.line - 2] + '\n' - lineDisplay += " " + (status.line - 1) + " " + lines[status.line - 1] + '\n' - lineDisplay += "> " + status.line + " " + lines[status.line] + '\n' - lineDisplay += " " + (status.line + 1) + " " + lines[status.line + 1] + '\n' - lineDisplay += " " + (status.line + 2) + " " + lines[status.line + 2] + '\n' + if (status.nb_lines > 1) { // If we're running a file ... greater than 1 to cover 2 commands in MS + lineDisplay ="=======Running: " + curFilename + '\n' + lineDisplay += " " + (status.line - 2) + " " + lines[status.line - 2].substring(0, dispLen) + '\n' + lineDisplay += " " + (status.line - 1) + " " + lines[status.line - 1].substring(0, dispLen) + '\n' + lineDisplay += "> " + status.line + " " + lines[status.line].substring(0, dispLen) + '\n' + lineDisplay += " " + (status.line + 1) + " " + lines[status.line + 1].substring(0, dispLen) + '\n' + lineDisplay += " " + (status.line + 2) + " " + lines[status.line + 2].substring(0, dispLen) + '\n' $("#txt_area").text(lineDisplay); $('#cmd-input').val('>'); } @@ -259,7 +259,6 @@ $(document).ready(function() { $('#cmd-input').val(""); $("#txt_area").text(""); updateSpeedsFromEngineConfig(); - $(".top-bar").click(); // ... and click to clear any dropdowns $("#cmd-input").focus(); // ... and reset focus } @@ -280,26 +279,36 @@ $(document).ready(function() { $("#cmd-input").focus(); // ... and reset focus }); + //... this only helps a little with focus + $(document).mouseenter(function(e){ + // Check if click was triggered on or within #menu_content +console.log("MOUSE-ENTER") + // if( $(e.target).closest("#speed-panel").length > 0 ) { + // return false; + // } else if($(e.target).closest("#speed-panel").length > 0) { + // return false; + // } + $("#cmd-input").focus(); // ... and reset focus + }); + // ** Process Macro Box Keys $("#cut_part_call").click(function(event) { - curFile=""; // ... clear out after running curFilename = ""; $("#curfilename").text(""); $('#file').val(''); - - $('#file').trigger('click'); }); + $("#first_macro_button").click(function(event) { console.log('got firstMacro'); sendCmd("C3"); }); + $("#second_macro_button").click(function(event) { console.log('got secondMacro'); sendCmd("C2"); }); - // Just for testing stuff ... $("#other").click(function() { @@ -308,7 +317,10 @@ $(document).ready(function() { event.preventDefault(); }); - //console.log("Speed is: " + speed_XY.toFixed(2)); - //console.log("Twice the speed is: " + (2*speed_XY).toFixed(2)); - }); + fabmo.requestStatus(function(err,status) { // first call to get us started + console.log('G2_first_state>' + status.state); + }); + + +}); \ No newline at end of file diff --git a/js/lib/fabmo.js b/js/lib/fabmo.js index 923af3d..dc6477d 100644 --- a/js/lib/fabmo.js +++ b/js/lib/fabmo.js @@ -41,12 +41,66 @@ var FabMoDashboard = function(options) { }; this._setupMessageListener(); // listen for escape key press to quit the engine - document.onkeyup = function (e) { - if(e.keyCode == 27) { + document.onkeydown = function (e) { + if(e.keyCode === 27) { console.warn("ESC key pressed - quitting engine."); this.stop(); + } else if (e.keyCode === 75 && e.ctrlKey ) { + this.manualEnter() + } + }.bind(this); + + function detectswipe(func) { + swipe_det = new Object(); + swipe_det.sX = 0; swipe_det.sY = 0; swipe_det.eX = 0; swipe_det.eY = 0; + var max_x = 80; //max x difference for vertical swipe + var min_y = 100; //min y swipe for vertical swipe + var swipe = true; + var maxSwipeTime = 300; + var direc = ""; + var swipeTime; + ele = window.document; + function startSwipeTime() { + swipeTime = setTimeout(function(){ + swipe = false; + }, maxSwipeTime); + }; + + ele.addEventListener('touchstart',function(e){ + startSwipeTime(); + var t = e.touches[0]; + swipe_det.sX = t.screenX; + swipe_det.sY = t.screenY; + },false); + ele.addEventListener('touchmove',function(e){ + var t = e.touches[0]; + swipe_det.eX = t.screenX; + swipe_det.eY = t.screenY; + },false); + ele.addEventListener('touchend',function(e){ + //vertical detection + if ((((swipe_det.eY - min_y > swipe_det.sY) || (swipe_det.eY + min_y < swipe_det.sY)) && ((swipe_det.eX < swipe_det.sX + max_x) && (swipe_det.sX > swipe_det.eX - max_x) && (swipe_det.eY > 0) && swipe))) { + clearTimeout(swipeTime); + if(swipe_det.eY < swipe_det.sY) direc = "u"; + else direc = "d"; + } + + if (direc != "") { + if(typeof func == 'function') func(direc); + } + direc = ""; + swipe_det.sX = 0; swipe_det.sY = 0; swipe_det.eX = 0; swipe_det.eY = 0; swipe = true; + + },false); + } + + myfunction = function (d) { + if(d === "u") { + this.manualEnter(); } - }.bind(this); + }.bind(this); + + detectswipe(myfunction); if(!this.options.defer) { this.ready(); @@ -164,6 +218,7 @@ FabMoDashboard.prototype._download = function(data, strFileName, strMimeType) { } // _download FabMoDashboard.prototype._call = function(name, data, callback) { + if(this.isPresent()) { message = {"call":name, "data":data} if(callback) { @@ -198,16 +253,7 @@ FabMoDashboard.prototype._simulateCall = function(name, data, callback) { } text.textContent = msg; showToaster(toast); - break; - - case "runGCode": - text.textContent = "GCode sent to tool: " + data; - showToaster(toast); - break; - - case "runSBP": - text.textContent = "OpenSBP sent to tool: " + data; - showToaster(toast); + callback(null, {}) break; case "showDRO": @@ -220,6 +266,16 @@ FabMoDashboard.prototype._simulateCall = function(name, data, callback) { showToaster(toaster); break; + case "runGCode": + text.textContent = "GCode sent to tool: " + data; + showToaster(toast); + break; + + case "runSBP": + text.textContent = "OpenSBP sent to tool: " + data; + showToaster(toast); + break; + default: text.textContent = name + " called."; showToaster(toast); @@ -356,8 +412,7 @@ FabMoDashboard.prototype.launchApp = function(id, args, callback) { FabMoDashboard.prototype.showDRO = function(callback) { this._call("showDRO", null, callback); } - -/** + /** * Hide the DRO (Digital ReadOut) in the dashboard if it is not already hidden. * * @method hideDRO @@ -368,6 +423,28 @@ FabMoDashboard.prototype.hideDRO = function(callback) { this._call("hideDRO", null, callback); } +/** + * Show the top nav bar + * + * @method showNav + * @param {function} callback Called once the nav has been displayed. + * @param {Error} callback.err Error object if there was an error. + */ +FabMoDashboard.prototype.showNav = function(callback) { + this._call("showNav", null, callback); +} + /** + * Hide the top nav bar + * + * @method hideNav + * @param {function} callback Called once the nav has been hidden. + * @param {Error} callback.err Error object if there was an error. + */ +FabMoDashboard.prototype.hideNav = function(callback) { + this._call("hideNav", null, callback); +} + + //Modal Functions FabMoDashboard.prototype.showModal = function(options, callback) { var callbacks = { @@ -477,8 +554,8 @@ function _makeJob(obj) { /** * Submit one or more jobs to the dashboard. * @param {Array|Object|jQuery} jobs A single job object, an array containing multiple job objects, or a jQuery object that points to a file type form input, or a form containing a file type input. - * @param {Object} [options] Options for job submission - * @todo Finish documenting this function + * @param {Object} [options] Options for job submission. Currently only accepts one option: `stayHere` which if true, will prevent the dashboard from jumping to the job manager when the job has been submitted. + * */ FabMoDashboard.prototype.submitJob = function(jobs, options, callback) { var args = {jobs : []}; @@ -677,6 +754,14 @@ FabMoDashboard.prototype.manualMoveFixed = function(axis, speed, distance, callb this._call("manualMoveFixed",{"axis":axis, "speed": speed, "dist":distance}, callback); } +/** + * Stream a raw gcode + * Tool must be in 'raw' manual mode for this to work. + */ +FabMoDashboard.prototype.manualRunGCode = function(code, callback) { + this._call("manualRunGCode",{"code": code}, callback); +} + /** * Start performing a manual move of the specified axis at the specified speed. * @@ -684,8 +769,17 @@ FabMoDashboard.prototype.manualMoveFixed = function(axis, speed, distance, callb * @param {Number} axis One of `x`,`y`,`z`,`a`,`b`,`c` * @param {Number} speed Speed in current tool units. Negative to move in the negative direction. */ -FabMoDashboard.prototype.manualStart = function(axis, speed) { - this._call("manualStart",{"axis":axis, "speed":speed}, callback); +FabMoDashboard.prototype.manualStart = function(axis, speed, second_axis, second_speed) { + this._call("manualStart",{"axis":axis, "speed":speed, "second_axis":second_axis, "second_speed":second_speed }, callback); +} + + +FabMoDashboard.prototype.manualEnter = function(options, callback) { + this._call("manualEnter",options, callback); +} + +FabMoDashboard.prototype.manualExit = function(axis, speed, callback) { + this._call("manualExit", callback); } /** @@ -1014,8 +1108,7 @@ var toaster = function () { } var showToaster = function (toaster) { toaster.style.visibility = 'visible'; - //*problem running just HTML - //setTimeout(function(){document.body.removeChild(toaster)}, 1000); + setTimeout(function(){document.body.removeChild(toaster)}, 1000); } return FabMoDashboard; diff --git a/js/sb_app.js b/js/sb_app.js index c85c21c..e706b5d 100644 --- a/js/sb_app.js +++ b/js/sb_app.js @@ -51,8 +51,8 @@ function getUsrResource(remote, local) { function postSbpAction(action) { setTimeout(function() { - $("#txt_area").text("Running:" + '\n' + " " + action); }, - 500); + $("#txt_area").text("-------Running:" + '\n' + " " + action); }, + 200); $('#cmd-input').val('>'); } @@ -196,4 +196,3 @@ function processCommandInput(command) { } return false } -