From 875f3bfa15b84e6a572599ea37f0aeef55cb1bc0 Mon Sep 17 00:00:00 2001 From: cTn Date: Tue, 16 Sep 2014 19:27:30 +0200 Subject: [PATCH] first CAP_BASEFLIGHT_CONFIG implementation (unfinished) for initial tab, including temporary backwards compatibility support --- tabs/initial_setup.css | 62 ++++- tabs/initial_setup.html | 143 ++++++++---- tabs/initial_setup.js | 490 ++++++++++++++++++++++++++-------------- 3 files changed, 484 insertions(+), 211 deletions(-) diff --git a/tabs/initial_setup.css b/tabs/initial_setup.css index 6e7a0a26f9..c3e2cd0fda 100644 --- a/tabs/initial_setup.css +++ b/tabs/initial_setup.css @@ -1,3 +1,14 @@ +/* temporary styles that are used during compatibility period */ +.tab-initial_setup .CAP_BASEFLIGHT_CONFIG, +.tab-initial_setup .COMPATIBILITY { + display: none; + height: calc(100% - 142px); +} +.tab-initial_setup .CAP_BASEFLIGHT_CONFIG #interactive_block { + width: calc(100% - 411px); +} +/* temporary styles end*/ + .tab-initial_setup { height: 100%; } @@ -48,7 +59,7 @@ float: left; position: relative; - height: calc(100% - 142px); + height: 100%; width: calc(100% - 522px); border: 1px solid silver; @@ -119,6 +130,55 @@ .tab-initial_setup .block_wrapper { font-size: 0; } + +.tab-initial_setup .block { + float: left; + display: block; + + margin-left: 10px; + + border: 1px solid silver; +} +.tab-initial_setup .block .head { + display: block; + + text-align: center; + line-height: 20px; + font-weight: bold; + + border-bottom: 1px solid silver; + background-color: #ececec; +} +.tab-initial_setup .mixer { + width: 200px; +} +.tab-initial_setup .mixer .preview { + display: block; + + width: 200px; + height: 140px; + + margin: 5px 0 5px 0; +} +.tab-initial_setup .mixer select { + display: block; + + padding-left: 5px; + + width: 100%; + height: 20px; + line-height: 20px; + + font-weight: bold; + + border-top: 1px solid silver; +} +.tab-initial_setup .block .info { + width: 200px; +} + + + .tab-initial_setup .battery, .tab-initial_setup .throttle, .tab-initial_setup .acc-trim, diff --git a/tabs/initial_setup.html b/tabs/initial_setup.html index 0db8182ee2..427593c824 100644 --- a/tabs/initial_setup.html +++ b/tabs/initial_setup.html @@ -20,55 +20,44 @@

-
-
- -
- - - - -
-
-
- -
-
-
-
-
-
-
+
+
+
+
+ + +
-
- -
-
-
-
-
-
-
+
+ + +
-
- -
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
+
@@ -80,6 +69,68 @@
+
+
+
+ +
+ + + + +
+
+
+ +
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
0 V
+
0 mAh
+
0 A
+
0 %
+
+
+
+
+
diff --git a/tabs/initial_setup.js b/tabs/initial_setup.js index 0b6aa2042c..5e8482c25f 100644 --- a/tabs/initial_setup.js +++ b/tabs/initial_setup.js @@ -11,7 +11,15 @@ TABS.initial_setup.initialize = function (callback) { googleAnalytics.sendAppView('Initial Setup'); function load_ident() { - MSP.send_message(MSP_codes.MSP_IDENT, false, false, load_misc_data); + MSP.send_message(MSP_codes.MSP_IDENT, false, false, load_config); + } + + function load_config() { + if (bit_check(CONFIG.capability, 30)) { + MSP.send_message(MSP_codes.MSP_CONFIG, false, false, load_misc_data); + } else { + load_misc_data(); + } } function load_misc_data() { @@ -28,112 +36,320 @@ TABS.initial_setup.initialize = function (callback) { // translate to user-selected language localize(); - // initialize 3D - self.initialize3D(); + // if CAP_BASEFLIGHT_CONFIG (30) + if (bit_check(CONFIG.capability, 30)) { + // current stuff, this will become default when the compatibility period ends + $('.CAP_BASEFLIGHT_CONFIG').show(); - // Fill in misc stuff - $('input[name="mincellvoltage"]').val(MISC.vbatmincellvoltage); - $('input[name="maxcellvoltage"]').val(MISC.vbatmaxcellvoltage); - $('input[name="voltagescale"]').val(MISC.vbatscale); + // initialize 3D + self.initialize3D(false); - $('input[name="minthrottle"]').val(MISC.minthrottle); - $('input[name="maxthrottle"]').val(MISC.maxthrottle); - $('input[name="failsafe_throttle"]').val(MISC.failsafe_throttle); - $('input[name="mincommand"]').val(MISC.mincommand); + // Display multiType and motor diagram (if such exist) + var str; + switch (CONFIG.multiType) { + case 1: // TRI + str = 'TRI'; + break; + case 2: // QUAD + + str = 'Quad +'; + break; + case 3: // QUAD X + str = 'Quad X'; + break; + case 4: // BI + str = 'BI'; + break; + case 5: // GIMBAL + str = 'Gimbal'; + break; + case 6: // Y6 + str = 'Y6'; + break; + case 7: // HEX 6 + str = 'HEX 6'; + break; + case 8: // FLYING_WING + str = 'Flying Wing'; + break; + case 9: // Y4 + str = 'Y4'; + break; + case 10: // HEX6 X + str = 'HEX6 X'; + break; + case 11: // OCTO X8 + case 12: + case 13: + str = 'OCTO X8'; + break; + case 14: // AIRPLANE + str = 'Airplane'; + break; + case 15: // Heli 120 + str = 'Heli 120'; + break; + case 16: // Heli 90 + str = 'Heli 90'; + break; + case 17: // Vtail + str = 'Vtail'; + break; + case 18: // HEX6 H + str = 'HEX6 H'; + break; + case 19: // PPM to SERVO + str = 'PPM to SERVO'; + break; + case 20: // Dualcopter + str = 'Dualcopter'; + break; + case 21: // Singlecopter + str = 'Singlecopter'; + break; + case 22: // Custom + str = 'Custom'; + break; + } - $('input[name="mag_declination"]').val(MISC.mag_declination / 10); + // set model name in interactive block + $('span.model').text(chrome.i18n.getMessage('initialSetupModel', [str])); - // Fill in the accel trimms from CONFIG object - $('input[name="pitch"]').val(CONFIG.accelerometerTrims[0]); - $('input[name="roll"]').val(CONFIG.accelerometerTrims[1]); + // set heading in interactive block + $('span.heading').text(chrome.i18n.getMessage('initialSetupheading', [0])); - // Display multiType and motor diagram (if such exist) - var str = ''; - switch (CONFIG.multiType) { - case 1: // TRI - str = 'TRI'; - $('.modelMixDiagram').attr('src', './images/motor_order/tri.svg').addClass('modelMixTri'); - break; - case 2: // QUAD + - str = 'Quad +'; - $('.modelMixDiagram').attr('src', './images/motor_order/quadp.svg').addClass('modelMixQuadP'); - break; - case 3: // QUAD X - str = 'Quad X'; - $('.modelMixDiagram').attr('src', './images/motor_order/quadx.svg').addClass('modelMixQuadX'); - break; - case 4: // BI - str = 'BI'; - break; - case 5: // GIMBAL - str = 'Gimbal'; - break; - case 6: // Y6 - str = 'Y6'; - $('.modelMixDiagram').attr('src', './images/motor_order/y6.svg').addClass('modelMixY6'); - break; - case 7: // HEX 6 - str = 'HEX 6'; - $('.modelMixDiagram').attr('src', './images/motor_order/hex6p.svg').addClass('modelMixHex6P'); - break; - case 8: // FLYING_WING - str = 'Flying Wing'; - break; - case 9: // Y4 - str = 'Y4'; - $('.modelMixDiagram').attr('src', './images/motor_order/y4.svg').addClass('modelMixY4'); - break; - case 10: // HEX6 X - str = 'HEX6 X'; - $('.modelMixDiagram').attr('src', './images/motor_order/hex6x.svg').addClass('modelMixHex6X'); - break; - case 11: // OCTO X8 - case 12: - case 13: - str = 'OCTO X8'; - $('.modelMixDiagram').attr('src', './images/motor_order/octox.svg').addClass('modelMixOctoX'); - break; - case 14: // AIRPLANE - str = 'Airplane'; - $('.modelMixDiagram').attr('src', './images/motor_order/airplane.svg').addClass('modelMixAirplane'); - break; - case 15: // Heli 120 - str = 'Heli 120'; - break; - case 16: // Heli 90 - str = 'Heli 90'; - break; - case 17: // Vtail - str = 'Vtail'; - $('.modelMixDiagram').attr('src', './images/motor_order/vtail.svg').addClass('modelMixVtail'); - break; - case 18: // HEX6 H - str = 'HEX6 H'; - $('.modelMixDiagram').attr("src", './images/motor_order/custom.svg').addClass('modelMixCustom'); - break; - case 19: // PPM to SERVO - str = 'PPM to SERVO'; - $('.modelMixDiagram').attr("src", './images/motor_order/custom.svg').addClass('modelMixCustom'); - break; - case 20: // Dualcopter - str = 'Dualcopter'; - $('.modelMixDiagram').attr("src", './images/motor_order/custom.svg').addClass('modelMixCustom'); - break; - case 21: // Singlecopter - str = 'Singlecopter'; - $('.modelMixDiagram').attr("src", './images/motor_order/custom.svg').addClass('modelMixCustom'); - break; - case 22: // Custom - str = 'Custom'; - $('.modelMixDiagram').attr("src", './images/motor_order/custom.svg').addClass('modelMixCustom'); - break; + // UI hook handling mixer type change that swaps the image representation + $('.mixer select').change(function () { + var val = $(this).val(); + + var imageArray = [ + 'custom', // there is no type 0, we will use custom image as spacer + 'tri', + 'quadp', + 'quadx', + 'custom', // bi + 'custom', // gimbal + 'y6', + 'hex6p', + 'custom', // flying wing + 'y4', + 'hex6x', + 'octox', + 'octox', + 'octox', + 'airplane', + 'custom', + 'custom', + 'vtail', + 'custom', + 'custom', + 'custom', + 'custom', + 'custom', + ]; + + $('.mixer .preview').attr('src', './images/motor_order/' + imageArray[val] + '.svg'); + }); + + // update mixer type with current value + $('.mixer select').val(BF_CONFIG.mixerConfiguration).change(); + + // save + $('a.update').click(function () { + // update object + BF_CONFIG.mixerConfiguration = parseInt($('.mixer select').val()); + + function save_to_eeprom() { + MSP.send_message(MSP_codes.MSP_EEPROM_WRITE, false, false, reboot); + } + + function reboot() { + GUI.log(chrome.i18n.getMessage('initialSetupEepromSaved')); + GUI.tab_switch_cleanup(); + + MSP.send_message(MSP_codes.MSP_SET_REBOOT, false, false, reinitialize); + } + + function reinitialize() { + GUI.log(chrome.i18n.getMessage('deviceRebooting')); + + MSP.send_message(MSP_codes.MSP_IDENT, false, false, function () { + GUI.log(chrome.i18n.getMessage('deviceReady')); + TABS.initial_setup.initialize(); + }); + } + + MSP.send_message(MSP_codes.MSP_SET_CONFIG, MSP.crunch('BF_CONFIG'), false, save_to_eeprom); // TODO reply byte is missing on the firmware side so this is where it fails + }); + } else { + // old stuff + $('.COMPATIBILITY').show(); + + // initialize 3D + self.initialize3D(true); + + // Fill in misc stuff + $('input[name="mincellvoltage"]').val(MISC.vbatmincellvoltage); + $('input[name="maxcellvoltage"]').val(MISC.vbatmaxcellvoltage); + $('input[name="voltagescale"]').val(MISC.vbatscale); + + $('input[name="minthrottle"]').val(MISC.minthrottle); + $('input[name="maxthrottle"]').val(MISC.maxthrottle); + $('input[name="failsafe_throttle"]').val(MISC.failsafe_throttle); + $('input[name="mincommand"]').val(MISC.mincommand); + + $('input[name="mag_declination"]').val(MISC.mag_declination / 10); + + // Fill in the accel trimms from CONFIG object + $('input[name="pitch"]').val(CONFIG.accelerometerTrims[0]); + $('input[name="roll"]').val(CONFIG.accelerometerTrims[1]); + + // Display multiType and motor diagram (if such exist) + var str; + switch (CONFIG.multiType) { + case 1: // TRI + str = 'TRI'; + $('.modelMixDiagram').attr('src', './images/motor_order/tri.svg').addClass('modelMixTri'); + break; + case 2: // QUAD + + str = 'Quad +'; + $('.modelMixDiagram').attr('src', './images/motor_order/quadp.svg').addClass('modelMixQuadP'); + break; + case 3: // QUAD X + str = 'Quad X'; + $('.modelMixDiagram').attr('src', './images/motor_order/quadx.svg').addClass('modelMixQuadX'); + break; + case 4: // BI + str = 'BI'; + break; + case 5: // GIMBAL + str = 'Gimbal'; + break; + case 6: // Y6 + str = 'Y6'; + $('.modelMixDiagram').attr('src', './images/motor_order/y6.svg').addClass('modelMixY6'); + break; + case 7: // HEX 6 + str = 'HEX 6'; + $('.modelMixDiagram').attr('src', './images/motor_order/hex6p.svg').addClass('modelMixHex6P'); + break; + case 8: // FLYING_WING + str = 'Flying Wing'; + break; + case 9: // Y4 + str = 'Y4'; + $('.modelMixDiagram').attr('src', './images/motor_order/y4.svg').addClass('modelMixY4'); + break; + case 10: // HEX6 X + str = 'HEX6 X'; + $('.modelMixDiagram').attr('src', './images/motor_order/hex6x.svg').addClass('modelMixHex6X'); + break; + case 11: // OCTO X8 + case 12: + case 13: + str = 'OCTO X8'; + $('.modelMixDiagram').attr('src', './images/motor_order/octox.svg').addClass('modelMixOctoX'); + break; + case 14: // AIRPLANE + str = 'Airplane'; + $('.modelMixDiagram').attr('src', './images/motor_order/airplane.svg').addClass('modelMixAirplane'); + break; + case 15: // Heli 120 + str = 'Heli 120'; + break; + case 16: // Heli 90 + str = 'Heli 90'; + break; + case 17: // Vtail + str = 'Vtail'; + $('.modelMixDiagram').attr('src', './images/motor_order/vtail.svg').addClass('modelMixVtail'); + break; + case 18: // HEX6 H + str = 'HEX6 H'; + $('.modelMixDiagram').attr("src", './images/motor_order/custom.svg').addClass('modelMixCustom'); + break; + case 19: // PPM to SERVO + str = 'PPM to SERVO'; + $('.modelMixDiagram').attr("src", './images/motor_order/custom.svg').addClass('modelMixCustom'); + break; + case 20: // Dualcopter + str = 'Dualcopter'; + $('.modelMixDiagram').attr("src", './images/motor_order/custom.svg').addClass('modelMixCustom'); + break; + case 21: // Singlecopter + str = 'Singlecopter'; + $('.modelMixDiagram').attr("src", './images/motor_order/custom.svg').addClass('modelMixCustom'); + break; + case 22: // Custom + str = 'Custom'; + $('.modelMixDiagram').attr("src", './images/motor_order/custom.svg').addClass('modelMixCustom'); + break; + } + + $('span.model').text(chrome.i18n.getMessage('initialSetupModel', [str])); + + // Heading + $('span.heading').text(chrome.i18n.getMessage('initialSetupheading', [0])); + + $('a.update').click(function () { + CONFIG.accelerometerTrims[0] = parseInt($('input[name="pitch"]').val()); + CONFIG.accelerometerTrims[1] = parseInt($('input[name="roll"]').val()); + + var buffer_out = new Array(); + buffer_out[0] = lowByte(CONFIG.accelerometerTrims[0]); + buffer_out[1] = highByte(CONFIG.accelerometerTrims[0]); + buffer_out[2] = lowByte(CONFIG.accelerometerTrims[1]); + buffer_out[3] = highByte(CONFIG.accelerometerTrims[1]); + + // Send over the new trims + MSP.send_message(MSP_codes.MSP_SET_ACC_TRIM, buffer_out); + + MISC.vbatmincellvoltage = parseFloat($('input[name="mincellvoltage"]').val()) * 10; + MISC.vbatmaxcellvoltage = parseFloat($('input[name="maxcellvoltage"]').val()) * 10; + MISC.vbatscale = parseInt($('input[name="voltagescale"]').val()); + + MISC.minthrottle = parseInt($('input[name="minthrottle"]').val()); + MISC.maxthrottle = parseInt($('input[name="maxthrottle"]').val()); + MISC.failsafe_throttle = parseInt($('input[name="failsafe_throttle"]').val()); + MISC.mincommand = parseInt($('input[name="mincommand"]').val()); + + MISC.mag_declination = parseFloat($('input[name="mag_declination"]').val()) * 10; + + // we also have to fill the unsupported bytes + var buffer_out = new Array(); + buffer_out[0] = 0; // powerfailmeter + buffer_out[1] = 0; + buffer_out[2] = lowByte(MISC.minthrottle); + buffer_out[3] = highByte(MISC.minthrottle); + buffer_out[4] = lowByte(MISC.maxthrottle); + buffer_out[5] = highByte(MISC.maxthrottle); + buffer_out[6] = lowByte(MISC.mincommand); + buffer_out[7] = highByte(MISC.mincommand); + buffer_out[8] = lowByte(MISC.failsafe_throttle); + buffer_out[9] = highByte(MISC.failsafe_throttle); + buffer_out[10] = 0; + buffer_out[11] = 0; + buffer_out[12] = 0; + buffer_out[13] = 0; + buffer_out[14] = 0; + buffer_out[15] = 0; + buffer_out[16] = lowByte(MISC.mag_declination); + buffer_out[17] = highByte(MISC.mag_declination); + buffer_out[18] = MISC.vbatscale; + buffer_out[19] = MISC.vbatmincellvoltage; + buffer_out[20] = MISC.vbatmaxcellvoltage; + buffer_out[21] = 0; // vbatlevel_crit (unused) + + // Send over new misc + MSP.send_message(MSP_codes.MSP_SET_MISC, buffer_out, false, save_to_eeprom); + + function save_to_eeprom() { + MSP.send_message(MSP_codes.MSP_EEPROM_WRITE, false, false, function () { + GUI.log(chrome.i18n.getMessage('initialSetupEepromSaved')); + }); + } + }); } - $('span.model').text(chrome.i18n.getMessage('initialSetupModel', [str])); - - // Heading - $('span.heading').text(chrome.i18n.getMessage('initialSetupheading', [0])); - // UI Hooks $('a.calibrateAccel').click(function () { var self = $(this); @@ -185,66 +401,6 @@ TABS.initial_setup.initialize = function (callback) { }); }); - - $('a.update').click(function () { - CONFIG.accelerometerTrims[0] = parseInt($('input[name="pitch"]').val()); - CONFIG.accelerometerTrims[1] = parseInt($('input[name="roll"]').val()); - - var buffer_out = new Array(); - buffer_out[0] = lowByte(CONFIG.accelerometerTrims[0]); - buffer_out[1] = highByte(CONFIG.accelerometerTrims[0]); - buffer_out[2] = lowByte(CONFIG.accelerometerTrims[1]); - buffer_out[3] = highByte(CONFIG.accelerometerTrims[1]); - - // Send over the new trims - MSP.send_message(MSP_codes.MSP_SET_ACC_TRIM, buffer_out); - - MISC.vbatmincellvoltage = parseFloat($('input[name="mincellvoltage"]').val()) * 10; - MISC.vbatmaxcellvoltage = parseFloat($('input[name="maxcellvoltage"]').val()) * 10; - MISC.vbatscale = parseInt($('input[name="voltagescale"]').val()); - - MISC.minthrottle = parseInt($('input[name="minthrottle"]').val()); - MISC.maxthrottle = parseInt($('input[name="maxthrottle"]').val()); - MISC.failsafe_throttle = parseInt($('input[name="failsafe_throttle"]').val()); - MISC.mincommand = parseInt($('input[name="mincommand"]').val()); - - MISC.mag_declination = parseFloat($('input[name="mag_declination"]').val()) * 10; - - // we also have to fill the unsupported bytes - var buffer_out = new Array(); - buffer_out[0] = 0; // powerfailmeter - buffer_out[1] = 0; - buffer_out[2] = lowByte(MISC.minthrottle); - buffer_out[3] = highByte(MISC.minthrottle); - buffer_out[4] = lowByte(MISC.maxthrottle); - buffer_out[5] = highByte(MISC.maxthrottle); - buffer_out[6] = lowByte(MISC.mincommand); - buffer_out[7] = highByte(MISC.mincommand); - buffer_out[8] = lowByte(MISC.failsafe_throttle); - buffer_out[9] = highByte(MISC.failsafe_throttle); - buffer_out[10] = 0; - buffer_out[11] = 0; - buffer_out[12] = 0; - buffer_out[13] = 0; - buffer_out[14] = 0; - buffer_out[15] = 0; - buffer_out[16] = lowByte(MISC.mag_declination); - buffer_out[17] = highByte(MISC.mag_declination); - buffer_out[18] = MISC.vbatscale; - buffer_out[19] = MISC.vbatmincellvoltage; - buffer_out[20] = MISC.vbatmaxcellvoltage; - buffer_out[21] = 0; // vbatlevel_crit (unused) - - // Send over new misc - MSP.send_message(MSP_codes.MSP_SET_MISC, buffer_out, false, save_to_eeprom); - - function save_to_eeprom() { - MSP.send_message(MSP_codes.MSP_EEPROM_WRITE, false, false, function () { - GUI.log(chrome.i18n.getMessage('initialSetupEepromSaved')); - }); - } - }); - // display current yaw fix value (important during tab re-initialization) $('div#interactive_block > a.reset').text(chrome.i18n.getMessage('initialSetupButtonResetZaxisValue', [self.yaw_fix])); @@ -286,7 +442,7 @@ TABS.initial_setup.initialize = function (callback) { GUI.interval_add('initial_setup_data_pull', get_analog_data, 50, true); // status data pulled via separate timer with static speed - GUI.interval_add('status_pull', function () { + GUI.interval_add('status_pull', function status_pull () { MSP.send_message(MSP_codes.MSP_STATUS); }, 250, true); @@ -294,10 +450,16 @@ TABS.initial_setup.initialize = function (callback) { } }; -TABS.initial_setup.initialize3D = function () { +TABS.initial_setup.initialize3D = function (compatibility) { var self = this; - var canvas = $('#canvas'); - var wrapper = $('#canvas_wrapper'); + + if (compatibility) { + var canvas = $('.COMPATIBILITY #canvas'); + var wrapper = $('.COMPATIBILITY #canvas_wrapper'); + } else { + var canvas = $('.CAP_BASEFLIGHT_CONFIG #canvas'); + var wrapper = $('.CAP_BASEFLIGHT_CONFIG #canvas_wrapper'); + } var camera = new THREE.PerspectiveCamera(50, wrapper.width() / wrapper.height(), 1, 10000);