Use Nasal to provide GPS search functions.
This commit is contained in:
parent
2c6a962a34
commit
4d3a00bf68
2 changed files with 120 additions and 38 deletions
|
@ -82,6 +82,12 @@ var RouteManagerDelegate = {
|
|||
fgcommand("activate-flightplan", props.Node.new({"activate": 0}));
|
||||
},
|
||||
|
||||
endOfFlightPlan: func
|
||||
{
|
||||
debug.dump("end of flight-plan, deactivating");
|
||||
fgcommand("activate-flightplan", props.Node.new({"activate": 0}));
|
||||
},
|
||||
|
||||
waypointsChanged: func
|
||||
{
|
||||
},
|
||||
|
|
|
@ -4,23 +4,118 @@
|
|||
<height>430</height>
|
||||
<modal>false</modal>
|
||||
<nasal>
|
||||
<open>
|
||||
<open><![CDATA[
|
||||
|
||||
var gps = props.globals.getNode("/instrumentation/gps/", 1);
|
||||
var dlg = props.globals.getNode("/sim/gui/dialogs/gps", 1);
|
||||
var cmd = gps.getNode("command", 1);
|
||||
var scratch = gps.getNode("scratch");
|
||||
var scratch = gps.getNode("scratch", 1);
|
||||
var scratchValid = scratch.getNode("valid", 1);
|
||||
|
||||
scratch.getNode("exact", 1).setBoolValue(0);
|
||||
var searchType = scratch.getNode("type", 1);
|
||||
var searchQuery = scratch.getNode("query", 1);
|
||||
|
||||
var copySearchArgs = func {
|
||||
searchType.setValue(dlg.getNode("search-type").getValue());
|
||||
searchQuery.setValue(dlg.getNode("search-query").getValue());
|
||||
}
|
||||
var updateSearchResults = func
|
||||
{
|
||||
debug.dump('search results is:', searchResults);
|
||||
|
||||
dlg.getNode("scratch-index", 1).setValue(0);
|
||||
dlg.getNode("scratch-has-next", 1).setBoolValue(size(searchResults) > 1);
|
||||
|
||||
if (size(searchResults) < 1) {
|
||||
scratchValid.setBoolValue(0);
|
||||
return;
|
||||
}
|
||||
|
||||
updateScratch();
|
||||
}
|
||||
|
||||
var updateScratch = func
|
||||
{
|
||||
var result = searchResults[dlg.getNode("scratch-index").getValue()];
|
||||
if (result == nil) {
|
||||
scratchValid.setBoolValue(0);
|
||||
return;
|
||||
}
|
||||
|
||||
var ty = result.type;
|
||||
scratchValid.setBoolValue(1);
|
||||
scratch.getNode("type", 1).setValue(ty);
|
||||
scratch.getNode("latitude-deg", 1).setValue(result.lat);
|
||||
scratch.getNode("longitude-deg", 1).setValue(result.lon);
|
||||
scratch.getNode("altitude-ft", 1).setValue(result.elevation);
|
||||
scratch.getNode("ident", 1).setValue(result.id);
|
||||
scratch.getNode("name", 1).setValue(result.name);
|
||||
|
||||
if (ty == 'vor') {
|
||||
scratch.getNode("frequency-mhz", 1).setValue(result.frequency);
|
||||
} elsif (ty == 'ndb') {
|
||||
scratch.getNode("frequency-khz", 1).setValue(result.frequency);
|
||||
}
|
||||
|
||||
var cd = positioned.courseAndDistance(result);
|
||||
scratch.getNode("mag-bearing-deg", 1).setValue(cd[0] + magvar());
|
||||
scratch.getNode("distance-nm", 1).setValue(cd[1]);
|
||||
|
||||
gui.dialog_update("gps");
|
||||
}
|
||||
|
||||
var doSearch = func()
|
||||
{
|
||||
var ty = dlg.getNode("search-type").getValue();
|
||||
var query = dlg.getNode("search-query").getValue();
|
||||
searchResults = positioned.sortByRange(positioned.findByIdent(query, ty));
|
||||
updateSearchResults();
|
||||
}
|
||||
|
||||
var doSearchNames = func
|
||||
{
|
||||
var ty = dlg.getNode("search-type").getValue();
|
||||
var query = dlg.getNode("search-query").getValue();
|
||||
searchResults = positioned.sortByRange(positioned.findByName(query, ty));
|
||||
updateSearchResults();
|
||||
}
|
||||
|
||||
var doSearchNearest = func
|
||||
{
|
||||
var ty = dlg.getNode("search-type").getValue();
|
||||
searchResults = positioned.findWithinRange(200.0, ty);
|
||||
updateSearchResults();
|
||||
}
|
||||
|
||||
var doLoadRouteWaypoint = func
|
||||
{
|
||||
var fp = flightplan();
|
||||
searchResults = [];
|
||||
for (var i=0; i < fp.getPlanSize(); i+=1) {
|
||||
append(searchResults, fp.getWP(i));
|
||||
}
|
||||
updateSearchResults();
|
||||
}
|
||||
|
||||
var doScratchPrevious = func
|
||||
{
|
||||
var index = dlg.getNode("scratch-index").getValue();
|
||||
if (index == 0) return;
|
||||
dlg.getNode("scratch-index").setValue(index - 1);
|
||||
dlg.getNode("scratch-has-next", 1).setValue(size(searchResults) > 1);
|
||||
updateScratch();
|
||||
}
|
||||
|
||||
var doScratchNext = func
|
||||
{
|
||||
var index = dlg.getNode("scratch-index").getValue();
|
||||
var lastIndex = size(searchResults) - 1;
|
||||
if (index == lastIndex) return;
|
||||
|
||||
dlg.getNode("scratch-has-next", 1).setValue((index + 1) < lastIndex);
|
||||
dlg.getNode("scratch-index").setValue(index + 1);
|
||||
updateScratch();
|
||||
}
|
||||
|
||||
var searchResults = [];
|
||||
updateSearchResults();
|
||||
|
||||
var slaved = props.globals.getNode("/instrumentation/nav[0]/slaved-to-gps", 1);
|
||||
</open>
|
||||
]]></open>
|
||||
|
||||
</nasal>
|
||||
<name>gps</name>
|
||||
<layout>vbox</layout>
|
||||
|
@ -336,36 +431,21 @@
|
|||
<legend>Search</legend>
|
||||
<binding>
|
||||
<command>nasal</command>
|
||||
<script>
|
||||
copySearchArgs();
|
||||
cmd.setValue("search");
|
||||
</script>
|
||||
<script>doSearch()</script>
|
||||
</binding>
|
||||
</button>
|
||||
<button>
|
||||
<legend>Search Names</legend>
|
||||
<binding>
|
||||
<command>nasal</command>
|
||||
<script>
|
||||
copySearchArgs();
|
||||
cmd.setValue("search-names");
|
||||
</script>
|
||||
<script>doSearchNames()</script>
|
||||
</binding>
|
||||
</button>
|
||||
<button>
|
||||
<legend>Nrst</legend>
|
||||
<binding>
|
||||
<command>nasal</command>
|
||||
<script>
|
||||
copySearchArgs();
|
||||
scratch.getNode("max-results", 1).setIntValue(10);
|
||||
|
||||
# ensure scratch pos is invalid, so we use current GPS
|
||||
# position as the search origin
|
||||
scratch.getNode("longitude-deg", 1).setDoubleValue(-9999);
|
||||
scratch.getNode("latitude-deg", 1).setDoubleValue(-9999);
|
||||
cmd.setValue("nearest")
|
||||
</script>
|
||||
<script>doSearchNearest()</script>
|
||||
</binding>
|
||||
</button>
|
||||
<button>
|
||||
|
@ -375,11 +455,7 @@
|
|||
<legend>Actv RTE WPT</legend>
|
||||
<binding>
|
||||
<command>nasal</command>
|
||||
<script>
|
||||
scratch.getNode("results", 1).clearValue();
|
||||
scratch.getNode("index", 1).setIntValue(-1);
|
||||
cmd.setValue("load-route-wpt")
|
||||
</script>
|
||||
<script>doLoadRouteWaypoint()</script>
|
||||
</binding>
|
||||
</button>
|
||||
<empty>
|
||||
|
@ -484,7 +560,7 @@
|
|||
<button>
|
||||
<enable>
|
||||
<greater-than>
|
||||
<property>/instrumentation/gps/scratch/index</property>
|
||||
<property>/sim/gui/dialogs/gps/scratch-index</property>
|
||||
<value>0</value>
|
||||
</greater-than>
|
||||
</enable>
|
||||
|
@ -494,12 +570,12 @@
|
|||
<key>left</key>
|
||||
<binding>
|
||||
<command>nasal</command>
|
||||
<script>cmd.setValue("previous")</script>
|
||||
<script>doScratchPrevious()</script>
|
||||
</binding>
|
||||
</button>
|
||||
<button>
|
||||
<enable>
|
||||
<property>/instrumentation/gps/scratch/has-next</property>
|
||||
<property>/sim/gui/dialogs/gps/scratch-has-next</property>
|
||||
</enable>
|
||||
<row>5</row>
|
||||
<col>1</col>
|
||||
|
@ -507,7 +583,7 @@
|
|||
<key>right</key>
|
||||
<binding>
|
||||
<command>nasal</command>
|
||||
<script>cmd.setValue("next")</script>
|
||||
<script>doScratchNext()</script>
|
||||
</binding>
|
||||
</button>
|
||||
</group>
|
||||
|
|
Loading…
Add table
Reference in a new issue