From 196f34dd34849bc74ca0a4d18121b1a7ceeb99f8 Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Thu, 17 Sep 2015 13:45:59 -0400
Subject: [PATCH] trigger event when ready for next line

---
 js/SerialMonitor/PositionControlPanelView.js |  1 -
 js/SerialMonitor/SerialMonitorView.js        |  2 --
 js/models/MachineState.js                    | 10 +++++++++-
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/js/SerialMonitor/PositionControlPanelView.js b/js/SerialMonitor/PositionControlPanelView.js
index 6b7016bb..c3859e32 100644
--- a/js/SerialMonitor/PositionControlPanelView.js
+++ b/js/SerialMonitor/PositionControlPanelView.js
@@ -27,7 +27,6 @@ define(['jquery', 'underscore', 'backbone', 'text!PositionControlPanelView.html'
 
         _renderPositionData: function(){
             var machineState = this.model.getMachineState();
-            console.log(machineState.toJSON());
             $("#positionData").html(_.template(positionTemplate)(machineState.toJSON()));
         },
 
diff --git a/js/SerialMonitor/SerialMonitorView.js b/js/SerialMonitor/SerialMonitorView.js
index 688066a4..9ab4e882 100644
--- a/js/SerialMonitor/SerialMonitorView.js
+++ b/js/SerialMonitor/SerialMonitorView.js
@@ -23,7 +23,6 @@ define(['jquery', 'underscore', 'backbone', 'serialComm', 'text!SerialMonitorVie
             this.listenTo(serialComm, "change:lastMessageReceived", this._updateIncomingMessage);
             this.listenTo(serialComm, "change:lastMessageSent", this._updateOutgoingMessage);
             this.listenTo(serialComm, "change:baudRate change:portName", this.render);
-            this.listenTo(serialComm, "change:baudRate", function(){console.log("got it")});
             this.listenTo(serialComm, "change:connected", function(){
                 if (!serialComm.get("connected")) this._close();
             });
@@ -115,7 +114,6 @@ define(['jquery', 'underscore', 'backbone', 'serialComm', 'text!SerialMonitorVie
         },
 
         render: function(){
-            console.log("render");
             if ($("input[type=text]").is(":focus")) return;
             this.$el.html(this.template(this._makeTemplateJSON()));
         },
diff --git a/js/models/MachineState.js b/js/models/MachineState.js
index fb7a1274..c1484ae4 100644
--- a/js/models/MachineState.js
+++ b/js/models/MachineState.js
@@ -23,15 +23,23 @@ define(['underscore', 'backbone'], function(_, Backbone){
                 var val = data["pos" + key];
                 if (val !== null && val !== undefined) self.set(key, val);
             });
-            if (data.stat !== null && data.stat !== undefined) this.set("status", data.stat);
+            if (data.stat !== null && data.stat !== undefined) {
+                this.set("status", data.stat);
+                if (data.stat == 1 || data.stat == 3 || data.stat == 4) this._triggerNextCommand();
+            }
         },
 
         setFooterStatus: function(data){
             if (data[1] == 0){//ok status
                 this.set("status", 3);
+                this._triggerNextCommand();
             } else this.set("status", 10);
         },
 
+        _triggerNextCommand: function(){
+            this.trigger("readyForNextCommand");
+        },
+
         refresh: function(){
             this.set(this.defaults);
         }
-- 
GitLab