Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2287 | - | 1 | using GMap.NET; |
2 | using GMap.NET.MapProviders; |
||
3 | using GMap.NET.WindowsPresentation; |
||
4 | using MKLiveView.GMapCustomMarkers; |
||
5 | using System; |
||
6 | using System.Collections.Generic; |
||
7 | using System.ComponentModel; |
||
8 | using System.Data; |
||
9 | using System.Diagnostics; |
||
10 | using System.IO; |
||
11 | using System.Linq; |
||
12 | using System.Linq.Expressions; |
||
13 | using System.Runtime.InteropServices; |
||
14 | using System.Text; |
||
15 | using System.Threading; |
||
16 | using System.Threading.Tasks; |
||
17 | using System.Windows; |
||
18 | using System.Windows.Controls; |
||
19 | using System.Windows.Data; |
||
20 | using System.Windows.Documents; |
||
21 | using System.Windows.Input; |
||
22 | using System.Windows.Interop; |
||
23 | using System.Windows.Media; |
||
24 | using System.Windows.Media.Animation; |
||
25 | using System.Windows.Media.Imaging; |
||
26 | using System.Windows.Navigation; |
||
27 | using System.Windows.Shapes; |
||
28 | using System.Windows.Threading; |
||
2313 | - | 29 | using System.Globalization; |
2324 | - | 30 | using System.Xml; |
31 | using System.Xml.Linq; |
||
2287 | - | 32 | |
33 | namespace MKLiveView |
||
34 | { |
||
35 | /// <summary> |
||
36 | /// Interaktionslogik für MainWindow.xaml |
||
37 | /// </summary> |
||
38 | public partial class MainWindow : Window |
||
39 | { |
||
2304 | - | 40 | #region declarations |
41 | |||
2287 | - | 42 | GMapMarker copter; |
43 | GMapMarker home; |
||
44 | PointLatLng start; |
||
45 | PointLatLng end; |
||
46 | PointLatLng pHome; |
||
2328 | - | 47 | GMapRoute mRouteWP; |
2342 | - | 48 | GMapMarker wpActiveMarker; |
2328 | - | 49 | List<PointLatLng> wpList = new List<PointLatLng>(); |
2324 | - | 50 | #region NC-Errors |
2287 | - | 51 | String[] NC_Error = new string[44] |
52 | { |
||
53 | "No Error", |
||
54 | "FC not compatible" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A1_.22FC_not_compatible_.22", |
||
55 | "MK3Mag not compatible" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A2_.22MK3Mag_not_compatible_.22", |
||
56 | "no FC communication" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A3_.22no_FC_communication_.22", |
||
57 | "no compass communication" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A4_.22no_compass_communication_.22", |
||
58 | "no GPS communication" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A5_.22no_GPS_communication_.22", |
||
59 | "bad compass value" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A6_.22bad_compass_value.22", |
||
60 | "RC Signal lost" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A7_.22RC_Signal_lost_.22", |
||
61 | "FC spi rx error" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A8_.22FC_spi_rx_error_.22", |
||
62 | "ERR: no NC communication" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A9:_.22ERR:_no_NC_communication.22", |
||
63 | "ERR: FC Nick Gyro" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A10_.22ERR:_FC_Nick_Gyro.22", |
||
64 | "ERR: FC Roll Gyro" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A11_.22ERR:_FC_Roll_Gyro.22", |
||
65 | "ERR: FC Yaw Gyro" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A12_.22ERR:_FC_Yaw_Gyro.22", |
||
66 | "ERR: FC Nick ACC" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A13_.22ERR:_FC_Nick_ACC.22", |
||
67 | "ERR: FC Roll ACC" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A14_.22ERR:_FC_Roll_ACC.22", |
||
68 | "ERR: FC Z-ACC" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A15_.22ERR:_FC_Z-ACC.22", |
||
69 | "ERR: Pressure sensor" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A16_.22ERR:_Pressure_sensor.22", |
||
70 | "ERR: FC I2C" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A17_.22ERR:_FC_I2C.22", |
||
71 | "ERR: Bl Missing" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A18_.22ERR:_Bl_Missing.22", |
||
72 | "Mixer Error" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A19_.22Mixer_Error.22", |
||
73 | "FC: Carefree Error" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A20_.22FC:_Carefree_Error.22", |
||
74 | "ERR: GPS lost" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A21_.22ERR:_GPS_lost.22", |
||
75 | "ERR: Magnet Error" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A22_.22ERR:_Magnet_Error.22", |
||
76 | "Motor restart" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A23_.22Motor_restart.22", |
||
77 | "BL Limitation" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A24_.22BL_Limitation.22", |
||
78 | "Waypoint range" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A25_.22Waypoint_range.22", |
||
79 | "ERR:No SD-Card" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A26_.22ERR:No_SD-Card.22", |
||
80 | "ERR:SD Logging aborted" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A27_.22ERR:SD_Logging_aborted.22", |
||
81 | "ERR:Flying range!" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A28_.22ERR:Flying_range.21.22", |
||
82 | "ERR:Max Altitude" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A29_.22ERR:Max_Altitude.22", |
||
83 | "No GPS Fix" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A30_.22No_GPS_Fix.22", |
||
84 | "compass not calibrated" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A31_.22compass_not_calibrated.22", |
||
85 | "ERR:BL selftest" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A32_.22ERR:BL_selftest.22", |
||
86 | "no ext. compass" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A33_.22no_ext._compass.22", |
||
87 | "compass sensor" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A34_.22compass_sensor.22", |
||
88 | "FAILSAFE pos.!" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A35_.22FAILSAFE_pos..21__.22", |
||
89 | "ERR:Redundancy" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A36_.22ERR:Redundancy__.22", |
||
90 | "Redundancy test" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A37_.22Redundancy_test_.22", |
||
91 | "GPS Update rate" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A38_.22GPS_Update_rate.22", |
||
92 | "ERR:Canbus" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A39_.22ERR:Canbus.22", |
||
93 | "ERR: 5V RC-Supply" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A40_.22ERR:_5V_RC-Supply.22", |
||
94 | "ERR:Power-Supply" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A41_.22ERR:Power-Supply.22", |
||
95 | "ACC not calibr." + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A42_.22ACC_not_calibr..22", |
||
96 | "ERR:Parachute!" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A43_.22ERR:Parachute.21.22" |
||
97 | }; |
||
2324 | - | 98 | #endregion NC-Errors |
2287 | - | 99 | [FlagsAttribute] |
100 | enum NC_HWError0 : short |
||
101 | { |
||
102 | None = 0, |
||
103 | SPI_RX = 1, |
||
104 | COMPASS_RX = 2, |
||
105 | FC_INCOMPATIBLE = 4, |
||
106 | COMPASS_INCOMPATIBLE = 8, |
||
107 | GPS_RX = 16, |
||
108 | COMPASS_VALUE = 32 |
||
109 | }; |
||
110 | [FlagsAttribute] |
||
111 | enum FC_HWError0 : short |
||
112 | { |
||
113 | None = 0, |
||
114 | GYRO_NICK = 1, |
||
115 | GYRO_ROLL = 2, |
||
116 | GYRO_YAW = 4, |
||
117 | ACC_NICK = 8, |
||
118 | ACC_ROLL = 16, |
||
119 | ACC_TOP = 32, |
||
120 | PRESSURE = 64, |
||
121 | CAREFREE = 128 |
||
122 | }; |
||
123 | [FlagsAttribute] |
||
124 | enum FC_HWError1 : short |
||
125 | { |
||
126 | None = 0, |
||
127 | I2C = 1, |
||
128 | BL_MISSING = 2, |
||
129 | SPI_RX = 4, |
||
130 | PPM = 8, |
||
131 | MIXER = 16, |
||
132 | RC_VOLTAGE = 32, |
||
133 | ACC_NOT_CAL = 64, |
||
134 | RES3 = 128 |
||
135 | }; |
||
136 | public enum LogMsgType { Incoming, Outgoing, Normal, Warning, Error }; |
||
137 | // Various colors for logging info |
||
138 | private Color[] LogMsgTypeColor = { Color.FromArgb(255, 43, 145, 175), Colors.Green, Colors.Black, Colors.Orange, Colors.Red }; |
||
139 | |||
140 | bool _bCBInit = true; |
||
141 | bool _init = true; |
||
142 | bool check_HWError = false; |
||
143 | |||
144 | string filePath = Directory.GetCurrentDirectory(); |
||
145 | bool bReadContinously = false; |
||
146 | bool _debugDataAutorefresh = true; |
||
147 | bool _navCtrlDataAutorefresh = true; |
||
148 | bool _blctrlDataAutorefresh = true; |
||
149 | bool _OSDAutorefresh = true; |
||
150 | bool _bErrorLog = false; |
||
151 | bool _bConnErr = false; |
||
152 | bool _bFollowCopter = false; |
||
2324 | - | 153 | bool _bGPXLog = false; |
2287 | - | 154 | |
155 | bool _bSaveWinStateNormal = true; |
||
156 | bool _bSaveWinStateFull = true; |
||
157 | |||
158 | double scaleNormalAll = 1; |
||
159 | double scaleNormalTopBar = 1; |
||
160 | double scaleNormalMotors = 1; |
||
161 | double scaleNormalOSD = 1; |
||
162 | double scaleNormalLOG = 1; |
||
163 | double scaleNormalHorizon = 1; |
||
164 | |||
165 | double scaleFullAll = 1; |
||
166 | double scaleFullTopBar = 1; |
||
167 | double scaleFullMotors = 1; |
||
168 | double scaleFullOSD = 1; |
||
169 | double scaleFullLOG = 1; |
||
170 | double scaleFullHorizon = 1; |
||
171 | |||
172 | int _iCtrlAct = 0; |
||
173 | int iOSDPage = 0; |
||
174 | int iOSDMax = 0; |
||
175 | int _iLifeCounter = 0; |
||
176 | int crcError = 0; |
||
177 | |||
2291 | - | 178 | bool _bSatFix = false; |
179 | Storyboard stbSatFixLostAnim; |
||
180 | bool _bAnimSatFixActive = false; |
||
181 | bool _bVoiceSatFixActive = false; |
||
182 | bool _bVoiceSatFixPlay = false; |
||
183 | int _iSatsLast = 0; |
||
184 | int _iSatsJitter = 0; |
||
185 | |||
186 | bool _bMagneticFieldOK = false; |
||
187 | Storyboard stbMagneticFieldAnim; |
||
188 | bool _bAnimMagneticFieldActive = false; |
||
189 | bool _bVoiceMagneticFieldActive = false; |
||
190 | bool _bVoiceMagneticFieldPlay = false; |
||
191 | int _iMagneticFieldLast = 0; |
||
192 | int _iMagneticFieldJitter = 0; |
||
193 | |||
194 | bool _bRCLevelOK = false; |
||
195 | Storyboard stbRCLevelAnim; |
||
196 | bool _bAnimRCLevelActive = false; |
||
197 | bool _bVoiceRCLevelActive = false; |
||
198 | bool _bVoiceRCLevelPlay = false; |
||
199 | int _iRCLevelLast = 0; |
||
200 | int _iRCLevelJitter = 0; |
||
201 | |||
2287 | - | 202 | int _iMotors = 4; |
203 | int _LipoCells = 4; |
||
204 | |||
205 | double _dLipoVMax = 16.88; |
||
206 | double _dLipoVMin = 12; |
||
207 | double _dThresholdVoltageWarn = 0; |
||
208 | double _dThresholdVoltageCrit = 0; |
||
209 | Storyboard stbVoltageCritAnim; |
||
210 | bool _bCritAnimVoltActive = false; |
||
211 | bool _bCritVoiceVoltActive = false; |
||
2291 | - | 212 | bool _bWarnVoiceVoltActive = false; |
2287 | - | 213 | bool _bVoiceVoltPlay = false; |
214 | double _dVoltLast = 0; |
||
215 | int _iVoltJitter = 0; |
||
216 | |||
2291 | - | 217 | double _dThresholdDistanceWarn = 100; |
218 | Storyboard stbDistanceWarnAnim; |
||
219 | bool _bAnimDistanceActive = false; |
||
220 | bool _bVoiceDistanceActive = false; |
||
221 | bool _bVoiceDistancePlay = false; |
||
222 | double _dDistanceLast = 0; |
||
223 | int _iDistanceJitter = 0; |
||
224 | |||
225 | double _dThresholdDistanceMax = 1000; |
||
226 | int _iThresholdRC = 160; |
||
227 | int _iThresholdMagField = 15; |
||
228 | |||
2295 | - | 229 | bool _bAutoHome = false; |
230 | bool _bFirstSatFix = false; |
||
231 | int _iFirstSatFix = 0; |
||
2291 | - | 232 | |
2287 | - | 233 | double _dTopHeight = 36; |
234 | |||
235 | int[] serChan = new int[12] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; |
||
236 | int[] serChan_sub = new int[12] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; |
||
237 | string[] serChanTitle = new string[12]; |
||
238 | |||
239 | string[] sAnalogLabel = new string[32]; |
||
240 | string[] sAnalogData = new string[32]; |
||
2324 | - | 241 | int[] iAnalogData = new int[32]; |
2287 | - | 242 | |
243 | int[] iTimings = new int[] {100,150,200,250,300,350,400,450,500,550,600,650,700,750,800,850,900,950,1000,1100,1200,1300,1400,1500,1600,1700,1800,1900,2000 }; |
||
244 | int[] iMotors = new int[] {3,4,5,6,7,8,9,10,11,12 }; |
||
245 | string[] sLiPoCells = new string[] { "3s", "4s", "5s", "6s" }; |
||
246 | /// <summary> |
||
247 | /// interval for sending debugdata (multiplied by 10ms) |
||
248 | /// </summary> |
||
249 | byte debugInterval = 10; //(=> 100ms) |
||
250 | /// <summary> |
||
251 | /// interval for sending BL-CTRL status (multiplied by 10ms) |
||
252 | /// </summary> |
||
253 | byte blctrlInterval = 75; |
||
254 | /// <summary> |
||
255 | /// interval for sending NAV-CTRL status (multiplied by 10ms) |
||
256 | /// </summary> |
||
257 | byte navctrlInterval = 80; |
||
258 | /// <summary> |
||
259 | /// interval for sending OSD page update (multiplied by 10ms) |
||
260 | /// </summary> |
||
261 | byte OSDInterval = 85; |
||
262 | /// <summary> |
||
263 | /// datatable for the debug data array - displayed on settings tabpage in datagridview |
||
264 | /// </summary> |
||
265 | DataTable dtAnalog = new DataTable(); |
||
266 | /// <summary> |
||
267 | /// datatable for motordata (current,temp) |
||
268 | /// </summary> |
||
2315 | - | 269 | DataTable dtMotors = new DataTable(); |
2287 | - | 270 | |
271 | DataTable dtWaypoints = new DataTable(); |
||
2313 | - | 272 | static volatile int _iWPCount = -1; |
273 | static volatile int _iWPIndex = -1; |
||
274 | int _iWPTimeout = 1000; |
||
2287 | - | 275 | bool _bGetWP = false; |
2328 | - | 276 | bool _bShowWPRoute = false; |
2287 | - | 277 | static volatile bool _bGetWPCount = false; |
2324 | - | 278 | DataTable dtGPX = new DataTable(); |
279 | DataRow drGPX; |
||
280 | bool _bAirborne = false; |
||
2340 | - | 281 | int _wpIndex = -1, _wpCount = 0; |
282 | |||
2287 | - | 283 | DispatcherTimer timer = new DispatcherTimer(); |
284 | |||
285 | /// <summary> |
||
286 | /// stuff for enabeling touch zoom for the map |
||
287 | /// </summary> |
||
288 | Point pTouch1 = new Point(0,0), pTouch2 = new Point(0,0); |
||
289 | int iFirstStylusID = -1; |
||
290 | public string connectButtonText |
||
291 | { |
||
292 | get |
||
293 | { |
||
294 | return bReadContinously ? "stop polling data" + System.Environment.NewLine + "from copter" : "start polling data" + System.Environment.NewLine + "from copter"; |
||
295 | } |
||
296 | } |
||
297 | |||
298 | WinState winState = new WinState(); |
||
2304 | - | 299 | #endregion declarations |
2287 | - | 300 | public MainWindow() |
301 | { |
||
302 | InitializeComponent(); |
||
303 | _initForm(); |
||
304 | _dataTablesInit(); |
||
305 | _setupMap(); |
||
306 | _init = false; |
||
307 | timer.Tick += new EventHandler(timerEvent); |
||
308 | timer.Interval = new TimeSpan(0, 0, 1); |
||
309 | timer.Start(); |
||
310 | } |
||
311 | |||
312 | #region init |
||
313 | void _initForm() |
||
314 | { |
||
315 | _readIni(); |
||
316 | if (_bSaveWinStateNormal) |
||
317 | _setScaleSliders(false); |
||
318 | cBoxTimingsDebug.ItemsSource = |
||
319 | cBoxTimingsNav.ItemsSource = |
||
320 | cBoxTimingsBl.ItemsSource = |
||
321 | cBoxTimingsOSD.ItemsSource = |
||
322 | iTimings; |
||
323 | cBoxLiPoCells.ItemsSource = sLiPoCells; |
||
324 | cBoxLiPoCells.SelectedItem = _LipoCells.ToString() + "s"; |
||
325 | _LipoMinMax(); |
||
326 | sliderThresholdVoltageWarn.Value = _dThresholdVoltageWarn; |
||
327 | sliderThresholdVoltageCrit.Value = _dThresholdVoltageCrit; |
||
328 | checkBoxThresholdVoltageVoice.IsChecked = _bVoiceVoltPlay; |
||
2291 | - | 329 | checkBoxSatfixLost.IsChecked = _bVoiceSatFixPlay; |
330 | checkBoxMagneticField.IsChecked = _bVoiceMagneticFieldPlay; |
||
331 | checkBoxThresholdDistanceVoice.IsChecked = _bVoiceDistancePlay; |
||
332 | sliderThresholdDistanceWarn.Value = _dThresholdDistanceWarn; |
||
333 | checkBoxRClevel.IsChecked = _bVoiceRCLevelPlay; |
||
2287 | - | 334 | |
2291 | - | 335 | sliderThresholdDistanceWarn.Maximum = _dThresholdDistanceMax; |
336 | |||
2287 | - | 337 | cBoxMotors.ItemsSource = iMotors; |
338 | cBoxMotors.SelectedItem = _iMotors; |
||
339 | |||
340 | serialPortCtrl.PortClosed += serialPortCtrl_PortClosed; |
||
341 | serialPortCtrl.PortOpened += serialPortCtrl_PortOpened; |
||
342 | serialPortCtrl.DataReceived += processMessage; |
||
343 | |||
344 | chkbAutoBL.IsChecked = _blctrlDataAutorefresh; |
||
345 | chkbAutoDbg.IsChecked = _debugDataAutorefresh; |
||
346 | chkbAutoNav.IsChecked = _navCtrlDataAutorefresh; |
||
347 | chkbAutoOSD.IsChecked = _OSDAutorefresh; |
||
348 | |||
349 | cBoxTimingsDebug.SelectedItem = debugInterval * 10; |
||
350 | cBoxTimingsNav.SelectedItem = navctrlInterval * 10; |
||
351 | cBoxTimingsBl.SelectedItem = blctrlInterval * 10; |
||
352 | cBoxTimingsOSD.SelectedItem = OSDInterval * 10; |
||
2295 | - | 353 | checkBoxAutoSetHP.IsChecked = _bAutoHome; |
2287 | - | 354 | checkBoxFollowCopter.IsChecked = _bFollowCopter; |
2324 | - | 355 | checkBoxGPXLog.IsChecked = _bGPXLog; |
2328 | - | 356 | checkBoxShowWPRoute.IsChecked = _bShowWPRoute; |
2287 | - | 357 | |
358 | } |
||
359 | /// <summary> |
||
360 | /// initialize the datatables |
||
361 | /// with columnnames etc |
||
362 | /// </summary> |
||
363 | void _dataTablesInit() |
||
364 | { |
||
2315 | - | 365 | dtMotors.Columns.Add("#"); |
2313 | - | 366 | if (Thread.CurrentThread.CurrentUICulture.Name == "de-DE") |
2315 | - | 367 | dtMotors.Columns.Add("Strom"); |
2313 | - | 368 | else |
2315 | - | 369 | dtMotors.Columns.Add("Current"); |
370 | dtMotors.Columns.Add("Temp"); |
||
371 | dgvMotors1.DataContext = dtMotors.DefaultView; |
||
2287 | - | 372 | _initDTMotors(); |
373 | |||
374 | Setter setter = new Setter(ContentControl.PaddingProperty, new Thickness(5,0,5,0)); |
||
375 | Style style = new Style(typeof(System.Windows.Controls.Primitives.DataGridColumnHeader)); |
||
376 | style.Setters.Add(setter); |
||
377 | setter = new Setter(ContentControl.BackgroundProperty, new SolidColorBrush(Colors.Transparent)); |
||
378 | style.Setters.Add(setter); |
||
379 | setter = new Setter(ContentControl.ForegroundProperty, new SolidColorBrush(Colors.White)); |
||
380 | style.Setters.Add(setter); |
||
2313 | - | 381 | |
382 | dtWaypoints.Columns.Add("Index",typeof(int)); |
||
2315 | - | 383 | dtWaypoints.Columns.Add("Type", typeof(int)); |
2313 | - | 384 | dtWaypoints.Columns.Add("Name",typeof(string)); |
2315 | - | 385 | dtWaypoints.Columns.Add("Latitude",typeof(double)); |
386 | dtWaypoints.Columns.Add("Longitude",typeof(double)); |
||
2313 | - | 387 | dtWaypoints.Columns.Add("Altitude",typeof(string)); |
388 | dtWaypoints.Columns.Add("Heading",typeof(string)); |
||
389 | dtWaypoints.Columns.Add("Speed",typeof(string)); |
||
390 | dtWaypoints.Columns.Add("ClimbRate",typeof(string)); |
||
391 | dtWaypoints.Columns.Add("Radius",typeof(string)); |
||
392 | dtWaypoints.Columns.Add("HoldTime",typeof(string)); |
||
393 | dtWaypoints.Columns.Add("AutoTrigger",typeof(string)); |
||
394 | dtWaypoints.Columns.Add("CamAngle",typeof(string)); |
||
395 | dtWaypoints.Columns.Add("Event",typeof(string)); |
||
396 | dtWaypoints.Columns.Add("Out1Timer",typeof(string)); |
||
397 | dtWaypoints.Columns.Add("Status",typeof(string)); |
||
398 | dtWaypoints.PrimaryKey = new DataColumn[] { dtWaypoints.Columns["Index"] }; |
||
399 | dgvWP.ItemsSource = dtWaypoints.DefaultView; |
||
2287 | - | 400 | dgvWP.ColumnHeaderStyle = new Style(); |
401 | dgvWP.ColumnHeaderStyle = style; |
||
2313 | - | 402 | |
2324 | - | 403 | dtGPX.Columns.Add("Index",typeof(int)); |
404 | dtGPX.Columns.Add("Latitude",typeof(double)); |
||
405 | dtGPX.Columns.Add("Longitude",typeof(double)); |
||
406 | dtGPX.Columns.Add("Elevation",typeof(int)); |
||
407 | dtGPX.Columns.Add("Time",typeof(string)); |
||
408 | dtGPX.PrimaryKey = new DataColumn[] { dtGPX.Columns["Index"] }; |
||
409 | drGPX = dtGPX.NewRow(); |
||
2313 | - | 410 | |
2287 | - | 411 | } |
412 | /// <summary> |
||
2315 | - | 413 | /// initialize the datatable dtMotors for motor values |
2313 | - | 414 | /// DataGridView dgvMotors1 is bound to dtMotors1 |
2287 | - | 415 | /// </summary> |
416 | void _initDTMotors() |
||
417 | { |
||
418 | for (int i = 0; i < 12; i++) |
||
419 | { |
||
2315 | - | 420 | if (dtMotors.Rows.Count < 12) |
421 | dtMotors.Rows.Add((i + 1).ToString(), "NA", "NA"); |
||
2287 | - | 422 | else |
423 | { |
||
2315 | - | 424 | dtMotors.Rows[i].SetField(1, "NA"); |
425 | dtMotors.Rows[i].SetField(2, "NA"); |
||
2287 | - | 426 | } |
427 | } |
||
428 | } |
||
429 | |||
430 | #endregion init |
||
431 | |||
432 | #region events |
||
433 | private void serialPortCtrl_PortOpened() |
||
434 | { |
||
435 | Dispatcher.Invoke(() => imageWiFi.Source = new BitmapImage(new Uri("Images/WiFi_G.png", UriKind.Relative))); |
||
436 | _getVersion(); |
||
437 | Thread.Sleep(100); |
||
438 | //_OSDMenue(0); |
||
439 | //Thread.Sleep(200); |
||
440 | //_sendSerialData(); |
||
441 | _readCont(true); |
||
442 | } |
||
443 | private void serialPortCtrl_PortClosed() |
||
444 | { |
||
445 | Dispatcher.Invoke(() => imageWiFi.Source = new BitmapImage(new Uri("Images/WiFi_W.png", UriKind.Relative))); |
||
446 | _readCont(false); |
||
447 | } |
||
2324 | - | 448 | bool _bToggle = false; |
2287 | - | 449 | void timerEvent(object sender, EventArgs e) |
450 | { |
||
451 | if (bReadContinously) |
||
452 | { |
||
453 | if (_debugDataAutorefresh) { _readDebugData(true); Thread.Sleep(10); } |
||
454 | |||
455 | if (_blctrlDataAutorefresh) { _readBLCtrl(true); Thread.Sleep(10); } |
||
456 | |||
457 | if (_navCtrlDataAutorefresh && _iCtrlAct == 2) { _readNavData(true); Thread.Sleep(10); } |
||
458 | check_HWError = true; |
||
459 | _getVersion(); |
||
460 | Thread.Sleep(10); |
||
461 | if (_OSDAutorefresh) |
||
462 | { |
||
463 | if (iOSDMax == 0 | cbOSD.Items.Count != iOSDMax) |
||
464 | _initOSDCB(); |
||
465 | _OSDMenueAutoRefresh(); |
||
466 | } |
||
467 | if (_iLifeCounter > 0) |
||
468 | { |
||
469 | Dispatcher.Invoke(() => imageConn.Source = new BitmapImage(new Uri("Images/Data_G.png", UriKind.Relative))); |
||
470 | // Dispatcher.Invoke((Action)(() => rctConnection.Fill = Brushes.LightGreen)); |
||
471 | _iLifeCounter = 0; |
||
472 | _bConnErr = false; |
||
2327 | - | 473 | if(_bAirborne && _bGPXLog) |
2324 | - | 474 | { |
475 | drGPX[0] = dtGPX.Rows.Count; |
||
476 | dtGPX.Rows.Add(new object[] { drGPX[0], drGPX[1], drGPX[2], drGPX[3], drGPX[4] }); |
||
477 | } |
||
2327 | - | 478 | Dispatcher.Invoke((Action)(() => tbSideBarGPXLog.Background = (_bAirborne && _bGPXLog && _bToggle) ? new SolidColorBrush(Colors.LightSeaGreen) : new SolidColorBrush(Colors.Transparent))); |
479 | Dispatcher.Invoke((Action)(() => tbSideBarGPXLog.Foreground = (_bAirborne && _bGPXLog) ? new SolidColorBrush(Colors.White) : new SolidColorBrush(Color.FromArgb(255, 211, 210, 210)))); |
||
480 | Dispatcher.Invoke((Action)(() => tbSideBarGPXLog.BorderBrush = (_bAirborne && _bGPXLog) ? new SolidColorBrush(Colors.White) : new SolidColorBrush(Color.FromArgb(255, 211, 210, 210)))); |
||
2324 | - | 481 | _bToggle = !_bToggle; |
2287 | - | 482 | } |
483 | else |
||
484 | { |
||
485 | if (!_bConnErr) |
||
486 | { |
||
487 | Log(LogMsgType.Error, "No communication to NC/FC!"); |
||
488 | Dispatcher.Invoke(() => imageConn.Source = new BitmapImage(new Uri("Images/Data_R.png", UriKind.Relative))); |
||
489 | // Dispatcher.Invoke((Action)(() => rctConnection.Fill = Brushes.Red)); |
||
490 | _bConnErr = true; |
||
491 | } |
||
492 | } |
||
493 | } |
||
494 | } |
||
495 | |||
496 | private void labelData_MouseDown(object sender, MouseButtonEventArgs e) |
||
497 | { |
||
498 | GridData.Visibility = GridData.Visibility == Visibility.Collapsed ? Visibility.Visible : Visibility.Collapsed; |
||
499 | GridSettings.Visibility = GridWP.Visibility = Visibility.Collapsed; |
||
500 | } |
||
501 | private void labelMotorData_MouseDown(object sender, MouseButtonEventArgs e) |
||
502 | { |
||
503 | GridMotors.Visibility = GridMotors.Visibility == Visibility.Hidden ? Visibility.Visible : Visibility.Hidden; |
||
504 | if (GridMotors.IsVisible) |
||
505 | _setMotorGridSize(); |
||
506 | } |
||
507 | private void labelSettings_MouseDown(object sender, MouseButtonEventArgs e) |
||
508 | { |
||
509 | GridData.Visibility = GridWP.Visibility = Visibility.Collapsed; |
||
510 | GridSettings.Visibility = GridSettings.Visibility == Visibility.Collapsed ? Visibility.Visible : Visibility.Collapsed; |
||
511 | } |
||
512 | private void labelLog_MouseDown(object sender, MouseButtonEventArgs e) |
||
513 | { |
||
514 | GridLog.Visibility = GridLog.Visibility == Visibility.Collapsed ? Visibility.Visible : Visibility.Collapsed; |
||
515 | } |
||
516 | private void labelOSD_MouseDown(object sender, MouseButtonEventArgs e) |
||
517 | { |
||
518 | GridOSD.Visibility = GridOSD.Visibility == Visibility.Hidden ? Visibility.Visible : Visibility.Hidden; |
||
519 | } |
||
520 | private void labelWaypoints_MouseDown(object sender, MouseButtonEventArgs e) |
||
521 | { |
||
522 | GridData.Visibility = GridSettings.Visibility = Visibility.Collapsed; |
||
523 | GridWP.Visibility = GridWP.Visibility == Visibility.Collapsed ? Visibility.Visible : Visibility.Collapsed; |
||
524 | } |
||
525 | |||
526 | private void btnGetWP_Click(object sender, RoutedEventArgs e) |
||
527 | { |
||
528 | Thread t = new Thread(new ThreadStart(_getWP)); |
||
529 | t.Start(); |
||
530 | } |
||
531 | private void btnSendWPList_Click(object sender, RoutedEventArgs e) |
||
532 | { |
||
2313 | - | 533 | Thread t = new Thread(new ThreadStart(_sendWPList)); |
534 | t.Start(); |
||
2287 | - | 535 | } |
536 | |||
537 | private void btnConnectToCopter_Click(object sender, RoutedEventArgs e) |
||
538 | { |
||
539 | if (!serialPortCtrl.Port.IsOpen) |
||
540 | serialPortCtrl.Connect(true); |
||
541 | else |
||
542 | _readCont(!bReadContinously); |
||
543 | } |
||
544 | private void btnSetHP_Click(object sender, RoutedEventArgs e) |
||
545 | { |
||
2347 | - | 546 | _setHomePos(); |
2287 | - | 547 | } |
548 | private void btnClearHP_Click(object sender, RoutedEventArgs e) |
||
549 | { |
||
2347 | - | 550 | _clearHomePos(); |
2287 | - | 551 | } |
552 | private void btnGotoHP_Click(object sender, RoutedEventArgs e) |
||
553 | { |
||
554 | if (home != null && MainMap.Markers.Contains(home)) |
||
555 | MainMap.Position = home.Position; |
||
556 | } |
||
2295 | - | 557 | private void checkBoxAutoSetHP_Click(object sender, RoutedEventArgs e) |
558 | { |
||
559 | _bAutoHome = (bool)checkBoxAutoSetHP.IsChecked; |
||
560 | } |
||
2287 | - | 561 | private void chkBoxSaveNormalState_Click(object sender, RoutedEventArgs e) |
562 | { |
||
563 | _bSaveWinStateNormal = (bool)chkBoxSaveNormalState.IsChecked; |
||
564 | } |
||
565 | private void chkBoxSaveFullScreenState_Click(object sender, RoutedEventArgs e) |
||
566 | { |
||
567 | _bSaveWinStateFull = (bool)chkBoxSaveFullScreenState.IsChecked; |
||
568 | } |
||
569 | |||
2291 | - | 570 | #region thresholds |
2287 | - | 571 | private void sliderThresholdVoltageWarn_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) |
572 | { |
||
573 | if(!_init) |
||
574 | _dThresholdVoltageWarn = sliderThresholdVoltageWarn.Value; |
||
575 | } |
||
576 | private void sliderThresholdVoltageCrit_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) |
||
577 | { |
||
578 | if(!_init) |
||
579 | _dThresholdVoltageCrit = sliderThresholdVoltageCrit.Value; |
||
580 | } |
||
581 | private void checkBoxThresholdVoltageVoice_Click(object sender, RoutedEventArgs e) |
||
582 | { |
||
583 | _bVoiceVoltPlay = (bool)checkBoxThresholdVoltageVoice.IsChecked; |
||
584 | } |
||
2291 | - | 585 | |
586 | private void sliderThresholdDistanceWarn_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) |
||
587 | { |
||
588 | if(!_init) |
||
589 | _dThresholdDistanceWarn = sliderThresholdDistanceWarn.Value; |
||
590 | } |
||
591 | private void checkBoxThresholdDistanceVoice_Click(object sender, RoutedEventArgs e) |
||
592 | { |
||
593 | _bVoiceDistancePlay = (bool)checkBoxThresholdDistanceVoice.IsChecked; |
||
594 | } |
||
595 | |||
596 | private void checkBoxSatfixLost_Click(object sender, RoutedEventArgs e) |
||
597 | { |
||
598 | _bVoiceSatFixPlay = (bool)checkBoxSatfixLost.IsChecked; |
||
599 | } |
||
600 | private void checkBoxMagneticField_Click(object sender, RoutedEventArgs e) |
||
601 | { |
||
602 | _bVoiceMagneticFieldPlay = (bool)checkBoxMagneticField.IsChecked; |
||
603 | } |
||
604 | private void checkBoxRClevel_Click(object sender, RoutedEventArgs e) |
||
605 | { |
||
606 | _bVoiceRCLevelPlay = (bool)checkBoxRClevel.IsChecked; |
||
607 | } |
||
608 | #endregion thresholds |
||
609 | |||
2287 | - | 610 | private void buttonSwitchNC_Click(object sender, RoutedEventArgs e) |
611 | { |
||
612 | _switchToNC(); |
||
613 | } |
||
614 | |||
615 | private void Window_Loaded(object sender, RoutedEventArgs e) |
||
616 | { |
||
617 | stbVoltageCritAnim = TryFindResource("VoltageCritAnim") as Storyboard; |
||
2291 | - | 618 | stbSatFixLostAnim = TryFindResource("SatFixLostAnim") as Storyboard; |
619 | stbMagneticFieldAnim = TryFindResource("MagneticFieldCritAnim") as Storyboard; |
||
620 | stbDistanceWarnAnim = TryFindResource("DistanceCritAnim") as Storyboard; |
||
621 | stbRCLevelAnim = TryFindResource("RCCritAnim") as Storyboard; |
||
2287 | - | 622 | _setMotorGridSize(); |
623 | } |
||
2310 | - | 624 | private void Window_Closing(object sender, CancelEventArgs e) |
625 | { |
||
626 | _writeIni(); |
||
2324 | - | 627 | if(_bGPXLog && dtGPX.Rows.Count > 0) |
628 | _saveGPXLog(); |
||
2310 | - | 629 | } |
2287 | - | 630 | #endregion events |
631 | |||
632 | #region GMap |
||
633 | |||
634 | void _setupMap() |
||
635 | { |
||
636 | MainMap.Manager.Mode = AccessMode.ServerAndCache; |
||
637 | MainMap.MapProvider = GMapProviders.BingHybridMap; |
||
638 | MainMap.SetPositionByKeywords("Landshut"); |
||
639 | MainMap.MinZoom = 0; |
||
640 | MainMap.MaxZoom = 24; |
||
641 | MainMap.Zoom = 16; |
||
642 | MainMap.ShowCenter = true; |
||
643 | MainMap.ShowTileGridLines = false; |
||
644 | sliderMapZoom.Value = 16; |
||
645 | comboBoxMapType.ItemsSource = providerList; |
||
646 | comboBoxMapType.DisplayMemberPath = "Name"; |
||
647 | comboBoxMapType.SelectedItem = MainMap.MapProvider; |
||
648 | |||
649 | // acccess mode |
||
650 | comboBoxMode.ItemsSource = Enum.GetValues(typeof(AccessMode)); |
||
651 | comboBoxMode.SelectedItem = MainMap.Manager.Mode; |
||
652 | |||
653 | } |
||
654 | |||
655 | /// <summary> |
||
656 | /// selection of relevant map providers --> if You need more, You can change the line: |
||
657 | /// comboBoxMapType.ItemsSource = providerList; |
||
658 | /// to: |
||
659 | /// comboBoxMapType.ItemsSource = GMapProviders.List; |
||
660 | /// in _setupMap() |
||
661 | /// or add items here: |
||
662 | /// </summary> |
||
663 | List<GMap.NET.MapProviders.GMapProvider> providerList = new List<GMap.NET.MapProviders.GMapProvider> |
||
664 | { GMap.NET.MapProviders.GMapProviders.OpenCycleMap, GMap.NET.MapProviders.GMapProviders.OpenCycleLandscapeMap, GMap.NET.MapProviders.GMapProviders.OpenCycleTransportMap, |
||
665 | GMap.NET.MapProviders.GMapProviders.BingMap,GMap.NET.MapProviders.GMapProviders.BingSatelliteMap,GMap.NET.MapProviders.GMapProviders.BingHybridMap, |
||
666 | GMap.NET.MapProviders.GMapProviders.GoogleMap,GMap.NET.MapProviders.GMapProviders.GoogleSatelliteMap,GMap.NET.MapProviders.GMapProviders.GoogleHybridMap,GMap.NET.MapProviders.GMapProviders.GoogleTerrainMap, |
||
667 | GMap.NET.MapProviders.GMapProviders.OviMap,GMap.NET.MapProviders.GMapProviders.OviSatelliteMap,GMap.NET.MapProviders.GMapProviders.OviHybridMap,GMap.NET.MapProviders.GMapProviders.OviTerrainMap}; |
||
668 | |||
669 | private void MainMap_Loaded(object sender, RoutedEventArgs e) |
||
670 | { |
||
671 | MainMap.Manager.Mode = AccessMode.ServerAndCache; |
||
672 | copter = new GMapMarker(MainMap.Position); |
||
2318 | - | 673 | |
674 | copter.Shape = new CustomMarkerCopter(this, copter, MainMap.Position.Lat.ToString("0.#######°") + System.Environment.NewLine + MainMap.Position.Lng.ToString("0.#######°"),"red"); |
||
675 | if (comboBoxCopterColor.SelectionBoxItem != null) |
||
676 | { |
||
677 | string s = comboBoxCopterColor.SelectionBoxItem.ToString(); |
||
678 | ((CustomMarkerCopter)(copter.Shape)).setColor(s); |
||
679 | } |
||
2287 | - | 680 | copter.Offset = new System.Windows.Point(-18, -18); |
681 | copter.ZIndex = int.MaxValue; |
||
682 | MainMap.Markers.Add(copter); |
||
683 | copter.Position = MainMap.Position; |
||
684 | } |
||
2347 | - | 685 | void _setHomePos() |
2287 | - | 686 | { |
687 | pHome = MainMap.Position; |
||
688 | if (!MainMap.Markers.Contains(home)) |
||
689 | { |
||
690 | home = new GMapMarker(MainMap.Position); |
||
691 | home.Shape = new CustomMarkerHome(this, home, MainMap.Position.Lat.ToString("0.#######°") + System.Environment.NewLine + MainMap.Position.Lng.ToString("0.#######°")); |
||
692 | home.Offset = new System.Windows.Point(-18, -18); |
||
693 | // home.ZIndex = int.MaxValue; |
||
694 | MainMap.Markers.Add(home); |
||
695 | } |
||
696 | home.Position = MainMap.Position; |
||
697 | ((CustomMarkerHome)(home.Shape)).setText(MainMap.Position.Lat.ToString("0.#######°") + System.Environment.NewLine + MainMap.Position.Lng.ToString("0.#######°")); |
||
698 | } |
||
2347 | - | 699 | void _setActiveWP(int iIndex) |
2287 | - | 700 | { |
2347 | - | 701 | if (wpActiveMarker == null || !MainMap.Markers.Contains(wpActiveMarker)) |
702 | { |
||
703 | Dispatcher.Invoke(() => |
||
704 | { |
||
705 | wpActiveMarker = new GMapMarker(wpList[iIndex]); |
||
706 | wpActiveMarker.Shape = new CustomMarkerWPActive(this, wpActiveMarker, "wpActive", 0); |
||
707 | wpActiveMarker.Offset = new Point(-17.5, -17.5); |
||
708 | MainMap.Markers.Add(wpActiveMarker); |
||
709 | }); |
||
710 | } |
||
711 | else |
||
712 | Dispatcher.Invoke(() => wpActiveMarker.Position = wpList[iIndex]); |
||
713 | |||
714 | } |
||
715 | void _clearHomePos() |
||
716 | { |
||
2287 | - | 717 | MainMap.Markers.Remove(home); |
718 | } |
||
2335 | - | 719 | void _clearMapMarkers(Type markerType) |
720 | { |
||
721 | for (int k = 0; k < MainMap.Markers.Count;) |
||
722 | { |
||
723 | GMapMarker p = MainMap.Markers[k]; |
||
2340 | - | 724 | if (p.GetType() == markerType | (p.Shape != null && p.Shape.GetType() == markerType)) |
2335 | - | 725 | MainMap.Markers.Remove(p); |
726 | else |
||
727 | k++; |
||
728 | } |
||
2287 | - | 729 | |
2335 | - | 730 | } |
731 | |||
2287 | - | 732 | // access mode |
733 | private void comboBoxMode_DropDownClosed(object sender, EventArgs e) |
||
734 | { |
||
735 | MainMap.Manager.Mode = (AccessMode)comboBoxMode.SelectedItem; |
||
736 | MainMap.ReloadMap(); |
||
737 | } |
||
738 | // zoom up |
||
739 | private void czuZoomUp_Click(object sender, RoutedEventArgs e) |
||
740 | { |
||
741 | MainMap.Zoom = ((int)MainMap.Zoom) + 1; |
||
742 | } |
||
743 | |||
744 | // zoom down |
||
745 | private void czuZoomDown_Click(object sender, RoutedEventArgs e) |
||
746 | { |
||
747 | MainMap.Zoom = ((int)(MainMap.Zoom + 0.99)) - 1; |
||
748 | } |
||
749 | |||
750 | // prefetch |
||
751 | private void buttonPrefetch_Click(object sender, RoutedEventArgs e) |
||
752 | { |
||
753 | RectLatLng area = MainMap.SelectedArea; |
||
754 | if (!area.IsEmpty) |
||
755 | { |
||
756 | for (int i = (int)MainMap.Zoom; i <= MainMap.MaxZoom; i++) |
||
757 | { |
||
758 | MessageBoxResult res = MessageBox.Show("Ready ripp at Zoom = " + i + " ?", "GMap.NET", MessageBoxButton.YesNoCancel); |
||
759 | |||
760 | if (res == MessageBoxResult.Yes) |
||
761 | { |
||
762 | TilePrefetcher obj = new TilePrefetcher(); |
||
763 | obj.Owner = this; |
||
764 | obj.ShowCompleteMessage = true; |
||
765 | obj.Start(area, i, MainMap.MapProvider, 100); |
||
766 | } |
||
767 | else if (res == MessageBoxResult.No) |
||
768 | { |
||
769 | continue; |
||
770 | } |
||
771 | else if (res == MessageBoxResult.Cancel) |
||
772 | { |
||
773 | break; |
||
774 | } |
||
775 | } |
||
776 | } |
||
777 | else |
||
778 | { |
||
779 | MessageBox.Show("Select map area holding ALT", "GMap.NET", MessageBoxButton.OK, MessageBoxImage.Exclamation); |
||
780 | } |
||
781 | } |
||
782 | |||
783 | // goto by geocoder |
||
784 | private void buttonGeoCoding_Click(object sender, RoutedEventArgs e) |
||
785 | { |
||
786 | _goto_byGeoCoder(); |
||
787 | } |
||
788 | // goto by geocoder |
||
789 | private void textBoxGeo_KeyUp(object sender, System.Windows.Input.KeyEventArgs e) |
||
790 | { |
||
791 | if (e.Key == System.Windows.Input.Key.Enter) |
||
792 | _goto_byGeoCoder(); |
||
793 | } |
||
794 | void _goto_byGeoCoder() |
||
795 | { |
||
796 | GeoCoderStatusCode status = MainMap.SetPositionByKeywords(textBoxGeo.Text); |
||
797 | if (status != GeoCoderStatusCode.G_GEO_SUCCESS) |
||
798 | { |
||
799 | MessageBox.Show("Geocoder can't find: '" + textBoxGeo.Text + "', reason: " + status.ToString(), "GMap.NET", MessageBoxButton.OK, MessageBoxImage.Exclamation); |
||
800 | } |
||
801 | } |
||
802 | private void buttonGeoLoc_Click(object sender, RoutedEventArgs e) |
||
803 | { |
||
804 | try |
||
805 | { |
||
806 | double lat = double.Parse(textBoxLat.Text, System.Globalization.CultureInfo.InvariantCulture); |
||
807 | double lng = double.Parse(textBoxLng.Text, System.Globalization.CultureInfo.InvariantCulture); |
||
808 | |||
809 | MainMap.Position = new PointLatLng(lat, lng); |
||
810 | } |
||
811 | catch (Exception ex) |
||
812 | { |
||
813 | MessageBox.Show("incorrect coordinate format: " + ex.Message); |
||
814 | } |
||
815 | |||
816 | } |
||
817 | |||
818 | private void ReloadMap_Click(object sender, RoutedEventArgs e) |
||
819 | { |
||
820 | MainMap.ReloadMap(); |
||
821 | } |
||
822 | |||
823 | private void MainMap_OnPositionChanged(PointLatLng point) |
||
824 | { |
||
825 | if (_bFollowCopter) |
||
826 | _setCopterData(MainMap.Position); |
||
827 | } |
||
828 | |||
829 | private void MainMap_OnMapZoomChanged() |
||
830 | { |
||
831 | if (_bFollowCopter) |
||
832 | _setCopterData(MainMap.Position); |
||
833 | if((int)sliderMapZoom.Value != MainMap.Zoom) |
||
834 | sliderMapZoom.Value = MainMap.Zoom; |
||
835 | } |
||
836 | |||
837 | void _setCopterData(PointLatLng p) |
||
838 | { |
||
839 | Dispatcher.Invoke(() => |
||
840 | { |
||
841 | copter.Position = p; |
||
842 | ((CustomMarkerCopter)(copter.Shape)).setText(p.Lat.ToString("0.#######°") + System.Environment.NewLine + p.Lng.ToString("0.#######°")); |
||
843 | textBoxLat_currentPos.Text = p.Lat.ToString() + "°"; |
||
844 | textBoxLng_currentPos.Text = p.Lng.ToString() + "°"; |
||
845 | }); |
||
846 | if (home != null && MainMap.Markers.Contains(home)) |
||
847 | { |
||
848 | Dispatcher.Invoke(() => ArtHor.rotateHome = GMapProviders.EmptyProvider.Projection.GetBearing(copter.Position, home.Position)); |
||
849 | double d = GMapProviders.EmptyProvider.Projection.GetDistance(home.Position, copter.Position); |
||
850 | Dispatcher.Invoke(() => tbTopDistanceHP.Text = (d * 1000).ToString("0.0 m")); |
||
2291 | - | 851 | |
852 | if(d*1000 < _dThresholdDistanceWarn) |
||
853 | { |
||
854 | _iDistanceJitter = 0; _bVoiceDistanceActive = false; |
||
855 | if (stbDistanceWarnAnim != null && _bAnimDistanceActive) |
||
856 | { |
||
857 | Dispatcher.Invoke(() => stbDistanceWarnAnim.Stop()); |
||
858 | _bAnimDistanceActive = false; |
||
859 | } |
||
860 | } |
||
861 | else |
||
862 | { |
||
863 | if (_iDistanceJitter < 20) |
||
864 | { _iDistanceJitter++; } |
||
865 | if (_iDistanceJitter == 20) |
||
866 | { |
||
867 | if (stbDistanceWarnAnim != null && !_bAnimDistanceActive) |
||
868 | { |
||
869 | Dispatcher.Invoke(() => stbDistanceWarnAnim.Begin()); |
||
870 | _bAnimDistanceActive = true; |
||
871 | } |
||
872 | if (_bVoiceDistancePlay && !_bVoiceDistanceActive) |
||
873 | { |
||
2295 | - | 874 | Thread t = new Thread(()=>_mediaPlayer("Voice\\Distance.mp3")); |
875 | t.Start(); |
||
2291 | - | 876 | _bVoiceDistanceActive = true; |
877 | } |
||
878 | _iDistanceJitter++; |
||
879 | } |
||
880 | } |
||
2287 | - | 881 | } |
882 | } |
||
883 | |||
884 | private void checkBoxFollowCopter_Click(object sender, RoutedEventArgs e) |
||
885 | { |
||
886 | _bFollowCopter = (bool)checkBoxFollowCopter.IsChecked; |
||
887 | } |
||
888 | |||
889 | private void sliderMapZoom_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) |
||
890 | { |
||
891 | if (MainMap.Zoom != sliderMapZoom.Value) |
||
892 | MainMap.Zoom = (int)sliderMapZoom.Value; |
||
893 | } |
||
894 | #region Touch zooming hackattack ;) |
||
895 | /// <summary> |
||
896 | /// inspired by http://www.codeproject.com/Articles/692286/WPF-and-multi-touch |
||
897 | /// </summary> |
||
898 | bool bFirstAccess = true; |
||
899 | double dDistance = 0; |
||
900 | int iZoom; |
||
901 | private void MainMap_StylusDown(object sender, StylusDownEventArgs e) |
||
902 | { |
||
903 | var id = e.StylusDevice.Id; |
||
904 | e.StylusDevice.Capture(MainMap); |
||
905 | if (iFirstStylusID == -1) |
||
906 | { |
||
907 | iFirstStylusID = id; |
||
908 | } |
||
909 | else |
||
910 | { |
||
911 | |||
912 | MainMap.CanDragMap = false; |
||
913 | } |
||
914 | } |
||
915 | private void MainMap_StylusUp(object sender, StylusEventArgs e) |
||
916 | { |
||
917 | MainMap.ReleaseStylusCapture(); |
||
918 | iFirstStylusID = -1; |
||
919 | bFirstAccess = true; |
||
920 | MainMap.CanDragMap = true; |
||
921 | iZoom = 0; |
||
922 | } |
||
923 | private void MainMap_StylusMove(object sender, StylusEventArgs e) |
||
924 | { |
||
925 | var id = e.StylusDevice.Id; |
||
926 | var tp = e.GetPosition(MainMap); |
||
927 | |||
928 | // This is the first Stylus point; just record its position. |
||
929 | if (id == iFirstStylusID) |
||
930 | { |
||
931 | pTouch1.X = tp.X; |
||
932 | pTouch1.Y = tp.Y; |
||
933 | } |
||
934 | else |
||
935 | if (iFirstStylusID > -1) |
||
936 | { |
||
937 | pTouch2.X = tp.X; |
||
938 | pTouch2.Y = tp.Y; |
||
939 | double distance = Point.Subtract(pTouch1, pTouch2).Length; |
||
940 | if (!bFirstAccess) |
||
941 | { |
||
942 | if (distance > dDistance) |
||
943 | iZoom++; |
||
944 | else |
||
945 | if (distance < dDistance) |
||
946 | iZoom--; |
||
947 | } |
||
948 | if (iZoom > 30) |
||
949 | { |
||
950 | iZoom = 0; |
||
951 | Dispatcher.Invoke(() => sliderMapZoom.Value += 1); |
||
952 | } |
||
953 | if (iZoom < -30) |
||
954 | { |
||
955 | iZoom = 0; |
||
956 | Dispatcher.Invoke(() => sliderMapZoom.Value -= 1); |
||
957 | } |
||
958 | dDistance = distance; |
||
959 | bFirstAccess = false; |
||
960 | } |
||
961 | } |
||
962 | #endregion Touch zooming hackattack ;) |
||
963 | |||
964 | #endregion GMap |
||
965 | |||
966 | #region settings |
||
967 | private void cBoxTimingsDebug_DropDownClosed(object sender, EventArgs e) |
||
968 | { |
||
969 | if(! _bCBInit && cBoxTimingsDebug.SelectedIndex > -1) |
||
970 | debugInterval = (byte)(Convert.ToInt16(cBoxTimingsDebug.SelectedItem) / 10); |
||
971 | } |
||
972 | private void cBoxTimingsNav_DropDownClosed(object sender, EventArgs e) |
||
973 | { |
||
974 | if(! _bCBInit && cBoxTimingsNav.SelectedIndex > -1) |
||
975 | navctrlInterval = (byte)(Convert.ToInt16(cBoxTimingsNav.SelectedItem) / 10); |
||
976 | } |
||
977 | private void cBoxTimingsBl_DropDownClosed(object sender, EventArgs e) |
||
978 | { |
||
979 | if (!_bCBInit && cBoxTimingsBl.SelectedIndex > -1) |
||
980 | blctrlInterval = (byte)(Convert.ToInt16(cBoxTimingsBl.SelectedItem) / 10); |
||
981 | } |
||
982 | private void cBoxTimingsOSD_DropDownClosed(object sender, EventArgs e) |
||
983 | { |
||
984 | if (!_bCBInit && cBoxTimingsOSD.SelectedIndex > -1) |
||
985 | OSDInterval = (byte)(Convert.ToInt16(cBoxTimingsOSD.SelectedItem) / 10); |
||
986 | } |
||
987 | private void chkbAutoDbg_Click(object sender, RoutedEventArgs e) |
||
988 | { |
||
989 | if (!_init) _debugDataAutorefresh = (bool)chkbAutoDbg.IsChecked; |
||
990 | } |
||
991 | private void chkbAutoNav_Click(object sender, RoutedEventArgs e) |
||
992 | { |
||
993 | if (!_init) _navCtrlDataAutorefresh = (bool)chkbAutoNav.IsChecked; |
||
994 | } |
||
995 | private void chkbAutoBL_Click(object sender, RoutedEventArgs e) |
||
996 | { |
||
997 | if (!_init) _blctrlDataAutorefresh = (bool)chkbAutoBL.IsChecked; |
||
998 | } |
||
999 | private void chkbAutoOSD_Click(object sender, RoutedEventArgs e) |
||
1000 | { |
||
1001 | if (!_init) _OSDAutorefresh = (bool)chkbAutoOSD.IsChecked; |
||
1002 | } |
||
1003 | |||
1004 | private void cBoxLiPoCells_DropDownClosed(object sender, EventArgs e) |
||
1005 | { |
||
1006 | if (cBoxLiPoCells.SelectedIndex > -1) |
||
1007 | { |
||
1008 | _LipoCells = cBoxLiPoCells.SelectedIndex + 3; |
||
1009 | _LipoMinMax(); |
||
1010 | } |
||
1011 | } |
||
1012 | void _LipoMinMax() |
||
1013 | { |
||
1014 | _dLipoVMax = (double)(_LipoCells) * 4.22; |
||
1015 | _dLipoVMin = (double)_LipoCells * 3; |
||
1016 | pbTopVoltage.Maximum = _dLipoVMax; |
||
1017 | pbTopVoltage.Minimum = _dLipoVMin; |
||
1018 | sliderThresholdVoltageWarn.Maximum = _dLipoVMax; |
||
1019 | sliderThresholdVoltageWarn.Minimum = _dLipoVMin; |
||
1020 | } |
||
1021 | private void cBoxMotors_DropDownClosed(object sender, EventArgs e) |
||
1022 | { |
||
1023 | if (cBoxMotors.SelectedIndex > -1) |
||
1024 | { |
||
1025 | _iMotors = cBoxMotors.SelectedIndex + 3; |
||
1026 | Dispatcher.Invoke(() => |
||
1027 | { |
||
1028 | dgvMotors1.Height = (272 / 12.6) * (_iMotors + 1); //272 / 12.6 --> Workaround, cause the headerheight = NaN...? |
||
1029 | GridMotors.Height = dgvMotors1.Height + 10; |
||
1030 | }); |
||
1031 | } |
||
1032 | } |
||
1033 | void _setMotorGridSize() |
||
1034 | { |
||
1035 | if (dgvMotors1.Columns.Count > 2) |
||
1036 | { |
||
1037 | dgvMotors1.Columns[0].Width = 24; |
||
1038 | dgvMotors1.Columns[1].Width = 50; |
||
1039 | dgvMotors1.Columns[2].Width = 50; |
||
1040 | dgvMotors1.Height = (272 / 12.6) * (_iMotors + 1); |
||
1041 | GridMotors.Height = dgvMotors1.Height + 10; |
||
1042 | } |
||
1043 | |||
1044 | } |
||
1045 | #endregion settings |
||
1046 | |||
1047 | #region functions |
||
1048 | |||
1049 | #region logging |
||
1050 | /// <summary> Log data to the terminal window. </summary> |
||
1051 | /// <param name="msgtype"> The type of message to be written. </param> |
||
1052 | /// <param name="msg"> The string containing the message to be shown. </param> |
||
1053 | private void Log(LogMsgType msgtype, string msg) |
||
1054 | { |
||
1055 | Dispatcher.Invoke(() => |
||
1056 | { |
||
1057 | // rtfTerminal.CaretPosition = rtfTerminal.CaretPosition.DocumentEnd; |
||
1058 | // rtfTerminal.Foreground = new SolidColorBrush(LogMsgTypeColor[(int)msgtype]); |
||
1059 | // rtfTerminal.AppendText(msg + "\r"); |
||
1060 | TextRange tr = new TextRange(rtfTerminal.Document.ContentEnd,rtfTerminal.Document.ContentEnd); |
||
1061 | tr.Text = msg; |
||
1062 | tr.ApplyPropertyValue(TextElement.ForegroundProperty, new SolidColorBrush(LogMsgTypeColor[(int)msgtype])); |
||
1063 | rtfTerminal.AppendText("\r"); |
||
1064 | rtfTerminal.ScrollToEnd(); |
||
1065 | }); |
||
1066 | } |
||
1067 | private void ErrorLog(LogMsgType msgtype, string msg) |
||
1068 | { |
||
1069 | Dispatcher.Invoke(() => |
||
1070 | { |
||
1071 | TextRange tr = new TextRange(rtfError.Document.ContentEnd, rtfError.Document.ContentEnd); |
||
1072 | tr.Text = msg; |
||
1073 | tr.ApplyPropertyValue(TextElement.ForegroundProperty, new SolidColorBrush(LogMsgTypeColor[(int)msgtype])); |
||
1074 | rtfError.AppendText("\r"); |
||
1075 | rtfError.ScrollToEnd(); |
||
1076 | |||
1077 | _bErrorLog = true; |
||
1078 | }); |
||
1079 | } |
||
1080 | /// <summary> |
||
1081 | /// Clear the line in the errorlog window |
||
1082 | /// containing the error string when error has ceased |
||
1083 | /// </summary> |
||
1084 | /// <param name="s">substring of errrormessage</param> |
||
1085 | void _clearErrorLog(string s) |
||
1086 | { |
||
1087 | Dispatcher.Invoke((Action)(() => |
||
1088 | { |
||
1089 | TextRange searchRange = new TextRange(rtfError.Document.ContentStart, rtfError.Document.ContentEnd); |
||
1090 | TextRange foundRange = FindTextInRange(searchRange, s); |
||
1091 | |||
1092 | int iStart = searchRange.Text.IndexOf(s, StringComparison.OrdinalIgnoreCase); |
||
1093 | |||
1094 | |||
1095 | if (iStart > -1) |
||
1096 | { |
||
1097 | int iLength = 0; |
||
1098 | int iEnd = searchRange.Text.IndexOf('\r', iStart); |
||
1099 | if (iEnd > 0) |
||
1100 | { |
||
1101 | iLength = iEnd + 1; |
||
1102 | int iHttp = searchRange.Text.IndexOf("http", iEnd); |
||
1103 | if (iHttp == iLength) |
||
1104 | { |
||
1105 | int iEnd2 = searchRange.Text.IndexOf('\r', iLength); |
||
1106 | if (iEnd2 > iLength) |
||
1107 | { |
||
1108 | iLength = iEnd2 + 1; |
||
1109 | // TextRange result = new TextRange(rtfError.Document.ContentStart.GetPositionAtOffset(iStart), GetTextPositionAtOffset(rtfError.Document.ContentStart.GetPositionAtOffset(iStart), iLength)); |
||
1110 | |||
1111 | rtfError.Selection.Select(rtfError.Document.ContentStart.GetPositionAtOffset(iStart), GetTextPositionAtOffset(rtfError.Document.ContentStart.GetPositionAtOffset(iStart), iLength)); |
||
1112 | rtfError.Selection.Text = string.Empty; |
||
1113 | if (rtfError.Document.ContentEnd.GetTextRunLength(LogicalDirection.Backward) < 2) _bErrorLog = false; |
||
1114 | } |
||
1115 | |||
1116 | } |
||
1117 | else |
||
1118 | { |
||
1119 | rtfError.Selection.Select(rtfError.Document.ContentStart.GetPositionAtOffset(iStart), GetTextPositionAtOffset(rtfError.Document.ContentStart.GetPositionAtOffset(iStart), iLength)); |
||
1120 | rtfError.Selection.Text = string.Empty; |
||
1121 | if (rtfError.Document.ContentEnd.GetTextRunLength(LogicalDirection.Backward) < 2) _bErrorLog = false; |
||
1122 | } |
||
1123 | } |
||
1124 | } |
||
1125 | })); |
||
1126 | |||
1127 | } |
||
1128 | public TextRange FindTextInRange(TextRange searchRange, string searchText) |
||
1129 | { |
||
1130 | int offset = searchRange.Text.IndexOf(searchText, StringComparison.OrdinalIgnoreCase); |
||
1131 | if (offset < 0) |
||
1132 | return null; // Not found |
||
1133 | |||
1134 | var start = GetTextPositionAtOffset(searchRange.Start, offset); |
||
1135 | TextRange result = new TextRange(start, GetTextPositionAtOffset(start, searchText.Length)); |
||
1136 | |||
1137 | return result; |
||
1138 | } |
||
1139 | TextPointer GetTextPositionAtOffset(TextPointer position, int characterCount) |
||
1140 | { |
||
1141 | while (position != null) |
||
1142 | { |
||
1143 | if (position.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.Text) |
||
1144 | { |
||
1145 | int count = position.GetTextRunLength(LogicalDirection.Forward); |
||
1146 | if (characterCount <= count) |
||
1147 | { |
||
1148 | return position.GetPositionAtOffset(characterCount); |
||
1149 | } |
||
1150 | |||
1151 | characterCount -= count; |
||
1152 | } |
||
1153 | |||
1154 | TextPointer nextContextPosition = position.GetNextContextPosition(LogicalDirection.Forward); |
||
1155 | if (nextContextPosition == null) |
||
1156 | return position; |
||
1157 | |||
1158 | position = nextContextPosition; |
||
1159 | } |
||
1160 | |||
1161 | return position; |
||
1162 | } |
||
1163 | #endregion logging |
||
1164 | |||
1165 | #region processing received data |
||
1166 | |||
1167 | private void processMessage(byte[] message) |
||
1168 | { |
||
1169 | if (message.Length > 0) |
||
1170 | { |
||
1171 | _iLifeCounter++; |
||
1172 | //Log(LogMsgType.Incoming, BitConverter.ToString(message)); |
||
1173 | //Log(LogMsgType.Incoming, message.Length.ToString()); |
||
1174 | string s = new string(ASCIIEncoding.ASCII.GetChars(message, 0, message.Length)); |
||
1175 | char cmdID; |
||
1176 | byte adr; |
||
1177 | byte[] data; |
||
1178 | byte[] tmp = null; |
||
1179 | if (message[0] != '#') |
||
1180 | { |
||
1181 | int iFound = -1; |
||
1182 | for (int i = 0; i < message.Length; i++) //Sometimes the FC/NC sends strings without termination (like WP messages) |
||
1183 | { //so this is a workaround to not spam the log box |
||
1184 | if (message[i] == 35) |
||
1185 | { |
||
1186 | iFound = i; |
||
1187 | break; |
||
1188 | } |
||
1189 | } |
||
1190 | if (iFound > 0) |
||
1191 | { |
||
1192 | s = new string(ASCIIEncoding.ASCII.GetChars(message, 0, iFound)); |
||
1193 | tmp = new byte[message.Length - iFound]; |
||
1194 | Buffer.BlockCopy(message, iFound, tmp, 0, message.Length - iFound); |
||
1195 | } |
||
1196 | s = s.Trim('\0', '\n', '\r'); |
||
1197 | if (s.Length > 0) |
||
1198 | Log(LogMsgType.Normal, s); |
||
1199 | if (tmp != null) |
||
1200 | { |
||
1201 | s = new string(ASCIIEncoding.ASCII.GetChars(tmp, 0, tmp.Length)); |
||
1202 | processMessage(tmp); |
||
1203 | } |
||
1204 | } |
||
1205 | //Debug.Print(s); |
||
1206 | else |
||
1207 | { |
||
1208 | FlightControllerMessage.ParseMessage(message, out cmdID, out adr, out data); |
||
1209 | |||
1210 | if (adr == 255) { crcError++; } |
||
1211 | else crcError = 0; |
||
1212 | Dispatcher.Invoke(() => tbCrc.Text = crcError.ToString()); |
||
1213 | //display the active controller (FC / NC) |
||
1214 | if (adr > 0 && adr < 3 && adr != _iCtrlAct) //adr < 3: temporary workaround cause when I've connected the FC alone it always switches between mk3mag & FC every second...??? |
||
1215 | { |
||
1216 | _iCtrlAct = adr; |
||
1217 | switch (adr) |
||
1218 | { |
||
1219 | case 1: |
||
1220 | Dispatcher.Invoke(() => tbCtrl.Text = "FC"); |
||
2298 | - | 1221 | Dispatcher.Invoke(() => buttonSwitchNC.Visibility = Visibility.Visible); |
2287 | - | 1222 | //Dispatcher.Invoke(() => labelSwitchToNavi.Visibility = Visibility.Visible); |
1223 | // _setFieldsNA(); //display fields NA for FC |
||
1224 | break; |
||
1225 | case 2: |
||
1226 | Dispatcher.Invoke(() => tbCtrl.Text = "NC"); |
||
1227 | //Dispatcher.Invoke(() => buttonSwitchNC.Visibility = Visibility.Hidden); |
||
1228 | //Dispatcher.Invoke(() => labelSwitchToNavi.Visibility = Visibility.Hidden); |
||
1229 | break; |
||
1230 | //case 3: |
||
1231 | // lblCtrl.Invoke((Action)(() => lblCtrl.Text = "MK3MAG")); |
||
1232 | // break; |
||
1233 | //case 4: |
||
1234 | // lblCtrl.Invoke((Action)(() => lblCtrl.Text = "BL-CTRL")); |
||
1235 | // break; |
||
1236 | default: |
||
1237 | Dispatcher.Invoke(() => tbCtrl.Text = "NA"); |
||
1238 | break; |
||
1239 | } |
||
1240 | // _loadLabelNames(); |
||
1241 | } |
||
1242 | // else |
||
1243 | // Debug.Print("Address == 0?"); |
||
1244 | |||
1245 | if (data != null && data.Length > 0) |
||
1246 | { |
||
1247 | s = new string(ASCIIEncoding.ASCII.GetChars(data, 1, data.Length - 1)); |
||
1248 | s = s.Trim('\0', '\n'); |
||
1249 | |||
1250 | switch (cmdID) |
||
1251 | { |
||
1252 | //case 'A': //Label names |
||
1253 | // _processLabelNames(s); |
||
1254 | // break; |
||
1255 | |||
1256 | case 'D': //Debug data |
||
1257 | _processDebugVals(adr, data); |
||
1258 | break; |
||
1259 | |||
1260 | case 'V': //Version |
||
1261 | _processVersion(adr, data); |
||
1262 | break; |
||
1263 | |||
1264 | case 'K'://BL-CTRL data |
||
1265 | _processBLCtrl(data); |
||
1266 | break; |
||
1267 | |||
1268 | case 'O': //NC Data |
||
1269 | _processNCData(data); |
||
1270 | break; |
||
1271 | |||
1272 | case 'E': //NC error-string |
||
1273 | ErrorLog(LogMsgType.Error, "NC Error: " + s); |
||
1274 | break; |
||
1275 | |||
1276 | case 'L': //OSD Menue (called by pagenumber) |
||
1277 | _processOSDSingle(data); |
||
1278 | break; |
||
1279 | |||
1280 | case 'H': //OSD Menue (with autoupdate - called by Key) |
||
1281 | _processOSDAuto(data); |
||
1282 | break; |
||
1283 | |||
1284 | case 'X': //Waypoint data |
||
1285 | _processWPData(data); |
||
1286 | break; |
||
1287 | |||
2313 | - | 1288 | case 'W': //return new Waypoint items count after sending waypoint to copter |
1289 | _iWPCount = data[0]; |
||
1290 | break; |
||
2287 | - | 1291 | //default: |
1292 | // Log(LogMsgType.Incoming, "cmd: " + cmdID.ToString()); |
||
1293 | // Log(LogMsgType.Incoming, BitConverter.ToString(data)); |
||
1294 | // break; |
||
1295 | } |
||
1296 | } |
||
1297 | //else |
||
1298 | //{ |
||
1299 | // Log(LogMsgType.Incoming, "cmd: " + cmdID.ToString()); |
||
1300 | // Log(LogMsgType.Incoming, BitConverter.ToString(data)); |
||
1301 | //} |
||
1302 | } |
||
1303 | } |
||
1304 | } |
||
1305 | /// <summary> |
||
1306 | /// Analog label names 'A' |
||
1307 | /// each label name is returned as a single string |
||
1308 | /// and added to string array sAnalogLabel[] |
||
1309 | /// and the datatable dtAnalog |
||
1310 | /// </summary> |
||
1311 | /// <param name="s">the label name</param> |
||
1312 | void _processLabelNames(string s) |
||
1313 | { |
||
1314 | //if (iLableIndex < 32) |
||
1315 | //{ |
||
1316 | // sAnalogLabel[iLableIndex] = s; |
||
1317 | // if (dtAnalog.Rows.Count < 32) |
||
1318 | // dtAnalog.Rows.Add(s, ""); |
||
1319 | // else |
||
1320 | // dtAnalog.Rows[iLableIndex].SetField(0, s); |
||
1321 | |||
1322 | // // _getAnalogLabels(iLableIndex + 1); |
||
1323 | //} |
||
1324 | //Debug.Print(s); |
||
1325 | } |
||
1326 | /// <summary> |
||
1327 | /// Debug values 'D' |
||
1328 | /// </summary> |
||
1329 | /// <param name="adr">adress of the active controller (1-FC, 2-NC)</param> |
||
1330 | /// <param name="data">the received byte array to process</param> |
||
1331 | void _processDebugVals(byte adr, byte[] data) |
||
1332 | { |
||
1333 | if (data.Length == 66) |
||
1334 | { |
||
2324 | - | 1335 | |
2287 | - | 1336 | double v; |
1337 | int index = 0; |
||
1338 | Int16 i16 = 0; |
||
1339 | double dTemp = 0; |
||
1340 | for (int i = 2; i < 66; i += 2) |
||
1341 | { |
||
1342 | i16 = data[i + 1]; |
||
1343 | i16 = (Int16)(i16 << 8); |
||
1344 | iAnalogData[index] = data[i] + i16; |
||
1345 | sAnalogData[index] = (data[i] + i16).ToString(); |
||
1346 | // dtAnalog.Rows[index].SetField(1, sAnalogData[index]); |
||
1347 | |||
1348 | if (adr == 2) //NC |
||
1349 | { |
||
1350 | switch (index) |
||
1351 | { |
||
1352 | case 0: //pitch (German: nick) |
||
1353 | Dispatcher.Invoke(() => ArtHor.Pitch = ((double)iAnalogData[index] / (double)10)); |
||
1354 | Dispatcher.Invoke((Action)(() => tbPitch.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0°"))); |
||
1355 | break; |
||
1356 | case 1: //roll |
||
1357 | Dispatcher.Invoke(() => ArtHor.Roll = ((double)iAnalogData[index] / (double)10)); |
||
1358 | Dispatcher.Invoke((Action)(() => tbRoll.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0°"))); |
||
1359 | break; |
||
1360 | case 4: //altitude |
||
1361 | Dispatcher.Invoke(() => tbAlt.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0 m")); |
||
1362 | Dispatcher.Invoke(() => tbTopHeight.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0 m")); |
||
2324 | - | 1363 | Dispatcher.Invoke(() => { drGPX[3] = (double)iAnalogData[index] / (double)10; }); |
2287 | - | 1364 | break; |
1365 | case 7: //Voltage |
||
1366 | v = (double)iAnalogData[index] / (double)10; |
||
1367 | Dispatcher.Invoke(() => tbVolt.Text = v.ToString("0.0 V")); |
||
1368 | Dispatcher.Invoke(() => tbTopVoltage.Text = v.ToString("0.0 V")); |
||
1369 | Dispatcher.Invoke(() => pbTopVoltage.Value = v); |
||
1370 | if (v - _dLipoVMin < 1 | v < _dThresholdVoltageWarn) |
||
1371 | { |
||
1372 | if (v == _dVoltLast) |
||
1373 | if(_iVoltJitter < 20) _iVoltJitter++; |
||
1374 | else |
||
1375 | { |
||
1376 | _iVoltJitter = 0; |
||
1377 | _dVoltLast = v; |
||
1378 | } |
||
1379 | if (_iVoltJitter == 20) |
||
1380 | { |
||
1381 | Dispatcher.Invoke(() => pbTopVoltage.Foreground = Brushes.Orange); |
||
1382 | |||
1383 | if (v - _dLipoVMin < 1 | v < _dThresholdVoltageCrit) |
||
1384 | { |
||
1385 | Dispatcher.Invoke(() => pbTopVoltage.Foreground = Brushes.Red); |
||
1386 | if (stbVoltageCritAnim != null && !_bCritAnimVoltActive) |
||
1387 | { |
||
1388 | Dispatcher.Invoke(() => stbVoltageCritAnim.Begin()); |
||
1389 | _bCritAnimVoltActive = true; |
||
1390 | } |
||
1391 | if (_bVoiceVoltPlay && !_bCritVoiceVoltActive) |
||
1392 | { |
||
2295 | - | 1393 | Thread t = new Thread(() => _mediaPlayer("Voice\\CriticalBattery.mp3")); |
1394 | t.Start(); |
||
2287 | - | 1395 | _bCritVoiceVoltActive = true; |
1396 | } |
||
1397 | } |
||
1398 | else |
||
1399 | { |
||
1400 | if (stbVoltageCritAnim != null && _bCritAnimVoltActive) |
||
1401 | { |
||
1402 | Dispatcher.Invoke(() => stbVoltageCritAnim.Stop()); |
||
1403 | _bCritAnimVoltActive = false; |
||
1404 | } |
||
1405 | _bCritVoiceVoltActive = false; |
||
1406 | |||
2291 | - | 1407 | if (_bVoiceVoltPlay && !_bWarnVoiceVoltActive) |
2287 | - | 1408 | { |
2295 | - | 1409 | Thread t = new Thread(() => _mediaPlayer("Voice\\LowBattery.mp3")); |
1410 | t.Start(); |
||
2291 | - | 1411 | _bWarnVoiceVoltActive = true; |
2287 | - | 1412 | } |
1413 | } |
||
1414 | } |
||
1415 | } |
||
1416 | else |
||
1417 | { |
||
1418 | Dispatcher.Invoke(() => pbTopVoltage.Foreground = new SolidColorBrush(Color.FromArgb(255, 107, 195, 123))); |
||
1419 | if (stbVoltageCritAnim != null && _bCritAnimVoltActive) |
||
1420 | { |
||
1421 | Dispatcher.Invoke(() => stbVoltageCritAnim.Stop()); |
||
1422 | _bCritAnimVoltActive = false; |
||
1423 | } |
||
1424 | _bCritVoiceVoltActive = false; |
||
2291 | - | 1425 | _bWarnVoiceVoltActive = false; |
2287 | - | 1426 | _iVoltJitter = 0; |
1427 | } |
||
1428 | break; |
||
1429 | case 8: // Current |
||
1430 | Dispatcher.Invoke(() => tbCur.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0 A")); |
||
1431 | Dispatcher.Invoke(() => tbTopCurrent.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0 A")); |
||
1432 | break; |
||
1433 | case 10: //heading |
||
2291 | - | 1434 | Dispatcher.Invoke((Action)(() => tbHeading.Text = sAnalogData[index] + "°")); |
2287 | - | 1435 | Dispatcher.Invoke(() => ArtHor.rotate = iAnalogData[index]); |
1436 | break; |
||
1437 | case 12: // SPI error |
||
2291 | - | 1438 | Dispatcher.Invoke((Action)(() => tbSPI.Text = sAnalogData[index])); |
2287 | - | 1439 | break; |
1440 | case 14: //i2c error |
||
2291 | - | 1441 | Dispatcher.Invoke((Action)(() => tbI2C.Text = sAnalogData[index])); |
2287 | - | 1442 | break; |
1443 | case 20: //Earthmagnet field |
||
2291 | - | 1444 | Dispatcher.Invoke((Action)(() => tbMagF.Text = sAnalogData[index] + "%")); |
1445 | Dispatcher.Invoke((Action)(() => tbTopEarthMag.Text = sAnalogData[index] + "%")); |
||
1446 | |||
1447 | if (Math.Abs(100 - iAnalogData[index]) < _iThresholdMagField) |
||
1448 | { |
||
1449 | Dispatcher.Invoke(() => imageEarthMag.Source = new BitmapImage(new Uri("Images/EarthMag.png", UriKind.Relative))); |
||
1450 | _iMagneticFieldJitter = 0; _bVoiceMagneticFieldActive = false; |
||
1451 | if (stbMagneticFieldAnim != null && _bAnimMagneticFieldActive) |
||
1452 | { |
||
1453 | Dispatcher.Invoke(() => stbMagneticFieldAnim.Stop()); |
||
1454 | _bAnimMagneticFieldActive = false; |
||
1455 | } |
||
1456 | } |
||
1457 | else |
||
1458 | { |
||
1459 | Dispatcher.Invoke(() => imageEarthMag.Source = new BitmapImage(new Uri("Images/EarthMag_R.png", UriKind.Relative))); |
||
1460 | if(_iMagneticFieldLast >= Math.Abs(100 - iAnalogData[index])) |
||
1461 | { |
||
1462 | if (_iMagneticFieldJitter < 20) |
||
1463 | _iMagneticFieldJitter++; |
||
1464 | } |
||
1465 | else |
||
1466 | { |
||
1467 | _iMagneticFieldJitter = 0; |
||
1468 | _iMagneticFieldLast = Math.Abs(100 - iAnalogData[index]); |
||
1469 | } |
||
1470 | if(_iMagneticFieldJitter == 20) |
||
1471 | { |
||
1472 | if (stbMagneticFieldAnim != null && !_bAnimMagneticFieldActive) |
||
1473 | { |
||
1474 | Dispatcher.Invoke(() => stbMagneticFieldAnim.Begin()); |
||
1475 | _bAnimMagneticFieldActive = true; |
||
1476 | } |
||
1477 | if (_bVoiceMagneticFieldPlay && !_bVoiceMagneticFieldActive) |
||
1478 | { |
||
2295 | - | 1479 | Thread t = new Thread(() => _mediaPlayer("Voice\\MagneticField.mp3")); |
1480 | t.Start(); |
||
2291 | - | 1481 | _bVoiceMagneticFieldActive = true; |
1482 | } |
||
1483 | } |
||
1484 | } |
||
2287 | - | 1485 | break; |
1486 | case 21: //GroundSpeed |
||
1487 | Dispatcher.Invoke((Action)(() => tbSpeed.Text = ((double)iAnalogData[index] / (double)100).ToString("0.00 m/s"))); |
||
1488 | Dispatcher.Invoke((Action)(() => tbTopSpeed.Text = ((double)iAnalogData[index] / (double)100).ToString("0.00 m/s"))); |
||
1489 | break; |
||
2291 | - | 1490 | |
1491 | ///********** needs testing --> not sure what position this is *************** |
||
2287 | - | 1492 | case 28: //Distance East from saved home position -> calculate distance with distance N + height |
1493 | dTemp = Math.Pow((double)iAnalogData[index], 2) + Math.Pow((double)iAnalogData[index - 1], 2); |
||
1494 | dTemp = Math.Sqrt(dTemp) / (double)10; //'flat' distance from HP with N/E |
||
1495 | // lblNCDist.Invoke((Action)(() => lblNCDist.Text = dTemp.ToString("0.00"))); |
||
1496 | dTemp = Math.Pow(dTemp, 2) + Math.Pow(((double)iAnalogData[4] / (double)10), 2); //adding 'height' into calculation |
||
1497 | dTemp = Math.Sqrt(dTemp) / (double)10; |
||
1498 | // Dispatcher.Invoke((Action)(() => tbTopDistanceHP.Text = dTemp.ToString("0.0 m"))); |
||
1499 | Dispatcher.Invoke((Action)(() => tbHP1.Text = dTemp.ToString("0.0 m"))); |
||
1500 | break; |
||
2291 | - | 1501 | |
2287 | - | 1502 | case 31: //Sats used |
1503 | Dispatcher.Invoke((Action)(() => tbSats.Text = sAnalogData[index])); |
||
1504 | // Dispatcher.Invoke((Action)(() => tbTopSats.Text = sAnalogData[index])); |
||
1505 | break; |
||
1506 | } |
||
1507 | } |
||
1508 | index++; |
||
1509 | } |
||
1510 | } |
||
1511 | else |
||
1512 | Debug.Print("wrong data-length (66): " + data.Length.ToString()); |
||
1513 | } |
||
1514 | /// <summary> |
||
1515 | /// Version string 'V' |
||
1516 | /// </summary> |
||
1517 | /// <param name="adr">adress of the active controller (1-FC, 2-NC)</param> |
||
1518 | /// <param name="data">the received byte array to process</param> |
||
1519 | void _processVersion(byte adr, byte[] data) |
||
1520 | { |
||
1521 | if (data.Length == 12) |
||
1522 | { |
||
1523 | if (!check_HWError) |
||
1524 | { |
||
1525 | string[] sVersionStruct = new string[10] { "SWMajor: ", "SWMinor: ", "ProtoMajor: ", "LabelTextCRC: ", "SWPatch: ", "HardwareError 1: ", "HardwareError 2: ", "HWMajor: ", "BL_Firmware: ", "Flags: " }; |
||
1526 | string sVersion = ""; |
||
1527 | //sbyte[] signed = Array.ConvertAll(data, b => unchecked((sbyte)b)); |
||
1528 | Log(LogMsgType.Warning, (adr == 1 ? "FC-" : "NC-") + "Version: "); |
||
1529 | sVersion = "HW V" + (data[7] / 10).ToString() + "." + (data[7] % 10).ToString(); |
||
1530 | Log(LogMsgType.Incoming, sVersion); |
||
1531 | sVersion = "SW V" + (data[0]).ToString() + "." + (data[1]).ToString() + ((char)(data[4] + 'a')).ToString(); |
||
1532 | Log(LogMsgType.Incoming, sVersion); |
||
1533 | Log(LogMsgType.Incoming, "BL-Firmware: V" + (data[8] / 100).ToString() + "." + (data[8] % 100).ToString()); |
||
1534 | } |
||
1535 | if (data[5] > 0) //error0 |
||
1536 | { |
||
1537 | if (adr == 1) |
||
1538 | ErrorLog(LogMsgType.Error, "FC - HW-Error " + data[5].ToString() + ": " + ((FC_HWError0)data[5]).ToString()); |
||
1539 | if (adr == 2) |
||
1540 | ErrorLog(LogMsgType.Error, "NC - HW-Error " + data[5].ToString() + ": " + ((NC_HWError0)data[5]).ToString()); |
||
1541 | } |
||
1542 | if (data[6] > 0) //error1 |
||
1543 | { |
||
1544 | if (adr == 1) |
||
1545 | ErrorLog(LogMsgType.Error, "FC - HW-Error " + data[6].ToString() + ": " + ((FC_HWError1)data[6]).ToString()); |
||
1546 | if (adr == 2) |
||
1547 | ErrorLog(LogMsgType.Error, "NC - Unknown HW-ERROR: " + data[6].ToString()); //@moment NC has only one error field |
||
1548 | } |
||
1549 | if ((data[5] + data[6] == 0) && _bErrorLog) |
||
1550 | _clearErrorLog(adr == 1 ? "FC - HW-Error" : "NC - HW-Error"); |
||
1551 | |||
1552 | } |
||
1553 | check_HWError = false; |
||
1554 | } |
||
1555 | /// <summary> |
||
1556 | /// BL-Ctrl data 'K' |
||
1557 | /// for FC you have to use a customized firmware |
||
1558 | /// </summary> |
||
1559 | /// <param name="data">the received byte array to process</param> |
||
1560 | void _processBLCtrl(byte[] data) |
||
1561 | { |
||
1562 | if (data.Length % 6 == 0) //data.Length up to 96 (16 motors x 6 byte data) --> new datastruct in FC -> not standard! |
||
1563 | { |
||
1564 | bool bAvailable = false; |
||
1565 | for (int i = 0; i < data.Length && data[i] < _iMotors; i += 6) // data[i] < _iMotors -- only show set number of motors (12 max @ moment) |
||
1566 | { |
||
1567 | |||
1568 | if ((data[i + 4] & 128) == 128) //Status bit at pos 7 = 128 dec -- if true, motor is available |
||
1569 | bAvailable = true; |
||
1570 | else |
||
1571 | bAvailable = false; |
||
1572 | |||
1573 | if (data[i] < _iMotors) |
||
1574 | { |
||
1575 | if (bAvailable) |
||
1576 | { |
||
2315 | - | 1577 | dtMotors.Rows[data[i]].SetField(1, ((double)data[i + 1] / (double)10).ToString("0.0 A")); |
1578 | dtMotors.Rows[data[i]].SetField(2, data[i + 2].ToString("0 °C")); |
||
2287 | - | 1579 | } |
1580 | else |
||
1581 | { |
||
2315 | - | 1582 | dtMotors.Rows[data[i]].SetField(1, "NA"); |
1583 | dtMotors.Rows[data[i]].SetField(2, "NA"); |
||
2287 | - | 1584 | } |
1585 | } |
||
1586 | //if (data[i] > 3 && data[i] < 8) |
||
1587 | //{ |
||
1588 | // if (bAvailable) |
||
1589 | // { |
||
1590 | // dtMotors2.Rows[data[i] - 4].SetField(1, ((double)data[i + 1] / (double)10).ToString("0.0 A")); |
||
1591 | // dtMotors2.Rows[data[i] - 4].SetField(2, data[i + 2].ToString("0 °C")); |
||
1592 | // } |
||
1593 | // else |
||
1594 | // { |
||
1595 | // dtMotors2.Rows[data[i] - 4].SetField(1, "NA"); |
||
1596 | // dtMotors2.Rows[data[i] - 4].SetField(2, "NA"); |
||
1597 | // } |
||
1598 | //} |
||
1599 | } |
||
1600 | } |
||
1601 | } |
||
1602 | /// <summary> |
||
1603 | /// Navi-Ctrl data 'O' |
||
1604 | /// GPS-Position, capacatiy, flying time... |
||
1605 | /// </summary> |
||
1606 | /// <param name="data">the received byte array to process</param> |
||
1607 | void _processNCData(byte[] data) |
||
1608 | { |
||
1609 | int i_32, i_16, iVal; |
||
1610 | double d; |
||
1611 | i_32 = data[4]; |
||
1612 | iVal = i_32 << 24; |
||
1613 | i_32 = data[3]; |
||
1614 | iVal += i_32 << 16; |
||
1615 | i_32 = data[2]; |
||
1616 | iVal += i_32 << 8; |
||
1617 | iVal += data[1]; |
||
1618 | d = (double)iVal / Math.Pow(10, 7); |
||
2324 | - | 1619 | Dispatcher.Invoke(() => { drGPX[2] = d; }); |
1620 | |||
2287 | - | 1621 | PointLatLng p = new PointLatLng(); |
1622 | |||
1623 | p.Lng = d; |
||
1624 | // lblNCGPSLong.Invoke((Action)(() => lblNCGPSLong.Text = d.ToString("0.######°"))); //GPS-Position: Longitude in decimal degree |
||
1625 | //lblNCGPSLong.Invoke((Action)(() => lblNCGPSLong.Text = _convertDegree(d))); //GPS-Position: Longitude in minutes, seconds |
||
1626 | |||
1627 | i_32 = data[8]; |
||
1628 | iVal = i_32 << 24; |
||
1629 | i_32 = data[7]; |
||
1630 | iVal += i_32 << 16; |
||
1631 | i_32 = data[6]; |
||
1632 | iVal += i_32 << 8; |
||
1633 | iVal += data[5]; |
||
1634 | d = (double)iVal / Math.Pow(10, 7); |
||
2324 | - | 1635 | Dispatcher.Invoke(() => { drGPX[1] = d; }); |
1636 | Dispatcher.Invoke(() => { drGPX[4] = DateTime.UtcNow.ToString("u", System.Globalization.CultureInfo.InvariantCulture); }); //2011-01-14T01:59:01Z }); |
||
2287 | - | 1637 | p.Lat = d; |
2291 | - | 1638 | if (data[50] > 4)//if more than 4 sats in use . otherwise the map would jump and scroll insane at beginning |
1639 | { |
||
1640 | _bSatFix = true; _iSatsJitter = 0; _bVoiceSatFixActive = false; |
||
2295 | - | 1641 | if(_bAutoHome && !_bFirstSatFix) |
1642 | { |
||
1643 | if (_iFirstSatFix < 3) |
||
1644 | _iFirstSatFix++; |
||
1645 | else |
||
1646 | { |
||
1647 | _bFirstSatFix = true; |
||
2347 | - | 1648 | Dispatcher.Invoke(() => _setHomePos()); |
2295 | - | 1649 | } |
1650 | } |
||
2291 | - | 1651 | if (stbSatFixLostAnim != null && _bAnimSatFixActive) |
1652 | { |
||
1653 | Dispatcher.Invoke(() => stbSatFixLostAnim.Stop()); |
||
1654 | _bAnimSatFixActive = false; |
||
1655 | } |
||
1656 | if (!_bFollowCopter) |
||
1657 | { |
||
1658 | _setCopterData(p); |
||
1659 | if (!MainMap.ViewArea.Contains(p)) |
||
1660 | Dispatcher.Invoke(() => MainMap.Position = p); |
||
2287 | - | 1661 | |
2291 | - | 1662 | } |
1663 | else |
||
2287 | - | 1664 | Dispatcher.Invoke(() => MainMap.Position = p); |
1665 | } |
||
1666 | else |
||
2291 | - | 1667 | { |
1668 | if(_bSatFix) |
||
1669 | { |
||
1670 | if (data[50] == _iSatsLast) |
||
1671 | { |
||
1672 | if (_iSatsJitter < 20) _iSatsJitter++; |
||
1673 | } |
||
1674 | else |
||
1675 | { |
||
1676 | _iSatsJitter = 0; |
||
1677 | _iSatsLast = data[50]; |
||
1678 | } |
||
2287 | - | 1679 | |
2291 | - | 1680 | if (_iSatsJitter == 20) |
1681 | { |
||
1682 | if (stbSatFixLostAnim != null && !_bAnimSatFixActive) |
||
1683 | { |
||
1684 | Dispatcher.Invoke(() => stbSatFixLostAnim.Begin()); |
||
1685 | _bAnimSatFixActive = true; |
||
1686 | } |
||
1687 | if (_bVoiceSatFixPlay && !_bVoiceSatFixActive) |
||
1688 | { |
||
2335 | - | 1689 | Thread th = new Thread(() => _mediaPlayer("Voice\\SatFixLost.mp3")); |
2295 | - | 1690 | th.Start(); |
2291 | - | 1691 | _bVoiceSatFixActive = true; |
1692 | } |
||
1693 | |||
1694 | _bSatFix = false; |
||
1695 | } |
||
1696 | } |
||
1697 | } |
||
1698 | |||
2287 | - | 1699 | // lblNCGPSLat.Invoke((Action)(() => lblNCGPSLat.Text = d.ToString("0.######°"))); //GPS-Position: Latitude in decimal degree |
1700 | //lblNCGPSLat.Invoke((Action)(() => lblNCGPSLat.Text = _convertDegree(d))); //GPS-Position: Latitude in minutes, seconds |
||
1701 | |||
1702 | i_16 = data[28]; |
||
1703 | i_16 = (Int16)(i_16 << 8); |
||
1704 | iVal = data[27] + i_16; |
||
1705 | Dispatcher.Invoke((Action)(() => tbWP.Text = ((double)iVal / (double)10).ToString("0.0 m"))); //Distance to next WP |
||
1706 | |||
1707 | i_16 = data[45]; |
||
1708 | i_16 = (Int16)(i_16 << 8); |
||
1709 | iVal = data[44] + i_16; |
||
1710 | // Dispatcher.Invoke((Action)(() => tbTopDistanceHP.Text = ((double)iVal / (double)10).ToString("0.0 m"))); //Distance to HP set by GPS on |
||
1711 | Dispatcher.Invoke((Action)(() => tbHP.Text = ((double)iVal / (double)10).ToString("0.0 m"))); //Distance to HP set by GPS on |
||
1712 | |||
1713 | Dispatcher.Invoke((Action)(() => tbWPIndex.Text = data[48].ToString())); //Waypoint index |
||
2347 | - | 1714 | if(data[48] > 0 && _wpIndex != data[48] -1 && wpList.Count > 0) |
2342 | - | 1715 | { |
2347 | - | 1716 | _setActiveWP(data[48]-1); |
1717 | _wpIndex = data[48]-1; |
||
2342 | - | 1718 | } |
2347 | - | 1719 | else |
1720 | { |
||
1721 | if ((data[48] == 0 || wpList.Count == 0) & MainMap.Markers.Contains(wpActiveMarker)) |
||
1722 | Dispatcher.Invoke(() => MainMap.Markers.Remove(wpActiveMarker)); |
||
1723 | } |
||
2342 | - | 1724 | |
1725 | if(wpList.Count > 0 && ((data[67] & 2) == 2)) |
||
1726 | { |
||
2340 | - | 1727 | // Dispatcher.Invoke(() => |
1728 | // { |
||
1729 | // if(data[48] < wpList.Count) |
||
1730 | // { |
||
1731 | // DataGridRow row; |
||
2342 | - | 1732 | // if (data[48] > 0) |
2340 | - | 1733 | // { |
1734 | // row = (DataGridRow)dgvWP.ItemContainerGenerator.ContainerFromIndex(data[48] - 1); |
||
1735 | // row.Background = new SolidColorBrush(Colors.Transparent); |
||
1736 | // } |
||
1737 | // row = (DataGridRow)dgvWP.ItemContainerGenerator.ContainerFromIndex(data[48]); |
||
1738 | // row.Background = new SolidColorBrush(Color.FromArgb(50, 0, 100, 255)); |
||
1739 | // } |
||
1740 | // }); |
||
2342 | - | 1741 | } |
2287 | - | 1742 | Dispatcher.Invoke((Action)(() => tbWPCount.Text = data[49].ToString())); //Waypoints count |
2340 | - | 1743 | _wpCount = data[49]; |
2287 | - | 1744 | Dispatcher.Invoke((Action)(() => tbTopSats.Text = data[50].ToString())); //Satellites |
1745 | |||
1746 | //--------------- Capacity used ------------------------ |
||
1747 | i_16 = data[81]; |
||
1748 | i_16 = (Int16)(i_16 << 8); |
||
1749 | iVal = data[80] + i_16; |
||
1750 | Dispatcher.Invoke((Action)(() => tbCapacity.Text = iVal.ToString() + " mAh")); |
||
1751 | Dispatcher.Invoke((Action)(() => tbTopCapacity.Text = iVal.ToString() + " mAh")); |
||
1752 | |||
1753 | //--------------- Flying time ------------------------ |
||
1754 | i_16 = data[56]; |
||
1755 | i_16 = (Int16)(i_16 << 8); |
||
1756 | iVal = data[55] + i_16; |
||
1757 | TimeSpan t = TimeSpan.FromSeconds(iVal); |
||
1758 | string Text = t.Hours.ToString("D2") + ":" + t.Minutes.ToString("D2") + ":" + t.Seconds.ToString("D2"); |
||
1759 | Dispatcher.Invoke((Action)(() => tbFTime.Text = Text.ToString())); |
||
1760 | Dispatcher.Invoke((Action)(() => tbTopFTime.Text = Text.ToString())); |
||
1761 | |||
1762 | //--------------- RC quality ------------------------ |
||
1763 | Dispatcher.Invoke((Action)(() => tbRCQ.Text = data[66].ToString())); |
||
1764 | Dispatcher.Invoke((Action)(() => tbTopRC.Text = data[66].ToString())); |
||
1765 | |||
2291 | - | 1766 | if(data[66] > _iThresholdRC) |
1767 | { |
||
1768 | _iRCLevelJitter = 0; _bVoiceRCLevelActive = false; |
||
1769 | if (stbRCLevelAnim != null && _bAnimRCLevelActive) |
||
1770 | { |
||
1771 | Dispatcher.Invoke(() => stbRCLevelAnim.Stop()); |
||
1772 | _bAnimRCLevelActive = false; |
||
1773 | } |
||
1774 | } |
||
1775 | else |
||
1776 | { |
||
1777 | if (_iRCLevelJitter < 20) _iRCLevelJitter++; |
||
1778 | if (_iRCLevelJitter == 20) |
||
1779 | { |
||
1780 | if (stbRCLevelAnim != null && !_bAnimRCLevelActive) |
||
1781 | { |
||
1782 | Dispatcher.Invoke(() => stbRCLevelAnim.Begin()); |
||
1783 | _bAnimRCLevelActive = true; |
||
1784 | } |
||
1785 | if (_bVoiceRCLevelPlay && !_bVoiceRCLevelActive) |
||
1786 | { |
||
2295 | - | 1787 | Thread th = new Thread(() => _mediaPlayer("Voice\\RCLevel.mp3")); |
1788 | th.Start(); |
||
2291 | - | 1789 | _bVoiceRCLevelActive = true; |
1790 | } |
||
1791 | _iRCLevelJitter++; |
||
1792 | } |
||
1793 | } |
||
1794 | |||
2287 | - | 1795 | //--------------- NC Error ------------------------ |
1796 | Dispatcher.Invoke((Action)(() => tbNCErr.Text = data[69].ToString())); //NC Errornumber |
||
1797 | if (data[69] > 0) |
||
1798 | _readNCError(); |
||
1799 | if (data[69] > 0 & data[69] < 44) |
||
1800 | ErrorLog(LogMsgType.Error, "NC Error [" + data[69].ToString() + "]: " + NC_Error[data[69]]); |
||
1801 | else |
||
1802 | if (_bErrorLog) _clearErrorLog("NC Error"); |
||
1803 | |||
2298 | - | 1804 | //-------------FC / NC Status Flags |
1805 | Dispatcher.Invoke((Action)(() => FC1_1.Background = ((data[67] & 1) ==1) ? new SolidColorBrush(Colors.LightSeaGreen) : new SolidColorBrush(Colors.Transparent)));// FC_STATUS_MOTOR_RUN 0x01 |
||
1806 | Dispatcher.Invoke((Action)(() => FC1_2.Background = ((data[67] & 2) ==2) ? new SolidColorBrush(Colors.LightSeaGreen) : new SolidColorBrush(Colors.Transparent)));// FC_STATUS_FLY 0x02 |
||
1807 | Dispatcher.Invoke((Action)(() => FC1_3.Background = ((data[67] & 4) ==4) ? new SolidColorBrush(Colors.LightSeaGreen) : new SolidColorBrush(Colors.Transparent)));// FC_STATUS_CALIBRATE 0x04 |
||
1808 | Dispatcher.Invoke((Action)(() => FC1_4.Background = ((data[67] & 8) ==8) ? new SolidColorBrush(Colors.LightSeaGreen) : new SolidColorBrush(Colors.Transparent)));// FC_STATUS_START 0x08 |
||
1809 | Dispatcher.Invoke((Action)(() => FC1_5.Background = ((data[67] & 16) ==16) ? new SolidColorBrush(Colors.LightCoral) : new SolidColorBrush(Colors.Transparent)));// FC_STATUS_EMERGENCY_LANDING 0x10 |
||
1810 | Dispatcher.Invoke((Action)(() => FC1_6.Background = ((data[67] & 32) ==32) ? new SolidColorBrush(Colors.LightCoral) : new SolidColorBrush(Colors.Transparent)));// FC_STATUS_LOWBAT 0x20 |
||
1811 | |||
1812 | Dispatcher.Invoke((Action)(() => FC2_1.Background = ((data[74] & 1) ==1) ? new SolidColorBrush(Colors.LightSeaGreen) : new SolidColorBrush(Colors.Transparent)));// FC_STATUS2_CAREFREE 0x01 |
||
1813 | Dispatcher.Invoke((Action)(() => FC2_2.Background = ((data[74] & 2) ==2) ? new SolidColorBrush(Colors.LightSeaGreen) : new SolidColorBrush(Colors.Transparent)));// FC_STATUS2_ALTITUDE_CONTROL 0x02 |
||
1814 | Dispatcher.Invoke((Action)(() => FC2_3.Background = ((data[74] & 4) ==4) ? new SolidColorBrush(Colors.LightCoral) : new SolidColorBrush(Colors.Transparent)));// FC_STATUS2_RC_FAILSAVE_ACTIVE 0x04 |
||
1815 | Dispatcher.Invoke((Action)(() => FC2_4.Background = ((data[74] & 8) ==8) ? new SolidColorBrush(Colors.LightSeaGreen) : new SolidColorBrush(Colors.Transparent)));// FC_STATUS2_OUT1_ACTIVE 0x08 |
||
1816 | Dispatcher.Invoke((Action)(() => FC2_5.Background = ((data[74] & 16) ==16) ? new SolidColorBrush(Colors.LightSeaGreen) : new SolidColorBrush(Colors.Transparent)));// FC_STATUS2_OUT2_ACTIVE 0x10 |
||
1817 | Dispatcher.Invoke((Action)(() => FC2_6.Background = ((data[74] & 32) ==32) ? new SolidColorBrush(Colors.LightSeaGreen) : new SolidColorBrush(Colors.Transparent)));// FC_STATUS2_WAIT_FOR_TAKEOFF 0x20 // Motor Running, but still on the ground |
||
1818 | Dispatcher.Invoke((Action)(() => FC2_7.Background = ((data[74] & 64) ==64) ? new SolidColorBrush(Colors.LightSeaGreen) : new SolidColorBrush(Colors.Transparent)));// FC_STATUS2_AUTO_STARTING 0x40 |
||
1819 | Dispatcher.Invoke((Action)(() => FC2_8.Background = ((data[74] & 128) ==128) ? new SolidColorBrush(Colors.LightSeaGreen) : new SolidColorBrush(Colors.Transparent)));// FC_STATUS2_AUTO_LANDING 0x80 |
||
1820 | |||
1821 | Dispatcher.Invoke((Action)(() => NC1_2.Background = ((data[68] & 2) == 2) ? new SolidColorBrush(Colors.LightSeaGreen) : new SolidColorBrush(Colors.Transparent)));// NC_FLAG_PH 0x02 |
||
1822 | Dispatcher.Invoke((Action)(() => NC1_3.Background = ((data[68] & 4) == 4) ? new SolidColorBrush(Colors.LightSeaGreen) : new SolidColorBrush(Colors.Transparent)));// NC_FLAG_CH 0x04 |
||
1823 | Dispatcher.Invoke((Action)(() => NC1_4.Background = ((data[68] & 8) == 8) ? new SolidColorBrush(Colors.LightCoral) : new SolidColorBrush(Colors.Transparent)));// NC_FLAG_RANGE_LIMIT 0x08 |
||
1824 | Dispatcher.Invoke((Action)(() => NC1_5.Background = ((data[68] & 16) == 16) ? new SolidColorBrush(Colors.LightCoral) : new SolidColorBrush(Colors.Transparent)));// NC_FLAG_NOSERIALLINK 0x10 |
||
1825 | Dispatcher.Invoke((Action)(() => NC1_6.Background = ((data[68] & 32) == 32) ? new SolidColorBrush(Colors.LightSeaGreen) : new SolidColorBrush(Colors.Transparent)));// NC_FLAG_TARGET_REACHED 0x20 |
||
1826 | Dispatcher.Invoke((Action)(() => NC1_7.Background = ((data[68] & 64) == 64) ? new SolidColorBrush(Colors.DodgerBlue) : new SolidColorBrush(Colors.Transparent)));// NC_FLAG_MANUAL_CONTROL 0x40 |
||
1827 | Dispatcher.Invoke((Action)(() => NC1_8.Background = ((data[68] & 128) == 128) ? new SolidColorBrush(Colors.LightSeaGreen) : new SolidColorBrush(Colors.Transparent)));// NC_FLAG_GPS_OK 0x80 |
||
2299 | - | 1828 | |
1829 | //Sidebar StatusSymbols |
||
1830 | Dispatcher.Invoke((Action)(() => tbSideBarStatusMotors.Background = ((data[67] & 1) ==1) ? new SolidColorBrush(Colors.LightSeaGreen) : new SolidColorBrush(Colors.Transparent)));// FC_STATUS_MOTOR_RUN 0x01 |
||
1831 | Dispatcher.Invoke((Action)(() => tbSideBarStatusMotors.Foreground = ((data[67] & 1) ==1) ? new SolidColorBrush(Colors.White) : new SolidColorBrush(Color.FromArgb(255,211,210,210))));// FC_STATUS_MOTOR_RUN 0x01 |
||
1832 | Dispatcher.Invoke((Action)(() => tbSideBarStatusMotors.BorderBrush = ((data[67] & 1) ==1) ? new SolidColorBrush(Colors.White) : new SolidColorBrush(Color.FromArgb(255, 211, 210, 210))));// FC_STATUS_MOTOR_RUN 0x01 |
||
1833 | |||
1834 | Dispatcher.Invoke((Action)(() => tbSideBarStatusCF.Background = ((data[74] & 1) == 1) ? new SolidColorBrush(Colors.LightSeaGreen) : new SolidColorBrush(Colors.Transparent)));// FC_STATUS2_CAREFREE 0x01 |
||
1835 | Dispatcher.Invoke((Action)(() => tbSideBarStatusCF.Foreground = ((data[74] & 1) == 1) ? new SolidColorBrush(Colors.White) : new SolidColorBrush(Color.FromArgb(255, 211, 210, 210))));// FC_STATUS2_CAREFREE 0x01 |
||
1836 | Dispatcher.Invoke((Action)(() => tbSideBarStatusCF.BorderBrush = ((data[74] & 1) ==1) ? new SolidColorBrush(Colors.White) : new SolidColorBrush(Color.FromArgb(255, 211, 210, 210))));// FC_STATUS2_CAREFREE 0x01 |
||
1837 | |||
1838 | Dispatcher.Invoke((Action)(() => tbSideBarStatusEmergencyLanding.Background = ((data[67] & 16) == 16) ? new SolidColorBrush(Colors.LightCoral) : new SolidColorBrush(Colors.Transparent)));// FC_STATUS_EMERGENCY_LANDING 0x10 |
||
2304 | - | 1839 | Dispatcher.Invoke((Action)(() => tbSideBarStatusEmergencyLanding.Foreground = ((data[67] & 16) == 16) ? new SolidColorBrush(Colors.White) : new SolidColorBrush(Color.FromArgb(255, 211, 210, 210))));// FC_STATUS_EMERGENCY_LANDING 0x10 |
1840 | Dispatcher.Invoke((Action)(() => tbSideBarStatusEmergencyLanding.BorderBrush = ((data[67] & 16) == 16) ? new SolidColorBrush(Colors.White) : new SolidColorBrush(Color.FromArgb(255, 211, 210, 210))));// FC_STATUS_EMERGENCY_LANDING 0x10 |
||
2299 | - | 1841 | |
1842 | Dispatcher.Invoke((Action)(() => tbSideBarStatusAC.Background = ((data[74] & 2) ==2) ? new SolidColorBrush(Colors.LightSeaGreen) : new SolidColorBrush(Colors.Transparent)));// FC_STATUS2_ALTITUDE_CONTROL 0x02 |
||
1843 | Dispatcher.Invoke((Action)(() => tbSideBarStatusAC.Foreground = ((data[74] & 2) ==2) ? new SolidColorBrush(Colors.White) : new SolidColorBrush(Color.FromArgb(255, 211, 210, 210))));// FC_STATUS2_ALTITUDE_CONTROL 0x02 |
||
1844 | Dispatcher.Invoke((Action)(() => tbSideBarStatusAC.BorderBrush = ((data[74] & 2) ==2) ? new SolidColorBrush(Colors.White) : new SolidColorBrush(Color.FromArgb(255, 211, 210, 210))));// FC_STATUS2_ALTITUDE_CONTROL 0x02 |
||
1845 | |||
1846 | Dispatcher.Invoke((Action)(() => tbSideBarStatusPH.Text = ((data[68] & 4) == 4) ? "CH" : "PH"));// NC_FLAG_PH 0x02 / NC_FLAG_CH 0x04 |
||
2304 | - | 1847 | Dispatcher.Invoke((Action)(() => tbSideBarStatusPH.Background = (((data[68] & 2) == 2)|((data[68] & 4) == 4)) ? new SolidColorBrush(Colors.LightSeaGreen) : new SolidColorBrush(Colors.Transparent)));// NC_FLAG_PH 0x02 / NC_FLAG_CH 0x04 |
1848 | Dispatcher.Invoke((Action)(() => tbSideBarStatusPH.Foreground = (((data[68] & 2) == 2)|((data[68] & 4) == 4)) ? new SolidColorBrush(Colors.White) : new SolidColorBrush(Color.FromArgb(255, 211, 210, 210))));// NC_FLAG_PH 0x02 / NC_FLAG_CH 0x04 |
||
1849 | Dispatcher.Invoke((Action)(() => tbSideBarStatusPH.BorderBrush = (((data[68] & 2) == 2)|((data[68] & 4) == 4)) ? new SolidColorBrush(Colors.White) : new SolidColorBrush(Color.FromArgb(255, 211, 210, 210))));// NC_FLAG_PH 0x02 / NC_FLAG_CH 0x04 |
||
2299 | - | 1850 | |
2324 | - | 1851 | _bAirborne = (data[67] & 2) == 2 ? true : false; |
2287 | - | 1852 | } |
1853 | /// <summary> |
||
1854 | /// Navi-Ctrl WP data struct 'X' |
||
1855 | /// called by index |
||
1856 | /// </summary> |
||
1857 | /// <param name="data">the received byte array to process</param> |
||
1858 | void _processWPData(byte[] data) |
||
1859 | { |
||
2313 | - | 1860 | _iWPCount = data[0]; |
2287 | - | 1861 | _bGetWPCount = false; |
1862 | if (data.Length >= 28) |
||
1863 | { |
||
1864 | Dispatcher.Invoke(() => lblWPIndex.Content = data[1].ToString()); |
||
1865 | Dispatcher.Invoke(() => lblWPCount.Content = data[0].ToString()); |
||
1866 | if (_bGetWP) |
||
1867 | { |
||
1868 | if (data[1] == 1) |
||
2315 | - | 1869 | { |
2333 | - | 1870 | if(mRouteWP != null) |
1871 | Dispatcher.Invoke(() => MainMap.Markers.Remove(mRouteWP)); |
||
2328 | - | 1872 | wpList.Clear(); |
1873 | |||
1874 | Dispatcher.Invoke(() => lblWPRouteDistance.Content = "0 m"); |
||
2287 | - | 1875 | dtWaypoints.Rows.Clear(); |
2333 | - | 1876 | Dispatcher.Invoke(() => |
1877 | { |
||
2318 | - | 1878 | for (int k = 0; k < MainMap.Markers.Count;) |
1879 | { |
||
1880 | GMapMarker p = MainMap.Markers[k]; |
||
1881 | if (p.Shape.GetType() == typeof(CustomMarkerWP)) |
||
1882 | MainMap.Markers.Remove(p); |
||
1883 | else |
||
1884 | k++; |
||
1885 | } |
||
1886 | }); |
||
2315 | - | 1887 | } |
2287 | - | 1888 | DataRow dr = dtWaypoints.NewRow(); |
1889 | dr = Waypoints.toDataRow(data, dr); |
||
2313 | - | 1890 | dtWaypoints.Rows.Add(dr); |
2318 | - | 1891 | Dispatcher.Invoke(() => { |
1892 | GMapMarker wp = new GMapMarker(new PointLatLng((double)dr[3], (double)dr[4])); |
||
1893 | wp.Shape = new CustomMarkerWP(this, wp, (string)dr[2],(int)dr[1]); |
||
2333 | - | 1894 | wp.Offset = new System.Windows.Point(-11.5, -11.5); |
2318 | - | 1895 | _setMarkerColor(wp, (int)dr[1]); |
1896 | MainMap.Markers.Add(wp); |
||
1897 | }); |
||
2313 | - | 1898 | Dispatcher.Invoke(() => dgvWP.Items.Refresh()); |
1899 | Dispatcher.Invoke(() => _iWPIndex = data[1]); |
||
2335 | - | 1900 | if ((int)dr[1] == 0) |
1901 | wpList.Add(new PointLatLng((double)dr[3], (double)dr[4])); |
||
2287 | - | 1902 | if (data[1] == data[0]) |
1903 | { |
||
1904 | _bGetWP = false; |
||
1905 | Dispatcher.Invoke(() => dgvWP.Items.Refresh()); |
||
2328 | - | 1906 | |
1907 | Dispatcher.Invoke(() => |
||
1908 | { |
||
1909 | if (comboBoxRouteColor.SelectionBoxItem != null) |
||
1910 | { |
||
1911 | string s = comboBoxRouteColor.SelectionBoxItem.ToString(); |
||
1912 | mRouteWP = new GMapRoute(wpList, _getBrush(s)); |
||
1913 | } |
||
1914 | else |
||
1915 | mRouteWP = new GMapRoute(wpList, null); |
||
1916 | |||
1917 | if (_bShowWPRoute) |
||
1918 | MainMap.Markers.Add(mRouteWP); |
||
1919 | }); |
||
1920 | MapRoute mr = new MapRoute(wpList, "WPList"); |
||
2333 | - | 1921 | Dispatcher.Invoke(() => lblWPRouteDistance.Content = (mr.Distance * 1000).ToString("0 m")); |
2287 | - | 1922 | } |
1923 | |||
1924 | } |
||
1925 | } |
||
1926 | else |
||
1927 | { |
||
1928 | Dispatcher.Invoke(() => lblWPIndex.Content = 0); |
||
1929 | Dispatcher.Invoke(() => lblWPCount.Content = 0); |
||
1930 | } |
||
1931 | } |
||
1932 | /// <summary> |
||
1933 | /// OSD Menue 'L' |
||
1934 | /// single page called by pagenumber |
||
1935 | /// no autoupdate |
||
1936 | /// </summary> |
||
1937 | /// <param name="data">the received byte array to process</param> |
||
1938 | void _processOSDSingle(byte[] data) |
||
1939 | { |
||
1940 | if (data.Length == 84) |
||
1941 | { |
||
1942 | string sMessage = ""; |
||
1943 | iOSDPage = data[0]; |
||
1944 | iOSDMax = data[1]; |
||
1945 | if (cbOSD.Items.Count != iOSDMax) _initOSDCB(); |
||
1946 | sMessage = new string(ASCIIEncoding.ASCII.GetChars(data, 2, data.Length - 4)); |
||
1947 | OSD(LogMsgType.Incoming, sMessage.Substring(0, 20)+ "\r", true); |
||
1948 | OSD(LogMsgType.Incoming, sMessage.Substring(20, 20)+ "\r", false); |
||
1949 | OSD(LogMsgType.Incoming, sMessage.Substring(40, 20)+ "\r", false); |
||
1950 | OSD(LogMsgType.Incoming, sMessage.Substring(60, 20), false); |
||
1951 | Dispatcher.Invoke(() => { cbOSD.SelectedValue = iOSDPage; }); |
||
1952 | // lblOSDPageNr.Invoke((Action)(() => lblOSDPageNr.Text = iOSDPage.ToString("[0]"))); |
||
1953 | |||
1954 | } |
||
1955 | //else |
||
1956 | // OSD(LogMsgType.Incoming, "Wrong length: " + data.Length + " (should be 84)"); |
||
1957 | |||
1958 | } |
||
1959 | /// <summary> |
||
1960 | /// OSD Menue 'H' |
||
1961 | /// called by keys (0x01,0x02,0x03,0x04) |
||
1962 | /// autoupdate |
||
1963 | /// </summary> |
||
1964 | /// <param name="data">the received byte array to process</param> |
||
1965 | void _processOSDAuto(byte[] data) |
||
1966 | { |
||
1967 | if (data.Length == 81) |
||
1968 | { |
||
1969 | string sMessage = ""; |
||
1970 | sMessage = new string(ASCIIEncoding.ASCII.GetChars(data, 0, data.Length - 1)); |
||
1971 | OSD(LogMsgType.Incoming, sMessage.Substring(0, 20)+ "\r", true); |
||
1972 | OSD(LogMsgType.Incoming, sMessage.Substring(20, 20)+ "\r", false); |
||
1973 | OSD(LogMsgType.Incoming, sMessage.Substring(40, 20)+ "\r", false); |
||
1974 | OSD(LogMsgType.Incoming, sMessage.Substring(60, 20), false); |
||
1975 | |||
1976 | } |
||
1977 | //else |
||
1978 | // OSD(LogMsgType.Incoming, "Wrong length: " + data.Length + " (should be 81)"); |
||
1979 | } |
||
1980 | |||
1981 | #endregion processing received data |
||
1982 | |||
1983 | #region controller messages |
||
1984 | /// <summary> send message to controller to request data |
||
1985 | /// for detailed info see http://wiki.mikrokopter.de/en/SerialProtocol/ |
||
1986 | /// </summary> |
||
1987 | /// <param name="CMDID"> the command ID </param> |
||
1988 | /// <param name="address"> the address of the controller: 0-any, 1-FC, 2-NC </param> |
||
1989 | private void _sendControllerMessage(char CMDID, byte address) |
||
1990 | { |
||
1991 | if (serialPortCtrl.Port.IsOpen) |
||
1992 | { |
||
1993 | Stream serialStream = serialPortCtrl.Port.BaseStream; |
||
1994 | byte[] bytes = FlightControllerMessage.CreateMessage(CMDID, address); |
||
1995 | serialStream.Write(bytes, 0, bytes.Length); |
||
1996 | |||
1997 | } |
||
1998 | else |
||
1999 | Log(LogMsgType.Error, "NOT CONNECTED!"); |
||
2000 | } |
||
2001 | /// <summary> send message to controller to request data |
||
2002 | /// for detailed info see http://wiki.mikrokopter.de/en/SerialProtocol/ |
||
2003 | /// </summary> |
||
2004 | /// <param name="CMDID"> the command ID </param> |
||
2005 | /// <param name="address"> the address of the controller: 0-any, 1-FC, 2-NC </param> |
||
2006 | /// <param name="data"> additional data for the request</param> |
||
2007 | private void _sendControllerMessage(char CMDID, byte address, byte[] data) |
||
2008 | { |
||
2009 | if (serialPortCtrl.Port.IsOpen) |
||
2010 | { |
||
2011 | Stream serialStream = serialPortCtrl.Port.BaseStream; |
||
2012 | byte[] bytes = FlightControllerMessage.CreateMessage(CMDID, address, data); |
||
2013 | serialStream.Write(bytes, 0, bytes.Length); |
||
2014 | |||
2015 | } |
||
2016 | else |
||
2017 | Log(LogMsgType.Error, "NOT CONNECTED!"); |
||
2018 | } |
||
2019 | |||
2020 | /// <summary> |
||
2021 | /// start/stop continous polling of controller values |
||
2022 | /// </summary> |
||
2023 | /// <param name="b">start/stop switch</param> |
||
2024 | void _readCont(bool b) |
||
2025 | { |
||
2026 | bReadContinously = b; |
||
2027 | if (bReadContinously) |
||
2028 | { |
||
2029 | if (_debugDataAutorefresh) { _readDebugData(true); Thread.Sleep(10); } |
||
2030 | if (_blctrlDataAutorefresh) { _readBLCtrl(true); Thread.Sleep(10); } |
||
2031 | if (_navCtrlDataAutorefresh && _iCtrlAct == 2) { _readNavData(true); Thread.Sleep(10); } |
||
2032 | if (_OSDAutorefresh) { _OSDMenueAutoRefresh(); Thread.Sleep(10); } |
||
2033 | // Dispatcher.Invoke((Action)(() => rctConnection.Fill = Brushes.LightGreen)); |
||
2034 | Dispatcher.Invoke(() => imageConn.Source = new BitmapImage(new Uri("Images/Data_G.png", UriKind.Relative))); |
||
2035 | } |
||
2036 | else |
||
2037 | { |
||
2038 | // Dispatcher.Invoke((Action)(() => rctConnection.Fill = Brushes.LightGray)); |
||
2039 | Dispatcher.Invoke(() => imageConn.Source = new BitmapImage(new Uri("Images/Data_W.png", UriKind.Relative))); |
||
2040 | _bConnErr = false; |
||
2041 | } |
||
2042 | _iLifeCounter = 0; |
||
2043 | } |
||
2044 | |||
2045 | private void _getVersion() |
||
2046 | { |
||
2047 | _sendControllerMessage('v', 0); |
||
2048 | } |
||
2049 | /// <summary> |
||
2050 | /// get FC version struct via NC |
||
2051 | /// by sending '1' as data (not documented in wiki...) |
||
2052 | /// returns HW error 255 (comment in uart1.c : tells the KopterTool that it is the FC-version) |
||
2053 | /// </summary> |
||
2054 | /// <param name="ctrl">controller number 1=FC</param> |
||
2055 | private void _getVersion(byte ctrl) |
||
2056 | { |
||
2057 | _sendControllerMessage('v', 0, new byte[1] { ctrl }); |
||
2058 | } |
||
2059 | /// <summary> |
||
2060 | /// Switch back to NC by sending the 'Magic Packet' 0x1B,0x1B,0x55,0xAA,0x00 |
||
2061 | /// </summary> |
||
2062 | private void _switchToNC() |
||
2063 | { |
||
2064 | if (serialPortCtrl.Port.IsOpen) |
||
2065 | { |
||
2066 | Stream serialStream = serialPortCtrl.Port.BaseStream; |
||
2067 | byte[] bytes = new byte[5] { 0x1B, 0x1B, 0x55, 0xAA, 0x00 }; |
||
2068 | serialStream.Write(bytes, 0, bytes.Length); |
||
2069 | |||
2070 | Thread.Sleep(100); |
||
2071 | _getVersion(); |
||
2072 | Thread.Sleep(100); |
||
2073 | // _OSDMenue(0); |
||
2074 | } |
||
2075 | else |
||
2076 | Log(LogMsgType.Error, "NOT CONNECTED!"); |
||
2077 | } |
||
2078 | /// <summary> |
||
2079 | /// switch to FC |
||
2080 | /// </summary> |
||
2081 | private void _switchToFC() |
||
2082 | { |
||
2083 | _sendControllerMessage('u', 2, new byte[1] { (byte)0 }); |
||
2084 | Thread.Sleep(100); |
||
2085 | _getVersion(); |
||
2086 | Thread.Sleep(100); |
||
2087 | // _OSDMenue(0); |
||
2088 | } |
||
2089 | /// <summary> |
||
2090 | /// send RESET signal to FC |
||
2091 | /// </summary> |
||
2092 | private void _resetCtrl() |
||
2093 | { |
||
2094 | _sendControllerMessage('R', 1); |
||
2095 | } |
||
2096 | /// <summary> |
||
2097 | /// poll the debug data (4sec subscription) |
||
2098 | /// </summary> |
||
2099 | /// <param name="auto"> onetimequery(false) or autoupdate(true) with set timing interval </param> |
||
2100 | private void _readDebugData(bool auto) |
||
2101 | { |
||
2102 | byte interval = auto ? debugInterval : (byte)0; |
||
2103 | _sendControllerMessage('d', 0, new byte[1] { debugInterval }); |
||
2104 | } |
||
2105 | /// <summary> |
||
2106 | /// poll the BL-CTRL status via NC (4sec subscription) |
||
2107 | /// </summary> |
||
2108 | /// <param name="auto"> onetimequery(false) or autoupdate(true) with set timing interval </param> |
||
2109 | private void _readBLCtrl(bool auto) |
||
2110 | { |
||
2111 | byte interval = auto ? blctrlInterval : (byte)0; |
||
2112 | _sendControllerMessage('k', 0, new byte[1] { interval }); |
||
2113 | } |
||
2114 | /// <summary> |
||
2115 | /// poll the NC data struct (4sec subscription) |
||
2116 | /// </summary> |
||
2117 | /// <param name="auto"> onetimequery(false) or autoupdate(true) with set timing interval </param> |
||
2118 | private void _readNavData(bool auto) |
||
2119 | { |
||
2120 | byte interval = auto ? navctrlInterval : (byte)0; |
||
2121 | _sendControllerMessage('o', 2, new byte[1] { interval }); |
||
2122 | } |
||
2123 | /// <summary> |
||
2124 | /// get the errortext for pending NC error |
||
2125 | /// </summary> |
||
2126 | private void _readNCError() |
||
2127 | { |
||
2128 | _sendControllerMessage('e', 2); |
||
2129 | } |
||
2130 | /// <summary> |
||
2131 | /// request the Waypoint at index |
||
2132 | /// </summary> |
||
2133 | /// <param name="index"></param> |
||
2134 | void _getpWP(int index) |
||
2135 | { |
||
2136 | if (serialPortCtrl.Port.IsOpen) |
||
2137 | { |
||
2138 | Stream serialStream = serialPortCtrl.Port.BaseStream; |
||
2139 | byte[] bytes = FlightControllerMessage.CreateMessage('x', 2, new byte[1] { (byte)index }); |
||
2140 | serialStream.Write(bytes, 0, bytes.Length); |
||
2141 | } |
||
2142 | else |
||
2143 | Log(LogMsgType.Error, "NOT CONNECTED!"); |
||
2144 | |||
2145 | } |
||
2146 | void _getWP() |
||
2147 | { |
||
2335 | - | 2148 | int iTimeout = 0; |
2287 | - | 2149 | _bGetWPCount = true; |
2315 | - | 2150 | _getpWP(1); //get the itemscount of wp |
2335 | - | 2151 | while (_bGetWPCount & iTimeout < _iWPTimeout * 5) |
2152 | { |
||
2153 | Thread.Sleep(10); |
||
2154 | iTimeout++; |
||
2155 | } |
||
2156 | if (_iWPCount > 0 & !_bGetWPCount) |
||
2287 | - | 2157 | _getWPList(); |
2158 | } |
||
2159 | void _getWPList() |
||
2160 | { |
||
2161 | _bGetWP = true; |
||
2313 | - | 2162 | int iTimeout=0; |
2163 | for (int j = 0; j < _iWPCount; j++) |
||
2287 | - | 2164 | { |
2165 | _getpWP(j + 1); |
||
2313 | - | 2166 | iTimeout = 0; |
2167 | while (_iWPIndex != j + 1 & iTimeout < _iWPTimeout * 5) |
||
2168 | { |
||
2169 | Thread.Sleep(1); |
||
2170 | iTimeout++; |
||
2171 | } |
||
2287 | - | 2172 | } |
2173 | } |
||
2340 | - | 2174 | |
2175 | void clearCopterWPList() |
||
2313 | - | 2176 | { |
2340 | - | 2177 | _clearCopterWPList(); |
2178 | } |
||
2179 | bool _clearCopterWPList() |
||
2180 | { |
||
2335 | - | 2181 | int iTimeout = 0; |
2313 | - | 2182 | if (serialPortCtrl.Port.IsOpen) |
2183 | { |
||
2184 | byte[] bData = new byte[30]; |
||
2185 | for (int i = 0; i < 30; i++) |
||
2186 | bData[i] = 0; |
||
2187 | Stream serialStream = serialPortCtrl.Port.BaseStream; |
||
2188 | byte[] bytes = FlightControllerMessage.CreateMessage('w', 2, bData); //delete all WP on Copter by sending 'invalid'(==0) at index 0 |
||
2189 | serialStream.Write(bytes, 0, bytes.Length); |
||
2287 | - | 2190 | |
2313 | - | 2191 | _iWPCount = -1; |
2340 | - | 2192 | while (_iWPCount == -1 & iTimeout < _iWPTimeout) |
2335 | - | 2193 | { |
2313 | - | 2194 | Thread.Sleep(10); |
2335 | - | 2195 | iTimeout++; |
2196 | } |
||
2313 | - | 2197 | Dispatcher.Invoke(() => lblWPCount.Content = _iWPCount.ToString()); |
2335 | - | 2198 | if (_iWPCount > -1) |
2340 | - | 2199 | return true; |
2200 | else |
||
2201 | Log(LogMsgType.Error, "Timeout while sending list!"); |
||
2202 | } |
||
2203 | else |
||
2204 | Log(LogMsgType.Error, "NOT CONNECTED!"); |
||
2205 | |||
2206 | return false; |
||
2207 | } |
||
2208 | void _sendWPList() |
||
2209 | { |
||
2210 | int iTimeout = 0; |
||
2211 | if (serialPortCtrl.Port.IsOpen) |
||
2212 | { |
||
2213 | if (_clearCopterWPList()) |
||
2313 | - | 2214 | { |
2335 | - | 2215 | for (int i = 0; i < dtWaypoints.Rows.Count; i++) |
2216 | { |
||
2340 | - | 2217 | _sendWayPoint(dtWaypoints.Rows[i],-1); |
2313 | - | 2218 | |
2335 | - | 2219 | _iWPCount = -1; |
2220 | iTimeout = 0; |
||
2221 | while (_iWPCount == -1 & iTimeout < _iWPTimeout * 5) |
||
2222 | { |
||
2223 | Thread.Sleep(10); |
||
2224 | iTimeout++; |
||
2225 | } |
||
2226 | if (_iWPCount == -1) |
||
2227 | { |
||
2228 | Log(LogMsgType.Error, "Timeout while sending list!"); |
||
2229 | break; |
||
2230 | } |
||
2231 | Dispatcher.Invoke(() => lblWPCount.Content = _iWPCount.ToString()); |
||
2232 | } |
||
2313 | - | 2233 | } |
2234 | } |
||
2235 | else |
||
2236 | Log(LogMsgType.Error, "NOT CONNECTED!"); |
||
2237 | |||
2238 | } |
||
2340 | - | 2239 | bool _sendWayPoint(DataRow dr, int index) |
2240 | { |
||
2313 | - | 2241 | |
2340 | - | 2242 | if (serialPortCtrl.Port.IsOpen) |
2243 | { |
||
2244 | byte[] bData = new byte[30]; |
||
2245 | for (int i = 0; i < 30; i++) |
||
2246 | bData[i] = 0; |
||
2247 | Stream serialStream = serialPortCtrl.Port.BaseStream; |
||
2248 | byte[] bytes; |
||
2249 | int iVal; |
||
2250 | double dVal; |
||
2251 | NumberFormatInfo nfi = new NumberFormatInfo(); |
||
2252 | nfi.NumberDecimalSeparator = ","; |
||
2253 | |||
2254 | //longitude |
||
2255 | dVal = Convert.ToDouble(dr[4], nfi); |
||
2256 | iVal = (int)(dVal * Math.Pow(10, 7)); |
||
2257 | bData[0] = (byte)(iVal & 0xff); |
||
2258 | bData[1] = (byte)((iVal >> 8) & 0xff); |
||
2259 | bData[2] = (byte)((iVal >> 16) & 0xff); |
||
2260 | bData[3] = (byte)(iVal >> 24); |
||
2261 | //latitude |
||
2262 | dVal = Convert.ToDouble(dr[3], nfi); |
||
2263 | iVal = (int)(dVal * Math.Pow(10, 7)); |
||
2264 | bData[4] = (byte)(iVal & 0xff); |
||
2265 | bData[5] = (byte)((iVal >> 8) & 0xff); |
||
2266 | bData[6] = (byte)((iVal >> 16) & 0xff); |
||
2267 | bData[7] = (byte)(iVal >> 24); |
||
2268 | //altitude |
||
2269 | dVal = Convert.ToDouble(dr[5], nfi); |
||
2270 | iVal = (int)(dVal * 10); |
||
2271 | bData[8] = (byte)(iVal & 0xff); |
||
2272 | bData[9] = (byte)((iVal >> 8) & 0xff); |
||
2273 | bData[10] = (byte)((iVal >> 16) & 0xff); |
||
2274 | bData[11] = (byte)(iVal >> 24); |
||
2275 | //Status 'NEWDATA' |
||
2276 | bData[12] = 1; |
||
2277 | //heading |
||
2278 | iVal = Convert.ToInt16(dr[6]); |
||
2279 | bData[13] = (byte)(iVal & 0xff); |
||
2280 | bData[14] = (byte)((iVal >> 8) & 0xff); |
||
2281 | //ToleranceRadius |
||
2282 | bData[15] = Convert.ToByte(dr[9]); |
||
2283 | //HoldTime |
||
2284 | bData[16] = Convert.ToByte(dr[10]); |
||
2285 | //Event_Flag |
||
2286 | bData[17] = Convert.ToByte(dr[13]); |
||
2287 | //Index |
||
2288 | bData[18] = index > 0 ? (byte)index : Convert.ToByte((int)dr[0]); |
||
2289 | //Type |
||
2290 | bData[19] = Convert.ToByte(dr[1]); |
||
2291 | //WP_EventChannelValue |
||
2292 | bData[20] = Convert.ToByte(dr[14]); |
||
2293 | //AltitudeRate |
||
2294 | bData[21] = Convert.ToByte(dr[8]); |
||
2295 | //Speed |
||
2296 | bData[22] = Convert.ToByte(dr[7]); |
||
2297 | //CamAngle |
||
2298 | bData[23] = (byte)Convert.ToInt16(dr[12]); |
||
2299 | //Name |
||
2300 | byte[] name = ASCIIEncoding.ASCII.GetBytes((string)dr[2]); |
||
2301 | bData[24] = name.Length > 0 ? name[0] : (byte)0; |
||
2302 | bData[25] = name.Length > 1 ? name[1] : (byte)0; |
||
2303 | bData[26] = name.Length > 2 ? name[2] : (byte)0; |
||
2304 | bData[27] = name.Length > 3 ? name[3] : (byte)0; |
||
2305 | //Autotrigger |
||
2306 | bData[28] = Convert.ToByte(dr[11]); |
||
2307 | |||
2308 | bytes = FlightControllerMessage.CreateMessage('w', 2, bData); |
||
2309 | serialStream.Write(bytes, 0, bytes.Length); |
||
2310 | |||
2311 | return true; |
||
2312 | } |
||
2313 | |||
2314 | return false; |
||
2315 | } |
||
2287 | - | 2316 | #region OSD-Menue |
2317 | |||
2318 | /// <summary> |
||
2319 | /// one time query of the OSD Menue with pagenumber |
||
2320 | /// </summary> |
||
2321 | /// <param name="iMenue">Menue page</param> |
||
2322 | void _OSDMenue(int iMenue) |
||
2323 | { |
||
2324 | if (serialPortCtrl.Port.IsOpen) |
||
2325 | { |
||
2326 | if (iMenue > iOSDMax) |
||
2327 | iMenue = 0; |
||
2328 | Stream serialStream = serialPortCtrl.Port.BaseStream; |
||
2329 | byte[] bytes = FlightControllerMessage.CreateMessage('l', 0, new byte[1] { (byte)iMenue }); |
||
2330 | serialStream.Write(bytes, 0, bytes.Length); |
||
2331 | } |
||
2332 | else |
||
2333 | Log(LogMsgType.Error, "NOT CONNECTED!"); |
||
2334 | |||
2335 | } |
||
2336 | /// <summary> |
||
2337 | /// call the OSDMenue and start autorefresh |
||
2338 | /// usually by sending a menuekey |
||
2339 | /// a bit tricky - but by sending inverted value of 32 (32 = 0010 0000) you can start the OSD menue with autoupdate (abo) without switching the page with the keyvalues (0x1, 0x2) |
||
2340 | /// therefore the value has to be negative (inverted) in order to distinguish from old (2 line) menuestyle |
||
2341 | /// and must not have any bits of the menue keys 0x1 0x2 0x4 0x8 (0x10?) --> 0x20 = -33 |
||
2342 | /// </summary> |
||
2343 | void _OSDMenueAutoRefresh() |
||
2344 | { |
||
2345 | _sendControllerMessage('h', 0, new byte[2] { unchecked((byte)(-33)), OSDInterval }); |
||
2346 | } |
||
2347 | void _OSDMenueAutoRefresh(byte key) |
||
2348 | { |
||
2349 | _sendControllerMessage('h', 0, new byte[2] { unchecked((byte)~key), OSDInterval }); |
||
2350 | } |
||
2351 | /// <summary> |
||
2352 | /// initialize the OSD menue combobox |
||
2353 | /// combox is filled by numbers from 0 to max pagenumber |
||
2354 | /// </summary> |
||
2355 | void _initOSDCB() |
||
2356 | { |
||
2357 | _bCBInit = true; |
||
2358 | if (iOSDMax == 0) |
||
2359 | { |
||
2360 | _OSDMenue(0); |
||
2361 | Thread.Sleep(10); |
||
2362 | } |
||
2363 | Dispatcher.Invoke((Action)(() => cbOSD.Items.Clear())); |
||
2364 | for (int i = 0; i <= iOSDMax; i++) |
||
2365 | { |
||
2366 | Dispatcher.Invoke((Action)(() => cbOSD.Items.Add(i))); |
||
2367 | } |
||
2368 | Dispatcher.Invoke((Action)(() => cbOSD.SelectedItem = iOSDPage)); |
||
2369 | _bCBInit = false; |
||
2370 | } |
||
2371 | private void btnOSDForward_Click(object sender, RoutedEventArgs e) |
||
2372 | { |
||
2373 | iOSDPage++; |
||
2374 | if (iOSDPage > iOSDMax) |
||
2375 | iOSDPage = 0; |
||
2376 | |||
2377 | _OSDMenue(iOSDPage); |
||
2378 | } |
||
2379 | private void btnOSDBackward_Click(object sender, RoutedEventArgs e) |
||
2380 | { |
||
2381 | iOSDPage--; |
||
2382 | if (iOSDPage < 0) |
||
2383 | iOSDPage = iOSDMax; |
||
2384 | |||
2385 | _OSDMenue(iOSDPage); |
||
2386 | } |
||
2387 | private void btnOSDLeave_Click(object sender, RoutedEventArgs e) |
||
2388 | { |
||
2389 | _OSDMenueAutoRefresh(8); |
||
2390 | } |
||
2391 | private void btnOSDEnter_Click(object sender, RoutedEventArgs e) |
||
2392 | { |
||
2393 | _OSDMenueAutoRefresh(4); |
||
2394 | } |
||
2395 | private void cbOSD_DropDownClosing(object sender, EventArgs e) |
||
2396 | { |
||
2397 | if (!_bCBInit && cbOSD.SelectedIndex > -1) |
||
2398 | _OSDMenue(cbOSD.SelectedIndex); |
||
2399 | } |
||
2400 | private void OSD(LogMsgType msgtype, string msg, bool bNew) |
||
2401 | { |
||
2402 | Dispatcher.Invoke(() => |
||
2403 | { |
||
2404 | TextRange tr; |
||
2405 | if (bNew) |
||
2406 | { |
||
2407 | rtfOSD.SelectAll(); |
||
2408 | rtfOSD.Selection.Text = string.Empty; |
||
2409 | } |
||
2410 | tr = new TextRange(rtfOSD.Document.ContentEnd, rtfOSD.Document.ContentEnd); |
||
2411 | tr.Text = msg; |
||
2412 | tr.ApplyPropertyValue(TextElement.ForegroundProperty, new SolidColorBrush(LogMsgTypeColor[(int)msgtype])); |
||
2413 | // rtfOSD.AppendText("\r"); |
||
2414 | rtfOSD.ScrollToEnd(); |
||
2415 | |||
2416 | }); |
||
2417 | } |
||
2418 | |||
2419 | #endregion OSD-Menue |
||
2420 | |||
2421 | #endregion controller messages |
||
2422 | |||
2295 | - | 2423 | void _mediaPlayer(string file) |
2424 | { |
||
2425 | if (File.Exists(file)) |
||
2426 | { |
||
2427 | MediaPlayer.MediaPlayer mp = new MediaPlayer.MediaPlayer(); |
||
2428 | mp.Open(file); |
||
2429 | mp.Play(); |
||
2430 | } |
||
2431 | } |
||
2310 | - | 2432 | |
2433 | /// <summary> |
||
2434 | /// Switch between fullscreen and normal window mode |
||
2435 | /// save & restore scaling settings |
||
2436 | /// </summary> |
||
2437 | /// <param name="sender"></param> |
||
2438 | /// <param name="e"></param> |
||
2287 | - | 2439 | private void imageFullscreen_MouseDown(object sender, MouseButtonEventArgs e) |
2440 | { |
||
2441 | if (winState.isMaximized) |
||
2442 | { |
||
2443 | winState.Restore(this); |
||
2444 | imageFullscreen.Source = new BitmapImage(new Uri("Images/Fullscreen.png", UriKind.Relative)); |
||
2445 | if(_bSaveWinStateFull) |
||
2446 | _saveScaleSliders(true); |
||
2447 | if(_bSaveWinStateNormal) |
||
2448 | _setScaleSliders(false); |
||
2449 | } |
||
2450 | else |
||
2451 | { |
||
2452 | winState.Maximize(this); |
||
2453 | imageFullscreen.Source = new BitmapImage(new Uri("Images/RestoreScreen.png", UriKind.Relative)); |
||
2454 | if(_bSaveWinStateNormal) |
||
2455 | _saveScaleSliders(false); |
||
2456 | if(_bSaveWinStateFull) |
||
2457 | _setScaleSliders(true); |
||
2458 | } |
||
2459 | } |
||
2460 | |||
2461 | /// <summary> |
||
2462 | /// reset the scaling of all UI elements to default |
||
2463 | /// </summary> |
||
2464 | /// <param name="sender"></param> |
||
2465 | /// <param name="e"></param> |
||
2466 | private void buttonUIScaleReset_Click(object sender, RoutedEventArgs e) |
||
2467 | { |
||
2468 | UIScaleHorizonSlider.Value = |
||
2469 | UIScaleLOGSlider.Value = |
||
2470 | UIScaleMotorsSlider.Value = |
||
2471 | UIScaleOSDSlider.Value = |
||
2472 | UIScaleSlider.Value = |
||
2473 | UIScaleTopSlider.Value = 1; |
||
2474 | } |
||
2475 | /// <summary> |
||
2476 | /// adjust the top postion of UI elements below the top bar to fit the bottom position of the bar when scaling the top bar |
||
2477 | /// </summary> |
||
2478 | /// <param name="sender"></param> |
||
2479 | /// <param name="e"></param> |
||
2480 | private void UIScaleTopSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) |
||
2481 | { |
||
2482 | GridSettings.Margin = new Thickness(GridSettings.Margin.Left, 36 * UIScaleTopSlider.Value, GridSettings.Margin.Right, GridSettings.Margin.Bottom); |
||
2483 | if (GridMotors != null) |
||
2484 | GridMotors.Margin = new Thickness(GridMotors.Margin.Left, 36 * UIScaleTopSlider.Value, GridMotors.Margin.Right, GridMotors.Margin.Bottom); |
||
2485 | if (GridSideBar != null) |
||
2486 | GridSideBar.Margin = new Thickness(GridSideBar.Margin.Left, 36 * UIScaleTopSlider.Value, GridSideBar.Margin.Right, GridSideBar.Margin.Bottom); |
||
2487 | if (GridOSD != null) |
||
2488 | GridOSD.Margin = new Thickness(GridOSD.Margin.Left, 36 * UIScaleTopSlider.Value, GridOSD.Margin.Right, GridOSD.Margin.Bottom); |
||
2489 | if (GridData != null) |
||
2490 | GridData.Margin = new Thickness(GridData.Margin.Left, 36 * UIScaleTopSlider.Value, GridData.Margin.Right, GridData.Margin.Bottom); |
||
2491 | if (GridWP != null) |
||
2492 | GridWP.Margin = new Thickness(GridWP.Margin.Left, 36 * UIScaleTopSlider.Value, GridWP.Margin.Right, GridWP.Margin.Bottom); |
||
2493 | } |
||
2310 | - | 2494 | /// <summary> |
2495 | /// restore the saved scalings for the fullscreen/normal window mode |
||
2496 | /// </summary> |
||
2497 | /// <param name="bFull">the mode the window is set to</param> |
||
2287 | - | 2498 | void _setScaleSliders(bool bFull) |
2499 | { |
||
2500 | if(bFull) |
||
2501 | { |
||
2502 | UIScaleSlider.Value = scaleFullAll; |
||
2503 | UIScaleTopSlider.Value = scaleFullTopBar; |
||
2504 | UIScaleMotorsSlider.Value = scaleFullMotors; |
||
2505 | UIScaleOSDSlider.Value = scaleFullOSD; |
||
2506 | UIScaleLOGSlider.Value = scaleFullLOG; |
||
2507 | UIScaleHorizonSlider.Value = scaleFullHorizon; |
||
2508 | } |
||
2509 | else |
||
2510 | { |
||
2511 | UIScaleSlider.Value = scaleNormalAll; |
||
2512 | UIScaleTopSlider.Value = scaleNormalTopBar; |
||
2513 | UIScaleMotorsSlider.Value = scaleNormalMotors; |
||
2514 | UIScaleOSDSlider.Value = scaleNormalOSD; |
||
2515 | UIScaleLOGSlider.Value = scaleNormalLOG; |
||
2516 | UIScaleHorizonSlider.Value = scaleNormalHorizon; |
||
2517 | } |
||
2518 | } |
||
2519 | |||
2310 | - | 2520 | /// <summary> |
2521 | /// save the scalings for the actual window mode |
||
2522 | /// </summary> |
||
2523 | /// <param name="bFull">the actual window mode</param> |
||
2287 | - | 2524 | void _saveScaleSliders(bool bFull) |
2525 | { |
||
2526 | |||
2527 | if (bFull) |
||
2528 | { |
||
2529 | scaleFullAll = UIScaleSlider.Value; |
||
2530 | scaleFullTopBar = UIScaleTopSlider.Value; |
||
2531 | scaleFullMotors = UIScaleMotorsSlider.Value; |
||
2532 | scaleFullOSD = UIScaleOSDSlider.Value; |
||
2533 | scaleFullLOG = UIScaleLOGSlider.Value; |
||
2534 | scaleFullHorizon = UIScaleHorizonSlider.Value; |
||
2535 | } |
||
2536 | else |
||
2537 | { |
||
2538 | scaleNormalAll = UIScaleSlider.Value; |
||
2539 | scaleNormalTopBar = UIScaleTopSlider.Value; |
||
2540 | scaleNormalMotors = UIScaleMotorsSlider.Value; |
||
2541 | scaleNormalOSD = UIScaleOSDSlider.Value; |
||
2542 | scaleNormalLOG = UIScaleLOGSlider.Value; |
||
2543 | scaleNormalHorizon = UIScaleHorizonSlider.Value; |
||
2544 | } |
||
2545 | } |
||
2546 | |||
2547 | /// <summary> |
||
2548 | /// read settings from ini-file |
||
2549 | /// </summary> |
||
2550 | void _readIni() |
||
2551 | { |
||
2552 | if (!File.Exists(filePath + "\\MKLiveViewSettings.ini")) |
||
2553 | _writeIni(); |
||
2554 | IniFile ini = new IniFile("MKLiveViewSettings.ini"); |
||
2555 | ini.path = filePath + "\\MKLiveViewSettings.ini"; |
||
2312 | - | 2556 | try |
2557 | { |
||
2287 | - | 2558 | |
2312 | - | 2559 | string sVal = ini.IniReadValue("timings", "AutorefreshDebugData"); |
2560 | if (sVal != "") _debugDataAutorefresh = Convert.ToBoolean(sVal); |
||
2561 | sVal = ini.IniReadValue("timings", "AutorefreshNavCtrlData"); |
||
2562 | if (sVal != "") _navCtrlDataAutorefresh = Convert.ToBoolean(sVal); |
||
2563 | sVal = ini.IniReadValue("timings", "AutorefreshBLCtrlData"); |
||
2564 | if (sVal != "") _blctrlDataAutorefresh = Convert.ToBoolean(sVal); |
||
2565 | sVal = ini.IniReadValue("timings", "AutorefreshOSDData"); |
||
2566 | if (sVal != "") _OSDAutorefresh = Convert.ToBoolean(sVal); |
||
2287 | - | 2567 | |
2312 | - | 2568 | sVal = ini.IniReadValue("timings", "IntervalDebugData"); |
2569 | if (sVal != "") debugInterval = (byte)Convert.ToInt16(sVal); |
||
2570 | sVal = ini.IniReadValue("timings", "IntervalNavCtrlData"); |
||
2571 | if (sVal != "") navctrlInterval = (byte)Convert.ToInt16(sVal); |
||
2572 | sVal = ini.IniReadValue("timings", "IntervalBLCtrlData"); |
||
2573 | if (sVal != "") blctrlInterval = (byte)Convert.ToInt16(sVal); |
||
2574 | sVal = ini.IniReadValue("timings", "IntervalOSDData"); |
||
2575 | if (sVal != "") OSDInterval = (byte)Convert.ToInt16(sVal); |
||
2287 | - | 2576 | |
2312 | - | 2577 | sVal = ini.IniReadValue("topBar", "voltage"); |
2578 | if (sVal != "") chkBoxTopBarShowVoltage.IsChecked = Convert.ToBoolean(sVal); |
||
2579 | sVal = ini.IniReadValue("topBar", "capacity"); |
||
2580 | if (sVal != "") chkBoxTopBarShowCapacity.IsChecked = Convert.ToBoolean(sVal); |
||
2581 | sVal = ini.IniReadValue("topBar", "current"); |
||
2582 | if (sVal != "") chkBoxTopBarShowCurrent.IsChecked = Convert.ToBoolean(sVal); |
||
2583 | sVal = ini.IniReadValue("topBar", "flightTime"); |
||
2584 | if (sVal != "") chkBoxTopBarShowFlightTime.IsChecked = Convert.ToBoolean(sVal); |
||
2585 | sVal = ini.IniReadValue("topBar", "distanceHP"); |
||
2586 | if (sVal != "") chkBoxTopBarShowDistanceHP.IsChecked = Convert.ToBoolean(sVal); |
||
2587 | sVal = ini.IniReadValue("topBar", "height"); |
||
2588 | if (sVal != "") chkBoxTopBarShowHeight.IsChecked = Convert.ToBoolean(sVal); |
||
2589 | sVal = ini.IniReadValue("topBar", "speed"); |
||
2590 | if (sVal != "") chkBoxTopBarShowSpeed.IsChecked = Convert.ToBoolean(sVal); |
||
2591 | sVal = ini.IniReadValue("topBar", "magneticField"); |
||
2592 | if (sVal != "") chkBoxTopBarShowMF.IsChecked = Convert.ToBoolean(sVal); |
||
2593 | sVal = ini.IniReadValue("topBar", "satellites"); |
||
2594 | if (sVal != "") chkBoxTopBarShowSatellites.IsChecked = Convert.ToBoolean(sVal); |
||
2595 | sVal = ini.IniReadValue("topBar", "rc"); |
||
2596 | if (sVal != "") chkBoxTopBarShowRC.IsChecked = Convert.ToBoolean(sVal); |
||
2287 | - | 2597 | |
2312 | - | 2598 | sVal = ini.IniReadValue("style", "saveFullScreen"); |
2599 | if (sVal != "") chkBoxSaveFullScreenState.IsChecked = Convert.ToBoolean(sVal); |
||
2600 | sVal = ini.IniReadValue("style", "saveNormalState"); |
||
2601 | if (sVal != "") chkBoxSaveNormalState.IsChecked = Convert.ToBoolean(sVal); |
||
2287 | - | 2602 | |
2312 | - | 2603 | sVal = ini.IniReadValue("style", "scaleNormalAll"); |
2604 | if (sVal != "") scaleNormalAll = Convert.ToDouble(sVal); |
||
2605 | sVal = ini.IniReadValue("style", "scaleNormalTopBar"); |
||
2606 | if (sVal != "") scaleNormalTopBar = Convert.ToDouble(sVal); |
||
2607 | sVal = ini.IniReadValue("style", "scaleNormalMotors"); |
||
2608 | if (sVal != "") scaleNormalMotors = Convert.ToDouble(sVal); |
||
2609 | sVal = ini.IniReadValue("style", "scaleNormalOSD"); |
||
2610 | if (sVal != "") scaleNormalOSD = Convert.ToDouble(sVal); |
||
2611 | sVal = ini.IniReadValue("style", "scaleNormalLOG"); |
||
2612 | if (sVal != "") scaleNormalLOG = Convert.ToDouble(sVal); |
||
2613 | sVal = ini.IniReadValue("style", "scaleNormalHorizon"); |
||
2614 | if (sVal != "") scaleNormalHorizon = Convert.ToDouble(sVal); |
||
2287 | - | 2615 | |
2312 | - | 2616 | sVal = ini.IniReadValue("style", "scaleFullAll"); |
2617 | if (sVal != "") scaleFullAll = Convert.ToDouble(sVal); |
||
2618 | sVal = ini.IniReadValue("style", "scaleFullTopBar"); |
||
2619 | if (sVal != "") scaleFullTopBar = Convert.ToDouble(sVal); |
||
2620 | sVal = ini.IniReadValue("style", "scaleFullMotors"); |
||
2621 | if (sVal != "") scaleFullMotors = Convert.ToDouble(sVal); |
||
2622 | sVal = ini.IniReadValue("style", "scaleFullOSD"); |
||
2623 | if (sVal != "") scaleFullOSD = Convert.ToDouble(sVal); |
||
2624 | sVal = ini.IniReadValue("style", "scaleFullLOG"); |
||
2625 | if (sVal != "") scaleFullLOG = Convert.ToDouble(sVal); |
||
2626 | sVal = ini.IniReadValue("style", "scaleFullHorizon"); |
||
2627 | if (sVal != "") scaleFullHorizon = Convert.ToDouble(sVal); |
||
2287 | - | 2628 | |
2312 | - | 2629 | sVal = ini.IniReadValue("general", "LiPoCells"); |
2630 | _LipoCells = Convert.ToInt16(sVal); |
||
2631 | sVal = ini.IniReadValue("general", "Motors"); |
||
2632 | if (sVal != "") _iMotors = Convert.ToInt16(sVal); |
||
2287 | - | 2633 | |
2312 | - | 2634 | sVal = ini.IniReadValue("map", "followMe"); |
2635 | if (sVal != "") _bFollowCopter = Convert.ToBoolean(sVal); |
||
2636 | sVal = ini.IniReadValue("map", "AutoSetHome"); |
||
2637 | if (sVal != "") _bAutoHome = Convert.ToBoolean(sVal); |
||
2324 | - | 2638 | sVal = ini.IniReadValue("map", "GPXLog"); |
2639 | if (sVal != "") _bGPXLog = Convert.ToBoolean(sVal); |
||
2287 | - | 2640 | |
2312 | - | 2641 | sVal = ini.IniReadValue("threshold", "VoltageWarning"); |
2642 | if(sVal != "") _dThresholdVoltageWarn = Convert.ToDouble(sVal); |
||
2643 | sVal = ini.IniReadValue("threshold", "VoltageCritical"); |
||
2644 | if(sVal != "") _dThresholdVoltageCrit = Convert.ToDouble(sVal); |
||
2645 | sVal = ini.IniReadValue("threshold", "VoiceVoltageEnable"); |
||
2646 | if(sVal != "") _bVoiceVoltPlay = Convert.ToBoolean(sVal); |
||
2647 | sVal = ini.IniReadValue("threshold", "VoiceSatFixEnable"); |
||
2648 | if(sVal != "") _bVoiceSatFixPlay = Convert.ToBoolean(sVal); |
||
2649 | sVal = ini.IniReadValue("threshold", "VoiceMagFieldEnable"); |
||
2650 | if(sVal != "") _bVoiceMagneticFieldPlay = Convert.ToBoolean(sVal); |
||
2651 | sVal = ini.IniReadValue("threshold", "DistanceWarning"); |
||
2652 | if(sVal != "") _dThresholdDistanceWarn = Convert.ToDouble(sVal); |
||
2653 | sVal = ini.IniReadValue("threshold", "VoiceDistanceWarnEnable"); |
||
2654 | if(sVal != "") _bVoiceDistancePlay = Convert.ToBoolean(sVal); |
||
2655 | sVal = ini.IniReadValue("threshold", "VoiceRCLevelWarnEnable"); |
||
2656 | if(sVal != "") _bVoiceRCLevelPlay = Convert.ToBoolean(sVal); |
||
2657 | sVal = ini.IniReadValue("threshold", "MaxDistance"); |
||
2658 | if(sVal != "") _dThresholdDistanceMax = Convert.ToDouble(sVal); |
||
2659 | sVal = ini.IniReadValue("threshold", "RCThreshold"); |
||
2660 | if(sVal != "") _iThresholdRC = Convert.ToInt32(sVal); |
||
2661 | sVal = ini.IniReadValue("threshold", "MagFieldThreshold"); |
||
2662 | if(sVal != "") _iThresholdMagField = Convert.ToInt32(sVal); |
||
2321 | - | 2663 | |
2664 | sVal = ini.IniReadValue("waypoints", "wpcolor"); |
||
2665 | if(sVal != "") comboBoxWPColor.SelectedIndex = Convert.ToInt32(sVal); |
||
2666 | sVal = ini.IniReadValue("waypoints", "poicolor"); |
||
2667 | if(sVal != "") comboBoxPOIColor.SelectedIndex = Convert.ToInt32(sVal); |
||
2668 | sVal = ini.IniReadValue("waypoints", "fscolor"); |
||
2669 | if(sVal != "") comboBoxFSColor.SelectedIndex = Convert.ToInt32(sVal); |
||
2670 | sVal = ini.IniReadValue("waypoints", "coptercolor"); |
||
2671 | if(sVal != "") comboBoxCopterColor.SelectedIndex = Convert.ToInt32(sVal); |
||
2328 | - | 2672 | sVal = ini.IniReadValue("waypoints", "routecolor"); |
2673 | if(sVal != "") comboBoxRouteColor.SelectedIndex = Convert.ToInt32(sVal); |
||
2674 | sVal = ini.IniReadValue("waypoints", "showWPRoute"); |
||
2675 | if(sVal != "") _bShowWPRoute = Convert.ToBoolean(sVal); |
||
2312 | - | 2676 | } |
2677 | catch (Exception e) |
||
2678 | { |
||
2287 | - | 2679 | |
2312 | - | 2680 | MessageBox.Show("Error parsing ini-file!" + Environment.NewLine + e.Message,"Read ini-file" ,MessageBoxButton.OK,MessageBoxImage.Error); |
2681 | } |
||
2682 | |||
2287 | - | 2683 | } |
2684 | |||
2685 | /// <summary> |
||
2686 | /// save settings to ini-file |
||
2687 | /// </summary> |
||
2688 | void _writeIni() |
||
2689 | { |
||
2690 | |||
2691 | IniFile ini = new IniFile("MKLiveViewSettings.ini"); |
||
2692 | ini.path = filePath + "\\MKLiveViewSettings.ini"; |
||
2693 | |||
2312 | - | 2694 | try |
2695 | { |
||
2287 | - | 2696 | |
2312 | - | 2697 | ini.IniWriteValue("timings", "AutorefreshDebugData", _debugDataAutorefresh ? "true" : "false"); |
2698 | ini.IniWriteValue("timings", "AutorefreshNavCtrlData", _navCtrlDataAutorefresh ? "true" : "false"); |
||
2699 | ini.IniWriteValue("timings", "AutorefreshBLCtrlData", _blctrlDataAutorefresh ? "true" : "false"); |
||
2700 | ini.IniWriteValue("timings", "AutorefreshOSDData", _OSDAutorefresh ? "true" : "false"); |
||
2287 | - | 2701 | |
2312 | - | 2702 | ini.IniWriteValue("timings", "IntervalDebugData", debugInterval.ToString()); |
2703 | ini.IniWriteValue("timings", "IntervalNavCtrlData", navctrlInterval.ToString()); |
||
2704 | ini.IniWriteValue("timings", "IntervalBLCtrlData", blctrlInterval.ToString()); |
||
2705 | ini.IniWriteValue("timings", "IntervalOSDData", OSDInterval.ToString()); |
||
2287 | - | 2706 | |
2312 | - | 2707 | ini.IniWriteValue("general", "LiPoCells", _LipoCells.ToString()); |
2708 | ini.IniWriteValue("general", "Motors", _iMotors.ToString()); |
||
2287 | - | 2709 | |
2312 | - | 2710 | ini.IniWriteValue("map", "followMe", _bFollowCopter.ToString()); |
2711 | ini.IniWriteValue("map", "AutoSetHome", _bAutoHome.ToString()); |
||
2324 | - | 2712 | ini.IniWriteValue("map", "GPXLog", _bGPXLog.ToString()); |
2287 | - | 2713 | |
2312 | - | 2714 | ini.IniWriteValue("topBar", "voltage", chkBoxTopBarShowVoltage.IsChecked.ToString()); |
2715 | ini.IniWriteValue("topBar", "capacity", chkBoxTopBarShowCapacity.IsChecked.ToString()); |
||
2716 | ini.IniWriteValue("topBar", "current", chkBoxTopBarShowCurrent.IsChecked.ToString()); |
||
2717 | ini.IniWriteValue("topBar", "flightTime", chkBoxTopBarShowFlightTime.IsChecked.ToString()); |
||
2718 | ini.IniWriteValue("topBar", "distanceHP", chkBoxTopBarShowDistanceHP.IsChecked.ToString()); |
||
2719 | ini.IniWriteValue("topBar", "height", chkBoxTopBarShowHeight.IsChecked.ToString()); |
||
2720 | ini.IniWriteValue("topBar", "speed", chkBoxTopBarShowSpeed.IsChecked.ToString()); |
||
2721 | ini.IniWriteValue("topBar", "magneticField", chkBoxTopBarShowMF.IsChecked.ToString()); |
||
2722 | ini.IniWriteValue("topBar", "satellites", chkBoxTopBarShowSatellites.IsChecked.ToString()); |
||
2723 | ini.IniWriteValue("topBar", "rc", chkBoxTopBarShowRC.IsChecked.ToString()); |
||
2287 | - | 2724 | |
2312 | - | 2725 | ini.IniWriteValue("style", "saveFullScreen", chkBoxSaveFullScreenState.IsChecked.ToString()); |
2726 | ini.IniWriteValue("style", "saveNormalState", chkBoxSaveNormalState.IsChecked.ToString()); |
||
2287 | - | 2727 | |
2312 | - | 2728 | ini.IniWriteValue("style", "scaleNormalAll", scaleNormalAll.ToString()); |
2729 | ini.IniWriteValue("style", "scaleNormalTopBar", scaleNormalTopBar.ToString()); |
||
2730 | ini.IniWriteValue("style", "scaleNormalMotors", scaleNormalMotors.ToString()); |
||
2731 | ini.IniWriteValue("style", "scaleNormalOSD", scaleNormalOSD.ToString()); |
||
2732 | ini.IniWriteValue("style", "scaleNormalLOG", scaleNormalLOG.ToString()); |
||
2733 | ini.IniWriteValue("style", "scaleNormalHorizon", scaleNormalHorizon.ToString()); |
||
2287 | - | 2734 | |
2312 | - | 2735 | ini.IniWriteValue("style", "scaleFullAll", scaleFullAll.ToString()); |
2736 | ini.IniWriteValue("style", "scaleFullTopBar", scaleFullTopBar.ToString()); |
||
2737 | ini.IniWriteValue("style", "scaleFullMotors", scaleFullMotors.ToString()); |
||
2738 | ini.IniWriteValue("style", "scaleFullOSD", scaleFullOSD.ToString()); |
||
2739 | ini.IniWriteValue("style", "scaleFullLOG", scaleFullLOG.ToString()); |
||
2740 | ini.IniWriteValue("style", "scaleFullHorizon", scaleFullHorizon.ToString()); |
||
2287 | - | 2741 | |
2312 | - | 2742 | ini.IniWriteValue("style", "horizon", chkBoxShowHorizon.IsChecked.ToString()); |
2743 | |||
2744 | ini.IniWriteValue("threshold", "VoltageWarning", _dThresholdVoltageWarn.ToString()); |
||
2745 | ini.IniWriteValue("threshold", "VoltageCritical", _dThresholdVoltageCrit.ToString()); |
||
2746 | ini.IniWriteValue("threshold", "VoiceVoltageEnable", _bVoiceVoltPlay.ToString()); |
||
2747 | ini.IniWriteValue("threshold", "VoiceSatFixEnable", _bVoiceSatFixPlay.ToString()); |
||
2748 | ini.IniWriteValue("threshold", "VoiceMagFieldEnable", _bVoiceMagneticFieldPlay.ToString()); |
||
2749 | ini.IniWriteValue("threshold", "VoiceDistanceWarnEnable", _bVoiceDistancePlay.ToString()); |
||
2750 | ini.IniWriteValue("threshold", "VoiceRCLevelWarnEnable", _bVoiceRCLevelPlay.ToString()); |
||
2751 | ini.IniWriteValue("threshold", "DistanceWarning", _dThresholdDistanceWarn.ToString()); |
||
2752 | ini.IniWriteValue("threshold", "MaxDistance", _dThresholdDistanceMax.ToString()); |
||
2753 | ini.IniWriteValue("threshold", "RCThreshold", _iThresholdRC.ToString()); |
||
2754 | ini.IniWriteValue("threshold", "MagFieldThreshold", _iThresholdMagField.ToString()); |
||
2321 | - | 2755 | |
2756 | ini.IniWriteValue("waypoints", "wpcolor", comboBoxWPColor.SelectedIndex.ToString()); |
||
2757 | ini.IniWriteValue("waypoints", "poicolor", comboBoxPOIColor.SelectedIndex.ToString()); |
||
2758 | ini.IniWriteValue("waypoints", "fscolor", comboBoxFSColor.SelectedIndex.ToString()); |
||
2759 | ini.IniWriteValue("waypoints", "coptercolor", comboBoxCopterColor.SelectedIndex.ToString()); |
||
2328 | - | 2760 | ini.IniWriteValue("waypoints", "routecolor", comboBoxRouteColor.SelectedIndex.ToString()); |
2761 | ini.IniWriteValue("waypoints", "showWPRoute", _bShowWPRoute.ToString()); |
||
2312 | - | 2762 | } |
2763 | catch (Exception e) |
||
2764 | { |
||
2765 | |||
2766 | MessageBox.Show("Error writing ini-file!" + Environment.NewLine + "Please make sure that the programm is in a location where it is allowed to write" + Environment.NewLine + e.Message, "Write ini-file", MessageBoxButton.OK, MessageBoxImage.Error); |
||
2767 | } |
||
2287 | - | 2768 | } |
2312 | - | 2769 | |
2315 | - | 2770 | #region WP |
2312 | - | 2771 | void _readWPLFile() |
2772 | { |
||
2773 | Microsoft.Win32.OpenFileDialog fd = new Microsoft.Win32.OpenFileDialog(); |
||
2774 | fd.Filter = "Waypointlists | *.wpl"; |
||
2775 | fd.Multiselect = false; |
||
2776 | if (fd.ShowDialog().Value) |
||
2777 | { |
||
2778 | string file = fd.SafeFileName; |
||
2779 | IniFile ini = new IniFile(fd.SafeFileName); |
||
2780 | ini.path = fd.FileName; |
||
2781 | |||
2782 | try |
||
2783 | { |
||
2784 | string sVal = ini.IniReadValue("General", "FileVersion"); |
||
2785 | if (sVal == "") |
||
2786 | MessageBox.Show("The file has no version declared - can't go on...", "", MessageBoxButton.OK, MessageBoxImage.Information); |
||
2787 | else |
||
2788 | { |
||
2789 | if (Convert.ToInt16(sVal) < 3) |
||
2790 | MessageBox.Show("The file version is not supported - can't go on...", "", MessageBoxButton.OK, MessageBoxImage.Information); |
||
2791 | else |
||
2792 | { |
||
2793 | sVal = ini.IniReadValue("General", "NumberOfWaypoints"); |
||
2794 | if (sVal == "") |
||
2795 | MessageBox.Show("The file has no number of waypoints declared - can't go on...", "", MessageBoxButton.OK, MessageBoxImage.Information); |
||
2796 | else |
||
2797 | { |
||
2798 | int wpnum = Convert.ToInt16(sVal); |
||
2799 | string wp; |
||
2800 | int i; |
||
2313 | - | 2801 | NumberFormatInfo nfi = new NumberFormatInfo(); |
2802 | nfi.NumberDecimalSeparator = "."; |
||
2312 | - | 2803 | dtWaypoints.Rows.Clear(); |
2327 | - | 2804 | //for(int k = 0; k < MainMap.Markers.Count;) |
2805 | //{ |
||
2806 | // GMapMarker p = MainMap.Markers[k]; |
||
2807 | // if (p.Shape.GetType() == typeof(CustomMarkerWP)) |
||
2808 | // MainMap.Markers.Remove(p); |
||
2809 | // else |
||
2810 | // k++; |
||
2811 | //} |
||
2812 | _clearMapMarkers(typeof(CustomMarkerWP)); |
||
2328 | - | 2813 | wpList.Clear(); |
2814 | if (mRouteWP != null) |
||
2815 | MainMap.Markers.Remove(mRouteWP); |
||
2342 | - | 2816 | if (wpActiveMarker != null) |
2817 | MainMap.Markers.Remove(wpActiveMarker); |
||
2328 | - | 2818 | Dispatcher.Invoke(() => lblWPRouteDistance.Content = "0 m"); |
2819 | |||
2312 | - | 2820 | for (int k = 1; k <= wpnum; k++) |
2821 | { |
||
2822 | DataRow dr = dtWaypoints.NewRow(); |
||
2823 | dr.ItemArray = new object[16]; |
||
2824 | object[] o = new object[16]; |
||
2825 | i = 0; |
||
2826 | wp = "Point" + k.ToString(); |
||
2827 | o[i] = k; |
||
2828 | i++; |
||
2829 | sVal = ini.IniReadValue(wp, "Type"); |
||
2830 | if (sVal != "") |
||
2315 | - | 2831 | o[i] = Convert.ToInt16(sVal) - 1; |
2312 | - | 2832 | i++; |
2833 | sVal = ini.IniReadValue(wp, "Prefix"); |
||
2834 | if (sVal != "") |
||
2835 | o[i] = sVal == "0" ? "P" + k.ToString() : sVal + k.ToString(); |
||
2836 | i++; |
||
2313 | - | 2837 | sVal = ini.IniReadValue(wp, "Latitude"); |
2312 | - | 2838 | if (sVal != "") |
2313 | - | 2839 | o[i] = Convert.ToDouble(sVal, nfi); |
2312 | - | 2840 | i++; |
2313 | - | 2841 | sVal = ini.IniReadValue(wp, "Longitude"); |
2312 | - | 2842 | if (sVal != "") |
2313 | - | 2843 | o[i] = Convert.ToDouble(sVal, nfi); |
2312 | - | 2844 | i++; |
2845 | sVal = ini.IniReadValue(wp, "Altitude"); |
||
2846 | if (sVal != "") |
||
2313 | - | 2847 | o[i] = Convert.ToDouble(sVal, nfi); |
2312 | - | 2848 | i++; |
2849 | sVal = ini.IniReadValue(wp, "Heading"); |
||
2850 | if (sVal != "") |
||
2851 | o[i] = Convert.ToInt16(sVal); |
||
2852 | i++; |
||
2853 | sVal = ini.IniReadValue(wp, "Speed"); |
||
2854 | if (sVal != "") |
||
2315 | - | 2855 | o[i] = Convert.ToInt16(sVal); |
2312 | - | 2856 | i++; |
2857 | sVal = ini.IniReadValue(wp, "ClimbRate"); |
||
2858 | if (sVal != "") |
||
2859 | o[i] = Convert.ToInt16(sVal); |
||
2860 | i++; |
||
2861 | sVal = ini.IniReadValue(wp, "Radius"); |
||
2862 | if (sVal != "") |
||
2863 | o[i] = Convert.ToInt16(sVal); |
||
2864 | i++; |
||
2865 | sVal = ini.IniReadValue(wp, "DelayTime"); |
||
2866 | if (sVal != "") |
||
2867 | o[i] = Convert.ToInt16(sVal); |
||
2868 | i++; |
||
2869 | sVal = ini.IniReadValue(wp, "AutoTrigger"); |
||
2870 | if (sVal != "") |
||
2871 | o[i] = Convert.ToInt16(sVal); ; |
||
2872 | i++; |
||
2873 | sVal = ini.IniReadValue(wp, "CAM-Nick"); |
||
2874 | if (sVal != "") |
||
2313 | - | 2875 | o[i] = Convert.ToInt16(sVal); |
2312 | - | 2876 | i++; |
2877 | o[i] = 0; |
||
2878 | i++; |
||
2879 | sVal = ini.IniReadValue(wp, "WP_Event_Channel_Value"); |
||
2880 | if (sVal != "") |
||
2881 | o[i] = Convert.ToInt16(sVal); |
||
2882 | i++; |
||
2883 | o[i] = "New"; |
||
2884 | |||
2885 | dr.ItemArray = o; |
||
2886 | dtWaypoints.Rows.Add(dr); |
||
2315 | - | 2887 | GMapMarker wpMarker = new GMapMarker(new PointLatLng((double)o[3], (double)o[4])); |
2888 | wpMarker.Shape = new CustomMarkerWP(this, wpMarker, (string)dr[2], (int)o[1]); |
||
2328 | - | 2889 | wpMarker.Offset = new System.Windows.Point(-11.5, -11.5); |
2890 | wpMarker.ZIndex = 100; |
||
2315 | - | 2891 | _setMarkerColor(wpMarker, (int)o[1]); |
2892 | MainMap.Markers.Add(wpMarker); |
||
2328 | - | 2893 | if((int)o[1] == 0) |
2894 | wpList.Add(new PointLatLng((double)o[3], (double)o[4])); |
||
2315 | - | 2895 | |
2312 | - | 2896 | Dispatcher.Invoke(() => lblWPIndex.Content = k.ToString()); |
2897 | Dispatcher.Invoke(() => lblWPCount.Content = k.ToString()); |
||
2898 | Dispatcher.Invoke(() => dgvWP.Items.Refresh()); |
||
2899 | Thread.Sleep(10); |
||
2900 | } |
||
2328 | - | 2901 | Dispatcher.Invoke(() => |
2902 | { |
||
2903 | if (comboBoxRouteColor.SelectionBoxItem != null) |
||
2904 | { |
||
2905 | string s = comboBoxRouteColor.SelectionBoxItem.ToString(); |
||
2906 | mRouteWP = new GMapRoute(wpList, _getBrush(s)); |
||
2907 | } |
||
2908 | else |
||
2909 | mRouteWP = new GMapRoute(wpList, null); |
||
2910 | |||
2911 | if (_bShowWPRoute) |
||
2912 | MainMap.Markers.Add(mRouteWP); |
||
2913 | }); |
||
2914 | |||
2915 | MapRoute mr = new MapRoute(wpList, "WPList"); |
||
2916 | Dispatcher.Invoke(() => lblWPRouteDistance.Content = (mr.Distance * 1000).ToString("0 m")); |
||
2917 | |||
2312 | - | 2918 | } |
2919 | } |
||
2920 | } |
||
2921 | |||
2922 | } |
||
2923 | catch (Exception e) |
||
2924 | { |
||
2925 | |||
2926 | MessageBox.Show("Error parsing wpl-file!" + Environment.NewLine + e.Message, "Read wpl-file", MessageBoxButton.OK, MessageBoxImage.Error); |
||
2927 | } |
||
2928 | |||
2929 | } |
||
2930 | } |
||
2328 | - | 2931 | Brush _getBrush(string color) |
2932 | { |
||
2933 | switch (color) |
||
2934 | { |
||
2935 | case "red": |
||
2936 | return Brushes.Red; |
||
2937 | case "green": |
||
2938 | return Brushes.Lime; |
||
2939 | case "blue": |
||
2940 | return Brushes.Aqua; |
||
2941 | case "pink": |
||
2942 | return Brushes.Magenta; |
||
2943 | case "yellow": |
||
2944 | return Brushes.Yellow; |
||
2945 | default: |
||
2946 | return Brushes.Magenta; |
||
2947 | } |
||
2948 | } |
||
2315 | - | 2949 | void _setMarkerColor(GMapMarker wpMarker,int iType) |
2950 | { |
||
2951 | Dispatcher.Invoke(() => |
||
2952 | { |
||
2953 | switch (iType) |
||
2954 | { |
||
2955 | case 0: |
||
2956 | if (comboBoxWPColor.SelectionBoxItem != null) |
||
2957 | { |
||
2958 | string s = comboBoxWPColor.SelectionBoxItem.ToString(); |
||
2959 | ((CustomMarkerWP)(wpMarker.Shape)).setColor(s); |
||
2960 | } |
||
2961 | else |
||
2962 | ((CustomMarkerWP)(wpMarker.Shape)).setColor("red"); |
||
2963 | break; |
||
2964 | case 1: |
||
2965 | if (comboBoxPOIColor.SelectionBoxItem != null) |
||
2966 | { |
||
2967 | string s = comboBoxPOIColor.SelectionBoxItem.ToString(); |
||
2968 | ((CustomMarkerWP)(wpMarker.Shape)).setColor(s); |
||
2969 | } |
||
2970 | else |
||
2971 | ((CustomMarkerWP)(wpMarker.Shape)).setColor("red"); |
||
2972 | break; |
||
2973 | case 2: |
||
2974 | if (comboBoxFSColor.SelectionBoxItem != null) |
||
2975 | { |
||
2976 | string s = comboBoxFSColor.SelectionBoxItem.ToString(); |
||
2977 | ((CustomMarkerWP)(wpMarker.Shape)).setColor(s); |
||
2978 | } |
||
2979 | else |
||
2980 | ((CustomMarkerWP)(wpMarker.Shape)).setColor("red"); |
||
2981 | break; |
||
2982 | default: |
||
2983 | ((CustomMarkerWP)(wpMarker.Shape)).setColor("red"); |
||
2984 | break; |
||
2985 | } |
||
2986 | }); |
||
2312 | - | 2987 | |
2315 | - | 2988 | } |
2989 | private void comboBoxWPColor_DropDownClosed(object sender, EventArgs e) |
||
2312 | - | 2990 | { |
2315 | - | 2991 | Dispatcher.Invoke(() => |
2992 | { |
||
2993 | if (comboBoxWPColor.SelectionBoxItem != null) |
||
2994 | { |
||
2995 | for (int k = 0; k < MainMap.Markers.Count;k++) |
||
2996 | { |
||
2997 | GMapMarker p = MainMap.Markers[k]; |
||
2998 | if (p.Shape.GetType() == typeof(CustomMarkerWP)) |
||
2999 | { |
||
3000 | if (((CustomMarkerWP)p.Shape).WPType == 0) |
||
3001 | { |
||
3002 | string s = comboBoxWPColor.SelectionBoxItem.ToString(); |
||
3003 | ((CustomMarkerWP)(p.Shape)).setColor(s); |
||
3004 | } |
||
3005 | } |
||
3006 | } |
||
3007 | } |
||
3008 | }); |
||
2312 | - | 3009 | } |
2315 | - | 3010 | private void comboBoxPOIColor_DropDownClosed(object sender, EventArgs e) |
3011 | { |
||
3012 | Dispatcher.Invoke(() => |
||
3013 | { |
||
3014 | if (comboBoxPOIColor.SelectionBoxItem != null) |
||
3015 | { |
||
3016 | for (int k = 0; k < MainMap.Markers.Count; k++) |
||
3017 | { |
||
3018 | GMapMarker p = MainMap.Markers[k]; |
||
3019 | if (p.Shape.GetType() == typeof(CustomMarkerWP)) |
||
3020 | { |
||
3021 | if (((CustomMarkerWP)p.Shape).WPType == 1) |
||
3022 | { |
||
3023 | string s = comboBoxPOIColor.SelectionBoxItem.ToString(); |
||
3024 | ((CustomMarkerWP)(p.Shape)).setColor(s); |
||
3025 | } |
||
3026 | } |
||
3027 | } |
||
3028 | } |
||
3029 | }); |
||
2287 | - | 3030 | |
2315 | - | 3031 | } |
3032 | private void comboBoxFSColor_DropDownClosed(object sender, EventArgs e) |
||
2287 | - | 3033 | { |
2315 | - | 3034 | Dispatcher.Invoke(() => |
3035 | { |
||
3036 | if (comboBoxFSColor.SelectionBoxItem != null) |
||
3037 | { |
||
3038 | for (int k = 0; k < MainMap.Markers.Count; k++) |
||
3039 | { |
||
3040 | GMapMarker p = MainMap.Markers[k]; |
||
3041 | if (p.Shape.GetType() == typeof(CustomMarkerWP)) |
||
3042 | { |
||
3043 | if (((CustomMarkerWP)p.Shape).WPType == 2) |
||
3044 | { |
||
3045 | string s = comboBoxFSColor.SelectionBoxItem.ToString(); |
||
3046 | ((CustomMarkerWP)(p.Shape)).setColor(s); |
||
3047 | } |
||
3048 | } |
||
3049 | } |
||
3050 | } |
||
3051 | }); |
||
2287 | - | 3052 | } |
2318 | - | 3053 | private void comboBoxCopterColor_DropDownClosed(object sender, EventArgs e) |
3054 | { |
||
3055 | Dispatcher.Invoke(() => { |
||
3056 | if (comboBoxCopterColor.SelectionBoxItem != null) |
||
3057 | { |
||
3058 | string s = comboBoxCopterColor.SelectionBoxItem.ToString(); |
||
3059 | ((CustomMarkerCopter)(copter.Shape)).setColor(s); |
||
3060 | } |
||
3061 | else |
||
3062 | ((CustomMarkerCopter)(copter.Shape)).setColor("red"); |
||
3063 | }); |
||
3064 | } |
||
2328 | - | 3065 | private void comboBoxRouteColor_DropDownClosed(object sender, EventArgs e) |
3066 | { |
||
3067 | Dispatcher.Invoke(() => |
||
3068 | { |
||
3069 | if (comboBoxRouteColor.SelectionBoxItem != null) |
||
3070 | { |
||
3071 | string s = comboBoxRouteColor.SelectionBoxItem.ToString(); |
||
3072 | MainMap.Markers.Remove(mRouteWP); |
||
3073 | mRouteWP = new GMapRoute(wpList, _getBrush(s)); |
||
3074 | if (_bShowWPRoute) |
||
3075 | MainMap.Markers.Add(mRouteWP); |
||
3076 | } |
||
3077 | }); |
||
3078 | } |
||
3079 | private void checkBoxShowWPRoute_Click(object sender, RoutedEventArgs e) |
||
3080 | { |
||
3081 | _bShowWPRoute = (bool)checkBoxShowWPRoute.IsChecked; |
||
3082 | if (_bShowWPRoute) |
||
3083 | { |
||
3084 | if (mRouteWP != null) |
||
3085 | MainMap.Markers.Add(mRouteWP); |
||
3086 | } |
||
3087 | else |
||
3088 | { |
||
3089 | if (mRouteWP != null) |
||
3090 | MainMap.Markers.Remove(mRouteWP); |
||
3091 | } |
||
3092 | } |
||
2315 | - | 3093 | private void btnLoadWPLFile_Click(object sender, RoutedEventArgs e) |
2287 | - | 3094 | { |
2315 | - | 3095 | _readWPLFile(); |
2287 | - | 3096 | } |
2335 | - | 3097 | private void btnClearWPList_Click(object sender, RoutedEventArgs e) |
3098 | { |
||
3099 | _clearMapMarkers(typeof(CustomMarkerWP)); |
||
2347 | - | 3100 | _clearMapMarkers(typeof(CustomMarkerWPActive)); |
2335 | - | 3101 | wpList.Clear(); |
3102 | if (mRouteWP != null) |
||
3103 | MainMap.Markers.Remove(mRouteWP); |
||
2347 | - | 3104 | //if (wpActiveMarker != null) |
3105 | // MainMap.Markers.Remove(wpActiveMarker); |
||
2335 | - | 3106 | dtWaypoints.Rows.Clear(); |
3107 | Dispatcher.Invoke(() => dgvWP.Items.Refresh()); |
||
3108 | Dispatcher.Invoke(() => lblWPIndex.Content = 0); |
||
3109 | Dispatcher.Invoke(() => lblWPCount.Content = 0); |
||
3110 | Dispatcher.Invoke(() => lblWPRouteDistance.Content = "0 m"); |
||
3111 | } |
||
2340 | - | 3112 | private void btnClearCopterList_Click(object sender, RoutedEventArgs e) |
3113 | { |
||
3114 | Thread t = new Thread(new ThreadStart(clearCopterWPList)); |
||
3115 | t.Start(); |
||
3116 | } |
||
3117 | private void dgvWP_MouseUp(object sender, MouseButtonEventArgs e) |
||
3118 | { |
||
3119 | if (dgvWP.SelectedIndex > -1 && dgvWP.SelectedIndex < dtWaypoints.Rows.Count) |
||
3120 | { |
||
3121 | if(_wpCount > 0) |
||
3122 | _sendWayPoint(dtWaypoints.Rows[dgvWP.SelectedIndex],-1); |
||
3123 | else |
||
3124 | _sendWayPoint(dtWaypoints.Rows[dgvWP.SelectedIndex],1); |
||
3125 | } |
||
3126 | } |
||
3127 | |||
2315 | - | 3128 | #endregion WP |
2335 | - | 3129 | |
2324 | - | 3130 | #region GPX |
3131 | private void checkBoxGPXLog_Click(object sender, RoutedEventArgs e) |
||
3132 | { |
||
3133 | _bGPXLog = (bool)checkBoxGPXLog.IsChecked; |
||
3134 | } |
||
3135 | void _gpxAdd(double lat,double lon, int elevation) |
||
3136 | { |
||
3137 | DataRow dr = dtGPX.NewRow(); |
||
3138 | dr[0] = dtGPX.Rows.Count - 1; |
||
3139 | dr[1] = lat; |
||
3140 | dr[2] = lon; |
||
3141 | dr[3] = elevation; |
||
3142 | dr[4] = DateTime.UtcNow.ToString("s", System.Globalization.CultureInfo.InvariantCulture); //2011-01-14T01:59:01Z |
||
3143 | dtGPX.Rows.Add(dr); |
||
3144 | } |
||
3145 | void _saveGPXLog() |
||
3146 | { |
||
3147 | if (!Directory.Exists("GPXLog")) |
||
3148 | Directory.CreateDirectory("GPXLog"); |
||
3149 | string SaveFileName = "GPXLog\\" + DateTime.Now.ToString("yyyyMMdd_HHmm") + ".gpx"; |
||
3150 | XmlTextWriter myXmlTextWriter = null; |
||
3151 | myXmlTextWriter = new XmlTextWriter(SaveFileName, null); |
||
3152 | NumberFormatInfo nfi = new NumberFormatInfo(); |
||
3153 | nfi.NumberDecimalSeparator = "."; |
||
2315 | - | 3154 | |
2324 | - | 3155 | try |
3156 | { |
||
3157 | myXmlTextWriter.Formatting = Formatting.Indented; |
||
3158 | |||
3159 | myXmlTextWriter.WriteStartDocument(); |
||
3160 | |||
3161 | myXmlTextWriter.WriteStartElement("gpx"); |
||
3162 | |||
3163 | myXmlTextWriter.WriteAttributeString("version", "1.0"); |
||
3164 | myXmlTextWriter.WriteAttributeString("creator", "MKLiveView v1.0"); |
||
3165 | myXmlTextWriter.WriteAttributeString("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); |
||
3166 | myXmlTextWriter.WriteAttributeString("xmlns", "http://www.topografix.com/GPX/1/1"); |
||
3167 | myXmlTextWriter.WriteAttributeString("xsi:schemaLocation", "http://www.topografix.com/GPX/1/1/gpx.xsd"); |
||
3168 | |||
3169 | myXmlTextWriter.WriteElementString("time", DateTime.UtcNow.ToString("u", System.Globalization.CultureInfo.InvariantCulture)); |
||
3170 | |||
3171 | myXmlTextWriter.WriteStartElement("trk"); |
||
3172 | myXmlTextWriter.WriteStartElement("trkseg"); |
||
3173 | for(int i = 0; i< dtGPX.Rows.Count;i++) |
||
3174 | { |
||
3175 | myXmlTextWriter.WriteStartElement("trkpt"); |
||
3176 | myXmlTextWriter.WriteAttributeString("lat", dtGPX.Rows[i][1].ToString() != "" ? ((double)dtGPX.Rows[i][1]).ToString(nfi) : ""); |
||
3177 | myXmlTextWriter.WriteAttributeString("lon", dtGPX.Rows[i][2].ToString() != "" ? ((double)dtGPX.Rows[i][2]).ToString(nfi) : ""); |
||
3178 | myXmlTextWriter.WriteElementString("ele", dtGPX.Rows[i][3].ToString()); |
||
3179 | myXmlTextWriter.WriteElementString("time", dtGPX.Rows[i][4].ToString()); |
||
3180 | myXmlTextWriter.WriteEndElement(); |
||
3181 | } |
||
3182 | myXmlTextWriter.WriteEndElement(); |
||
3183 | myXmlTextWriter.WriteEndElement(); |
||
3184 | myXmlTextWriter.WriteEndElement(); |
||
3185 | } |
||
3186 | catch (Exception e) |
||
3187 | { |
||
3188 | Console.WriteLine("Exception: {0}", e.ToString()); |
||
3189 | } |
||
3190 | finally |
||
3191 | { |
||
3192 | if (myXmlTextWriter != null) |
||
3193 | { |
||
3194 | myXmlTextWriter.Close(); |
||
3195 | } |
||
3196 | } |
||
3197 | } |
||
3198 | |||
3199 | private void btnLoadGPXLog_Click(object sender, RoutedEventArgs e) |
||
3200 | { |
||
3201 | _loadGPXLog(); |
||
3202 | } |
||
3203 | |||
2327 | - | 3204 | private void btnClearRoute_Click(object sender, RoutedEventArgs e) |
3205 | { |
||
3206 | _clearMapMarkers(typeof(GMapRoute)); |
||
3207 | } |
||
3208 | |||
2340 | - | 3209 | |
2324 | - | 3210 | void _loadGPXLog() |
3211 | { |
||
3212 | |||
3213 | Microsoft.Win32.OpenFileDialog fd = new Microsoft.Win32.OpenFileDialog(); |
||
3214 | fd.Filter = "GPX-Logfile | *.gpx"; |
||
3215 | fd.Multiselect = false; |
||
3216 | if (fd.ShowDialog().Value) |
||
3217 | { |
||
3218 | string file = fd.FileName; |
||
3219 | try |
||
3220 | { |
||
3221 | XDocument gpxDoc = XDocument.Load(file); |
||
3222 | XNamespace gpx = XNamespace.Get("http://www.topografix.com/GPX/1/1"); |
||
3223 | |||
3224 | NumberFormatInfo nfi = new NumberFormatInfo(); |
||
3225 | nfi.NumberDecimalSeparator = "."; |
||
3226 | |||
3227 | var tracks = from track in gpxDoc.Descendants(gpx + "trk") |
||
3228 | select new |
||
3229 | { |
||
3230 | Name = track.Element(gpx + "name") != null ? track.Element(gpx + "name").Value : null, |
||
3231 | Segs = ( |
||
3232 | from trackpoint in track.Descendants(gpx + "trkpt") |
||
3233 | select new |
||
3234 | { |
||
3235 | Latitude = trackpoint.Attribute("lat").Value, |
||
3236 | Longitude = trackpoint.Attribute("lon").Value, |
||
3237 | Elevation = trackpoint.Element(gpx + "ele") != null ? |
||
3238 | trackpoint.Element(gpx + "ele").Value : null, |
||
3239 | Time = trackpoint.Element(gpx + "time") != null ? |
||
3240 | trackpoint.Element(gpx + "time").Value : null |
||
3241 | } |
||
3242 | ) |
||
3243 | }; |
||
3244 | |||
3245 | List<PointLatLng> wpl = new List<PointLatLng>(); |
||
3246 | foreach(var trk in tracks) |
||
3247 | { |
||
3248 | foreach(var trkseg in trk.Segs) |
||
3249 | { |
||
3250 | if(trkseg.Latitude != "" && trkseg.Longitude !="") |
||
3251 | wpl.Add(new PointLatLng(Convert.ToDouble(trkseg.Latitude, nfi), Convert.ToDouble(trkseg.Longitude, nfi))); |
||
3252 | } |
||
3253 | |||
3254 | } |
||
3255 | if(wpl.Count() > 0) |
||
3256 | { |
||
2327 | - | 3257 | _clearMapMarkers(typeof(GMapRoute)); |
3258 | //for (int k = 0; k < MainMap.Markers.Count;) |
||
3259 | //{ |
||
3260 | // GMapMarker p = MainMap.Markers[k]; |
||
3261 | // if (p.Shape.GetType() == typeof(GMapRoute)) |
||
3262 | // MainMap.Markers.Remove(p); |
||
3263 | // else |
||
3264 | // k++; |
||
3265 | //} |
||
2324 | - | 3266 | MapRoute mr = new MapRoute(wpl, "flying"); |
2328 | - | 3267 | Dispatcher.Invoke(() => |
3268 | { |
||
3269 | GMapRoute mRoute; |
||
3270 | if (comboBoxRouteColor.SelectionBoxItem != null) |
||
3271 | { |
||
3272 | string s = comboBoxRouteColor.SelectionBoxItem.ToString(); |
||
3273 | mRoute = new GMapRoute(wpList, _getBrush(s)); |
||
3274 | } |
||
3275 | else |
||
3276 | mRoute = new GMapRoute(wpList, null); |
||
2324 | - | 3277 | |
2328 | - | 3278 | MainMap.Markers.Add(mRoute); |
3279 | }); |
||
2324 | - | 3280 | } |
3281 | |||
3282 | } |
||
3283 | catch (Exception e) |
||
3284 | { |
||
3285 | Console.WriteLine("Exception: {0}", e.ToString()); |
||
3286 | } |
||
3287 | } |
||
3288 | } |
||
3289 | #endregion GPX |
||
2315 | - | 3290 | #endregion functions |
2287 | - | 3291 | } |
2315 | - | 3292 | /// <summary> |
3293 | /// formats the wp datatable values for display in datagrid - this is bound in the datagrid as a converter |
||
3294 | /// </summary> |
||
2313 | - | 3295 | public class waypointsConverter : IValueConverter |
3296 | { |
||
3297 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) |
||
3298 | { |
||
3299 | if (value != null) |
||
3300 | { |
||
3301 | switch ((string)parameter) |
||
3302 | { |
||
3303 | case "Latitude": |
||
3304 | return value.ToString() + " °"; |
||
3305 | case "Longitude": |
||
3306 | return value.ToString() + " °"; |
||
3307 | case "Radius": |
||
3308 | return value.ToString() + " m"; |
||
3309 | case "Altitude": |
||
3310 | return value.ToString() + " m"; |
||
3311 | case "ClimbRate": |
||
3312 | return value.ToString() == "255" ? "Auto" : (System.Convert.ToDouble(value) / 10).ToString("0.0 m/s"); |
||
3313 | case "DelayTime": |
||
3314 | return value.ToString() + " s"; |
||
3315 | case "Heading": |
||
3316 | return Waypoints.Heading(System.Convert.ToInt32(value)); |
||
3317 | case "Speed": |
||
3318 | return Waypoints.WPSpeed(System.Convert.ToInt16(value)); |
||
3319 | case "CamAngle": |
||
3320 | return Waypoints.CAMAngle(System.Convert.ToInt16(value)); |
||
3321 | case "Type": |
||
3322 | return ((Waypoints.pointType)(System.Convert.ToInt16(value))).ToString(); |
||
3323 | case "AutoTrigger": |
||
3324 | return value.ToString() == "0" ? "- - -" : value.ToString() + " m"; |
||
3325 | case "Status": |
||
3326 | return Waypoints.WPSpeed(System.Convert.ToInt16(value)); |
||
3327 | } |
||
3328 | |||
3329 | return value.ToString(); |
||
3330 | } |
||
3331 | else return value; |
||
3332 | } |
||
3333 | |||
3334 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) |
||
3335 | { |
||
3336 | throw new NotImplementedException(); |
||
3337 | } |
||
3338 | } |
||
3339 | |||
2287 | - | 3340 | public class IniFile |
3341 | { |
||
3342 | public string path; |
||
3343 | |||
3344 | [DllImport("kernel32")] |
||
3345 | private static extern long WritePrivateProfileString(string section, |
||
3346 | string key, string val, string filePath); |
||
3347 | |||
3348 | [DllImport("kernel32.dll", CharSet = CharSet.Auto)] |
||
3349 | static extern uint GetPrivateProfileSectionNames(IntPtr lpszReturnBuffer, |
||
3350 | uint nSize, string lpFileName); |
||
3351 | |||
3352 | [DllImport("kernel32")] |
||
3353 | private static extern int GetPrivateProfileString(string section, |
||
3354 | string key, string def, StringBuilder retVal, |
||
3355 | int size, string filePath); |
||
3356 | |||
3357 | public IniFile(string INIPath) |
||
3358 | { |
||
3359 | path = INIPath; |
||
3360 | } |
||
3361 | |||
3362 | public void IniWriteValue(string Section, string Key, string Value) |
||
3363 | { |
||
3364 | WritePrivateProfileString(Section, Key, Value, this.path); |
||
3365 | } |
||
3366 | |||
3367 | public string IniReadValue(string Section, string Key) |
||
3368 | { |
||
3369 | StringBuilder temp = new StringBuilder(255); |
||
3370 | int i = GetPrivateProfileString(Section, Key, "", temp, 255, this.path); |
||
3371 | return temp.ToString(); |
||
3372 | } |
||
3373 | //Ini_sections auslesen in String-Array |
||
3374 | public string[] IniSectionNames() |
||
3375 | { |
||
3376 | |||
3377 | // uint MAX_BUFFER = 32767; |
||
3378 | uint MAX_BUFFER = 8388608; |
||
3379 | IntPtr pReturnedString = Marshal.AllocCoTaskMem((int)MAX_BUFFER); |
||
3380 | uint bytesReturned = GetPrivateProfileSectionNames(pReturnedString, MAX_BUFFER, this.path); |
||
3381 | if (bytesReturned == 0) |
||
3382 | { |
||
3383 | Marshal.FreeCoTaskMem(pReturnedString); |
||
3384 | return null; |
||
3385 | } |
||
3386 | string local = Marshal.PtrToStringAuto(pReturnedString, (int)bytesReturned).ToString(); |
||
3387 | Marshal.FreeCoTaskMem(pReturnedString); |
||
3388 | //use of Substring below removes terminating null for split |
||
3389 | return local.Substring(0, local.Length - 1).Split('\0'); |
||
3390 | |||
3391 | |||
3392 | } |
||
3393 | } |
||
3394 | |||
3395 | /// <summary> |
||
3396 | /// Selected Win AI Function Calls |
||
3397 | /// </summary> |
||
3398 | public class WinApi |
||
3399 | { |
||
3400 | [DllImport("user32.dll", EntryPoint = "GetSystemMetrics")] |
||
3401 | public static extern int GetSystemMetrics(int which); |
||
3402 | [DllImport("user32.dll")] |
||
3403 | public static extern void |
||
3404 | SetWindowPos(IntPtr hwnd, IntPtr hwndInsertAfter, |
||
3405 | int X, int Y, int width, int height, uint flags); |
||
3406 | |||
3407 | private const int SM_CXSCREEN = 0; |
||
3408 | private const int SM_CYSCREEN = 1; |
||
3409 | private static IntPtr HWND_TOP = IntPtr.Zero; |
||
3410 | private const int SWP_SHOWWINDOW = 64; // 0x0040 |
||
3411 | |||
3412 | public static int ScreenX |
||
3413 | { |
||
3414 | get { return GetSystemMetrics(SM_CXSCREEN); } |
||
3415 | } |
||
3416 | |||
3417 | public static int ScreenY |
||
3418 | { |
||
3419 | get { return GetSystemMetrics(SM_CYSCREEN); } |
||
3420 | } |
||
3421 | |||
3422 | public static void SetWinFullScreen(IntPtr hwnd) |
||
3423 | { |
||
3424 | SetWindowPos(hwnd, HWND_TOP, -8, -7, ScreenX+15, ScreenY+14, SWP_SHOWWINDOW); |
||
3425 | } |
||
3426 | } |
||
3427 | /// <summary> |
||
3428 | /// Class used to preserve / restore state of the window |
||
3429 | /// </summary> |
||
3430 | public class WinState |
||
3431 | { |
||
3432 | private WindowState winState; |
||
3433 | private WindowStyle brdStyle; |
||
3434 | private bool topMost; |
||
3435 | private Rect restore; |
||
3436 | private bool IsMaximized = false; |
||
3437 | |||
3438 | public bool isMaximized |
||
3439 | { |
||
3440 | get { return IsMaximized; } |
||
3441 | } |
||
3442 | public void Maximize(Window targetForm) |
||
3443 | { |
||
3444 | if (!IsMaximized) |
||
3445 | { |
||
3446 | IsMaximized = true; |
||
3447 | Save(targetForm); |
||
3448 | targetForm.WindowState = WindowState.Maximized; |
||
3449 | targetForm.WindowStyle = WindowStyle.None; |
||
3450 | targetForm.Topmost = true; |
||
3451 | WinApi.SetWinFullScreen(new WindowInteropHelper(targetForm).Handle); |
||
3452 | } |
||
3453 | } |
||
3454 | |||
3455 | public void Save(Window targetForm) |
||
3456 | { |
||
3457 | winState = targetForm.WindowState; |
||
3458 | brdStyle = targetForm.WindowStyle; |
||
3459 | topMost = targetForm.Topmost; |
||
3460 | restore = targetForm.RestoreBounds; |
||
3461 | } |
||
3462 | public void Restore(Window targetForm) |
||
3463 | { |
||
3464 | targetForm.WindowState = winState; |
||
3465 | targetForm.WindowStyle = brdStyle; |
||
3466 | targetForm.Topmost = topMost; |
||
3467 | |||
3468 | targetForm.Left = restore.Left; |
||
3469 | targetForm.Top = restore.Top; |
||
3470 | targetForm.Height = restore.Height; |
||
3471 | targetForm.Width = restore.Width; |
||
3472 | IsMaximized = false; |
||
3473 | } |
||
3474 | } |
||
3475 | |||
3476 | } |