2015-01-09 01:11:46 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
TABS.led_strip = {
|
|
|
|
wireMode: false,
|
2015-01-25 15:22:43 +00:00
|
|
|
functions: ['w', 'f', 'i', 'a', 't', 'r', 'c'],
|
2015-01-16 00:15:41 +00:00
|
|
|
directions: ['n', 'e', 's', 'w', 'u', 'd'],
|
2015-01-09 01:11:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
TABS.led_strip.initialize = function (callback, scrollPosition) {
|
|
|
|
var self = this;
|
|
|
|
|
2015-03-30 02:18:32 +00:00
|
|
|
TABS.led_strip.wireMode = false;
|
|
|
|
|
2015-01-09 01:11:46 +00:00
|
|
|
if (GUI.active_tab != 'led_strip') {
|
|
|
|
GUI.active_tab = 'led_strip';
|
|
|
|
googleAnalytics.sendAppView('LED Strip');
|
|
|
|
}
|
|
|
|
|
|
|
|
function load_led_config() {
|
|
|
|
MSP.send_message(MSP_codes.MSP_LED_STRIP_CONFIG, false, false, load_html);
|
|
|
|
}
|
|
|
|
|
|
|
|
function load_html() {
|
|
|
|
$('#content').load("./tabs/led_strip.html", process_html);
|
|
|
|
}
|
|
|
|
|
|
|
|
load_led_config();
|
|
|
|
|
|
|
|
|
|
|
|
function buildUsedWireNumbers() {
|
|
|
|
var usedWireNumbers = [];
|
|
|
|
$('.mainGrid .gPoint .wire').each(function () {
|
|
|
|
var wireNumber = parseInt($(this).html());
|
|
|
|
if (wireNumber >= 0) {
|
|
|
|
usedWireNumbers.push(wireNumber);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
usedWireNumbers.sort(function(a,b){return a - b});
|
|
|
|
return usedWireNumbers;
|
|
|
|
}
|
|
|
|
|
|
|
|
function process_html() {
|
|
|
|
|
|
|
|
localize();
|
|
|
|
|
|
|
|
// Build Grid
|
|
|
|
var theHTML = [];
|
|
|
|
var theHTMLlength = 0;
|
|
|
|
for (i=0; i<256; i++) {
|
|
|
|
theHTML[theHTMLlength++] = ('<div class="gPoint"><div class="indicators"><span class="north"></span><span class="south"></span><span class="west"></span><span class="east"></span><span class="up">U</span><span class="down">D</span></div><span class="wire"></span></div>');
|
|
|
|
}
|
|
|
|
$('.mainGrid').html(theHTML.join(''));
|
|
|
|
|
|
|
|
$('.tempOutput').click(function() {
|
|
|
|
$(this).select();
|
|
|
|
});
|
|
|
|
|
2015-01-22 20:27:13 +00:00
|
|
|
// Clear button
|
2015-01-09 01:11:46 +00:00
|
|
|
$('.funcClear').click(function() {
|
|
|
|
$('.gPoint').each(function() {
|
|
|
|
if ($(this).is('.ui-selected')) {
|
2015-01-22 20:27:13 +00:00
|
|
|
removeFunctionsAndDirections(this);
|
|
|
|
$(this).find('.wire').html('');
|
2015-01-09 01:11:46 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.controls button').removeClass('btnOn');
|
2015-01-22 20:27:13 +00:00
|
|
|
updateBulkCmd();
|
2015-01-09 01:11:46 +00:00
|
|
|
});
|
|
|
|
|
2015-01-22 20:27:13 +00:00
|
|
|
// Clear All button
|
|
|
|
$('.funcClearAll').click(function() {
|
|
|
|
$('.gPoint').each(function() {
|
|
|
|
removeFunctionsAndDirections(this);
|
|
|
|
});
|
|
|
|
$('.gPoint .wire').html('');
|
|
|
|
|
|
|
|
updateBulkCmd();
|
|
|
|
|
|
|
|
$('.controls button').removeClass('btnOn');
|
|
|
|
});
|
|
|
|
|
|
|
|
function removeFunctionsAndDirections(element) {
|
|
|
|
var classesToRemove = [];
|
|
|
|
|
|
|
|
TABS.led_strip.functions.forEach(function(letter) {
|
|
|
|
classesToRemove.push('function-' + letter);
|
|
|
|
});
|
|
|
|
TABS.led_strip.directions.forEach(function(letter) {
|
|
|
|
classesToRemove.push('dir-' + letter);
|
|
|
|
});
|
|
|
|
$(element).removeClass(classesToRemove.join(' '));
|
|
|
|
}
|
|
|
|
|
2015-01-09 01:11:46 +00:00
|
|
|
|
|
|
|
// Directional Buttons
|
2015-01-16 00:15:41 +00:00
|
|
|
$('.directions').on('click', 'button', function() {
|
2015-01-09 01:11:46 +00:00
|
|
|
var that = this;
|
|
|
|
if ($('.ui-selected').length > 0) {
|
2015-01-16 00:15:41 +00:00
|
|
|
TABS.led_strip.directions.forEach(function(letter) {
|
|
|
|
if ($(that).is('.dir-' + letter)) {
|
2015-01-23 18:01:09 +00:00
|
|
|
if ($(that).is('.btnOn')) {
|
|
|
|
$(that).removeClass('btnOn');
|
|
|
|
$('.ui-selected').removeClass('dir-' + letter);
|
|
|
|
} else {
|
|
|
|
$(that).addClass('btnOn');
|
|
|
|
$('.ui-selected').addClass('dir-' + letter);
|
|
|
|
}
|
2015-01-09 01:11:46 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
updateBulkCmd();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Mode Buttons
|
2015-01-16 00:15:41 +00:00
|
|
|
$('.functions').on('click', 'button', function() {
|
2015-01-09 01:11:46 +00:00
|
|
|
var that = this;
|
|
|
|
if ($('.ui-selected').length > 0) {
|
2015-01-16 00:15:41 +00:00
|
|
|
TABS.led_strip.functions.forEach(function(letter) {
|
|
|
|
if ($(that).is('.function-' + letter)) {
|
2015-01-23 18:01:09 +00:00
|
|
|
|
|
|
|
if ($(that).is('.btnOn')) {
|
|
|
|
$(that).removeClass('btnOn');
|
|
|
|
$('.ui-selected').removeClass('function-' + letter);
|
|
|
|
} else {
|
|
|
|
$(that).addClass('btnOn');
|
|
|
|
$('.ui-selected').addClass('function-' + letter);
|
|
|
|
}
|
2015-01-09 01:11:46 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
updateBulkCmd();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-01-23 01:12:20 +00:00
|
|
|
// Color Buttons
|
|
|
|
$('.colors').on('click', 'button', function() {
|
|
|
|
var that = this;
|
|
|
|
var colorButtons = $(this).parent().find('button');
|
|
|
|
|
|
|
|
for (var colorIndex = 0; colorIndex < 16; colorIndex++) {
|
|
|
|
colorButtons.removeClass('btnOn');
|
|
|
|
$('.ui-selected').removeClass('color-' + colorIndex);
|
|
|
|
|
|
|
|
if ($(that).is('.color-' + colorIndex)) {
|
|
|
|
$('.ui-selected').addClass('color-' + colorIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$(this).addClass('btnOn');
|
|
|
|
|
|
|
|
updateBulkCmd();
|
|
|
|
});
|
|
|
|
|
2015-01-09 01:11:46 +00:00
|
|
|
$('.funcWire').click(function() {
|
|
|
|
$(this).toggleClass('btnOn');
|
2015-03-30 02:18:32 +00:00
|
|
|
TABS.led_strip.wireMode = $(this).hasClass('btnOn');
|
2015-01-09 01:11:46 +00:00
|
|
|
$('.mainGrid').toggleClass('gridWire');
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.funcWireClearSelect').click(function() {
|
|
|
|
$('.ui-selected').each(function() {
|
|
|
|
var thisWire = $(this).find('.wire');
|
|
|
|
if (thisWire.html() != '') {
|
|
|
|
thisWire.html('');
|
|
|
|
}
|
|
|
|
updateBulkCmd();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.funcWireClear').click(function() {
|
|
|
|
$('.gPoint .wire').html('');
|
|
|
|
updateBulkCmd();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.mainGrid').selectable({
|
|
|
|
filter: ' > div',
|
|
|
|
stop: function() {
|
2015-01-29 18:24:00 +00:00
|
|
|
var functionsInSelection = [];
|
|
|
|
var directionsInSelection = [];
|
2015-01-23 18:01:09 +00:00
|
|
|
|
2015-01-09 01:11:46 +00:00
|
|
|
$('.ui-selected').each(function() {
|
|
|
|
|
|
|
|
|
|
|
|
var usedWireNumbers = buildUsedWireNumbers();
|
|
|
|
|
|
|
|
var nextWireNumber = 0;
|
|
|
|
for (var nextWireNumber = 0; nextWireNumber < usedWireNumbers.length; nextWireNumber++) {
|
|
|
|
if (usedWireNumbers[nextWireNumber] != nextWireNumber) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TABS.led_strip.wireMode) {
|
|
|
|
if ($(this).find('.wire').html() == '' && nextWireNumber < LED_STRIP.length) {
|
|
|
|
$(this).find('.wire').html(nextWireNumber);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var that = this;
|
|
|
|
|
2015-01-16 00:15:41 +00:00
|
|
|
TABS.led_strip.directions.forEach(function(letter) {
|
2015-01-23 01:12:20 +00:00
|
|
|
var className = '.dir-' + letter;
|
|
|
|
if ($(that).is(className)) {
|
2015-01-29 18:24:00 +00:00
|
|
|
directionsInSelection.push(className);
|
2015-01-09 01:11:46 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-01-16 00:15:41 +00:00
|
|
|
TABS.led_strip.functions.forEach(function(letter) {
|
2015-01-23 01:12:20 +00:00
|
|
|
var className = '.function-' + letter;
|
|
|
|
if ($(that).is(className)) {
|
2015-01-29 18:24:00 +00:00
|
|
|
functionsInSelection.push(className);
|
2015-01-09 01:11:46 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-01-23 01:12:20 +00:00
|
|
|
for (var colorIndex = 0; colorIndex < 16; colorIndex++) {
|
|
|
|
var className = '.color-' + colorIndex;
|
|
|
|
if ($(this).is(className)) {
|
|
|
|
$(className).addClass('btnOn');
|
|
|
|
} else {
|
|
|
|
$(className).removeClass('btnOn');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-09 01:11:46 +00:00
|
|
|
updateBulkCmd();
|
|
|
|
});
|
2015-01-23 18:01:09 +00:00
|
|
|
|
|
|
|
$('.functions button').removeClass('btnOn');
|
2015-01-29 18:24:00 +00:00
|
|
|
functionsInSelection.forEach(function(function_e) {
|
|
|
|
$(function_e).addClass('btnOn');
|
2015-01-23 18:01:09 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$('.directions button').removeClass('btnOn');
|
2015-01-29 18:24:00 +00:00
|
|
|
directionsInSelection.forEach(function(direction_e) {
|
|
|
|
$(direction_e).addClass('btnOn');
|
2015-01-23 18:01:09 +00:00
|
|
|
});
|
2015-01-09 01:11:46 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.mainGrid').disableSelection();
|
|
|
|
|
|
|
|
$('.gPoint').each(function(){
|
|
|
|
var gridNumber = ($(this).index() + 1);
|
|
|
|
var row = Math.ceil(gridNumber / 16) - 1;
|
|
|
|
var col = gridNumber/16 % 1 * 16 - 1;
|
|
|
|
if (col < 0) {
|
|
|
|
col = 15;
|
|
|
|
}
|
|
|
|
|
|
|
|
var ledResult = findLed(col, row);
|
|
|
|
if (!ledResult) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var ledIndex = ledResult.index;
|
|
|
|
var led = ledResult.led;
|
|
|
|
|
2015-01-23 01:12:20 +00:00
|
|
|
if (led.functions.length == 0 && led.directions.length == 0 && led.color == 0) {
|
2015-01-09 01:11:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$(this).find('.wire').html(ledIndex);
|
|
|
|
|
|
|
|
for (var modeIndex = 0; modeIndex < led.functions.length; modeIndex++) {
|
2015-01-16 00:15:41 +00:00
|
|
|
$(this).addClass('function-' + led.functions[modeIndex]);
|
2015-01-09 01:11:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (var directionIndex = 0; directionIndex < led.directions.length; directionIndex++) {
|
|
|
|
$(this).addClass('dir-' + led.directions[directionIndex]);
|
|
|
|
}
|
2015-01-23 01:12:20 +00:00
|
|
|
|
|
|
|
$(this).addClass('color-' + led.color);
|
2015-01-09 01:11:46 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
updateBulkCmd();
|
|
|
|
|
2015-01-16 00:15:41 +00:00
|
|
|
$('a.save').click(function () {
|
|
|
|
|
|
|
|
MSP.sendLedStripConfig(save_to_eeprom);
|
|
|
|
|
|
|
|
function save_to_eeprom() {
|
2015-01-16 00:29:16 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_EEPROM_WRITE, false, false, function() {
|
|
|
|
GUI.log(chrome.i18n.getMessage('ledStripEepromSaved'));
|
|
|
|
});
|
2015-01-16 00:15:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2015-01-09 01:11:46 +00:00
|
|
|
if (callback) callback();
|
|
|
|
}
|
|
|
|
|
|
|
|
function findLed(x, y) {
|
|
|
|
for (var ledIndex = 0; ledIndex < LED_STRIP.length; ledIndex++) {
|
|
|
|
var led = LED_STRIP[ledIndex];
|
|
|
|
if (led.x == x && led.y == y) {
|
|
|
|
return { index: ledIndex, led: led };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateBulkCmd() {
|
|
|
|
var counter = 0;
|
|
|
|
|
|
|
|
var lines = [];
|
2015-01-16 00:15:41 +00:00
|
|
|
var ledStripLength = LED_STRIP.length;
|
|
|
|
|
|
|
|
LED_STRIP = [];
|
2015-01-09 01:11:46 +00:00
|
|
|
|
|
|
|
$('.gPoint').each(function(){
|
2015-01-16 00:15:41 +00:00
|
|
|
if ($(this).is('[class*="function"]')) {
|
2015-01-09 01:11:46 +00:00
|
|
|
var gridNumber = ($(this).index() + 1);
|
|
|
|
var row = Math.ceil(gridNumber / 16) - 1;
|
|
|
|
var col = gridNumber/16 % 1 * 16 - 1;
|
|
|
|
if (col < 0) {col = 15;}
|
|
|
|
|
|
|
|
var wireNumber = $(this).find('.wire').html();
|
2015-01-16 00:15:41 +00:00
|
|
|
var functions = '';
|
2015-01-09 01:11:46 +00:00
|
|
|
var directions = '';
|
2015-01-23 01:12:20 +00:00
|
|
|
var colorIndex = 0;
|
2015-01-09 01:11:46 +00:00
|
|
|
var that = this;
|
2015-01-23 01:12:20 +00:00
|
|
|
|
|
|
|
var match = $(this).attr("class").match(/(^|\s)color-([0-9]+)(\s|$)/);
|
|
|
|
if (match) {
|
|
|
|
colorIndex = match[2];
|
|
|
|
}
|
|
|
|
|
2015-01-16 00:15:41 +00:00
|
|
|
TABS.led_strip.functions.forEach(function(letter){
|
|
|
|
if ($(that).is('.function-' + letter)) {
|
|
|
|
functions += letter;
|
2015-01-09 01:11:46 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-01-16 00:15:41 +00:00
|
|
|
TABS.led_strip.directions.forEach(function(letter){
|
2015-01-09 01:11:46 +00:00
|
|
|
if ($(that).is('.dir-' + letter)) {
|
2015-01-16 00:15:41 +00:00
|
|
|
directions += letter;
|
2015-01-09 01:11:46 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (wireNumber != '') {
|
2015-01-16 00:15:41 +00:00
|
|
|
var led = {
|
|
|
|
x: col,
|
|
|
|
y: row,
|
|
|
|
directions: directions,
|
2015-01-23 01:12:20 +00:00
|
|
|
functions: functions,
|
|
|
|
color: colorIndex
|
2015-01-16 00:15:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LED_STRIP[wireNumber] = led;
|
2015-01-09 01:11:46 +00:00
|
|
|
}
|
|
|
|
counter++;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-01-16 00:15:41 +00:00
|
|
|
var defaultLed = {
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
directions: '',
|
|
|
|
functions: ''
|
|
|
|
};
|
|
|
|
|
|
|
|
for (var i = 0; i < ledStripLength; i++) {
|
|
|
|
if (LED_STRIP[i]) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
LED_STRIP[i] = defaultLed;
|
|
|
|
}
|
|
|
|
|
2015-01-09 01:11:46 +00:00
|
|
|
var usedWireNumbers = buildUsedWireNumbers();
|
|
|
|
|
|
|
|
var remaining = LED_STRIP.length - usedWireNumbers.length;
|
2015-01-16 00:15:41 +00:00
|
|
|
|
2015-01-09 01:11:46 +00:00
|
|
|
$('.wires-remaining div').html(remaining);
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
TABS.led_strip.cleanup = function (callback) {
|
|
|
|
if (callback) callback();
|
|
|
|
};
|