Commit ef1e6396 authored by Amanda Ghassaei's avatar Amanda Ghassaei

position data updating machine sate

parent 2310e25a
......@@ -91,3 +91,9 @@ span.outgoing {
text-align: center;
padding-top: 20px;
}
.positionVal {
color: #7777FF;
font-size: 30px;
padding-left: 5px;
}
<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-default">Refresh Position</a><br/>
<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
......@@ -2,6 +2,7 @@
* Created by aghassaei on 9/11/15.
*/
//this.model == serialComm
define(['jquery', 'underscore', 'backbone', 'text!PositionControlPanelView.html', 'text!PositionDataView.html'],
function($, _, Backbone, template, positionTemplate){
......@@ -18,18 +19,28 @@ define(['jquery', 'underscore', 'backbone', 'text!PositionControlPanelView.html'
initialize: function(){
this.listenTo(this.model.getMachineState(), "change", this._renderPositionData);
this.render();
this._askForPosition();
},
_renderPositionData: function(){
var machineState = this.model.getMachineState();
if (machineState === null) {
$("#positionData").html("<div id='positionDataError'>no position data available</div>");
return;
}
console.log(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(){
return {};
},
......
X: <%= xAxis %><br/>
Y: <%= yAxis %><br/>
Z: <%= zAxis %><br/><br/>
A: <%= aAxis %><br/>
B: <%= bAxis %><br/>
C: <%= cAxis %><br/>
\ No newline at end of file
X: &nbsp;&nbsp;<span class="positionVal"><%= x %></span><br/>
Y: &nbsp;&nbsp;<span class="positionVal"><%= y %></span><br/>
Z: &nbsp;&nbsp;<span class="positionVal"><%= z %></span><br/><br/>
A: &nbsp;&nbsp;<span class="positionVal"><%= a %></span><br/>
B: &nbsp;&nbsp;<span class="positionVal"><%= b %></span><br/>
C: &nbsp;&nbsp;<span class="positionVal"><%= c %></span><br/>
\ No newline at end of file
......@@ -102,7 +102,7 @@ define(['jquery', 'underscore', 'backbone', 'serialComm', 'text!SerialMonitorVie
_addOutputData: function(html){
var $output = $("#serialMonitorOutput");
$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){
......
......@@ -15,7 +15,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
cellType: "cube",
connectionType: "gik",
latticeType: "dnaBricks",
latticeType: "willGik",
partType: null,
aspectRatio: null,
......
......@@ -36,7 +36,7 @@ define(['underscore', 'backbone', 'threeModel', 'three', 'plist', 'globals'], fu
cellsVisible: true,
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),
realisticColorScheme: false,
......
......@@ -3,31 +3,34 @@
*/
define(['backbone'], function(Backbone){
define(['underscore', 'backbone'], function(_, Backbone){
var MachineState = Backbone.Model.extend({
defaults:{
xAxis: null,
yAxis: null,
zAxis: null,
aAxis: null,
bAxis: null,
cAxis: null
x: null,
y: null,
z: null,
a: null,
b: null,
c: null
},
destroy: function(){
this.set("xAxis", null, {silent:true});
this.set("yAxis", null, {silent:true});
this.set("zAxis", null, {silent:true});
this.set("aAxis", null, {silent:true});
this.set("bAxis", null, {silent:true});
this.set("cAxis", null, {silent:true});
setPosition: function(data){
var self = this;
_.each(this.attributes, function(attribute, key){
var val = data["pos" + key];
if (val !== null && val !== undefined) self.set(key, val);
});
},
refresh: function(){
this.set(this.defaults);
}
});
return MachineState;
return new MachineState();
});
\ No newline at end of file
......@@ -2,7 +2,7 @@
* 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({
......@@ -19,7 +19,7 @@ define(['underscore', 'backbone', 'socketio', 'machineState'], function(_, Backb
},
initialize: function(){
this.machineState = null;
this.machineState = machineState;
this.attemptToConnectToNode();
},
......@@ -61,8 +61,7 @@ define(['underscore', 'backbone', 'socketio', 'machineState'], function(_, Backb
},
refreshMachineState: function(){//when updating connection, create a new instance of machine state
if (this.machineState) this.machineState.destroy();
this.machineState = new MachineState();
this.machineState.refresh();
},
getMachineState: function(){
......@@ -101,6 +100,14 @@ define(['underscore', 'backbone', 'socketio', 'machineState'], function(_, Backb
if (data == "" || data == '\n' || data == "\r") return;
serialComm.set("lastMessageReceived", data, {silent:true});
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){
......
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