Commit 7187c3aa authored by Amanda Ghassaei's avatar Amanda Ghassaei
Browse files

parent for comm menu

parent e6ba3fbd
......@@ -39,6 +39,7 @@ require.config({
//communication
socketio: '../dependencies/socket.io-1.3.5',
serialComm: 'models/SerialComm',
commPlist: 'plists/CommPlist',
//lattice classes and extra methods
latticeBase: 'lattice/LatticeBase',
......@@ -140,6 +141,7 @@ require.config({
mDynamicMenu: 'menus/MDynamicMenuView',
assemblerSetupMenu: 'menus/AssemblerSetupMenuView',
editComponentMenu: 'menus/EditComponentMenuView',
commParentMenu: 'menus/CommParentMenu',
//templates
navViewMenuTemplate: 'menus/templates/NavViewMenu.html',
......
/**
* Created by aghassaei on 8/28/15.
*/
define(['jquery', 'underscore', 'menuParent', 'plist', 'serialComm', 'text!setupCommMenuTemplate', 'commPlist'],
function($, _, MenuParentView, plist, serialComm, template, commPlist){
return MenuParentView.extend({
parentEvents: {
"change #sendSerialMessage": "_sendMessage"
},
_initialize: function(){
_.extend(this.events, this.parentEvents);
this.listenTo(serialComm, "change", this.render);
this.listenTo(serialComm, "change:lastMessageReceived", this._updateIncomingMessage);
this.inTimeout = false;
if (this.__initialize) this.__initialize();
},
getPropertyOwner: function($target){
if ($target.hasClass("serialComm")) return serialComm;
return null;
},
_sendMessage: function(e){
e.preventDefault();
var message = $("#sendSerialMessage").val();
$("#sendSerialMessage").val("");
if (message == "") return;
serialComm.send(message);
},
_updateIncomingMessage: function(){
var message = serialComm.get("lastMessageReceived");
var $message = $("#incomingSerialMessage");
$message.html(message);
$message.css("background", "#ffff99");
if (!this.inTimeout) {
this.inTimeout = true;
var self = this;
setTimeout(function(){
$message.css("background", "white");
self.inTimeout = false;
}, 100);
}
}
});
});
\ No newline at end of file
......@@ -2,21 +2,25 @@
* Created by aghassaei on 3/11/15.
*/
define(['jquery', 'underscore', 'menuParent', 'plist', 'lattice', 'text!sendMenuTemplate'], function($, _, MenuParentView, plist, lattice, template){
define(['jquery', 'underscore', 'commParentMenu', 'serialComm', 'commPlist', 'text!sendMenuTemplate'],
function($, _, CommParentMenu, serialComm, commPlist, template){
return CommParentMenu.extend({
return MenuParentView.extend({
events: {
},
_initialize: function(){
//bind events
__initialize: function(){
},
_makeTemplateJSON: function(){
return null;
console.log("render");
return _.extend(serialComm.toJSON(), commPlist);
},
template: _.template(template)
});
});
\ No newline at end of file
......@@ -3,58 +3,21 @@
*/
define(['jquery', 'underscore', 'menuParent', 'plist', 'serialComm', 'text!setupCommMenuTemplate'],
function($, _, MenuParentView, plist, serialComm, template){
define(['jquery', 'underscore', 'commParentMenu', 'serialComm', 'text!setupCommMenuTemplate', 'commPlist'],
function($, _, CommParentMenu, serialComm, template, commPlist){
return MenuParentView.extend({
return CommParentMenu.extend({
events: {
"click #serialFlushBuffer": "_flushBuffer",
"click #nodeSetupInstructions": "_setupInstructions",
"click #refreshPorts": "_refreshPorts",
"change #seriallTestMessage": "_sendTestMessage",
"click #reconnectToNode": "_reconnectToNode"
},
_initialize: function(){
this.listenTo(serialComm, "change", this.render);
this.listenTo(serialComm, "change:lastMessageReceived", this._updateIncomingMessage);
this.inTimeout = false;
},
getPropertyOwner: function($target){
if ($target.hasClass("serialComm")) return serialComm;
return null;
},
_sendTestMessage: function(e){
e.preventDefault();
var message = $("#seriallTestMessage").val();
$("#seriallTestMessage").val("");
if (message == "") return;
serialComm.send(message);
},
_updateIncomingMessage: function(){
var message = serialComm.get("lastMessageReceived");
var $message = $("#incomingSerialMessage");
console.log(message);
$message.html(message);
$message.css("background", "#ffff99");
if (!this.inTimeout) {
this.inTimeout = true;
var self = this;
setTimeout(function(){
$message.css("background", "white");
self.inTimeout = false;
}, 100);
}
__initialize: function(){
},
_flushBuffer: function(e){
......@@ -83,7 +46,8 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'serialComm', 'text!setup
},
_makeTemplateJSON: function(){
return _.extend(this.model.toJSON(), serialComm.toJSON(), {allBaudRates: [300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, 115200]});
console.log("render");
return _.extend(serialComm.toJSON(), commPlist);
},
template: _.template(template),
......
realtime communication with machine
\ No newline at end of file
Incoming: &nbsp;&nbsp;<pre id="incomingSerialMessage"></pre><br/><br/>
Out: &nbsp;&nbsp;<input id="sendSerialMessage" value="" placeholder="Send Message" class="seventyFiveWidth form-control unresponsiveInput" type="text"><br/><br/>
<a href="#" id="stopMachine" class="btn btn-block btn-lg btn-danger">Stop</a><br/>
\ No newline at end of file
......@@ -23,7 +23,7 @@
</div>
&nbsp;&nbsp;<a href="#" id="refreshPorts" class="btn btn-lg btn-default btn-icon"><img src="assets/imgs/refreshIcon.png"></a><br/><br/>
Incoming: &nbsp;&nbsp;<pre id="incomingSerialMessage"></pre><br/><br/>
Out: &nbsp;&nbsp;<input id="seriallTestMessage" value="<%= testMessage %>" placeholder="Send Message" class="seventyFiveWidth form-control unresponsiveInput" type="text"><br/><br/>
Out: &nbsp;&nbsp;<input id="sendSerialMessage" value="" placeholder="Send Message" class="seventyFiveWidth form-control unresponsiveInput" type="text"><br/><br/>
<a href="#" id="serialFlushBuffer" class="btn btn-block btn-lg btn-danger">Flush Buffer</a><br/>
<% }else{ %>
No node server found.<br/><br/>
......
......@@ -13,8 +13,8 @@ define(['underscore', 'backbone', 'socketio'], function(_, Backbone, io){
portName: "Select Port",
baudRate: 200,
error: null,
testMessage: "",
lastMessageReceived: ""
lastMessageReceived: "",
lastMessageSent: ""
},
initialize: function(){
......
/**
* Created by aghassaei on 8/28/15.
*/
define([], function(){
return {
allBaudRates: [300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, 115200]
}
});
\ No newline at end of file
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