-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainGUI.cs
5522 lines (4530 loc) · 227 KB
/
mainGUI.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* MultiWii Windows GUI by Andras Schaffer (EOSBandi)
* February 2015 V2.4
*
*
* LogBrowser is based on ArduPlanner Mega code written by Michael Oborne http://www.diydrones.com
* Instrument controls are based on AvionicsInstrument Controls written by Guillaume CHOUTEAU http://www.codeproject.com/Articles/27411/C-Avionic-Instrument-Controls
* Video capture code is using Aforge.Net Framework http://www.aforgenet.com
* Graph parts are using ZedGraph control http://sourceforge.net/projects/zedgraph/
*
*/
using System;
using System.Text;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.IO.Ports;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Linq;
using System.Collections.Generic;
using AForge.Video;
using AForge.Video.DirectShow;
using AForge.Video.FFMPEG;
using MultiWiiGUIControls;
using ZedGraph;
using GMap.NET;
using GMap.NET.WindowsForms;
using GMap.NET.WindowsForms.Markers;
using GMap.NET.MapProviders;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Media;
using System.Speech;
using System.Speech.Synthesis;
using System.Windows.Forms;
using MultiWiiWinGUI.Module;
using MultiWiiWinGUI.MWGUIControls;
namespace MultiWiiWinGUI
{
public partial class mainGUI : Form
{
#region Common variables (properties)
const string SVersion = "2.4";
byte byteVersion = 230;
uint iNaviVersion = 7; //Navigation code version
const string sVersionUrl = "http://mw-wingui.googlecode.com/svn/trunk/WinGui2/version.xml";
private string sVersionFromSVN;
private XDocument doc;
static string sOptionsConfigFilename = "optionsconfig";
const string sGuiSettingsFilename = "gui_settings.xml";
enum CopterType { Tri = 1, QuadP, QuadX, BI, Gimbal, Y6, Hex6, FlyWing, Y4,
Hex6X, OctoX8, OctoFlatX, OctoFlatP, Airplane, Heli_120_CCPM, Heli_90_DEG, Vtail4,
Hex6H, PPM_to_Servo, DualCopter, Singlecopter };
string[] sGpsMode = { "None", "PosHold", "RTH", "Mission" };
string[] sNavState = { "None", "RTH Start", "RTH Enroute", "PosHold infinit", "PosHold timed", "WP Enroute", "Process next","Jump","Start Land","Land in Progress","Landed","Settling before land","Start descent" };
string[] sNavError = { "导航系统工作中.",
"下一个路径点的距离超过安全极限,中止任务",
"GPS接收弱-暂停任务,飞行器处于无控制飞行状态!",
"读取下一个任务点出现内存错误,中止任务.",
"任务完成." ,
"定时等待任务.",
"检测到无效的跳转目标,中止任务.",
"无效的任务步骤操作码检测,中止任务.",
"等待到达返航的高度.",
"GPS定位丢失,任务失败-飞行器处于无控制飞行状态!",
"飞行器被锁定,导航程序被禁止。",
"着陆正在进行中,如果可能的话请检查参数。"};
string[] sSerialSpeeds = { "115200", "57600", "38400", "19200", "9600" };
string[] sRefreshSpeeds = {"20 Hz", "10 Hz", "5 Hz", "2 Hz", "1 Hz" };
int[] iRefreshIntervals = {5, 10, 20, 50, 100 };
const int rcLow = 1300;
const int rcMid = 1700;
const int rcLevel1 = 1230;
const int rcLevel2 = 1360;
const int rcLevel3 = 1490;
const int rcLevel4 = 1620;
const int rcLevel5 = 1749;
const string sRelName = "2.4";
Boolean isCLI = false;
string inCLIBuffer;
//PID values
static PID[] Pid;
static SerialPort serialPort;
static bool isConnected = false; //is port connected or not ?
static bool bSerialError = false;
static bool isPaused = false;
static double xTimeStamp = 0;
static byte[] bSerialBuffer;
static int iCheckBoxItems = 0; //number of checkboxItems (readed from optionsconfig.xml
static int iPidItems = 0; //number if Pid items (const definition)
static mw_data_gui mw_gui; //Data structures in that contains the data in the gui
static mw_settings mw_params;
static GUI_settings gui_settings;
static bool bOptions_needs_refresh = true;
static bool bRestartNeeded = false; //FC software version changed, must restart
static string[] option_names;
static string[] option_indicators;
static string[] option_desc;
static LineItem curve_acc_roll, curve_acc_pitch, curve_acc_z;
static LineItem curve_gyro_roll, curve_gyro_pitch, curve_gyro_yaw;
static LineItem curve_mag_roll, curve_mag_pitch, curve_mag_yaw;
static LineItem curve_alt, curve_head;
static LineItem curve_dbg1, curve_dbg2, curve_dbg3, curve_dbg4;
static RollingPointPairList list_acc_roll, list_acc_pitch, list_acc_z;
static RollingPointPairList list_gyro_roll, list_gyro_pitch, list_gyro_yaw;
static RollingPointPairList list_mag_roll, list_mag_pitch, list_mag_yaw;
static RollingPointPairList list_alt, list_head;
static RollingPointPairList list_dbg1, list_dbg2, list_dbg3, list_dbg4;
static Scale xScale;
CheckBoxEx[, ,] aux;
indicator_lamp[] indicators;
indicator_lamp[] indicators_mission;
System.Windows.Forms.Label[] cb_labels;
System.Windows.Forms.Label[] aux_labels;
System.Windows.Forms.Label[,] lmh_labels;
CultureInfo culture = new CultureInfo("zh-cn");
XmlTextReader reader;
int z;
//For video capture
static bool bVideoRecording = false;
static bool bVideoConnected = false;
static VideoFileWriter vfwWriter;
static FilterInfoCollection videoDevices;
static VideoCaptureDevice videoSource;
static TimeSpan tsFrameTimeStamp;
static TimeSpan tsFrameRate;
static Pen drawPen;
static System.Drawing.SolidBrush drawBrush;
static System.Drawing.Font drawFont;
//For logging
StreamWriter wLogStream;
StreamWriter wKMLLogStream;
static bool bLogRunning = false;
static bool bKMLLogRunning = false;
static UInt32 last_mode_flags; //Contains the mode flags from the pervious log write tick
static int GPS_lat_old, GPS_lon_old;
//Routes on Map
static GMapRoute GMRouteFlightPath;
static GMapRoute GMRouteMission;
//Map Overlays
static GMapOverlay GMOverlayFlightPath;// static so can update from gcs
static GMapOverlay GMOverlayWaypoints;
static GMapOverlay GMOverlayMission;
static GMapOverlay GMOverlayLiveData;
static GMapOverlay GMOverlayPOI;
//static PointLatLng copterPos = new PointLatLng(22.758201, 108.263773); //Just the corrds of my flying place
static PointLatLng copterPos = new PointLatLng(22.761075, 108.259851);
static bool isMouseDown = false;
static bool isMouseDraging = false;
static bool bPosholdRecorded = false;
static bool bHomeRecorded = false;
// markers
GMarkerGoogle currentMarker;
GMapMarkerRect CurentRectMarker = null;
GMapMarker center;
GMapMarker markerGoToClick = new GMarkerGoogle(new PointLatLng(0.0, 0.0),GMarkerGoogleType.lightblue);
List<PointLatLng> points = new List<PointLatLng>();
PointLatLng GPS_pos;
PointLatLng end;
PointLatLng start;
DebugWindow frmDebug;
string strDebug = "";
//Navigaton constants
static mission_step_structure mission_step;
const int MISSION_FLAG_END = 0xA5; //Flags that this is the last step
const byte IDLE = 0;
const byte HEADER_START = 1;
const byte HEADER_M = 2;
const byte HEADER_ARROW = 3;
const byte HEADER_SIZE = 4;
const byte HEADER_CMD = 5;
const byte HEADER_ERR = 6;
static byte[] inBuf;
static int AUX_CHANNELS = 4;
static byte c_state = IDLE;
static Boolean err_rcvd = false;
static byte offset = 0;
static byte dataSize = 0;
static byte checksum = 0;
static byte cmd;
static int serial_error_count = 0;
static int serial_packet_rx_count = 0;
static int serial_packet_tx_count = 0;
static int telemetry_link_quality = 0;
static int telemetry_started = 0;
static int telemetry_status_sent = 0;
static int telemetry_status_received = 0;
static byte previous_nav_error;
static int selectedrow;
static bool bGoToClikEnabled = false;
static int iDefAlt = 25; //Default altitude 25meters
static int iGTCAlt = 25;
//Servo settings
System.Windows.Forms.Label[] servo_text;
CheckBoxEx[] servo_reverse;
System.Windows.Forms.NumericUpDown[] servo_rate;
System.Windows.Forms.NumericUpDown[] servo_min;
System.Windows.Forms.NumericUpDown[] servo_mid;
System.Windows.Forms.NumericUpDown[] servo_max;
static int response_counter = 0;
static byte last_response = 0;
static byte update_cycle_count = 0; //Counts the update cycles (10 cycles all)
static bool bShowGauges = false;
static int prev_wp = 0;
static int prev_state = 0;
SpeechSynthesizer speech;
#endregion
public mainGUI()
{
InitializeComponent();
gui_settings = new GUI_settings();
if (!gui_settings.read_from_xml(sGuiSettingsFilename))
{
Environment.Exit(-1);
}
#region map_setup
// config map
MainMap.MinZoom = 1;
MainMap.MaxZoom = 20;
MainMap.CacheLocation = Path.GetDirectoryName(Application.ExecutablePath) + "/mapcache/";
//for (int i = 0; i < mapProviders.Length; i++)
//{
// cbMapProviders.Items.Add(mapProviders[i]);
//}
// map events
MainMap.OnPositionChanged += new PositionChanged(MainMap_OnCurrentPositionChanged);
//MainMap.OnMarkerClick += new MarkerClick(MainMap_OnMarkerClick);
MainMap.OnMapZoomChanged += new MapZoomChanged(MainMap_OnMapZoomChanged);
MainMap.MouseMove += new MouseEventHandler(MainMap_MouseMove);
MainMap.MouseDown += new MouseEventHandler(MainMap_MouseDown);
MainMap.MouseUp += new MouseEventHandler(MainMap_MouseUp);
MainMap.OnMarkerEnter += new MarkerEnter(MainMap_OnMarkerEnter);
MainMap.OnMarkerLeave += new MarkerLeave(MainMap_OnMarkerLeave);
currentMarker = new GMarkerGoogle(MainMap.Position,GMarkerGoogleType.red);
//MainMap.MapScaleInfoEnabled = true;
MainMap.ForceDoubleBuffer = true;
MainMap.Manager.Mode = AccessMode.ServerAndCache;
MainMap.Position = GetChinesePoint(copterPos);
//MainMap.Position = copterPos;
Pen penRoute = new Pen(Color.Yellow, 3);
Pen penScale = new Pen(Color.Blue, 3);
MainMap.ScalePen = penScale;
GMOverlayFlightPath = new GMapOverlay("flightpath");
MainMap.Overlays.Add(GMOverlayFlightPath);
GMOverlayMission = new GMapOverlay("missionroute");
MainMap.Overlays.Add(GMOverlayMission);
GMOverlayWaypoints = new GMapOverlay("waypoints");
MainMap.Overlays.Add(GMOverlayWaypoints);
GMOverlayLiveData = new GMapOverlay("livedata");
MainMap.Overlays.Add(GMOverlayLiveData);
GMOverlayPOI = new GMapOverlay("poi");
MainMap.Overlays.Add(GMOverlayPOI);
GMOverlayLiveData.Markers.Clear();
GMOverlayLiveData.Markers.Add(new GMapMarkerCopter(GetChinesePoint(copterPos), 0, 0, 0, 3));
GMRouteFlightPath = new GMapRoute(points, "flightpath");
GMRouteFlightPath.Stroke = penRoute;
GMOverlayFlightPath.Routes.Add(GMRouteFlightPath);
center = new GMarkerGoogle(MainMap.Position,GMarkerGoogleType.blue_dot);
//center = new GMapMarkerCross(MainMap.Position);
MainMap.Invalidate(false);
//MainMap.Refresh();
#endregion
}
private void mainGUI_Load(object sender, EventArgs e)
{
//First step, check it gui_settings file is exists or not, if not then start settings wizard
if (!File.Exists(sGuiSettingsFilename))
{
setup_wizard panelSetupWizard = new setup_wizard();
panelSetupWizard.ShowDialog();
}
//Now there must be a valid settings file, so we can continue with normal execution
splash_screen splash = new splash_screen();
splash.sVersionLabel = SVersion;
splash.Show();
splash.Refresh();
//Start with Settings file read, and parse exit if unsuccessfull
gui_settings = new GUI_settings();
if (!gui_settings.read_from_xml(sGuiSettingsFilename))
{
Environment.Exit(-1);
}
//fill out relevant variables
cbGUISpeechEnabled.Checked = gui_settings.speech_enabled;
sOptionsConfigFilename = sOptionsConfigFilename + ".xml";
read_options_config(); //read and parse optionsconfig.xml file. sets iCheckBoxItems
iCheckBoxItems = 24; //Theoretical maximum
splash.sStatus = "正在构建内部数据...";
splash.Refresh();
mw_gui = new mw_data_gui(iPidItems, iCheckBoxItems, gui_settings.iSoftwareVersion);
mw_params = new mw_settings(iPidItems, iCheckBoxItems, gui_settings.iSoftwareVersion);
mission_step = new mission_step_structure();
//Quick hack to get pid names to mw_params untill redo the structures
for (int i = 0; i < iPidItems; i++)
{
mw_params.pidnames[i] = Pid[i].name;
}
splash.sFcVersionLabel = "MultiWii version " + sRelName;
splash.sStatus = "正在连接到飞控...";
splash.Refresh();
MainMap.Manager.Mode = AccessMode.ServerAndCache;
if (!Stuff.PingNetwork("www.sina.com.cn"))
{
DialogResult result = MessageBox.Show("地图控件无法连接到互联网,是否采用缓存模式?", "GMap.NET控件无法访问互联网", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (result == DialogResult.Yes)
{
MainMap.Manager.Mode = AccessMode.CacheOnly;
}
// MessageBox.Show("地图控件无法连接到互联网,将采用缓存模式.", "GMap.NET - Demo.WindowsForms", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
cbGpsCorrect.Checked = gui_settings.GpsCorrect;
cbMapProviders.DataSource = GMapProviders.List;
this.cbMapProviders.SelectedIndexChanged += new System.EventHandler(this.cbMapProviders_SelectedIndexChanged);
cbMapProviders.SelectedIndex = gui_settings.iMapProviderSelectedIndex;
MainMap.MapProvider = (GMapProvider) cbMapProviders.Items[gui_settings.iMapProviderSelectedIndex];
MainMap.Zoom = 18;
splash.sStatus = "正在构建操作界面元素...";
splash.Refresh();
bSerialBuffer = new byte[65];
inBuf = new byte[300]; //init input buffer
ToolTip toolTip1 = new ToolTip();
toolTip1.AutoPopDelay = 5000;
toolTip1.InitialDelay = 1000;
toolTip1.ReshowDelay = 500;
toolTip1.ShowAlways = true;
//rcOptions1 = new byte[iCheckBoxItems];
//rcOptions2 = new byte[iCheckBoxItems];
//Fill out settings tab
l_Capture_folder.Text = gui_settings.sCaptureFolder;
l_LogFolder.Text = gui_settings.sLogFolder;
l_Settings_folder.Text = gui_settings.sSettingsFolder;
cb_Logging_enabled.Checked = gui_settings.bEnableLogging;
//Set log enties checkboxes
cb_Log1.Checked = gui_settings.logGraw;
cb_Log2.Checked = gui_settings.logGatt;
cb_Log3.Checked = gui_settings.logGmag;
cb_Log4.Checked = gui_settings.logGrcc;
cb_Log5.Checked = gui_settings.logGrcx;
cb_Log6.Checked = gui_settings.logGmot;
cb_Log7.Checked = gui_settings.logGsrv;
cb_Log8.Checked = gui_settings.logGnav;
cb_Log9.Checked = gui_settings.logGpar;
cb_Log10.Checked = gui_settings.logGdbg;
cbCellcount.SelectedIndex = gui_settings.cellcount - 1;
cbGUISpeechEnabled.Checked = gui_settings.speech_enabled;
cbSpeakAlt.Checked = gui_settings.announce_alt_enabled;
cbSpeakBattery.Checked = gui_settings.announce_vbat_enabled;
cbSpeakDist.Checked = gui_settings.announce_dist_enabled;
comboSpeakInterval.SelectedIndex = gui_settings.announce_interval;
b_save_gui_settings.BackColor = Color.Transparent;
splash.sStatus = "正在创建PID数据结构...";
splash.Refresh();
//Build servo control arrays
// It is a mess and not an elegant solution BUT WORKS
servo_text = new System.Windows.Forms.Label[8];
servo_text[0] = lSrvName1;
servo_text[1] = lSrvName2;
servo_text[2] = lSrvName3;
servo_text[3] = lSrvName4;
servo_text[4] = lSrvName5;
servo_text[5] = lSrvName6;
servo_text[6] = lSrvName7;
servo_text[7] = lSrvName8;
servo_reverse = new CheckBoxEx[8];
servo_reverse[0] = cbSrvRev1;
servo_reverse[1] = cbSrvRev2;
servo_reverse[2] = cbSrvRev3;
servo_reverse[3] = cbSrvRev4;
servo_reverse[4] = cbSrvRev5;
servo_reverse[5] = cbSrvRev6;
servo_reverse[6] = cbSrvRev7;
servo_reverse[7] = cbSrvRev8;
servo_rate = new System.Windows.Forms.NumericUpDown[8];
servo_rate[0] = nSrvRate1;
servo_rate[1] = nSrvRate2;
servo_rate[2] = nSrvRate3;
servo_rate[3] = nSrvRate4;
servo_rate[4] = nSrvRate5;
servo_rate[5] = nSrvRate6;
servo_rate[6] = nSrvRate7;
servo_rate[7] = nSrvRate8;
servo_min = new System.Windows.Forms.NumericUpDown[8];
servo_min[0] = nSrvMin1;
servo_min[1] = nSrvMin2;
servo_min[2] = nSrvMin3;
servo_min[3] = nSrvMin4;
servo_min[4] = nSrvMin5;
servo_min[5] = nSrvMin6;
servo_min[6] = nSrvMin7;
servo_min[7] = nSrvMin8;
servo_mid = new System.Windows.Forms.NumericUpDown[8];
servo_mid[0] = nSrvMid1;
servo_mid[1] = nSrvMid2;
servo_mid[2] = nSrvMid3;
servo_mid[3] = nSrvMid4;
servo_mid[4] = nSrvMid5;
servo_mid[5] = nSrvMid6;
servo_mid[6] = nSrvMid7;
servo_mid[7] = nSrvMid8;
servo_max = new System.Windows.Forms.NumericUpDown[8];
servo_max[0] = nSrvMax1;
servo_max[1] = nSrvMax2;
servo_max[2] = nSrvMax3;
servo_max[3] = nSrvMax4;
servo_max[4] = nSrvMax5;
servo_max[5] = nSrvMax6;
servo_max[6] = nSrvMax7;
servo_max[7] = nSrvMax8;
//Build PID control structure based on the Pid structure.
const int iLineSpace = 36;
const int iRow1 = 30;
const int iRow2 = 130;
const int iRow3 = 230;
const int iTopY = 25;
Font fontField = new Font("Tahoma", 9, FontStyle.Bold);
Size fieldSize = new Size(70, 25);
for (int i = 0; i < iPidItems; i++)
{
Pid[i].pidLabel = new System.Windows.Forms.Label();
Pid[i].pidLabel.Text = Pid[i].name;
Pid[i].pidLabel.Location = new Point(iRow1, 10 + i * iLineSpace);
Pid[i].pidLabel.Visible = true;
Pid[i].pidLabel.AutoSize = true;
Pid[i].pidLabel.ForeColor = Color.White;
Pid[i].pidLabel.TextAlign = ContentAlignment.MiddleRight;
toolTip1.SetToolTip(Pid[i].pidLabel, Pid[i].description);
this.tabPagePID.Controls.Add(Pid[i].pidLabel);
if (Pid[i].Pshown)
{
Pid[i].Pfield = new System.Windows.Forms.NumericUpDown();
Pid[i].Pfield.ValueChanged += new EventHandler(pfield_valuechange);
Pid[i].Pfield.Location = new Point(iRow1, iTopY + i * iLineSpace);
Pid[i].Pfield.Size = fieldSize;
Pid[i].Pfield.Font = fontField;
Pid[i].Pfield.BorderStyle = BorderStyle.None;
Pid[i].Pfield.Maximum = Pid[i].Pmax;
Pid[i].Pfield.Minimum = Pid[i].Pmin;
Pid[i].Pfield.DecimalPlaces = decimals(Pid[i].Pprec);
Pid[i].Pfield.Increment = 1 / (decimal)Pid[i].Pprec;
this.tabPagePID.Controls.Add(Pid[i].Pfield);
Pid[i].Plabel = new System.Windows.Forms.Label();
Pid[i].Plabel.Text = "P";
Pid[i].Plabel.Font = fontField;
Pid[i].Plabel.ForeColor = Color.White;
Pid[i].Plabel.Location = new Point(iRow1 - 20, iTopY + i * iLineSpace);
this.tabPagePID.Controls.Add(Pid[i].Plabel);
}
if (Pid[i].Ishown)
{
Pid[i].Ifield = new System.Windows.Forms.NumericUpDown();
Pid[i].Ifield.ValueChanged += new EventHandler(ifield_valuechange);
Pid[i].Ifield.Location = new Point(iRow2, iTopY + i * iLineSpace);
Pid[i].Ifield.Size = fieldSize;
Pid[i].Ifield.Font = fontField;
Pid[i].Ifield.BorderStyle = BorderStyle.None;
Pid[i].Ifield.Maximum = Pid[i].Imax;
Pid[i].Ifield.Minimum = Pid[i].Imin;
Pid[i].Ifield.DecimalPlaces = decimals(Pid[i].Iprec);
Pid[i].Ifield.Increment = 1 / (decimal)Pid[i].Iprec;
this.tabPagePID.Controls.Add(Pid[i].Ifield);
Pid[i].Ilabel = new System.Windows.Forms.Label();
Pid[i].Ilabel.Text = "I";
Pid[i].Ilabel.Font = fontField;
Pid[i].Ilabel.ForeColor = Color.White;
Pid[i].Ilabel.Location = new Point(iRow2 - 20, iTopY + i * iLineSpace);
this.tabPagePID.Controls.Add(Pid[i].Ilabel);
}
if (Pid[i].Dshown)
{
Pid[i].Dfield = new System.Windows.Forms.NumericUpDown();
Pid[i].Dfield.ValueChanged += new EventHandler(dfield_valuechange);
Pid[i].Dfield.Location = new Point(iRow3, iTopY + i * iLineSpace);
Pid[i].Dfield.Size = fieldSize;
Pid[i].Dfield.Font = fontField;
Pid[i].Dfield.BorderStyle = BorderStyle.None;
Pid[i].Dfield.Maximum = Pid[i].Dmax;
Pid[i].Dfield.Minimum = Pid[i].Dmin;
Pid[i].Dfield.DecimalPlaces = decimals(Pid[i].Dprec);
Pid[i].Dfield.Increment = 1 / (decimal)Pid[i].Dprec;
this.tabPagePID.Controls.Add(Pid[i].Dfield);
Pid[i].Dlabel = new System.Windows.Forms.Label();
Pid[i].Dlabel.Text = "D";
Pid[i].Dlabel.Font = fontField;
Pid[i].Dlabel.ForeColor = Color.White;
Pid[i].Dlabel.Location = new Point(iRow3 - 20, iTopY + i * iLineSpace);
this.tabPagePID.Controls.Add(Pid[i].Dlabel);
}
//Set up stuff at the mission palane
txtDefAlt.Text = iDefAlt.ToString(); //Set up default altitude
txtGTCAlt.Text = iGTCAlt.ToString(); //Set up default Go to Click altitude
}
//Tooltips (needs improvement)
toolTip1.SetToolTip(b_check_all_ACC, "Select all ACC values");
toolTip1.SetToolTip(b_uncheck_all_ACC, "Deselect all ACC values");
toolTip1.SetToolTip(lDefAlt, "默认航路点高度(in Above Ground Level where Home position Ground level is zero)");
toolTip1.SetToolTip(txtDefAlt, "默认航路点高度(in Above Ground Level where Home position Ground level is zero)");
this.Refresh();
splash.sStatus = "正在检查串口...";
splash.Refresh();
serial_ports_enumerate();
foreach (string speed in sSerialSpeeds)
{
cb_serial_speed.Items.Add(speed);
}
cb_serial_speed.SelectedItem = gui_settings.sPreferedSerialSpeed;
if (cb_serial_port.Items.Count == 0)
{
b_connect.Enabled = false; //Nos serial port, disable connect
}
//Init serial port object
serialPort = new SerialPort();
//Set up serial port parameters (at least the ones what we know upfront
serialPort.DataBits = 8;
serialPort.Parity = Parity.None;
serialPort.StopBits = StopBits.One;
serialPort.Handshake = Handshake.None;
serialPort.DtrEnable = false; //??
serialPort.ReadBufferSize = 4096; //4K byte of read buffer
serialPort.ReadTimeout = 500; // 500msec timeout;
//Init Realtime Monitor panel controls
foreach (string rate in sRefreshSpeeds)
{
cb_monitor_rate.Items.Add(rate);
}
cb_monitor_rate.SelectedIndex = 1; //10Hz is the default
splash.sStatus = "正在配置计时器...";
splash.Refresh();
//Setup timers
timer_realtime.Tick += new EventHandler(timer_realtime_Tick);
timer_realtime.Interval = iRefreshIntervals[cb_monitor_rate.SelectedIndex];
timer_realtime.Enabled = true;
timer_realtime.Stop();
splash.sStatus = "正在配置传感器曲线图控件...";
splash.Refresh();
//Set up zgMonitor control for real time monitoring
GraphPane myPane = zgMonitor.GraphPane;
// Set the titles and axis labels
myPane.Title.Text = "";
myPane.XAxis.Title.Text = "";
myPane.YAxis.Title.Text = "";
//Set up pointlists and curves
list_acc_roll = new RollingPointPairList(600);
curve_acc_roll = myPane.AddCurve("acc_roll", list_acc_roll, Color.Red, SymbolType.None);
list_acc_pitch = new RollingPointPairList(600);
curve_acc_pitch = myPane.AddCurve("acc_pitch", list_acc_pitch, Color.Green, SymbolType.None);
list_acc_z = new RollingPointPairList(600);
curve_acc_z = myPane.AddCurve("acc_z", list_acc_z, Color.Blue, SymbolType.None);
list_gyro_roll = new RollingPointPairList(600);
curve_gyro_roll = myPane.AddCurve("gyro_roll", list_gyro_roll, Color.Khaki, SymbolType.None);
list_gyro_pitch = new RollingPointPairList(600);
curve_gyro_pitch = myPane.AddCurve("gyro_pitch", list_gyro_pitch, Color.Cyan, SymbolType.None);
list_gyro_yaw = new RollingPointPairList(600);
curve_gyro_yaw = myPane.AddCurve("gyro_yaw", list_gyro_yaw, Color.Magenta, SymbolType.None);
list_mag_roll = new RollingPointPairList(600);
curve_mag_roll = myPane.AddCurve("mag_roll", list_mag_roll, Color.CadetBlue, SymbolType.None);
list_mag_pitch = new RollingPointPairList(600);
curve_mag_pitch = myPane.AddCurve("mag_pitch", list_mag_pitch, Color.MediumPurple, SymbolType.None);
list_mag_yaw = new RollingPointPairList(600);
curve_mag_yaw = myPane.AddCurve("mag_yaw", list_mag_yaw, Color.DarkGoldenrod, SymbolType.None);
list_alt = new RollingPointPairList(600);
curve_alt = myPane.AddCurve("alt", list_alt, Color.White, SymbolType.None);
list_head = new RollingPointPairList(600);
curve_head = myPane.AddCurve("head", list_head, Color.Orange, SymbolType.None);
list_dbg1 = new RollingPointPairList(600);
curve_dbg1 = myPane.AddCurve("dbg1", list_dbg1, Color.PaleTurquoise, SymbolType.None);
list_dbg2 = new RollingPointPairList(600);
curve_dbg2 = myPane.AddCurve("dbg2", list_dbg2, Color.PaleTurquoise, SymbolType.None);
list_dbg3 = new RollingPointPairList(600);
curve_dbg3 = myPane.AddCurve("dbg3", list_dbg3, Color.PaleTurquoise, SymbolType.None);
list_dbg4 = new RollingPointPairList(600);
curve_dbg4 = myPane.AddCurve("dbg4", list_dbg4, Color.PaleTurquoise, SymbolType.None);
// Show the x axis grid
myPane.XAxis.MajorGrid.IsVisible = true;
myPane.YAxis.MajorGrid.IsVisible = true;
myPane.XAxis.MajorGrid.Color = Color.DarkGray;
myPane.YAxis.MajorGrid.Color = Color.DarkGray;
myPane.XAxis.Scale.IsVisible = false;
// Make the Y axis scale red
myPane.YAxis.Scale.FontSpec.FontColor = Color.DarkGray;
myPane.YAxis.Title.FontSpec.FontColor = Color.DarkGray;
// turn off the opposite tics so the Y tics don't show up on the Y2 axis
myPane.YAxis.MajorTic.IsOpposite = false;
myPane.YAxis.MinorTic.IsOpposite = false;
// Don't display the Y zero line
myPane.YAxis.MajorGrid.IsZeroLine = true;
// Align the Y axis labels so they are flush to the axis
myPane.YAxis.Scale.Align = AlignP.Inside;
myPane.YAxis.Color = Color.DarkGray;
myPane.YAxis.Scale.IsVisible = false;
// Manually set the axis range
myPane.YAxis.Scale.Min = -600;
myPane.YAxis.Scale.Max = 600;
myPane.XAxis.Color = Color.DarkGray;
myPane.Border.Color = Color.FromArgb(64, 64, 64);
myPane.Chart.Fill = new Fill(Color.Black, Color.Black, 45.0f);
myPane.Fill = new Fill(Color.FromArgb(64, 64, 64), Color.FromArgb(64, 64, 64), 45.0f);
myPane.Legend.IsVisible = false;
myPane.XAxis.Scale.IsVisible = false;
myPane.YAxis.Scale.IsVisible = true;
myPane.XAxis.Scale.MagAuto = true;
myPane.YAxis.Scale.MagAuto = false;
zgMonitor.IsEnableHPan = true;
zgMonitor.IsEnableHZoom = true;
foreach (ZedGraph.LineItem li in myPane.CurveList)
{
li.Line.Width = 1;
}
myPane.YAxis.Title.FontSpec.FontColor = Color.DarkGray;
myPane.XAxis.Title.FontSpec.FontColor = Color.DarkGray;
myPane.XAxis.Scale.Min = 0;
myPane.XAxis.Scale.Max = 600;
myPane.XAxis.Type = AxisType.Linear;
zgMonitor.ScrollGrace = 0;
xScale = zgMonitor.GraphPane.XAxis.Scale;
zgMonitor.AxisChange();
splash.sStatus = "初始化视频记录功能...";
splash.Refresh();
//Init video capture dev
try
{
// enumerate video devices
videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
if (videoDevices.Count == 0)
throw new ApplicationException();
// add all devices to combo
foreach (FilterInfo device in videoDevices)
{
dropdown_devices.Items.Add(device.Name);
}
}
catch (ApplicationException)
{
dropdown_devices.Items.Add("找不到本地视频端口,是不是你的电脑没有摄像头或者视频卡驱动没有安装");
dropdown_devices.Enabled = false;
b_video_connect.Enabled = false;
}
dropdown_devices.SelectedIndex = 0;
cb_codec.SelectedIndex = 0;
//Drawing stuff for OSD
drawPen = new Pen(Color.White, 1);
drawFont = new System.Drawing.Font(FontFamily.GenericMonospace, 16.0F);
drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.White);
//Disable buttons that are not working till connected
b_reset.Enabled = false;
b_cal_acc.Enabled = false;
b_cal_mag.Enabled = false;
b_read_settings.Enabled = false;
b_write_settings.Enabled = false;
b_write_to_file.Enabled = false;
b_load_from_file.Enabled = false;
btnDownLoadMission.Enabled = false;
btnUploadMission.Enabled = false;
//init instrument panels
altitude_meter1.SetAlimeterParameters(0);
vertical_speed_indicator1.SetVerticalSpeedIndicatorParameters(0);
System.Threading.Thread.Sleep(2000);
splash.Close();
MainMap.Invalidate(false);
int w = MainMap.Size.Width;
MainMap.Width = w +1 ;
MainMap.Width = w;
MainMap.ShowCenter = false;
mw_gui.max_wp_number = gui_settings.max_wp_number;
mw_gui.wp_radius = gui_settings.wp_radius;
//Welcome message from Anna
if (gui_settings.speech_enabled)
{
speech = new SpeechSynthesizer();
speech.Rate = -2;
speech.SpeakAsync("系统启动完成。");
}
}
bool check_capability(int captocheck)
{
if ((mw_gui.capability & captocheck) > 0)
{
return true;
}
else
return false;
}
uint get_navi_version()
{
return (mw_gui.capability >> 28);
}
private void create_RC_Checkboxes(string[] names)
{
//Build indicator lamps array
indicators = new indicator_lamp[iCheckBoxItems];
int row = 0; int col = 0;
int startx = 490; int starty = 7;
for (int i = 0; i < iCheckBoxItems; i++)
{
indicators[i] = new indicator_lamp();
indicators[i].Location = new Point(startx + col * 67, starty + row * 19);
indicators[i].Visible = true;
indicators[i].Text = names[i];
indicators[i].indicator_color = 1;
this.splitContainer3.Panel1.Controls.Add(indicators[i]);
col++;
if (col == 2) { col = 0; row++; }
}
//Build a second indicator lamps array on Mission plane
indicators_mission = new indicator_lamp[iCheckBoxItems];
startx = this.splitContainer9.Panel1.Location.X + this.splitContainer9.Panel1.Width ;
starty = this.splitContainer9.Panel1.Location.Y + 20;
for (int i = 0; i < iCheckBoxItems; i++)
{
indicators_mission[i] = new indicator_lamp();
indicators_mission[i].Location = new Point(startx , starty + i * 19);
indicators_mission[i].Text = names[i];
indicators_mission[i].indicator_color = 1;
indicators_mission[i].Anchor = ( AnchorStyles.Right | AnchorStyles.Top );
indicators_mission[i].Visible = bShowGauges;
this.splitContainer9.Panel1.Controls.Add(indicators_mission[i]);
this.splitContainer9.Panel1.Controls.SetChildIndex(indicators_mission[i], 0);
}
//Build the RC control checkboxes structure
if (!check_capability(CAP.EXTENDED_AUX))
{
#region normal_aux_states
aux = new CheckBoxEx[4, 4, iCheckBoxItems];
startx = 200;
starty = 60;
int a, b, c;
for (c = 0; c < 4; c++)
{
for (a = 0; a < 3; a++)
{
for (b = 0; b < iCheckBoxItems; b++)
{
aux[c, a, b] = new CheckBoxEx();
aux[c, a, b].Location = new Point(startx + a * 18 + c * 70, starty + b * 25);
aux[c, a, b].Visible = true;
aux[c, a, b].Text = "";
aux[c, a, b].AutoSize = true;
aux[c, a, b].Size = new Size(16, 16);
aux[c, a, b].UseVisualStyleBackColor = true;
aux[c, a, b].CheckedChanged += new System.EventHandler(this.aux_checked_changed_event);
//Set info on the given checkbox position
aux[c, a, b].aux = c; //Which aux channel
aux[c, a, b].rclevel = a; //which rc level
aux[c, a, b].item = b; //Which item
this.tabPageRC.Controls.Add(aux[c, a, b]);
}
}
}
aux_labels = new System.Windows.Forms.Label[4];
lmh_labels = new System.Windows.Forms.Label[4, 3]; // aux1-4, L,M,H
string strlmh = "LMH";
for (a = 0; a < 4; a++)
{
aux_labels[a] = new System.Windows.Forms.Label();
aux_labels[a].Text = "AUX" + String.Format("{0:0}", a + 1);
aux_labels[a].Location = new Point(startx + a * 70 + 8, starty - 35);
aux_labels[a].AutoSize = true;
aux_labels[a].ForeColor = Color.White;
this.tabPageRC.Controls.Add(aux_labels[a]);
for (b = 0; b < 3; b++)
{
lmh_labels[a, b] = new System.Windows.Forms.Label();
lmh_labels[a, b].Text = strlmh.Substring(b, 1); ;
lmh_labels[a, b].Location = new Point(startx + a * 70 + b * 18, starty - 20);
lmh_labels[a, b].AutoSize = true;
lmh_labels[a, b].ForeColor = Color.White;
this.tabPageRC.Controls.Add(lmh_labels[a, b]);
}
}