10.3.x-maintenance
cTn 2013-04-12 19:17:27 +02:00
parent e1c1522da5
commit ac1090b4a4
6 changed files with 207 additions and 73 deletions

View File

@ -731,6 +731,35 @@ a:hover {
.tab-sensors #baro {
height: 120px;
}
.tab-cli {
}
.tab-cli p {
padding: 5px;
border: 1px dotted silver;
}
.tab-cli .window {
margin-top: 10px;
height: 400px;
padding: 5px;
overflow-y: scroll;
overflow-x: hidden;
color: white;
border: 1px solid silver;
background-color: black;
}
.tab-cli input {
margin-top: 10px;
display: block;
width: 911px;
padding-left: 5px;
border: 1px solid silver;
}
/* Flotr related styles */
.flotr-legend {

View File

@ -1,7 +1,7 @@
var timers = new Array();
$(document).ready(function() {
var tabs = $('#tabs > ul');
tabs = $('#tabs > ul');
$('a', tabs).click(function() {
if ($(this).parent().hasClass('active') == false) { // only initialize when the tab isn't already active
if (connectionId < 1) { // if there is no active connection, return
@ -11,6 +11,11 @@ $(document).ready(function() {
// Disable any active "data pulling" timer
disable_timers();
// Disable CLI (there is no "nicer way of doing so right now)
if (CLI_active == true) {
leave_CLI();
}
// Disable previous active button
$('li', tabs).removeClass('active');
@ -29,12 +34,15 @@ $(document).ready(function() {
$('#content').load("./tabs/motor_outputs.html", tab_initialize_motor_outputs);
} else if ($(this).parent().hasClass('tab_sensors')) {
$('#content').load("./tabs/sensors.html", tab_initialize_sensors);
} else if ($(this).parent().hasClass('tab_cli')) {
$('#content').load("./tabs/cli.html", tab_initialize_cli);
}
}
});
// temporary
//$('#content').load("./tabs/initial_setup.html", tab_initialize_initial_setup);
//$('#content').load("./tabs/cli.html", tab_initialize_cli);
});
function disable_timers() {

View File

@ -103,6 +103,8 @@ var GPS_DATA = {
update: 0
};
var CLI_active = false;
$(document).ready(function() {
port_picker = $('div#port-picker .port select');
baud_picker = $('div#port-picker #baud');
@ -148,16 +150,26 @@ $(document).ready(function() {
// Disable any active "data pulling" timer
disable_timers();
// Disable CLI (there is no "nicer way of doing so right now)
if (CLI_active == true) {
leave_CLI(function() {
chrome.serial.close(connectionId, onClosed);
clearTimeout(connection_delay);
clearInterval(serial_poll);
clearInterval(port_usage_poll);
});
} else {
chrome.serial.close(connectionId, onClosed);
clearTimeout(connection_delay);
clearInterval(serial_poll);
clearInterval(port_usage_poll);
}
// Change port utilization to 0
$('span.port-usage').html('0%');
$(this).text('Connect');
$(this).removeClass('active');
} else { // even number of clicks
@ -234,6 +246,8 @@ function onCharRead(readInfo) {
var data = new Uint8Array(readInfo.data);
for (var i = 0; i < data.length; i++) {
if (CLI_active != true) {
// Standard "GUI" MSP handling
switch (message_state) {
case 0: // sync char 1
if (data[i] == 36) { // $
@ -297,6 +311,10 @@ function onCharRead(readInfo) {
message_state = 0;
break;
}
} else {
// CLI Enabled (Terminal "style" handling)
handle_CLI(data[i]);
}
char_counter++;
}

View File

@ -17,6 +17,7 @@
<script type="text/javascript" src="./tabs/auxiliary_configuration.js"></script>
<script type="text/javascript" src="./tabs/motor_outputs.js"></script>
<script type="text/javascript" src="./tabs/sensors.js"></script>
<script type="text/javascript" src="./tabs/cli.js"></script>
</head>
<body>
<div id="main-wrapper">
@ -82,6 +83,7 @@
<li class="tab_auxiliary_configuration"><a href="#">Auxiliary Configuration</a></li>
<li class="tab_motor_outputs"><a href="#">Motor/Servo Outputs</a></li>
<li class="tab_sensors"><a href="#">Raw Sensor Data</a></li>
<li class="tab_cli"><a href="#">CLI</a></li>
</ul>
<div class="clear-both"></div>
</div>

9
tabs/cli.html Normal file
View File

@ -0,0 +1,9 @@
<div class="tab-cli">
<p>
<span style="color: red;">Note</span>: Leaving CLI tab or pressing Disconnect will <strong>automatically</strong>
send "<strong>exit</strong>" to the board, which will make the controller save all the changes and <span style="color: red">restart</span>.
</p>
<div class="window">
</div>
<input type="text" name="commands" value="" />
</div>

68
tabs/cli.js Normal file
View File

@ -0,0 +1,68 @@
function tab_initialize_cli() {
CLI_active = true;
// Enter CLI mode
var bufferOut = new ArrayBuffer(1);
var bufView = new Uint8Array(bufferOut);
bufView[0] = 0x23; // #
chrome.serial.write(connectionId, bufferOut, function(writeInfo) {
// used for debugging purposes (should be disabled in "stable" builds
console.log("Wrote: " + writeInfo.bytesWritten + " bytes");
});
$('.tab-cli input').keypress(function(event) {
if (event.which == 13) { // enter
var out_string = $('.tab-cli input').val();
var bufferOut = new ArrayBuffer(out_string.length + 1); // +1 for enter character
var bufView = new Uint8Array(bufferOut);
for (var i = 0; i < out_string.length; i++) {
bufView[i] = out_string.charCodeAt(i);
}
bufView[out_string.length] = 0x0D; // enter
chrome.serial.write(connectionId, bufferOut, function(writeInfo) {
$('.tab-cli input').val('');
});
}
});
// give input element user focus
$('.tab-cli input').focus();
}
function leave_CLI(callback) {
var bufferOut = new ArrayBuffer(5);
var bufView = new Uint8Array(bufferOut);
bufView[0] = 0x65; // e
bufView[1] = 0x78; // x
bufView[2] = 0x69; // i
bufView[3] = 0x74; // t
bufView[4] = 0x0D; // enter
chrome.serial.write(connectionId, bufferOut, function(writeInfo) {
if (typeof callback !== 'undefined') {
callback();
}
});
CLI_active = false;
}
function handle_CLI(data) {
switch (data) {
case 10: // line feed
break;
case 13: // carriage return
$('.tab-cli .window').append("<br />");
break;
default:
$('.tab-cli .window').append(String.fromCharCode(data));
$('.tab-cli .window').scrollTop($('.tab-cli .window').height());
}
}