From 916e16cb5156c99f6239edcc32a59a9c5f1fcacb Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Wed, 9 Sep 2015 02:09:35 -0400 Subject: [PATCH] setting up serial monitor window --- SerialMonitor.html | 3 +- js/main.js | 2 +- js/menus/CommParentMenu.js | 1 + js/menus/SerialMonitorController.js | 44 ++++++++++++++++ js/menus/SerialMonitorView.js | 63 +++++++++++++++++------ js/menus/SetupCommMenuView.js | 4 +- js/menus/templates/SetupCommMenuView.html | 6 +-- js/models/SerialComm.js | 11 +++- node/nodeServer.js | 2 +- 9 files changed, 108 insertions(+), 28 deletions(-) create mode 100644 js/menus/SerialMonitorController.js diff --git a/SerialMonitor.html b/SerialMonitor.html index 15b32814..04f37a35 100644 --- a/SerialMonitor.html +++ b/SerialMonitor.html @@ -5,9 +5,10 @@ <link href="dependencies/flatUI/css/vendor/bootstrap.min.css" rel="stylesheet"><!-- Loading Bootstrap --> <link href="dependencies/flatUI/css/flat-ui.css" rel="stylesheet"><!-- Loading Flat UI --> <link href="css/serialMonitor.css" rel="stylesheet"><!-- Loading custom stylingI --> + <script data-main="js/menus/SerialMonitorView" src="dependencies/require/require.js"></script> </head> <html><div id="serialMonitorView"> serial monitor - <input id="serialMonitorSend" value="" placeholder="Send Message" class="form-control" type="text"> + <input id="sendSerialMessage" value="" placeholder="Send Message" class="form-control" type="text"> </div> </html> \ No newline at end of file diff --git a/js/main.js b/js/main.js index aee356d6..d927b0b4 100644 --- a/js/main.js +++ b/js/main.js @@ -142,7 +142,7 @@ require.config({ assemblerSetupMenu: 'menus/AssemblerSetupMenuView', editComponentMenu: 'menus/EditComponentMenuView', commParentMenu: 'menus/CommParentMenu', - serialMonitor: 'menus/SerialMonitorView', + serialMonitorController: 'menus/SerialMonitorController', //templates navViewMenuTemplate: 'menus/templates/NavViewMenu.html', diff --git a/js/menus/CommParentMenu.js b/js/menus/CommParentMenu.js index f5109241..aa4fd434 100644 --- a/js/menus/CommParentMenu.js +++ b/js/menus/CommParentMenu.js @@ -32,6 +32,7 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'serialComm', 'text!setup }, _sendMessage: function(e){ + console.log("here"); e.preventDefault(); var message = $("#sendSerialMessage").val(); $("#sendSerialMessage").val(""); diff --git a/js/menus/SerialMonitorController.js b/js/menus/SerialMonitorController.js new file mode 100644 index 00000000..eab4ebe0 --- /dev/null +++ b/js/menus/SerialMonitorController.js @@ -0,0 +1,44 @@ +/** + * Created by aghassaei on 9/8/15. + */ + + +define(['jquery', 'underscore', 'backbone'], function($, _, Backbone){ + + var SerialMonitorView = Backbone.View.extend({ + + events: { + }, + + initialize: function(){ + this.popup = null; + var self = this; + $(window).unload(function(){ + self.popup.close();//close popup when leaving page + }); + }, + + open: function(){ + if (this.popup){ + this.popup.focus(); + return; + } + this.popup = window.open('SerialMonitor.html', '', 'height=400, width=400, titlebar=no, toolbar=no, menubar=yes, scrollbars=no, resizable=yes, location=no, directories=no, status=no'); + var self = this; + $(this.popup).unload(function(){ + self.onClose(); + }); + }, + + onClose: function(){ + var self = this; + setTimeout(function(){ + if (self.popup.closed) self.popup = null; + }, 100);//todo this is stupid, find an event that fires with window.closed == true + } + + }); + + return new SerialMonitorView(); + +}); \ No newline at end of file diff --git a/js/menus/SerialMonitorView.js b/js/menus/SerialMonitorView.js index 78683ff3..c1f35fdb 100644 --- a/js/menus/SerialMonitorView.js +++ b/js/menus/SerialMonitorView.js @@ -1,35 +1,64 @@ /** - * Created by aghassaei on 9/8/15. + * Created by aghassaei on 9/9/15. */ +require.config({ -define(['jquery', 'underscore', 'backbone'], function($, _, Backbone){ + baseUrl: 'js', - var SerialMonitorView = Backbone.View.extend({ - - el: "#serialMonitorView", + paths: { + jquery: '../dependencies/jquery-2.1.3', + underscore: '../dependencies/underscore', + backbone: '../dependencies/backbone' + }, - events: { + shim: { + three: { + exports: 'THREE' }, - - initialize: function(){ - this.open(); + orbitControls: { + deps: ['three'], + exports: 'THREE' }, - - open: function(){ - window.open('SerialMonitor.html', '', 'height=400, width=400, titlebar=no, toolbar=no, menubar=yes, scrollbars=no, resizable=yes, location=no, directories=no, status=no'); + stlLoader: { + deps: ['three'], + exports: 'THREE' + }, + fileSaverLib: { + exports: 'saveAs' + }, + flatUI: { + deps: ['jquery'] + }, + bootstrapSlider:{ + deps: ['jquery'], + exports: '$' + }, + 'socketio': { + exports: 'io' }, + 'numeric': { + exports: 'numeric' + } + } - onClose: function(){ +}); - }, +console.log("hi"); + +require(['jquery', 'underscore', 'backbone'], function($, _, Backbone){ - _destroy: function(){ + console.log("here45"); + + var SerialMonitorView = Backbone.View.extend({ + el: "#serialMonitorView", + + initialize: function(){ + $("#serialMonitorView").html("working"); } }); - return SerialMonitorView; - + new SerialMonitorView(); }); \ No newline at end of file diff --git a/js/menus/SetupCommMenuView.js b/js/menus/SetupCommMenuView.js index c126a1c5..759fbad8 100644 --- a/js/menus/SetupCommMenuView.js +++ b/js/menus/SetupCommMenuView.js @@ -49,9 +49,7 @@ define(['jquery', 'underscore', 'commParentMenu', 'serialComm', 'text!setupCommM _openSerialMonitor: function(e){ e.preventDefault(); - require(['serialMonitor'], function(SerialMonitor){ - var serialMonitor = new SerialMonitor(); - }); + serialComm.openSerialMonitor(); }, _makeTemplateJSON: function(){ diff --git a/js/menus/templates/SetupCommMenuView.html b/js/menus/templates/SetupCommMenuView.html index e5cee310..648e085b 100644 --- a/js/menus/templates/SetupCommMenuView.html +++ b/js/menus/templates/SetupCommMenuView.html @@ -1,7 +1,7 @@ -<% if(error){ %> - <div class="inlineWarning"><%= error %></div> -<% } %> <% if(connected){ %> + <% if(error){ %> + <div class="inlineWarning"><%= error %></div> + <% } %> Status: <% if (portConnected){ %> Connected <% } else { %> <span class="red">Disconnected</span> <% } %><br/><br/> Baud Rate: <div class="btn-group"> diff --git a/js/models/SerialComm.js b/js/models/SerialComm.js index 2c3d79b3..ffe090f6 100644 --- a/js/models/SerialComm.js +++ b/js/models/SerialComm.js @@ -50,6 +50,12 @@ define(['underscore', 'backbone', 'socketio'], function(_, Backbone, io){ if (property === null || property === undefined || value === null || value === undefined) return; this.socket.emit(property, value);//always pass user interaction on this.set(property, value); + }, + + openSerialMonitor: function(){ + require(['serialMonitorController'], function(serialMonitorController){ + serialMonitorController.open(); + }); } }); @@ -86,8 +92,9 @@ define(['underscore', 'backbone', 'socketio'], function(_, Backbone, io){ serialComm.set("portConnected", false); }); - socket.on("errorMsg", function(error){ - serialComm.set("error", error); + socket.on("errorMsg", function(data){ + console.log(data); + serialComm.set("error", data.error); }); socket.on("error", function(error){ diff --git a/node/nodeServer.js b/node/nodeServer.js index 13c2cfc3..e6de3544 100644 --- a/node/nodeServer.js +++ b/node/nodeServer.js @@ -159,7 +159,7 @@ io.on('connection', function(socket){ function onPortError(error){ console.log("Serial port error " + error); - socket.emit("errorMsg", error); + socket.emit("errorMsg", {error:String(error)}); } }); -- GitLab