Subversion Repositories Projects

Rev

Rev 2313 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2313 Rev 2315
Line 258... Line 258...
258
        /// </summary>
258
        /// </summary>
259
        DataTable dtAnalog = new DataTable();
259
        DataTable dtAnalog = new DataTable();
260
        /// <summary>
260
        /// <summary>
261
        /// datatable for motordata (current,temp)
261
        /// datatable for motordata (current,temp)
262
        /// </summary>
262
        /// </summary>
263
        DataTable dtMotors1 = new DataTable();
263
        DataTable dtMotors = new DataTable();
Line 264... Line 264...
264
 
264
 
265
        DataTable dtWaypoints = new DataTable();
265
        DataTable dtWaypoints = new DataTable();
266
        static volatile int _iWPCount = -1;
266
        static volatile int _iWPCount = -1;
267
        static volatile int _iWPIndex = -1;
267
        static volatile int _iWPIndex = -1;
Line 348... Line 348...
348
        /// initialize the datatables
348
        /// initialize the datatables
349
        /// with columnnames etc
349
        /// with columnnames etc
350
        /// </summary>
350
        /// </summary>
351
        void _dataTablesInit()
351
        void _dataTablesInit()
352
        {
352
        {
353
            dtMotors1.Columns.Add("#");
353
            dtMotors.Columns.Add("#");
354
            if (Thread.CurrentThread.CurrentUICulture.Name == "de-DE")
354
            if (Thread.CurrentThread.CurrentUICulture.Name == "de-DE")
355
                dtMotors1.Columns.Add("Strom");
355
                dtMotors.Columns.Add("Strom");
356
            else
356
            else
357
                dtMotors1.Columns.Add("Current");
357
                dtMotors.Columns.Add("Current");
358
            dtMotors1.Columns.Add("Temp");
358
            dtMotors.Columns.Add("Temp");
359
            dgvMotors1.DataContext = dtMotors1.DefaultView;
359
            dgvMotors1.DataContext = dtMotors.DefaultView;
360
            _initDTMotors();
360
            _initDTMotors();
Line 361... Line 361...
361
 
361
 
362
            Setter setter = new Setter(ContentControl.PaddingProperty, new Thickness(5,0,5,0));
362
            Setter setter = new Setter(ContentControl.PaddingProperty, new Thickness(5,0,5,0));
363
            Style style = new Style(typeof(System.Windows.Controls.Primitives.DataGridColumnHeader));
363
            Style style = new Style(typeof(System.Windows.Controls.Primitives.DataGridColumnHeader));
Line 366... Line 366...
366
            style.Setters.Add(setter);
366
            style.Setters.Add(setter);
367
            setter = new Setter(ContentControl.ForegroundProperty, new SolidColorBrush(Colors.White));
367
            setter = new Setter(ContentControl.ForegroundProperty, new SolidColorBrush(Colors.White));
368
            style.Setters.Add(setter);
368
            style.Setters.Add(setter);
Line 369... Line 369...
369
 
369
 
370
            dtWaypoints.Columns.Add("Index",typeof(int));
370
            dtWaypoints.Columns.Add("Index",typeof(int));
371
            dtWaypoints.Columns.Add("Type",typeof(string));
371
            dtWaypoints.Columns.Add("Type", typeof(int));
372
            dtWaypoints.Columns.Add("Name",typeof(string));
372
            dtWaypoints.Columns.Add("Name",typeof(string));
373
            dtWaypoints.Columns.Add("Latitude",typeof(string));
373
            dtWaypoints.Columns.Add("Latitude",typeof(double));
374
            dtWaypoints.Columns.Add("Longitude",typeof(string));
374
            dtWaypoints.Columns.Add("Longitude",typeof(double));
375
            dtWaypoints.Columns.Add("Altitude",typeof(string));
375
            dtWaypoints.Columns.Add("Altitude",typeof(string));
376
            dtWaypoints.Columns.Add("Heading",typeof(string));
376
            dtWaypoints.Columns.Add("Heading",typeof(string));
377
            dtWaypoints.Columns.Add("Speed",typeof(string));
377
            dtWaypoints.Columns.Add("Speed",typeof(string));
378
            dtWaypoints.Columns.Add("ClimbRate",typeof(string));
378
            dtWaypoints.Columns.Add("ClimbRate",typeof(string));
Line 389... Line 389...
389
            dgvWP.ColumnHeaderStyle = style;
389
            dgvWP.ColumnHeaderStyle = style;
Line 390... Line 390...
390
 
390
 
391
 
391
 
392
        }
392
        }
393
        /// <summary>
393
        /// <summary>
394
        /// initialize the datatable dtMotors1 for motor values
394
        /// initialize the datatable dtMotors for motor values
395
        /// DataGridView dgvMotors1 is bound to dtMotors1
395
        /// DataGridView dgvMotors1 is bound to dtMotors1
396
        /// </summary>
396
        /// </summary>
397
        void _initDTMotors()
397
        void _initDTMotors()
398
        {
398
        {
399
            for (int i = 0; i < 12; i++)
399
            for (int i = 0; i < 12; i++)
400
            {
400
            {
401
                if (dtMotors1.Rows.Count < 12)
401
                if (dtMotors.Rows.Count < 12)
402
                    dtMotors1.Rows.Add((i + 1).ToString(), "NA", "NA");
402
                    dtMotors.Rows.Add((i + 1).ToString(), "NA", "NA");
403
                else
403
                else
404
                {
404
                {
405
                    dtMotors1.Rows[i].SetField(1, "NA");
405
                    dtMotors.Rows[i].SetField(1, "NA");
406
                    dtMotors1.Rows[i].SetField(2, "NA");
406
                    dtMotors.Rows[i].SetField(2, "NA");
407
                }
407
                }
Line 408... Line 408...
408
            }
408
            }
Line 1506... Line 1506...
1506
 
1506
 
1507
                    if (data[i] < _iMotors)
1507
                    if (data[i] < _iMotors)
1508
                    {
1508
                    {
1509
                        if (bAvailable)
1509
                        if (bAvailable)
1510
                        {
1510
                        {
1511
                            dtMotors1.Rows[data[i]].SetField(1, ((double)data[i + 1] / (double)10).ToString("0.0 A"));
1511
                            dtMotors.Rows[data[i]].SetField(1, ((double)data[i + 1] / (double)10).ToString("0.0 A"));
1512
                            dtMotors1.Rows[data[i]].SetField(2, data[i + 2].ToString("0 °C"));
1512
                            dtMotors.Rows[data[i]].SetField(2, data[i + 2].ToString("0 °C"));
1513
                        }
1513
                        }
1514
                        else
1514
                        else
1515
                        {
1515
                        {
1516
                            dtMotors1.Rows[data[i]].SetField(1, "NA");
1516
                            dtMotors.Rows[data[i]].SetField(1, "NA");
1517
                            dtMotors1.Rows[data[i]].SetField(2, "NA");
1517
                            dtMotors.Rows[data[i]].SetField(2, "NA");
1518
                        }
1518
                        }
1519
                    }
1519
                    }
1520
                    //if (data[i] > 3 && data[i] < 8)
1520
                    //if (data[i] > 3 && data[i] < 8)
1521
                    //{
1521
                    //{
Line 1767... Line 1767...
1767
                Dispatcher.Invoke(() => lblWPIndex.Content = data[1].ToString());
1767
                Dispatcher.Invoke(() => lblWPIndex.Content = data[1].ToString());
1768
                Dispatcher.Invoke(() => lblWPCount.Content = data[0].ToString());
1768
                Dispatcher.Invoke(() => lblWPCount.Content = data[0].ToString());
1769
                if (_bGetWP)
1769
                if (_bGetWP)
1770
                {
1770
                {
1771
                    if (data[1] == 1)
1771
                    if (data[1] == 1)
-
 
1772
                    {
1772
                        dtWaypoints.Rows.Clear();
1773
                        dtWaypoints.Rows.Clear();
-
 
1774
                        foreach (GMapMarker p in MainMap.Markers)
-
 
1775
                        {
-
 
1776
                            if (p.Shape.GetType() == typeof(CustomMarkerWP))
-
 
1777
                                MainMap.Markers.Remove(p);
-
 
1778
                        }
-
 
1779
                    }
1773
                    DataRow dr = dtWaypoints.NewRow();
1780
                    DataRow dr = dtWaypoints.NewRow();
1774
                    dr = Waypoints.toDataRow(data, dr);
1781
                    dr = Waypoints.toDataRow(data, dr);
1775
                    dtWaypoints.Rows.Add(dr);
1782
                    dtWaypoints.Rows.Add(dr);
-
 
1783
                    GMapMarker wp = new GMapMarker(new PointLatLng((double)dr[3], (double)dr[4]));
-
 
1784
                    wp.Shape = new CustomMarkerWP(this, wp, (string)dr[2],(int)dr[1]);
-
 
1785
                    _setMarkerColor(wp, (int)dr[1]);
-
 
1786
                    MainMap.Markers.Add(wp);
1776
                    Dispatcher.Invoke(() => dgvWP.Items.Refresh());
1787
                    Dispatcher.Invoke(() => dgvWP.Items.Refresh());
1777
                    Dispatcher.Invoke(() => _iWPIndex = data[1]);
1788
                    Dispatcher.Invoke(() => _iWPIndex = data[1]);
1778
                    if (data[1] == data[0])
1789
                    if (data[1] == data[0])
1779
                    {
1790
                    {
1780
                        _bGetWP = false;
1791
                        _bGetWP = false;
Line 2003... Line 2014...
2003
                Log(LogMsgType.Error, "NOT CONNECTED!");
2014
                Log(LogMsgType.Error, "NOT CONNECTED!");
Line 2004... Line 2015...
2004
 
2015
 
2005
        }
2016
        }
2006
        void _getWP()
2017
        void _getWP()
2007
        {
-
 
2008
            //if (_iWP > 0)
-
 
2009
            //{
-
 
2010
            //    _getWPList();
-
 
2011
            //}
-
 
2012
            //else
-
 
2013
            //{
-
 
2014
            //    if (_iWP == -1)
-
 
2015
            //    {
2018
        {
2016
            _bGetWPCount = true;
2019
            _bGetWPCount = true;
2017
            _getpWP(1);
2020
            _getpWP(1); //get the itemscount of wp
2018
            while (_bGetWPCount)
2021
            while (_bGetWPCount)
2019
                Thread.Sleep(100);
2022
                Thread.Sleep(100);
2020
            if (_iWPCount > 0)
2023
            if (_iWPCount > 0)
2021
                _getWPList();
-
 
2022
            //    }
-
 
2023
            //}
2024
                _getWPList();
2024
        }
2025
        }
2025
        void _getWPList()
2026
        void _getWPList()
2026
        {
2027
        {
2027
            _bGetWP = true;
2028
            _bGetWP = true;
Line 2556... Line 2557...
2556
 
2557
 
2557
                MessageBox.Show("Error writing ini-file!" + Environment.NewLine + "Please make sure that the programm is in a location where it is allowed to write" + Environment.NewLine + e.Message, "Write ini-file", MessageBoxButton.OK, MessageBoxImage.Error);
2558
                MessageBox.Show("Error writing ini-file!" + Environment.NewLine + "Please make sure that the programm is in a location where it is allowed to write" + Environment.NewLine + e.Message, "Write ini-file", MessageBoxButton.OK, MessageBoxImage.Error);
2558
            }
2559
            }
Line -... Line 2560...
-
 
2560
        }
2559
        }
2561
 
2560
 
2562
        #region WP
2561
        void _readWPLFile()
2563
        void _readWPLFile()
2562
        {
2564
        {
2563
            Microsoft.Win32.OpenFileDialog fd = new Microsoft.Win32.OpenFileDialog();
2565
            Microsoft.Win32.OpenFileDialog fd = new Microsoft.Win32.OpenFileDialog();
Line 2589... Line 2591...
2589
                                string wp;
2591
                                string wp;
2590
                                int i;
2592
                                int i;
2591
                                NumberFormatInfo nfi = new NumberFormatInfo();
2593
                                NumberFormatInfo nfi = new NumberFormatInfo();
2592
                                nfi.NumberDecimalSeparator = ".";
2594
                                nfi.NumberDecimalSeparator = ".";
2593
                                dtWaypoints.Rows.Clear();
2595
                                dtWaypoints.Rows.Clear();
-
 
2596
                                for(int k = 0; k < MainMap.Markers.Count;)
-
 
2597
                                {
-
 
2598
                                    GMapMarker p = MainMap.Markers[k];
-
 
2599
                                    if (p.Shape.GetType() == typeof(CustomMarkerWP))
-
 
2600
                                        MainMap.Markers.Remove(p);
-
 
2601
                                    else
-
 
2602
                                        k++;
-
 
2603
                                }
2594
                                for (int k = 1; k <= wpnum; k++)
2604
                                for (int k = 1; k <= wpnum; k++)
2595
                                {
2605
                                {
2596
                                    DataRow dr = dtWaypoints.NewRow();
2606
                                    DataRow dr = dtWaypoints.NewRow();
2597
                                    dr.ItemArray = new object[16];
2607
                                    dr.ItemArray = new object[16];
2598
                                    object[] o = new object[16];
2608
                                    object[] o = new object[16];
Line 2600... Line 2610...
2600
                                    wp = "Point" + k.ToString();
2610
                                    wp = "Point" + k.ToString();
2601
                                    o[i] = k;
2611
                                    o[i] = k;
2602
                                    i++;
2612
                                    i++;
2603
                                    sVal = ini.IniReadValue(wp, "Type");
2613
                                    sVal = ini.IniReadValue(wp, "Type");
2604
                                    if (sVal != "")
2614
                                    if (sVal != "")
2605
                                        o[i] = Convert.ToInt16(sVal) -1;
2615
                                        o[i] = Convert.ToInt16(sVal) - 1;
2606
                                    i++;
2616
                                    i++;
2607
                                    sVal = ini.IniReadValue(wp, "Prefix");
2617
                                    sVal = ini.IniReadValue(wp, "Prefix");
2608
                                    if (sVal != "")
2618
                                    if (sVal != "")
2609
                                        o[i] = sVal == "0" ? "P" + k.ToString() : sVal + k.ToString();
2619
                                        o[i] = sVal == "0" ? "P" + k.ToString() : sVal + k.ToString();
2610
                                    i++;
2620
                                    i++;
Line 2624... Line 2634...
2624
                                    if (sVal != "")
2634
                                    if (sVal != "")
2625
                                        o[i] = Convert.ToInt16(sVal);
2635
                                        o[i] = Convert.ToInt16(sVal);
2626
                                    i++;
2636
                                    i++;
2627
                                    sVal = ini.IniReadValue(wp, "Speed");
2637
                                    sVal = ini.IniReadValue(wp, "Speed");
2628
                                    if (sVal != "")
2638
                                    if (sVal != "")
2629
                                        o[i] =Convert.ToInt16(sVal);
2639
                                        o[i] = Convert.ToInt16(sVal);
2630
                                    i++;
2640
                                    i++;
2631
                                    sVal = ini.IniReadValue(wp, "ClimbRate");
2641
                                    sVal = ini.IniReadValue(wp, "ClimbRate");
2632
                                    if (sVal != "")
2642
                                    if (sVal != "")
2633
                                        o[i] = Convert.ToInt16(sVal);
2643
                                        o[i] = Convert.ToInt16(sVal);
2634
                                    i++;
2644
                                    i++;
Line 2655... Line 2665...
2655
                                        o[i] = Convert.ToInt16(sVal);
2665
                                        o[i] = Convert.ToInt16(sVal);
2656
                                    i++;
2666
                                    i++;
2657
                                    o[i] = "New";
2667
                                    o[i] = "New";
Line 2658... Line 2668...
2658
 
2668
 
2659
                                    dr.ItemArray = o;
-
 
2660
                                  //  dtWaypoints.Rows.Add(dr);
2669
                                    dr.ItemArray = o;
-
 
2670
                                    dtWaypoints.Rows.Add(dr);
-
 
2671
                                    GMapMarker wpMarker = new GMapMarker(new PointLatLng((double)o[3], (double)o[4]));
-
 
2672
                                    wpMarker.Shape = new CustomMarkerWP(this, wpMarker, (string)dr[2], (int)o[1]);
-
 
2673
                                    _setMarkerColor(wpMarker, (int)o[1]);
-
 
2674
                                    MainMap.Markers.Add(wpMarker);
2661
                                    dtWaypoints.Rows.Add(dr);
2675
 
2662
                                    Dispatcher.Invoke(() => lblWPIndex.Content = k.ToString());
2676
                                    Dispatcher.Invoke(() => lblWPIndex.Content = k.ToString());
2663
                                    Dispatcher.Invoke(() => lblWPCount.Content = k.ToString());
2677
                                    Dispatcher.Invoke(() => lblWPCount.Content = k.ToString());
2664
                                    Dispatcher.Invoke(() => dgvWP.Items.Refresh());
2678
                                    Dispatcher.Invoke(() => dgvWP.Items.Refresh());
2665
                                    Thread.Sleep(10);
2679
                                    Thread.Sleep(10);
Line 2675... Line 2689...
2675
                    MessageBox.Show("Error parsing wpl-file!" + Environment.NewLine + e.Message, "Read wpl-file", MessageBoxButton.OK, MessageBoxImage.Error);
2689
                    MessageBox.Show("Error parsing wpl-file!" + Environment.NewLine + e.Message, "Read wpl-file", MessageBoxButton.OK, MessageBoxImage.Error);
2676
                }
2690
                }
Line 2677... Line 2691...
2677
 
2691
 
2678
            }
2692
            }
-
 
2693
        }
-
 
2694
        void _setMarkerColor(GMapMarker wpMarker,int iType)
-
 
2695
        {
-
 
2696
            Dispatcher.Invoke(() =>
-
 
2697
            {
-
 
2698
                switch (iType)
-
 
2699
                {
-
 
2700
                    case 0:
-
 
2701
                        if (comboBoxWPColor.SelectionBoxItem != null)
-
 
2702
                        {
-
 
2703
                            string s = comboBoxWPColor.SelectionBoxItem.ToString();
-
 
2704
                            ((CustomMarkerWP)(wpMarker.Shape)).setColor(s);
-
 
2705
                        }
-
 
2706
                        else
-
 
2707
                            ((CustomMarkerWP)(wpMarker.Shape)).setColor("red");
-
 
2708
                        break;
-
 
2709
                    case 1:
-
 
2710
                        if (comboBoxPOIColor.SelectionBoxItem != null)
-
 
2711
                        {
-
 
2712
                            string s = comboBoxPOIColor.SelectionBoxItem.ToString();
-
 
2713
                            ((CustomMarkerWP)(wpMarker.Shape)).setColor(s);
-
 
2714
                        }
-
 
2715
                        else
-
 
2716
                            ((CustomMarkerWP)(wpMarker.Shape)).setColor("red");
-
 
2717
                        break;
-
 
2718
                    case 2:
-
 
2719
                        if (comboBoxFSColor.SelectionBoxItem != null)
-
 
2720
                        {
-
 
2721
                            string s = comboBoxFSColor.SelectionBoxItem.ToString();
-
 
2722
                            ((CustomMarkerWP)(wpMarker.Shape)).setColor(s);
-
 
2723
                        }
-
 
2724
                        else
-
 
2725
                            ((CustomMarkerWP)(wpMarker.Shape)).setColor("red");
-
 
2726
                        break;
-
 
2727
                    default:
-
 
2728
                        ((CustomMarkerWP)(wpMarker.Shape)).setColor("red");
-
 
2729
                        break;
-
 
2730
                }
Line -... Line 2731...
-
 
2731
            });
2679
        }
2732
 
2680
 
2733
        }
-
 
2734
        private void comboBoxWPColor_DropDownClosed(object sender, EventArgs e)
-
 
2735
        {
-
 
2736
            Dispatcher.Invoke(() =>
-
 
2737
            {
-
 
2738
                if (comboBoxWPColor.SelectionBoxItem != null)
-
 
2739
                {
-
 
2740
                    for (int k = 0; k < MainMap.Markers.Count;k++)
-
 
2741
                    {
2681
        private void btnLoadWPLFile_Click(object sender, RoutedEventArgs e)
2742
                        GMapMarker p = MainMap.Markers[k];
-
 
2743
                        if (p.Shape.GetType() == typeof(CustomMarkerWP))
-
 
2744
                        {
-
 
2745
                            if (((CustomMarkerWP)p.Shape).WPType == 0)
-
 
2746
                            {
-
 
2747
                                string s = comboBoxWPColor.SelectionBoxItem.ToString();
-
 
2748
                                ((CustomMarkerWP)(p.Shape)).setColor(s);
-
 
2749
                            }
-
 
2750
                        }
-
 
2751
                    }
2682
        {
2752
                }
-
 
2753
            });
-
 
2754
        }
2683
            _readWPLFile();
2755
        private void comboBoxPOIColor_DropDownClosed(object sender, EventArgs e)
2684
        }
2756
        {
2685
        #endregion functions
2757
            Dispatcher.Invoke(() =>
-
 
2758
            {
-
 
2759
                if (comboBoxPOIColor.SelectionBoxItem != null)
-
 
2760
                {
-
 
2761
                    for (int k = 0; k < MainMap.Markers.Count; k++)
-
 
2762
                    {
-
 
2763
                        GMapMarker p = MainMap.Markers[k];
-
 
2764
                        if (p.Shape.GetType() == typeof(CustomMarkerWP))
-
 
2765
                        {
-
 
2766
                            if (((CustomMarkerWP)p.Shape).WPType == 1)
-
 
2767
                            {
-
 
2768
                                string s = comboBoxPOIColor.SelectionBoxItem.ToString();
-
 
2769
                                ((CustomMarkerWP)(p.Shape)).setColor(s);
-
 
2770
                            }
-
 
2771
                        }
2686
    }
2772
                    }
Line -... Line 2773...
-
 
2773
                }
2687
    public class BooleanToVisibilityConverter : IValueConverter
2774
            });
2688
    {
2775
 
-
 
2776
        }
-
 
2777
        private void comboBoxFSColor_DropDownClosed(object sender, EventArgs e)
-
 
2778
        {
-
 
2779
            Dispatcher.Invoke(() =>
-
 
2780
            {
-
 
2781
                if (comboBoxFSColor.SelectionBoxItem != null)
-
 
2782
                {
-
 
2783
                    for (int k = 0; k < MainMap.Markers.Count; k++)
-
 
2784
                    {
-
 
2785
                        GMapMarker p = MainMap.Markers[k];
-
 
2786
                        if (p.Shape.GetType() == typeof(CustomMarkerWP))
-
 
2787
                        {
2689
 
2788
                            if (((CustomMarkerWP)p.Shape).WPType == 2)
-
 
2789
                            {
-
 
2790
                                string s = comboBoxFSColor.SelectionBoxItem.ToString();
-
 
2791
                                ((CustomMarkerWP)(p.Shape)).setColor(s);
-
 
2792
                            }
-
 
2793
                        }
2690
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
2794
                    }
2691
        {
-
 
2692
            return (bool)value ? Visibility.Visible : Visibility.Collapsed;
2795
                }
2693
        }
2796
            });
2694
 
2797
        }
2695
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
2798
        private void btnLoadWPLFile_Click(object sender, RoutedEventArgs e)
2696
        {
2799
        {
Line -... Line 2800...
-
 
2800
            _readWPLFile();
-
 
2801
        }
-
 
2802
        #endregion WP
-
 
2803
 
-
 
2804
        #endregion functions
2697
            throw new NotImplementedException();
2805
    }
2698
        }
2806
     /// <summary>
2699
    }
2807
    /// formats the wp datatable values for display in datagrid - this is bound in the datagrid as a converter
2700
 
2808
    /// </summary>
2701
    public class waypointsConverter : IValueConverter
2809
    public class waypointsConverter : IValueConverter