Commit 0ac16c40 authored by Amanda Ghassaei's avatar Amanda Ghassaei
Browse files

machine state model will grab position infor from machine

parent 529e954d
...@@ -73,10 +73,12 @@ span.outgoing { ...@@ -73,10 +73,12 @@ span.outgoing {
} }
#positionPanel { #positionPanel {
padding: 20px 30px;
width: 300px; width: 300px;
height: 100%; height: 100%;
background-color: red; background-color: red;
border-left: 2px solid #bdc3c7; border-left: 2px solid #bdc3c7;
background-color: #fdfdfd; background-color: #fdfdfd;
display: inline-block; display: inline-block;
font-size: 30px;
} }
\ No newline at end of file
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
/**
* Created by aghassaei on 9/11/15.
*/
define(['jquery', 'underscore', 'backbone', 'text!PositionControlPanelView.html'], function($, _, Backbone, template){
return Backbone.View.extend({
el: "#positionPanel",
events: {
},
initialize: function(){
this.render();
},
_makeTemplateJSON: function(){
console.log(this.model);
var machineState = this.model.getMachineState();
if (machineState === null) return {};
return machineState.toJSON();
},
render: function(){
this.$el.html(this.template(this._makeTemplateJSON()));
},
template: _.template(template)
});
});
\ No newline at end of file
...@@ -15,12 +15,14 @@ require.config({ ...@@ -15,12 +15,14 @@ require.config({
serialMonitor: 'SerialMonitor', serialMonitor: 'SerialMonitor',
serialMonitorView: 'SerialMonitorView', serialMonitorView: 'SerialMonitorView',
positionControlPanelView: 'PositionControlPanelView',
menuParent: '../menus/MenuParentView', menuParent: '../menus/MenuParentView',
commParentMenu: '../menus/CommParentMenu', commParentMenu: '../menus/CommParentMenu',
plist: '../plists/PList', plist: '../plists/PList',
commPlist: '../plists/commPlist', commPlist: '../plists/commPlist',
serialComm: '../models/SerialComm' serialComm: '../models/SerialComm',
machineState: '../models/MachineState'
}, },
...@@ -35,6 +37,8 @@ require.config({ ...@@ -35,6 +37,8 @@ require.config({
}); });
require(['serialMonitorView', 'serialMonitor'], function(SerialMonitorView, serialMonitor){ require(['serialMonitorView', 'serialMonitor', 'positionControlPanelView', 'serialComm'],
function(SerialMonitorView, serialMonitor, PositionControlPanelView, serialComm){
new SerialMonitorView({model: serialMonitor}); new SerialMonitorView({model: serialMonitor});
new PositionControlPanelView({model:serialComm});
}); });
\ No newline at end of file
...@@ -40,6 +40,7 @@ require.config({ ...@@ -40,6 +40,7 @@ require.config({
socketio: '../dependencies/socket.io-1.3.5', socketio: '../dependencies/socket.io-1.3.5',
serialComm: 'models/SerialComm', serialComm: 'models/SerialComm',
commPlist: 'plists/CommPlist', commPlist: 'plists/CommPlist',
machineState: 'models/MachineState',
//lattice classes and extra methods //lattice classes and extra methods
latticeBase: 'lattice/LatticeBase', latticeBase: 'lattice/LatticeBase',
......
/**
* Created by aghassaei on 9/11/15.
*/
define(['backbone'], function(Backbone){
var MachineState = Backbone.Model.extend({
defaults:{
xAxis: null,
yAxis: null,
zAxis: null,
aAxis: null,
bAxis: null,
cAxis: 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});
}
});
return 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'], function(_, Backbone, io){ define(['underscore', 'backbone', 'socketio', 'machineState'], function(_, Backbone, io, MachineState){
var SerialComm = Backbone.Model.extend({ var SerialComm = Backbone.Model.extend({
...@@ -18,6 +18,7 @@ define(['underscore', 'backbone', 'socketio'], function(_, Backbone, io){ ...@@ -18,6 +18,7 @@ define(['underscore', 'backbone', 'socketio'], function(_, Backbone, io){
}, },
initialize: function(){ initialize: function(){
this.machineState = null;
this.attemptToConnectToNode(); this.attemptToConnectToNode();
}, },
...@@ -46,6 +47,15 @@ define(['underscore', 'backbone', 'socketio'], function(_, Backbone, io){ ...@@ -46,6 +47,15 @@ define(['underscore', 'backbone', 'socketio'], function(_, Backbone, io){
this.socket.emit("flush"); this.socket.emit("flush");
}, },
refreshMachineState: function(){//when updating connection, create a new instance of machine state
if (this.machineState) this.machineState.destroy();
this.machineState = new MachineState();
},
getMachineState: function(){
return this.machineState;
},
setProperty: function(property, value){//portName, baudRate setProperty: function(property, value){//portName, baudRate
if (property === null || property === undefined || value === null || value === undefined) return; if (property === null || property === undefined || value === null || value === undefined) return;
this.socket.emit(property, value);//always pass user interaction on this.socket.emit(property, value);//always pass user interaction on
...@@ -93,6 +103,7 @@ define(['underscore', 'backbone', 'socketio'], function(_, Backbone, io){ ...@@ -93,6 +103,7 @@ define(['underscore', 'backbone', 'socketio'], function(_, Backbone, io){
serialComm.set("portName", data.portName); serialComm.set("portName", data.portName);
serialComm.set("portConnected", true); serialComm.set("portConnected", true);
serialComm.set("error", false); serialComm.set("error", false);
serialComm.refreshMachineState();
}); });
socket.on('portDisconnected', function(data){ socket.on('portDisconnected', 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