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

Save and load mission from EEPROM, fix bugs

This commit is contained in:
Sergej Pozdnyakov 2018-01-28 14:21:59 +03:00
parent efda795698
commit 536c5488e4
5 changed files with 72 additions and 31 deletions

View file

@ -2324,10 +2324,10 @@
"message": "Mission Control"
},
"loadMissionButton": {
"message": "Load mission"
"message": "Load mission from FC"
},
"saveMissionButton": {
"message": "Save mission"
"message": "Save mission to FC"
},
"loadEepromMissionButton": {
"message": "Load Eeprom mission"
@ -2352,5 +2352,11 @@
},
"useOnlyStandalone": {
"message": "Use stand-alone application.<br> Please visit the <a href=\"https://github.com/iNavFlight/inav-configurator/releases\" target=\"_blank\">website</a> to read the release notes and download."
},
"eeprom_load_ok": {
"message": "EEPROM <span style=\"color: #37a8db\">loaded</span>"
},
"confirm_delete_all_points": {
"message": "Do you really want to delete all points?"
}
}

View file

@ -17,6 +17,7 @@ var MSPCodes = {
MSP_POSITION_ESTIMATION_CONFIG: 16,
MSP_SET_POSITION_ESTIMATION_CONFIG: 17,
MSP_WP_MISSION_LOAD: 18,
MSP_WP_MISSION_SAVE: 19,
MSP_WP_GETINFO: 20,
MSP_RTH_AND_LAND_CONFIG: 21,

View file

@ -341,8 +341,8 @@ var mspHelper = (function (gui) {
case MSPCodes.MSP_WP:
MISSION_PLANER.bufferPoint.number = data.getUint8(0);
MISSION_PLANER.bufferPoint.action = data.getUint8(1);
MISSION_PLANER.bufferPoint.lon = data.getInt32(2, true) / 10000000;
MISSION_PLANER.bufferPoint.lat = data.getInt32(6, true) / 10000000;
MISSION_PLANER.bufferPoint.lat = data.getInt32(2, true) / 10000000;
MISSION_PLANER.bufferPoint.lon = data.getInt32(6, true) / 10000000;
MISSION_PLANER.bufferPoint.alt = data.getInt32(10, true);
break;
@ -1120,6 +1120,14 @@ var mspHelper = (function (gui) {
case MSPCodes.MSP_SET_WP:
console.log('Point saved');
break;
case MSPCodes.MSP_WP_MISSION_SAVE:
// buffer.push(0);
console.log(data);
break;
case MSPCodes.MSP_WP_MISSION_LOAD:
console.log('Mission load');
break;
default:
console.log('Unknown code detected: ' + dataHandler.code);
} else {
@ -1601,8 +1609,6 @@ var mspHelper = (function (gui) {
break;
case MSPCodes.MSP_SET_WP:
console.log(MISSION_PLANER.bufferPoint.lat);
console.log(MISSION_PLANER.bufferPoint.lon);
buffer.push(MISSION_PLANER.bufferPoint.number); // sbufReadU8(src); // number
buffer.push(MISSION_PLANER.bufferPoint.action); // sbufReadU8(src); // action
buffer.push(specificByte(MISSION_PLANER.bufferPoint.lat, 0)); // sbufReadU32(src); // lat
@ -1627,11 +1633,17 @@ var mspHelper = (function (gui) {
break;
case MSPCodes.MSP_WP:
console.log(MISSION_PLANER.bufferPoint.number);
buffer.push(MISSION_PLANER.bufferPoint.number);
buffer.push(MISSION_PLANER.bufferPoint.number+1);
break;
case MSPCodes.MSP_WP_MISSION_SAVE:
// buffer.push(0);
console.log(buffer);
break;
case MSPCodes.MSP_WP_MISSION_LOAD:
// buffer.push(0);
console.log(buffer);
break;
default:

View file

@ -3,7 +3,7 @@
<div id="missionMap"></div>
<div id="notLoadMap" data-i18n="useOnlyStandalone" style="display: none;"></div>
</div>
<div class="content_toolbar">
<div class="content_toolbar" id="missionControls">
<div class="waypoint waypoint-left">
<div class="gui_box" style="padding-bottom: 10px">
<div class="gui_box_titlebar">
@ -12,8 +12,8 @@
<div class="spacer">
<input type="hidden" name="pointNumber" value="">
<div class="point">
<select name="type" id="pointType" disabled>
<option value="1">Home</option>
<select name="type" id="pointType">
<!--<option value="1">Home</option>-->
<option value="1">Waypoint</option>
<option value="4">RTH</option>
</select>
@ -27,7 +27,7 @@
<input id="pointLon" type="text" value="0.0" required>
</div>
<div class="point">
<label class="point-label" for="pointAlt">Alt: </label>
<label class="point-label" for="pointAlt">Alt (cm): </label>
<input id="pointAlt" type="text" value="0" required>
</div>
<div>

View file

@ -29,7 +29,7 @@ TABS.mission_control.initialize = function (callback) {
if (typeof require !== "undefined") {
initMap();
} else {
$('#missionMap').hide();
$('#missionMap, #missionControls').hide();
$('#notLoadMap').show();
}
localize();
@ -100,7 +100,7 @@ TABS.mission_control.initialize = function (callback) {
map.addLayer(vectorLayer);
}
function addMarker(_pos, _alt) {
function addMarker(_pos, _alt, _action) {
var iconFeature = new ol.Feature({
geometry: new ol.geom.Point(_pos),
name: 'Null Island',
@ -139,6 +139,7 @@ TABS.mission_control.initialize = function (callback) {
vectorLayer.alt = _alt;
vectorLayer.number = markers.length;
vectorLayer.action = _action;
markers.push(vectorLayer);
@ -285,7 +286,7 @@ TABS.mission_control.initialize = function (callback) {
target: document.getElementById('missionMap'),
view: new ol.View({
center: ol.proj.fromLonLat([lon, lat]),
zoom: 10
zoom: 14
})
});
@ -305,8 +306,9 @@ TABS.mission_control.initialize = function (callback) {
$('#pointLat').val(coord[0]);
$('#pointLon').val(coord[1]);
$('#pointAlt').val(selectedMarker.alt);
$('#pointType').val(selectedMarker.action);
} else {
map.addLayer(addMarker(evt.coordinate, 0));
map.addLayer(addMarker(evt.coordinate, 1500, 1));
repaint();
}
});
@ -325,25 +327,24 @@ TABS.mission_control.initialize = function (callback) {
});
$('#removeAllPoints').on('click', function () {
for (var i in markers) {
map.removeLayer(markers[i]);
if (confirm(chrome.i18n.getMessage('confirm_delete_all_points'))) {
removeAllPoints();
}
markers = [];
clearEditForm();
repaint();
});
$('#removePoint').on('click', function () {
if (selectedMarker) {
map.removeLayer(selectedMarker);
var tmp = [];
for (var i in markers) {
if (markers[i] !== selectedMarker) {
if (markers[i] !== selectedMarker && typeof markers[i].action !== "undefined") {
tmp.push(markers[i]);
}
}
map.removeLayer(selectedMarker);
markers = tmp;
selectedMarker = null;
clearEditForm();
repaint();
}
@ -356,6 +357,7 @@ TABS.mission_control.initialize = function (callback) {
var geometry = t.getSource().getFeatures()[0].getGeometry();
geometry.setCoordinates(ol.proj.fromLonLat([parseFloat($('#pointLat').val()), parseFloat($('#pointLon').val())]));
t.alt = $('#pointAlt').val();
t.action = $('#pointType').val();
}
});
@ -366,8 +368,8 @@ TABS.mission_control.initialize = function (callback) {
});
$('#loadMissionButton').on('click', function () {
removeAllPoints();
$(this).addClass('disabled');
console.log('Start get point');
GUI.log('Start get point');
pointForSend = 0;
@ -383,7 +385,9 @@ TABS.mission_control.initialize = function (callback) {
});
$('#loadEepromMissionButton').on('click', function () {
GUI.log(chrome.i18n.getMessage('eeprom_load_ok'));
MSP.send_message(MSPCodes.MSP_WP_MISSION_LOAD, false, getPointsFromEprom);
});
$('#saveEepromMissionButton').on('click', function () {
GUI.log(chrome.i18n.getMessage('eeprom_saved_ok'));
@ -393,20 +397,39 @@ TABS.mission_control.initialize = function (callback) {
updateTotalInfo();
}
function removeAllPoints() {
for (var i in markers) {
map.removeLayer(markers[i]);
}
markers = [];
clearEditForm();
repaint();
}
function getPointsFromEprom() {
pointForSend = 0;
MSP.send_message(MSPCodes.MSP_WP_GETINFO, false, false, getNextPoint);
}
function getNextPoint() {
var coord;
if (pointForSend > 0) {
// console.log(MISSION_PLANER.bufferPoint.lon);
// console.log(MISSION_PLANER.bufferPoint.lat);
// console.log(MISSION_PLANER.bufferPoint.alt);
// console.log(MISSION_PLANER.bufferPoint.action);
map.addLayer(addMarker(ol.proj.fromLonLat([MISSION_PLANER.bufferPoint.lon, MISSION_PLANER.bufferPoint.lat]), MISSION_PLANER.bufferPoint.alt));
// repaint();
coord = ol.proj.fromLonLat([MISSION_PLANER.bufferPoint.lon, MISSION_PLANER.bufferPoint.lat]);
map.addLayer(addMarker(coord, MISSION_PLANER.bufferPoint.alt, MISSION_PLANER.bufferPoint.action));
}
if (pointForSend > MISSION_PLANER.countBusyPoints) {
if (pointForSend >= MISSION_PLANER.countBusyPoints) {
GUI.log('End get point');
$('#loadMissionButton').removeClass('disabled');
map.getView().setCenter(coord);
repaint();
updateTotalInfo();
return;
}
@ -430,12 +453,11 @@ TABS.mission_control.initialize = function (callback) {
var geometry = markers[pointForSend].getSource().getFeatures()[0].getGeometry();
var coordinate = ol.proj.toLonLat(geometry.getCoordinates());
MISSION_PLANER.bufferPoint.number = pointForSend;
MISSION_PLANER.bufferPoint.action = 1;
MISSION_PLANER.bufferPoint.lat = parseInt(coordinate[0] * 10000000);
MISSION_PLANER.bufferPoint.lon = parseInt(coordinate[1] * 10000000);
MISSION_PLANER.bufferPoint.number = pointForSend + 1;
MISSION_PLANER.bufferPoint.action = markers[pointForSend].action;
MISSION_PLANER.bufferPoint.lon = parseInt(coordinate[0] * 10000000);
MISSION_PLANER.bufferPoint.lat = parseInt(coordinate[1] * 10000000);
MISSION_PLANER.bufferPoint.alt = markers[pointForSend].alt;
pointForSend++;
if (pointForSend >= markers.length) {
MISSION_PLANER.bufferPoint.endMission = 0xA5;