2013-06-19 11:06:14 +00:00
|
|
|
// Get access to the background window object
|
|
|
|
// This object is used to pass current connectionId to the backround page
|
|
|
|
// so the onClosed event can close the port for us if it was left opened, without this
|
|
|
|
// users can experience weird behavior if they would like to access the serial bus afterwards.
|
|
|
|
chrome.runtime.getBackgroundPage(function(result) {
|
|
|
|
backgroundPage = result;
|
2013-12-06 17:32:32 +00:00
|
|
|
backgroundPage.app_window = window;
|
2013-06-19 11:06:14 +00:00
|
|
|
});
|
|
|
|
|
2013-08-26 12:41:10 +00:00
|
|
|
// Google Analytics stuff begin
|
|
|
|
var service = analytics.getService('ice_cream_app');
|
|
|
|
var ga_tracker = service.getTracker('UA-32728876-6');
|
|
|
|
|
|
|
|
ga_tracker.sendAppView('Application Started');
|
|
|
|
// Google Analytics stuff end
|
2013-06-13 11:11:53 +00:00
|
|
|
|
2013-12-18 13:57:27 +00:00
|
|
|
$(document).ready(function() {
|
|
|
|
// set bounds (default 960x600)
|
|
|
|
if (screen.height > 600) {
|
2014-01-18 18:21:30 +00:00
|
|
|
chrome.app.window.current().setBounds({width: 962, height: 627});
|
2013-12-18 13:57:27 +00:00
|
|
|
} else {
|
|
|
|
$('div#content').height(280);
|
2014-01-18 18:21:30 +00:00
|
|
|
chrome.app.window.current().setBounds({width: 960, height: 427});
|
2013-12-18 13:57:27 +00:00
|
|
|
}
|
|
|
|
|
2014-01-18 18:21:30 +00:00
|
|
|
// bind controls
|
|
|
|
$('#frame .minimize').click(function() {
|
|
|
|
chrome.app.window.current().minimize();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#frame .maximize').click(function() {
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#frame .close').click(function() {
|
|
|
|
chrome.app.window.current().close();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Tabs
|
2013-04-13 00:43:23 +00:00
|
|
|
var tabs = $('#tabs > ul');
|
2013-04-08 19:10:47 +00:00
|
|
|
$('a', tabs).click(function() {
|
|
|
|
if ($(this).parent().hasClass('active') == false) { // only initialize when the tab isn't already active
|
2014-01-18 11:09:12 +00:00
|
|
|
if (configuration_received == false) { // if there is no active connection, return
|
2013-11-08 17:43:51 +00:00
|
|
|
notify('You need to connect before you can view any of the tabs', 'red');
|
2013-04-08 19:10:47 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-09 05:14:21 +00:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
GUI.tab_switch_cleanup(function() {
|
2013-12-09 18:34:34 +00:00
|
|
|
// disable previously active tab highlight
|
2013-11-09 05:14:21 +00:00
|
|
|
$('li', tabs).removeClass('active');
|
|
|
|
|
2013-12-09 18:34:34 +00:00
|
|
|
// get tab class name (there should be only one class listed)
|
|
|
|
var tab = $(self).parent().prop('class');
|
|
|
|
|
|
|
|
// Highlight selected tab
|
2013-11-09 05:14:21 +00:00
|
|
|
$(self).parent().addClass('active');
|
|
|
|
|
2013-12-09 18:34:34 +00:00
|
|
|
switch (tab) {
|
|
|
|
case 'tab_initial_setup':
|
|
|
|
$('#content').load("./tabs/initial_setup.html", tab_initialize_initial_setup);
|
|
|
|
break;
|
|
|
|
case 'tab_pid_tuning':
|
|
|
|
$('#content').load("./tabs/pid_tuning.html", tab_initialize_pid_tuning);
|
|
|
|
break;
|
|
|
|
case 'tab_receiver':
|
|
|
|
$('#content').load("./tabs/receiver.html", tab_initialize_receiver);
|
|
|
|
break;
|
|
|
|
case 'tab_auxiliary_configuration':
|
|
|
|
$('#content').load("./tabs/auxiliary_configuration.html", tab_initialize_auxiliary_configuration);
|
|
|
|
break;
|
|
|
|
case 'tab_servos':
|
|
|
|
$('#content').load("./tabs/servos.html", tab_initialize_servos);
|
|
|
|
break;
|
|
|
|
case 'tab_gps':
|
|
|
|
$('#content').load("./tabs/gps.html", tab_initialize_gps);
|
|
|
|
break;
|
|
|
|
case 'tab_motor_outputs':
|
|
|
|
$('#content').load("./tabs/motor_outputs.html", tab_initialize_motor_outputs);
|
|
|
|
break;
|
|
|
|
case 'tab_sensors':
|
|
|
|
$('#content').load("./tabs/sensors.html", tab_initialize_sensors);
|
|
|
|
break;
|
|
|
|
case 'tab_cli':
|
|
|
|
$('#content').load("./tabs/cli.html", tab_initialize_cli);
|
|
|
|
break;
|
2013-11-09 05:14:21 +00:00
|
|
|
}
|
|
|
|
});
|
2013-04-08 19:10:47 +00:00
|
|
|
}
|
|
|
|
});
|
2013-04-09 15:58:54 +00:00
|
|
|
|
2013-10-30 16:42:04 +00:00
|
|
|
tab_initialize_default();
|
2014-01-15 19:25:51 +00:00
|
|
|
|
2014-01-15 23:55:45 +00:00
|
|
|
// listen to all input change events and adjust the value within limits if necessary
|
2014-01-16 00:58:07 +00:00
|
|
|
$("#content").on("focus", 'input[type="number"]', function() {
|
|
|
|
var element = $(this);
|
|
|
|
var val = element.val();
|
|
|
|
|
|
|
|
if (!isNaN(val)) {
|
|
|
|
element.data('previousValue', parseFloat(val));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-01-15 19:25:51 +00:00
|
|
|
$("#content").on("change", 'input[type="number"]', function() {
|
2014-01-16 00:58:07 +00:00
|
|
|
var element = $(this);
|
|
|
|
var min = parseFloat(element.prop('min'));
|
|
|
|
var max = parseFloat(element.prop('max'));
|
|
|
|
var step = parseFloat(element.prop('step'));
|
|
|
|
var val = parseFloat(element.val());
|
2014-01-15 19:25:51 +00:00
|
|
|
|
2014-01-15 23:55:45 +00:00
|
|
|
// only adjust minimal end if bound is set
|
2014-01-16 00:58:07 +00:00
|
|
|
if (element.prop('min')) {
|
|
|
|
if (val < min) element.val(min);
|
2014-01-15 19:25:51 +00:00
|
|
|
}
|
|
|
|
|
2014-01-15 23:55:45 +00:00
|
|
|
// only adjust maximal end if bound is set
|
2014-01-16 00:58:07 +00:00
|
|
|
if (element.prop('max')) {
|
|
|
|
if (val > max) element.val(max);
|
|
|
|
}
|
|
|
|
|
|
|
|
// if entered value is illegal use previous value instead
|
|
|
|
if (isNaN(val)) {
|
|
|
|
element.val(element.data('previousValue'));
|
|
|
|
}
|
|
|
|
|
|
|
|
// if step is not set or step is int and value is float use previous value instead
|
|
|
|
if (isNaN(step) || step % 1 === 0) {
|
|
|
|
if (val % 1 !== 0) {
|
|
|
|
element.val(element.data('previousValue'));
|
|
|
|
}
|
2014-01-15 19:25:51 +00:00
|
|
|
}
|
|
|
|
});
|
2013-11-08 17:31:19 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
function notify(message, color) {
|
|
|
|
$('span.notify').html('<span style="color: ' + color + '">' + message + '</span>');+
|
|
|
|
$('span.notify span').fadeOut(5000, function() {
|
|
|
|
$(this).remove();
|
|
|
|
});
|
|
|
|
|
2013-11-13 08:49:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function microtime() {
|
|
|
|
var now = new Date().getTime() / 1000;
|
|
|
|
|
|
|
|
return now;
|
2013-11-20 11:24:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// accepting single level array with "value" as key
|
|
|
|
function array_difference(firstArray, secondArray) {
|
|
|
|
var cloneArray = [];
|
|
|
|
|
|
|
|
// create hardcopy
|
|
|
|
for (var i = 0; i < firstArray.length; i++) {
|
|
|
|
cloneArray.push(firstArray[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0; i < secondArray.length; i++) {
|
|
|
|
if (cloneArray.indexOf(secondArray[i]) != -1) {
|
|
|
|
cloneArray.splice(cloneArray.indexOf(secondArray[i]), 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return cloneArray;
|
2014-01-22 14:36:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function add_custom_spinners() {
|
|
|
|
var spinner_element = '<div class="spinner"><div class="up"></div><div class="down"></div></div>';
|
|
|
|
|
|
|
|
$('input[type="number"]').each(function() {
|
|
|
|
var input = $(this);
|
2014-01-22 15:02:55 +00:00
|
|
|
|
2014-01-22 16:05:34 +00:00
|
|
|
// only add new spinner if one doesn't already exist
|
|
|
|
if (!input.next().hasClass('spinner')) {
|
|
|
|
var isInt = true;
|
|
|
|
if (input.prop('step') == '') {
|
2014-01-22 15:02:55 +00:00
|
|
|
isInt = true;
|
|
|
|
} else {
|
2014-01-22 16:05:34 +00:00
|
|
|
if (input.prop('step').indexOf('.') == -1) {
|
|
|
|
isInt = true;
|
|
|
|
} else {
|
|
|
|
isInt = false;
|
|
|
|
}
|
2014-01-22 14:36:34 +00:00
|
|
|
}
|
|
|
|
|
2014-01-22 16:05:34 +00:00
|
|
|
// make space for spinner
|
|
|
|
input.width(input.width() - 16);
|
|
|
|
|
|
|
|
// add spinner
|
|
|
|
input.after(spinner_element);
|
|
|
|
|
|
|
|
// get spinner refference
|
|
|
|
var spinner = input.next();
|
|
|
|
|
|
|
|
// bind UI hooks to spinner
|
|
|
|
$('.up', spinner).click(function() {
|
|
|
|
up();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.up', spinner).mousedown(function() {
|
|
|
|
GUI.timeout_add('spinner', function() {
|
|
|
|
GUI.interval_add('spinner', function() {
|
|
|
|
up();
|
|
|
|
}, 100, true);
|
|
|
|
}, 250);
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.up', spinner).mouseup(function() {
|
|
|
|
GUI.timeout_remove('spinner');
|
|
|
|
GUI.interval_remove('spinner');
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.up', spinner).mouseleave(function() {
|
|
|
|
GUI.timeout_remove('spinner');
|
|
|
|
GUI.interval_remove('spinner');
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
$('.down', spinner).click(function() {
|
|
|
|
down();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.down', spinner).mousedown(function() {
|
|
|
|
GUI.timeout_add('spinner', function() {
|
|
|
|
GUI.interval_add('spinner', function() {
|
|
|
|
down();
|
|
|
|
}, 100, true);
|
|
|
|
}, 250);
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.down', spinner).mouseup(function() {
|
|
|
|
GUI.timeout_remove('spinner');
|
|
|
|
GUI.interval_remove('spinner');
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.down', spinner).mouseleave(function() {
|
|
|
|
GUI.timeout_remove('spinner');
|
|
|
|
GUI.interval_remove('spinner');
|
|
|
|
});
|
|
|
|
|
|
|
|
var up = function() {
|
|
|
|
if (isInt) {
|
|
|
|
var current_value = parseInt(input.val());
|
|
|
|
input.val(current_value + 1);
|
|
|
|
} else {
|
|
|
|
var current_value = parseFloat(input.val());
|
|
|
|
var step = parseFloat(input.prop('step'));
|
|
|
|
var step_decimals = input.prop('step').length - 2;
|
|
|
|
|
|
|
|
input.val((current_value + step).toFixed(step_decimals));
|
|
|
|
}
|
2014-01-22 14:36:34 +00:00
|
|
|
|
2014-01-22 16:05:34 +00:00
|
|
|
input.change();
|
|
|
|
};
|
2014-01-22 14:36:34 +00:00
|
|
|
|
2014-01-22 16:05:34 +00:00
|
|
|
var down = function() {
|
|
|
|
if (isInt) {
|
|
|
|
var current_value = parseInt(input.val());
|
|
|
|
input.val(current_value - 1);
|
|
|
|
} else {
|
|
|
|
var current_value = parseFloat(input.val());
|
|
|
|
var step = parseFloat(input.prop('step'));
|
|
|
|
var step_decimals = input.prop('step').length - 2;
|
|
|
|
|
|
|
|
input.val((current_value - step).toFixed(step_decimals));
|
|
|
|
}
|
|
|
|
|
|
|
|
input.change();
|
|
|
|
};
|
|
|
|
}
|
2014-01-22 14:36:34 +00:00
|
|
|
});
|
2013-11-08 17:31:19 +00:00
|
|
|
}
|