Subversion Repositories Projects

Rev

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

Rev 2289 Rev 2291
Line 165... Line 165...
165
        int iOSDPage = 0;
165
        int iOSDPage = 0;
166
        int iOSDMax = 0;
166
        int iOSDMax = 0;
167
        int _iLifeCounter = 0;
167
        int _iLifeCounter = 0;
168
        int crcError = 0;
168
        int crcError = 0;
Line -... Line 169...
-
 
169
 
-
 
170
        bool _bSatFix = false;
-
 
171
        Storyboard stbSatFixLostAnim;
-
 
172
        bool _bAnimSatFixActive = false;
-
 
173
        bool _bVoiceSatFixActive = false;
-
 
174
        bool _bVoiceSatFixPlay = false;
-
 
175
        int _iSatsLast = 0;
-
 
176
        int _iSatsJitter = 0;
-
 
177
 
-
 
178
        bool _bMagneticFieldOK = false;
-
 
179
        Storyboard stbMagneticFieldAnim;
-
 
180
        bool _bAnimMagneticFieldActive = false;
-
 
181
        bool _bVoiceMagneticFieldActive = false;
-
 
182
        bool _bVoiceMagneticFieldPlay = false;
-
 
183
        int _iMagneticFieldLast = 0;
-
 
184
        int _iMagneticFieldJitter = 0;
-
 
185
 
-
 
186
        bool _bRCLevelOK = false;
-
 
187
        Storyboard stbRCLevelAnim;
-
 
188
        bool _bAnimRCLevelActive = false;
-
 
189
        bool _bVoiceRCLevelActive = false;
-
 
190
        bool _bVoiceRCLevelPlay = false;
-
 
191
        int _iRCLevelLast = 0;
-
 
192
        int _iRCLevelJitter = 0;
169
 
193
 
170
        int _iMotors = 4;
194
        int _iMotors = 4;
Line 171... Line 195...
171
        int _LipoCells = 4;
195
        int _LipoCells = 4;
172
 
196
 
173
        double _dLipoVMax = 16.88;
197
        double _dLipoVMax = 16.88;
174
        double _dLipoVMin = 12;
198
        double _dLipoVMin = 12;
175
        double _dThresholdVoltageWarn = 0;
199
        double _dThresholdVoltageWarn = 0;
176
        double _dThresholdVoltageCrit = 0;
200
        double _dThresholdVoltageCrit = 0;
177
        Storyboard stbVoltageCritAnim;
201
        Storyboard stbVoltageCritAnim;
178
        bool _bCritAnimVoltActive = false;
202
        bool _bCritAnimVoltActive = false;
179
        bool _bCritVoiceVoltActive = false;
203
        bool _bCritVoiceVoltActive = false;
180
        bool _bCWarnVoiceVoltActive = false;
204
        bool _bWarnVoiceVoltActive = false;
181
        bool _bVoiceVoltPlay = false;
205
        bool _bVoiceVoltPlay = false;
Line -... Line 206...
-
 
206
        double _dVoltLast = 0;
-
 
207
        int _iVoltJitter = 0;
-
 
208
 
-
 
209
        double _dThresholdDistanceWarn = 100;
-
 
210
        Storyboard stbDistanceWarnAnim;
-
 
211
        bool _bAnimDistanceActive = false;
-
 
212
        bool _bVoiceDistanceActive = false;
-
 
213
        bool _bVoiceDistancePlay = false;
-
 
214
        double _dDistanceLast = 0;
-
 
215
        int _iDistanceJitter = 0;
-
 
216
 
-
 
217
        double _dThresholdDistanceMax = 1000;
-
 
218
        int _iThresholdRC = 160;
182
        double _dVoltLast = 0;
219
        int _iThresholdMagField = 15;
Line 183... Line 220...
183
        int _iVoltJitter = 0;
220
 
184
 
221
 
185
        double _dTopHeight = 36;
222
        double _dTopHeight = 36;
Line 269... Line 306...
269
            cBoxLiPoCells.SelectedItem = _LipoCells.ToString() + "s";
306
            cBoxLiPoCells.SelectedItem = _LipoCells.ToString() + "s";
270
            _LipoMinMax();
307
            _LipoMinMax();
271
            sliderThresholdVoltageWarn.Value = _dThresholdVoltageWarn;
308
            sliderThresholdVoltageWarn.Value = _dThresholdVoltageWarn;
272
            sliderThresholdVoltageCrit.Value = _dThresholdVoltageCrit;
309
            sliderThresholdVoltageCrit.Value = _dThresholdVoltageCrit;
273
            checkBoxThresholdVoltageVoice.IsChecked = _bVoiceVoltPlay;
310
            checkBoxThresholdVoltageVoice.IsChecked = _bVoiceVoltPlay;
-
 
311
            checkBoxSatfixLost.IsChecked = _bVoiceSatFixPlay;
-
 
312
            checkBoxMagneticField.IsChecked = _bVoiceMagneticFieldPlay;
-
 
313
            checkBoxThresholdDistanceVoice.IsChecked = _bVoiceDistancePlay;
-
 
314
            sliderThresholdDistanceWarn.Value = _dThresholdDistanceWarn;
-
 
315
            checkBoxRClevel.IsChecked = _bVoiceRCLevelPlay;
-
 
316
 
-
 
317
            sliderThresholdDistanceWarn.Maximum = _dThresholdDistanceMax;
Line 274... Line 318...
274
 
318
 
275
            cBoxMotors.ItemsSource = iMotors;
319
            cBoxMotors.ItemsSource = iMotors;
Line 276... Line 320...
276
            cBoxMotors.SelectedItem = _iMotors;
320
            cBoxMotors.SelectedItem = _iMotors;
Line 505... Line 549...
505
        private void chkBoxSaveFullScreenState_Click(object sender, RoutedEventArgs e)
549
        private void chkBoxSaveFullScreenState_Click(object sender, RoutedEventArgs e)
506
        {
550
        {
507
            _bSaveWinStateFull = (bool)chkBoxSaveFullScreenState.IsChecked;
551
            _bSaveWinStateFull = (bool)chkBoxSaveFullScreenState.IsChecked;
508
        }
552
        }
Line -... Line 553...
-
 
553
 
509
 
554
        #region thresholds
510
        private void sliderThresholdVoltageWarn_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
555
        private void sliderThresholdVoltageWarn_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
511
        {
556
        {
512
            if(!_init)
557
            if(!_init)
513
                _dThresholdVoltageWarn = sliderThresholdVoltageWarn.Value;
558
                _dThresholdVoltageWarn = sliderThresholdVoltageWarn.Value;
Line 519... Line 564...
519
        }
564
        }
520
        private void checkBoxThresholdVoltageVoice_Click(object sender, RoutedEventArgs e)
565
        private void checkBoxThresholdVoltageVoice_Click(object sender, RoutedEventArgs e)
521
        {
566
        {
522
            _bVoiceVoltPlay = (bool)checkBoxThresholdVoltageVoice.IsChecked;
567
            _bVoiceVoltPlay = (bool)checkBoxThresholdVoltageVoice.IsChecked;
523
        }
568
        }
-
 
569
 
-
 
570
        private void sliderThresholdDistanceWarn_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
-
 
571
        {
-
 
572
            if(!_init)
-
 
573
                _dThresholdDistanceWarn = sliderThresholdDistanceWarn.Value;
-
 
574
        }
-
 
575
        private void checkBoxThresholdDistanceVoice_Click(object sender, RoutedEventArgs e)
-
 
576
        {
-
 
577
            _bVoiceDistancePlay = (bool)checkBoxThresholdDistanceVoice.IsChecked;
-
 
578
        }
-
 
579
 
-
 
580
        private void checkBoxSatfixLost_Click(object sender, RoutedEventArgs e)
-
 
581
        {
-
 
582
            _bVoiceSatFixPlay = (bool)checkBoxSatfixLost.IsChecked;
-
 
583
        }
-
 
584
        private void checkBoxMagneticField_Click(object sender, RoutedEventArgs e)
-
 
585
        {
-
 
586
            _bVoiceMagneticFieldPlay = (bool)checkBoxMagneticField.IsChecked;
-
 
587
        }
-
 
588
        private void checkBoxRClevel_Click(object sender, RoutedEventArgs e)
-
 
589
        {
-
 
590
            _bVoiceRCLevelPlay = (bool)checkBoxRClevel.IsChecked;
-
 
591
        }
-
 
592
        #endregion thresholds
-
 
593
 
524
        private void buttonSwitchNC_Click(object sender, RoutedEventArgs e)
594
        private void buttonSwitchNC_Click(object sender, RoutedEventArgs e)
525
        {
595
        {
526
            _switchToNC();
596
            _switchToNC();
527
        }
597
        }
Line 528... Line 598...
528
 
598
 
529
        private void Window_Loaded(object sender, RoutedEventArgs e)
599
        private void Window_Loaded(object sender, RoutedEventArgs e)
530
        {
600
        {
-
 
601
            stbVoltageCritAnim = TryFindResource("VoltageCritAnim") as Storyboard;
-
 
602
            stbSatFixLostAnim = TryFindResource("SatFixLostAnim") as Storyboard;
-
 
603
            stbMagneticFieldAnim = TryFindResource("MagneticFieldCritAnim") as Storyboard;
-
 
604
            stbDistanceWarnAnim = TryFindResource("DistanceCritAnim") as Storyboard;
531
            stbVoltageCritAnim = TryFindResource("VoltageCritAnim") as Storyboard;
605
            stbRCLevelAnim = TryFindResource("RCCritAnim") as Storyboard;
532
            _setMotorGridSize();
606
            _setMotorGridSize();
533
        }
607
        }
Line 534... Line 608...
534
        #endregion events
608
        #endregion events
Line 716... Line 790...
716
            if (home != null && MainMap.Markers.Contains(home))
790
            if (home != null && MainMap.Markers.Contains(home))
717
            {
791
            {
718
                Dispatcher.Invoke(() => ArtHor.rotateHome = GMapProviders.EmptyProvider.Projection.GetBearing(copter.Position, home.Position));
792
                Dispatcher.Invoke(() => ArtHor.rotateHome = GMapProviders.EmptyProvider.Projection.GetBearing(copter.Position, home.Position));
719
                double d = GMapProviders.EmptyProvider.Projection.GetDistance(home.Position, copter.Position);
793
                double d = GMapProviders.EmptyProvider.Projection.GetDistance(home.Position, copter.Position);
720
                Dispatcher.Invoke(() => tbTopDistanceHP.Text = (d * 1000).ToString("0.0 m"));
794
                Dispatcher.Invoke(() => tbTopDistanceHP.Text = (d * 1000).ToString("0.0 m"));
-
 
795
 
-
 
796
                if(d*1000 < _dThresholdDistanceWarn)
-
 
797
                {
-
 
798
                    _iDistanceJitter = 0; _bVoiceDistanceActive = false;
-
 
799
                    if (stbDistanceWarnAnim != null && _bAnimDistanceActive)
-
 
800
                    {
-
 
801
                        Dispatcher.Invoke(() => stbDistanceWarnAnim.Stop());
-
 
802
                        _bAnimDistanceActive = false;
-
 
803
                    }
-
 
804
                }
-
 
805
                else
-
 
806
                {
-
 
807
                    //if (d * 1000 == _dDistanceLast)
-
 
808
                    //{
-
 
809
                    //    if (_iDistanceJitter < 20)
-
 
810
                    //    { _iDistanceJitter++; }
-
 
811
                    //}
-
 
812
                    //else
-
 
813
                    //{
-
 
814
                    //    _iDistanceJitter = 0;
-
 
815
                    //    _dDistanceLast = d * 1000;
-
 
816
                    //}
-
 
817
                    if (_iDistanceJitter < 20)
-
 
818
                    { _iDistanceJitter++; }
-
 
819
                    if (_iDistanceJitter == 20)
-
 
820
                    {
-
 
821
                        if (stbDistanceWarnAnim != null && !_bAnimDistanceActive)
-
 
822
                        {
-
 
823
                            Dispatcher.Invoke(() => stbDistanceWarnAnim.Begin());
-
 
824
                            _bAnimDistanceActive = true;
-
 
825
                        }
-
 
826
                        if (_bVoiceDistancePlay && !_bVoiceDistanceActive)
-
 
827
                        {
-
 
828
                            if (File.Exists("Voice\\Distance.mp3"))
-
 
829
                            {
-
 
830
 
-
 
831
                                MediaPlayer.MediaPlayer mp = new MediaPlayer.MediaPlayer();
-
 
832
                                mp.Open("Voice\\Distance.mp3");
-
 
833
                                mp.Play();
-
 
834
                            }
-
 
835
                            _bVoiceDistanceActive = true;
-
 
836
                        }
-
 
837
                        _iDistanceJitter++;
-
 
838
                    }
-
 
839
                }
-
 
840
 
721
            }
841
            }
722
        }
842
        }
Line 723... Line 843...
723
 
843
 
724
        private void checkBoxFollowCopter_Click(object sender, RoutedEventArgs e)
844
        private void checkBoxFollowCopter_Click(object sender, RoutedEventArgs e)
Line 1243... Line 1363...
1243
                                                Dispatcher.Invoke(() => stbVoltageCritAnim.Stop());
1363
                                                Dispatcher.Invoke(() => stbVoltageCritAnim.Stop());
1244
                                                _bCritAnimVoltActive = false;
1364
                                                _bCritAnimVoltActive = false;
1245
                                            }
1365
                                            }
1246
                                            _bCritVoiceVoltActive = false;
1366
                                            _bCritVoiceVoltActive = false;
Line 1247... Line 1367...
1247
 
1367
 
1248
                                            if (_bVoiceVoltPlay && !_bCWarnVoiceVoltActive)
1368
                                            if (_bVoiceVoltPlay && !_bWarnVoiceVoltActive)
1249
                                            {
1369
                                            {
1250
                                                if (File.Exists("Voice\\LowBattery.mp3"))
1370
                                                if (File.Exists("Voice\\LowBattery.mp3"))
Line 1251... Line 1371...
1251
                                                {
1371
                                                {
1252
 
1372
 
1253
                                                    MediaPlayer.MediaPlayer mp = new MediaPlayer.MediaPlayer();
1373
                                                    MediaPlayer.MediaPlayer mp = new MediaPlayer.MediaPlayer();
1254
                                                    mp.Open("Voice\\LowBattery.mp3");
1374
                                                    mp.Open("Voice\\LowBattery.mp3");
1255
                                                    mp.Play();
1375
                                                    mp.Play();
1256
                                                }
1376
                                                }
1257
                                                _bCWarnVoiceVoltActive = true;
1377
                                                _bWarnVoiceVoltActive = true;
1258
                                            }
1378
                                            }
1259
                                        }
1379
                                        }
1260
                                    }
1380
                                    }
Line 1266... Line 1386...
1266
                                    {
1386
                                    {
1267
                                        Dispatcher.Invoke(() => stbVoltageCritAnim.Stop());
1387
                                        Dispatcher.Invoke(() => stbVoltageCritAnim.Stop());
1268
                                        _bCritAnimVoltActive = false;
1388
                                        _bCritAnimVoltActive = false;
1269
                                    }
1389
                                    }
1270
                                    _bCritVoiceVoltActive = false;
1390
                                    _bCritVoiceVoltActive = false;
1271
                                    _bCWarnVoiceVoltActive = false;
1391
                                    _bWarnVoiceVoltActive = false;
1272
                                    _iVoltJitter = 0;
1392
                                    _iVoltJitter = 0;
1273
                                }
1393
                                }
1274
                                break;
1394
                                break;
1275
                            case 8: // Current
1395
                            case 8: // Current
1276
                                Dispatcher.Invoke(() => tbCur.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0 A"));
1396
                                Dispatcher.Invoke(() => tbCur.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0 A"));
1277
                                Dispatcher.Invoke(() => tbTopCurrent.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0 A"));
1397
                                Dispatcher.Invoke(() => tbTopCurrent.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0 A"));
1278
                                break;
1398
                                break;
1279
                            case 10: //heading
1399
                            case 10: //heading
1280
                                     Dispatcher.Invoke((Action)(() => tbHeading.Text = sAnalogData[index] + "°"));
1400
                                Dispatcher.Invoke((Action)(() => tbHeading.Text = sAnalogData[index] + "°"));
1281
                                Dispatcher.Invoke(() => ArtHor.rotate = iAnalogData[index]);
1401
                                Dispatcher.Invoke(() => ArtHor.rotate = iAnalogData[index]);
1282
                                break;
1402
                                break;
1283
                            case 12: // SPI error
1403
                            case 12: // SPI error
1284
                                     Dispatcher.Invoke((Action)(() => tbSPI.Text = sAnalogData[index]));
1404
                                Dispatcher.Invoke((Action)(() => tbSPI.Text = sAnalogData[index]));
1285
                                break;
1405
                                break;
1286
                            case 14: //i2c error
1406
                            case 14: //i2c error
1287
                                     Dispatcher.Invoke((Action)(() => tbI2C.Text = sAnalogData[index]));
1407
                                Dispatcher.Invoke((Action)(() => tbI2C.Text = sAnalogData[index]));
1288
                                break;
1408
                                break;
1289
                            case 20: //Earthmagnet field
1409
                            case 20: //Earthmagnet field
1290
                                     Dispatcher.Invoke((Action)(() => tbMagF.Text = sAnalogData[index] + "%"));
1410
                                Dispatcher.Invoke((Action)(() => tbMagF.Text = sAnalogData[index] + "%"));
1291
                                     Dispatcher.Invoke((Action)(() => tbTopEarthMag.Text = sAnalogData[index] + "%"));
1411
                                Dispatcher.Invoke((Action)(() => tbTopEarthMag.Text = sAnalogData[index] + "%"));
-
 
1412
                               
1292
                                     if(iAnalogData[index] > 115 | iAnalogData[index] < 85)
1413
                                if (Math.Abs(100 - iAnalogData[index]) < _iThresholdMagField)
-
 
1414
                                {
1293
                                        Dispatcher.Invoke(() => imageEarthMag.Source = new BitmapImage(new Uri("Images/EarthMag_R.png", UriKind.Relative)));
1415
                                    Dispatcher.Invoke(() => imageEarthMag.Source = new BitmapImage(new Uri("Images/EarthMag.png", UriKind.Relative)));
-
 
1416
                                    _iMagneticFieldJitter = 0; _bVoiceMagneticFieldActive = false;
-
 
1417
                                    if (stbMagneticFieldAnim != null && _bAnimMagneticFieldActive)
-
 
1418
                                    {
-
 
1419
                                        Dispatcher.Invoke(() => stbMagneticFieldAnim.Stop());
-
 
1420
                                        _bAnimMagneticFieldActive = false;
1294
                                     else
1421
                                    }
-
 
1422
                                }
-
 
1423
                                else
-
 
1424
                                {
1295
                                        Dispatcher.Invoke(() => imageEarthMag.Source = new BitmapImage(new Uri("Images/EarthMag.png", UriKind.Relative)));
1425
                                    Dispatcher.Invoke(() => imageEarthMag.Source = new BitmapImage(new Uri("Images/EarthMag_R.png", UriKind.Relative)));
-
 
1426
                                    if(_iMagneticFieldLast >= Math.Abs(100 - iAnalogData[index]))
-
 
1427
                                    {
-
 
1428
                                        if (_iMagneticFieldJitter < 20)
-
 
1429
                                            _iMagneticFieldJitter++;
-
 
1430
                                    }
-
 
1431
                                    else
-
 
1432
                                    {
-
 
1433
                                        _iMagneticFieldJitter = 0;
-
 
1434
                                        _iMagneticFieldLast = Math.Abs(100 - iAnalogData[index]);
-
 
1435
                                    }
-
 
1436
                                    if(_iMagneticFieldJitter == 20)
-
 
1437
                                    {
-
 
1438
                                        if (stbMagneticFieldAnim != null && !_bAnimMagneticFieldActive)
-
 
1439
                                        {
-
 
1440
                                            Dispatcher.Invoke(() => stbMagneticFieldAnim.Begin());
-
 
1441
                                            _bAnimMagneticFieldActive = true;
-
 
1442
                                        }
-
 
1443
                                        if (_bVoiceMagneticFieldPlay && !_bVoiceMagneticFieldActive)
-
 
1444
                                        {
-
 
1445
                                            if (File.Exists("Voice\\MagneticField.mp3"))
-
 
1446
                                            {
-
 
1447
 
-
 
1448
                                                MediaPlayer.MediaPlayer mp = new MediaPlayer.MediaPlayer();
-
 
1449
                                                mp.Open("Voice\\MagneticField.mp3");
-
 
1450
                                                mp.Play();
-
 
1451
                                            }
-
 
1452
                                            _bVoiceMagneticFieldActive = true;
-
 
1453
                                        }
-
 
1454
                                    }
-
 
1455
                                }
1296
                                break;
1456
                                break;
1297
                            case 21: //GroundSpeed
1457
                            case 21: //GroundSpeed
1298
                                     Dispatcher.Invoke((Action)(() => tbSpeed.Text = ((double)iAnalogData[index] / (double)100).ToString("0.00 m/s")));
1458
                                     Dispatcher.Invoke((Action)(() => tbSpeed.Text = ((double)iAnalogData[index] / (double)100).ToString("0.00 m/s")));
1299
                                     Dispatcher.Invoke((Action)(() => tbTopSpeed.Text = ((double)iAnalogData[index] / (double)100).ToString("0.00 m/s")));
1459
                                     Dispatcher.Invoke((Action)(() => tbTopSpeed.Text = ((double)iAnalogData[index] / (double)100).ToString("0.00 m/s")));
1300
                                break;
1460
                                break;
-
 
1461
 
-
 
1462
                            ///**********   needs testing --> not sure what position this is  ***************
1301
                            case 28: //Distance East from saved home position -> calculate distance with distance N + height
1463
                            case 28: //Distance East from saved home position -> calculate distance with distance N + height
1302
                                    dTemp = Math.Pow((double)iAnalogData[index], 2) + Math.Pow((double)iAnalogData[index - 1], 2);
1464
                                    dTemp = Math.Pow((double)iAnalogData[index], 2) + Math.Pow((double)iAnalogData[index - 1], 2);
1303
                                    dTemp = Math.Sqrt(dTemp) / (double)10; //'flat' distance from HP with N/E
1465
                                    dTemp = Math.Sqrt(dTemp) / (double)10; //'flat' distance from HP with N/E
1304
                                                                           //  lblNCDist.Invoke((Action)(() => lblNCDist.Text = dTemp.ToString("0.00")));
1466
                                                                           //  lblNCDist.Invoke((Action)(() => lblNCDist.Text = dTemp.ToString("0.00")));
1305
                                    dTemp = Math.Pow(dTemp, 2) + Math.Pow(((double)iAnalogData[4] / (double)10), 2); //adding 'height' into calculation
1467
                                    dTemp = Math.Pow(dTemp, 2) + Math.Pow(((double)iAnalogData[4] / (double)10), 2); //adding 'height' into calculation
1306
                                    dTemp = Math.Sqrt(dTemp) / (double)10;
1468
                                    dTemp = Math.Sqrt(dTemp) / (double)10;
1307
                               //     Dispatcher.Invoke((Action)(() => tbTopDistanceHP.Text = dTemp.ToString("0.0 m")));
1469
                               //     Dispatcher.Invoke((Action)(() => tbTopDistanceHP.Text = dTemp.ToString("0.0 m")));
1308
                                    Dispatcher.Invoke((Action)(() => tbHP1.Text = dTemp.ToString("0.0 m")));
1470
                                    Dispatcher.Invoke((Action)(() => tbHP1.Text = dTemp.ToString("0.0 m")));
1309
                                break;
1471
                                break;
-
 
1472
 
1310
                            case 31: //Sats used
1473
                            case 31: //Sats used
1311
                                     Dispatcher.Invoke((Action)(() => tbSats.Text = sAnalogData[index]));
1474
                                     Dispatcher.Invoke((Action)(() => tbSats.Text = sAnalogData[index]));
1312
                                    // Dispatcher.Invoke((Action)(() => tbTopSats.Text = sAnalogData[index]));                                   
1475
                                    // Dispatcher.Invoke((Action)(() => tbTopSats.Text = sAnalogData[index]));                                   
1313
                                break;
1476
                                break;
1314
                        }
1477
                        }
1315
                    }
1478
                    }
1316
                    //if (adr == 1) //FC
-
 
1317
                    //{
-
 
1318
                    //    switch (index)
-
 
1319
                    //    {
-
 
1320
                    //        case 0: //pitch (German: nick)
-
 
1321
                    //            artificialHorizon1.Invoke((Action)(() => artificialHorizon1.pitch_angle = ((double)iAnalogData[index] / (double)10)));
-
 
1322
                    //            lblNCPitch.Invoke((Action)(() => lblNCPitch.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0°")));
-
 
1323
                    //            break;
-
 
1324
                    //        case 1: //roll
-
 
1325
                    //            artificialHorizon1.Invoke((Action)(() => artificialHorizon1.roll_angle = ((double)iAnalogData[index] / (double)10)));
-
 
1326
                    //            lblNCRoll.Invoke((Action)(() => lblNCRoll.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0°")));
-
 
1327
                    //            break;
-
 
1328
                    //        case 5: //altitude
-
 
1329
                    //            lblNCAlt.Invoke((Action)(() => lblNCAlt.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0 m")));
-
 
1330
                    //            break;
-
 
1331
                    //        case 8: //heading
-
 
1332
                    //            lblNCCompass.Invoke((Action)(() => lblNCCompass.Text = sAnalogData[index] + "°"));
-
 
1333
                    //            headingIndicator1.Invoke((Action)(() => headingIndicator1.SetHeadingIndicatorParameters(iAnalogData[index])));
-
 
1334
                    //            break;
-
 
1335
                    //        case 9: //Voltage
-
 
1336
                    //            lblNCVolt.Invoke((Action)(() => lblNCVolt.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0 V")));
-
 
1337
                    //            break;
-
 
1338
                    //        case 10: //Receiver quality
-
 
1339
                    //            lblNCRC.Invoke((Action)(() => lblNCRC.Text = sAnalogData[index]));
-
 
1340
                    //            break;
-
 
1341
                    //        case 22: // Current
-
 
1342
                    //            lblNCCur.Invoke((Action)(() => lblNCCur.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0 A")));
-
 
1343
                    //            break;
-
 
1344
                    //        case 23: //capacity used
-
 
1345
                    //            lblNCCap.Invoke((Action)(() => lblNCCap.Text = (iAnalogData[index]).ToString("0 mAh")));
-
 
1346
                    //            break;
-
 
1347
                    //        case 27: // SPI error
-
 
1348
                    //            lblNCSPI.Invoke((Action)(() => lblNCSPI.Text = sAnalogData[index]));
-
 
1349
                    //            break;
-
 
1350
                    //        case 28: //i2c error
-
 
1351
                    //            lblNCI2C.Invoke((Action)(() => lblNCI2C.Text = sAnalogData[index]));
-
 
1352
                    //            break;
-
 
1353
                    //    }
-
 
1354
                    //}
-
 
1355
                    index++;
1479
                    index++;
1356
                }
1480
                }
1357
            }
1481
            }
1358
            else
1482
            else
1359
                Debug.Print("wrong data-length (66): " + data.Length.ToString());
1483
                Debug.Print("wrong data-length (66): " + data.Length.ToString());
Line 1477... Line 1601...
1477
            i_32 = data[6];
1601
            i_32 = data[6];
1478
            iVal += i_32 << 8;
1602
            iVal += i_32 << 8;
1479
            iVal += data[5];
1603
            iVal += data[5];
1480
            d = (double)iVal / Math.Pow(10, 7);
1604
            d = (double)iVal / Math.Pow(10, 7);
1481
            p.Lat = d;
1605
            p.Lat = d;
1482
 
-
 
1483
            if (!_bFollowCopter && data[50] > 4) //if more than 4 sats in use . otherwise the map would jump and scroll insane
1606
            if (data[50] > 4)//if more than 4 sats in use . otherwise the map would jump and scroll insane at beginning
1484
            {
1607
            {
-
 
1608
                _bSatFix = true; _iSatsJitter = 0; _bVoiceSatFixActive = false;
-
 
1609
                if (stbSatFixLostAnim != null && _bAnimSatFixActive)
-
 
1610
                {
-
 
1611
                    Dispatcher.Invoke(() => stbSatFixLostAnim.Stop());
-
 
1612
                    _bAnimSatFixActive = false;
-
 
1613
                }
-
 
1614
                if (!_bFollowCopter)
-
 
1615
                {
1485
                _setCopterData(p);
1616
                    _setCopterData(p);
1486
                if(!MainMap.ViewArea.Contains(p))
1617
                    if (!MainMap.ViewArea.Contains(p))
1487
                    Dispatcher.Invoke(() => MainMap.Position = p);
1618
                        Dispatcher.Invoke(() => MainMap.Position = p);
Line -... Line 1619...
-
 
1619
 
-
 
1620
                }
-
 
1621
                else
1488
 
1622
                    Dispatcher.Invoke(() => MainMap.Position = p);
1489
            }
1623
            }
-
 
1624
            else
-
 
1625
            {
-
 
1626
                if(_bSatFix)
-
 
1627
                {
-
 
1628
                    if (data[50] == _iSatsLast)
1490
            else
1629
                    {
-
 
1630
                        if (_iSatsJitter < 20) _iSatsJitter++;
-
 
1631
                    }
-
 
1632
                    else
1491
                if(data[50] > 4) //if more than 4 sats in use . otherwise the map would jump and scroll insane
1633
                    {
-
 
1634
                        _iSatsJitter = 0;
-
 
1635
                        _iSatsLast = data[50];
Line -... Line 1636...
-
 
1636
                    }
-
 
1637
 
-
 
1638
                    if (_iSatsJitter == 20)
-
 
1639
                    {
-
 
1640
                        if (stbSatFixLostAnim != null && !_bAnimSatFixActive)
-
 
1641
                        {
-
 
1642
                            Dispatcher.Invoke(() => stbSatFixLostAnim.Begin());
-
 
1643
                            _bAnimSatFixActive = true;
-
 
1644
                        }
-
 
1645
                        if (_bVoiceSatFixPlay && !_bVoiceSatFixActive)
-
 
1646
                        {
-
 
1647
                            if (File.Exists("Voice\\CriticalBattery.mp3"))
-
 
1648
                            {
-
 
1649
 
-
 
1650
                                MediaPlayer.MediaPlayer mp = new MediaPlayer.MediaPlayer();
-
 
1651
                                mp.Open("Voice\\CriticalBattery.mp3");
-
 
1652
                                mp.Play();
-
 
1653
                            }
-
 
1654
                            _bVoiceSatFixActive = true;
-
 
1655
                        }
-
 
1656
 
-
 
1657
                        _bSatFix = false;
-
 
1658
                    }
Line 1492... Line 1659...
1492
                    Dispatcher.Invoke(() => MainMap.Position = p);
1659
                }
1493
 
1660
            }
Line 1494... Line 1661...
1494
 
1661
 
Line 1530... Line 1697...
1530
 
1697
 
1531
            //--------------- RC quality ------------------------
1698
            //--------------- RC quality ------------------------
1532
            Dispatcher.Invoke((Action)(() => tbRCQ.Text = data[66].ToString()));
1699
            Dispatcher.Invoke((Action)(() => tbRCQ.Text = data[66].ToString()));
Line -... Line 1700...
-
 
1700
            Dispatcher.Invoke((Action)(() => tbTopRC.Text = data[66].ToString()));
-
 
1701
 
-
 
1702
            if(data[66] > _iThresholdRC)
-
 
1703
            {
-
 
1704
                _iRCLevelJitter = 0; _bVoiceRCLevelActive = false;
-
 
1705
                if (stbRCLevelAnim != null && _bAnimRCLevelActive)
-
 
1706
                {
-
 
1707
                    Dispatcher.Invoke(() => stbRCLevelAnim.Stop());
-
 
1708
                    _bAnimRCLevelActive = false;
-
 
1709
                }
-
 
1710
            }
-
 
1711
            else
-
 
1712
            {
-
 
1713
                if (_iRCLevelJitter < 20) _iRCLevelJitter++;
-
 
1714
                if (_iRCLevelJitter == 20)
-
 
1715
                {
-
 
1716
                    if (stbRCLevelAnim != null && !_bAnimRCLevelActive)
-
 
1717
                    {
-
 
1718
                        Dispatcher.Invoke(() => stbRCLevelAnim.Begin());
-
 
1719
                        _bAnimRCLevelActive = true;
-
 
1720
                    }
-
 
1721
                    if (_bVoiceRCLevelPlay && !_bVoiceRCLevelActive)
-
 
1722
                    {
-
 
1723
                        if (File.Exists("Voice\\RCLevel.mp3"))
-
 
1724
                        {
-
 
1725
 
-
 
1726
                            MediaPlayer.MediaPlayer mp = new MediaPlayer.MediaPlayer();
-
 
1727
                            mp.Open("Voice\\RCLevel.mp3");
-
 
1728
                            mp.Play();
-
 
1729
                        }
-
 
1730
                        _bVoiceRCLevelActive = true;
-
 
1731
                    }
-
 
1732
                        _iRCLevelJitter++;
Line 1533... Line 1733...
1533
            Dispatcher.Invoke((Action)(() => tbTopRC.Text = data[66].ToString()));
1733
                }
1534
 
1734
            }
1535
 
1735
 
1536
            //--------------- NC Error ------------------------
1736
            //--------------- NC Error ------------------------
Line 2133... Line 2333...
2133
 
2333
 
2134
            sVal = ini.IniReadValue("threshold", "VoltageWarning");
2334
            sVal = ini.IniReadValue("threshold", "VoltageWarning");
2135
            if(sVal != "") _dThresholdVoltageWarn = Convert.ToDouble(sVal);
2335
            if(sVal != "") _dThresholdVoltageWarn = Convert.ToDouble(sVal);
2136
            sVal = ini.IniReadValue("threshold", "VoltageCritical");
2336
            sVal = ini.IniReadValue("threshold", "VoltageCritical");
2137
            if(sVal != "") _dThresholdVoltageCrit = Convert.ToDouble(sVal);
2337
            if(sVal != "") _dThresholdVoltageCrit = Convert.ToDouble(sVal);
2138
            sVal = ini.IniReadValue("threshold", "VoiceEnable");
2338
            sVal = ini.IniReadValue("threshold", "VoiceVoltageEnable");
-
 
2339
            if(sVal != "") _bVoiceVoltPlay = Convert.ToBoolean(sVal);
-
 
2340
            sVal = ini.IniReadValue("threshold", "VoiceSatFixEnable");
-
 
2341
            if(sVal != "") _bVoiceSatFixPlay = Convert.ToBoolean(sVal);
-
 
2342
            sVal = ini.IniReadValue("threshold", "VoiceMagFieldEnable");
-
 
2343
            if(sVal != "") _bVoiceMagneticFieldPlay = Convert.ToBoolean(sVal);
-
 
2344
            sVal = ini.IniReadValue("threshold", "DistanceWarning");
-
 
2345
            if(sVal != "") _dThresholdDistanceWarn = Convert.ToDouble(sVal);
-
 
2346
            sVal = ini.IniReadValue("threshold", "VoiceDistanceWarnEnable");
-
 
2347
            if(sVal != "") _bVoiceDistancePlay = Convert.ToBoolean(sVal);
-
 
2348
            sVal = ini.IniReadValue("threshold", "VoiceRCLevelWarnEnable");
-
 
2349
            if(sVal != "") _bVoiceRCLevelPlay = Convert.ToBoolean(sVal);
-
 
2350
            sVal = ini.IniReadValue("threshold", "MaxDistance");
-
 
2351
            if(sVal != "") _dThresholdDistanceMax = Convert.ToDouble(sVal);
-
 
2352
            sVal = ini.IniReadValue("threshold", "RCThreshold");
-
 
2353
            if(sVal != "") _iThresholdRC = Convert.ToInt32(sVal);
-
 
2354
            sVal = ini.IniReadValue("threshold", "MagFieldThreshold");
Line 2139... Line 2355...
2139
            if(sVal != "") _bVoiceVoltPlay = Convert.ToBoolean(sVal);
2355
            if(sVal != "") _iThresholdMagField = Convert.ToInt32(sVal);
Line -... Line 2356...
-
 
2356
 
2140
 
2357
        }
2141
        }
2358
 
2142
 
2359
 
2143
        /// <summary>
2360
        /// <summary>
2144
        /// save settings to ini-file
2361
        /// save settings to ini-file
Line 2194... Line 2411...
2194
 
2411
 
Line 2195... Line 2412...
2195
            ini.IniWriteValue("style", "horizon", chkBoxShowHorizon.IsChecked.ToString());
2412
            ini.IniWriteValue("style", "horizon", chkBoxShowHorizon.IsChecked.ToString());
2196
 
2413
 
2197
            ini.IniWriteValue("threshold", "VoltageWarning", _dThresholdVoltageWarn.ToString());
2414
            ini.IniWriteValue("threshold", "VoltageWarning", _dThresholdVoltageWarn.ToString());
2198
            ini.IniWriteValue("threshold", "VoltageCritical", _dThresholdVoltageCrit.ToString());
-
 
-
 
2415
            ini.IniWriteValue("threshold", "VoltageCritical", _dThresholdVoltageCrit.ToString());
-
 
2416
            ini.IniWriteValue("threshold", "VoiceVoltageEnable", _bVoiceVoltPlay.ToString());
-
 
2417
            ini.IniWriteValue("threshold", "VoiceSatFixEnable", _bVoiceSatFixPlay.ToString());
-
 
2418
            ini.IniWriteValue("threshold", "VoiceMagFieldEnable", _bVoiceMagneticFieldPlay.ToString());
-
 
2419
            ini.IniWriteValue("threshold", "VoiceDistanceWarnEnable", _bVoiceDistancePlay.ToString());
-
 
2420
            ini.IniWriteValue("threshold", "VoiceRCLevelWarnEnable", _bVoiceRCLevelPlay.ToString());
-
 
2421
            ini.IniWriteValue("threshold", "DistanceWarning", _dThresholdDistanceWarn.ToString());
-
 
2422
            ini.IniWriteValue("threshold", "MaxDistance", _dThresholdDistanceMax.ToString());
2199
            ini.IniWriteValue("threshold", "VoiceEnable", _bVoiceVoltPlay.ToString());
2423
            ini.IniWriteValue("threshold", "RCThreshold", _iThresholdRC.ToString());
2200
 
2424
            ini.IniWriteValue("threshold", "MagFieldThreshold", _iThresholdMagField.ToString());
Line 2201... Line 2425...
2201
        }
2425
        }
2202
        #endregion functions
2426
        #endregion functions