diff --git a/SerialMonitor.html b/SerialMonitor.html index 15b32814b318cbd45134a41be46b45204aefd68f..04f37a35619e79115a4b1cbc111b40ae732899ea 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 aee356d65a6ff95abcd9b2dbbb4d9fc7f2c0f36a..d927b0b440de3061c771a42ad1e97e6c870e7b7e 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 f51092412e78c49a67dfafd881faf7f1deb9a00c..aa4fd434790c86a7c3b8c70781ab5204c29ae94d 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 0000000000000000000000000000000000000000..eab4ebe05e97b4db1995be5eebb0874ea8cf1bdc --- /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 78683ff366c06e339a4ca028afa8f2c884f17a6c..c1f35fdb19c9418577e0315ae53a11fc51101942 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 c126a1c5f792c4d31abd066e4e26414f52fc7307..759fbad8bfe55335c4426f6ec53894b7863b3634 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 e5cee310aff0a28537560a86a9bfbc16cd8fc566..648e085b561c1b8c6d1a30eb35168ceedc0609d7 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 2c3d79b346daa63fd2d91ad3e212742b2272c017..ffe090f6c3a4b2cf5f343fd4a7bb2d80d9537191 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 13c2cfc3f2c526420190391a59bc1a26870e5acf..e6de354491431435e5a674dceb5032ca5bf82668 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)}); } });