1
0
Fork 0
mirror of https://github.com/iNavFlight/inav-configurator.git synced 2025-07-23 16:25:19 +03:00

Code Review

Correction on indentation + Mission validation
This commit is contained in:
ArnoTlse 2021-02-22 14:10:52 +01:00
parent 9745aee718
commit d3a48e0f56
8 changed files with 824 additions and 696 deletions

View file

@ -0,0 +1,219 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="32"
height="32"
viewBox="0 0 8.4666667 8.4666667"
version="1.1"
id="svg8"
inkscape:version="1.0.1 (3bc2e813f5, 2020-09-07)"
sodipodi:docname="cf_icon_MP_save2file.svg">
<defs
id="defs2">
<filter
inkscape:collect="always"
style="color-interpolation-filters:sRGB"
id="filter920"
x="-1.3837457e-05"
width="1.0000277"
y="-1.3373132e-05"
height="1.0000267">
<feGaussianBlur
inkscape:collect="always"
stdDeviation="1.3311481e-05"
id="feGaussianBlur922" />
</filter>
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="25.455844"
inkscape:cx="17.94419"
inkscape:cy="15.357511"
inkscape:document-units="mm"
inkscape:current-layer="layer2"
inkscape:document-rotation="0"
showgrid="false"
units="px"
inkscape:window-width="1368"
inkscape:window-height="850"
inkscape:window-x="-6"
inkscape:window-y="-6"
inkscape:window-maximized="1" />
<metadata
id="metadata5">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:groupmode="layer"
id="layer2"
inkscape:label="Calque 2">
<rect
style="opacity:0.994175;fill:#000000;fill-opacity:1;stroke:#ffffff;stroke-width:3.175;stroke-linecap:round;stroke-linejoin:round;stroke-dashoffset:100"
id="rect836"
width="8.8929396"
height="8.7165508"
x="0.029398149"
y="0.014699074" />
</g>
<g
inkscape:label="Calque 1"
inkscape:groupmode="layer"
id="layer1"
style="display:inline">
<rect
style="opacity:0.994175;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:3.175;stroke-linecap:round;stroke-linejoin:round;stroke-dashoffset:100"
id="rect838"
width="3.1896987"
height="4.2627311"
x="2.8810186"
y="2.2416089"
ry="0.14699078" />
<rect
style="opacity:0.994175;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:3.175;stroke-linecap:round;stroke-linejoin:round;stroke-dashoffset:100"
id="rect840"
width="0.10289352"
height="0.1175926"
x="4.2774305"
y="4.2333331"
ry="0.051446758" />
</g>
<g
inkscape:groupmode="layer"
id="layer3"
inkscape:label="coin"
style="display:inline;opacity:0.980775;filter:url(#filter920)">
<path
sodipodi:type="star"
style="opacity:0.994175;fill:none;fill-opacity:1;stroke:#000000;stroke-width:0;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:100;stroke-opacity:1"
id="path851"
sodipodi:sides="3"
sodipodi:cx="5.5856476"
sodipodi:cy="2.6752317"
sodipodi:r1="1.4524583"
sodipodi:r2="0.48779002"
sodipodi:arg1="2.1981044"
sodipodi:arg2="3.245302"
inkscape:flatsided="true"
inkscape:rounded="0"
inkscape:randomized="0"
d="M 4.7331018,3.8511572 4.9935391,1.3489427 7.0303018,2.8255952 Z"
inkscape:transform-center-x="-0.24768571"
transform="matrix(1.0496075,0.44790841,0.11075364,1,-0.47061262,-2.5315702)"
inkscape:transform-center-y="-0.2423188" />
<path
sodipodi:type="star"
style="opacity:0.994175;fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:0.00160072;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:7.55905;stroke-opacity:1;paint-order:normal"
id="path878"
sodipodi:sides="3"
sodipodi:cx="4.531703"
sodipodi:cy="3.5546846"
sodipodi:r1="1.1501029"
sodipodi:r2="0.57505137"
sodipodi:arg1="1.5707963"
sodipodi:arg2="2.6179939"
inkscape:flatsided="true"
inkscape:rounded="0"
inkscape:randomized="0"
d="m 4.531703,4.7047875 -0.9960183,-1.7251543 1.9920366,0 z"
inkscape:transform-center-y="0.1930168"
transform="matrix(0,0.58136529,-0.67130283,-0.33565141,8.0709536,1.1862026)"
inkscape:transform-center-x="0.19301688" />
<path
sodipodi:type="star"
style="opacity:0.994175;fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:0.00160072;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:7.55905;stroke-opacity:1;paint-order:normal"
id="path924"
sodipodi:sides="3"
sodipodi:cx="4.531703"
sodipodi:cy="3.5546846"
sodipodi:r1="1.1501029"
sodipodi:r2="0.57505137"
sodipodi:arg1="1.5707963"
sodipodi:arg2="2.6179939"
inkscape:flatsided="true"
inkscape:rounded="0"
inkscape:randomized="0"
d="m 4.531703,4.7047875 -0.9960183,-1.7251543 1.9920366,0 z"
inkscape:transform-center-y="0.1930168"
transform="matrix(0,0.58136529,-0.67130283,-0.33565141,8.0709536,1.1862026)"
inkscape:transform-center-x="0.19301688" />
</g>
<g
inkscape:groupmode="layer"
id="g932"
inkscape:label="coin_decoupe"
style="display:inline;opacity:0.980775;filter:url(#filter920)">
<path
sodipodi:type="star"
style="opacity:0.994175;fill:none;fill-opacity:1;stroke:#000000;stroke-width:0;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:100;stroke-opacity:1"
id="path926"
sodipodi:sides="3"
sodipodi:cx="5.5856476"
sodipodi:cy="2.6752317"
sodipodi:r1="1.4524583"
sodipodi:r2="0.48779002"
sodipodi:arg1="2.1981044"
sodipodi:arg2="3.245302"
inkscape:flatsided="true"
inkscape:rounded="0"
inkscape:randomized="0"
d="M 4.7331018,3.8511572 4.9935391,1.3489427 7.0303018,2.8255952 Z"
inkscape:transform-center-x="-0.24768571"
transform="matrix(1.0496075,0.44790841,0.11075364,1,-0.47061262,-2.5315702)"
inkscape:transform-center-y="-0.2423188" />
<path
sodipodi:type="star"
style="opacity:0.994175;fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:0.00160072;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:7.55905;stroke-opacity:1;paint-order:normal"
id="path928"
sodipodi:sides="3"
sodipodi:cx="4.531703"
sodipodi:cy="3.5546846"
sodipodi:r1="1.1501029"
sodipodi:r2="0.57505137"
sodipodi:arg1="1.5707963"
sodipodi:arg2="2.6179939"
inkscape:flatsided="true"
inkscape:rounded="0"
inkscape:randomized="0"
d="m 4.531703,4.7047875 -0.9960183,-1.7251543 1.9920366,0 z"
inkscape:transform-center-y="0.1930168"
transform="matrix(0,0.58136529,-0.67130283,-0.33565141,8.0709536,1.1862026)"
inkscape:transform-center-x="0.19301688" />
<path
sodipodi:type="star"
style="opacity:0.994175;fill:none;fill-opacity:1;stroke:#000000;stroke-width:0.203596;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:0;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:normal"
id="path930"
sodipodi:sides="3"
sodipodi:cx="4.531703"
sodipodi:cy="3.5546846"
sodipodi:r1="1.1501029"
sodipodi:r2="0.57505137"
sodipodi:arg1="1.5707963"
sodipodi:arg2="2.6179939"
inkscape:flatsided="true"
inkscape:rounded="0"
inkscape:randomized="0"
d="m 4.531703,4.7047875 -0.9960183,-1.7251543 1.9920366,0 z"
inkscape:transform-center-y="-0.23115762"
transform="matrix(0,-0.69624532,0.80395486,0.40197743,2.4520438,4.7798234)"
inkscape:transform-center-x="-0.23115767" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 8.2 KiB

BIN
images/icons/save2file.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 604 B

View file

@ -14,7 +14,7 @@
display: block;
cursor: pointer;
transition: all ease 0.2s;
padding: 0 9px;
padding: 0 0 0 20px;
line-height: 28px;
margin: 5px;
float: left;
@ -22,11 +22,17 @@
text-align: center;
}
.tab-mission-control .btn a:hover {
background-color: #3394b5;
transition: all ease 0.2s;
}
.tab-mission-control .ic_save {
background-image: url(../images/icons/cf_icon_mission_white.svg);
}
.tab-mission-control .btn a:active {
background-color: #37a8db;
transition: all ease 0.0s;
@ -199,3 +205,4 @@
.tab-mission-control .missionTable tr:nth-child(even) th {
background-color: #ebe7e7;
}

View file

@ -26,13 +26,6 @@
</div>
</div>
</div>
<!--<div id="missionPlanerTemplate" class="gui_box grey" style="display: none">
<div class="gui_box_titlebar">
<div class="spacer_box_title i18n-replaced" data-i18n="missionTemplateHead">Mission Template</div>
</div>
<div class="spacer">
</div>
</div>-->
<div id="missionPlanerTotalInfo" class="gui_box grey">
<div class="gui_box_titlebar">
<div class="spacer_box_title i18n-replaced" data-i18n="missionTotalInformationHead">Total information</div>
@ -51,20 +44,10 @@
<div id="missionValid" style="display: inline-block"></div>
</div>
<br>
<!--<div style="display: flex;">
<input type="checkbox" style="width: 18px; margin-left: 5px;" id="rthEndMission">
<label for="rthEndMission" style="padding: 2px;">RTH at the end of the mission</label>
</div>
<div id="rthSettings" style="display: none">
<div style="display: flex">
<input type="checkbox" id="rthLanding" style="width: 18px; margin-left: 5px;">
<label for="rthLanding" style="padding: 2px">Landing</label>
</div>
</div>-->
<hr>
<div class="btn save_btn">
<a id="loadFileMissionButton" class="save" href="#" data-i18n="loadFileMissionButton">Load file mission</a>
<a id="saveFileMissionButton" class="save" href="#" data-i18n="saveFileMissionButton">Save file mission</a>
<a id="loadFileMissionButton" class="tabicon ic_save2file" href="#" data-i18n="loadFileMissionButton">Load file mission</a>
<a id="saveFileMissionButton" class="tabicon ic_save2file" href="#" data-i18n="saveFileMissionButton">Save file mission</a>
</div>
<div class="btn save_btn">
<a id="loadMissionButton" class="save" href="#" data-i18n="loadMissionButton">Load mission from FC</a>

View file

@ -76,13 +76,6 @@ TABS.mission_control.initialize = function (callback) {
loadHtml();
}
function updateTotalInfo() {
if (CONFIGURATOR.connectionValid) {
$('#availablePoints').text(MISSION_PLANER.countBusyPoints + '/' + MISSION_PLANER.maxWaypoints);
$('#missionValid').html(MISSION_PLANER.isValidMission ? chrome.i18n.getMessage('armingCheckPass') : chrome.i18n.getMessage('armingCheckFail'));
}
}
function loadHtml() {
GUI.load("./tabs/mission_control.html", process_html);
}
@ -335,6 +328,9 @@ TABS.mission_control.initialize = function (callback) {
var actionPointForSend = 0;
var settings = { speed: 0, alt: 5000};
/////////////////////////////////////////////
// Reinit Form
/////////////////////////////////////////////
// Function to clear/reinit Jquery variable
function clearEditForm() {
$('#pointLat').val('');
@ -352,6 +348,9 @@ TABS.mission_control.initialize = function (callback) {
$('#MPeditPoint').fadeOut(300);
}
/////////////////////////////////////////////
// Manage Settings
/////////////////////////////////////////////
function loadSettings() {
chrome.storage.local.get('missionPlanerSettings', function (result) {
if (result.missionPlanerSettings) {
@ -370,6 +369,17 @@ TABS.mission_control.initialize = function (callback) {
$('#MPdefaultPointSpeed').val(settings.speed);
}
function closeSettingsPanel() {
$('#missionPlanerSettings').hide();
$('#missionPlanerTotalInfo').fadeIn(300);
if (selectedMarker !== null) {
$('#MPeditPoint').fadeIn(300);
}
}
/////////////////////////////////////////////
// Manage Plotting functions
/////////////////////////////////////////////
// Function to repaint lines between markers
function repaint() {
var oldPos;
@ -417,10 +427,8 @@ TABS.mission_control.initialize = function (callback) {
}
// If one is SET_HEAD, draw labelled line in-between with heading value
else if (typeof oldPos !== 'undefined' && activatePoi != true && activateHead == true) {
console.log(oldHeading);
paintLine(oldPos, geometry.getCoordinates(), '#1497f1', 0, lineText=String(oldHeading)+"°");
}
// If classic WPs is defined with a JUMP options, draw pink dashed line in-between
if (options.key == "JUMP") {
paintLine(geometry.getCoordinates(), markers[options.targetWP-1].getSource().getFeatures()[0].getGeometry().getCoordinates(), '#e935d6', 5, "Repeat x"+String(options.numRepeat));
@ -447,7 +455,7 @@ TABS.mission_control.initialize = function (callback) {
}
}
// function modified to tale into account optional arguement such color, linedash and line label
// function modified to take into account optional argument such color, linedash and line label
function paintLine(pos1, pos2, color='#1497f1', lineDash=0, lineText="") {
var line = new ol.geom.LineString([pos1, pos2]);
@ -553,6 +561,9 @@ TABS.mission_control.initialize = function (callback) {
return vectorLayer;
}
/////////////////////////////////////////////
// Manage Map construction
/////////////////////////////////////////////
function initMap() {
var app = {};
@ -633,41 +644,6 @@ TABS.mission_control.initialize = function (callback) {
};
ol.inherits(app.PlannerSettingsControl, ol.control.Control);
/**
* @constructor
* @extends {ol.control.Control}
* @param {Object=} opt_options Control options.
*/
/*app.PlannerTemplateControl = function (opt_options) {
var options = opt_options || {};
var button = document.createElement('button');
button.innerHTML = ' ';
button.style = 'background: url(\'../images/CF_template_white.svg\') no-repeat 1px -1px;background-color: rgba(0,60,136,.5);';
var handleShowTemplate = function () {
$('#MPeditPoint, #missionPlanerTotalInfo', '#missionPlanerSettings').hide();
$('#missionPlanerTemplate').fadeIn(300);
};
button.addEventListener('click', handleShowTemplate, false);
button.addEventListener('touchstart', handleShowTemplate, false);
var element = document.createElement('div');
element.className = 'mission-control-template ol-unselectable ol-control';
element.appendChild(button);
element.title = 'MP Template';
ol.control.Control.call(this, {
element: element,
target: options.target
});
};
ol.inherits(app.PlannerTemplateControl, ol.control.Control);
*/
/**
* @param {ol.MapBrowserEvent} evt Map browser event.
* @return {boolean} `true` to start the drag sequence.
@ -829,12 +805,9 @@ TABS.mission_control.initialize = function (callback) {
});
if (selectedFeature)
{
for (var i in markers)
{
if (markers[i] == tempMarker)
{
if (selectedFeature) {
for (var i in markers) {
if (markers[i] == tempMarker) {
selectedMarker = tempMarker;
var geometry = selectedFeature.getGeometry();
@ -856,7 +829,6 @@ TABS.mission_control.initialize = function (callback) {
$('[name=Options]').filter('[value='+selectedMarker.options['key']+']').prop('checked', true);
// Manage RTH, JUMP, SET_HEAD options for WP
if (selectedMarker.options.key == "RTH") {
console.log(selectedMarker.options.landAfter);
$('#Options_LandRTH').prop('checked', selectedMarker.options.landAfter);
}
else if (selectedMarker.options.key == "JUMP") {
@ -867,10 +839,8 @@ TABS.mission_control.initialize = function (callback) {
$('#Options_HeadingHead').val(selectedMarker.options.heading);
}
// Selection box update depending on choice of type of waypoint
for (var j in dictOfLabelParameterPoint[selectedMarker.action])
{
if (dictOfLabelParameterPoint[selectedMarker.action][j] != '')
{
for (var j in dictOfLabelParameterPoint[selectedMarker.action]) {
if (dictOfLabelParameterPoint[selectedMarker.action][j] != '') {
$('#pointP'+String(j).slice(-1)+'class').fadeIn(300);
$('label[for=pointP'+String(j).slice(-1)+']').html(dictOfLabelParameterPoint[selectedMarker.action][j]);
}
@ -883,7 +853,8 @@ TABS.mission_control.initialize = function (callback) {
$('#MPeditPoint').fadeIn(300);
}
}
} else {
}
else {
map.addLayer(addMarker(evt.coordinate, settings.alt, MWNP.WPTYPE.WAYPOINT, settings.speed));
repaint();
}
@ -947,24 +918,29 @@ TABS.mission_control.initialize = function (callback) {
geometry.setCoordinates(ol.proj.fromLonLat([parseFloat($('#pointLon').val()), parseFloat($('#pointLat').val())]));
t.alt = $('#pointAlt').val();
t.action = $('#pointType').val();
console.log(typeof t.action);
// if action is Set_POI, PH_UNLIM, LAND, set parameter_i to 0
if (t.action == '5' || t.action == '2' || t.action == '8') {
t.parameter1 = 0;
t.parameter2 = 0;
t.parameter3 = 0;
}
// else for other kind of waypoints, set parameter_i to pointP_i value
else {
console.log("$('#pointP1').val() : ",$('#pointP1').val());
t.parameter1 = $('#pointP1').val();
t.parameter2 = $('#pointP2').val();
t.parameter3 = $('#pointP3').val();
}
// Manage Options
// if RTH options selected, store GUI value in t.options
if ($('input[name=Options]:checked').val() == "RTH") {
t.options = {key: $('input[name=Options]:checked').val(),
landAfter: $('#Options_LandRTH').prop('checked')
};
}
// if JUMP options selected, store GUI value in t.options
else if ($('input[name=Options]:checked').val() == "JUMP") {
// check if users input values verify the condition i an integer btw [0,99] and within length of Markers
if (!Array.from({length: markers.length}, (v, i) => i+1).includes(Number($('#Options_TargetJUMP').val())) || (Number($('#Options_NumberJUMP').val())<0 || Number($('#Options_NumberJUMP').val())>99)) {
alert(chrome.i18n.getMessage('MissionPlannerJumpSettingsCheck'))
t.options = {key: 'None'}
@ -976,7 +952,9 @@ TABS.mission_control.initialize = function (callback) {
};
}
}
// if SET_HEAD options selected, store GUI value in t.options
else if ($('input[name=Options]:checked').val() == "SET_HEAD") {
// Check if Heading is btw [0, 360°] or = -1
if ($('#Options_HeadingHead').val()>360 || ($('#Options_HeadingHead').val()<0 && $('#Options_HeadingHead').val() !=-1)) {
alert(chrome.i18n.getMessage('MissionPlannerHeadSettingsCheck'))
t.options = {key: 'None'}
@ -992,9 +970,7 @@ TABS.mission_control.initialize = function (callback) {
}
}
});
selectedMarker.getSource().getFeatures()[0].setStyle(getPointIcon(selectedMarker.action, false, selectedMarker.number));
console.log("selectedMarker", selectedMarker);
selectedMarker = null;
clearEditForm();
repaint();
@ -1011,7 +987,6 @@ TABS.mission_control.initialize = function (callback) {
});
$('#saveFileMissionButton').on('click', function () {
//if (!markers.length) return;
nwdialog.setContext(document);
nwdialog.saveFileDialog('', '.mission', function(result) {
saveMissionFile(result);
@ -1023,7 +998,7 @@ TABS.mission_control.initialize = function (callback) {
removeAllPoints();
$(this).addClass('disabled');
GUI.log('Start get point');
// Reinit some internal parameters
pointForSend = 0;
actionPointForSend = 0;
nonMarkerPoint = [];
@ -1036,7 +1011,7 @@ TABS.mission_control.initialize = function (callback) {
$('#saveMissionButton').on('click', function () {
$(this).addClass('disabled');
GUI.log('Start send point');
// Reinit some internal parameters
pointForSend = 0;
actionPointForSend = 0;
nonMarkerPoint = [];
@ -1058,15 +1033,6 @@ TABS.mission_control.initialize = function (callback) {
MSP.send_message(MSPCodes.MSP_WP_MISSION_SAVE, [0], false);
});
// RTH missions commented as integrated into WP options direclty
/*$('#rthEndMission').on('change', function () {
if ($(this).is(':checked')) {
$('#rthSettings').fadeIn(300);
} else {
$('#rthSettings').fadeOut(300);
}
});*/
$('#saveSettings').on('click', function () {
settings = { speed: $('#MPdefaultPointSpeed').val(), alt: $('#MPdefaultPointAlt').val() };
saveSettings();
@ -1082,10 +1048,8 @@ TABS.mission_control.initialize = function (callback) {
// Add function to update parameter i field in the selected Edit WP Box
$('#pointType').on('change', function () {
selectedMarker.action = $('#pointType').val();
for (var j in dictOfLabelParameterPoint[selectedMarker.action])
{
if (dictOfLabelParameterPoint[selectedMarker.action][j] != '')
{
for (var j in dictOfLabelParameterPoint[selectedMarker.action]) {
if (dictOfLabelParameterPoint[selectedMarker.action][j] != '') {
$('#pointP'+String(j).slice(-1)+'class').fadeIn(300);
$('label[for=pointP'+String(j).slice(-1)+']').html(dictOfLabelParameterPoint[selectedMarker.action][j]);
}
@ -1096,18 +1060,13 @@ TABS.mission_control.initialize = function (callback) {
}
else {$('#pointOptionclass').fadeOut(300);}
});
updateTotalInfo();
}
function closeSettingsPanel() {
$('#missionPlanerSettings').hide();
$('#missionPlanerTotalInfo').fadeIn(300);
if (selectedMarker !== null) {
$('#MPeditPoint').fadeIn(300);
}
}
/////////////////////////////////////////////
// Manage Buttons toolbox
/////////////////////////////////////////////
function removeAllPoints() {
for (var i in markers) {
map.removeLayer(markers[i]);
@ -1115,10 +1074,6 @@ TABS.mission_control.initialize = function (callback) {
markers = [];
clearEditForm();
updateTotalInfo();
// RTH section commented as RTH options is integrated into WP box
/*$('#rthEndMission').prop('checked', false);
$('#rthSettings').fadeOut(300);
$('#rthLanding').prop('checked', false);*/
repaint();
}
@ -1213,11 +1168,11 @@ TABS.mission_control.initialize = function (callback) {
// draw actual mission
removeAllPoints();
// Create nonMarkerPointListRead list to store index of non marker point (i.e RTH, SET_HEAD, JUMP) => useful for JUMP part
var nonMarkerPointListRead =[]
for (var i = 0; i < mission.points.length; i++) {
if ([MWNP.WPTYPE.JUMP,MWNP.WPTYPE.SET_HEAD,MWNP.WPTYPE.RTH].includes(mission.points[i].action)) {nonMarkerPointListRead.push(mission.points[i].index);};
}
console.log("nonMarkerPointListRead : ",nonMarkerPointListRead);
// Updated code to take into account WP options (JUMP, SET_HEAD, RTH)
for (var i = 0; i < mission.points.length; i++) {
if ([MWNP.WPTYPE.WAYPOINT,MWNP.WPTYPE.PH_UNLIM,MWNP.WPTYPE.PH_TIME,MWNP.WPTYPE.LAND, MWNP.WPTYPE.SET_POI].includes(mission.points[i].action)) {
@ -1291,6 +1246,7 @@ TABS.mission_control.initialize = function (callback) {
for (var i = 0; i < markers.length; i++) {
var geometry = markers[i].getSource().getFeatures()[0].getGeometry();
var coordinate = ol.proj.toLonLat(geometry.getCoordinates());
// if marker is Set_POI, PH_UNLIM, LAND
if (markers[i].action == '5' || markers[i].action == '2' || markers[i].action == '8' ) {
var point = { $: {
'no': (j),
@ -1305,6 +1261,7 @@ TABS.mission_control.initialize = function (callback) {
data.missionitem.push(point);
j++;
}
// else marker is not Set_POI, PH_UNLIM, LAND
else {
var point = { $: {
'no': (j),
@ -1319,10 +1276,10 @@ TABS.mission_control.initialize = function (callback) {
data.missionitem.push(point);
j++;
}
// Manage Options for markers
// If marker has options key = JUMP, provide JUMP data (Waypoint target for Jump and number of repeat) to Parameter1 and Parameter2
if (markers[i].options.key == "JUMP") {
nonMarkerPoint.push(j);
/* console.log("nonMarkerPoint : ", nonMarkerPoint);
console.log("getNumberOfNonMarkerForJump : ",getNumberOfNonMarkerForJump2(nonMarkerPoint, Number(markers[i].options.targetWP))); */
point = { $: {
'no': (j),
'action': 'JUMP',
@ -1336,6 +1293,7 @@ TABS.mission_control.initialize = function (callback) {
data.missionitem.push(point);
j++;
}
// If marker has options key = SET_HEAD, provide SET_HEAD heading data to Parameter1
else if (markers[i].options.key == "SET_HEAD") {
point = { $: {
'no': (j),
@ -1351,6 +1309,7 @@ TABS.mission_control.initialize = function (callback) {
nonMarkerPoint.push(j);
j++;
}
// If marker has options key = RTH, provide RTH data (whether landing is required) to Parameter1
else if (markers[i].options.key == "RTH") {
actionPointForSend++;
point = { $: {
@ -1369,11 +1328,6 @@ TABS.mission_control.initialize = function (callback) {
};
}
// add last RTH point - Section commented as RTH is directly integrated as a WP options
/*if ($('#rthEndMission').is(':checked')) {
data.missionitem.push({ $: { 'no': (markers.length + 1), 'action': 'RTH', 'lon': 0, 'lat': 0, 'alt': (settings.alt / 100), 'parameter1': ($('#rthLanding').is(':checked') ? 1 : 0) } });
}*/
var builder = new window.xml2js.Builder({ 'rootName': 'mission', 'renderOpts': { 'pretty': true, 'indent': '\t', 'newline': '\n' } });
var xml = builder.buildObject(data);
fs.writeFile(filename, xml, (err) => {
@ -1384,26 +1338,12 @@ TABS.mission_control.initialize = function (callback) {
GUI.log('File saved');
});
}
// New function to get number of Non Marker point such as JUMP, SET_HEAD and RTH
function getNumberOfNonMarkerForJump(nonMarkerPointList, numTargetMarker) {
for (i = 0; i < nonMarkerPointList.length; i++) {
if (numTargetMarker<=nonMarkerPointList[i+1] && numTargetMarker>nonMarkerPointList[i]) {
return i+1;
}
else {
return 0;
}
}
}
// New function to get number of Non Marker point such as JUMP, SET_HEAD and RTH
// New: function to get number of Non Marker points such as JUMP, SET_HEAD and RTH
function getNumberOfNonMarkerForJump2(nonMarkerPointList, numTargetMarker) {
for (i = 1; i < nonMarkerPointList.length; i++) {
console.log("i : ", i);
console.log("nonMarkerPointList[i-1] : ",nonMarkerPointList[i-1]);
console.log("numTargetMarker : ", numTargetMarker);
if (numTargetMarker>=nonMarkerPointList[i-1]) {
numTargetMarker++
numTargetMarker++;
}
else {
return numTargetMarker;
@ -1411,17 +1351,12 @@ TABS.mission_control.initialize = function (callback) {
}
}
// New function to get number of Non Marker point such as JUMP, SET_HEAD and RTH
// New: Reversed function to get number of Non Marker points such as JUMP, SET_HEAD and RTH
function getNumberOfNonMarkerForJumpReversed(nonMarkerPointList, numTargetMarker) {
var numTargetMarkerOut = 0;
for (i = 1; i < nonMarkerPointList.length; i++) {
// console.log("i : ", i);
// console.log("nonMarkerPointList[i] : ",nonMarkerPointList[i-1]);
// console.log("numTargetMarker : ", numTargetMarker);
// console.log("numTargetMarkerOut : ", numTargetMarkerOut);
// console.log(numTargetMarker>=nonMarkerPointList[i-1]);
if (numTargetMarker>=nonMarkerPointList[i-1]) {
numTargetMarkerOut++
numTargetMarkerOut++;
}
else {
return numTargetMarker-numTargetMarkerOut;
@ -1452,11 +1387,7 @@ TABS.mission_control.initialize = function (callback) {
endGetPoint();
return;
}
/* console.log(MISSION_PLANER.bufferPoint);
console.log("countBusyPoints : "+MISSION_PLANER.countBusyPoints);
console.log("POINT : "+pointForSend);
console.log("Mission : "+MISSION_PLANER.bufferPoint.number); */
// Populate a dictionary pointFromBuffer which stores all the point values from buffer to be post-treated then (Needed for JUMP option at least)
if (pointForSend > 0) {
pointFromBuffer[MISSION_PLANER.bufferPoint.number] = {
number : MISSION_PLANER.bufferPoint.number,
@ -1470,13 +1401,10 @@ TABS.mission_control.initialize = function (callback) {
};
if ([MWNP.WPTYPE.JUMP,MWNP.WPTYPE.SET_HEAD,MWNP.WPTYPE.RTH].includes(MISSION_PLANER.bufferPoint.action)) {nonMarkerPointListRead.push(MISSION_PLANER.bufferPoint.number);};
}
/* console.log(pointFromBuffer);
console.log(nonMarkerPointListRead); */
// Once all points have been scanned and pointFromBuffer populated, then scan pointFromBuffer to generate the Map Layers Markers
if (pointForSend >= MISSION_PLANER.countBusyPoints) {
Object.keys(pointFromBuffer).forEach(function(key) {
// console.log(pointFromBuffer[key]);
// console.log("Key : "+key);
if ([MWNP.WPTYPE.WAYPOINT,MWNP.WPTYPE.PH_UNLIM,MWNP.WPTYPE.PH_TIME,MWNP.WPTYPE.LAND, MWNP.WPTYPE.SET_POI].includes(pointFromBuffer[key].action)) {
if ((Number(key)+1) <= MISSION_PLANER.countBusyPoints) {
var coord = ol.proj.fromLonLat([pointFromBuffer[key].lon, pointFromBuffer[key].lat]);
@ -1486,7 +1414,6 @@ TABS.mission_control.initialize = function (callback) {
};
}
else if (pointFromBuffer[Number(key)+1].action == MWNP.WPTYPE.JUMP) {
/* console.log("getNumberOfNonMarkerForJumpReversed : ",getNumberOfNonMarkerForJumpReversed(nonMarkerPointListRead, pointFromBuffer[Number(key)+1].p1)); */
var options = {key: 'JUMP',
targetWP: getNumberOfNonMarkerForJumpReversed(nonMarkerPointListRead, pointFromBuffer[Number(key)+1].p1),
numRepeat: pointFromBuffer[Number(key)+1].p2
@ -1527,12 +1454,13 @@ TABS.mission_control.initialize = function (callback) {
}
function sendNextPoint() {
//var isRTH = $('#rthEndMission').is(':checked');
console.log("Point : "+ (pointForSend+actionPointForSend));
if ((pointForSend) < markers.length) {
if (pointForSend >= markers.length) {
endSendPoint();
return;
}
var geometry = markers[pointForSend].getSource().getFeatures()[0].getGeometry();
var coordinate = ol.proj.toLonLat(geometry.getCoordinates());
// If MISSION_PLANER.bufferPoint do not content any options keys (i.e different from None) => isOptions==false
if (isOptions == false) {
if (markers[pointForSend].action == '5' || markers[pointForSend].action == '2' || markers[pointForSend].action == '8' ) {
MISSION_PLANER.bufferPoint.number = pointForSend + actionPointForSend + 1;
@ -1562,16 +1490,19 @@ TABS.mission_control.initialize = function (callback) {
pointForSend++;
}
oldMarkers = markers[pointForSend]
if (pointForSend >= markers.length) {
MISSION_PLANER.bufferPoint.endMission = 0xA5;
}
else {
MISSION_PLANER.bufferPoint.endMission = 0;
}
MSP.send_message(MSPCodes.MSP_SET_WP, mspHelper.crunch(MSPCodes.MSP_SET_WP), false, sendNextPoint);
}
// else if MISSION_PLANER.bufferPoint do content any options keys (i.e different from None) => isOptions==true
else if (isOptions == true) {
if ((pointForSend) < markers.length) {
if (oldMarkers.options.key == "JUMP") {
actionPointForSend++;
nonMarkerPoint.push(pointForSend + actionPointForSend+1);
console.log("nonMarkerPoint : ", nonMarkerPoint);
console.log("getNumberOfNonMarkerForJump : ",getNumberOfNonMarkerForJump2(nonMarkerPoint, Number(oldMarkers.options.targetWP)));
MISSION_PLANER.bufferPoint.number = pointForSend + actionPointForSend + 1;
MISSION_PLANER.bufferPoint.action = String(MWNP.WPTYPE[oldMarkers.options.key]);
MISSION_PLANER.bufferPoint.lon = 0;
@ -1584,8 +1515,6 @@ TABS.mission_control.initialize = function (callback) {
else if (oldMarkers.options.key == "SET_HEAD") {
actionPointForSend++;
nonMarkerPoint.push(pointForSend + actionPointForSend+1);
console.log("nonMarkerPoint : ", nonMarkerPoint);
MISSION_PLANER.bufferPoint.number = pointForSend + actionPointForSend + 1;
MISSION_PLANER.bufferPoint.action = String(MWNP.WPTYPE[oldMarkers.options.key]);
MISSION_PLANER.bufferPoint.lon = 0;
@ -1598,8 +1527,6 @@ TABS.mission_control.initialize = function (callback) {
else if (oldMarkers.options.key == "RTH") {
actionPointForSend++;
nonMarkerPoint.push(pointForSend + actionPointForSend+1);
console.log("nonMarkerPoint : ", nonMarkerPoint);
MISSION_PLANER.bufferPoint.number = pointForSend + actionPointForSend + 1;
MISSION_PLANER.bufferPoint.action = String(MWNP.WPTYPE[oldMarkers.options.key]);
MISSION_PLANER.bufferPoint.lon = 0;
@ -1611,28 +1538,13 @@ TABS.mission_control.initialize = function (callback) {
}
isOptions = false;
pointForSend++;
MSP.send_message(MSPCodes.MSP_SET_WP, mspHelper.crunch(MSPCodes.MSP_SET_WP), false, sendNextPoint);
}
}
if (pointForSend >= markers.length) {
MISSION_PLANER.bufferPoint.endMission = 0xA5;
}
else {
/*if (isRTH) {
MISSION_PLANER.bufferPoint.number = pointForSend + 1;
MISSION_PLANER.bufferPoint.action = 4;
MISSION_PLANER.bufferPoint.lon = 0;
MISSION_PLANER.bufferPoint.lat = 0;
MISSION_PLANER.bufferPoint.alt = 0;
MISSION_PLANER.bufferPoint.endMission = 0xA5;
MISSION_PLANER.bufferPoint.p1 = $('#rthLanding').is(':checked') ? 1 : 0;
MSP.send_message(MSPCodes.MSP_SET_WP, mspHelper.crunch(MSPCodes.MSP_SET_WP), false, endSendPoint);
} else {
endSendPoint();
}*/
MISSION_PLANER.bufferPoint.endMission = 0xA5;
console.log("EndSendPoint");
endSendPoint();
return;
MISSION_PLANER.bufferPoint.endMission = 0;
}
MSP.send_message(MSPCodes.MSP_SET_WP, mspHelper.crunch(MSPCodes.MSP_SET_WP), false, sendNextPoint);
}
}
@ -1644,6 +1556,13 @@ TABS.mission_control.initialize = function (callback) {
$('#saveMissionButton').removeClass('disabled');
}
function updateTotalInfo() {
if (CONFIGURATOR.connectionValid) {
$('#availablePoints').text(MISSION_PLANER.countBusyPoints + '/' + MISSION_PLANER.maxWaypoints);
$('#missionValid').html(MISSION_PLANER.isValidMission ? chrome.i18n.getMessage('armingCheckPass') : chrome.i18n.getMessage('armingCheckFail'));
}
}
};