diff --git a/js/SerialMonitor/appState.js b/js/SerialMonitor/appState.js new file mode 100644 index 0000000000000000000000000000000000000000..052883c549b4e56d3bfa37d70f9bba94c73dbe10 --- /dev/null +++ b/js/SerialMonitor/appState.js @@ -0,0 +1,8 @@ +/** + * Created by aghassaei on 10/22/15. + */ + + +define([], function(){ + return {}; +}); \ No newline at end of file diff --git a/js/SerialMonitor/lattice.js b/js/SerialMonitor/lattice.js new file mode 100644 index 0000000000000000000000000000000000000000..052883c549b4e56d3bfa37d70f9bba94c73dbe10 --- /dev/null +++ b/js/SerialMonitor/lattice.js @@ -0,0 +1,8 @@ +/** + * Created by aghassaei on 10/22/15. + */ + + +define([], function(){ + return {}; +}); \ No newline at end of file diff --git a/js/models/SerialComm.js b/js/models/SerialComm.js index a1ed3c9f2de6033b00d6450a615c5e9ad17327d3..32e4384ad6a4cabe178912057132d3912d1bd112 100644 --- a/js/models/SerialComm.js +++ b/js/models/SerialComm.js @@ -2,8 +2,10 @@ * Created by aghassaei on 6/17/15. */ -define(['underscore', 'backbone', 'socketio', 'machineState', 'cam'], - function(_, Backbone, io, machineState, cam){ +//todo get cam, lattice, appstate out of here + +define(['underscore', 'backbone', 'socketio', 'machineState', 'cam', 'lattice', 'appState'], + function(_, Backbone, io, machineState, cam, lattice, appState){ var SerialComm = Backbone.Model.extend({ @@ -23,9 +25,14 @@ define(['underscore', 'backbone', 'socketio', 'machineState', 'cam'], initialize: function(){ this.machineState = machineState; this.listenTo(machineState, "change", this._updateVirtualMachine); + if (appState.get) this.listenTo(appState, "change:currentNav", this._navChanged); this.attemptToConnectToNode(); }, + _navChanged: function(){ + if (appState.previous("currentNav") == "navComm") lattice.showCells("cells"); + }, + attemptToConnectToNode: function(){ if (!this.get("connected")) { this.socket = io.connect('http://localhost:8080', {'forceNew':true}); @@ -75,8 +82,16 @@ define(['underscore', 'backbone', 'socketio', 'machineState', 'cam'], if (machineState && machineState.isReadyStatus()){ var lineNum = cam.get("simLineNumber"); var allLines = cam.get("dataOut").split("\n"); + if (lineNum == 0) lattice.hideCells("cells"); if (lineNum >= 0 && lineNum < allLines.length) { var line = allLines[lineNum]; + + if (line.substr(0,2) == "({"){ + var index = line.substr(1,line.length-2); + index = JSON.parse(index); + lattice.showCellAtIndex(index); + } + self.listenToOnce(machineState, "readyForNextCommand", function(){ lineNum ++; cam.set("simLineNumber", lineNum);