Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 474 → Rev 475

/MissionCockpit/branches/V0.2.0_EN/mkcockpit.pl
0,0 → 1,2131
#!/usr/bin/perl
#y!/usr/bin/perl -d:ptkdb
 
###############################################################################
#
# mkcockpit.pl - MK Mission Cockpit - GUI
#
# Copyright (C) 2009 Rainer Walther (rainerwalther-mail@web.de)
#
# Creative Commons Lizenz mit den Zusaetzen (by, nc, sa)
#
# Es ist Ihnen gestattet:
# * das Werk vervielfältigen, verbreiten und öffentlich zugänglich machen
# * Abwandlungen bzw. Bearbeitungen des Inhaltes anfertigen
#
# Zu den folgenden Bedingungen:
# * Namensnennung.
# Sie müssen den Namen des Autors/Rechteinhabers in der von ihm festgelegten Weise nennen.
# * Keine kommerzielle Nutzung.
# Dieses Werk darf nicht für kommerzielle Zwecke verwendet werden.
# * Weitergabe unter gleichen Bedingungen.
# Wenn Sie den lizenzierten Inhalt bearbeiten oder in anderer Weise umgestalten,
# verändern oder als Grundlage für einen anderen Inhalt verwenden,
# dürfen Sie den neu entstandenen Inhalt nur unter Verwendung von Lizenzbedingungen
# weitergeben, die mit denen dieses Lizenzvertrages identisch oder vergleichbar sind.
#
# Im Falle einer Verbreitung müssen Sie anderen die Lizenzbedingungen, unter welche dieses
# Werk fällt, mitteilen. Am Einfachsten ist es, einen Link auf diese Seite einzubinden.
#
# Jede der vorgenannten Bedingungen kann aufgehoben werden, sofern Sie die Einwilligung
# des Rechteinhabers dazu erhalten.
#
# Diese Lizenz lässt die Urheberpersönlichkeitsrechte unberührt.
#
# Weitere Details zur Lizenzbestimmung gibt es hier:
# Kurzform: http://creativecommons.org/licenses/by-nc-sa/3.0/de/
# Komplett: http://creativecommons.org/licenses/by-nc-sa/3.0/de/legalcode
#
###############################################################################
# 2009-02-20 0.0.1 rw created
# 2009-04-01 0.1.0 rw RC1
# 2009-04-16 0.1.1 rw Bugfix, ALT= average of airsensor and Sat
# 2009-05-14 0.2.0 rw Waypoint Player
#
###############################################################################
 
$Version = "0.2.0 - 2009-05-14";
use threads; # http://search.cpan.org/~jdhedden/threads-1.72/threads.pm
# http://perldoc.perl.org/threads.html
use threads::shared; # http://search.cpan.org/~jdhedden/threads-shared-1.28/shared.pm
use Thread::Queue; # http://search.cpan.org/dist/Thread-Queue-2.11/lib/Thread/Queue.pm
use Tk;
use Tk::Balloon;
use Tk::Dialog;
use Tk::Notebook;
use Math::Trig;
use Time::HiRes qw(usleep); # http://search.cpan.org/~jhi/Time-HiRes-1.9719/HiRes.pm
use XML::Simple; # http://search.cpan.org/dist/XML-Simple-2.18/lib/XML/Simple.pm
 
# change working directory to program path
my $Cwd = substr ($0, 0, rindex ($0, "mkcockpit.pl"));
chdir $Cwd;
 
# set path for local Perl libs
push @INC, $Cwd . "perl/lib", $Cwd . "perl/site/lib";
 
# Version setting
share (%Version);
$Version{'mkcockpit.pl'} = $Version;
 
# Read configuration
 
$XmlConfigFile = "mkcockpit.xml";
$Cfg = XMLin($XmlConfigFile);
 
require "track.pl"; # Tracking antenna
require "mkcomm.pl"; # MK communication
require "logging.pl"; # CSV and GPX Logging
require "geserver.pl"; # Google Earth Server
require "$Cfg->{'map'}->{'MapDir'}/map.pl"; # Landkarte
require "libmap.pl"; # map subs
require "translate.pl"; # Übersetzungstable
 
# Thread fuer Kommunikation mit MK starten
# Output: %MkOsd, %MkTarget, %MkNcDebug, %Mk
# Input: Thread-Queue: $MkSendQueue
$mk_thr = threads->create (\&MkCommLoop) -> detach();
 
# Start Logging Thread
$log_thr = threads->create (\&MkLogLoop) -> detach();
 
# Start GoogleEarth Thread
$ge_thr = threads->create (\&GeServer) -> detach();
 
# Aktuell gültige Karte
my %Map = %{$Maps{'Current'}};
# Hauptfenster
my $main = new MainWindow;
$main->title ("MK Mission Cockpit");
 
#-----------------------------------------------------------------
# Menu
#-----------------------------------------------------------------
 
# Menu bar
my $menu_bar = $main->Menu;
$main->optionAdd("*tearOff", "false");
$main->configure ('-menu' => $menu_bar);
 
my $menu_file = $menu_bar->cascade('-label' => "~File");
$menu_file->command('-label' => 'Preferences',
'-command' => [\&Configure],
);
$menu_file->separator;
$menu_file->command('-label' => 'E~xit',
'-command' => sub{exit(0)},
);
 
my $menu_debug = $menu_bar->cascade(-label => "D~ebug");
$menu_debug->command('-label' => 'NC ~OSD Record (O)',
'-command' => [\&DisplayHash, \%MkOsd, "NC OSD Record (O)", "Display Refresh Heartbeat"],
);
$menu_debug->command('-label' => 'NC ~Target Record (s)',
'-command' => [\&DisplayHash, \%MkTarget, "NC Target Record (s)", "Display Refresh Heartbeat"],
);
$menu_debug->command('-label' => 'NC ~Debug Record (D)',
'-command' => [\&DisplayHash, \%MkNcDebug, "NC Debug Record (D)", "Display Refresh Heartbeat"],
);
$menu_debug->command('-label' => 'NC ~Other',
'-command' => [\&DisplayHash, \%Mk, "NC Other", "Display Refresh Heartbeat"],
);
$menu_debug->separator;
$menu_debug->command('-label' => 'Tracking ~Antenna Debug Record',
'-command' => [\&DisplayHash, \%MkTrack, "Tracking Antenna Debug Record", "Display Refresh Heartbeat"],
);
 
my $menu_help = $menu_bar->cascade(-label => "~Help");
$menu_help->command('-label' => 'Version',
'-command' => [\&DisplayHash, \%Version, "Version", "Display"],
);
$menu_help->separator;
$menu_help->command('-label' => 'About',
'-command' => sub
{
my $License = <<EOF;
Copyright (C) 2009 Rainer Walther (rainerwalther-mail\@web.de)
 
Creative Commons Lizenz mit den Zusaetzen (by, nc, sa)
 
Siehe LICENSE.TXT
EOF
 
my $DlgAbout = $frame_map->Dialog('-title' => 'About MK Mission Cockpit',
'-text' => "$License",
'-buttons' => ['OK'],
'-bitmap' => 'info',
);
$DlgAbout->Show;
});
 
 
# Main window Status line
$frame_status = $main->Frame( '-background' => 'lightgray',
) -> pack('-side' => 'bottom',
'-anchor' => 'w',
'-fill' => 'none',
'-expand' => 'y',
);
$status_line = $frame_status->Label ('-text' => 'Status line',
) -> pack ('-side' => 'bottom',
);
 
#-----------------------------------------------------------------
# Frames
#-----------------------------------------------------------------
 
#
# Frame: Map
#
$frame_map = $main->Frame( '-background' => 'lightgray',
'-relief' => 'sunken',
'-borderwidth' => 5,
) -> pack('-side' => 'top',
'-fill' => 'x',
);
 
# Map Überschrift
$frame_map_top = $frame_map->Frame() -> pack( '-side' => 'top',
'-expand' => 'x',
'-anchor' => 'w',
);
 
$frame_map_top->Label ('-text' => "Karte: $Map{'Name'} ($Map{'File'})",
'-background' => 'lightgray',
'-relief' => 'flat',
) -> pack( '-side' => 'left' );
 
# Map Statuszeile
$map_status = $frame_map->Frame( '-background' => 'lightgray',
) -> pack('-side' => 'bottom',
'-anchor' => 'w',
'-fill' => 'none',
'-expand' => 'y',
);
$map_status_line = $map_status->Label ( '-text' => 'Statuszeile',
'-background' => 'lightgray',
) -> pack ('-side' => 'bottom',);
 
# Map Canvas
 
# Canvas size
$MapSizeX = $Map{'Size_X'};
$MapSizeY = $Map{'Size_Y'};
 
$map_canvas = $frame_map->Canvas( '-width' => $MapSizeX,
'-height' => $MapSizeY,
'-cursor' => 'cross',
) -> pack();
 
# load Map photo
$map_canvas->Photo( 'Map',
'-file' => "$Cfg->{'map'}->{'MapDir'}/$Map{'File'}",
);
$map_canvas->createImage( 0, 0,
'-tags' => 'Map',
'-anchor' => 'nw',
'-image' => 'Map',
);
 
# border polygon
$map_canvas->createPolygon( @Map{'Border'},
'-tags' => 'Map-Border',
'-fill' => '',
'-outline' => $Cfg->{'mkcockpit'}->{'ColorAirfield'}, '-width' => 2,
);
# load Heartbeat icon
$map_canvas->Photo( 'HeartbeatSmall',
'-file' => "$Cfg->{'mkcockpit'}->{'IconHeartSmall'}",
);
$map_canvas->Photo( 'HeartbeatLarge',
'-file' => "$Cfg->{'mkcockpit'}->{'IconHeartLarge'}",
);
$map_canvas->createImage( $MapSizeX/4, 10,
'-tags' => 'Heartbeat',
'-anchor' => 'nw',
'-image' => 'HeartbeatSmall',
);
 
# load Satellite icon
$map_canvas->Photo( 'Satellite-Photo',
'-file' => "$Cfg->{'mkcockpit'}->{'IconSatellite'}",
);
$map_canvas->createImage($MapSizeX-190, -100, # hide photo
'-tags' => 'Satellite',
'-anchor' => 'nw',
'-image' => 'Satellite-Photo',
);
 
# load Waypoint icon
$map_canvas->Photo( 'Waypoint-Photo',
'-file' => "$Cfg->{'mkcockpit'}->{'IconWaypoint'}",
);
# load Target icon
$map_canvas->Photo( 'Target-Photo',
'-file' => "$Cfg->{'mkcockpit'}->{'IconTarget'}",
);
$map_canvas->createImage(0, -100, # hide photo
'-tags' => 'Target',
'-anchor' => 'nw',
'-image' => 'Target-Photo',
);
 
# load Fox icon
$map_canvas->Photo( 'Fox-Photo',
'-file' => "$Cfg->{'mkcockpit'}->{'IconFox'}",
);
$map_canvas->createImage($MapSizeX/2+50, $MapSizeY/2,
'-tags' => 'Fox',
'-anchor' => 'nw',
'-image' => 'Fox-Photo',
);
 
# load WP-Player icons
$map_canvas->Photo( 'WpPlay-Foto', '-file' => "$Cfg->{'waypoint'}->{'IconPlay'}");
$map_canvas->Photo( 'WpStop-Foto', '-file' => "$Cfg->{'waypoint'}->{'IconStop'}");
$map_canvas->Photo( 'WpPause-Foto', '-file' => "$Cfg->{'waypoint'}->{'IconPause'}");
$map_canvas->Photo( 'WpNext-Foto', '-file' => "$Cfg->{'waypoint'}->{'IconNext'}");
$map_canvas->Photo( 'WpPrev-Foto', '-file' => "$Cfg->{'waypoint'}->{'IconPrev'}");
$map_canvas->Photo( 'WpFirst-Foto', '-file' => "$Cfg->{'waypoint'}->{'IconFirst'}");
$map_canvas->Photo( 'WpLast-Foto', '-file' => "$Cfg->{'waypoint'}->{'IconLast'}");
$map_canvas->Photo( 'WpHome-Foto', '-file' => "$Cfg->{'waypoint'}->{'IconHome'}");
 
$map_canvas->createImage($MapSizeX/2+100, $MapSizeY-48,
'-tags' => 'Wp-PlayPause',
'-anchor' => 'nw',
'-image' => 'WpPlay-Foto',
);
$map_canvas->createImage($MapSizeX/2+150, $MapSizeY-48,
'-tags' => 'Wp-Stop',
'-anchor' => 'nw',
'-image' => 'WpStop-Foto',
);
$map_canvas->createImage($MapSizeX/2, $MapSizeY-48,
'-tags' => 'Wp-Next',
'-anchor' => 'nw',
'-image' => 'WpNext-Foto',
);
$map_canvas->createImage($MapSizeX/2-50, $MapSizeY-48,
'-tags' => 'Wp-Prev',
'-anchor' => 'nw',
'-image' => 'WpPrev-Foto',
);
$map_canvas->createImage($MapSizeX/2-100, $MapSizeY-48,
'-tags' => 'Wp-First',
'-anchor' => 'nw',
'-image' => 'WpFirst-Foto',
);
$map_canvas->createImage($MapSizeX/2+50, $MapSizeY-48,
'-tags' => 'Wp-Last',
'-anchor' => 'nw',
'-image' => 'WpLast-Foto',
);
$map_canvas->createImage($MapSizeX/2-150, $MapSizeY-48,
'-tags' => 'Wp-Home',
'-anchor' => 'nw',
'-image' => 'WpHome-Foto',
);
 
 
# Balloon attached to Canvas
$map_balloon = $frame_map->Balloon('-statusbar' => $status_line, );
$map_balloon->attach($map_canvas,
'-balloonposition' => 'mouse',
'-state' => 'balloon',
'-msg' => { 'MK-Arrow' => "MikroKopter",
'MK-Home-Line' => "Go Home",
'MK-Home-Dist' => "Distance to Home",
'MK-Target-Line' => "This way to the target",
'MK-Target-Dist' => "Distance to target",
'MK-Speed' => 'Velocity vector',
'Map-Variometer' => 'Variometer',
'Map-Variometer-Pointer' => 'Variometer',
'Map-Variometer-Skala' => 'Variometer',
'Fox' => 'Target for fox hunting',
'Heartbeat' => 'MK data activity',
'Satellite' => 'Good satellite reception',
'Waypoint' => 'Waypoint',
'Map-Border' => 'Map border',
'Waypoint-Connector' => 'Waypoint Connector',
'Wp-PlayPause' => 'Play/Pause',
'Wp-Stop' => 'Stop',
'Wp-First' => 'Go to First Waypoint',
'Wp-Last' => 'Go to Last Waypoint',
'Wp-Next' => 'Go to Next Waypoint',
'Wp-Prev' => 'Go to Previous Waypoint',
'Wp-Home' => 'Go Home',
},
);
#
# Mouse buttons
#
# general Mouse button 1
$map_canvas->CanvasBind("<Button-1>", sub
{
# print coords in status line
my ($x, $y) = ($Tk::event->x, $Tk::event->y);
my ($Lat, $Lon) = &MapXY2Gps($x, $y);
$map_status_line->configure ('-text' => "Lat: $Lat Lon: $Lon x: $x y: $y");
});
# Mouse button 1 for Fox
my $FoxOldx = 0;
my $FoxOldy = 0;
 
# Pick Fox
$map_canvas->bind('Fox' => '<Button-1>' => sub
{
# prepare to move Fox
my ($x, $y) = ($Tk::event->x, $Tk::event->y);
$FoxOldx = $x;
$FoxOldy = $y;
$FoxTime = time;
});
 
# Move Fox
$map_canvas->bind('Fox' => '<Button1-Motion>' => sub
{
my ($x, $y) = ($Tk::event->x, $Tk::event->y);
my $id = $map_canvas->find('withtag', 'current');
 
$map_canvas->move($id => $x - $FoxOldx, $y - $FoxOldy);
$FoxOldx = $x;
$FoxOldy = $y;
if ( time > $FoxTime )
{
# wenn in Bewegung Koordinaten nur 1/s senden
my ($x0, $y0, $x1, $y1) = $map_canvas->bbox ($id);
$x = $x0 + ($x1 - $x0)/2;
$y = $y1;
 
my ($Lat, $Lon) = &MapXY2Gps($x, $y);
&MkFlyTo ( '-lat' => $Lat,
'-lon' => $Lon,
'-mode' => "Target",
);
$FoxTime = time;
 
$map_status_line->configure ('-text' => "Target coordinates sent -> Lat: $Lat Lon: $Lon x: $x y: $y");
}
});
 
# Release Fox
$map_canvas->bind('Fox' => '<Button1-ButtonRelease>' => sub
{
my ($x, $y) = ($Tk::event->x, $Tk::event->y);
my $id = $map_canvas->find('withtag', 'current');
 
my ($x0, $y0, $x1, $y1) = $map_canvas->bbox ($id);
$x = $x0 + ($x1 - $x0)/2;
$y = $y1;
my ($Lat, $Lon) = &MapXY2Gps($x, $y);
&MkFlyTo ( '-lat' => $Lat,
'-lon' => $Lon,
'-mode' => "Target",
);
 
# Show user that Waypoints in MK are cleared
$WaypointsModified = 1;
&WpRedrawLines();
 
$map_status_line->configure ('-text' => "Target coordinates sent -> Lat: $Lat Lon: $Lon x: $x y: $y");
});
 
# Pick Waypoint
$map_canvas->bind('Waypoint' => '<Button-1>' => sub
{
# prepare to move
my ($x, $y) = ($Tk::event->x, $Tk::event->y);
$WpOldx = $x;
$WpOldy = $y;
});
# Move Waypoint
$map_canvas->bind('Waypoint' => '<Button1-Motion>' => sub
{
my ($x, $y) = ($Tk::event->x, $Tk::event->y);
my $id = $map_canvas->find('withtag', 'current');
 
# move icon and Wp-Number
my $WpIndex = &WpGetIndexFromId($id);
if ( $WpIndex >= 0 )
{
my $Tag = $Waypoints[$WpIndex]{'Tag'};
$map_canvas->move($Tag => $x - $WpOldx, $y - $WpOldy);
}
 
$WpOldx = $x;
$WpOldy = $y;
});
 
# Release Wp
$map_canvas->bind('Waypoint' => '<Button1-ButtonRelease>' => sub
{
my ($x, $y) = ($Tk::event->x, $Tk::event->y);
my $id = $map_canvas->find('withtag', 'current');
 
# take coords from lower/middle icon position
my ($x0, $y0, $x1, $y1) = $map_canvas->bbox ($id);
$x = $x0 + ($x1 - $x0)/2;
$y = $y1;
 
# update Waypoint-Array
my $WpIndex = &WpGetIndexFromId($id);
if ( $WpIndex >= 0 )
{
# got it: set new coords
 
my ($Lat, $Lon) = &MapXY2Gps($x, $y);
my $Wp = $Waypoints[$WpIndex];
$Wp->{'MapX'} = $x;
$Wp->{'MapY'} = $y;
$Wp->{'Pos_Lat'} = $Lat;
$Wp->{'Pos_Lon'} = $Lon;
# redraw connector-lines
&WpRedrawLines();
 
# red connectors: Wp still have to be sent to MK
$map_canvas->itemconfigure('Waypoint-Connector',
'-fill' => $Cfg->{'mkcockpit'}->{'ColorWpResend'},
);
$WaypointsModified = 1;
my $WpNum = $WpIndex + 1;
$map_status_line->configure ('-text' => "Waypoint $WpNum postponed Lat: $Lat Lon: $Lon x: $x y: $y");
}
});
 
 
#
# Waypoint-Player - uses Waypoint-List: @Waypoints
#
 
# WP Player state machine
$WpPlayerMode = 'Stop'; # Start, Stop, Pause
$WpPlayerIndex = 0;
$WpPlayerHoldtime = -1;
 
# Mouse bindings
$map_canvas->bind('Wp-PlayPause' => '<Button-1>' => \&CbWpPlayerPlayPause );
$map_canvas->bind('Wp-Next' => '<Button-1>' => \&CbWpPlayerNext );
$map_canvas->bind('Wp-Prev' => '<Button-1>' => \&CbWpPlayerPrev );
$map_canvas->bind('Wp-First' => '<Button-1>' => \&CbWpPlayerFirst );
$map_canvas->bind('Wp-Last' => '<Button-1>' => \&CbWpPlayerLast );
$map_canvas->bind('Wp-Home' => '<Button-1>' => \&CbWpPlayerHome );
$map_canvas->bind('Wp-Stop' => '<Button-1>' => \&CbWpPlayerStop );
 
 
# Focus Canvas, if any key pressed. Needed for the following key-bindings
$main->bind('<Any-Enter>' => sub { $map_canvas->Tk::focus });
 
# Disable default bindings on canvas
$main->bind('Tk::Canvas',"<$_>",undef)for qw /Left Right Up Down/;
 
# keyboard bindings
$map_canvas->Tk::bind( '<Key-space>', \&CbWpPlayerPlayPause );
$map_canvas->Tk::bind( '<Key-n>' , \&CbWpPlayerNext );
$map_canvas->Tk::bind( '<Key-p>' , \&CbWpPlayerPrev );
$map_canvas->Tk::bind( '<Key-f>' , \&CbWpPlayerFirst );
$map_canvas->Tk::bind( '<Key-l>' , \&CbWpPlayerLast );
$map_canvas->Tk::bind( '<Key-h>' , \&CbWpPlayerHome );
$map_canvas->Tk::bind( '<Key-s>' , \&CbWpPlayerStop );
 
 
# Mouse button 3 context menu
my $map_menu = $map_canvas->Menu('-tearoff' => 0,
'-title' =>'None',
'-menuitems' =>
[
[Button => "Add Waypoint and send", -command => sub
{
my $Tag = sprintf "Waypoint-%d.%d", time, int (rand(9)) ; # kind of unique Tag for this Wp
 
# Waypoint Icon
my $IconHeight = 48;
my $IconWidth = 48;
$map_canvas->createImage($MapCanvasX-$IconWidth/2, $MapCanvasY-$IconHeight,
'-tags' => ['Waypoint', $Tag],
'-anchor' => 'nw',
'-image' => 'Waypoint-Photo',
);
 
# Waypoint Number
my $WpNumber = scalar @Waypoints + 1;
$map_canvas->createText ( $MapCanvasX+3, $MapCanvasY-$IconHeight/2+12,
'-tags' => ['WaypointNumber', $Tag],
'-text' => $WpNumber,
'-font' => '-*-Arial-Bold-R-Normal--*-100-*',
'-fill' => $Cfg->{'mkcockpit'}->{'ColorWpNumber'},
'-anchor' => 'w',
);
 
$map_canvas->lower('Waypoint', 'Fox'); # waypoint below Fox
$map_canvas->lower('WaypointNumber', 'Waypoint'); # Nr below waypoint
 
# send Wp to MK
($Lat, $Lon) = &MapXY2Gps($MapCanvasX, $MapCanvasY);
&MkFlyTo ( '-lat' => $Lat,
'-lon' => $Lon,
'-mode' => "Waypoint"
);
# save Wp-Hash in Waypoint-Array
my $Wp = {};
$Wp->{'Tag'} = $Tag;
$Wp->{'MapX'} = $MapCanvasX;
$Wp->{'MapY'} = $MapCanvasY;
$Wp->{'Pos_Lat'} = $Lat;
$Wp->{'Pos_Lon'} = $Lon;
$Wp->{'Pos_Alt'} = $MkOsd{'CurPos_Alt'};
$Wp->{'Heading'} = $Cfg->{'waypoint'}->{'DefaultHeading'};
$Wp->{'ToleranceRadius'} = $Cfg->{'waypoint'}->{'DefaultToleranceRadius'};
$Wp->{'Holdtime'} = $Cfg->{'waypoint'}->{'DefaultHoldtime'};
$Wp->{'Event_Flag'} = $Cfg->{'waypoint'}->{'DefaultEventFlag'};
push @Waypoints, $Wp;
 
# redraw connector-lines
&WpRedrawLines();
 
$map_status_line->configure ('-text' => "Waypoint is stored and sent -> Lat: $Lat Lon: $Lon");
}],
 
 
[Button => "Waypoint Properties", -command => sub
{
# find Wp-Hash for selected icon/tag
my $WpIndex = &WpGetIndexFromId($MapCanvasId);
if ( $WpIndex >= 0 )
{
my $Wp = $Waypoints[$WpIndex];
my $WpNum = $WpIndex + 1;
 
&DisplayHash ($Wp, "Waypoint Properties $WpNum", "Edit Waypoint Refresh");
 
$map_status_line->configure ('-text' => "Wegpunkt $WpNum Eigenschaften");
}
}],
[Button => " Send all Waypoints again", -command => sub
{
&WpSendAll();
$map_status_line->configure ('-text' => "All waypoints sent");
}],
 
'', # Separator
[Button => "Waypoint loaded and sent", -command => sub
{
$WpFile = $main->getOpenFile('-defaultextension' => ".xml",
'-filetypes' =>
[['Waypoints', '.xml' ],
['All Files', '*', ],
],
'-initialdir' => $Cfg->{'waypoint'}->{'WpDir'},
'-title' => "Wegpunkte laden",
);
if ( -f $WpFile )
{
# XML in Hash-Ref lesen
my $Wp = XMLin($WpFile, ForceArray => 1);
 
# XML Hash-Ref in Wp-Array umkopieren
undef @Waypoints;
foreach $key (sort keys %$Wp)
{
my $Point = $Wp->{$key}->[0];
 
# relative Pixelkoordinaten auf Bildgroesse umrechnen
if ( $Point->{'MapX'} <= 1 and $Point->{'MapY'} <= 1 )
{
$Point->{'MapX'} = int ( $Point->{'MapX'} * $MapSizeX + 0.5 );
$Point->{'MapY'} = int ( $Point->{'MapY'} * $MapSizeY + 0.5 );
}
 
# GPS Koordinaten für die aktuelle Karte neu aus Map x/y berechnen
my ($Lat, $Lon) = &MapXY2Gps($Point->{'MapX'}, $Point->{'MapY'});
$Point->{'Pos_Lat'} = $Lat;
$Point->{'Pos_Lon'} = $Lon;
 
push @Waypoints, $Point;
}
 
&WpSendAll();
&WpRedrawLines();
&WpRedrawIcons();
$map_status_line->configure ('-text' => "Waypoints from $WpFile loaded and sent");
}
}],
[Button => "Save Waypoints", -command => sub
{
$WpFile = $main->getSaveFile('-defaultextension' => ".xml",
'-filetypes' =>
[['Waypoints', '.xml' ],
['All Files', '*', ],
],
'-initialdir' => $Cfg->{'waypoint'}->{'WpDir'},
'-title' => "Save Waypoints",
);
 
# Waypoint-Array in Hash umkopieren
my %Wp;
for $i ( 0 .. $#Waypoints )
{
 
my $key = sprintf ("WP-%04d", $i);
$Wp{$key} = $Waypoints[$i];
 
# Pixelkoordinaten relativ zur Bildgroesse speichern
$Wp{$key}{'MapX'} /= $MapSizeX;
$Wp{$key}{'MapY'} /= $MapSizeY;
}
 
# WP-Hash als XML speichern
&XMLout (\%Wp,
'OutputFile' => $WpFile,
'AttrIndent' => '1',
'RootName' => 'Waypoints',
);
$map_status_line->configure ('-text' => "Waypoints stored in $WpFile");
}],
'', # Separator
 
[Button => "Delete waypoint", -command => sub
{
# find Wp-Hash for selected icon/tag
my $WpIndex = &WpGetIndexFromId($MapCanvasId);
if ( $WpIndex >= 0 )
{
my $Wp = $Waypoints[$WpIndex];
 
# remove icon and Wp-Number on canvas;
$map_canvas->delete($Wp->{'Tag'});
 
# delete Wp in Waypoint-Array
splice @Waypoints, $WpIndex, 1;
 
# redraw connector-lines
$WaypointsModified = 1;
&WpRedrawLines();
&WpRedrawIcons(); # wg. Wp-Nummern
 
$WpNum = $WpIndex + 1;
$map_status_line->configure ('-text' => "Waypoint $WpNum deleted");
}
}],
 
[Button => "Delete all waypoints and send", -command => sub
{
undef @Waypoints;
 
# remove all Wp-Icons and Wp-Number on canvas
$map_canvas->delete('Waypoint');
$map_canvas->delete('WaypointNumber');
# redraw connector-lines
&WpRedrawLines();
 
&WpSendAll();
 
$map_status_line->configure ('-text' => "All Waypoints $WpIndex deleted");
}],
 
'', # Separator
[Button => "Fly immediately to Target", -command => sub
{
&MkFlyTo ( '-x' => $MapCanvasX,
'-y' => $MapCanvasY,
'-mode' => "Target"
);
 
# redraw connector-lines
$WaypointsModified = 1;
&WpRedrawLines();
 
$map_status_line->configure ('-text' => "Target coordinates sent -> Lat: $Lat Lon: $Lon x: $x y: $y");
}],
]
);
$map_canvas->CanvasBind("<Button-3>" => [ sub
{
$map_canvas->focus;
my($w, $x, $y) = @_;
($MapCanvasX, $MapCanvasY) = ($Tk::event->x, $Tk::event->y);
$MapCanvasId = $map_canvas->find('withtag', 'current');
$map_menu->post($x, $y);
}, Ev('X'), Ev('Y') ] );
 
 
#
# Objects on canvas
#
 
# Line from MK to Home
$map_canvas->createLine ( $MapSizeX/2, $MapSizeY/2, $MapSizeX/2, $MapSizeY/2,
'-tags' => 'MK-Home-Line',
'-arrow' => 'none',
'-fill' => $Cfg->{'mkcockpit'}->{'ColorHomeLine'},
'-width' => 3,
);
# Text Entfernung positioniert an der Home-Linie
$map_canvas->createText ( $MapSizeX/2 + 8, $MapSizeY/2 - 8,
'-tags' => 'MK-Home-Dist',
'-text' => '0 m',
'-anchor' => 'w',
'-font' => '-*-Arial-Bold-R-Normal--*-200-*',
'-fill' => $Cfg->{'mkcockpit'}->{'ColorHomeDist'},
);
 
# Line from MK to Target, draw invisible out of sight
$map_canvas->createLine ( 0, -100, 0, -100,
'-tags' => 'MK-Target-Line',
'-arrow' => 'none',
'-fill' => $Cfg->{'mkcockpit'}->{'ColorTargetLine'},
'-width' => 3,
);
# Text Entfernung positioniert an der Target-Linie
$map_canvas->createText ( 0, -100,
'-tags' => 'MK-Target-Dist',
'-text' => '0 m',
'-anchor' => 'w',
'-font' => '-*-Arial-Bold-R-Normal--*-200-*',
'-fill' => $Cfg->{'mkcockpit'}->{'ColorTargetDist'},
);
# MK Geschwindigkeits-Vektor
$MapMkSpeedLen = 60; # Länge Speed-Zeiger
my $x0 = $MapSizeX/2;
my $y0 = $MapSizeY/2;
my $x1 = $MapSizeX/2;
my $y1 = $MapSizeY/2 - $MapMkSpeedLen;
$map_canvas->createLine ( $x0, $y0, $x1, $y1,
'-tags' => 'MK-Speed',
'-arrow' => 'last',
'-arrowshape' => [10, 10, 3 ],
'-fill' => $Cfg->{'mkcockpit'}->{'ColorSpeedVector'},
'-width' => 4,
);
 
# MK als Pfeilspitze einer Linie darstellen
$MapMkLen = 25;
my $x0 = $MapSizeX/2;
my $y0 = $MapSizeY/2 + $MapMkLen/2;
my $x1 = $MapSizeX/2;
my $y1 = $MapSizeY/2 - $MapMkLen/2;
$map_canvas->createLine ( $x0, $y0, $x1, $y1,
'-tags' => 'MK-Arrow',
'-arrow' => 'last',
'-arrowshape' => [25, 30, 10 ],
'-fill' => $Cfg->{'mkcockpit'}->{'ColorMkSatNo'},
'-width' => 1
);
 
# OSD Daten auf Karte anzeigen
 
# Flugzeit
$map_canvas->createText ( $MapSizeX/2 - 40, 20,
'-tags' => 'MK-OSD-Tim-Label',
'-text' => 'TIM',
'-font' => '-*-Arial-Bold-R-Normal--*-150-*',
'-fill' => $Cfg->{'mkcockpit'}->{'ColorOsd'},
'-anchor' => 'w',
);
 
$map_canvas->createText ( $MapSizeX/2, 20,
'-tags' => 'MK-OSD-Tim-Value',
'-text' => $MkFlyingTime, # $MkOsd{'FlyingTime'},
'-font' => '-*-Arial-Bold-R-Normal--*-270-*',
'-fill' => $Cfg->{'mkcockpit'}->{'ColorOsd'},
'-anchor' => 'w',
);
 
# Batterie Spannung
$map_canvas->createText ( $MapSizeX/2 - 40, 50,
'-tags' => 'MK-OSD-Bat-Label',
'-text' => 'BAT',
'-font' => '-*-Arial-Bold-R-Normal--*-150-*',
'-fill' => $Cfg->{'mkcockpit'}->{'ColorOsd'},
'-anchor' => 'w',
);
 
$map_canvas->createText ( $MapSizeX/2, 50,
'-tags' => 'MK-OSD-Bat-Value',
'-text' => sprintf ("%3.1f V", $MkOsd{'UBat'}),
'-font' => '-*-Arial-Bold-R-Normal--*-270-*',
'-fill' => $Cfg->{'mkcockpit'}->{'ColorOsd'},
'-anchor' => 'w',
);
 
# Ground speed
$map_canvas->createText ( 10, 20,
'-tags' => 'MK-OSD-Spd-Label',
'-text' => 'SPD',
'-font' => '-*-Arial-Bold-R-Normal--*-150-*',
'-fill' => $Cfg->{'mkcockpit'}->{'ColorOsd'},
'-anchor' => 'w',
);
 
$map_canvas->createText ( 50, 20,
'-tags' => 'MK-OSD-Spd-Value',
'-text' => sprintf ("%3d km/h", $MkOsd{'GroundSpeed'} * 0.036),
'-font' => '-*-Arial-Bold-R-Normal--*-270-*',
'-fill' => $Cfg->{'mkcockpit'}->{'ColorOsd'},
'-anchor' => 'w',
);
 
# Hoehe (Luftdruck)
$map_canvas->createText ( 10, 50,
'-tags' => 'MK-OSD-Alt-Label',
'-text' => 'ALT',
'-font' => '-*-Arial-Bold-R-Normal--*-150-*',
'-fill' => $Cfg->{'mkcockpit'}->{'ColorOsd'},
'-anchor' => 'w',
);
 
$map_canvas->createText ( 50, 50,
'-tags' => 'MK-OSD-Alt-Value',
'-text' => sprintf ("%3d m", $MkOsd{'Altimeter'}/$Cfg->{'mkcockpit'}->{'AltFactor'}),
'-font' => '-*-Arial-Bold-R-Normal--*-270-*',
'-fill' => $Cfg->{'mkcockpit'}->{'ColorOsd'},
'-anchor' => 'w',
);
 
# Variometer
$map_canvas->createText ( 10, 80,
'-tags' => 'MK-OSD-Vsi-Label',
'-text' => 'VSI',
'-font' => '-*-Arial-Bold-R-Normal--*-150-*',
'-fill' => $Cfg->{'mkcockpit'}->{'ColorOsd'},
'-anchor' => 'w',
);
 
$map_canvas->createText ( 50, 80,
'-tags' => 'MK-OSD-Vsi-Value',
'-text' => sprintf ("%3d", $MkOsd{'Variometer'}),
'-font' => '-*-Arial-Bold-R-Normal--*-270-*',
'-fill' => $Cfg->{'mkcockpit'}->{'ColorOsd'},
'-anchor' => 'w',
);
 
# Anzahl Satelitten
$map_canvas->createText ( $MapSizeX - 130, 20,
'-tags' => 'MK-OSD-Sat-Label',
'-text' => 'SAT',
'-font' => '-*-Arial-Bold-R-Normal--*-150-*',
'-fill' => $Cfg->{'mkcockpit'}->{'ColorOsd'},
'-anchor' => 'w',
);
 
$map_canvas->createText ( $MapSizeX - 80, 20,
'-tags' => 'MK-OSD-Sat-Value',
'-text' => "$MkOsd{'SatsInUse'}",
'-font' => '-*-Arial-Bold-R-Normal--*-270-*',
'-fill' => $Cfg->{'mkcockpit'}->{'ColorOsd'},
'-anchor' => 'w',
);
 
# Wegpunkte
$map_canvas->createText ( $MapSizeX - 130, 50,
'-tags' => 'MK-OSD-Wp-Label',
'-text' => 'WPT',
'-font' => '-*-Arial-Bold-R-Normal--*-150-*',
'-fill' => $Cfg->{'mkcockpit'}->{'ColorOsd'},
'-anchor' => 'w',
);
 
$map_canvas->createText ( $MapSizeX - 80, 50,
'-tags' => 'MK-OSD-Wp-Value',
'-text' => $MkOsd{'WaypointIndex'} . "/" . $MkOsd{'WaypointNumber'} ,
'-font' => '-*-Arial-Bold-R-Normal--*-270-*',
'-fill' => $Cfg->{'mkcockpit'}->{'ColorOsd'},
'-anchor' => 'w',
);
# Navigation Mode
$map_canvas->createText ( $MapSizeX - 130, 80,
'-tags' => 'MK-OSD-Mode-Label',
'-text' => 'MOD',
'-font' => '-*-Arial-Bold-R-Normal--*-150-*',
'-fill' => $Cfg->{'mkcockpit'}->{'ColorOsd'},
'-anchor' => 'w',
);
 
$map_canvas->createText ( $MapSizeX - 80, 80,
'-tags' => 'MK-OSD-Mode-Value',
'-text' => '' ,
'-font' => '-*-Arial-Bold-R-Normal--*-270-*',
'-fill' => $Cfg->{'mkcockpit'}->{'ColorOsd'},
'-anchor' => 'w',
);
# Waypoint Holdtime count down
$map_canvas->createText ( $MapSizeX - 130, -110,
'-tags' => 'MK-OSD-Holdtime-Label',
'-text' => 'HLD', # Holdtime Count Down
'-font' => '-*-Arial-Bold-R-Normal--*-150-*',
'-fill' => $Cfg->{'mkcockpit'}->{'ColorOsd'},
'-anchor' => 'w',
);
 
$map_canvas->createText ( $MapSizeX - 80, -110,
'-tags' => 'MK-OSD-Holdtime-Value',
'-text' => '--' ,
'-font' => '-*-Arial-Bold-R-Normal--*-270-*',
'-fill' => $Cfg->{'mkcockpit'}->{'ColorOsd'},
'-anchor' => 'w',
);
 
# Variometer on canvas
my @Polygon;
for ( $y = -100; $y <= 100; $y += 10)
{
my $Len = 5;
if ( ($y % 50) == 0 )
{
$Len = 10;
$map_canvas->createText ( $Len+5, $MapSizeY/2 + $y,
'-tags' => 'Map-Variometer-Skala',
'-text' => sprintf ("%3d", -$y / 10),
'-anchor' => 'w',
'-font' => '-*-Arial-Normal-R-Normal--*-150-*',
'-fill' => $Cfg->{'mkcockpit'}->{'ColorVariometer'},
);
}
push @Polygon, ( 0, $MapSizeY/2 + $y);
push @Polygon, ($Len, $MapSizeY/2 + $y);
push @Polygon, ( 0, $MapSizeY/2 + $y);
}
 
$map_canvas->createLine(@Polygon,
'-tags' => 'Map-Variometer',
'-fill' => $Cfg->{'mkcockpit'}->{'ColorVariometer'},
'-width' => 2,
'-arrow' => 'none',
);
# Vario Pointer
$map_canvas->createPolygon( 5, $MapSizeY/2, 20, $MapSizeY/2+10, 20, $MapSizeY/2-10,
'-tags' => 'Map-Variometer-Pointer',
'-fill' => $Cfg->{'mkcockpit'}->{'ColorVariometerPointer'},
'-outline' => 'black', '-width' => 1,
);
 
# Tracking Canvas
 
if ( $Cfg->{'track'}->{'Active'} =~ /y/i )
{
# Canvas size
$TrackSizeX = 125;
$TrackSizeY = 100;
$TrackOffY = $TrackSizeY - $MapSizeY + 20;
$TrackPtrLen = 50; # Länge Zeiger
 
# draw in map-canvas
$track_canvas = $map_canvas;
 
# Ziffernblatt
my $x0 = $TrackSizeX/2 - $TrackPtrLen;
my $y0 = $TrackSizeY + $TrackPtrLen - $TrackOffY;
my $x1 = $TrackSizeX/2 + $TrackPtrLen;
my $y1 = $TrackSizeY - $TrackPtrLen - $TrackOffY;
$track_canvas->createArc ( $x0, $y0, $x1, $y1,
'-extent' => '200',
'-start' => '-10',
'-style' => 'chord',
'-outline' => 'gray', '-width' => '1',
);
 
# Skala Ziffernblatt
for ($i=0; $i<=180; $i+=15)
{
my $pi = 3.14159265358979;
my $x0 = $TrackSizeX/2 - ($TrackPtrLen - 20) * cos($i / 180 * $pi);
my $y0 = $TrackSizeY - ($TrackPtrLen - 20) * sin($i / 180 * $pi) - $TrackOffY;
my $x1 = $TrackSizeX/2 - ($TrackPtrLen - 28) * cos($i / 180 * $pi);
my $y1 = $TrackSizeY - ($TrackPtrLen - 28) * sin($i / 180 * $pi) - $TrackOffY;
$track_canvas->createLine ( $x0, $y0, $x1, $y1,
'-fill' => 'white',
'-width' => 1,
);
}
 
# Skala Beschriftung Ziffernblatt
for ($i=0; $i<=180; $i+=45)
{
my $pi = 3.14159265358979;
my $x0 = $TrackSizeX/2 - ($TrackPtrLen - 12) * cos($i / 180 * $pi);
my $y0 = $TrackSizeY - ($TrackPtrLen - 12) * sin($i / 180 * $pi) - $TrackOffY;
$track_canvas->createText ( $x0, $y0,
'-text' => $i - 90,
'-fill' => 'white',
);
}
 
# Ziffernblatt Beschriftung Einheit
my $x0 = $TrackSizeX/2;
my $y0 = $MapSizeY -6;
$track_canvas->createText ( $x0, $y0,
'-text' => "Antenna Angle",
'-justify' => 'center',
'-fill' => 'white',
);
# Zeiger
my $x0 = $TrackSizeX/2;
my $y0 = $TrackSizeY - 0 - $TrackOffY;
my $x1 = $TrackSizeX/2;
my $y1 = $TrackSizeY - ($TrackPtrLen - 22) - $TrackOffY;
$track_ptr_id= $track_canvas->createLine ( $x0, $y0, $x1, $y1,
'-tags' => 'Track-Ptr',
'-arrow' => 'last',
'-arrowshape' => [20, 30, 5 ],
'-fill' => 'red',
'-width' => 8,
);
# Zeiger Center
my $Dia = 7;
my $x0 = $TrackSizeX/2 - $Dia;
my $y0 = $TrackSizeY + $Dia - $TrackOffY;
my $x1 = $TrackSizeX/2 + $Dia;
my $y1 = $TrackSizeY - $Dia - $TrackOffY;
$track_canvas->createArc ( $x0, $y0, $x1, $y1,
'-extent' => '359',
'-outline' => 'gray', '-width' => 1,
'-fill' => 'gray',
);
}
#-----------------------------------------------------------------
# Timer
#-----------------------------------------------------------------
 
#
# Timer: 5s
#
$main->repeat (5000, sub
{
if ( ! $MkSendWp )
{
# Query Frequency OSD und Debug regelmäßig neu einstellen, falls Übertragungsfehler
$MkSendQueue->enqueue( "o", "$AddrNC", pack ("C", 10) ); # Frequency OSD Record, * 10ms
$MkSendQueue->enqueue( "d", "$AddrNC", pack ("C", 10) ); # Frequency MK Debug Record, * 10ms
$MkSendQueue->enqueue( "v", "$AddrNC", ""); # Version
$MkSendQueue->enqueue( "e", "$AddrNC", ""); # Error Text Request
}
});
 
#
# Timer: 0.1s - Map Overlay aktualisieren
#
$frame_map_top->repeat (100, sub
{
lock (%MkOsd); # until end of block
 
# Aktuell gültige Karte
my %Map = %{$Maps{'Current'}};
 
if ( $MkOsd{'_Timestamp'} >= time-2 )
{
# Gueltige OSD Daten
my $SatsInUse = $MkOsd{'SatsInUse'};
if ( $SatsInUse > 0 and $MkOsd{'CurPos_Stat'} == 1 and $MkOsd{'HomePos_Stat'} == 1 )
{
# ausreichender GPS Empfang
 
# get x,y map coords of current position
my ($C_x, $C_y, $C_Angel) = &MapGps2XY($MkOsd{'CurPos_Lat'}, $MkOsd{'CurPos_Lon'}, $MkOsd{'CompassHeading'});
# rotate MK arrow
my $dy = sin (deg2rad $C_Angel) * ($MapMkLen/2);
my $dx = cos (deg2rad $C_Angel) * ($MapMkLen/2);
my $x0 = $C_x - $dx;
my $y0 = $C_y - $dy;
my $x1 = $C_x + $dx;
my $y1 = $C_y + $dy;
$map_canvas->coords ('MK-Arrow', $x0, $y0, $x1, $y1);
 
# Update speed vector
my $MapAngel = &MapAngel(); # Norh to Map-Horizont
my $GpsSpeedNorth = $MkNcDebug{'Analog_21'};
my $GpsSpeedEast = $MkNcDebug{'Analog_22'};
my $PhiGpsSpeed = rad2deg atan2 ( $GpsSpeedEast, $GpsSpeedNorth );
$PhiMapSpeed = $PhiGpsSpeed - $MapAngel;
 
# 555 cm/s ~ 20 km/h -> Zeigerlänge = $MkSpeedLen bei 20 km/h
my $dy = sin (deg2rad $PhiMapSpeed) * $MapMkSpeedLen * $MkOsd{'GroundSpeed'} / 555;
my $dx = cos (deg2rad $PhiMapSpeed) * $MapMkSpeedLen * $MkOsd{'GroundSpeed'} / 555;
my $x0 = $C_x;
my $y0 = $C_y;
my $x1 = $C_x + $dx;
my $y1 = $C_y + $dy;
$map_canvas->coords ('MK-Speed', $x0, $y0, $x1, $y1);
# Update Line between Home and MK
my ($H_x, $H_y) = &MapGps2XY($MkOsd{'HomePos_Lat'}, $MkOsd{'HomePos_Lon'});
$map_canvas->coords ('MK-Home-Line', $H_x, $H_y, $C_x, $C_y);
 
# Update Distance between Home and MK
my ($Dist, $Bearing) = MapGpsTo($MkOsd{'CurPos_Lat'}, $MkOsd{'CurPos_Lon'},
$MkOsd{'HomePos_Lat'}, $MkOsd{'HomePos_Lon'} );
my $x = ($C_x - $H_x) / 2 + $H_x + 8;
my $y = ($C_y - $H_y) / 2 + $H_y + 8;
$map_canvas->coords ('MK-Home-Dist', $x, $y);
$map_canvas->itemconfigure ('MK-Home-Dist',
'-text' => sprintf ("%4d m", $Dist),
);
 
# Update OSD - Sat dependent values
$map_canvas->itemconfigure ('MK-OSD-Spd-Value', '-text' => sprintf ("%3d km/h", $MkOsd{'GroundSpeed'} * 0.036) );
 
# Alt = average Luftdruck und Sat
my $Alt = int ( ($MkOsd{'Altimeter'} / $Cfg->{'mkcockpit'}->{'AltFactor'} +
$MkOsd{'CurPos_Alt'} - $MkOsd{'HomePos_Alt'} + 0.5) / 2 );
$map_canvas->itemconfigure ('MK-OSD-Alt-Value', '-text' => sprintf ("%d m", $Alt) );
 
if ( $MkOsd{'TargetPos_Stat'} == 1 )
{
# Valid Target
# Update Line between Target and MK
my ($T_x, $T_y) = &MapGps2XY($MkOsd{'TargetPos_Lat'}, $MkOsd{'TargetPos_Lon'});
$map_canvas->coords ('MK-Target-Line', $C_x, $C_y, $T_x, $T_y);
 
# Update Distance between Target and MK
my ($Dist, $Bearing) = MapGpsTo($MkOsd{'CurPos_Lat'}, $MkOsd{'CurPos_Lon'},
$MkOsd{'TargetPos_Lat'}, $MkOsd{'TargetPos_Lon'} );
my $x = ($C_x - $T_x) / 2 + $T_x - 8;
my $y = ($C_y - $T_y) / 2 + $T_y + 8;
$map_canvas->coords ('MK-Target-Dist', $x, $y);
$map_canvas->itemconfigure ('MK-Target-Dist',
'-text' => sprintf ("%4d m", $Dist),
);
# show target icon
my $IconHeight = 48;
my $IconWidth = 48;
$map_canvas->coords('Target', $T_x - $IconWidth/2, $T_y - $IconHeight );
}
else
{
# No valid Target, move target line out of sight/canvas
$map_canvas->coords ('MK-Target-Line', 0, -100, 0, -100);
$map_canvas->coords ('MK-Home-Dist', 0, -100);
 
# hide target icon
$map_canvas->coords('Target', 0, -100, );
}
}
else
{
# kein ausreichender Sat-Empfang
$map_canvas->itemconfigure ('MK-OSD-Spd-Value', '-text' => sprintf ("%3d km/h", 0 ) );
}
 
# Update OSD - non Sat dependent values
$map_canvas->itemconfigure ('MK-OSD-Bat-Value', '-text' => sprintf ("%3.1f V", $MkOsd{'UBat'}) );
$map_canvas->itemconfigure ('MK-OSD-Vsi-Value', '-text' => sprintf ("%3d", $MkOsd{'Variometer'}) );
$map_canvas->itemconfigure ('MK-OSD-Tim-Value', '-text' => sprintf ("%02d:%02d", $MkFlyingTime / 60, $MkFlyingTime % 60) );
$map_canvas->itemconfigure ('MK-OSD-Sat-Value', '-text' => $MkOsd{'SatsInUse'} );
 
# Waypoints abhaengig vom Modus NC/Player
my $WpValue = "--/--";
if ( $MkOsd{'WaypointNumber'} > 0)
{
$WpValue = sprintf ("%d/%d", $MkOsd{'WaypointIndex'} +1, $MkOsd{'WaypointNumber'});
}
if ($WpPlayerMode ne "Stop")
{
$WpValue = sprintf ("%d/%d", $WpPlayerIndex +1, scalar @Waypoints);
}
$map_canvas->itemconfigure ('MK-OSD-Wp-Value', '-text' => "$WpValue");
 
# blink battery warning
$map_canvas->itemconfigure ('MK-OSD-Bat-Value', '-fill' => $Cfg->{'mkcockpit'}->{'ColorOsd'});
if ( $MkOsd{'UBat'} < $Cfg->{'mkcockpit'}->{'UBatWarning'} )
{
if ( time %2 )
{
$map_canvas->itemconfigure ('MK-OSD-Bat-Value', '-fill' => 'red');
}
}
 
my $Mode = "";
if ($MkOsd{'NCFlags'} & 0x04) { $Mode = "WPT"};
if ($WpPlayerMode eq "Play") { $Mode = "Play" };
if ($WpPlayerMode eq "Pause") { $Mode = "Paus" };
if ($WpPlayerMode eq "Home") { $Mode = "Home" };
if ($MkOsd{'NCFlags'} & 0x01) { $Mode = "Free"};
if ($MkOsd{'NCFlags'} & 0x02) { $Mode = "PH"};
if ($MkOsd{'NCFlags'} & 0x08) { $Mode = "$Mode" . " !"}; # Range Warning
$map_canvas->itemconfigure ('MK-OSD-Mode-Value', '-text' => "$Mode" );
 
# Holdtime count down
if ( $WpPlayerHoldtime >= 0 )
{
my $Holdtime = int ($WpPlayerHoldtime / 2 + 0.5);
$map_canvas->itemconfigure ('MK-OSD-Holdtime-Value', '-text' => sprintf ("%d s", $Holdtime) );
$map_canvas->coords ('MK-OSD-Holdtime-Label', $MapSizeX - 130, 110);
$map_canvas->coords ('MK-OSD-Holdtime-Value', $MapSizeX - 80, 110);
}
else
{
# move out of sight
$map_canvas->coords ('MK-OSD-Holdtime-Label', $MapSizeX - 130, -110);
$map_canvas->coords ('MK-OSD-Holdtime-Value', $MapSizeX - 80, -110);
}
 
 
# Farbe MK-Zeiger abhängig vom GPS Empfang
my $MkCol= $Cfg->{'mkcockpit'}->{'ColorMkSatNo'};
if ( $SatsInUse >= 1 ) { $MkCol = $Cfg->{'mkcockpit'}->{'ColorMkSatLow'} ; }
if ( $SatsInUse >= 6 ) { $MkCol = $Cfg->{'mkcockpit'}->{'ColorMkSatGood'}; }
$map_canvas->itemconfigure ('MK-Arrow', '-fill' => $MkCol);
 
# Variometer Pointer
my $dy = -$MkOsd{'Variometer'} * 10;
$map_canvas->coords('Map-Variometer-Pointer', 5, $MapSizeY/2+$dy, 20, $MapSizeY/2+10+$dy, 20, $MapSizeY/2-10+$dy);
# Show/Hide SatFix Icon
if ($MkOsd{'SatsInUse'} >= 6 )
{
$map_canvas->coords('Satellite', $MapSizeX-190, 10, );
}
else
{
# move icon out of sight
$map_canvas->coords('Satellite', 0, -100, );
}
}
else
{
# keine aktuellen OSD Daten vom MK verfügbar
}
 
});
 
#
# Timer: 0.1s - Tracking Anzeige aktualisieren
#
if ( $Cfg->{'track'}->{'Active'} =~ /y/i )
{
$frame_map_top->repeat (100, sub
{
# Aktuell gültige Karte
my %Map = %{$Maps{'Current'}};
 
# Zeiger neu zeichnen
my $ServoPan = @ServoPos[$MkTrack{'ServoPan'}];
if ( $ServoPan ne "" )
{
my $x0 = $TrackSizeX/2;
my $y0 = $TrackSizeY - 0 - $TrackOffY;
my $x1 = $TrackSizeX/2 - ($TrackPtrLen-22) * cos( deg2rad $ServoPan);
my $y1 = $TrackSizeY - ($TrackPtrLen-22) * sin (deg2rad $ServoPan) - $TrackOffY;
$track_canvas->coords ('Track-Ptr', $x0, $y0, $x1, $y1);
}
 
# Farbe Zeiger abhängig vom GPS Empfang
my $SatsInUse = $MkOsd{'SatsInUse'};
my $TrackPtrCol= 'red';
if ( $SatsInUse >= 1 ) { $TrackPtrCol = 'orange'; }
if ( $SatsInUse >= 6 ) { $TrackPtrCol = 'green'; }
$track_canvas->itemconfigure ('Track-Ptr', '-fill' => $TrackPtrCol);
});
}
 
 
#
# Timer: 0.5s - Waypoint Player
#
$frame_map_top->repeat (500, sub
{
if ($MkOsd{'NCFlags'} & 0x04)
{
# NC is in WPT Mode
 
if ( $WpPlayerMode eq "Pause" )
{
if ( $WpPlayerPause_Lat ne "" and $WpPlayerPause_Lon ne "" )
{
# Gespeicherte Pausen-Pos senden
&MkFlyTo ( '-lat' => $WpPlayerPause_Lat,
'-lon' => $WpPlayerPause_Lon,
'-holdtime' => "60",
'-mode' => "Target",
);
}
}
 
if ( $WpPlayerMode eq "Home" )
{
lock (%MkOsd); # until end of block
if ( $MkOsd{'HomePos_Stat'} == 1 )
{
&MkFlyTo ( '-lat' => $MkOsd{'HomePos_Lat'},
'-lon' => $MkOsd{'HomePos_Lon'},
'-holdtime' => "60",
'-mode' => "Target",
);
}
}
 
my $WpCnt = scalar @Waypoints;
if ( $WpPlayerMode eq "Play" and $WpCnt > 0 and $WpPlayerIndex < $WpCnt )
{
# Target WP-Pos senden
my $Wp_Lon = $Waypoints[$WpPlayerIndex]{'Pos_Lon'};
my $Wp_Lat = $Waypoints[$WpPlayerIndex]{'Pos_Lat'};
if ( $Wp_Lat ne "" and $Wp_Lon ne "" )
{
&MkFlyTo ( '-lat' => $Wp_Lat,
'-lon' => $Wp_Lon,
'-holdtime' => "60",
'-mode' => "Target",
);
}
}
if ( $WpPlayerMode eq "Play" )
{
# Ziel erreicht?
if ( &WpCheckTargetReached() )
{
&WpTargetNext();
}
}
}
 
# WP Player Holdtime count down
if ( $WpPlayerHoldtime > 0 )
{
$WpPlayerHoldtime --;
}
});
 
 
#
# Timer: 1s
#
$frame_map_top->repeat (1000, sub
{
# Aktuell gültige Karte
my %Map = %{$Maps{'Current'}};
 
if ( $MkOsd{'_Timestamp'} >= time -2 )
{
 
# Heartbeat MK Datenübertragung
if ( time %2 )
{
$map_canvas->itemconfigure('Heartbeat', '-image' => 'HeartbeatLarge', );
}
else
{
$map_canvas->itemconfigure('Heartbeat', '-image' => 'HeartbeatSmall', );
}
 
# Flugzeit aktualisieren
# Flugzeit selber mitzählen, da $MkOsd{'FlyingTime'} immer 0 (0.14b)
if ( $MkOsd{'MKFlags'} & 0x02 )
{
$MkFlyingTime += 1;
}
 
# Footprint
if ( $Cfg->{'mkcockpit'}->{'FootprintLength'} > 0 )
{
if ( $MkOsd{'SatsInUse'} > 0 and $MkOsd{'CurPos_Stat'} == 1 )
{
# neuen Footprint hinten anhaengen
my ($x, $y) = &MapGps2XY($MkOsd{'CurPos_Lat'}, $MkOsd{'CurPos_Lon'});
push @Footprint, $x, $y;
}
 
while ( $#Footprint / 2 > $Cfg->{'mkcockpit'}->{'FootprintLength'} )
{
# alte Footprints entfernen
splice @Footprint, 0, 2;
}
 
&FootprintRedraw();
}
 
# tracking antenne
if ( $MkOsd{'MKFlags'} & 0x01 and ! $MkTrack{'IsRunning'} and
$Cfg->{'track'}->{'Active'} =~ /y/i )
{
# start track at 1st motor start
$track_thr = threads->create (\&TrackAntennaGps)->detach();
$MkTrack{'IsRunning'} = "Running";
}
}
});
 
 
MainLoop(); # should never end
 
 
#-----------------------------------------------------------------
# Subroutines
#-----------------------------------------------------------------
 
# Get Wp Index from Canvas Id
sub WpGetIndexFromId()
{
my ($id) = @_;
 
my @Tags = $map_canvas->gettags($id);
my $WpTag = $Tags[1];
 
for $i (0 .. $#Waypoints)
{
my $Wp = $Waypoints[$i];
if ( $Wp->{'Tag'} eq $WpTag )
{
# got it
return $i;
}
}
return -1;
}
 
# Resend all Waypoints to MK
sub WpSendAll()
{
# OSD/Debug Query Frequency verringern, sonst kommen nicht alle Wp im MK an
# Sicherheitshalber doppelt senden
$MkSendWp = 1; # verhindert ueberschreiben im Timer
$MkSendQueue->enqueue( "o", "$AddrNC", pack ("C", 1000) ); # Frequency OSD Record, * 10ms
$MkSendQueue->enqueue( "d", "$AddrNC", pack ("C", 1000) ); # Frequency MK Debug Record, * 10ms
usleep (200000);
$MkSendQueue->enqueue( "o", "$AddrNC", pack ("C", 1000) ); # Frequency OSD Record, * 10ms
$MkSendQueue->enqueue( "d", "$AddrNC", pack ("C", 1000) ); # Frequency MK Debug Record, * 10ms
usleep (200000);
 
# Alte WP-Liste im MK löschen
my $Wp = $Waypoints[0];
&MkFlyTo ( '-lat' => $Wp->{'Pos_Lat'},
'-lon' => Wp->{'Pos_Lon'},
'-mode' => "Waypoint Delete"
);
for $i (0 .. $#Waypoints)
{
my $Wp = $Waypoints[$i];
&MkFlyTo ( '-lat' => $Wp->{'Pos_Lat'},
'-lon' => $Wp->{'Pos_Lon'},
'-alt' => $Wp->{'Pos_Alt'},
'-heading' => $Wp->{'Heading'},
'-toleranceradius' => $Wp->{'ToleranceRadius'},
'-holdtime' => $Wp->{'Holdtime'},
'-eventflag' => $Wp->{'Event_Flag'},
'-mode' => "Waypoint"
);
usleep (150000) # NC Zeit zum Verarbeiten geben
}
 
$MkSendWp = 0; # normale OSD/Debug Query Frequency wird automatisch im 5s Timer wieder eingestellt
 
# gray connectors: Wp are sent to MK
$map_canvas->itemconfigure('Waypoint-Connector',
'-fill' => $Cfg->{'mkcockpit'}->{'ColorWpConnector'},
);
 
# MK ist nun synchron mit @Waypoints
$WaypointsModified = 0;
}
 
# Redraw Waypoint Icons
sub WpRedrawIcons()
{
# delete old icons and Wp-Number from canvas
$map_canvas->delete('Waypoint');
$map_canvas->delete('WaypointNumber');
 
# create new icons
for $i (0 .. $#Waypoints)
{
my $Wp = $Waypoints[$i];
my $x = $Wp->{'MapX'};
my $y = $Wp->{'MapY'};
my $Tag = $Wp->{'Tag'};
 
# Waypoint Icon
my $IconHeight = 48;
my $IconWidth = 48;
$map_canvas->createImage($x-$IconWidth/2, $y-$IconHeight,
'-tags' => ['Waypoint', $Tag],
'-anchor' => 'nw',
'-image' => 'Waypoint-Photo',
);
# Waypoint Number
my $WpNumber = $i + 1;
$map_canvas->createText ( $x+3, $y-$IconHeight/2+12,
'-tags' => ['WaypointNumber', $Tag],
'-text' => $WpNumber,
'-font' => '-*-Arial-Bold-R-Normal--*-100-*',
'-fill' => $Cfg->{'mkcockpit'}->{'ColorWpNumber'},
'-anchor' => 'w',
);
 
}
$map_canvas->lower('Waypoint', 'Fox'); # waypoint below Fox
$map_canvas->lower('WaypointNumber', 'Waypoint'); # waypoint-number below waypoint
}
 
# Redraw Waypoint connectors
sub WpRedrawLines()
{
# delete old connectors from canvas
$map_canvas->delete('Waypoint-Connector');
 
my $Color = $Cfg->{'mkcockpit'}->{'ColorWpConnector'};
if ( $WaypointsModified )
{
$Color = $Cfg->{'mkcockpit'}->{'ColorWpResend'};
}
 
my $Wp = $Waypoints[0];
my $x_last = $Wp->{'MapX'};
my $y_last = $Wp->{'MapY'};
for $i (1 .. $#Waypoints)
{
my $Wp = $Waypoints[$i];
my $x = $Wp->{'MapX'};
my $y = $Wp->{'MapY'};
 
$map_canvas->createLine ( $x_last, $y_last, $x, $y,
'-tags' => 'Waypoint-Connector',
'-arrow' => 'last',
'-arrowshape' => [10, 10, 3 ],
'-fill' => $Color,
'-width' => 1,
);
$x_last = $x;
$y_last = $y;
}
$map_canvas->lower('Waypoint-Connector', 'Waypoint'); # connector below waypoint
}
 
 
# Redraw Footprint
sub FootprintRedraw()
{
# delete old Footprint fom canvas
$map_canvas->delete('Footprint');
 
if ( scalar @Footprint >= 4 ) # at least 2 Koordinaten-Paare
{
$map_canvas->createLine ( @Footprint,
'-tags' => 'Footprint',
'-fill' => $Cfg->{'mkcockpit'}->{'ColorFootprint'},
'-width' => 1,
);
}
$map_canvas->lower('Footprint', 'Fox');
}
 
 
# Display or Modify Hash
sub DisplayHash()
{
my ($hrefData, $Titel, $Mode) = @_;
 
# $Mode: Display, Edit, Waypoint, Refresh
 
my %Id;
my $Label;
my $Value;
 
# Neues Fenster aufmachen
my $popup = $main->Toplevel();
$popup->title($Titel);
# Buttons
my $popup_button = $popup->Frame() -> pack('-side' => 'bottom',
'-expand' => 'y',
'-anchor' => 's',
'-padx' => 5,
'-pady' => 5,
);
$popup_button->Button('-text' => 'Close',
'-command' => sub
{
if ( $Mode =~ /edit/i and $Mode =~ /waypoint/i )
{
$WaypointsModified = 1;
&WpRedrawLines();
&WpRedrawIcons();
}
 
$popup->destroy()
})->pack;
 
# Frame mit den Labels
my $popup_label = $popup->Frame() -> pack('-side' => 'left',
'-expand' => 'y',
'-anchor' => 'w',
'-padx' => 10,
'-pady' => 10,
);
# Labels anzeigen
foreach $Label ( sort keys %{$hrefData})
{
if ( $Translate{$Label} ne "" )
{
$Label = $Translate{$Label};
}
$popup_label->Label ('-text' => $Label,
'-width' => 25,
'-anchor' => 'w',
) -> pack();
}
# Frame mit den Daten
my $popup_values = $popup->Frame() -> pack('-side' => 'left',
'-expand' => 'y',
'-anchor' => 'w',
'-padx' => 10,
'-pady' => 10,
);
# Daten anzeigen
foreach $Value ( sort keys %{$hrefData})
{
if ( $Mode =~ /display/i )
{
# Display
$Id{$Value} = $popup_values->Label ('-text' => ${$hrefData}{$Value},
'-width' => 20,
'-anchor' => 'e',
'-relief' => 'sunken',
) -> pack();
}
if ( $Mode =~ /edit/i )
{
# Edit
$Id{$Value} = $popup_values->Entry ('-textvariable' => \${$hrefData}{$Value},
'-exportselection' => '1',
'-width' => 20,
'-relief' => 'sunken',
) -> pack();
if ( $Mode =~ /waypoint/i )
{
# einige Waypoint-Felder nicht aenderbar einstellen
if ( "MapX MapY Pos_Lat Pos_Lon Tag" =~ /$Value/i )
{
$Id{$Value}->configure('-state' => 'disabled', );
}
}
}
}
 
if ( $Mode =~ /refresh/i )
{
# Timer: 0.1s
$popup_values->repeat (100, sub
{
# Datenfelder alle 100ms aktualisieren
 
my $BgColor = 'white';
if ( $Mode =~ /heartbeat/i )
{
$BgColor = 'red';
if ( $MkOsd{'_Timestamp'} >= time-2 )
{
# gültige daten vom MK
$BgColor = 'white';
}
}
foreach $Value ( sort keys %{$hrefData} )
{
$Id{$Value}->configure('-text' => ${$hrefData}{$Value},
'-background' => "$BgColor",
);
}
});
}
 
return 0;
}
 
 
 
# KonfigurationsClose mkcockpit.xml im Popup-Fenster editieren
sub Configure()
{
 
# Copy Cfg-Hash for editing
my $CfgEdit = {%{$Cfg}};
foreach $key (keys %{$Cfg})
{
if ( ref $Cfg->{$key} )
{
$CfgEdit->{$key} = {%{$Cfg->{$key}}};
}
}
 
# Neues Fenster aufmachen
my $popup = $main->Toplevel();
$popup->title("Preferences - $XmlConfigFile");
 
# jede Sektion in einem Tab anzeigen
my $book = $popup->NoteBook()->pack( -fill=>'both', -expand=>1 );
foreach $key (sort keys %{$CfgEdit})
{
if ( ! ref $CfgEdit->{$key} )
{
next;
}
 
my $TabLabel = "$key";
if ( $Translate{$key} ne "" )
{
$TabLabel = $Translate{$key};
}
 
my $Tab = $book->add( "$key", -label=>"$TabLabel", );
 
# Frame fuer Buttons
my $book_button = $Tab->Frame() -> pack('-side' => 'bottom',
'-expand' => 'y',
'-anchor' => 's',
'-padx' => 5,
'-pady' => 5,
);
 
$book_button->Button('-text' => 'OK',
'-width' => '10',
'-command' => sub
{
# Copy back CfgEdit-Hash
$Cfg = {%{$CfgEdit}};
foreach $key (keys %{$CfgEdit})
{
if ( ref $CfgEdit->{$key} )
{
$Cfg->{$key} = {%{$CfgEdit->{$key}}};
}
}
 
# set new timestamp
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
my $TimeStamp = sprintf ("%04d%02d%02d-%02d%02d%02d", $year+1900, $mon+1, $mday, $hour, $min, $sec);
$Cfg->{'CreationDate'} = $TimeStamp;
 
# Cfg in mkcockpit.xml speichern
&XMLout ($Cfg,
'OutputFile' => $XmlConfigFile,
'AttrIndent' => '1',
'RootName' => 'mkcockpit-Config',
);
 
$popup->destroy();
} )->pack ('-side' => 'left',
'-expand' => 'y',
'-anchor' => 's',
'-padx' => 5,
'-pady' => 5,
);
$book_button->Button('-text' => 'Abort',
'-width' => '10',
'-command' => sub { $popup->destroy() },
)->pack ('-side' => 'left',
'-expand' => 'y',
'-anchor' => 's',
'-padx' => 5,
'-pady' => 5,
);
$book_button->Label ('-text' => "*) Changes are effective only after program restart!",
'-anchor' => 'w',
'-foreground' => 'red',
) ->pack ('-side' => 'left',
'-expand' => 'y',
'-anchor' => 's',
'-padx' => 10,
'-pady' => 5,
);
 
# Frame mit den Labels
my $popup_label = $Tab->Frame() -> pack('-side' => 'left',
'-expand' => 'y',
'-anchor' => 'w',
'-padx' => 10,
'-pady' => 10,
);
# Labels anzeigen
foreach $Label ( sort keys %{$CfgEdit->{$key}})
{
if ( $Translate{$Label} ne "" )
{
$Label = $Translate{$Label};
}
$popup_label->Label ('-text' => $Label,
'-width' => 30,
'-anchor' => 'w',
) -> pack();
}
# Frame mit den Daten
my $popup_values = $Tab->Frame() -> pack('-side' => 'left',
'-expand' => 'y',
'-anchor' => 'w',
'-padx' => 10,
'-pady' => 10,
);
# Eingabefelder mit Daten anzeigen
foreach $Value ( sort keys %{$CfgEdit->{$key}})
{
$popup_values->Entry ('-textvariable' => \$CfgEdit->{$key}->{$Value},
'-exportselection' => '1',
'-width' => 30,
'-relief' => 'sunken',
) -> pack();
}
}
}
 
 
# Waypoint Player: Goto next Waypoint
sub WpTargetNext()
{
$WpPlayerIndex ++;
if ( $WpPlayerIndex > $#Waypoints )
{
# Restart with 1st Wp
$WpPlayerIndex = 0;
}
 
$WpPlayerHoldtime = -1;
}
 
# Waypoint Player: Goto previous Waypoint
sub WpTargetPrev()
{
$WpPlayerIndex --;
if ( $WpPlayerIndex < 0 )
{
# Restart with last Wp
$WpPlayerIndex = $#Waypoints;
}
 
$WpPlayerHoldtime = -1;
}
 
# Waypoint Player: Goto first Waypoint
sub WpTargetFirst()
{
$WpPlayerIndex = 0;
$WpPlayerHoldtime = -1;
}
 
# Waypoint Player: Goto last Waypoint
sub WpTargetLast()
{
$WpPlayerIndex = $#Waypoints;
$WpPlayerHoldtime = -1;
}
 
 
# Waypoint Player: Waypoint Target reached?
sub WpCheckTargetReached()
{
if ( $WpPlayerHoldtime == -1 )
{
lock (%MkOsd); # until end of block
 
if ( $MkOsd{'_Timestamp'} >= time-2 and # Gueltige OSD Daten
$MkOsd{'NCFlags'} & 0x04 and # WPT-Mode
$MkOsd{'SatsInUse'} >= 6 and $MkOsd{'CurPos_Stat'} == 1 and $MkOsd{'HomePos_Stat'} == 1)
{
# Gueltige SAT Daten
my $WpTarget_Lat = $Waypoints[$WpPlayerIndex]{'Pos_Lat'};
my $WpTarget_Lon = $Waypoints[$WpPlayerIndex]{'Pos_Lon'};
my $WpTolerance = $Waypoints[$WpPlayerIndex]{'ToleranceRadius'};
my $WpHoldtime = $Waypoints[$WpPlayerIndex]{'Holdtime'};
 
# Operation Radius pruefen
my ($HomeDist, $HomeBearing) = &MapGpsTo($MkOsd{'HomePos_Lat'}, $MkOsd{'HomePos_Lon'}, $WpTarget_Lat, $WpTarget_Lon );
if ( $HomeDist > $MkOsd{'OperatingRadius'} )
{
# Target entsprechend Operation Radius neu berechnen
$HomeDist = $MkOsd{'OperatingRadius'};
($WpTarget_Lat, $WpTarget_Lon) = &MapGpsAt($MkOsd{'HomePos_Lat'}, $MkOsd{'HomePos_Lon'}, $HomeDist, $HomeBearing);
}
 
 
# Abstand zum Ziel pruefen
my ($Dist, $Bearing) = &MapGpsTo($MkOsd{'CurPos_Lat'}, $MkOsd{'CurPos_Lon'}, $WpTarget_Lat, $WpTarget_Lon );
if ( $Dist <= $WpTolerance )
{
# Target reached - count down Holdtime
$WpPlayerHoldtime = 2 * $WpHoldtime; # 0..2n - decrement im 0.5s timer
}
}
}
 
if ( $WpPlayerHoldtime == 0 ) # wird im 0.5s timer runtergezaehlt
{
# Target reached - Holdtime is over
$WpPlayerHoldtime = -1;
return 1;
}
 
# Target NOT reached
return 0;
}
 
 
#
# Call Back
#
 
# Wp-Player CallBack: Play/Pause button
sub CbWpPlayerPlayPause()
{
# Play/Pause-Icon loeschen und neu anzeigen
$map_canvas->delete('Wp-PlayPause');
 
if ( ($WpPlayerMode eq "Pause") or ($WpPlayerMode eq "Stop") or ($WpPlayerMode eq "Home") )
{
$WpPlayerMode = 'Play';
$WpPlayerHoldtime = -1;
$map_canvas->createImage($MapSizeX/2+100, $MapSizeY-48,
'-tags' => 'Wp-PlayPause',
'-anchor' => 'nw',
'-image' => 'WpPause-Foto',
);
}
else
{
$WpPlayerMode = 'Pause';
$WpPlayerHoldtime = -1;
$map_canvas->createImage($MapSizeX/2+100, $MapSizeY-48,
'-tags' => 'Wp-PlayPause',
'-anchor' => 'nw',
'-image' => 'WpPlay-Foto',
);
 
# momentane Position merken und im Wp-Timer dauernd senden
$WpPlayerPause_Lon = "";
$WpPlayerPause_Lat = "";
 
lock (%MkOsd); # until end of block
if ( $MkOsd{'_Timestamp'} >= time-2 )
{
# Gueltige OSD Daten
if ( $MkOsd{'SatsInUse'} >= 6 and $MkOsd{'CurPos_Stat'} == 1 )
{
$WpPlayerPause_Lon = $MkOsd{'CurPos_Lon'};
$WpPlayerPause_Lat = $MkOsd{'CurPos_Lat'};
}
}
}
}
 
 
# Wp-Player CallBack: Next
sub CbWpPlayerNext()
{
if ( $WpPlayerMode ne 'Stop' )
{
&WpTargetNext();
}
}
 
 
# Wp-Player CallBack: Prev
sub CbWpPlayerPrev()
{
if ( $WpPlayerMode ne 'Stop' )
{
&WpTargetPrev();
}
}
 
 
# Wp-Player CallBack: First
sub CbWpPlayerFirst()
{
if ( $WpPlayerMode ne 'Stop' )
{
&WpTargetFirst();
}
}
 
# Wp-Player CallBack: Last
sub CbWpPlayerLast()
{
if ( $WpPlayerMode ne 'Stop' )
{
&WpTargetLast();
}
}
 
 
# Wp-Player CallBack: Home
sub CbWpPlayerHome()
{
if ( $WpPlayerMode ne 'Stop' )
{
$WpPlayerMode = 'Home';
&WpTargetFirst();
 
$map_canvas->delete('Wp-PlayPause');
$map_canvas->createImage($MapSizeX/2+100, $MapSizeY-48,
'-tags' => 'Wp-PlayPause',
'-anchor' => 'nw',
'-image' => 'WpPlay-Foto',
);
}
}
 
 
# Wp-Player CallBack: Stop
sub CbWpPlayerStop()
{
if ( $WpPlayerMode ne 'Stop' )
{
$WpPlayerMode = 'Stop';
&WpFirstFirst();
 
$map_canvas->delete('Wp-PlayPause');
$map_canvas->createImage($MapSizeX/2+100, $MapSizeY-48,
'-tags' => 'Wp-PlayPause',
'-anchor' => 'nw',
'-image' => 'WpPlay-Foto',
);
 
# Show user that Waypoints in MK are cleared
$WaypointsModified = 1;
&WpRedrawLines();
}
}
 
 
1;
__END__
/MissionCockpit/branches/V0.2.0_EN/translate.pl
0,0 → 1,188
#!/usr/bin/perl
#!/usr/bin/perl -d:ptkdb
 
###############################################################################
#
# translate.pl - Translation fuer MK Datensaetze
#
# Copyright (C) 2009 Rainer Walther (rainerwalther-mail@web.de)
#
# Creative Commons Lizenz mit den Zusaetzen (by, nc, sa)
#
# Es ist Ihnen gestattet:
# * das Werk vervielfältigen, verbreiten und öffentlich zugänglich machen
# * Abwandlungen bzw. Bearbeitungen des Inhaltes anfertigen
#
# Zu den folgenden Bedingungen:
# * Namensnennung.
# Sie müssen den Namen des Autors/Rechteinhabers in der von ihm festgelegten Weise nennen.
# * Keine kommerzielle Nutzung.
# Dieses Werk darf nicht für kommerzielle Zwecke verwendet werden.
# * Weitergabe unter gleichen Bedingungen.
# Wenn Sie den lizenzierten Inhalt bearbeiten oder in anderer Weise umgestalten,
# verändern oder als Grundlage für einen anderen Inhalt verwenden,
# dürfen Sie den neu entstandenen Inhalt nur unter Verwendung von Lizenzbedingungen
# weitergeben, die mit denen dieses Lizenzvertrages identisch oder vergleichbar sind.
#
# Im Falle einer Verbreitung müssen Sie anderen die Lizenzbedingungen, unter welche dieses
# Werk fällt, mitteilen. Am Einfachsten ist es, einen Link auf diese Seite einzubinden.
#
# Jede der vorgenannten Bedingungen kann aufgehoben werden, sofern Sie die Einwilligung
# des Rechteinhabers dazu erhalten.
#
# Diese Lizenz lässt die Urheberpersönlichkeitsrechte unberührt.
#
# Weitere Details zur Lizenzbestimmung gibt es hier:
# Kurzform: http://creativecommons.org/licenses/by-nc-sa/3.0/de/
# Komplett: http://creativecommons.org/licenses/by-nc-sa/3.0/de/legalcode
#
###############################################################################
#
# 2009-02-23 0.0.1 rw created
# 2009-04-01 0.1.0 rw RC1
# 2009-05-06 0.1.1 rw NC 0.15c
#
###############################################################################
 
$Version{'translate.pl'} = "0.1.1 - 2009-04-06";
 
%Translate = (
# NC Debug
"Analog_00" => "Angel Nick",
"Analog_01" => "Angel Roll",
"Analog_02" => "ACC Nick",
"Analog_03" => "ACC Roll",
"Analog_05" => "MK-Flags",
"Analog_06" => "NC-Flags",
"Analog_09" => "GPS Data",
"Analog_10" => "Compass Heading",
"Analog_11" => "Gyro Heading",
"Analog_12" => "SPI Error",
"Analog_13" => "SPI OK",
"Analog_14" => "I2C Error",
"Analog_15" => "I2C OK",
"Analog_16" => "FC Kalman K",
"Analog_17" => "ACC Speed North",
"Analog_18" => "ACC Speed East",
"Analog_19" => "GPS ACC",
"Analog_20" => "Max Drift",
"Analog_21" => "Speed North",
"Analog_22" => "Speed East",
"Analog_23" => "P-Part",
"Analog_24" => "I-Part",
"Analog_25" => "D-Part",
"Analog_26" => "PID-Part",
"Analog_27" => "Distance North",
"Analog_28" => "Distance East",
"Analog_29" => "GPS Nick",
"Analog_30" => "GPS Roll",
"Analog_31" => "Satellite Receive",
# NC OSD
"Altimeter" => "Altitude (air)",
"AngleNick" => "Nick angle",
"AngleRoll" => "Roll angle",
"CompassHeading" => "Compass Heading",
"CurPos_Alt" => "Position Höhe",
"CurPos_Lat" => "Position Latitude",
"CurPos_Lon" => "Position Longitude",
"CurPos_Stat" => "Position Status",
"Errorcode" => "Error Code",
"FlyingTime" => "Flying time",
"GroundSpeed" => "Ground speed",
"Heading" => "Heading",
"HomePosDev_Bearing" => "Homeposition Bearing",
"HomePosDev_Dist" => "Homeposition Distance",
"HomePos_Alt" => "Homeposition Altitude",
"HomePos_Lat" => "Homeposition Latitude",
"HomePos_Lon" => "Homeposition Longitude",
"HomePos_Stat" => "Homeposition Status",
"MKFlags" => "MK Flags",
"NCFlags" => "NC Flags",
"OperatingRadius" => "Operating Radius",
"RC_Quality" => "RC Signal quality",
"SatsInUse" => "Satellites in use",
"TargetHoldTime" => "Target hold time",
"TargetPosDev_Bearing" => "Target Richtung",
"TargetPosDev_Dist" => "Target Distance",
"TargetPos_Alt" => "Target Altitude",
"TargetPos_Lat" => "Target Latitude",
"TargetPos_Lon" => "Target Longitude",
"TargetPos_Stat" => "Target Status",
"TopSpeed" => "Vertical Speed",
"UBat" => "Battery Voltage",
"Variometer" => "Variometer",
"WaypointIndex" => "Waypoint Index",
"WaypointNumber" => "Waypoint Number",
"_Timestamp" => "_Timestamp",
 
# NC Target
"EventFlag" => "Event Flag",
"Richtung" => "Direction",
"HoldTime" => "Hold Time",
"Pos_Alt" => "Position Altitude",
"Pos_Lat" => "Position Latitude",
"Pos_Lon" => "Position Longitude",
"Pos_Stat" => "Position Status",
"ToleranceRadius" => "Tolerance Radius",
 
# Configuration
"geserver" => "Google Earth Server",
"logging" => "Logging",
"map" => "Map",
"mkcockpit" => "Mission Cockpit",
"mkcomm" => "MK Communication",
"Port" => "Port *",
"track" => "Tracking Antenna",
"waypoint" => "Waypoint",
"HttpPort" => "HTTP Port *",
"CsvLogDir" => "CSV Log directory *",
"GpxLogDir" => "GPX Log directory *",
"KmlLogDir" => "KML Log directory *",
"MapDefault" => "Map default Background image *",
"MapDir" => "List of maps *",
"Active" => "Tracking Antenna active *",
"AltFactor" => "Altitude factor (air) in Meter",
"DefaultEventFlag" => "Default Event-Flag",
"DefaultHeading" => "Default Heading",
"DefaultHoldtime" => "Default Holdtime",
"DefaultToleranceRadius"=> "Default Tolerance Radius",
"WpDir" => "Waypoint List *",
"ColorAirfield" => "Colour Airfield boundary *",
"ColorHomeDist" => "Colour Text Distance Home *",
"ColorHomeLine" => "Colour Line Distance Home *",
"ColorMkSatGood" => "Colour MK good Sat reception",
"ColorMkSatLow" => "Colour MK weak Sat reception",
"ColorMkSatNo" => "Colour MK no Sat reception",
"ColorOsd" => "Colour OSD *",
"ColorSpeedVector" => "Colour Speed-Vector *",
"ColorTargetDist" => "Colour Text Target distance *",
"ColorTargetLine" => "Colour Linie Target distance *",
"ColorVariometer" => "Colour Variometer Scale *",
"ColorVariometerPointer"=> "Colour Variometer pointer *",
"ColorWpConnector" => "Colour Waypoint connector",
"ColorWpResend" => "Colour Wp-Conn. changed",
"ColorWpNumber" => "Colour Waypoint Number",
"ColorFootprint" => "Colour Footprint",
"FootprintLength" => "Länge Footprint (in s)",
"IconFox" => "Icon Fox *",
"IconHeartLarge" => "Icon Heartbeat large *",
"IconHeartSmall" => "Icon Heartbeat small *",
"IconSatellite" => "Icon Satellite *",
"IconTarget" => "Icon Target *",
"IconWaypoint" => "Icon Waypoint *",
"Intervall" => "Interval (in s) *",
"UBatWarning" => "Battery Warning (in V) ",
 
# Waypoint
+
+ "MapY" => "Y-Position on the map",
+ "Event_Flag" => "Event Flag",
+ "Holdtime" => "Waiting time at Waypoint",
+ );
+
+
+1;
+
+__END__