From 61dd3e4802f0fa7c0533ef03e1ea70de685cd87b Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Wed, 22 May 2013 21:34:00 -0400 Subject: [PATCH] updates for newest makerbot gcode add fix for unrecognized gcode objects add alert for failure to save model to localstorage --- web/gcode-model.js | 42 +++++++++++++++++++++++++++++++++++++++++- web/gcode-parser.js | 9 ++++++--- web/ui.js | 8 ++++++-- 3 files changed, 53 insertions(+), 6 deletions(-) diff --git a/web/gcode-model.js b/web/gcode-model.js index 527df3c..0154ed5 100644 --- a/web/gcode-model.js +++ b/web/gcode-model.js @@ -75,6 +75,10 @@ function createObjectFromGCode(gcode) { // happens from the current extruded length to a length of // 22.4 mm. + /* newer makerbot gcode uses A instead of E on G1 */ + if (args.a && !args.e) { + args.e = args.a; + } var newLine = { x: args.x !== undefined ? absolute(lastLine.x, args.x) : lastLine.x, y: args.y !== undefined ? absolute(lastLine.y, args.y) : lastLine.y, @@ -136,6 +140,22 @@ function createObjectFromGCode(gcode) { lastLine = newLine; }, + G130: function(args) { + // G130: MakerBot Set Stepper Motor VRef to defaults + }, + + G161: function(args) { + // G161: MakerBot Home Z Axis + }, + + G162: function(args) { + // G162: MakerBot Home XY Axis + }, + + M73: function(args) { + // M73: MakerBot Progress Meter Info + }, + M82: function(args) { // M82: Set E codes absolute (default) // Descriped in Sprintrun source code. @@ -155,8 +175,28 @@ function createObjectFromGCode(gcode) { // No-op }, + M126: function(args) { + // M126: MakerBot Turn On Fan + }, + + M127: function(args) { + // M127: MakerBot Turn Off Fan + }, + + M132: function(args) { + // M132: MakerBot Recall Stored Offsets + }, + + M136: function(args) { + // M136: MakerBot Build Begin + }, + + M137: function(args) { + // M136: MakerBot Build End + }, + 'default': function(args, info) { - console.error('Unknown command:', args.cmd, args, info); + console.log('Unknown command:', args.cmd, args, info); }, }); diff --git a/web/gcode-parser.js b/web/gcode-parser.js index 0e28942..8ec7085 100644 --- a/web/gcode-parser.js +++ b/web/gcode-parser.js @@ -11,6 +11,7 @@ function GCodeParser(handlers) { GCodeParser.prototype.parseLine = function(text, info) { text = text.replace(/;.*$/, '').trim(); // Remove comments + text = text.replace(/^\(.*\)$/, '').trim(); // Remove MakeBot layer info if (text) { var tokens = text.split(' '); if (tokens) { @@ -19,9 +20,11 @@ GCodeParser.prototype.parseLine = function(text, info) { 'cmd': cmd }; tokens.splice(1).forEach(function(token) { - var key = token[0].toLowerCase(); - var value = parseFloat(token.substring(1)); - args[key] = value; + if (token[0]) { + var key = token[0].toLowerCase(); + var value = parseFloat(token.substring(1)); + args[key] = value; + } }); var handler = this.handlers[tokens[0]] || this.handlers['default']; if (handler) { diff --git a/web/ui.js b/web/ui.js index b65caa9..068e54e 100644 --- a/web/ui.js +++ b/web/ui.js @@ -38,8 +38,12 @@ function openGCodeFromText(gcode) { } object = createObjectFromGCode(gcode); scene.add(object); - localStorage.setItem('last-imported', gcode); - localStorage.removeItem('last-loaded'); + try { + localStorage.setItem('last-imported', gcode); + localStorage.removeItem('last-loaded'); + } catch (e) { + alert('error storing model: '+e); + } }