Subversion Repositories Projects

Rev

Rev 2362 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2362 Rev 2363
Line 1896... Line 1896...
1896
                        });
1896
                        });
1897
                    }
1897
                    }
1898
                    DataRow dr = dtWaypoints.NewRow();
1898
                    DataRow dr = dtWaypoints.NewRow();
1899
                    dr = Waypoints.toDataRow(data, dr);
1899
                    dr = Waypoints.toDataRow(data, dr);
1900
                    dtWaypoints.Rows.Add(dr);
1900
                    dtWaypoints.Rows.Add(dr);
1901
                    Dispatcher.Invoke(() => {
-
 
1902
                        GMapMarker wp = new GMapMarker(new PointLatLng((double)dr[3], (double)dr[4]));
-
 
1903
                        wp.Shape = new CustomMarkerWP(this, wp, (string)dr[2],(int)dr[1]);
1901
                    _createWP(new PointLatLng((double)dr[3], (double)dr[4]), (string)dr[2], (int)dr[1]);
1904
                        wp.Offset = new System.Windows.Point(-11.5, -11.5);
-
 
1905
                        _setMarkerColor(wp, (int)dr[1]);
-
 
1906
                        MainMap.Markers.Add(wp);
-
 
1907
                    });
-
 
1908
                    Dispatcher.Invoke(() => dgvWP.Items.Refresh());
1902
                    Dispatcher.Invoke(() => dgvWP.Items.Refresh());
1909
                    Dispatcher.Invoke(() => _iWPIndex = data[1]);
1903
                    Dispatcher.Invoke(() => _iWPIndex = data[1]);
1910
                    if ((int)dr[1] == 0)
-
 
1911
                        wpList.Add(new PointLatLng((double)dr[3], (double)dr[4]));
-
 
1912
                    if (data[1] == data[0])
1904
                    if (data[1] == data[0])
1913
                    {
1905
                    {
1914
                        _bGetWP = false;
1906
                        _bGetWP = false;
1915
                        Dispatcher.Invoke(() => dgvWP.Items.Refresh());
1907
                        Dispatcher.Invoke(() => dgvWP.Items.Refresh());
Line 2179... Line 2171...
2179
                    Thread.Sleep(1);
2171
                    Thread.Sleep(1);
2180
                    iTimeout++;
2172
                    iTimeout++;
2181
                }
2173
                }
2182
            }
2174
            }
2183
        }
2175
        }
2184
 
-
 
-
 
2176
        /// <summary>
-
 
2177
        /// Wrapper for _clearCopterWPList()
-
 
2178
        /// necessary, cause it is called by threadnew which does not like return values...
-
 
2179
        /// </summary>
2185
        void clearCopterWPList()
2180
        void clearCopterWPList()
2186
        {
2181
        {
2187
            _clearCopterWPList();
2182
            _clearCopterWPList();
2188
        }
2183
        }
-
 
2184
        /// <summary>
-
 
2185
        /// clear the WP list of the copter
-
 
2186
        /// by sending 'invalid' and index '0'
-
 
2187
        /// </summary>
-
 
2188
        /// <returns></returns>
2189
        bool _clearCopterWPList()
2189
        bool _clearCopterWPList()
2190
        {
2190
        {
2191
            int iTimeout = 0;
2191
            int iTimeout = 0;
2192
            if (serialPortCtrl.Port.IsOpen)
2192
            if (serialPortCtrl.Port.IsOpen)
2193
            {
2193
            {
Line 2251... Line 2251...
2251
            }
2251
            }
2252
            else
2252
            else
2253
                Log(LogMsgType.Error, "NOT CONNECTED!");
2253
                Log(LogMsgType.Error, "NOT CONNECTED!");
Line 2254... Line 2254...
2254
 
2254
 
2255
        }
-
 
2256
 
2255
        }
2257
        bool _sendWayPoint(DataRow dr, int index, char command)
2256
        bool _sendWayPoint(DataRow dr, int index, char command)
Line 2258... Line 2257...
2258
        {
2257
        {
2259
 
2258
 
Line 3171... Line 3170...
3171
                                NumberFormatInfo nfi = new NumberFormatInfo();
3170
                                NumberFormatInfo nfi = new NumberFormatInfo();
3172
                                nfi.NumberDecimalSeparator = ".";
3171
                                nfi.NumberDecimalSeparator = ".";
3173
                                dtWaypoints.Rows.Clear();
3172
                                dtWaypoints.Rows.Clear();
3174
                                _wpEdit = -1;
3173
                                _wpEdit = -1;
3175
                                _clearMapMarkers(typeof(CustomMarkerWP));
3174
                                _clearMapMarkers(typeof(CustomMarkerWP));
-
 
3175
                                _clearMapMarkers(typeof(CustomMarkerWPActive));
3176
                                wpList.Clear();
3176
                                wpList.Clear();
3177
                                if (mRouteWP != null)
3177
                                if (mRouteWP != null)
3178
                                    MainMap.Markers.Remove(mRouteWP);
3178
                                    MainMap.Markers.Remove(mRouteWP);
3179
                                if (wpActiveMarker != null)
3179
                                //if (wpActiveMarker != null)
3180
                                    MainMap.Markers.Remove(wpActiveMarker);
3180
                                //    MainMap.Markers.Remove(wpActiveMarker);
3181
                                Dispatcher.Invoke(() => lblWPRouteDistance.Content = "0 m");
3181
                                Dispatcher.Invoke(() => lblWPRouteDistance.Content = "0 m");
Line 3182... Line 3182...
3182
 
3182
 
3183
                                for (int k = 1; k <= wpnum; k++)
3183
                                for (int k = 1; k <= wpnum; k++)
3184
                                {
3184
                                {
Line 3246... Line 3246...
3246
                                    i++;
3246
                                    i++;
3247
                                    o[i] = "New";
3247
                                    o[i] = "New";
Line 3248... Line 3248...
3248
 
3248
 
3249
                                    dr.ItemArray = o;
3249
                                    dr.ItemArray = o;
3250
                                    dtWaypoints.Rows.Add(dr);
-
 
3251
                                    GMapMarker wpMarker = new GMapMarker(new PointLatLng((double)o[3], (double)o[4]));
-
 
3252
                                    wpMarker.Shape = new CustomMarkerWP(this, wpMarker, (string)dr[2], (int)o[1]);
-
 
3253
                                    wpMarker.Offset = new System.Windows.Point(-11.5, -11.5);
-
 
3254
                                    wpMarker.ZIndex = 100;
-
 
3255
                                    _setMarkerColor(wpMarker, (int)o[1]);
-
 
3256
                                    MainMap.Markers.Add(wpMarker);
-
 
3257
                                    if((int)o[1] == 0)
3250
                                    dtWaypoints.Rows.Add(dr);
Line 3258... Line 3251...
3258
                                        wpList.Add(new PointLatLng((double)o[3], (double)o[4]));
3251
                                    _createWP(new PointLatLng((double)o[3], (double)o[4]), (string)dr[2], (int)o[1]);
3259
 
3252
 
3260
                                    Dispatcher.Invoke(() => lblWPIndex.Content = k.ToString());
3253
                                    Dispatcher.Invoke(() => lblWPIndex.Content = k.ToString());
3261
                                    Dispatcher.Invoke(() => lblWPCount.Content = k.ToString());
3254
                                    Dispatcher.Invoke(() => lblWPCount.Content = k.ToString());
Line 3358... Line 3351...
3358
                }
3351
                }
3359
                else
3352
                else
3360
                    mRouteWP = new GMapRoute(wpList, null);
3353
                    mRouteWP = new GMapRoute(wpList, null);
Line 3361... Line 3354...
3361
 
3354
 
3362
                if (_bShowWPRoute)
3355
                if (_bShowWPRoute)
3363
                    MainMap.Markers.Add(mRouteWP);
3356
                    Dispatcher.Invoke(() => MainMap.Markers.Add(mRouteWP));
Line 3364... Line 3357...
3364
            });
3357
            });
3365
 
3358
 
Line 3366... Line 3359...
3366
            MapRoute mr = new MapRoute(wpList, "WPList");
3359
            MapRoute mr = new MapRoute(wpList, "WPList");
-
 
3360
            Dispatcher.Invoke(() => lblWPRouteDistance.Content = (mr.Distance * 1000).ToString("0 m"));
-
 
3361
 
-
 
3362
        }
-
 
3363
 
-
 
3364
        GMapMarker _createWP(PointLatLng p, string name, int type)
-
 
3365
        {
-
 
3366
            GMapMarker wpMarker = new GMapMarker(p);
-
 
3367
            wpMarker.Shape = new CustomMarkerWP(this, wpMarker, name, type);
-
 
3368
            wpMarker.Offset = new System.Windows.Point(-11.5, -11.5);
-
 
3369
            wpMarker.ZIndex = 100;
-
 
3370
            _setMarkerColor(wpMarker, type);
-
 
3371
            Dispatcher.Invoke(() => MainMap.Markers.Add(wpMarker));
-
 
3372
            if (type == 0)
3367
            Dispatcher.Invoke(() => lblWPRouteDistance.Content = (mr.Distance * 1000).ToString("0 m"));
3373
                wpList.Add(p);
3368
 
3374
            return wpMarker;
3369
        }
3375
        }
3370
        void _setMarkerColor(GMapMarker wpMarker,int iType)
3376
        void _setMarkerColor(GMapMarker wpMarker,int iType)
3371
        {
3377
        {
Line 3542... Line 3548...
3542
            {
3548
            {
3543
                //if (_wpCount > 0)
3549
                //if (_wpCount > 0)
3544
                //    _sendWayPoint(dtWaypoints.Rows[dgvWP.SelectedIndex], -1,'s');
3550
                //    _sendWayPoint(dtWaypoints.Rows[dgvWP.SelectedIndex], -1,'s');
3545
                //else
3551
                //else
3546
                //    _sendWayPoint(dtWaypoints.Rows[dgvWP.SelectedIndex], 1,'s');
3552
                //    _sendWayPoint(dtWaypoints.Rows[dgvWP.SelectedIndex], 1,'s');
-
 
3553
 
3547
                int index = dgvWP.SelectedIndex;
3554
                int index = dgvWP.SelectedIndex;
3548
                Thread t = new Thread(() => _sendWPList(index));
3555
                Thread t = new Thread(() => _sendWPList(index));
3549
                t.Start();
3556
                t.Start();
Line 3550... Line 3557...
3550
 
3557
 
Line 3686... Line 3693...
3686
 
3693
 
Line 3687... Line 3694...
3687
        }
3694
        }
3688
 
3695
 
-
 
3696
        private void btnEditWPSave_Click(object sender, RoutedEventArgs e)
-
 
3697
        {
-
 
3698
            if(dgvWP.SelectedIndex > -1 && dgvWP.SelectedIndex < dtWaypoints.Rows.Count)
-
 
3699
            {
-
 
3700
                dtWaypoints.Rows[dgvWP.SelectedIndex][1] = cbWPEditType.SelectedIndex;
-
 
3701
                dtWaypoints.Rows[dgvWP.SelectedIndex][2] = tbWPEditPrefix.Text + (dgvWP.SelectedIndex + 1).ToString();
-
 
3702
                dtWaypoints.Rows[dgvWP.SelectedIndex][3] = Convert.ToDouble(tbWPEditLat.Text.Replace('.', ','));
-
 
3703
                dtWaypoints.Rows[dgvWP.SelectedIndex][4] = Convert.ToDouble(tbWPEditLon.Text.Replace('.', ','));
-
 
3704
                dtWaypoints.Rows[dgvWP.SelectedIndex][5] = tbWPEditAlt.Text;
-
 
3705
                switch (cbWPEditHeading.SelectedIndex)
-
 
3706
                {
-
 
3707
                    case 0:
-
 
3708
                        dtWaypoints.Rows[dgvWP.SelectedIndex][6] = "0";
-
 
3709
                        break;
-
 
3710
                    case 1:
-
 
3711
                        dtWaypoints.Rows[dgvWP.SelectedIndex][6] = "-" + tbWPEditHeading.Text;
-
 
3712
                        break;
-
 
3713
                    case 2:
-
 
3714
                        dtWaypoints.Rows[dgvWP.SelectedIndex][6] = tbWPEditHeading.Text;
-
 
3715
                        break;
-
 
3716
                }
-
 
3717
                switch (cbWPEditSpeed.SelectedIndex)
-
 
3718
                {
-
 
3719
                    case 0:
-
 
3720
                        dtWaypoints.Rows[dgvWP.SelectedIndex][7] = "0";
-
 
3721
                        break;
-
 
3722
                    case 1:
-
 
3723
                        dtWaypoints.Rows[dgvWP.SelectedIndex][7] = (System.Convert.ToDouble(tbWPEditSpeed.Text.Replace('.', ',')) * 10).ToString("0");
-
 
3724
                        break;
-
 
3725
                    case 2:
-
 
3726
                        dtWaypoints.Rows[dgvWP.SelectedIndex][7] = (256 - Convert.ToInt16(tbWPEditSpeed.Text)).ToString();
-
 
3727
                        break;
-
 
3728
                }
-
 
3729
                switch (cbWPEditClimbrate.SelectedIndex)
-
 
3730
                {
-
 
3731
                    case 0:
-
 
3732
                        dtWaypoints.Rows[dgvWP.SelectedIndex][8] = "255";
-
 
3733
                        break;
-
 
3734
                    case 1:
-
 
3735
                        dtWaypoints.Rows[dgvWP.SelectedIndex][8] = (System.Convert.ToDouble(tbWPEditClimbrate.Text.Replace('.',',')) * 10).ToString("0");
-
 
3736
                        break;
-
 
3737
                }
-
 
3738
                dtWaypoints.Rows[dgvWP.SelectedIndex][9] = tbWPEditRadius.Text;
-
 
3739
                dtWaypoints.Rows[dgvWP.SelectedIndex][10] = tbWPEditHoldtime.Text;
-
 
3740
                dtWaypoints.Rows[dgvWP.SelectedIndex][11] = tbWPEditAutoTrigger.Text;
-
 
3741
                switch (cbWPEditCamAngle.SelectedIndex)
-
 
3742
                {
-
 
3743
                    case 0:
-
 
3744
                        dtWaypoints.Rows[dgvWP.SelectedIndex][12] = "0";
-
 
3745
                        break;
-
 
3746
                    case 1:
-
 
3747
                        dtWaypoints.Rows[dgvWP.SelectedIndex][12] = "255";
-
 
3748
                        break;
-
 
3749
                    case 2:
-
 
3750
                        dtWaypoints.Rows[dgvWP.SelectedIndex][12] = tbWPEditCamAngle.Text;
-
 
3751
                        break;
-
 
3752
                }
-
 
3753
                dtWaypoints.Rows[dgvWP.SelectedIndex][14] = tbWPEditOut1.Text;
-
 
3754
 
-
 
3755
                _clearMapMarkers(typeof(CustomMarkerWP));
-
 
3756
                _clearMapMarkers(typeof(CustomMarkerWPActive));
-
 
3757
                wpList.Clear();
-
 
3758
                if (mRouteWP != null)
-
 
3759
                    MainMap.Markers.Remove(mRouteWP);
-
 
3760
 
-
 
3761
                for (int k = 0; k < dtWaypoints.Rows.Count; k++)
-
 
3762
                {
-
 
3763
                    _createWP(new PointLatLng((double)dtWaypoints.Rows[k][3], (double)dtWaypoints.Rows[k][4]), (string)dtWaypoints.Rows[k][2], (int)dtWaypoints.Rows[k][1]);
-
 
3764
                }
-
 
3765
                _routeUpdate();
-
 
3766
                dgvWP.Items.Refresh();
Line 3689... Line 3767...
3689
        private void btnEditWPSave_Click(object sender, RoutedEventArgs e)
3767
 
3690
        {
3768
            }
3691
 
3769
 
Line 3698... Line 3776...
3698
        {
3776
        {
3699
           if(!((TextBox)sender).IsReadOnly)
3777
           if(!((TextBox)sender).IsReadOnly)
3700
            {
3778
            {
3701
                KeyPad.Keypad k = new KeyPad.Keypad(this);
3779
                KeyPad.Keypad k = new KeyPad.Keypad(this);
Line -... Line 3780...
-
 
3780
 
-
 
3781
                switch (((TextBox)sender).Name)
-
 
3782
                {
-
 
3783
                    case "tbWPEditLat":
-
 
3784
                        k.Title = "Latitude";
-
 
3785
                        k.LENGTH = 17;
-
 
3786
                        k.MAX = 359.9;
-
 
3787
                        break;
-
 
3788
                    case "tbWPEditLon":
-
 
3789
                        k.Title = "Longitude";
-
 
3790
                        k.LENGTH = 17;
-
 
3791
                        k.MAX = 359.9;
-
 
3792
                        break;
-
 
3793
                    case "tbWPEditAlt":
-
 
3794
                        k.Title = "Altitude";
-
 
3795
                        k.LENGTH = 3;
3702
 
3796
                        k.MAX = 254;
-
 
3797
                        k.disableDecimal();
-
 
3798
                        break;
-
 
3799
                    case "tbWPEditHeading":
-
 
3800
                        k.Title = "Heading";
-
 
3801
                        k.LENGTH = 3;
-
 
3802
                        k.MAX = 359;
-
 
3803
                        k.MIN = 1;
-
 
3804
                        k.disableDecimal();
-
 
3805
                        break;
-
 
3806
                    case "tbWPEditSpeed":
-
 
3807
                        k.Title = "Speed";
-
 
3808
                        k.LENGTH = 4;
-
 
3809
                        k.MAX = 24.7;
-
 
3810
                        k.MIN = 0.1;
-
 
3811
                        break;
3703
                //var x = KeyInterop.VirtualKeyFromKey(e.Key);
3812
                    case "tbWPEditClimbrate":
-
 
3813
                        k.Title = "Climbrate";
-
 
3814
                        k.LENGTH = 4;
-
 
3815
                        k.MAX = 25.4;
-
 
3816
                        k.MIN = 0.1;
-
 
3817
                        break;
-
 
3818
                    case "tbWPEditRadius":
-
 
3819
                        k.Title = "Radius";
-
 
3820
                        k.LENGTH = 3;
-
 
3821
                        k.MAX = 254;
-
 
3822
                        k.disableDecimal();
-
 
3823
                        break;
-
 
3824
                    case "tbWPEditHoldtime":
-
 
3825
                        k.Title = "Holdtime";
-
 
3826
                        k.LENGTH = 3;
-
 
3827
                        k.MAX = 254;
-
 
3828
                        break;
3704
                KeyConverter x = new KeyConverter();
3829
                    case "tbWPEditAutoTrigger":
3705
                string s = x.ConvertToString(e.Key);
-
 
-
 
3830
                        k.Title = "Autotrigger";
-
 
3831
                        k.LENGTH = 3;
-
 
3832
                        k.MAX = 254;
-
 
3833
                        k.disableDecimal();
-
 
3834
                        break;
-
 
3835
                    case "tbWPEditCamAngle":
-
 
3836
                        k.Title = "Camera angle";
-
 
3837
                        k.LENGTH = 3;
-
 
3838
                        k.MAX = 254;
-
 
3839
                        k.MIN = 1;
-
 
3840
                        k.disableDecimal();
-
 
3841
                        break;
3706
 
3842
                    case "tbWPEditOut1":
-
 
3843
                        k.Title = "OUT1 timer interval";
3707
                if ("1234567890,\b".IndexOf(s) < 0) //general check for valid chars(0-9) and backspace (\b)
3844
                        k.LENGTH = 3;
-
 
3845
                        k.MAX = 254;
-
 
3846
                        k.disableDecimal();
3708
                    e.Handled = true;
3847
                        break;
3709
                else
3848
                }
3710
                    if ("\b".IndexOf(s) < 0)
3849
                k.Result = ((TextBox)sender).Text;
3711
                        if (Convert.ToInt16(((TextBox)sender).Text + s) > 360) //if valid and not backspace, check for upper limit of the resulting number
3850
                if(k.ShowDialog() == true && k.Result.Length > 0)
3712
                            e.Handled = true;
-
 
3713
 
3851
                    ((TextBox)sender).Text = k.Result;
3714
            }
3852
            }
Line 3715... Line 3853...
3715
        }
3853
        }
3716
 
3854