Commit 1331955e authored by Amanda Ghassaei's avatar Amanda Ghassaei
Browse files

serial monitor features

parent 28039c4c
......@@ -9,6 +9,34 @@ define(['backbone'], function(Backbone){
defaults: {
autoscroll: true
},
history: [],
historyIndex: -1,
appendOutput: function(message){
this.history.unshift(message);
this.historyIndex = -1;
if (this.history.length>50) this.history.pop();
},
getPrevHistElem: function(){
this.historyIndex++;
if (this.historyIndex < 0) this.historyIndex = 0;
if (this.history.length == 0) return "";
if (this.history.length <= this.historyIndex) this.historyIndex = this.history.length-1;
return this.history[this.historyIndex];
},
getNewerHistElem: function(){
if (this.history.length == 0) return "";
this.historyIndex --;
if (this.historyIndex < 0) {
this.historyIndex = -1;
return "";
}
if (this.history.length <= this.historyIndex) this.historyIndex = this.history.length-1;
return this.history[this.historyIndex];
}
});
......
......@@ -10,6 +10,9 @@ define(['jquery', 'underscore', 'commParentMenu', 'serialComm', 'text!SerialMoni
el: "#serialMonitorView",
parentEvents: {
},
events: {
"click #clearMonitor": "render",
"change input:checkbox": "_clickCheckbox"
......@@ -17,14 +20,27 @@ define(['jquery', 'underscore', 'commParentMenu', 'serialComm', 'text!SerialMoni
__initialize: function(){
_.bindAll(this, "_onKeyUp");
$(document).bind('keyup', {}, this._onKeyUp);
this.listenTo(serialComm, "change:lastMessageSent", this._updateOutgoingMessage);
this.listenTo(serialComm, "change:baudRate change:portName", this.render);
this.listenTo(serialComm, "change:connected", function(){
if (!serialComm.get("connected")) this._close();
})
});
this.render();
},
_onKeyUp: function(e){
var $output = $("#sendSerialMessage");
if ($output.is(":focus")){
if (e.keyCode == 38) $output.val(this.model.getPrevHistElem());
else if (e.keyCode == 40) $output.val(this.model.getNewerHistElem());
else if (e.keyCode == 13) this._sendMessage(e);
}
},
_clickCheckbox: function(e){
e.preventDefault();
var $target = $(e.target);
......@@ -63,8 +79,10 @@ define(['jquery', 'underscore', 'commParentMenu', 'serialComm', 'text!SerialMoni
return this.model.toJSON();
},
__sendMessage: function(message){
_updateOutgoingMessage: function(){
var message = serialComm.get("lastMessageSent");
this._addOutputData("<span class='outgoing'>" + message + "</span><br/>");
this.model.appendOutput(message);
},
_updateIncomingMessage: function(){
......
......@@ -37,7 +37,6 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'serialComm', 'commPlist'
$("#sendSerialMessage").val("");
if (message == "") return;
serialComm.send(message);
if (this.__sendMessage) this.__sendMessage(message);
},
_updateIncomingMessage: function(){
......
......@@ -9,7 +9,7 @@
<a href="#" id="streamCommands" class="btn btn-block btn-lg btn-success">Stream</a>
<% } %>
<br/>
Incoming: &nbsp;&nbsp;<pre id="incomingSerialMessage"></pre><br/><br/>
Incoming: &nbsp;&nbsp;<pre id="incomingSerialMessage"><br/></pre><br/>
Out: &nbsp;&nbsp;<input id="sendSerialMessage" value="" placeholder="Send Message" class="seventyFiveWidth form-control unresponsiveInput" type="text"><br/><br/>
Next Line: &nbsp;&nbsp;<input id="nextLine" value="" placeholder="##" class="intInput form-control unresponsiveInput" type="text">
<a href="#" id="previousLineButton" class="btn btn-lg btn-default">Prev</a>
......
......@@ -77,6 +77,11 @@ define(['underscore', 'backbone', 'socketio'], function(_, Backbone, io){
serialComm.trigger("change:lastMessageReceived");
});
socket.on('dataSent', function(data){
serialComm.set("lastMessageSent", data, {silent:true});
serialComm.trigger("change:lastMessageSent");
});
socket.on('portConnected', function(data){
console.log("connected port " + data.portName + " at " + data.baudRate);
serialComm.set("baudRate", data.baudRate);
......
......@@ -50,6 +50,7 @@ io.on('connection', function(socket){
});
socket.on('dataOut', function(data){
io.emit('dataSent', data);
data += '\n';
console.log("Sending data: " + data);
currentPort.write(new Buffer(data), function(err, res) {
......
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