diff --git a/js/SerialMonitor/PositionControlPanelView.html b/js/SerialMonitor/PositionControlPanelView.html index 15f398bb68526c3f332aaf7b88fca03cacf65c04..2d2e2df18b6a6a7e2047e7d91b8b4d5b62ce8684 100644 --- a/js/SerialMonitor/PositionControlPanelView.html +++ b/js/SerialMonitor/PositionControlPanelView.html @@ -1,5 +1,5 @@ <div id="positionData"> </div><br/> <a href="#" id="askForPosition" class="btn btn-block btn-lg btn-default">Refresh</a> -<a href="#" id="askForPosition" class="btn btn-block btn-lg btn-warning">Pause</a> +<a href="#" id="pauseOutput" class="btn btn-block btn-lg btn-warning">Pause</a> <a href="#" id="stopMachine" class="btn pull-right btn-block btn-lg btn-danger">Stop</a> \ No newline at end of file diff --git a/js/SerialMonitor/PositionControlPanelView.js b/js/SerialMonitor/PositionControlPanelView.js index 511318a5ea387b38415916e1ac2c07af71521ed0..60775b9040ddf94272dea77a165f1e8a71d88978 100644 --- a/js/SerialMonitor/PositionControlPanelView.js +++ b/js/SerialMonitor/PositionControlPanelView.js @@ -11,7 +11,9 @@ define(['jquery', 'underscore', 'backbone', 'text!PositionControlPanelView.html' el: "#positionPanel", events: { - + "click #stopMachine": "_stopMachine", + "click #pauseOutput": "_pause", + "click #askForPosition": "_askForPosition" }, @@ -21,7 +23,6 @@ define(['jquery', 'underscore', 'backbone', 'text!PositionControlPanelView.html' _renderPositionData: function(){ var machineState = this.model.getMachineState(); - console.log(machineState); if (machineState === null) { $("#positionData").html("<div id='positionDataError'>no position data available</div>"); return; @@ -38,7 +39,7 @@ define(['jquery', 'underscore', 'backbone', 'text!PositionControlPanelView.html' this._renderPositionData(); }, - template: _.template(template), + template: _.template(template) }); diff --git a/js/SerialMonitor/SerialMonitorView.js b/js/SerialMonitor/SerialMonitorView.js index 40f3ddab0f2a4119c4757bae78341d33fbb0e00b..fcebe94facbf54cde08e2ccdf7de3ab37d4b52f4 100644 --- a/js/SerialMonitor/SerialMonitorView.js +++ b/js/SerialMonitor/SerialMonitorView.js @@ -3,27 +3,24 @@ */ -define(['jquery', 'underscore', 'commParentMenu', 'serialComm', 'text!SerialMonitorView.html'], - function($, _, CommParentMenu, serialComm, template){ +define(['jquery', 'underscore', 'backbone', 'serialComm', 'text!SerialMonitorView.html'], + function($, _, Backbone, serialComm, template){ - return CommParentMenu.extend({ + return Backbone.View.extend({ el: "#serialMonitorView", - parentEvents: { - }, - events: { "click #clearMonitor": "_clear", "change input:checkbox": "_clickCheckbox" }, - __initialize: function(){ + initialize: function(){ _.bindAll(this, "_onKeyUp"); $(document).bind('keyup', {}, this._onKeyUp); - + 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:connected", function(){ @@ -79,6 +76,14 @@ define(['jquery', 'underscore', 'commParentMenu', 'serialComm', 'text!SerialMoni } }, + _sendMessage: function(e){ + e.preventDefault(); + var message = $("#sendSerialMessage").val(); + $("#sendSerialMessage").val(""); + if (message == "") return; + serialComm.send(message); + }, + _makeTemplateJSON: function(){ return this.model.toJSON(); }, @@ -101,14 +106,18 @@ define(['jquery', 'underscore', 'commParentMenu', 'serialComm', 'text!SerialMoni _clear: function(e){ e.preventDefault(); - this.render(); + $("#serialMonitorOutput").html(""); }, _close: function(){ - this.userInitedReload = false; window.close(); }, + render: function(){ + if ($("input[type=text]").is(":focus")) return; + this.$el.html(this.template(this._makeTemplateJSON())); + }, + template: _.template(template) }); diff --git a/js/cam/Cam.js b/js/cam/Cam.js index 23fe573781183255da6f3e165524d876f858b7f8..a6563ab656354233e1206d5e65d7f745409df6d8 100644 --- a/js/cam/Cam.js +++ b/js/cam/Cam.js @@ -299,7 +299,6 @@ define(['underscore', 'three', 'backbone', 'appState', 'latticeCAM', 'threeModel scaledSettings, function(){ currentLine++; self.set("simLineNumber", currentLine); - console.log(self); self._stockSimulation(); }); } else { diff --git a/js/menus/SendMenuView.js b/js/menus/SendMenuView.js index a4d1e807f0db139b9d50e5486720514a2cbc4882..feea3546b30257e422223a32021cc64cf39b4a09 100644 --- a/js/menus/SendMenuView.js +++ b/js/menus/SendMenuView.js @@ -18,32 +18,28 @@ define(['jquery', 'underscore', 'menuParent', 'serialComm', 'commPlist', 'text!s }, - __initialize: function(){ - this.isStreaming = false; + _initialize: function(){ this.listenTo(this.model, "change:stockSimulationPlaying", this.render); + this.listenTo(serialComm, "change:isStreaming", this.render); this.listenTo(cam, "change:simLineNumber", this._drawGcodeHighlighter); }, _startStream: function(e){ e.preventDefault(); this.model.set("stockSimulationPlaying", true); - this.isStreaming = true; - this.render(); + serialComm.startStream(); }, _pauseStream: function(e){ e.preventDefault(); this.model.set("stockSimulationPlaying", false); - this.isStreaming = false; - this.render(); + serialComm.pauseStream(); }, _stopMachine: function(e){ e.preventDefault(); this.model.set("stockSimulationPlaying", false); - this.isStreaming = false; - serialComm.send("!"); - this.render(); + serialComm.stopStream(); }, _decrementLineNum: function(e){ @@ -63,7 +59,6 @@ define(['jquery', 'underscore', 'menuParent', 'serialComm', 'commPlist', 'text!s _drawGcodeHighlighter: function(){ var lineNum = cam.get("simLineNumber"); - console.log(lineNum); if (lineNum == 0) return; var code = cam.get("dataOut").split("\n"); code[lineNum] = "<span id='gcodeHighlighter'>" + code[lineNum] + " </span>"; @@ -78,7 +73,7 @@ define(['jquery', 'underscore', 'menuParent', 'serialComm', 'commPlist', 'text!s }, _makeTemplateJSON: function(){ - return _.extend(serialComm.toJSON(), commPlist, cam.toJSON(), camPlist, {streaming: this.isStreaming}); + return _.extend(serialComm.toJSON(), commPlist, cam.toJSON(), camPlist); }, _render: function(){ diff --git a/js/menus/templates/SendMenuView.html b/js/menus/templates/SendMenuView.html index 010546f9c576c123527a8ae9b94d8d4f9b782f4d..c7f271af6f91898f08ef6843b2d2cfe68c154cf4 100644 --- a/js/menus/templates/SendMenuView.html +++ b/js/menus/templates/SendMenuView.html @@ -2,7 +2,7 @@ <% if(dataOut==0){ %> You need to go through the Assemble workflow to setup your machine and create <%= allCamProcesses[camProcess] %> first. <% }else{ %> - <% if(streaming){ %> + <% if(isStreaming){ %> <a href="#" id="pauseStream" class="btn btn-halfWidth btn-lg btn-warning">Pause</a> <a href="#" id="stopMachine" class="btn pull-right btn-halfWidth btn-lg btn-danger">Stop</a><br/> <% }else{ %> diff --git a/js/models/SerialComm.js b/js/models/SerialComm.js index 806fe8c2b5ace727d74590d1b1f9cc1c74b58bb1..4bd02eeaa0367e2d53cfc6a2e4a8e325fe08d65b 100644 --- a/js/models/SerialComm.js +++ b/js/models/SerialComm.js @@ -14,7 +14,8 @@ define(['underscore', 'backbone', 'socketio', 'machineState'], function(_, Backb baudRate: 200, error: null, lastMessageReceived: null, - lastMessageSent: "" + lastMessageSent: "", + isStreaming: false }, initialize: function(){ @@ -47,6 +48,18 @@ define(['underscore', 'backbone', 'socketio', 'machineState'], function(_, Backb this.socket.emit("flush"); }, + startStream: function(){ + this.socket.emit("startStream"); + }, + + pauseStream: function(){ + this.socket.emit("pauseStream"); + }, + + stopStream: function(){ + this.socket.emit("stopStream"); + }, + refreshMachineState: function(){//when updating connection, create a new instance of machine state if (this.machineState) this.machineState.destroy(); this.machineState = new MachineState(); @@ -97,6 +110,11 @@ define(['underscore', 'backbone', 'socketio', 'machineState'], function(_, Backb serialComm.trigger("change:lastMessageSent"); }); + socket.on('isStreaming', function(data){ + console.log(data); + serialComm.set("isStreaming", data); + }); + socket.on('portConnected', function(data){ console.log("connected port " + data.portName + " at " + data.baudRate); serialComm.set("baudRate", data.baudRate); diff --git a/node/nodeServer.js b/node/nodeServer.js index 2e2f469652bb9b2ff07b60febdaf8f94c8109aaa..ef7ce05315d04fe37d8fdb2abae3e9b9f8db10e1 100644 --- a/node/nodeServer.js +++ b/node/nodeServer.js @@ -19,6 +19,7 @@ var io = require('socket.io').listen(8080); var portName = null; var currentPort = null; var baudRate = 115200; +var isStreaming = false; //io.sockets.on('connection', function (socket) { // io.emit('baudRate', baudRate); @@ -50,6 +51,10 @@ io.on('connection', function(socket){ }); socket.on('dataOut', function(data){ + outputData(data); + }); + + function outputData(data){ io.emit('dataSent', data); data += '\n'; console.log("Sending data: " + data); @@ -57,7 +62,7 @@ io.on('connection', function(socket){ if (err) onPortError(err); }); // currentPort.write(new Buffer([parseInt(data)]));//write byte - }); + } socket.on('flush', function(){ if (currentPort) currentPort.flush(function(){ @@ -70,6 +75,25 @@ io.on('connection', function(socket){ allPorts = refreshAvailablePorts(); }); + socket.on('stopStream', function(){ + outputData("!"); + setIsStreaming(false); + }); + + socket.on('startStream', function(){ + setIsStreaming(true); + }); + + socket.on('pauseStream', function(){ + setIsStreaming(false); + }); + + function setIsStreaming(state){ + if (state == isStreaming) return; + isStreaming = state; + io.emit('isStreaming', isStreaming); + } + function checkThatPortExists(_portName){ if (allPorts.indexOf(_portName) < 0) { onPortError("no available port called " + _portName);