Commit ef1e6396 authored by Amanda Ghassaei's avatar Amanda Ghassaei

position data updating machine sate

parent 2310e25a
...@@ -91,3 +91,9 @@ span.outgoing { ...@@ -91,3 +91,9 @@ span.outgoing {
text-align: center; text-align: center;
padding-top: 20px; padding-top: 20px;
} }
.positionVal {
color: #7777FF;
font-size: 30px;
padding-left: 5px;
}
<div id="positionData"> <div id="positionData">
</div><br/> </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-default">Refresh Position</a><br/>
<a href="#" id="pauseOutput" 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> <a href="#" id="stopMachine" class="btn pull-right btn-block btn-lg btn-danger">Stop</a>
\ No newline at end of file
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Created by aghassaei on 9/11/15. * Created by aghassaei on 9/11/15.
*/ */
//this.model == serialComm
define(['jquery', 'underscore', 'backbone', 'text!PositionControlPanelView.html', 'text!PositionDataView.html'], define(['jquery', 'underscore', 'backbone', 'text!PositionControlPanelView.html', 'text!PositionDataView.html'],
function($, _, Backbone, template, positionTemplate){ function($, _, Backbone, template, positionTemplate){
...@@ -18,18 +19,28 @@ define(['jquery', 'underscore', 'backbone', 'text!PositionControlPanelView.html' ...@@ -18,18 +19,28 @@ define(['jquery', 'underscore', 'backbone', 'text!PositionControlPanelView.html'
initialize: function(){ initialize: function(){
this.listenTo(this.model.getMachineState(), "change", this._renderPositionData);
this.render(); this.render();
this._askForPosition();
}, },
_renderPositionData: function(){ _renderPositionData: function(){
var machineState = this.model.getMachineState(); var machineState = this.model.getMachineState();
if (machineState === null) { console.log(machineState.toJSON());
$("#positionData").html("<div id='positionDataError'>no position data available</div>");
return;
}
$("#positionData").html(_.template(positionTemplate)(machineState.toJSON())); $("#positionData").html(_.template(positionTemplate)(machineState.toJSON()));
}, },
_askForPosition: function(e){
if (e) e.preventDefault();
this.model.send('{"sr":n}');
},
_stopMachine: function(e){
e.preventDefault();
this.model.send("!");
},
_makeTemplateJSON: function(){ _makeTemplateJSON: function(){
return {}; return {};
}, },
......
X: <%= xAxis %><br/> X: &nbsp;&nbsp;<span class="positionVal"><%= x %></span><br/>
Y: <%= yAxis %><br/> Y: &nbsp;&nbsp;<span class="positionVal"><%= y %></span><br/>
Z: <%= zAxis %><br/><br/> Z: &nbsp;&nbsp;<span class="positionVal"><%= z %></span><br/><br/>
A: <%= aAxis %><br/> A: &nbsp;&nbsp;<span class="positionVal"><%= a %></span><br/>
B: <%= bAxis %><br/> B: &nbsp;&nbsp;<span class="positionVal"><%= b %></span><br/>
C: <%= cAxis %><br/> C: &nbsp;&nbsp;<span class="positionVal"><%= c %></span><br/>
\ No newline at end of file \ No newline at end of file
...@@ -102,7 +102,7 @@ define(['jquery', 'underscore', 'backbone', 'serialComm', 'text!SerialMonitorVie ...@@ -102,7 +102,7 @@ define(['jquery', 'underscore', 'backbone', 'serialComm', 'text!SerialMonitorVie
_addOutputData: function(html){ _addOutputData: function(html){
var $output = $("#serialMonitorOutput"); var $output = $("#serialMonitorOutput");
$output.append(html); $output.append(html);
if (this.model.get("autoscroll")) $output.animate({scrollTop:$output.scrollTop()+$output.innerHeight()}, "fast"); if (this.model.get("autoscroll")) $output.scrollTop($output.scrollTop()+$output.innerHeight());
}, },
_clear: function(e){ _clear: function(e){
......
...@@ -15,7 +15,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre ...@@ -15,7 +15,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
cellType: "cube", cellType: "cube",
connectionType: "gik", connectionType: "gik",
latticeType: "dnaBricks", latticeType: "willGik",
partType: null, partType: null,
aspectRatio: null, aspectRatio: null,
......
...@@ -36,7 +36,7 @@ define(['underscore', 'backbone', 'threeModel', 'three', 'plist', 'globals'], fu ...@@ -36,7 +36,7 @@ define(['underscore', 'backbone', 'threeModel', 'three', 'plist', 'globals'], fu
cellsVisible: true, cellsVisible: true,
superCellIndex: new THREE.Vector3(0,0,0),//offset of superCell adds superCellIndex: new THREE.Vector3(0,0,0),//offset of superCell adds
gikLength: 2,//this updates super cell range when using non-composite materials gikLength: 4,//this updates super cell range when using non-composite materials
superCellRange: new THREE.Vector3(1,1,1), superCellRange: new THREE.Vector3(1,1,1),
realisticColorScheme: false, realisticColorScheme: false,
......
...@@ -3,31 +3,34 @@ ...@@ -3,31 +3,34 @@
*/ */
define(['backbone'], function(Backbone){ define(['underscore', 'backbone'], function(_, Backbone){
var MachineState = Backbone.Model.extend({ var MachineState = Backbone.Model.extend({
defaults:{ defaults:{
xAxis: null, x: null,
yAxis: null, y: null,
zAxis: null, z: null,
aAxis: null, a: null,
bAxis: null, b: null,
cAxis: null c: null
}, },
destroy: function(){ setPosition: function(data){
this.set("xAxis", null, {silent:true}); var self = this;
this.set("yAxis", null, {silent:true}); _.each(this.attributes, function(attribute, key){
this.set("zAxis", null, {silent:true}); var val = data["pos" + key];
this.set("aAxis", null, {silent:true}); if (val !== null && val !== undefined) self.set(key, val);
this.set("bAxis", null, {silent:true}); });
this.set("cAxis", null, {silent:true}); },
refresh: function(){
this.set(this.defaults);
} }
}); });
return MachineState; return new MachineState();
}); });
\ No newline at end of file
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* Created by aghassaei on 6/17/15. * Created by aghassaei on 6/17/15.
*/ */
define(['underscore', 'backbone', 'socketio', 'machineState'], function(_, Backbone, io, MachineState){ define(['underscore', 'backbone', 'socketio', 'machineState'], function(_, Backbone, io, machineState){
var SerialComm = Backbone.Model.extend({ var SerialComm = Backbone.Model.extend({
...@@ -19,7 +19,7 @@ define(['underscore', 'backbone', 'socketio', 'machineState'], function(_, Backb ...@@ -19,7 +19,7 @@ define(['underscore', 'backbone', 'socketio', 'machineState'], function(_, Backb
}, },
initialize: function(){ initialize: function(){
this.machineState = null; this.machineState = machineState;
this.attemptToConnectToNode(); this.attemptToConnectToNode();
}, },
...@@ -61,8 +61,7 @@ define(['underscore', 'backbone', 'socketio', 'machineState'], function(_, Backb ...@@ -61,8 +61,7 @@ define(['underscore', 'backbone', 'socketio', 'machineState'], function(_, Backb
}, },
refreshMachineState: function(){//when updating connection, create a new instance of machine state refreshMachineState: function(){//when updating connection, create a new instance of machine state
if (this.machineState) this.machineState.destroy(); this.machineState.refresh();
this.machineState = new MachineState();
}, },
getMachineState: function(){ getMachineState: function(){
...@@ -101,6 +100,14 @@ define(['underscore', 'backbone', 'socketio', 'machineState'], function(_, Backb ...@@ -101,6 +100,14 @@ define(['underscore', 'backbone', 'socketio', 'machineState'], function(_, Backb
if (data == "" || data == '\n' || data == "\r") return; if (data == "" || data == '\n' || data == "\r") return;
serialComm.set("lastMessageReceived", data, {silent:true}); serialComm.set("lastMessageReceived", data, {silent:true});
serialComm.trigger("change:lastMessageReceived"); serialComm.trigger("change:lastMessageReceived");
try {
var json = JSON.parse(data);
if (json.r && json.r.sr){
serialComm.getMachineState().setPosition(json.r.sr);
} else if (json.sr){
serialComm.getMachineState().setPosition(json.sr);
}
} catch(err) {}
}); });
socket.on('dataSent', function(data){ socket.on('dataSent', function(data){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment