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; |
||
2355 | - | 281 | int _wpIndex = -1, _wpCount = 0, _wpEdit = -1; |
2340 | - | 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 | |
2349 | - | 358 | _initSerialCtrl(); |
2287 | - | 359 | } |
360 | /// <summary> |
||
361 | /// initialize the datatables |
||
362 | /// with columnnames etc |
||
363 | /// </summary> |
||
364 | void _dataTablesInit() |
||
365 | { |
||
2315 | - | 366 | dtMotors.Columns.Add("#"); |
2313 | - | 367 | if (Thread.CurrentThread.CurrentUICulture.Name == "de-DE") |
2315 | - | 368 | dtMotors.Columns.Add("Strom"); |
2313 | - | 369 | else |
2315 | - | 370 | dtMotors.Columns.Add("Current"); |
371 | dtMotors.Columns.Add("Temp"); |
||
372 | dgvMotors1.DataContext = dtMotors.DefaultView; |
||
2287 | - | 373 | _initDTMotors(); |
374 | |||
375 | Setter setter = new Setter(ContentControl.PaddingProperty, new Thickness(5,0,5,0)); |
||
376 | Style style = new Style(typeof(System.Windows.Controls.Primitives.DataGridColumnHeader)); |
||
377 | style.Setters.Add(setter); |
||
378 | setter = new Setter(ContentControl.BackgroundProperty, new SolidColorBrush(Colors.Transparent)); |
||
379 | style.Setters.Add(setter); |
||
380 | setter = new Setter(ContentControl.ForegroundProperty, new SolidColorBrush(Colors.White)); |
||
381 | style.Setters.Add(setter); |
||
2313 | - | 382 | |
383 | dtWaypoints.Columns.Add("Index",typeof(int)); |
||
2315 | - | 384 | dtWaypoints.Columns.Add("Type", typeof(int)); |
2313 | - | 385 | dtWaypoints.Columns.Add("Name",typeof(string)); |
2315 | - | 386 | dtWaypoints.Columns.Add("Latitude",typeof(double)); |
387 | dtWaypoints.Columns.Add("Longitude",typeof(double)); |
||
2313 | - | 388 | dtWaypoints.Columns.Add("Altitude",typeof(string)); |
389 | dtWaypoints.Columns.Add("Heading",typeof(string)); |
||
390 | dtWaypoints.Columns.Add("Speed",typeof(string)); |
||
391 | dtWaypoints.Columns.Add("ClimbRate",typeof(string)); |
||
392 | dtWaypoints.Columns.Add("Radius",typeof(string)); |
||
393 | dtWaypoints.Columns.Add("HoldTime",typeof(string)); |
||
394 | dtWaypoints.Columns.Add("AutoTrigger",typeof(string)); |
||
395 | dtWaypoints.Columns.Add("CamAngle",typeof(string)); |
||
396 | dtWaypoints.Columns.Add("Event",typeof(string)); |
||
397 | dtWaypoints.Columns.Add("Out1Timer",typeof(string)); |
||
398 | dtWaypoints.Columns.Add("Status",typeof(string)); |
||
399 | dtWaypoints.PrimaryKey = new DataColumn[] { dtWaypoints.Columns["Index"] }; |
||
400 | dgvWP.ItemsSource = dtWaypoints.DefaultView; |
||
2287 | - | 401 | dgvWP.ColumnHeaderStyle = new Style(); |
402 | dgvWP.ColumnHeaderStyle = style; |
||
2313 | - | 403 | |
2324 | - | 404 | dtGPX.Columns.Add("Index",typeof(int)); |
405 | dtGPX.Columns.Add("Latitude",typeof(double)); |
||
406 | dtGPX.Columns.Add("Longitude",typeof(double)); |
||
407 | dtGPX.Columns.Add("Elevation",typeof(int)); |
||
408 | dtGPX.Columns.Add("Time",typeof(string)); |
||
409 | dtGPX.PrimaryKey = new DataColumn[] { dtGPX.Columns["Index"] }; |
||
410 | drGPX = dtGPX.NewRow(); |
||
2313 | - | 411 | |
2287 | - | 412 | } |
413 | /// <summary> |
||
2315 | - | 414 | /// initialize the datatable dtMotors for motor values |
2313 | - | 415 | /// DataGridView dgvMotors1 is bound to dtMotors1 |
2287 | - | 416 | /// </summary> |
417 | void _initDTMotors() |
||
418 | { |
||
419 | for (int i = 0; i < 12; i++) |
||
420 | { |
||
2315 | - | 421 | if (dtMotors.Rows.Count < 12) |
422 | dtMotors.Rows.Add((i + 1).ToString(), "NA", "NA"); |
||
2287 | - | 423 | else |
424 | { |
||
2315 | - | 425 | dtMotors.Rows[i].SetField(1, "NA"); |
426 | dtMotors.Rows[i].SetField(2, "NA"); |
||
2287 | - | 427 | } |
428 | } |
||
429 | } |
||
430 | |||
431 | #endregion init |
||
432 | |||
433 | #region events |
||
434 | private void serialPortCtrl_PortOpened() |
||
435 | { |
||
436 | Dispatcher.Invoke(() => imageWiFi.Source = new BitmapImage(new Uri("Images/WiFi_G.png", UriKind.Relative))); |
||
437 | _getVersion(); |
||
438 | Thread.Sleep(100); |
||
439 | //_OSDMenue(0); |
||
440 | //Thread.Sleep(200); |
||
441 | //_sendSerialData(); |
||
442 | _readCont(true); |
||
443 | } |
||
444 | private void serialPortCtrl_PortClosed() |
||
445 | { |
||
446 | Dispatcher.Invoke(() => imageWiFi.Source = new BitmapImage(new Uri("Images/WiFi_W.png", UriKind.Relative))); |
||
447 | _readCont(false); |
||
448 | } |
||
2324 | - | 449 | bool _bToggle = false; |
2287 | - | 450 | void timerEvent(object sender, EventArgs e) |
451 | { |
||
452 | if (bReadContinously) |
||
453 | { |
||
454 | if (_debugDataAutorefresh) { _readDebugData(true); Thread.Sleep(10); } |
||
455 | |||
456 | if (_blctrlDataAutorefresh) { _readBLCtrl(true); Thread.Sleep(10); } |
||
457 | |||
458 | if (_navCtrlDataAutorefresh && _iCtrlAct == 2) { _readNavData(true); Thread.Sleep(10); } |
||
459 | check_HWError = true; |
||
460 | _getVersion(); |
||
461 | Thread.Sleep(10); |
||
462 | if (_OSDAutorefresh) |
||
463 | { |
||
464 | if (iOSDMax == 0 | cbOSD.Items.Count != iOSDMax) |
||
465 | _initOSDCB(); |
||
466 | _OSDMenueAutoRefresh(); |
||
467 | } |
||
468 | if (_iLifeCounter > 0) |
||
469 | { |
||
470 | Dispatcher.Invoke(() => imageConn.Source = new BitmapImage(new Uri("Images/Data_G.png", UriKind.Relative))); |
||
471 | // Dispatcher.Invoke((Action)(() => rctConnection.Fill = Brushes.LightGreen)); |
||
472 | _iLifeCounter = 0; |
||
473 | _bConnErr = false; |
||
2327 | - | 474 | if(_bAirborne && _bGPXLog) |
2324 | - | 475 | { |
476 | drGPX[0] = dtGPX.Rows.Count; |
||
477 | dtGPX.Rows.Add(new object[] { drGPX[0], drGPX[1], drGPX[2], drGPX[3], drGPX[4] }); |
||
478 | } |
||
2327 | - | 479 | Dispatcher.Invoke((Action)(() => tbSideBarGPXLog.Background = (_bAirborne && _bGPXLog && _bToggle) ? new SolidColorBrush(Colors.LightSeaGreen) : new SolidColorBrush(Colors.Transparent))); |
480 | Dispatcher.Invoke((Action)(() => tbSideBarGPXLog.Foreground = (_bAirborne && _bGPXLog) ? new SolidColorBrush(Colors.White) : new SolidColorBrush(Color.FromArgb(255, 211, 210, 210)))); |
||
481 | Dispatcher.Invoke((Action)(() => tbSideBarGPXLog.BorderBrush = (_bAirborne && _bGPXLog) ? new SolidColorBrush(Colors.White) : new SolidColorBrush(Color.FromArgb(255, 211, 210, 210)))); |
||
2324 | - | 482 | _bToggle = !_bToggle; |
2287 | - | 483 | } |
484 | else |
||
485 | { |
||
486 | if (!_bConnErr) |
||
487 | { |
||
488 | Log(LogMsgType.Error, "No communication to NC/FC!"); |
||
489 | Dispatcher.Invoke(() => imageConn.Source = new BitmapImage(new Uri("Images/Data_R.png", UriKind.Relative))); |
||
490 | // Dispatcher.Invoke((Action)(() => rctConnection.Fill = Brushes.Red)); |
||
491 | _bConnErr = true; |
||
492 | } |
||
493 | } |
||
494 | } |
||
495 | } |
||
496 | |||
497 | private void labelData_MouseDown(object sender, MouseButtonEventArgs e) |
||
498 | { |
||
499 | GridData.Visibility = GridData.Visibility == Visibility.Collapsed ? Visibility.Visible : Visibility.Collapsed; |
||
500 | GridSettings.Visibility = GridWP.Visibility = Visibility.Collapsed; |
||
501 | } |
||
502 | private void labelMotorData_MouseDown(object sender, MouseButtonEventArgs e) |
||
503 | { |
||
504 | GridMotors.Visibility = GridMotors.Visibility == Visibility.Hidden ? Visibility.Visible : Visibility.Hidden; |
||
505 | if (GridMotors.IsVisible) |
||
506 | _setMotorGridSize(); |
||
507 | } |
||
508 | private void labelSettings_MouseDown(object sender, MouseButtonEventArgs e) |
||
509 | { |
||
510 | GridData.Visibility = GridWP.Visibility = Visibility.Collapsed; |
||
511 | GridSettings.Visibility = GridSettings.Visibility == Visibility.Collapsed ? Visibility.Visible : Visibility.Collapsed; |
||
512 | } |
||
513 | private void labelLog_MouseDown(object sender, MouseButtonEventArgs e) |
||
514 | { |
||
515 | GridLog.Visibility = GridLog.Visibility == Visibility.Collapsed ? Visibility.Visible : Visibility.Collapsed; |
||
516 | } |
||
517 | private void labelOSD_MouseDown(object sender, MouseButtonEventArgs e) |
||
518 | { |
||
519 | GridOSD.Visibility = GridOSD.Visibility == Visibility.Hidden ? Visibility.Visible : Visibility.Hidden; |
||
520 | } |
||
521 | private void labelWaypoints_MouseDown(object sender, MouseButtonEventArgs e) |
||
522 | { |
||
523 | GridData.Visibility = GridSettings.Visibility = Visibility.Collapsed; |
||
524 | GridWP.Visibility = GridWP.Visibility == Visibility.Collapsed ? Visibility.Visible : Visibility.Collapsed; |
||
525 | } |
||
526 | |||
527 | private void btnGetWP_Click(object sender, RoutedEventArgs e) |
||
528 | { |
||
529 | Thread t = new Thread(new ThreadStart(_getWP)); |
||
530 | t.Start(); |
||
531 | } |
||
532 | private void btnSendWPList_Click(object sender, RoutedEventArgs e) |
||
533 | { |
||
2313 | - | 534 | Thread t = new Thread(new ThreadStart(_sendWPList)); |
535 | t.Start(); |
||
2287 | - | 536 | } |
537 | |||
538 | private void btnConnectToCopter_Click(object sender, RoutedEventArgs e) |
||
539 | { |
||
540 | if (!serialPortCtrl.Port.IsOpen) |
||
541 | serialPortCtrl.Connect(true); |
||
542 | else |
||
543 | _readCont(!bReadContinously); |
||
544 | } |
||
545 | private void btnSetHP_Click(object sender, RoutedEventArgs e) |
||
546 | { |
||
2347 | - | 547 | _setHomePos(); |
2287 | - | 548 | } |
549 | private void btnClearHP_Click(object sender, RoutedEventArgs e) |
||
550 | { |
||
2347 | - | 551 | _clearHomePos(); |
2287 | - | 552 | } |
553 | private void btnGotoHP_Click(object sender, RoutedEventArgs e) |
||
554 | { |
||
555 | if (home != null && MainMap.Markers.Contains(home)) |
||
556 | MainMap.Position = home.Position; |
||
557 | } |
||
2295 | - | 558 | private void checkBoxAutoSetHP_Click(object sender, RoutedEventArgs e) |
559 | { |
||
560 | _bAutoHome = (bool)checkBoxAutoSetHP.IsChecked; |
||
561 | } |
||
2287 | - | 562 | private void chkBoxSaveNormalState_Click(object sender, RoutedEventArgs e) |
563 | { |
||
564 | _bSaveWinStateNormal = (bool)chkBoxSaveNormalState.IsChecked; |
||
565 | } |
||
566 | private void chkBoxSaveFullScreenState_Click(object sender, RoutedEventArgs e) |
||
567 | { |
||
568 | _bSaveWinStateFull = (bool)chkBoxSaveFullScreenState.IsChecked; |
||
569 | } |
||
570 | |||
2291 | - | 571 | #region thresholds |
2287 | - | 572 | private void sliderThresholdVoltageWarn_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) |
573 | { |
||
574 | if(!_init) |
||
575 | _dThresholdVoltageWarn = sliderThresholdVoltageWarn.Value; |
||
576 | } |
||
577 | private void sliderThresholdVoltageCrit_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) |
||
578 | { |
||
579 | if(!_init) |
||
580 | _dThresholdVoltageCrit = sliderThresholdVoltageCrit.Value; |
||
581 | } |
||
582 | private void checkBoxThresholdVoltageVoice_Click(object sender, RoutedEventArgs e) |
||
583 | { |
||
584 | _bVoiceVoltPlay = (bool)checkBoxThresholdVoltageVoice.IsChecked; |
||
585 | } |
||
2291 | - | 586 | |
587 | private void sliderThresholdDistanceWarn_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) |
||
588 | { |
||
589 | if(!_init) |
||
590 | _dThresholdDistanceWarn = sliderThresholdDistanceWarn.Value; |
||
591 | } |
||
592 | private void checkBoxThresholdDistanceVoice_Click(object sender, RoutedEventArgs e) |
||
593 | { |
||
594 | _bVoiceDistancePlay = (bool)checkBoxThresholdDistanceVoice.IsChecked; |
||
595 | } |
||
596 | |||
597 | private void checkBoxSatfixLost_Click(object sender, RoutedEventArgs e) |
||
598 | { |
||
599 | _bVoiceSatFixPlay = (bool)checkBoxSatfixLost.IsChecked; |
||
600 | } |
||
601 | private void checkBoxMagneticField_Click(object sender, RoutedEventArgs e) |
||
602 | { |
||
603 | _bVoiceMagneticFieldPlay = (bool)checkBoxMagneticField.IsChecked; |
||
604 | } |
||
605 | private void checkBoxRClevel_Click(object sender, RoutedEventArgs e) |
||
606 | { |
||
607 | _bVoiceRCLevelPlay = (bool)checkBoxRClevel.IsChecked; |
||
608 | } |
||
609 | #endregion thresholds |
||
610 | |||
2287 | - | 611 | private void buttonSwitchNC_Click(object sender, RoutedEventArgs e) |
612 | { |
||
613 | _switchToNC(); |
||
614 | } |
||
615 | |||
616 | private void Window_Loaded(object sender, RoutedEventArgs e) |
||
617 | { |
||
618 | stbVoltageCritAnim = TryFindResource("VoltageCritAnim") as Storyboard; |
||
2291 | - | 619 | stbSatFixLostAnim = TryFindResource("SatFixLostAnim") as Storyboard; |
620 | stbMagneticFieldAnim = TryFindResource("MagneticFieldCritAnim") as Storyboard; |
||
621 | stbDistanceWarnAnim = TryFindResource("DistanceCritAnim") as Storyboard; |
||
622 | stbRCLevelAnim = TryFindResource("RCCritAnim") as Storyboard; |
||
2287 | - | 623 | _setMotorGridSize(); |
624 | } |
||
2310 | - | 625 | private void Window_Closing(object sender, CancelEventArgs e) |
626 | { |
||
627 | _writeIni(); |
||
2324 | - | 628 | if(_bGPXLog && dtGPX.Rows.Count > 0) |
629 | _saveGPXLog(); |
||
2310 | - | 630 | } |
2287 | - | 631 | #endregion events |
632 | |||
633 | #region GMap |
||
634 | |||
635 | void _setupMap() |
||
636 | { |
||
637 | MainMap.Manager.Mode = AccessMode.ServerAndCache; |
||
638 | MainMap.MapProvider = GMapProviders.BingHybridMap; |
||
639 | MainMap.SetPositionByKeywords("Landshut"); |
||
640 | MainMap.MinZoom = 0; |
||
641 | MainMap.MaxZoom = 24; |
||
642 | MainMap.Zoom = 16; |
||
643 | MainMap.ShowCenter = true; |
||
644 | MainMap.ShowTileGridLines = false; |
||
645 | sliderMapZoom.Value = 16; |
||
646 | comboBoxMapType.ItemsSource = providerList; |
||
647 | comboBoxMapType.DisplayMemberPath = "Name"; |
||
648 | comboBoxMapType.SelectedItem = MainMap.MapProvider; |
||
649 | |||
650 | // acccess mode |
||
651 | comboBoxMode.ItemsSource = Enum.GetValues(typeof(AccessMode)); |
||
652 | comboBoxMode.SelectedItem = MainMap.Manager.Mode; |
||
653 | |||
654 | } |
||
655 | |||
656 | /// <summary> |
||
657 | /// selection of relevant map providers --> if You need more, You can change the line: |
||
658 | /// comboBoxMapType.ItemsSource = providerList; |
||
659 | /// to: |
||
660 | /// comboBoxMapType.ItemsSource = GMapProviders.List; |
||
661 | /// in _setupMap() |
||
662 | /// or add items here: |
||
663 | /// </summary> |
||
664 | List<GMap.NET.MapProviders.GMapProvider> providerList = new List<GMap.NET.MapProviders.GMapProvider> |
||
665 | { GMap.NET.MapProviders.GMapProviders.OpenCycleMap, GMap.NET.MapProviders.GMapProviders.OpenCycleLandscapeMap, GMap.NET.MapProviders.GMapProviders.OpenCycleTransportMap, |
||
666 | GMap.NET.MapProviders.GMapProviders.BingMap,GMap.NET.MapProviders.GMapProviders.BingSatelliteMap,GMap.NET.MapProviders.GMapProviders.BingHybridMap, |
||
667 | GMap.NET.MapProviders.GMapProviders.GoogleMap,GMap.NET.MapProviders.GMapProviders.GoogleSatelliteMap,GMap.NET.MapProviders.GMapProviders.GoogleHybridMap,GMap.NET.MapProviders.GMapProviders.GoogleTerrainMap, |
||
668 | GMap.NET.MapProviders.GMapProviders.OviMap,GMap.NET.MapProviders.GMapProviders.OviSatelliteMap,GMap.NET.MapProviders.GMapProviders.OviHybridMap,GMap.NET.MapProviders.GMapProviders.OviTerrainMap}; |
||
669 | |||
670 | private void MainMap_Loaded(object sender, RoutedEventArgs e) |
||
671 | { |
||
672 | MainMap.Manager.Mode = AccessMode.ServerAndCache; |
||
673 | copter = new GMapMarker(MainMap.Position); |
||
2318 | - | 674 | |
675 | copter.Shape = new CustomMarkerCopter(this, copter, MainMap.Position.Lat.ToString("0.#######°") + System.Environment.NewLine + MainMap.Position.Lng.ToString("0.#######°"),"red"); |
||
676 | if (comboBoxCopterColor.SelectionBoxItem != null) |
||
677 | { |
||
678 | string s = comboBoxCopterColor.SelectionBoxItem.ToString(); |
||
679 | ((CustomMarkerCopter)(copter.Shape)).setColor(s); |
||
680 | } |
||
2287 | - | 681 | copter.Offset = new System.Windows.Point(-18, -18); |
682 | copter.ZIndex = int.MaxValue; |
||
683 | MainMap.Markers.Add(copter); |
||
684 | copter.Position = MainMap.Position; |
||
685 | } |
||
2347 | - | 686 | void _setHomePos() |
2287 | - | 687 | { |
688 | pHome = MainMap.Position; |
||
689 | if (!MainMap.Markers.Contains(home)) |
||
690 | { |
||
691 | home = new GMapMarker(MainMap.Position); |
||
692 | home.Shape = new CustomMarkerHome(this, home, MainMap.Position.Lat.ToString("0.#######°") + System.Environment.NewLine + MainMap.Position.Lng.ToString("0.#######°")); |
||
693 | home.Offset = new System.Windows.Point(-18, -18); |
||
694 | // home.ZIndex = int.MaxValue; |
||
695 | MainMap.Markers.Add(home); |
||
696 | } |
||
697 | home.Position = MainMap.Position; |
||
698 | ((CustomMarkerHome)(home.Shape)).setText(MainMap.Position.Lat.ToString("0.#######°") + System.Environment.NewLine + MainMap.Position.Lng.ToString("0.#######°")); |
||
699 | } |
||
2347 | - | 700 | void _setActiveWP(int iIndex) |
2287 | - | 701 | { |
2347 | - | 702 | if (wpActiveMarker == null || !MainMap.Markers.Contains(wpActiveMarker)) |
703 | { |
||
704 | Dispatcher.Invoke(() => |
||
705 | { |
||
706 | wpActiveMarker = new GMapMarker(wpList[iIndex]); |
||
707 | wpActiveMarker.Shape = new CustomMarkerWPActive(this, wpActiveMarker, "wpActive", 0); |
||
708 | wpActiveMarker.Offset = new Point(-17.5, -17.5); |
||
709 | MainMap.Markers.Add(wpActiveMarker); |
||
710 | }); |
||
711 | } |
||
712 | else |
||
713 | Dispatcher.Invoke(() => wpActiveMarker.Position = wpList[iIndex]); |
||
714 | |||
715 | } |
||
716 | void _clearHomePos() |
||
717 | { |
||
2287 | - | 718 | MainMap.Markers.Remove(home); |
719 | } |
||
2335 | - | 720 | void _clearMapMarkers(Type markerType) |
721 | { |
||
722 | for (int k = 0; k < MainMap.Markers.Count;) |
||
723 | { |
||
724 | GMapMarker p = MainMap.Markers[k]; |
||
2340 | - | 725 | if (p.GetType() == markerType | (p.Shape != null && p.Shape.GetType() == markerType)) |
2335 | - | 726 | MainMap.Markers.Remove(p); |
727 | else |
||
728 | k++; |
||
729 | } |
||
2287 | - | 730 | |
2335 | - | 731 | } |
2369 | - | 732 | |
733 | GMapMarker _findWPMarker(string name) |
||
2368 | - | 734 | { |
735 | for (int k = 0; k < MainMap.Markers.Count;) |
||
736 | { |
||
737 | GMapMarker p = MainMap.Markers[k]; |
||
738 | if (p.GetType() == typeof(CustomMarkerWP) | (p.Shape != null && p.Shape.GetType() == typeof(CustomMarkerWP))) |
||
2369 | - | 739 | if (((CustomMarkerWP)p.Shape).WPText == name) |
740 | return p; |
||
2368 | - | 741 | else |
742 | k++; |
||
743 | else |
||
744 | k++; |
||
745 | } |
||
2369 | - | 746 | return null; |
2368 | - | 747 | } |
2369 | - | 748 | void _clearWPMarker(string name) |
749 | { |
||
750 | GMapMarker p = _findWPMarker(name); |
||
751 | if(p != null) |
||
752 | MainMap.Markers.Remove(p); |
||
753 | } |
||
2368 | - | 754 | void _renameWPMarker(string s1, string s2) |
755 | { |
||
2369 | - | 756 | GMapMarker p = _findWPMarker(s1); |
757 | if (p != null) |
||
758 | ((CustomMarkerWP)p.Shape).WPText = s2; |
||
2368 | - | 759 | } |
2372 | - | 760 | void _WPMarkerSetType(string text, int type) |
761 | { |
||
762 | GMapMarker p = _findWPMarker(text); |
||
763 | if (p != null) |
||
764 | ((CustomMarkerWP)p.Shape).WPType = type; |
||
765 | } |
||
2369 | - | 766 | void _repositionWPMarker(PointLatLng point, string name) |
767 | { |
||
768 | GMapMarker p = _findWPMarker(name); |
||
769 | if (p != null) |
||
770 | p.Position = point; |
||
771 | } |
||
772 | |||
2287 | - | 773 | // access mode |
774 | private void comboBoxMode_DropDownClosed(object sender, EventArgs e) |
||
775 | { |
||
776 | MainMap.Manager.Mode = (AccessMode)comboBoxMode.SelectedItem; |
||
777 | MainMap.ReloadMap(); |
||
778 | } |
||
779 | // zoom up |
||
780 | private void czuZoomUp_Click(object sender, RoutedEventArgs e) |
||
781 | { |
||
782 | MainMap.Zoom = ((int)MainMap.Zoom) + 1; |
||
783 | } |
||
784 | |||
785 | // zoom down |
||
786 | private void czuZoomDown_Click(object sender, RoutedEventArgs e) |
||
787 | { |
||
788 | MainMap.Zoom = ((int)(MainMap.Zoom + 0.99)) - 1; |
||
789 | } |
||
790 | |||
791 | // prefetch |
||
792 | private void buttonPrefetch_Click(object sender, RoutedEventArgs e) |
||
793 | { |
||
794 | RectLatLng area = MainMap.SelectedArea; |
||
795 | if (!area.IsEmpty) |
||
796 | { |
||
797 | for (int i = (int)MainMap.Zoom; i <= MainMap.MaxZoom; i++) |
||
798 | { |
||
799 | MessageBoxResult res = MessageBox.Show("Ready ripp at Zoom = " + i + " ?", "GMap.NET", MessageBoxButton.YesNoCancel); |
||
800 | |||
801 | if (res == MessageBoxResult.Yes) |
||
802 | { |
||
803 | TilePrefetcher obj = new TilePrefetcher(); |
||
804 | obj.Owner = this; |
||
805 | obj.ShowCompleteMessage = true; |
||
806 | obj.Start(area, i, MainMap.MapProvider, 100); |
||
807 | } |
||
808 | else if (res == MessageBoxResult.No) |
||
809 | { |
||
810 | continue; |
||
811 | } |
||
812 | else if (res == MessageBoxResult.Cancel) |
||
813 | { |
||
814 | break; |
||
815 | } |
||
816 | } |
||
817 | } |
||
818 | else |
||
819 | { |
||
820 | MessageBox.Show("Select map area holding ALT", "GMap.NET", MessageBoxButton.OK, MessageBoxImage.Exclamation); |
||
821 | } |
||
822 | } |
||
823 | |||
824 | // goto by geocoder |
||
825 | private void buttonGeoCoding_Click(object sender, RoutedEventArgs e) |
||
826 | { |
||
827 | _goto_byGeoCoder(); |
||
828 | } |
||
829 | // goto by geocoder |
||
830 | private void textBoxGeo_KeyUp(object sender, System.Windows.Input.KeyEventArgs e) |
||
831 | { |
||
832 | if (e.Key == System.Windows.Input.Key.Enter) |
||
833 | _goto_byGeoCoder(); |
||
834 | } |
||
835 | void _goto_byGeoCoder() |
||
836 | { |
||
837 | GeoCoderStatusCode status = MainMap.SetPositionByKeywords(textBoxGeo.Text); |
||
838 | if (status != GeoCoderStatusCode.G_GEO_SUCCESS) |
||
839 | { |
||
840 | MessageBox.Show("Geocoder can't find: '" + textBoxGeo.Text + "', reason: " + status.ToString(), "GMap.NET", MessageBoxButton.OK, MessageBoxImage.Exclamation); |
||
841 | } |
||
842 | } |
||
843 | private void buttonGeoLoc_Click(object sender, RoutedEventArgs e) |
||
844 | { |
||
845 | try |
||
846 | { |
||
847 | double lat = double.Parse(textBoxLat.Text, System.Globalization.CultureInfo.InvariantCulture); |
||
848 | double lng = double.Parse(textBoxLng.Text, System.Globalization.CultureInfo.InvariantCulture); |
||
849 | |||
850 | MainMap.Position = new PointLatLng(lat, lng); |
||
851 | } |
||
852 | catch (Exception ex) |
||
853 | { |
||
854 | MessageBox.Show("incorrect coordinate format: " + ex.Message); |
||
855 | } |
||
856 | |||
857 | } |
||
858 | |||
859 | private void ReloadMap_Click(object sender, RoutedEventArgs e) |
||
860 | { |
||
861 | MainMap.ReloadMap(); |
||
862 | } |
||
863 | |||
864 | private void MainMap_OnPositionChanged(PointLatLng point) |
||
865 | { |
||
866 | if (_bFollowCopter) |
||
867 | _setCopterData(MainMap.Position); |
||
868 | } |
||
869 | |||
870 | private void MainMap_OnMapZoomChanged() |
||
871 | { |
||
872 | if (_bFollowCopter) |
||
873 | _setCopterData(MainMap.Position); |
||
874 | if((int)sliderMapZoom.Value != MainMap.Zoom) |
||
875 | sliderMapZoom.Value = MainMap.Zoom; |
||
876 | } |
||
877 | |||
878 | void _setCopterData(PointLatLng p) |
||
879 | { |
||
880 | Dispatcher.Invoke(() => |
||
881 | { |
||
882 | copter.Position = p; |
||
883 | ((CustomMarkerCopter)(copter.Shape)).setText(p.Lat.ToString("0.#######°") + System.Environment.NewLine + p.Lng.ToString("0.#######°")); |
||
884 | textBoxLat_currentPos.Text = p.Lat.ToString() + "°"; |
||
885 | textBoxLng_currentPos.Text = p.Lng.ToString() + "°"; |
||
886 | }); |
||
887 | if (home != null && MainMap.Markers.Contains(home)) |
||
888 | { |
||
889 | Dispatcher.Invoke(() => ArtHor.rotateHome = GMapProviders.EmptyProvider.Projection.GetBearing(copter.Position, home.Position)); |
||
890 | double d = GMapProviders.EmptyProvider.Projection.GetDistance(home.Position, copter.Position); |
||
891 | Dispatcher.Invoke(() => tbTopDistanceHP.Text = (d * 1000).ToString("0.0 m")); |
||
2291 | - | 892 | |
893 | if(d*1000 < _dThresholdDistanceWarn) |
||
894 | { |
||
895 | _iDistanceJitter = 0; _bVoiceDistanceActive = false; |
||
896 | if (stbDistanceWarnAnim != null && _bAnimDistanceActive) |
||
897 | { |
||
898 | Dispatcher.Invoke(() => stbDistanceWarnAnim.Stop()); |
||
899 | _bAnimDistanceActive = false; |
||
900 | } |
||
901 | } |
||
902 | else |
||
903 | { |
||
904 | if (_iDistanceJitter < 20) |
||
905 | { _iDistanceJitter++; } |
||
906 | if (_iDistanceJitter == 20) |
||
907 | { |
||
908 | if (stbDistanceWarnAnim != null && !_bAnimDistanceActive) |
||
909 | { |
||
910 | Dispatcher.Invoke(() => stbDistanceWarnAnim.Begin()); |
||
911 | _bAnimDistanceActive = true; |
||
912 | } |
||
913 | if (_bVoiceDistancePlay && !_bVoiceDistanceActive) |
||
914 | { |
||
2295 | - | 915 | Thread t = new Thread(()=>_mediaPlayer("Voice\\Distance.mp3")); |
916 | t.Start(); |
||
2291 | - | 917 | _bVoiceDistanceActive = true; |
918 | } |
||
919 | _iDistanceJitter++; |
||
920 | } |
||
921 | } |
||
2287 | - | 922 | } |
923 | } |
||
924 | |||
925 | private void checkBoxFollowCopter_Click(object sender, RoutedEventArgs e) |
||
926 | { |
||
927 | _bFollowCopter = (bool)checkBoxFollowCopter.IsChecked; |
||
928 | } |
||
929 | |||
930 | private void sliderMapZoom_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) |
||
931 | { |
||
932 | if (MainMap.Zoom != sliderMapZoom.Value) |
||
933 | MainMap.Zoom = (int)sliderMapZoom.Value; |
||
934 | } |
||
935 | #region Touch zooming hackattack ;) |
||
936 | /// <summary> |
||
937 | /// inspired by http://www.codeproject.com/Articles/692286/WPF-and-multi-touch |
||
938 | /// </summary> |
||
939 | bool bFirstAccess = true; |
||
940 | double dDistance = 0; |
||
941 | int iZoom; |
||
942 | private void MainMap_StylusDown(object sender, StylusDownEventArgs e) |
||
943 | { |
||
944 | var id = e.StylusDevice.Id; |
||
945 | e.StylusDevice.Capture(MainMap); |
||
946 | if (iFirstStylusID == -1) |
||
947 | { |
||
948 | iFirstStylusID = id; |
||
949 | } |
||
950 | else |
||
951 | { |
||
952 | |||
953 | MainMap.CanDragMap = false; |
||
954 | } |
||
955 | } |
||
956 | private void MainMap_StylusUp(object sender, StylusEventArgs e) |
||
957 | { |
||
958 | MainMap.ReleaseStylusCapture(); |
||
959 | iFirstStylusID = -1; |
||
960 | bFirstAccess = true; |
||
961 | MainMap.CanDragMap = true; |
||
962 | iZoom = 0; |
||
963 | } |
||
964 | private void MainMap_StylusMove(object sender, StylusEventArgs e) |
||
965 | { |
||
966 | var id = e.StylusDevice.Id; |
||
967 | var tp = e.GetPosition(MainMap); |
||
968 | |||
969 | // This is the first Stylus point; just record its position. |
||
970 | if (id == iFirstStylusID) |
||
971 | { |
||
972 | pTouch1.X = tp.X; |
||
973 | pTouch1.Y = tp.Y; |
||
974 | } |
||
975 | else |
||
976 | if (iFirstStylusID > -1) |
||
977 | { |
||
978 | pTouch2.X = tp.X; |
||
979 | pTouch2.Y = tp.Y; |
||
980 | double distance = Point.Subtract(pTouch1, pTouch2).Length; |
||
981 | if (!bFirstAccess) |
||
982 | { |
||
983 | if (distance > dDistance) |
||
984 | iZoom++; |
||
985 | else |
||
986 | if (distance < dDistance) |
||
987 | iZoom--; |
||
988 | } |
||
989 | if (iZoom > 30) |
||
990 | { |
||
991 | iZoom = 0; |
||
992 | Dispatcher.Invoke(() => sliderMapZoom.Value += 1); |
||
993 | } |
||
994 | if (iZoom < -30) |
||
995 | { |
||
996 | iZoom = 0; |
||
997 | Dispatcher.Invoke(() => sliderMapZoom.Value -= 1); |
||
998 | } |
||
999 | dDistance = distance; |
||
1000 | bFirstAccess = false; |
||
1001 | } |
||
1002 | } |
||
1003 | #endregion Touch zooming hackattack ;) |
||
1004 | |||
1005 | #endregion GMap |
||
1006 | |||
1007 | #region settings |
||
1008 | private void cBoxTimingsDebug_DropDownClosed(object sender, EventArgs e) |
||
1009 | { |
||
1010 | if(! _bCBInit && cBoxTimingsDebug.SelectedIndex > -1) |
||
1011 | debugInterval = (byte)(Convert.ToInt16(cBoxTimingsDebug.SelectedItem) / 10); |
||
1012 | } |
||
1013 | private void cBoxTimingsNav_DropDownClosed(object sender, EventArgs e) |
||
1014 | { |
||
1015 | if(! _bCBInit && cBoxTimingsNav.SelectedIndex > -1) |
||
1016 | navctrlInterval = (byte)(Convert.ToInt16(cBoxTimingsNav.SelectedItem) / 10); |
||
1017 | } |
||
1018 | private void cBoxTimingsBl_DropDownClosed(object sender, EventArgs e) |
||
1019 | { |
||
1020 | if (!_bCBInit && cBoxTimingsBl.SelectedIndex > -1) |
||
1021 | blctrlInterval = (byte)(Convert.ToInt16(cBoxTimingsBl.SelectedItem) / 10); |
||
1022 | } |
||
1023 | private void cBoxTimingsOSD_DropDownClosed(object sender, EventArgs e) |
||
1024 | { |
||
1025 | if (!_bCBInit && cBoxTimingsOSD.SelectedIndex > -1) |
||
1026 | OSDInterval = (byte)(Convert.ToInt16(cBoxTimingsOSD.SelectedItem) / 10); |
||
1027 | } |
||
1028 | private void chkbAutoDbg_Click(object sender, RoutedEventArgs e) |
||
1029 | { |
||
1030 | if (!_init) _debugDataAutorefresh = (bool)chkbAutoDbg.IsChecked; |
||
1031 | } |
||
1032 | private void chkbAutoNav_Click(object sender, RoutedEventArgs e) |
||
1033 | { |
||
1034 | if (!_init) _navCtrlDataAutorefresh = (bool)chkbAutoNav.IsChecked; |
||
1035 | } |
||
1036 | private void chkbAutoBL_Click(object sender, RoutedEventArgs e) |
||
1037 | { |
||
1038 | if (!_init) _blctrlDataAutorefresh = (bool)chkbAutoBL.IsChecked; |
||
1039 | } |
||
1040 | private void chkbAutoOSD_Click(object sender, RoutedEventArgs e) |
||
1041 | { |
||
1042 | if (!_init) _OSDAutorefresh = (bool)chkbAutoOSD.IsChecked; |
||
1043 | } |
||
1044 | |||
1045 | private void cBoxLiPoCells_DropDownClosed(object sender, EventArgs e) |
||
1046 | { |
||
1047 | if (cBoxLiPoCells.SelectedIndex > -1) |
||
1048 | { |
||
1049 | _LipoCells = cBoxLiPoCells.SelectedIndex + 3; |
||
1050 | _LipoMinMax(); |
||
1051 | } |
||
1052 | } |
||
1053 | void _LipoMinMax() |
||
1054 | { |
||
1055 | _dLipoVMax = (double)(_LipoCells) * 4.22; |
||
1056 | _dLipoVMin = (double)_LipoCells * 3; |
||
1057 | pbTopVoltage.Maximum = _dLipoVMax; |
||
1058 | pbTopVoltage.Minimum = _dLipoVMin; |
||
1059 | sliderThresholdVoltageWarn.Maximum = _dLipoVMax; |
||
1060 | sliderThresholdVoltageWarn.Minimum = _dLipoVMin; |
||
1061 | } |
||
1062 | private void cBoxMotors_DropDownClosed(object sender, EventArgs e) |
||
1063 | { |
||
1064 | if (cBoxMotors.SelectedIndex > -1) |
||
1065 | { |
||
1066 | _iMotors = cBoxMotors.SelectedIndex + 3; |
||
1067 | Dispatcher.Invoke(() => |
||
1068 | { |
||
1069 | dgvMotors1.Height = (272 / 12.6) * (_iMotors + 1); //272 / 12.6 --> Workaround, cause the headerheight = NaN...? |
||
1070 | GridMotors.Height = dgvMotors1.Height + 10; |
||
1071 | }); |
||
1072 | } |
||
1073 | } |
||
1074 | void _setMotorGridSize() |
||
1075 | { |
||
1076 | if (dgvMotors1.Columns.Count > 2) |
||
1077 | { |
||
1078 | dgvMotors1.Columns[0].Width = 24; |
||
1079 | dgvMotors1.Columns[1].Width = 50; |
||
1080 | dgvMotors1.Columns[2].Width = 50; |
||
1081 | dgvMotors1.Height = (272 / 12.6) * (_iMotors + 1); |
||
1082 | GridMotors.Height = dgvMotors1.Height + 10; |
||
1083 | } |
||
1084 | |||
1085 | } |
||
1086 | #endregion settings |
||
1087 | |||
1088 | #region functions |
||
1089 | |||
1090 | #region logging |
||
1091 | /// <summary> Log data to the terminal window. </summary> |
||
1092 | /// <param name="msgtype"> The type of message to be written. </param> |
||
1093 | /// <param name="msg"> The string containing the message to be shown. </param> |
||
1094 | private void Log(LogMsgType msgtype, string msg) |
||
1095 | { |
||
1096 | Dispatcher.Invoke(() => |
||
1097 | { |
||
1098 | // rtfTerminal.CaretPosition = rtfTerminal.CaretPosition.DocumentEnd; |
||
1099 | // rtfTerminal.Foreground = new SolidColorBrush(LogMsgTypeColor[(int)msgtype]); |
||
1100 | // rtfTerminal.AppendText(msg + "\r"); |
||
1101 | TextRange tr = new TextRange(rtfTerminal.Document.ContentEnd,rtfTerminal.Document.ContentEnd); |
||
1102 | tr.Text = msg; |
||
1103 | tr.ApplyPropertyValue(TextElement.ForegroundProperty, new SolidColorBrush(LogMsgTypeColor[(int)msgtype])); |
||
1104 | rtfTerminal.AppendText("\r"); |
||
1105 | rtfTerminal.ScrollToEnd(); |
||
1106 | }); |
||
1107 | } |
||
1108 | private void ErrorLog(LogMsgType msgtype, string msg) |
||
1109 | { |
||
1110 | Dispatcher.Invoke(() => |
||
1111 | { |
||
1112 | TextRange tr = new TextRange(rtfError.Document.ContentEnd, rtfError.Document.ContentEnd); |
||
1113 | tr.Text = msg; |
||
1114 | tr.ApplyPropertyValue(TextElement.ForegroundProperty, new SolidColorBrush(LogMsgTypeColor[(int)msgtype])); |
||
1115 | rtfError.AppendText("\r"); |
||
1116 | rtfError.ScrollToEnd(); |
||
1117 | |||
1118 | _bErrorLog = true; |
||
1119 | }); |
||
1120 | } |
||
1121 | /// <summary> |
||
1122 | /// Clear the line in the errorlog window |
||
1123 | /// containing the error string when error has ceased |
||
1124 | /// </summary> |
||
1125 | /// <param name="s">substring of errrormessage</param> |
||
1126 | void _clearErrorLog(string s) |
||
1127 | { |
||
1128 | Dispatcher.Invoke((Action)(() => |
||
1129 | { |
||
1130 | TextRange searchRange = new TextRange(rtfError.Document.ContentStart, rtfError.Document.ContentEnd); |
||
1131 | TextRange foundRange = FindTextInRange(searchRange, s); |
||
1132 | |||
1133 | int iStart = searchRange.Text.IndexOf(s, StringComparison.OrdinalIgnoreCase); |
||
1134 | |||
1135 | |||
1136 | if (iStart > -1) |
||
1137 | { |
||
1138 | int iLength = 0; |
||
1139 | int iEnd = searchRange.Text.IndexOf('\r', iStart); |
||
1140 | if (iEnd > 0) |
||
1141 | { |
||
1142 | iLength = iEnd + 1; |
||
1143 | int iHttp = searchRange.Text.IndexOf("http", iEnd); |
||
1144 | if (iHttp == iLength) |
||
1145 | { |
||
1146 | int iEnd2 = searchRange.Text.IndexOf('\r', iLength); |
||
1147 | if (iEnd2 > iLength) |
||
1148 | { |
||
1149 | iLength = iEnd2 + 1; |
||
1150 | // TextRange result = new TextRange(rtfError.Document.ContentStart.GetPositionAtOffset(iStart), GetTextPositionAtOffset(rtfError.Document.ContentStart.GetPositionAtOffset(iStart), iLength)); |
||
1151 | |||
1152 | rtfError.Selection.Select(rtfError.Document.ContentStart.GetPositionAtOffset(iStart), GetTextPositionAtOffset(rtfError.Document.ContentStart.GetPositionAtOffset(iStart), iLength)); |
||
1153 | rtfError.Selection.Text = string.Empty; |
||
1154 | if (rtfError.Document.ContentEnd.GetTextRunLength(LogicalDirection.Backward) < 2) _bErrorLog = false; |
||
1155 | } |
||
1156 | |||
1157 | } |
||
1158 | else |
||
1159 | { |
||
1160 | rtfError.Selection.Select(rtfError.Document.ContentStart.GetPositionAtOffset(iStart), GetTextPositionAtOffset(rtfError.Document.ContentStart.GetPositionAtOffset(iStart), iLength)); |
||
1161 | rtfError.Selection.Text = string.Empty; |
||
1162 | if (rtfError.Document.ContentEnd.GetTextRunLength(LogicalDirection.Backward) < 2) _bErrorLog = false; |
||
1163 | } |
||
1164 | } |
||
1165 | } |
||
1166 | })); |
||
1167 | |||
1168 | } |
||
1169 | public TextRange FindTextInRange(TextRange searchRange, string searchText) |
||
1170 | { |
||
1171 | int offset = searchRange.Text.IndexOf(searchText, StringComparison.OrdinalIgnoreCase); |
||
1172 | if (offset < 0) |
||
1173 | return null; // Not found |
||
1174 | |||
1175 | var start = GetTextPositionAtOffset(searchRange.Start, offset); |
||
1176 | TextRange result = new TextRange(start, GetTextPositionAtOffset(start, searchText.Length)); |
||
1177 | |||
1178 | return result; |
||
1179 | } |
||
1180 | TextPointer GetTextPositionAtOffset(TextPointer position, int characterCount) |
||
1181 | { |
||
1182 | while (position != null) |
||
1183 | { |
||
1184 | if (position.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.Text) |
||
1185 | { |
||
1186 | int count = position.GetTextRunLength(LogicalDirection.Forward); |
||
1187 | if (characterCount <= count) |
||
1188 | { |
||
1189 | return position.GetPositionAtOffset(characterCount); |
||
1190 | } |
||
1191 | |||
1192 | characterCount -= count; |
||
1193 | } |
||
1194 | |||
1195 | TextPointer nextContextPosition = position.GetNextContextPosition(LogicalDirection.Forward); |
||
1196 | if (nextContextPosition == null) |
||
1197 | return position; |
||
1198 | |||
1199 | position = nextContextPosition; |
||
1200 | } |
||
1201 | |||
1202 | return position; |
||
1203 | } |
||
1204 | #endregion logging |
||
1205 | |||
1206 | #region processing received data |
||
1207 | |||
1208 | private void processMessage(byte[] message) |
||
1209 | { |
||
1210 | if (message.Length > 0) |
||
1211 | { |
||
1212 | _iLifeCounter++; |
||
1213 | //Log(LogMsgType.Incoming, BitConverter.ToString(message)); |
||
1214 | //Log(LogMsgType.Incoming, message.Length.ToString()); |
||
1215 | string s = new string(ASCIIEncoding.ASCII.GetChars(message, 0, message.Length)); |
||
1216 | char cmdID; |
||
1217 | byte adr; |
||
1218 | byte[] data; |
||
1219 | byte[] tmp = null; |
||
1220 | if (message[0] != '#') |
||
1221 | { |
||
1222 | int iFound = -1; |
||
1223 | for (int i = 0; i < message.Length; i++) //Sometimes the FC/NC sends strings without termination (like WP messages) |
||
1224 | { //so this is a workaround to not spam the log box |
||
1225 | if (message[i] == 35) |
||
1226 | { |
||
1227 | iFound = i; |
||
1228 | break; |
||
1229 | } |
||
1230 | } |
||
1231 | if (iFound > 0) |
||
1232 | { |
||
1233 | s = new string(ASCIIEncoding.ASCII.GetChars(message, 0, iFound)); |
||
1234 | tmp = new byte[message.Length - iFound]; |
||
1235 | Buffer.BlockCopy(message, iFound, tmp, 0, message.Length - iFound); |
||
1236 | } |
||
1237 | s = s.Trim('\0', '\n', '\r'); |
||
1238 | if (s.Length > 0) |
||
1239 | Log(LogMsgType.Normal, s); |
||
1240 | if (tmp != null) |
||
1241 | { |
||
1242 | s = new string(ASCIIEncoding.ASCII.GetChars(tmp, 0, tmp.Length)); |
||
1243 | processMessage(tmp); |
||
1244 | } |
||
1245 | } |
||
1246 | //Debug.Print(s); |
||
1247 | else |
||
1248 | { |
||
1249 | FlightControllerMessage.ParseMessage(message, out cmdID, out adr, out data); |
||
1250 | |||
1251 | if (adr == 255) { crcError++; } |
||
1252 | else crcError = 0; |
||
1253 | Dispatcher.Invoke(() => tbCrc.Text = crcError.ToString()); |
||
1254 | //display the active controller (FC / NC) |
||
1255 | 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...??? |
||
1256 | { |
||
1257 | _iCtrlAct = adr; |
||
1258 | switch (adr) |
||
1259 | { |
||
1260 | case 1: |
||
1261 | Dispatcher.Invoke(() => tbCtrl.Text = "FC"); |
||
2298 | - | 1262 | Dispatcher.Invoke(() => buttonSwitchNC.Visibility = Visibility.Visible); |
2287 | - | 1263 | //Dispatcher.Invoke(() => labelSwitchToNavi.Visibility = Visibility.Visible); |
1264 | // _setFieldsNA(); //display fields NA for FC |
||
1265 | break; |
||
1266 | case 2: |
||
1267 | Dispatcher.Invoke(() => tbCtrl.Text = "NC"); |
||
1268 | //Dispatcher.Invoke(() => buttonSwitchNC.Visibility = Visibility.Hidden); |
||
1269 | //Dispatcher.Invoke(() => labelSwitchToNavi.Visibility = Visibility.Hidden); |
||
1270 | break; |
||
1271 | //case 3: |
||
1272 | // lblCtrl.Invoke((Action)(() => lblCtrl.Text = "MK3MAG")); |
||
1273 | // break; |
||
1274 | //case 4: |
||
1275 | // lblCtrl.Invoke((Action)(() => lblCtrl.Text = "BL-CTRL")); |
||
1276 | // break; |
||
1277 | default: |
||
1278 | Dispatcher.Invoke(() => tbCtrl.Text = "NA"); |
||
1279 | break; |
||
1280 | } |
||
1281 | // _loadLabelNames(); |
||
1282 | } |
||
1283 | // else |
||
1284 | // Debug.Print("Address == 0?"); |
||
1285 | |||
1286 | if (data != null && data.Length > 0) |
||
1287 | { |
||
1288 | s = new string(ASCIIEncoding.ASCII.GetChars(data, 1, data.Length - 1)); |
||
1289 | s = s.Trim('\0', '\n'); |
||
1290 | |||
1291 | switch (cmdID) |
||
1292 | { |
||
1293 | //case 'A': //Label names |
||
1294 | // _processLabelNames(s); |
||
1295 | // break; |
||
1296 | |||
1297 | case 'D': //Debug data |
||
1298 | _processDebugVals(adr, data); |
||
1299 | break; |
||
1300 | |||
1301 | case 'V': //Version |
||
1302 | _processVersion(adr, data); |
||
1303 | break; |
||
1304 | |||
1305 | case 'K'://BL-CTRL data |
||
1306 | _processBLCtrl(data); |
||
1307 | break; |
||
1308 | |||
1309 | case 'O': //NC Data |
||
1310 | _processNCData(data); |
||
1311 | break; |
||
1312 | |||
1313 | case 'E': //NC error-string |
||
1314 | ErrorLog(LogMsgType.Error, "NC Error: " + s); |
||
1315 | break; |
||
1316 | |||
1317 | case 'L': //OSD Menue (called by pagenumber) |
||
1318 | _processOSDSingle(data); |
||
1319 | break; |
||
1320 | |||
1321 | case 'H': //OSD Menue (with autoupdate - called by Key) |
||
1322 | _processOSDAuto(data); |
||
1323 | break; |
||
1324 | |||
1325 | case 'X': //Waypoint data |
||
1326 | _processWPData(data); |
||
1327 | break; |
||
1328 | |||
2313 | - | 1329 | case 'W': //return new Waypoint items count after sending waypoint to copter |
1330 | _iWPCount = data[0]; |
||
1331 | break; |
||
2287 | - | 1332 | //default: |
1333 | // Log(LogMsgType.Incoming, "cmd: " + cmdID.ToString()); |
||
1334 | // Log(LogMsgType.Incoming, BitConverter.ToString(data)); |
||
1335 | // break; |
||
1336 | } |
||
1337 | } |
||
1338 | //else |
||
1339 | //{ |
||
1340 | // Log(LogMsgType.Incoming, "cmd: " + cmdID.ToString()); |
||
1341 | // Log(LogMsgType.Incoming, BitConverter.ToString(data)); |
||
1342 | //} |
||
1343 | } |
||
1344 | } |
||
1345 | } |
||
1346 | /// <summary> |
||
1347 | /// Analog label names 'A' |
||
1348 | /// each label name is returned as a single string |
||
1349 | /// and added to string array sAnalogLabel[] |
||
1350 | /// and the datatable dtAnalog |
||
1351 | /// </summary> |
||
1352 | /// <param name="s">the label name</param> |
||
1353 | void _processLabelNames(string s) |
||
1354 | { |
||
1355 | //if (iLableIndex < 32) |
||
1356 | //{ |
||
1357 | // sAnalogLabel[iLableIndex] = s; |
||
1358 | // if (dtAnalog.Rows.Count < 32) |
||
1359 | // dtAnalog.Rows.Add(s, ""); |
||
1360 | // else |
||
1361 | // dtAnalog.Rows[iLableIndex].SetField(0, s); |
||
1362 | |||
1363 | // // _getAnalogLabels(iLableIndex + 1); |
||
1364 | //} |
||
1365 | //Debug.Print(s); |
||
1366 | } |
||
1367 | /// <summary> |
||
1368 | /// Debug values 'D' |
||
1369 | /// </summary> |
||
1370 | /// <param name="adr">adress of the active controller (1-FC, 2-NC)</param> |
||
1371 | /// <param name="data">the received byte array to process</param> |
||
1372 | void _processDebugVals(byte adr, byte[] data) |
||
1373 | { |
||
1374 | if (data.Length == 66) |
||
1375 | { |
||
2324 | - | 1376 | |
2287 | - | 1377 | double v; |
1378 | int index = 0; |
||
1379 | Int16 i16 = 0; |
||
1380 | double dTemp = 0; |
||
1381 | for (int i = 2; i < 66; i += 2) |
||
1382 | { |
||
1383 | i16 = data[i + 1]; |
||
1384 | i16 = (Int16)(i16 << 8); |
||
1385 | iAnalogData[index] = data[i] + i16; |
||
1386 | sAnalogData[index] = (data[i] + i16).ToString(); |
||
1387 | // dtAnalog.Rows[index].SetField(1, sAnalogData[index]); |
||
1388 | |||
1389 | if (adr == 2) //NC |
||
1390 | { |
||
1391 | switch (index) |
||
1392 | { |
||
1393 | case 0: //pitch (German: nick) |
||
1394 | Dispatcher.Invoke(() => ArtHor.Pitch = ((double)iAnalogData[index] / (double)10)); |
||
1395 | Dispatcher.Invoke((Action)(() => tbPitch.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0°"))); |
||
1396 | break; |
||
1397 | case 1: //roll |
||
1398 | Dispatcher.Invoke(() => ArtHor.Roll = ((double)iAnalogData[index] / (double)10)); |
||
1399 | Dispatcher.Invoke((Action)(() => tbRoll.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0°"))); |
||
1400 | break; |
||
1401 | case 4: //altitude |
||
1402 | Dispatcher.Invoke(() => tbAlt.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0 m")); |
||
1403 | Dispatcher.Invoke(() => tbTopHeight.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0 m")); |
||
2324 | - | 1404 | Dispatcher.Invoke(() => { drGPX[3] = (double)iAnalogData[index] / (double)10; }); |
2287 | - | 1405 | break; |
1406 | case 7: //Voltage |
||
1407 | v = (double)iAnalogData[index] / (double)10; |
||
1408 | Dispatcher.Invoke(() => tbVolt.Text = v.ToString("0.0 V")); |
||
1409 | Dispatcher.Invoke(() => tbTopVoltage.Text = v.ToString("0.0 V")); |
||
1410 | Dispatcher.Invoke(() => pbTopVoltage.Value = v); |
||
1411 | if (v - _dLipoVMin < 1 | v < _dThresholdVoltageWarn) |
||
1412 | { |
||
1413 | if (v == _dVoltLast) |
||
1414 | if(_iVoltJitter < 20) _iVoltJitter++; |
||
1415 | else |
||
1416 | { |
||
1417 | _iVoltJitter = 0; |
||
1418 | _dVoltLast = v; |
||
1419 | } |
||
1420 | if (_iVoltJitter == 20) |
||
1421 | { |
||
1422 | Dispatcher.Invoke(() => pbTopVoltage.Foreground = Brushes.Orange); |
||
1423 | |||
1424 | if (v - _dLipoVMin < 1 | v < _dThresholdVoltageCrit) |
||
1425 | { |
||
1426 | Dispatcher.Invoke(() => pbTopVoltage.Foreground = Brushes.Red); |
||
1427 | if (stbVoltageCritAnim != null && !_bCritAnimVoltActive) |
||
1428 | { |
||
1429 | Dispatcher.Invoke(() => stbVoltageCritAnim.Begin()); |
||
1430 | _bCritAnimVoltActive = true; |
||
1431 | } |
||
1432 | if (_bVoiceVoltPlay && !_bCritVoiceVoltActive) |
||
1433 | { |
||
2295 | - | 1434 | Thread t = new Thread(() => _mediaPlayer("Voice\\CriticalBattery.mp3")); |
1435 | t.Start(); |
||
2287 | - | 1436 | _bCritVoiceVoltActive = true; |
1437 | } |
||
1438 | } |
||
1439 | else |
||
1440 | { |
||
1441 | if (stbVoltageCritAnim != null && _bCritAnimVoltActive) |
||
1442 | { |
||
1443 | Dispatcher.Invoke(() => stbVoltageCritAnim.Stop()); |
||
1444 | _bCritAnimVoltActive = false; |
||
1445 | } |
||
1446 | _bCritVoiceVoltActive = false; |
||
1447 | |||
2291 | - | 1448 | if (_bVoiceVoltPlay && !_bWarnVoiceVoltActive) |
2287 | - | 1449 | { |
2295 | - | 1450 | Thread t = new Thread(() => _mediaPlayer("Voice\\LowBattery.mp3")); |
1451 | t.Start(); |
||
2291 | - | 1452 | _bWarnVoiceVoltActive = true; |
2287 | - | 1453 | } |
1454 | } |
||
1455 | } |
||
1456 | } |
||
1457 | else |
||
1458 | { |
||
1459 | Dispatcher.Invoke(() => pbTopVoltage.Foreground = new SolidColorBrush(Color.FromArgb(255, 107, 195, 123))); |
||
1460 | if (stbVoltageCritAnim != null && _bCritAnimVoltActive) |
||
1461 | { |
||
1462 | Dispatcher.Invoke(() => stbVoltageCritAnim.Stop()); |
||
1463 | _bCritAnimVoltActive = false; |
||
1464 | } |
||
1465 | _bCritVoiceVoltActive = false; |
||
2291 | - | 1466 | _bWarnVoiceVoltActive = false; |
2287 | - | 1467 | _iVoltJitter = 0; |
1468 | } |
||
1469 | break; |
||
1470 | case 8: // Current |
||
1471 | Dispatcher.Invoke(() => tbCur.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0 A")); |
||
1472 | Dispatcher.Invoke(() => tbTopCurrent.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0 A")); |
||
1473 | break; |
||
1474 | case 10: //heading |
||
2291 | - | 1475 | Dispatcher.Invoke((Action)(() => tbHeading.Text = sAnalogData[index] + "°")); |
2287 | - | 1476 | Dispatcher.Invoke(() => ArtHor.rotate = iAnalogData[index]); |
1477 | break; |
||
1478 | case 12: // SPI error |
||
2291 | - | 1479 | Dispatcher.Invoke((Action)(() => tbSPI.Text = sAnalogData[index])); |
2287 | - | 1480 | break; |
1481 | case 14: //i2c error |
||
2291 | - | 1482 | Dispatcher.Invoke((Action)(() => tbI2C.Text = sAnalogData[index])); |
2287 | - | 1483 | break; |
1484 | case 20: //Earthmagnet field |
||
2291 | - | 1485 | Dispatcher.Invoke((Action)(() => tbMagF.Text = sAnalogData[index] + "%")); |
1486 | Dispatcher.Invoke((Action)(() => tbTopEarthMag.Text = sAnalogData[index] + "%")); |
||
1487 | |||
1488 | if (Math.Abs(100 - iAnalogData[index]) < _iThresholdMagField) |
||
1489 | { |
||
1490 | Dispatcher.Invoke(() => imageEarthMag.Source = new BitmapImage(new Uri("Images/EarthMag.png", UriKind.Relative))); |
||
1491 | _iMagneticFieldJitter = 0; _bVoiceMagneticFieldActive = false; |
||
1492 | if (stbMagneticFieldAnim != null && _bAnimMagneticFieldActive) |
||
1493 | { |
||
1494 | Dispatcher.Invoke(() => stbMagneticFieldAnim.Stop()); |
||
1495 | _bAnimMagneticFieldActive = false; |
||
1496 | } |
||
1497 | } |
||
1498 | else |
||
1499 | { |
||
1500 | Dispatcher.Invoke(() => imageEarthMag.Source = new BitmapImage(new Uri("Images/EarthMag_R.png", UriKind.Relative))); |
||
1501 | if(_iMagneticFieldLast >= Math.Abs(100 - iAnalogData[index])) |
||
1502 | { |
||
1503 | if (_iMagneticFieldJitter < 20) |
||
1504 | _iMagneticFieldJitter++; |
||
1505 | } |
||
1506 | else |
||
1507 | { |
||
1508 | _iMagneticFieldJitter = 0; |
||
1509 | _iMagneticFieldLast = Math.Abs(100 - iAnalogData[index]); |
||
1510 | } |
||
1511 | if(_iMagneticFieldJitter == 20) |
||
1512 | { |
||
1513 | if (stbMagneticFieldAnim != null && !_bAnimMagneticFieldActive) |
||
1514 | { |
||
1515 | Dispatcher.Invoke(() => stbMagneticFieldAnim.Begin()); |
||
1516 | _bAnimMagneticFieldActive = true; |
||
1517 | } |
||
1518 | if (_bVoiceMagneticFieldPlay && !_bVoiceMagneticFieldActive) |
||
1519 | { |
||
2295 | - | 1520 | Thread t = new Thread(() => _mediaPlayer("Voice\\MagneticField.mp3")); |
1521 | t.Start(); |
||
2291 | - | 1522 | _bVoiceMagneticFieldActive = true; |
1523 | } |
||
1524 | } |
||
1525 | } |
||
2287 | - | 1526 | break; |
1527 | case 21: //GroundSpeed |
||
1528 | Dispatcher.Invoke((Action)(() => tbSpeed.Text = ((double)iAnalogData[index] / (double)100).ToString("0.00 m/s"))); |
||
1529 | Dispatcher.Invoke((Action)(() => tbTopSpeed.Text = ((double)iAnalogData[index] / (double)100).ToString("0.00 m/s"))); |
||
1530 | break; |
||
2291 | - | 1531 | |
1532 | ///********** needs testing --> not sure what position this is *************** |
||
2287 | - | 1533 | case 28: //Distance East from saved home position -> calculate distance with distance N + height |
1534 | dTemp = Math.Pow((double)iAnalogData[index], 2) + Math.Pow((double)iAnalogData[index - 1], 2); |
||
1535 | dTemp = Math.Sqrt(dTemp) / (double)10; //'flat' distance from HP with N/E |
||
1536 | // lblNCDist.Invoke((Action)(() => lblNCDist.Text = dTemp.ToString("0.00"))); |
||
1537 | dTemp = Math.Pow(dTemp, 2) + Math.Pow(((double)iAnalogData[4] / (double)10), 2); //adding 'height' into calculation |
||
1538 | dTemp = Math.Sqrt(dTemp) / (double)10; |
||
1539 | // Dispatcher.Invoke((Action)(() => tbTopDistanceHP.Text = dTemp.ToString("0.0 m"))); |
||
1540 | Dispatcher.Invoke((Action)(() => tbHP1.Text = dTemp.ToString("0.0 m"))); |
||
1541 | break; |
||
2291 | - | 1542 | |
2287 | - | 1543 | case 31: //Sats used |
1544 | Dispatcher.Invoke((Action)(() => tbSats.Text = sAnalogData[index])); |
||
1545 | // Dispatcher.Invoke((Action)(() => tbTopSats.Text = sAnalogData[index])); |
||
1546 | break; |
||
1547 | } |
||
1548 | } |
||
1549 | index++; |
||
1550 | } |
||
1551 | } |
||
1552 | else |
||
1553 | Debug.Print("wrong data-length (66): " + data.Length.ToString()); |
||
1554 | } |
||
1555 | /// <summary> |
||
1556 | /// Version string 'V' |
||
1557 | /// </summary> |
||
1558 | /// <param name="adr">adress of the active controller (1-FC, 2-NC)</param> |
||
1559 | /// <param name="data">the received byte array to process</param> |
||
1560 | void _processVersion(byte adr, byte[] data) |
||
1561 | { |
||
1562 | if (data.Length == 12) |
||
1563 | { |
||
1564 | if (!check_HWError) |
||
1565 | { |
||
1566 | string[] sVersionStruct = new string[10] { "SWMajor: ", "SWMinor: ", "ProtoMajor: ", "LabelTextCRC: ", "SWPatch: ", "HardwareError 1: ", "HardwareError 2: ", "HWMajor: ", "BL_Firmware: ", "Flags: " }; |
||
1567 | string sVersion = ""; |
||
1568 | //sbyte[] signed = Array.ConvertAll(data, b => unchecked((sbyte)b)); |
||
1569 | Log(LogMsgType.Warning, (adr == 1 ? "FC-" : "NC-") + "Version: "); |
||
1570 | sVersion = "HW V" + (data[7] / 10).ToString() + "." + (data[7] % 10).ToString(); |
||
1571 | Log(LogMsgType.Incoming, sVersion); |
||
1572 | sVersion = "SW V" + (data[0]).ToString() + "." + (data[1]).ToString() + ((char)(data[4] + 'a')).ToString(); |
||
1573 | Log(LogMsgType.Incoming, sVersion); |
||
1574 | Log(LogMsgType.Incoming, "BL-Firmware: V" + (data[8] / 100).ToString() + "." + (data[8] % 100).ToString()); |
||
1575 | } |
||
1576 | if (data[5] > 0) //error0 |
||
1577 | { |
||
1578 | if (adr == 1) |
||
1579 | ErrorLog(LogMsgType.Error, "FC - HW-Error " + data[5].ToString() + ": " + ((FC_HWError0)data[5]).ToString()); |
||
1580 | if (adr == 2) |
||
1581 | ErrorLog(LogMsgType.Error, "NC - HW-Error " + data[5].ToString() + ": " + ((NC_HWError0)data[5]).ToString()); |
||
1582 | } |
||
1583 | if (data[6] > 0) //error1 |
||
1584 | { |
||
1585 | if (adr == 1) |
||
1586 | ErrorLog(LogMsgType.Error, "FC - HW-Error " + data[6].ToString() + ": " + ((FC_HWError1)data[6]).ToString()); |
||
1587 | if (adr == 2) |
||
1588 | ErrorLog(LogMsgType.Error, "NC - Unknown HW-ERROR: " + data[6].ToString()); //@moment NC has only one error field |
||
1589 | } |
||
1590 | if ((data[5] + data[6] == 0) && _bErrorLog) |
||
1591 | _clearErrorLog(adr == 1 ? "FC - HW-Error" : "NC - HW-Error"); |
||
1592 | |||
1593 | } |
||
1594 | check_HWError = false; |
||
1595 | } |
||
1596 | /// <summary> |
||
1597 | /// BL-Ctrl data 'K' |
||
1598 | /// for FC you have to use a customized firmware |
||
1599 | /// </summary> |
||
1600 | /// <param name="data">the received byte array to process</param> |
||
1601 | void _processBLCtrl(byte[] data) |
||
1602 | { |
||
1603 | if (data.Length % 6 == 0) //data.Length up to 96 (16 motors x 6 byte data) --> new datastruct in FC -> not standard! |
||
1604 | { |
||
1605 | bool bAvailable = false; |
||
1606 | for (int i = 0; i < data.Length && data[i] < _iMotors; i += 6) // data[i] < _iMotors -- only show set number of motors (12 max @ moment) |
||
1607 | { |
||
1608 | |||
1609 | if ((data[i + 4] & 128) == 128) //Status bit at pos 7 = 128 dec -- if true, motor is available |
||
1610 | bAvailable = true; |
||
1611 | else |
||
1612 | bAvailable = false; |
||
1613 | |||
1614 | if (data[i] < _iMotors) |
||
1615 | { |
||
1616 | if (bAvailable) |
||
1617 | { |
||
2315 | - | 1618 | dtMotors.Rows[data[i]].SetField(1, ((double)data[i + 1] / (double)10).ToString("0.0 A")); |
1619 | dtMotors.Rows[data[i]].SetField(2, data[i + 2].ToString("0 °C")); |
||
2287 | - | 1620 | } |
1621 | else |
||
1622 | { |
||
2315 | - | 1623 | dtMotors.Rows[data[i]].SetField(1, "NA"); |
1624 | dtMotors.Rows[data[i]].SetField(2, "NA"); |
||
2287 | - | 1625 | } |
1626 | } |
||
1627 | //if (data[i] > 3 && data[i] < 8) |
||
1628 | //{ |
||
1629 | // if (bAvailable) |
||
1630 | // { |
||
1631 | // dtMotors2.Rows[data[i] - 4].SetField(1, ((double)data[i + 1] / (double)10).ToString("0.0 A")); |
||
1632 | // dtMotors2.Rows[data[i] - 4].SetField(2, data[i + 2].ToString("0 °C")); |
||
1633 | // } |
||
1634 | // else |
||
1635 | // { |
||
1636 | // dtMotors2.Rows[data[i] - 4].SetField(1, "NA"); |
||
1637 | // dtMotors2.Rows[data[i] - 4].SetField(2, "NA"); |
||
1638 | // } |
||
1639 | //} |
||
1640 | } |
||
1641 | } |
||
1642 | } |
||
1643 | /// <summary> |
||
1644 | /// Navi-Ctrl data 'O' |
||
1645 | /// GPS-Position, capacatiy, flying time... |
||
1646 | /// </summary> |
||
1647 | /// <param name="data">the received byte array to process</param> |
||
1648 | void _processNCData(byte[] data) |
||
1649 | { |
||
1650 | int i_32, i_16, iVal; |
||
1651 | double d; |
||
1652 | i_32 = data[4]; |
||
1653 | iVal = i_32 << 24; |
||
1654 | i_32 = data[3]; |
||
1655 | iVal += i_32 << 16; |
||
1656 | i_32 = data[2]; |
||
1657 | iVal += i_32 << 8; |
||
1658 | iVal += data[1]; |
||
1659 | d = (double)iVal / Math.Pow(10, 7); |
||
2324 | - | 1660 | Dispatcher.Invoke(() => { drGPX[2] = d; }); |
1661 | |||
2287 | - | 1662 | PointLatLng p = new PointLatLng(); |
1663 | |||
1664 | p.Lng = d; |
||
1665 | // lblNCGPSLong.Invoke((Action)(() => lblNCGPSLong.Text = d.ToString("0.######°"))); //GPS-Position: Longitude in decimal degree |
||
1666 | //lblNCGPSLong.Invoke((Action)(() => lblNCGPSLong.Text = _convertDegree(d))); //GPS-Position: Longitude in minutes, seconds |
||
1667 | |||
1668 | i_32 = data[8]; |
||
1669 | iVal = i_32 << 24; |
||
1670 | i_32 = data[7]; |
||
1671 | iVal += i_32 << 16; |
||
1672 | i_32 = data[6]; |
||
1673 | iVal += i_32 << 8; |
||
1674 | iVal += data[5]; |
||
1675 | d = (double)iVal / Math.Pow(10, 7); |
||
2324 | - | 1676 | Dispatcher.Invoke(() => { drGPX[1] = d; }); |
1677 | Dispatcher.Invoke(() => { drGPX[4] = DateTime.UtcNow.ToString("u", System.Globalization.CultureInfo.InvariantCulture); }); //2011-01-14T01:59:01Z }); |
||
2287 | - | 1678 | p.Lat = d; |
2291 | - | 1679 | if (data[50] > 4)//if more than 4 sats in use . otherwise the map would jump and scroll insane at beginning |
1680 | { |
||
1681 | _bSatFix = true; _iSatsJitter = 0; _bVoiceSatFixActive = false; |
||
2295 | - | 1682 | if(_bAutoHome && !_bFirstSatFix) |
1683 | { |
||
1684 | if (_iFirstSatFix < 3) |
||
1685 | _iFirstSatFix++; |
||
1686 | else |
||
1687 | { |
||
1688 | _bFirstSatFix = true; |
||
2347 | - | 1689 | Dispatcher.Invoke(() => _setHomePos()); |
2295 | - | 1690 | } |
1691 | } |
||
2291 | - | 1692 | if (stbSatFixLostAnim != null && _bAnimSatFixActive) |
1693 | { |
||
1694 | Dispatcher.Invoke(() => stbSatFixLostAnim.Stop()); |
||
1695 | _bAnimSatFixActive = false; |
||
1696 | } |
||
1697 | if (!_bFollowCopter) |
||
1698 | { |
||
1699 | _setCopterData(p); |
||
1700 | if (!MainMap.ViewArea.Contains(p)) |
||
1701 | Dispatcher.Invoke(() => MainMap.Position = p); |
||
2287 | - | 1702 | |
2291 | - | 1703 | } |
1704 | else |
||
2287 | - | 1705 | Dispatcher.Invoke(() => MainMap.Position = p); |
1706 | } |
||
1707 | else |
||
2291 | - | 1708 | { |
1709 | if(_bSatFix) |
||
1710 | { |
||
1711 | if (data[50] == _iSatsLast) |
||
1712 | { |
||
1713 | if (_iSatsJitter < 20) _iSatsJitter++; |
||
1714 | } |
||
1715 | else |
||
1716 | { |
||
1717 | _iSatsJitter = 0; |
||
1718 | _iSatsLast = data[50]; |
||
1719 | } |
||
2287 | - | 1720 | |
2291 | - | 1721 | if (_iSatsJitter == 20) |
1722 | { |
||
1723 | if (stbSatFixLostAnim != null && !_bAnimSatFixActive) |
||
1724 | { |
||
1725 | Dispatcher.Invoke(() => stbSatFixLostAnim.Begin()); |
||
1726 | _bAnimSatFixActive = true; |
||
1727 | } |
||
1728 | if (_bVoiceSatFixPlay && !_bVoiceSatFixActive) |
||
1729 | { |
||
2335 | - | 1730 | Thread th = new Thread(() => _mediaPlayer("Voice\\SatFixLost.mp3")); |
2295 | - | 1731 | th.Start(); |
2291 | - | 1732 | _bVoiceSatFixActive = true; |
1733 | } |
||
1734 | |||
1735 | _bSatFix = false; |
||
1736 | } |
||
1737 | } |
||
1738 | } |
||
1739 | |||
2287 | - | 1740 | i_16 = data[28]; |
1741 | i_16 = (Int16)(i_16 << 8); |
||
1742 | iVal = data[27] + i_16; |
||
1743 | Dispatcher.Invoke((Action)(() => tbWP.Text = ((double)iVal / (double)10).ToString("0.0 m"))); //Distance to next WP |
||
1744 | |||
1745 | i_16 = data[45]; |
||
1746 | i_16 = (Int16)(i_16 << 8); |
||
1747 | iVal = data[44] + i_16; |
||
1748 | // Dispatcher.Invoke((Action)(() => tbTopDistanceHP.Text = ((double)iVal / (double)10).ToString("0.0 m"))); //Distance to HP set by GPS on |
||
1749 | Dispatcher.Invoke((Action)(() => tbHP.Text = ((double)iVal / (double)10).ToString("0.0 m"))); //Distance to HP set by GPS on |
||
1750 | |||
1751 | Dispatcher.Invoke((Action)(() => tbWPIndex.Text = data[48].ToString())); //Waypoint index |
||
2355 | - | 1752 | Dispatcher.Invoke((Action)(() => lblWPIndexNC.Content = data[48].ToString())); |
2347 | - | 1753 | if(data[48] > 0 && _wpIndex != data[48] -1 && wpList.Count > 0) |
2342 | - | 1754 | { |
2347 | - | 1755 | _setActiveWP(data[48]-1); |
2355 | - | 1756 | if((data[67] & 2) == 2) |
1757 | Dispatcher.Invoke(() => { |
||
1758 | DataGridRow row; |
||
1759 | if (_wpIndex > -1) |
||
1760 | { |
||
1761 | row = (DataGridRow)dgvWP.ItemContainerGenerator.ContainerFromIndex(_wpIndex); |
||
1762 | row.Background = new SolidColorBrush(Colors.Transparent); |
||
1763 | row.BorderBrush = new SolidColorBrush(Colors.Transparent); |
||
1764 | row.BorderThickness = new Thickness(0); |
||
1765 | } |
||
1766 | _wpIndex = data[48] - 1; |
||
1767 | row = (DataGridRow)dgvWP.ItemContainerGenerator.ContainerFromIndex(_wpIndex); |
||
2366 | - | 1768 | row.Background = new SolidColorBrush(Color.FromArgb(80, 0, 255, 100)); |
1769 | row.BorderBrush = new SolidColorBrush(Colors.SpringGreen); |
||
2355 | - | 1770 | row.BorderThickness = new Thickness(2); |
1771 | dgvWP.UpdateLayout(); |
||
1772 | }); |
||
2347 | - | 1773 | _wpIndex = data[48]-1; |
2342 | - | 1774 | } |
2347 | - | 1775 | else |
1776 | { |
||
1777 | if ((data[48] == 0 || wpList.Count == 0) & MainMap.Markers.Contains(wpActiveMarker)) |
||
2355 | - | 1778 | { |
2347 | - | 1779 | Dispatcher.Invoke(() => MainMap.Markers.Remove(wpActiveMarker)); |
2355 | - | 1780 | Dispatcher.Invoke(() => |
1781 | { |
||
1782 | DataGridRow row; |
||
2368 | - | 1783 | if (_wpIndex > -1 && data[48] == 0 && wpList.Count > _wpIndex) |
2355 | - | 1784 | { |
1785 | row = (DataGridRow)dgvWP.ItemContainerGenerator.ContainerFromIndex(_wpIndex); |
||
1786 | row.Background = new SolidColorBrush(Colors.Transparent); |
||
1787 | row.BorderBrush = new SolidColorBrush(Colors.Transparent); |
||
1788 | row.BorderThickness = new Thickness(0); |
||
1789 | _wpIndex = -1; |
||
1790 | } |
||
1791 | }); |
||
1792 | |||
1793 | } |
||
2347 | - | 1794 | } |
2342 | - | 1795 | |
2287 | - | 1796 | Dispatcher.Invoke((Action)(() => tbWPCount.Text = data[49].ToString())); //Waypoints count |
2355 | - | 1797 | Dispatcher.Invoke((Action)(() => lblWPCountNC.Content = data[49].ToString())); //Waypoints count |
2340 | - | 1798 | _wpCount = data[49]; |
2287 | - | 1799 | Dispatcher.Invoke((Action)(() => tbTopSats.Text = data[50].ToString())); //Satellites |
1800 | |||
1801 | //--------------- Capacity used ------------------------ |
||
1802 | i_16 = data[81]; |
||
1803 | i_16 = (Int16)(i_16 << 8); |
||
1804 | iVal = data[80] + i_16; |
||
1805 | Dispatcher.Invoke((Action)(() => tbCapacity.Text = iVal.ToString() + " mAh")); |
||
1806 | Dispatcher.Invoke((Action)(() => tbTopCapacity.Text = iVal.ToString() + " mAh")); |
||
1807 | |||
1808 | //--------------- Flying time ------------------------ |
||
1809 | i_16 = data[56]; |
||
1810 | i_16 = (Int16)(i_16 << 8); |
||
1811 | iVal = data[55] + i_16; |
||
1812 | TimeSpan t = TimeSpan.FromSeconds(iVal); |
||
1813 | string Text = t.Hours.ToString("D2") + ":" + t.Minutes.ToString("D2") + ":" + t.Seconds.ToString("D2"); |
||
1814 | Dispatcher.Invoke((Action)(() => tbFTime.Text = Text.ToString())); |
||
1815 | Dispatcher.Invoke((Action)(() => tbTopFTime.Text = Text.ToString())); |
||
1816 | |||
1817 | //--------------- RC quality ------------------------ |
||
1818 | Dispatcher.Invoke((Action)(() => tbRCQ.Text = data[66].ToString())); |
||
1819 | Dispatcher.Invoke((Action)(() => tbTopRC.Text = data[66].ToString())); |
||
1820 | |||
2291 | - | 1821 | if(data[66] > _iThresholdRC) |
1822 | { |
||
1823 | _iRCLevelJitter = 0; _bVoiceRCLevelActive = false; |
||
1824 | if (stbRCLevelAnim != null && _bAnimRCLevelActive) |
||
1825 | { |
||
1826 | Dispatcher.Invoke(() => stbRCLevelAnim.Stop()); |
||
1827 | _bAnimRCLevelActive = false; |
||
1828 | } |
||
1829 | } |
||
1830 | else |
||
1831 | { |
||
1832 | if (_iRCLevelJitter < 20) _iRCLevelJitter++; |
||
1833 | if (_iRCLevelJitter == 20) |
||
1834 | { |
||
1835 | if (stbRCLevelAnim != null && !_bAnimRCLevelActive) |
||
1836 | { |
||
1837 | Dispatcher.Invoke(() => stbRCLevelAnim.Begin()); |
||
1838 | _bAnimRCLevelActive = true; |
||
1839 | } |
||
1840 | if (_bVoiceRCLevelPlay && !_bVoiceRCLevelActive) |
||
1841 | { |
||
2295 | - | 1842 | Thread th = new Thread(() => _mediaPlayer("Voice\\RCLevel.mp3")); |
1843 | th.Start(); |
||
2291 | - | 1844 | _bVoiceRCLevelActive = true; |
1845 | } |
||
1846 | _iRCLevelJitter++; |
||
1847 | } |
||
1848 | } |
||
1849 | |||
2287 | - | 1850 | //--------------- NC Error ------------------------ |
1851 | Dispatcher.Invoke((Action)(() => tbNCErr.Text = data[69].ToString())); //NC Errornumber |
||
1852 | if (data[69] > 0) |
||
1853 | _readNCError(); |
||
1854 | if (data[69] > 0 & data[69] < 44) |
||
1855 | ErrorLog(LogMsgType.Error, "NC Error [" + data[69].ToString() + "]: " + NC_Error[data[69]]); |
||
1856 | else |
||
1857 | if (_bErrorLog) _clearErrorLog("NC Error"); |
||
1858 | |||
2298 | - | 1859 | //-------------FC / NC Status Flags |
1860 | Dispatcher.Invoke((Action)(() => FC1_1.Background = ((data[67] & 1) ==1) ? new SolidColorBrush(Colors.LightSeaGreen) : new SolidColorBrush(Colors.Transparent)));// FC_STATUS_MOTOR_RUN 0x01 |
||
1861 | Dispatcher.Invoke((Action)(() => FC1_2.Background = ((data[67] & 2) ==2) ? new SolidColorBrush(Colors.LightSeaGreen) : new SolidColorBrush(Colors.Transparent)));// FC_STATUS_FLY 0x02 |
||
1862 | Dispatcher.Invoke((Action)(() => FC1_3.Background = ((data[67] & 4) ==4) ? new SolidColorBrush(Colors.LightSeaGreen) : new SolidColorBrush(Colors.Transparent)));// FC_STATUS_CALIBRATE 0x04 |
||
1863 | Dispatcher.Invoke((Action)(() => FC1_4.Background = ((data[67] & 8) ==8) ? new SolidColorBrush(Colors.LightSeaGreen) : new SolidColorBrush(Colors.Transparent)));// FC_STATUS_START 0x08 |
||
1864 | Dispatcher.Invoke((Action)(() => FC1_5.Background = ((data[67] & 16) ==16) ? new SolidColorBrush(Colors.LightCoral) : new SolidColorBrush(Colors.Transparent)));// FC_STATUS_EMERGENCY_LANDING 0x10 |
||
1865 | Dispatcher.Invoke((Action)(() => FC1_6.Background = ((data[67] & 32) ==32) ? new SolidColorBrush(Colors.LightCoral) : new SolidColorBrush(Colors.Transparent)));// FC_STATUS_LOWBAT 0x20 |
||
1866 | |||
1867 | Dispatcher.Invoke((Action)(() => FC2_1.Background = ((data[74] & 1) ==1) ? new SolidColorBrush(Colors.LightSeaGreen) : new SolidColorBrush(Colors.Transparent)));// FC_STATUS2_CAREFREE 0x01 |
||
1868 | Dispatcher.Invoke((Action)(() => FC2_2.Background = ((data[74] & 2) ==2) ? new SolidColorBrush(Colors.LightSeaGreen) : new SolidColorBrush(Colors.Transparent)));// FC_STATUS2_ALTITUDE_CONTROL 0x02 |
||
1869 | Dispatcher.Invoke((Action)(() => FC2_3.Background = ((data[74] & 4) ==4) ? new SolidColorBrush(Colors.LightCoral) : new SolidColorBrush(Colors.Transparent)));// FC_STATUS2_RC_FAILSAVE_ACTIVE 0x04 |
||
1870 | Dispatcher.Invoke((Action)(() => FC2_4.Background = ((data[74] & 8) ==8) ? new SolidColorBrush(Colors.LightSeaGreen) : new SolidColorBrush(Colors.Transparent)));// FC_STATUS2_OUT1_ACTIVE 0x08 |
||
1871 | Dispatcher.Invoke((Action)(() => FC2_5.Background = ((data[74] & 16) ==16) ? new SolidColorBrush(Colors.LightSeaGreen) : new SolidColorBrush(Colors.Transparent)));// FC_STATUS2_OUT2_ACTIVE 0x10 |
||
1872 | 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 |
||
1873 | Dispatcher.Invoke((Action)(() => FC2_7.Background = ((data[74] & 64) ==64) ? new SolidColorBrush(Colors.LightSeaGreen) : new SolidColorBrush(Colors.Transparent)));// FC_STATUS2_AUTO_STARTING 0x40 |
||
1874 | Dispatcher.Invoke((Action)(() => FC2_8.Background = ((data[74] & 128) ==128) ? new SolidColorBrush(Colors.LightSeaGreen) : new SolidColorBrush(Colors.Transparent)));// FC_STATUS2_AUTO_LANDING 0x80 |
||
1875 | |||
1876 | Dispatcher.Invoke((Action)(() => NC1_2.Background = ((data[68] & 2) == 2) ? new SolidColorBrush(Colors.LightSeaGreen) : new SolidColorBrush(Colors.Transparent)));// NC_FLAG_PH 0x02 |
||
1877 | Dispatcher.Invoke((Action)(() => NC1_3.Background = ((data[68] & 4) == 4) ? new SolidColorBrush(Colors.LightSeaGreen) : new SolidColorBrush(Colors.Transparent)));// NC_FLAG_CH 0x04 |
||
1878 | Dispatcher.Invoke((Action)(() => NC1_4.Background = ((data[68] & 8) == 8) ? new SolidColorBrush(Colors.LightCoral) : new SolidColorBrush(Colors.Transparent)));// NC_FLAG_RANGE_LIMIT 0x08 |
||
1879 | Dispatcher.Invoke((Action)(() => NC1_5.Background = ((data[68] & 16) == 16) ? new SolidColorBrush(Colors.LightCoral) : new SolidColorBrush(Colors.Transparent)));// NC_FLAG_NOSERIALLINK 0x10 |
||
1880 | Dispatcher.Invoke((Action)(() => NC1_6.Background = ((data[68] & 32) == 32) ? new SolidColorBrush(Colors.LightSeaGreen) : new SolidColorBrush(Colors.Transparent)));// NC_FLAG_TARGET_REACHED 0x20 |
||
1881 | Dispatcher.Invoke((Action)(() => NC1_7.Background = ((data[68] & 64) == 64) ? new SolidColorBrush(Colors.DodgerBlue) : new SolidColorBrush(Colors.Transparent)));// NC_FLAG_MANUAL_CONTROL 0x40 |
||
1882 | Dispatcher.Invoke((Action)(() => NC1_8.Background = ((data[68] & 128) == 128) ? new SolidColorBrush(Colors.LightSeaGreen) : new SolidColorBrush(Colors.Transparent)));// NC_FLAG_GPS_OK 0x80 |
||
2299 | - | 1883 | |
1884 | //Sidebar StatusSymbols |
||
1885 | Dispatcher.Invoke((Action)(() => tbSideBarStatusMotors.Background = ((data[67] & 1) ==1) ? new SolidColorBrush(Colors.LightSeaGreen) : new SolidColorBrush(Colors.Transparent)));// FC_STATUS_MOTOR_RUN 0x01 |
||
1886 | 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 |
||
1887 | 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 |
||
1888 | |||
1889 | Dispatcher.Invoke((Action)(() => tbSideBarStatusCF.Background = ((data[74] & 1) == 1) ? new SolidColorBrush(Colors.LightSeaGreen) : new SolidColorBrush(Colors.Transparent)));// FC_STATUS2_CAREFREE 0x01 |
||
1890 | 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 |
||
1891 | 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 |
||
1892 | |||
1893 | Dispatcher.Invoke((Action)(() => tbSideBarStatusEmergencyLanding.Background = ((data[67] & 16) == 16) ? new SolidColorBrush(Colors.LightCoral) : new SolidColorBrush(Colors.Transparent)));// FC_STATUS_EMERGENCY_LANDING 0x10 |
||
2304 | - | 1894 | 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 |
1895 | 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 | - | 1896 | |
1897 | Dispatcher.Invoke((Action)(() => tbSideBarStatusAC.Background = ((data[74] & 2) ==2) ? new SolidColorBrush(Colors.LightSeaGreen) : new SolidColorBrush(Colors.Transparent)));// FC_STATUS2_ALTITUDE_CONTROL 0x02 |
||
1898 | 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 |
||
1899 | 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 |
||
1900 | |||
1901 | Dispatcher.Invoke((Action)(() => tbSideBarStatusPH.Text = ((data[68] & 4) == 4) ? "CH" : "PH"));// NC_FLAG_PH 0x02 / NC_FLAG_CH 0x04 |
||
2304 | - | 1902 | 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 |
1903 | 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 |
||
1904 | 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 | - | 1905 | |
2324 | - | 1906 | _bAirborne = (data[67] & 2) == 2 ? true : false; |
2287 | - | 1907 | } |
1908 | /// <summary> |
||
1909 | /// Navi-Ctrl WP data struct 'X' |
||
1910 | /// called by index |
||
1911 | /// </summary> |
||
1912 | /// <param name="data">the received byte array to process</param> |
||
1913 | void _processWPData(byte[] data) |
||
1914 | { |
||
2313 | - | 1915 | _iWPCount = data[0]; |
2287 | - | 1916 | _bGetWPCount = false; |
1917 | if (data.Length >= 28) |
||
1918 | { |
||
1919 | Dispatcher.Invoke(() => lblWPIndex.Content = data[1].ToString()); |
||
1920 | Dispatcher.Invoke(() => lblWPCount.Content = data[0].ToString()); |
||
1921 | if (_bGetWP) |
||
1922 | { |
||
1923 | if (data[1] == 1) |
||
2315 | - | 1924 | { |
2333 | - | 1925 | Dispatcher.Invoke(() => |
1926 | { |
||
2356 | - | 1927 | wpList.Clear(); |
1928 | _clearMapMarkers(typeof(CustomMarkerWP)); |
||
1929 | if (mRouteWP != null) |
||
1930 | MainMap.Markers.Remove(mRouteWP); |
||
1931 | if (wpActiveMarker != null) |
||
1932 | MainMap.Markers.Remove(wpActiveMarker); |
||
1933 | lblWPRouteDistance.Content = "0 m"; |
||
1934 | dtWaypoints.Rows.Clear(); |
||
2368 | - | 1935 | _wpEdit = -1;_wpIndex = -1; |
2318 | - | 1936 | }); |
2315 | - | 1937 | } |
2287 | - | 1938 | DataRow dr = dtWaypoints.NewRow(); |
1939 | dr = Waypoints.toDataRow(data, dr); |
||
2313 | - | 1940 | dtWaypoints.Rows.Add(dr); |
2363 | - | 1941 | _createWP(new PointLatLng((double)dr[3], (double)dr[4]), (string)dr[2], (int)dr[1]); |
2313 | - | 1942 | Dispatcher.Invoke(() => dgvWP.Items.Refresh()); |
1943 | Dispatcher.Invoke(() => _iWPIndex = data[1]); |
||
2287 | - | 1944 | if (data[1] == data[0]) |
1945 | { |
||
1946 | _bGetWP = false; |
||
2368 | - | 1947 | _routeUpdate(); |
2287 | - | 1948 | } |
1949 | |||
1950 | } |
||
1951 | } |
||
1952 | else |
||
1953 | { |
||
1954 | Dispatcher.Invoke(() => lblWPIndex.Content = 0); |
||
1955 | Dispatcher.Invoke(() => lblWPCount.Content = 0); |
||
1956 | } |
||
1957 | } |
||
1958 | /// <summary> |
||
1959 | /// OSD Menue 'L' |
||
1960 | /// single page called by pagenumber |
||
1961 | /// no autoupdate |
||
1962 | /// </summary> |
||
1963 | /// <param name="data">the received byte array to process</param> |
||
1964 | void _processOSDSingle(byte[] data) |
||
1965 | { |
||
1966 | if (data.Length == 84) |
||
1967 | { |
||
1968 | string sMessage = ""; |
||
1969 | iOSDPage = data[0]; |
||
1970 | iOSDMax = data[1]; |
||
1971 | if (cbOSD.Items.Count != iOSDMax) _initOSDCB(); |
||
1972 | sMessage = new string(ASCIIEncoding.ASCII.GetChars(data, 2, data.Length - 4)); |
||
1973 | OSD(LogMsgType.Incoming, sMessage.Substring(0, 20)+ "\r", true); |
||
1974 | OSD(LogMsgType.Incoming, sMessage.Substring(20, 20)+ "\r", false); |
||
1975 | OSD(LogMsgType.Incoming, sMessage.Substring(40, 20)+ "\r", false); |
||
1976 | OSD(LogMsgType.Incoming, sMessage.Substring(60, 20), false); |
||
1977 | Dispatcher.Invoke(() => { cbOSD.SelectedValue = iOSDPage; }); |
||
1978 | // lblOSDPageNr.Invoke((Action)(() => lblOSDPageNr.Text = iOSDPage.ToString("[0]"))); |
||
1979 | |||
1980 | } |
||
1981 | //else |
||
1982 | // OSD(LogMsgType.Incoming, "Wrong length: " + data.Length + " (should be 84)"); |
||
1983 | |||
1984 | } |
||
1985 | /// <summary> |
||
1986 | /// OSD Menue 'H' |
||
1987 | /// called by keys (0x01,0x02,0x03,0x04) |
||
1988 | /// autoupdate |
||
1989 | /// </summary> |
||
1990 | /// <param name="data">the received byte array to process</param> |
||
1991 | void _processOSDAuto(byte[] data) |
||
1992 | { |
||
1993 | if (data.Length == 81) |
||
1994 | { |
||
1995 | string sMessage = ""; |
||
1996 | sMessage = new string(ASCIIEncoding.ASCII.GetChars(data, 0, data.Length - 1)); |
||
1997 | OSD(LogMsgType.Incoming, sMessage.Substring(0, 20)+ "\r", true); |
||
1998 | OSD(LogMsgType.Incoming, sMessage.Substring(20, 20)+ "\r", false); |
||
1999 | OSD(LogMsgType.Incoming, sMessage.Substring(40, 20)+ "\r", false); |
||
2000 | OSD(LogMsgType.Incoming, sMessage.Substring(60, 20), false); |
||
2001 | |||
2002 | } |
||
2003 | //else |
||
2004 | // OSD(LogMsgType.Incoming, "Wrong length: " + data.Length + " (should be 81)"); |
||
2005 | } |
||
2006 | |||
2007 | #endregion processing received data |
||
2008 | |||
2009 | #region controller messages |
||
2010 | /// <summary> send message to controller to request data |
||
2011 | /// for detailed info see http://wiki.mikrokopter.de/en/SerialProtocol/ |
||
2012 | /// </summary> |
||
2013 | /// <param name="CMDID"> the command ID </param> |
||
2014 | /// <param name="address"> the address of the controller: 0-any, 1-FC, 2-NC </param> |
||
2015 | private void _sendControllerMessage(char CMDID, byte address) |
||
2016 | { |
||
2017 | if (serialPortCtrl.Port.IsOpen) |
||
2018 | { |
||
2019 | Stream serialStream = serialPortCtrl.Port.BaseStream; |
||
2020 | byte[] bytes = FlightControllerMessage.CreateMessage(CMDID, address); |
||
2021 | serialStream.Write(bytes, 0, bytes.Length); |
||
2022 | |||
2023 | } |
||
2024 | else |
||
2025 | Log(LogMsgType.Error, "NOT CONNECTED!"); |
||
2026 | } |
||
2027 | /// <summary> send message to controller to request data |
||
2028 | /// for detailed info see http://wiki.mikrokopter.de/en/SerialProtocol/ |
||
2029 | /// </summary> |
||
2030 | /// <param name="CMDID"> the command ID </param> |
||
2031 | /// <param name="address"> the address of the controller: 0-any, 1-FC, 2-NC </param> |
||
2032 | /// <param name="data"> additional data for the request</param> |
||
2033 | private void _sendControllerMessage(char CMDID, byte address, byte[] data) |
||
2034 | { |
||
2035 | if (serialPortCtrl.Port.IsOpen) |
||
2036 | { |
||
2037 | Stream serialStream = serialPortCtrl.Port.BaseStream; |
||
2038 | byte[] bytes = FlightControllerMessage.CreateMessage(CMDID, address, data); |
||
2039 | serialStream.Write(bytes, 0, bytes.Length); |
||
2040 | |||
2041 | } |
||
2042 | else |
||
2043 | Log(LogMsgType.Error, "NOT CONNECTED!"); |
||
2044 | } |
||
2045 | |||
2046 | /// <summary> |
||
2047 | /// start/stop continous polling of controller values |
||
2048 | /// </summary> |
||
2049 | /// <param name="b">start/stop switch</param> |
||
2050 | void _readCont(bool b) |
||
2051 | { |
||
2052 | bReadContinously = b; |
||
2053 | if (bReadContinously) |
||
2054 | { |
||
2055 | if (_debugDataAutorefresh) { _readDebugData(true); Thread.Sleep(10); } |
||
2056 | if (_blctrlDataAutorefresh) { _readBLCtrl(true); Thread.Sleep(10); } |
||
2057 | if (_navCtrlDataAutorefresh && _iCtrlAct == 2) { _readNavData(true); Thread.Sleep(10); } |
||
2058 | if (_OSDAutorefresh) { _OSDMenueAutoRefresh(); Thread.Sleep(10); } |
||
2059 | // Dispatcher.Invoke((Action)(() => rctConnection.Fill = Brushes.LightGreen)); |
||
2060 | Dispatcher.Invoke(() => imageConn.Source = new BitmapImage(new Uri("Images/Data_G.png", UriKind.Relative))); |
||
2061 | } |
||
2062 | else |
||
2063 | { |
||
2064 | // Dispatcher.Invoke((Action)(() => rctConnection.Fill = Brushes.LightGray)); |
||
2065 | Dispatcher.Invoke(() => imageConn.Source = new BitmapImage(new Uri("Images/Data_W.png", UriKind.Relative))); |
||
2066 | _bConnErr = false; |
||
2067 | } |
||
2068 | _iLifeCounter = 0; |
||
2069 | } |
||
2070 | |||
2071 | private void _getVersion() |
||
2072 | { |
||
2073 | _sendControllerMessage('v', 0); |
||
2074 | } |
||
2075 | /// <summary> |
||
2076 | /// get FC version struct via NC |
||
2077 | /// by sending '1' as data (not documented in wiki...) |
||
2078 | /// returns HW error 255 (comment in uart1.c : tells the KopterTool that it is the FC-version) |
||
2079 | /// </summary> |
||
2080 | /// <param name="ctrl">controller number 1=FC</param> |
||
2081 | private void _getVersion(byte ctrl) |
||
2082 | { |
||
2083 | _sendControllerMessage('v', 0, new byte[1] { ctrl }); |
||
2084 | } |
||
2085 | /// <summary> |
||
2086 | /// Switch back to NC by sending the 'Magic Packet' 0x1B,0x1B,0x55,0xAA,0x00 |
||
2087 | /// </summary> |
||
2088 | private void _switchToNC() |
||
2089 | { |
||
2090 | if (serialPortCtrl.Port.IsOpen) |
||
2091 | { |
||
2092 | Stream serialStream = serialPortCtrl.Port.BaseStream; |
||
2093 | byte[] bytes = new byte[5] { 0x1B, 0x1B, 0x55, 0xAA, 0x00 }; |
||
2094 | serialStream.Write(bytes, 0, bytes.Length); |
||
2095 | |||
2096 | Thread.Sleep(100); |
||
2097 | _getVersion(); |
||
2098 | Thread.Sleep(100); |
||
2099 | // _OSDMenue(0); |
||
2100 | } |
||
2101 | else |
||
2102 | Log(LogMsgType.Error, "NOT CONNECTED!"); |
||
2103 | } |
||
2104 | /// <summary> |
||
2105 | /// switch to FC |
||
2106 | /// </summary> |
||
2107 | private void _switchToFC() |
||
2108 | { |
||
2109 | _sendControllerMessage('u', 2, new byte[1] { (byte)0 }); |
||
2110 | Thread.Sleep(100); |
||
2111 | _getVersion(); |
||
2112 | Thread.Sleep(100); |
||
2113 | // _OSDMenue(0); |
||
2114 | } |
||
2115 | /// <summary> |
||
2116 | /// send RESET signal to FC |
||
2117 | /// </summary> |
||
2118 | private void _resetCtrl() |
||
2119 | { |
||
2120 | _sendControllerMessage('R', 1); |
||
2121 | } |
||
2122 | /// <summary> |
||
2123 | /// poll the debug data (4sec subscription) |
||
2124 | /// </summary> |
||
2125 | /// <param name="auto"> onetimequery(false) or autoupdate(true) with set timing interval </param> |
||
2126 | private void _readDebugData(bool auto) |
||
2127 | { |
||
2128 | byte interval = auto ? debugInterval : (byte)0; |
||
2129 | _sendControllerMessage('d', 0, new byte[1] { debugInterval }); |
||
2130 | } |
||
2131 | /// <summary> |
||
2132 | /// poll the BL-CTRL status via NC (4sec subscription) |
||
2133 | /// </summary> |
||
2134 | /// <param name="auto"> onetimequery(false) or autoupdate(true) with set timing interval </param> |
||
2135 | private void _readBLCtrl(bool auto) |
||
2136 | { |
||
2137 | byte interval = auto ? blctrlInterval : (byte)0; |
||
2138 | _sendControllerMessage('k', 0, new byte[1] { interval }); |
||
2139 | } |
||
2140 | /// <summary> |
||
2141 | /// poll the NC data struct (4sec subscription) |
||
2142 | /// </summary> |
||
2143 | /// <param name="auto"> onetimequery(false) or autoupdate(true) with set timing interval </param> |
||
2144 | private void _readNavData(bool auto) |
||
2145 | { |
||
2146 | byte interval = auto ? navctrlInterval : (byte)0; |
||
2147 | _sendControllerMessage('o', 2, new byte[1] { interval }); |
||
2148 | } |
||
2149 | /// <summary> |
||
2150 | /// get the errortext for pending NC error |
||
2151 | /// </summary> |
||
2152 | private void _readNCError() |
||
2153 | { |
||
2154 | _sendControllerMessage('e', 2); |
||
2155 | } |
||
2156 | /// <summary> |
||
2157 | /// request the Waypoint at index |
||
2158 | /// </summary> |
||
2159 | /// <param name="index"></param> |
||
2160 | void _getpWP(int index) |
||
2161 | { |
||
2162 | if (serialPortCtrl.Port.IsOpen) |
||
2163 | { |
||
2164 | Stream serialStream = serialPortCtrl.Port.BaseStream; |
||
2165 | byte[] bytes = FlightControllerMessage.CreateMessage('x', 2, new byte[1] { (byte)index }); |
||
2166 | serialStream.Write(bytes, 0, bytes.Length); |
||
2167 | } |
||
2168 | else |
||
2169 | Log(LogMsgType.Error, "NOT CONNECTED!"); |
||
2170 | |||
2171 | } |
||
2172 | void _getWP() |
||
2173 | { |
||
2335 | - | 2174 | int iTimeout = 0; |
2287 | - | 2175 | _bGetWPCount = true; |
2315 | - | 2176 | _getpWP(1); //get the itemscount of wp |
2335 | - | 2177 | while (_bGetWPCount & iTimeout < _iWPTimeout * 5) |
2178 | { |
||
2179 | Thread.Sleep(10); |
||
2180 | iTimeout++; |
||
2181 | } |
||
2182 | if (_iWPCount > 0 & !_bGetWPCount) |
||
2287 | - | 2183 | _getWPList(); |
2184 | } |
||
2185 | void _getWPList() |
||
2186 | { |
||
2187 | _bGetWP = true; |
||
2313 | - | 2188 | int iTimeout=0; |
2189 | for (int j = 0; j < _iWPCount; j++) |
||
2287 | - | 2190 | { |
2191 | _getpWP(j + 1); |
||
2313 | - | 2192 | iTimeout = 0; |
2193 | while (_iWPIndex != j + 1 & iTimeout < _iWPTimeout * 5) |
||
2194 | { |
||
2195 | Thread.Sleep(1); |
||
2196 | iTimeout++; |
||
2197 | } |
||
2287 | - | 2198 | } |
2199 | } |
||
2363 | - | 2200 | /// <summary> |
2201 | /// Wrapper for _clearCopterWPList() |
||
2202 | /// necessary, cause it is called by threadnew which does not like return values... |
||
2203 | /// </summary> |
||
2340 | - | 2204 | void clearCopterWPList() |
2313 | - | 2205 | { |
2340 | - | 2206 | _clearCopterWPList(); |
2207 | } |
||
2363 | - | 2208 | /// <summary> |
2209 | /// clear the WP list of the copter |
||
2210 | /// by sending 'invalid' and index '0' |
||
2211 | /// </summary> |
||
2212 | /// <returns></returns> |
||
2340 | - | 2213 | bool _clearCopterWPList() |
2214 | { |
||
2335 | - | 2215 | int iTimeout = 0; |
2313 | - | 2216 | if (serialPortCtrl.Port.IsOpen) |
2217 | { |
||
2218 | byte[] bData = new byte[30]; |
||
2219 | for (int i = 0; i < 30; i++) |
||
2220 | bData[i] = 0; |
||
2221 | Stream serialStream = serialPortCtrl.Port.BaseStream; |
||
2222 | byte[] bytes = FlightControllerMessage.CreateMessage('w', 2, bData); //delete all WP on Copter by sending 'invalid'(==0) at index 0 |
||
2223 | serialStream.Write(bytes, 0, bytes.Length); |
||
2287 | - | 2224 | |
2313 | - | 2225 | _iWPCount = -1; |
2340 | - | 2226 | while (_iWPCount == -1 & iTimeout < _iWPTimeout) |
2335 | - | 2227 | { |
2313 | - | 2228 | Thread.Sleep(10); |
2335 | - | 2229 | iTimeout++; |
2230 | } |
||
2313 | - | 2231 | Dispatcher.Invoke(() => lblWPCount.Content = _iWPCount.ToString()); |
2335 | - | 2232 | if (_iWPCount > -1) |
2340 | - | 2233 | return true; |
2234 | else |
||
2235 | Log(LogMsgType.Error, "Timeout while sending list!"); |
||
2236 | } |
||
2237 | else |
||
2238 | Log(LogMsgType.Error, "NOT CONNECTED!"); |
||
2239 | |||
2240 | return false; |
||
2241 | } |
||
2242 | void _sendWPList() |
||
2243 | { |
||
2362 | - | 2244 | _sendWPList(0); |
2245 | } |
||
2246 | void _sendWPList(int iStart) |
||
2247 | { |
||
2340 | - | 2248 | int iTimeout = 0; |
2249 | if (serialPortCtrl.Port.IsOpen) |
||
2250 | { |
||
2251 | if (_clearCopterWPList()) |
||
2313 | - | 2252 | { |
2362 | - | 2253 | int k = 1; |
2254 | for (int i = iStart; i < dtWaypoints.Rows.Count; i++) |
||
2335 | - | 2255 | { |
2362 | - | 2256 | k = iStart > 0 ? k : -1; |
2257 | _sendWayPoint(dtWaypoints.Rows[i], k, 'w'); |
||
2313 | - | 2258 | |
2335 | - | 2259 | _iWPCount = -1; |
2260 | iTimeout = 0; |
||
2261 | while (_iWPCount == -1 & iTimeout < _iWPTimeout * 5) |
||
2262 | { |
||
2263 | Thread.Sleep(10); |
||
2264 | iTimeout++; |
||
2265 | } |
||
2266 | if (_iWPCount == -1) |
||
2267 | { |
||
2268 | Log(LogMsgType.Error, "Timeout while sending list!"); |
||
2269 | break; |
||
2270 | } |
||
2271 | Dispatcher.Invoke(() => lblWPCount.Content = _iWPCount.ToString()); |
||
2362 | - | 2272 | k++; |
2335 | - | 2273 | } |
2313 | - | 2274 | } |
2275 | } |
||
2276 | else |
||
2277 | Log(LogMsgType.Error, "NOT CONNECTED!"); |
||
2278 | |||
2279 | } |
||
2356 | - | 2280 | bool _sendWayPoint(DataRow dr, int index, char command) |
2340 | - | 2281 | { |
2313 | - | 2282 | |
2340 | - | 2283 | if (serialPortCtrl.Port.IsOpen) |
2284 | { |
||
2285 | byte[] bData = new byte[30]; |
||
2286 | for (int i = 0; i < 30; i++) |
||
2287 | bData[i] = 0; |
||
2288 | Stream serialStream = serialPortCtrl.Port.BaseStream; |
||
2289 | byte[] bytes; |
||
2290 | int iVal; |
||
2291 | double dVal; |
||
2292 | NumberFormatInfo nfi = new NumberFormatInfo(); |
||
2293 | nfi.NumberDecimalSeparator = ","; |
||
2294 | |||
2295 | //longitude |
||
2296 | dVal = Convert.ToDouble(dr[4], nfi); |
||
2297 | iVal = (int)(dVal * Math.Pow(10, 7)); |
||
2298 | bData[0] = (byte)(iVal & 0xff); |
||
2299 | bData[1] = (byte)((iVal >> 8) & 0xff); |
||
2300 | bData[2] = (byte)((iVal >> 16) & 0xff); |
||
2301 | bData[3] = (byte)(iVal >> 24); |
||
2302 | //latitude |
||
2303 | dVal = Convert.ToDouble(dr[3], nfi); |
||
2304 | iVal = (int)(dVal * Math.Pow(10, 7)); |
||
2305 | bData[4] = (byte)(iVal & 0xff); |
||
2306 | bData[5] = (byte)((iVal >> 8) & 0xff); |
||
2307 | bData[6] = (byte)((iVal >> 16) & 0xff); |
||
2308 | bData[7] = (byte)(iVal >> 24); |
||
2309 | //altitude |
||
2310 | dVal = Convert.ToDouble(dr[5], nfi); |
||
2311 | iVal = (int)(dVal * 10); |
||
2312 | bData[8] = (byte)(iVal & 0xff); |
||
2313 | bData[9] = (byte)((iVal >> 8) & 0xff); |
||
2314 | bData[10] = (byte)((iVal >> 16) & 0xff); |
||
2315 | bData[11] = (byte)(iVal >> 24); |
||
2316 | //Status 'NEWDATA' |
||
2317 | bData[12] = 1; |
||
2318 | //heading |
||
2319 | iVal = Convert.ToInt16(dr[6]); |
||
2320 | bData[13] = (byte)(iVal & 0xff); |
||
2321 | bData[14] = (byte)((iVal >> 8) & 0xff); |
||
2322 | //ToleranceRadius |
||
2323 | bData[15] = Convert.ToByte(dr[9]); |
||
2324 | //HoldTime |
||
2325 | bData[16] = Convert.ToByte(dr[10]); |
||
2326 | //Event_Flag |
||
2327 | bData[17] = Convert.ToByte(dr[13]); |
||
2328 | //Index |
||
2329 | bData[18] = index > 0 ? (byte)index : Convert.ToByte((int)dr[0]); |
||
2330 | //Type |
||
2331 | bData[19] = Convert.ToByte(dr[1]); |
||
2332 | //WP_EventChannelValue |
||
2333 | bData[20] = Convert.ToByte(dr[14]); |
||
2334 | //AltitudeRate |
||
2335 | bData[21] = Convert.ToByte(dr[8]); |
||
2336 | //Speed |
||
2337 | bData[22] = Convert.ToByte(dr[7]); |
||
2338 | //CamAngle |
||
2339 | bData[23] = (byte)Convert.ToInt16(dr[12]); |
||
2340 | //Name |
||
2362 | - | 2341 | string s = index > 0 ? ((string)dr[2]).Substring(0, 1) + index.ToString() : (string)dr[2]; |
2342 | byte[] name = ASCIIEncoding.ASCII.GetBytes(s); |
||
2340 | - | 2343 | bData[24] = name.Length > 0 ? name[0] : (byte)0; |
2344 | bData[25] = name.Length > 1 ? name[1] : (byte)0; |
||
2345 | bData[26] = name.Length > 2 ? name[2] : (byte)0; |
||
2346 | bData[27] = name.Length > 3 ? name[3] : (byte)0; |
||
2347 | //Autotrigger |
||
2348 | bData[28] = Convert.ToByte(dr[11]); |
||
2349 | |||
2356 | - | 2350 | bytes = FlightControllerMessage.CreateMessage(command, 2, bData); |
2340 | - | 2351 | serialStream.Write(bytes, 0, bytes.Length); |
2352 | |||
2353 | return true; |
||
2354 | } |
||
2355 | |||
2356 | return false; |
||
2357 | } |
||
2287 | - | 2358 | #region OSD-Menue |
2359 | |||
2360 | /// <summary> |
||
2361 | /// one time query of the OSD Menue with pagenumber |
||
2362 | /// </summary> |
||
2363 | /// <param name="iMenue">Menue page</param> |
||
2364 | void _OSDMenue(int iMenue) |
||
2365 | { |
||
2366 | if (serialPortCtrl.Port.IsOpen) |
||
2367 | { |
||
2368 | if (iMenue > iOSDMax) |
||
2369 | iMenue = 0; |
||
2370 | Stream serialStream = serialPortCtrl.Port.BaseStream; |
||
2371 | byte[] bytes = FlightControllerMessage.CreateMessage('l', 0, new byte[1] { (byte)iMenue }); |
||
2372 | serialStream.Write(bytes, 0, bytes.Length); |
||
2373 | } |
||
2374 | else |
||
2375 | Log(LogMsgType.Error, "NOT CONNECTED!"); |
||
2376 | |||
2377 | } |
||
2378 | /// <summary> |
||
2379 | /// call the OSDMenue and start autorefresh |
||
2380 | /// usually by sending a menuekey |
||
2381 | /// 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) |
||
2382 | /// therefore the value has to be negative (inverted) in order to distinguish from old (2 line) menuestyle |
||
2383 | /// and must not have any bits of the menue keys 0x1 0x2 0x4 0x8 (0x10?) --> 0x20 = -33 |
||
2384 | /// </summary> |
||
2385 | void _OSDMenueAutoRefresh() |
||
2386 | { |
||
2387 | _sendControllerMessage('h', 0, new byte[2] { unchecked((byte)(-33)), OSDInterval }); |
||
2388 | } |
||
2389 | void _OSDMenueAutoRefresh(byte key) |
||
2390 | { |
||
2391 | _sendControllerMessage('h', 0, new byte[2] { unchecked((byte)~key), OSDInterval }); |
||
2392 | } |
||
2393 | /// <summary> |
||
2394 | /// initialize the OSD menue combobox |
||
2395 | /// combox is filled by numbers from 0 to max pagenumber |
||
2396 | /// </summary> |
||
2397 | void _initOSDCB() |
||
2398 | { |
||
2399 | _bCBInit = true; |
||
2400 | if (iOSDMax == 0) |
||
2401 | { |
||
2402 | _OSDMenue(0); |
||
2403 | Thread.Sleep(10); |
||
2404 | } |
||
2405 | Dispatcher.Invoke((Action)(() => cbOSD.Items.Clear())); |
||
2406 | for (int i = 0; i <= iOSDMax; i++) |
||
2407 | { |
||
2408 | Dispatcher.Invoke((Action)(() => cbOSD.Items.Add(i))); |
||
2409 | } |
||
2410 | Dispatcher.Invoke((Action)(() => cbOSD.SelectedItem = iOSDPage)); |
||
2411 | _bCBInit = false; |
||
2412 | } |
||
2413 | private void btnOSDForward_Click(object sender, RoutedEventArgs e) |
||
2414 | { |
||
2415 | iOSDPage++; |
||
2416 | if (iOSDPage > iOSDMax) |
||
2417 | iOSDPage = 0; |
||
2418 | |||
2419 | _OSDMenue(iOSDPage); |
||
2420 | } |
||
2421 | private void btnOSDBackward_Click(object sender, RoutedEventArgs e) |
||
2422 | { |
||
2423 | iOSDPage--; |
||
2424 | if (iOSDPage < 0) |
||
2425 | iOSDPage = iOSDMax; |
||
2426 | |||
2427 | _OSDMenue(iOSDPage); |
||
2428 | } |
||
2429 | private void btnOSDLeave_Click(object sender, RoutedEventArgs e) |
||
2430 | { |
||
2431 | _OSDMenueAutoRefresh(8); |
||
2432 | } |
||
2433 | private void btnOSDEnter_Click(object sender, RoutedEventArgs e) |
||
2434 | { |
||
2435 | _OSDMenueAutoRefresh(4); |
||
2436 | } |
||
2437 | private void cbOSD_DropDownClosing(object sender, EventArgs e) |
||
2438 | { |
||
2439 | if (!_bCBInit && cbOSD.SelectedIndex > -1) |
||
2440 | _OSDMenue(cbOSD.SelectedIndex); |
||
2441 | } |
||
2442 | private void OSD(LogMsgType msgtype, string msg, bool bNew) |
||
2443 | { |
||
2444 | Dispatcher.Invoke(() => |
||
2445 | { |
||
2446 | TextRange tr; |
||
2447 | if (bNew) |
||
2448 | { |
||
2449 | rtfOSD.SelectAll(); |
||
2450 | rtfOSD.Selection.Text = string.Empty; |
||
2451 | } |
||
2452 | tr = new TextRange(rtfOSD.Document.ContentEnd, rtfOSD.Document.ContentEnd); |
||
2453 | tr.Text = msg; |
||
2454 | tr.ApplyPropertyValue(TextElement.ForegroundProperty, new SolidColorBrush(LogMsgTypeColor[(int)msgtype])); |
||
2455 | // rtfOSD.AppendText("\r"); |
||
2456 | rtfOSD.ScrollToEnd(); |
||
2457 | |||
2458 | }); |
||
2459 | } |
||
2460 | |||
2461 | #endregion OSD-Menue |
||
2462 | |||
2463 | #endregion controller messages |
||
2464 | |||
2295 | - | 2465 | void _mediaPlayer(string file) |
2466 | { |
||
2467 | if (File.Exists(file)) |
||
2468 | { |
||
2469 | MediaPlayer.MediaPlayer mp = new MediaPlayer.MediaPlayer(); |
||
2470 | mp.Open(file); |
||
2471 | mp.Play(); |
||
2472 | } |
||
2473 | } |
||
2310 | - | 2474 | |
2362 | - | 2475 | #region ui |
2310 | - | 2476 | /// <summary> |
2477 | /// Switch between fullscreen and normal window mode |
||
2478 | /// save & restore scaling settings |
||
2479 | /// </summary> |
||
2480 | /// <param name="sender"></param> |
||
2481 | /// <param name="e"></param> |
||
2287 | - | 2482 | private void imageFullscreen_MouseDown(object sender, MouseButtonEventArgs e) |
2483 | { |
||
2484 | if (winState.isMaximized) |
||
2485 | { |
||
2486 | winState.Restore(this); |
||
2487 | imageFullscreen.Source = new BitmapImage(new Uri("Images/Fullscreen.png", UriKind.Relative)); |
||
2488 | if(_bSaveWinStateFull) |
||
2489 | _saveScaleSliders(true); |
||
2490 | if(_bSaveWinStateNormal) |
||
2491 | _setScaleSliders(false); |
||
2492 | } |
||
2493 | else |
||
2494 | { |
||
2495 | winState.Maximize(this); |
||
2496 | imageFullscreen.Source = new BitmapImage(new Uri("Images/RestoreScreen.png", UriKind.Relative)); |
||
2497 | if(_bSaveWinStateNormal) |
||
2498 | _saveScaleSliders(false); |
||
2499 | if(_bSaveWinStateFull) |
||
2500 | _setScaleSliders(true); |
||
2501 | } |
||
2502 | } |
||
2503 | |||
2504 | /// <summary> |
||
2505 | /// reset the scaling of all UI elements to default |
||
2506 | /// </summary> |
||
2507 | /// <param name="sender"></param> |
||
2508 | /// <param name="e"></param> |
||
2509 | private void buttonUIScaleReset_Click(object sender, RoutedEventArgs e) |
||
2510 | { |
||
2511 | UIScaleHorizonSlider.Value = |
||
2512 | UIScaleLOGSlider.Value = |
||
2513 | UIScaleMotorsSlider.Value = |
||
2514 | UIScaleOSDSlider.Value = |
||
2515 | UIScaleSlider.Value = |
||
2516 | UIScaleTopSlider.Value = 1; |
||
2517 | } |
||
2518 | /// <summary> |
||
2519 | /// adjust the top postion of UI elements below the top bar to fit the bottom position of the bar when scaling the top bar |
||
2520 | /// </summary> |
||
2521 | /// <param name="sender"></param> |
||
2522 | /// <param name="e"></param> |
||
2523 | private void UIScaleTopSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) |
||
2524 | { |
||
2525 | GridSettings.Margin = new Thickness(GridSettings.Margin.Left, 36 * UIScaleTopSlider.Value, GridSettings.Margin.Right, GridSettings.Margin.Bottom); |
||
2526 | if (GridMotors != null) |
||
2527 | GridMotors.Margin = new Thickness(GridMotors.Margin.Left, 36 * UIScaleTopSlider.Value, GridMotors.Margin.Right, GridMotors.Margin.Bottom); |
||
2528 | if (GridSideBar != null) |
||
2529 | GridSideBar.Margin = new Thickness(GridSideBar.Margin.Left, 36 * UIScaleTopSlider.Value, GridSideBar.Margin.Right, GridSideBar.Margin.Bottom); |
||
2530 | if (GridOSD != null) |
||
2531 | GridOSD.Margin = new Thickness(GridOSD.Margin.Left, 36 * UIScaleTopSlider.Value, GridOSD.Margin.Right, GridOSD.Margin.Bottom); |
||
2532 | if (GridData != null) |
||
2533 | GridData.Margin = new Thickness(GridData.Margin.Left, 36 * UIScaleTopSlider.Value, GridData.Margin.Right, GridData.Margin.Bottom); |
||
2534 | if (GridWP != null) |
||
2535 | GridWP.Margin = new Thickness(GridWP.Margin.Left, 36 * UIScaleTopSlider.Value, GridWP.Margin.Right, GridWP.Margin.Bottom); |
||
2536 | } |
||
2310 | - | 2537 | /// <summary> |
2538 | /// restore the saved scalings for the fullscreen/normal window mode |
||
2539 | /// </summary> |
||
2540 | /// <param name="bFull">the mode the window is set to</param> |
||
2287 | - | 2541 | void _setScaleSliders(bool bFull) |
2542 | { |
||
2543 | if(bFull) |
||
2544 | { |
||
2545 | UIScaleSlider.Value = scaleFullAll; |
||
2546 | UIScaleTopSlider.Value = scaleFullTopBar; |
||
2547 | UIScaleMotorsSlider.Value = scaleFullMotors; |
||
2548 | UIScaleOSDSlider.Value = scaleFullOSD; |
||
2549 | UIScaleLOGSlider.Value = scaleFullLOG; |
||
2550 | UIScaleHorizonSlider.Value = scaleFullHorizon; |
||
2551 | } |
||
2552 | else |
||
2553 | { |
||
2554 | UIScaleSlider.Value = scaleNormalAll; |
||
2555 | UIScaleTopSlider.Value = scaleNormalTopBar; |
||
2556 | UIScaleMotorsSlider.Value = scaleNormalMotors; |
||
2557 | UIScaleOSDSlider.Value = scaleNormalOSD; |
||
2558 | UIScaleLOGSlider.Value = scaleNormalLOG; |
||
2559 | UIScaleHorizonSlider.Value = scaleNormalHorizon; |
||
2560 | } |
||
2561 | } |
||
2562 | |||
2310 | - | 2563 | /// <summary> |
2564 | /// save the scalings for the actual window mode |
||
2565 | /// </summary> |
||
2566 | /// <param name="bFull">the actual window mode</param> |
||
2287 | - | 2567 | void _saveScaleSliders(bool bFull) |
2568 | { |
||
2569 | |||
2570 | if (bFull) |
||
2571 | { |
||
2572 | scaleFullAll = UIScaleSlider.Value; |
||
2573 | scaleFullTopBar = UIScaleTopSlider.Value; |
||
2574 | scaleFullMotors = UIScaleMotorsSlider.Value; |
||
2575 | scaleFullOSD = UIScaleOSDSlider.Value; |
||
2576 | scaleFullLOG = UIScaleLOGSlider.Value; |
||
2577 | scaleFullHorizon = UIScaleHorizonSlider.Value; |
||
2578 | } |
||
2579 | else |
||
2580 | { |
||
2581 | scaleNormalAll = UIScaleSlider.Value; |
||
2582 | scaleNormalTopBar = UIScaleTopSlider.Value; |
||
2583 | scaleNormalMotors = UIScaleMotorsSlider.Value; |
||
2584 | scaleNormalOSD = UIScaleOSDSlider.Value; |
||
2585 | scaleNormalLOG = UIScaleLOGSlider.Value; |
||
2586 | scaleNormalHorizon = UIScaleHorizonSlider.Value; |
||
2587 | } |
||
2588 | } |
||
2362 | - | 2589 | #endregion ui |
2287 | - | 2590 | |
2591 | /// <summary> |
||
2592 | /// read settings from ini-file |
||
2593 | /// </summary> |
||
2594 | void _readIni() |
||
2595 | { |
||
2596 | if (!File.Exists(filePath + "\\MKLiveViewSettings.ini")) |
||
2597 | _writeIni(); |
||
2598 | IniFile ini = new IniFile("MKLiveViewSettings.ini"); |
||
2599 | ini.path = filePath + "\\MKLiveViewSettings.ini"; |
||
2312 | - | 2600 | try |
2601 | { |
||
2287 | - | 2602 | |
2312 | - | 2603 | string sVal = ini.IniReadValue("timings", "AutorefreshDebugData"); |
2604 | if (sVal != "") _debugDataAutorefresh = Convert.ToBoolean(sVal); |
||
2605 | sVal = ini.IniReadValue("timings", "AutorefreshNavCtrlData"); |
||
2606 | if (sVal != "") _navCtrlDataAutorefresh = Convert.ToBoolean(sVal); |
||
2607 | sVal = ini.IniReadValue("timings", "AutorefreshBLCtrlData"); |
||
2608 | if (sVal != "") _blctrlDataAutorefresh = Convert.ToBoolean(sVal); |
||
2609 | sVal = ini.IniReadValue("timings", "AutorefreshOSDData"); |
||
2610 | if (sVal != "") _OSDAutorefresh = Convert.ToBoolean(sVal); |
||
2287 | - | 2611 | |
2312 | - | 2612 | sVal = ini.IniReadValue("timings", "IntervalDebugData"); |
2613 | if (sVal != "") debugInterval = (byte)Convert.ToInt16(sVal); |
||
2614 | sVal = ini.IniReadValue("timings", "IntervalNavCtrlData"); |
||
2615 | if (sVal != "") navctrlInterval = (byte)Convert.ToInt16(sVal); |
||
2616 | sVal = ini.IniReadValue("timings", "IntervalBLCtrlData"); |
||
2617 | if (sVal != "") blctrlInterval = (byte)Convert.ToInt16(sVal); |
||
2618 | sVal = ini.IniReadValue("timings", "IntervalOSDData"); |
||
2619 | if (sVal != "") OSDInterval = (byte)Convert.ToInt16(sVal); |
||
2287 | - | 2620 | |
2312 | - | 2621 | sVal = ini.IniReadValue("topBar", "voltage"); |
2622 | if (sVal != "") chkBoxTopBarShowVoltage.IsChecked = Convert.ToBoolean(sVal); |
||
2623 | sVal = ini.IniReadValue("topBar", "capacity"); |
||
2624 | if (sVal != "") chkBoxTopBarShowCapacity.IsChecked = Convert.ToBoolean(sVal); |
||
2625 | sVal = ini.IniReadValue("topBar", "current"); |
||
2626 | if (sVal != "") chkBoxTopBarShowCurrent.IsChecked = Convert.ToBoolean(sVal); |
||
2627 | sVal = ini.IniReadValue("topBar", "flightTime"); |
||
2628 | if (sVal != "") chkBoxTopBarShowFlightTime.IsChecked = Convert.ToBoolean(sVal); |
||
2629 | sVal = ini.IniReadValue("topBar", "distanceHP"); |
||
2630 | if (sVal != "") chkBoxTopBarShowDistanceHP.IsChecked = Convert.ToBoolean(sVal); |
||
2631 | sVal = ini.IniReadValue("topBar", "height"); |
||
2632 | if (sVal != "") chkBoxTopBarShowHeight.IsChecked = Convert.ToBoolean(sVal); |
||
2633 | sVal = ini.IniReadValue("topBar", "speed"); |
||
2634 | if (sVal != "") chkBoxTopBarShowSpeed.IsChecked = Convert.ToBoolean(sVal); |
||
2635 | sVal = ini.IniReadValue("topBar", "magneticField"); |
||
2636 | if (sVal != "") chkBoxTopBarShowMF.IsChecked = Convert.ToBoolean(sVal); |
||
2637 | sVal = ini.IniReadValue("topBar", "satellites"); |
||
2638 | if (sVal != "") chkBoxTopBarShowSatellites.IsChecked = Convert.ToBoolean(sVal); |
||
2639 | sVal = ini.IniReadValue("topBar", "rc"); |
||
2640 | if (sVal != "") chkBoxTopBarShowRC.IsChecked = Convert.ToBoolean(sVal); |
||
2287 | - | 2641 | |
2312 | - | 2642 | sVal = ini.IniReadValue("style", "saveFullScreen"); |
2643 | if (sVal != "") chkBoxSaveFullScreenState.IsChecked = Convert.ToBoolean(sVal); |
||
2644 | sVal = ini.IniReadValue("style", "saveNormalState"); |
||
2645 | if (sVal != "") chkBoxSaveNormalState.IsChecked = Convert.ToBoolean(sVal); |
||
2287 | - | 2646 | |
2312 | - | 2647 | sVal = ini.IniReadValue("style", "scaleNormalAll"); |
2648 | if (sVal != "") scaleNormalAll = Convert.ToDouble(sVal); |
||
2649 | sVal = ini.IniReadValue("style", "scaleNormalTopBar"); |
||
2650 | if (sVal != "") scaleNormalTopBar = Convert.ToDouble(sVal); |
||
2651 | sVal = ini.IniReadValue("style", "scaleNormalMotors"); |
||
2652 | if (sVal != "") scaleNormalMotors = Convert.ToDouble(sVal); |
||
2653 | sVal = ini.IniReadValue("style", "scaleNormalOSD"); |
||
2654 | if (sVal != "") scaleNormalOSD = Convert.ToDouble(sVal); |
||
2655 | sVal = ini.IniReadValue("style", "scaleNormalLOG"); |
||
2656 | if (sVal != "") scaleNormalLOG = Convert.ToDouble(sVal); |
||
2657 | sVal = ini.IniReadValue("style", "scaleNormalHorizon"); |
||
2658 | if (sVal != "") scaleNormalHorizon = Convert.ToDouble(sVal); |
||
2287 | - | 2659 | |
2312 | - | 2660 | sVal = ini.IniReadValue("style", "scaleFullAll"); |
2661 | if (sVal != "") scaleFullAll = Convert.ToDouble(sVal); |
||
2662 | sVal = ini.IniReadValue("style", "scaleFullTopBar"); |
||
2663 | if (sVal != "") scaleFullTopBar = Convert.ToDouble(sVal); |
||
2664 | sVal = ini.IniReadValue("style", "scaleFullMotors"); |
||
2665 | if (sVal != "") scaleFullMotors = Convert.ToDouble(sVal); |
||
2666 | sVal = ini.IniReadValue("style", "scaleFullOSD"); |
||
2667 | if (sVal != "") scaleFullOSD = Convert.ToDouble(sVal); |
||
2668 | sVal = ini.IniReadValue("style", "scaleFullLOG"); |
||
2669 | if (sVal != "") scaleFullLOG = Convert.ToDouble(sVal); |
||
2670 | sVal = ini.IniReadValue("style", "scaleFullHorizon"); |
||
2671 | if (sVal != "") scaleFullHorizon = Convert.ToDouble(sVal); |
||
2287 | - | 2672 | |
2312 | - | 2673 | sVal = ini.IniReadValue("general", "LiPoCells"); |
2674 | _LipoCells = Convert.ToInt16(sVal); |
||
2675 | sVal = ini.IniReadValue("general", "Motors"); |
||
2676 | if (sVal != "") _iMotors = Convert.ToInt16(sVal); |
||
2287 | - | 2677 | |
2312 | - | 2678 | sVal = ini.IniReadValue("map", "followMe"); |
2679 | if (sVal != "") _bFollowCopter = Convert.ToBoolean(sVal); |
||
2680 | sVal = ini.IniReadValue("map", "AutoSetHome"); |
||
2681 | if (sVal != "") _bAutoHome = Convert.ToBoolean(sVal); |
||
2324 | - | 2682 | sVal = ini.IniReadValue("map", "GPXLog"); |
2683 | if (sVal != "") _bGPXLog = Convert.ToBoolean(sVal); |
||
2287 | - | 2684 | |
2312 | - | 2685 | sVal = ini.IniReadValue("threshold", "VoltageWarning"); |
2686 | if(sVal != "") _dThresholdVoltageWarn = Convert.ToDouble(sVal); |
||
2687 | sVal = ini.IniReadValue("threshold", "VoltageCritical"); |
||
2688 | if(sVal != "") _dThresholdVoltageCrit = Convert.ToDouble(sVal); |
||
2689 | sVal = ini.IniReadValue("threshold", "VoiceVoltageEnable"); |
||
2690 | if(sVal != "") _bVoiceVoltPlay = Convert.ToBoolean(sVal); |
||
2691 | sVal = ini.IniReadValue("threshold", "VoiceSatFixEnable"); |
||
2692 | if(sVal != "") _bVoiceSatFixPlay = Convert.ToBoolean(sVal); |
||
2693 | sVal = ini.IniReadValue("threshold", "VoiceMagFieldEnable"); |
||
2694 | if(sVal != "") _bVoiceMagneticFieldPlay = Convert.ToBoolean(sVal); |
||
2695 | sVal = ini.IniReadValue("threshold", "DistanceWarning"); |
||
2696 | if(sVal != "") _dThresholdDistanceWarn = Convert.ToDouble(sVal); |
||
2697 | sVal = ini.IniReadValue("threshold", "VoiceDistanceWarnEnable"); |
||
2698 | if(sVal != "") _bVoiceDistancePlay = Convert.ToBoolean(sVal); |
||
2699 | sVal = ini.IniReadValue("threshold", "VoiceRCLevelWarnEnable"); |
||
2700 | if(sVal != "") _bVoiceRCLevelPlay = Convert.ToBoolean(sVal); |
||
2701 | sVal = ini.IniReadValue("threshold", "MaxDistance"); |
||
2702 | if(sVal != "") _dThresholdDistanceMax = Convert.ToDouble(sVal); |
||
2703 | sVal = ini.IniReadValue("threshold", "RCThreshold"); |
||
2704 | if(sVal != "") _iThresholdRC = Convert.ToInt32(sVal); |
||
2705 | sVal = ini.IniReadValue("threshold", "MagFieldThreshold"); |
||
2706 | if(sVal != "") _iThresholdMagField = Convert.ToInt32(sVal); |
||
2321 | - | 2707 | |
2708 | sVal = ini.IniReadValue("waypoints", "wpcolor"); |
||
2709 | if(sVal != "") comboBoxWPColor.SelectedIndex = Convert.ToInt32(sVal); |
||
2710 | sVal = ini.IniReadValue("waypoints", "poicolor"); |
||
2711 | if(sVal != "") comboBoxPOIColor.SelectedIndex = Convert.ToInt32(sVal); |
||
2712 | sVal = ini.IniReadValue("waypoints", "fscolor"); |
||
2713 | if(sVal != "") comboBoxFSColor.SelectedIndex = Convert.ToInt32(sVal); |
||
2714 | sVal = ini.IniReadValue("waypoints", "coptercolor"); |
||
2715 | if(sVal != "") comboBoxCopterColor.SelectedIndex = Convert.ToInt32(sVal); |
||
2328 | - | 2716 | sVal = ini.IniReadValue("waypoints", "routecolor"); |
2717 | if(sVal != "") comboBoxRouteColor.SelectedIndex = Convert.ToInt32(sVal); |
||
2718 | sVal = ini.IniReadValue("waypoints", "showWPRoute"); |
||
2719 | if(sVal != "") _bShowWPRoute = Convert.ToBoolean(sVal); |
||
2349 | - | 2720 | |
2721 | for (int i = 0; i < 12; i++) |
||
2722 | { |
||
2723 | sVal = ini.IniReadValue("serial", "ch" + i.ToString() + "Val"); |
||
2724 | if (sVal != "") |
||
2725 | serChan[i] = Convert.ToInt16(sVal); |
||
2726 | sVal = ini.IniReadValue("serial", "ch" + i.ToString() + "Title"); |
||
2727 | if (sVal != "") |
||
2728 | serChanTitle[i] = sVal; |
||
2729 | for (int y = 0; i < 4 && y < 3; y++) |
||
2730 | { |
||
2731 | sVal = ini.IniReadValue("serial", "ch" + i.ToString() + "ValSub" + y.ToString()); |
||
2732 | if (sVal != "") |
||
2733 | serChan_sub[(i * 3) + y] = Convert.ToInt16(sVal); |
||
2734 | } |
||
2735 | } |
||
2736 | |||
2312 | - | 2737 | } |
2738 | catch (Exception e) |
||
2739 | { |
||
2287 | - | 2740 | |
2312 | - | 2741 | MessageBox.Show("Error parsing ini-file!" + Environment.NewLine + e.Message,"Read ini-file" ,MessageBoxButton.OK,MessageBoxImage.Error); |
2742 | } |
||
2743 | |||
2287 | - | 2744 | } |
2745 | |||
2746 | /// <summary> |
||
2747 | /// save settings to ini-file |
||
2748 | /// </summary> |
||
2749 | void _writeIni() |
||
2750 | { |
||
2751 | |||
2752 | IniFile ini = new IniFile("MKLiveViewSettings.ini"); |
||
2753 | ini.path = filePath + "\\MKLiveViewSettings.ini"; |
||
2754 | |||
2312 | - | 2755 | try |
2756 | { |
||
2287 | - | 2757 | |
2312 | - | 2758 | ini.IniWriteValue("timings", "AutorefreshDebugData", _debugDataAutorefresh ? "true" : "false"); |
2759 | ini.IniWriteValue("timings", "AutorefreshNavCtrlData", _navCtrlDataAutorefresh ? "true" : "false"); |
||
2760 | ini.IniWriteValue("timings", "AutorefreshBLCtrlData", _blctrlDataAutorefresh ? "true" : "false"); |
||
2761 | ini.IniWriteValue("timings", "AutorefreshOSDData", _OSDAutorefresh ? "true" : "false"); |
||
2287 | - | 2762 | |
2312 | - | 2763 | ini.IniWriteValue("timings", "IntervalDebugData", debugInterval.ToString()); |
2764 | ini.IniWriteValue("timings", "IntervalNavCtrlData", navctrlInterval.ToString()); |
||
2765 | ini.IniWriteValue("timings", "IntervalBLCtrlData", blctrlInterval.ToString()); |
||
2766 | ini.IniWriteValue("timings", "IntervalOSDData", OSDInterval.ToString()); |
||
2287 | - | 2767 | |
2312 | - | 2768 | ini.IniWriteValue("general", "LiPoCells", _LipoCells.ToString()); |
2769 | ini.IniWriteValue("general", "Motors", _iMotors.ToString()); |
||
2287 | - | 2770 | |
2312 | - | 2771 | ini.IniWriteValue("map", "followMe", _bFollowCopter.ToString()); |
2772 | ini.IniWriteValue("map", "AutoSetHome", _bAutoHome.ToString()); |
||
2324 | - | 2773 | ini.IniWriteValue("map", "GPXLog", _bGPXLog.ToString()); |
2287 | - | 2774 | |
2312 | - | 2775 | ini.IniWriteValue("topBar", "voltage", chkBoxTopBarShowVoltage.IsChecked.ToString()); |
2776 | ini.IniWriteValue("topBar", "capacity", chkBoxTopBarShowCapacity.IsChecked.ToString()); |
||
2777 | ini.IniWriteValue("topBar", "current", chkBoxTopBarShowCurrent.IsChecked.ToString()); |
||
2778 | ini.IniWriteValue("topBar", "flightTime", chkBoxTopBarShowFlightTime.IsChecked.ToString()); |
||
2779 | ini.IniWriteValue("topBar", "distanceHP", chkBoxTopBarShowDistanceHP.IsChecked.ToString()); |
||
2780 | ini.IniWriteValue("topBar", "height", chkBoxTopBarShowHeight.IsChecked.ToString()); |
||
2781 | ini.IniWriteValue("topBar", "speed", chkBoxTopBarShowSpeed.IsChecked.ToString()); |
||
2782 | ini.IniWriteValue("topBar", "magneticField", chkBoxTopBarShowMF.IsChecked.ToString()); |
||
2783 | ini.IniWriteValue("topBar", "satellites", chkBoxTopBarShowSatellites.IsChecked.ToString()); |
||
2784 | ini.IniWriteValue("topBar", "rc", chkBoxTopBarShowRC.IsChecked.ToString()); |
||
2287 | - | 2785 | |
2312 | - | 2786 | ini.IniWriteValue("style", "saveFullScreen", chkBoxSaveFullScreenState.IsChecked.ToString()); |
2787 | ini.IniWriteValue("style", "saveNormalState", chkBoxSaveNormalState.IsChecked.ToString()); |
||
2287 | - | 2788 | |
2312 | - | 2789 | ini.IniWriteValue("style", "scaleNormalAll", scaleNormalAll.ToString()); |
2790 | ini.IniWriteValue("style", "scaleNormalTopBar", scaleNormalTopBar.ToString()); |
||
2791 | ini.IniWriteValue("style", "scaleNormalMotors", scaleNormalMotors.ToString()); |
||
2792 | ini.IniWriteValue("style", "scaleNormalOSD", scaleNormalOSD.ToString()); |
||
2793 | ini.IniWriteValue("style", "scaleNormalLOG", scaleNormalLOG.ToString()); |
||
2794 | ini.IniWriteValue("style", "scaleNormalHorizon", scaleNormalHorizon.ToString()); |
||
2287 | - | 2795 | |
2312 | - | 2796 | ini.IniWriteValue("style", "scaleFullAll", scaleFullAll.ToString()); |
2797 | ini.IniWriteValue("style", "scaleFullTopBar", scaleFullTopBar.ToString()); |
||
2798 | ini.IniWriteValue("style", "scaleFullMotors", scaleFullMotors.ToString()); |
||
2799 | ini.IniWriteValue("style", "scaleFullOSD", scaleFullOSD.ToString()); |
||
2800 | ini.IniWriteValue("style", "scaleFullLOG", scaleFullLOG.ToString()); |
||
2801 | ini.IniWriteValue("style", "scaleFullHorizon", scaleFullHorizon.ToString()); |
||
2287 | - | 2802 | |
2312 | - | 2803 | ini.IniWriteValue("style", "horizon", chkBoxShowHorizon.IsChecked.ToString()); |
2804 | |||
2805 | ini.IniWriteValue("threshold", "VoltageWarning", _dThresholdVoltageWarn.ToString()); |
||
2806 | ini.IniWriteValue("threshold", "VoltageCritical", _dThresholdVoltageCrit.ToString()); |
||
2807 | ini.IniWriteValue("threshold", "VoiceVoltageEnable", _bVoiceVoltPlay.ToString()); |
||
2808 | ini.IniWriteValue("threshold", "VoiceSatFixEnable", _bVoiceSatFixPlay.ToString()); |
||
2809 | ini.IniWriteValue("threshold", "VoiceMagFieldEnable", _bVoiceMagneticFieldPlay.ToString()); |
||
2810 | ini.IniWriteValue("threshold", "VoiceDistanceWarnEnable", _bVoiceDistancePlay.ToString()); |
||
2811 | ini.IniWriteValue("threshold", "VoiceRCLevelWarnEnable", _bVoiceRCLevelPlay.ToString()); |
||
2812 | ini.IniWriteValue("threshold", "DistanceWarning", _dThresholdDistanceWarn.ToString()); |
||
2813 | ini.IniWriteValue("threshold", "MaxDistance", _dThresholdDistanceMax.ToString()); |
||
2814 | ini.IniWriteValue("threshold", "RCThreshold", _iThresholdRC.ToString()); |
||
2815 | ini.IniWriteValue("threshold", "MagFieldThreshold", _iThresholdMagField.ToString()); |
||
2321 | - | 2816 | |
2817 | ini.IniWriteValue("waypoints", "wpcolor", comboBoxWPColor.SelectedIndex.ToString()); |
||
2818 | ini.IniWriteValue("waypoints", "poicolor", comboBoxPOIColor.SelectedIndex.ToString()); |
||
2819 | ini.IniWriteValue("waypoints", "fscolor", comboBoxFSColor.SelectedIndex.ToString()); |
||
2820 | ini.IniWriteValue("waypoints", "coptercolor", comboBoxCopterColor.SelectedIndex.ToString()); |
||
2328 | - | 2821 | ini.IniWriteValue("waypoints", "routecolor", comboBoxRouteColor.SelectedIndex.ToString()); |
2822 | ini.IniWriteValue("waypoints", "showWPRoute", _bShowWPRoute.ToString()); |
||
2349 | - | 2823 | |
2824 | for (int i = 0; i < 12; i++) |
||
2825 | { |
||
2826 | ini.IniWriteValue("serial", "ch" + i.ToString() + "Val", serChan[i].ToString()); |
||
2827 | ini.IniWriteValue("serial", "ch" + i.ToString() + "Title", serChanTitle[i]); |
||
2828 | for (int y = 0; i < 4 && y < 3; y++) |
||
2829 | { |
||
2830 | ini.IniWriteValue("serial", "ch" + i.ToString() + "ValSub" + y.ToString(), serChan_sub[(i * 3) + y].ToString()); |
||
2831 | } |
||
2832 | } |
||
2833 | |||
2312 | - | 2834 | } |
2835 | catch (Exception e) |
||
2836 | { |
||
2837 | |||
2838 | 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); |
||
2839 | } |
||
2287 | - | 2840 | } |
2350 | - | 2841 | |
2349 | - | 2842 | #region serial channels |
2843 | /// <summary> |
||
2844 | /// Sending the serial channel values |
||
2845 | /// </summary> |
||
2846 | void _sendSerialData() |
||
2847 | { |
||
2848 | byte[] serData = new byte[12]; |
||
2849 | for (int i = 0; i < 12; i++) |
||
2850 | { |
||
2851 | serData[i] = unchecked((byte)(serChan[i] - 127)); |
||
2852 | } |
||
2853 | _sendControllerMessage('y', 1, serData); |
||
2854 | } |
||
2855 | /// <summary> |
||
2856 | /// init the controls for displaying |
||
2857 | /// and setting serial control channels |
||
2858 | /// </summary> |
||
2859 | void _initSerialCtrl() |
||
2860 | { |
||
2861 | SerChan1ScaleSlider.Value = serChan[0]; |
||
2862 | textBoxSerial1.Text = serChanTitle[0]; |
||
2863 | SerChan2ScaleSlider.Value = serChan[1]; |
||
2864 | textBoxSerial2.Text = serChanTitle[1]; |
||
2350 | - | 2865 | SerChan3ScaleSlider.Value = serChan[2]; |
2866 | textBoxSerial3.Text = serChanTitle[2]; |
||
2349 | - | 2867 | //SerChan4ScaleSlider.Value = serChan[3]; |
2868 | //textBoxSerial4.Text = serChanTitle[3]; |
||
2869 | //trckbarSerial5.Value = serChan[4]; |
||
2870 | //textBoxSerial5.Text = serChanTitle[4]; |
||
2871 | //trckbarSerial6.Value = serChan[5]; |
||
2872 | //textBoxSerial6.Text = serChanTitle[5]; |
||
2873 | //trckbarSerial7.Value = serChan[6]; |
||
2874 | //textBoxSerial7.Text = serChanTitle[6]; |
||
2875 | //trckbarSerial8.Value = serChan[7]; |
||
2876 | //textBoxSerial8.Text = serChanTitle[7]; |
||
2312 | - | 2877 | |
2349 | - | 2878 | textBoxSerial1_val1.Text = serChan_sub[0].ToString(); |
2879 | textBoxSerial1_val2.Text = serChan_sub[1].ToString(); |
||
2880 | textBoxSerial1_val3.Text = serChan_sub[2].ToString(); |
||
2881 | textBoxSerial2_val1.Text = serChan_sub[3].ToString(); |
||
2882 | textBoxSerial2_val2.Text = serChan_sub[4].ToString(); |
||
2883 | textBoxSerial2_val3.Text = serChan_sub[5].ToString(); |
||
2350 | - | 2884 | textBoxSerial3_val1.Text = serChan_sub[6].ToString(); |
2885 | textBoxSerial3_val2.Text = serChan_sub[7].ToString(); |
||
2886 | textBoxSerial3_val3.Text = serChan_sub[8].ToString(); |
||
2349 | - | 2887 | //textBoxSerial4_val1.Text = serChan_sub[9].ToString(); |
2888 | //textBoxSerial4_val2.Text = serChan_sub[10].ToString(); |
||
2889 | //textBoxSerial4_val3.Text = serChan_sub[11].ToString(); |
||
2890 | } |
||
2891 | private void SerChan1ScaleSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) |
||
2892 | { |
||
2893 | if (!_init) |
||
2894 | { |
||
2895 | serChan[0] = (int)SerChan1ScaleSlider.Value; |
||
2896 | _sendSerialData(); |
||
2897 | } |
||
2898 | } |
||
2899 | private void textBoxSerial1_TextChanged(object sender, TextChangedEventArgs e) |
||
2900 | { |
||
2901 | if (!_init) |
||
2902 | { |
||
2903 | serChanTitle[0] = textBoxSerial1.Text; |
||
2904 | } |
||
2905 | } |
||
2906 | private void textBoxSerial1_val1_TextChanged(object sender, TextChangedEventArgs e) |
||
2907 | { |
||
2908 | if (textBoxSerial1_val1.Text.Length > 0 & !_init) |
||
2909 | { |
||
2910 | serChan_sub[0] = Convert.ToInt16(textBoxSerial1_val1.Text); |
||
2911 | } |
||
2912 | } |
||
2913 | private void textBoxSerial1_val2_TextChanged(object sender, TextChangedEventArgs e) |
||
2914 | { |
||
2915 | if (textBoxSerial1_val2.Text.Length > 0 & !_init) |
||
2916 | { |
||
2917 | serChan_sub[1] = Convert.ToInt16(textBoxSerial1_val2.Text); |
||
2918 | } |
||
2919 | } |
||
2920 | private void textBoxSerial1_val3_TextChanged(object sender, TextChangedEventArgs e) |
||
2921 | { |
||
2922 | if (textBoxSerial1_val3.Text.Length > 0 & !_init) |
||
2923 | { |
||
2924 | serChan_sub[2] = Convert.ToInt16(textBoxSerial1_val3.Text); |
||
2925 | } |
||
2926 | } |
||
2927 | private void btnSer1_val1_Click(object sender, RoutedEventArgs e) |
||
2928 | { |
||
2929 | if (textBoxSerial1_val1.Text.Length > 0) |
||
2930 | { |
||
2931 | SerChan1ScaleSlider.Value = Convert.ToInt16(textBoxSerial1_val1.Text); |
||
2932 | } |
||
2933 | } |
||
2934 | private void btnSer1_0_Click(object sender, RoutedEventArgs e) |
||
2935 | { |
||
2936 | SerChan1ScaleSlider.Value = 0; |
||
2937 | } |
||
2938 | private void btnSer1_127_Click(object sender, RoutedEventArgs e) |
||
2939 | { |
||
2940 | SerChan1ScaleSlider.Value = 127; |
||
2941 | } |
||
2942 | private void btnSer1_254_Click(object sender, RoutedEventArgs e) |
||
2943 | { |
||
2944 | SerChan1ScaleSlider.Value = 254; |
||
2945 | } |
||
2946 | private void btnSer1_val2_Click(object sender, RoutedEventArgs e) |
||
2947 | { |
||
2948 | if (textBoxSerial1_val2.Text.Length > 0) |
||
2949 | { |
||
2950 | SerChan1ScaleSlider.Value = Convert.ToInt16(textBoxSerial1_val2.Text); |
||
2951 | } |
||
2952 | } |
||
2953 | private void btnSer1_val3_Click(object sender, RoutedEventArgs e) |
||
2954 | { |
||
2955 | if (textBoxSerial1_val3.Text.Length > 0) |
||
2956 | { |
||
2957 | SerChan1ScaleSlider.Value = Convert.ToInt16(textBoxSerial1_val3.Text); |
||
2958 | } |
||
2959 | } |
||
2960 | |||
2961 | private void SerChan2ScaleSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) |
||
2962 | { |
||
2963 | if (!_init) |
||
2964 | { |
||
2965 | serChan[1] = (int)SerChan2ScaleSlider.Value; |
||
2966 | _sendSerialData(); |
||
2967 | } |
||
2968 | } |
||
2969 | private void textBoxSerial2_TextChanged(object sender, TextChangedEventArgs e) |
||
2970 | { |
||
2971 | if (!_init) |
||
2972 | { |
||
2973 | serChanTitle[1] = textBoxSerial2.Text; |
||
2974 | } |
||
2975 | } |
||
2976 | private void textBoxSerial2_val1_TextChanged(object sender, TextChangedEventArgs e) |
||
2977 | { |
||
2978 | if (textBoxSerial2_val1.Text.Length > 0 & !_init) |
||
2979 | { |
||
2980 | serChan_sub[3] = Convert.ToInt16(textBoxSerial2_val1.Text); |
||
2981 | } |
||
2982 | } |
||
2983 | private void textBoxSerial2_val2_TextChanged(object sender, TextChangedEventArgs e) |
||
2984 | { |
||
2985 | if (textBoxSerial2_val2.Text.Length > 0 & !_init) |
||
2986 | { |
||
2987 | serChan_sub[4] = Convert.ToInt16(textBoxSerial2_val2.Text); |
||
2988 | } |
||
2989 | } |
||
2990 | private void textBoxSerial2_val3_TextChanged(object sender, TextChangedEventArgs e) |
||
2991 | { |
||
2992 | if (textBoxSerial2_val3.Text.Length > 0 & !_init) |
||
2993 | { |
||
2994 | serChan_sub[5] = Convert.ToInt16(textBoxSerial2_val3.Text); |
||
2995 | } |
||
2996 | } |
||
2997 | private void btnSer2_0_Click(object sender, RoutedEventArgs e) |
||
2998 | { |
||
2999 | SerChan2ScaleSlider.Value = 0; |
||
3000 | } |
||
3001 | private void btnSer2_127_Click(object sender, RoutedEventArgs e) |
||
3002 | { |
||
3003 | SerChan2ScaleSlider.Value = 127; |
||
3004 | } |
||
3005 | private void btnSer2_254_Click(object sender, RoutedEventArgs e) |
||
3006 | { |
||
3007 | SerChan2ScaleSlider.Value = 254; |
||
3008 | } |
||
3009 | private void btnSer2_val1_Click(object sender, RoutedEventArgs e) |
||
3010 | { |
||
3011 | if (textBoxSerial2_val1.Text.Length > 0) |
||
3012 | { |
||
3013 | SerChan2ScaleSlider.Value = Convert.ToInt16(textBoxSerial2_val1.Text); |
||
3014 | } |
||
3015 | } |
||
3016 | private void btnSer2_val2_Click(object sender, RoutedEventArgs e) |
||
3017 | { |
||
3018 | if (textBoxSerial2_val2.Text.Length > 0) |
||
3019 | { |
||
3020 | SerChan2ScaleSlider.Value = Convert.ToInt16(textBoxSerial2_val2.Text); |
||
3021 | } |
||
3022 | } |
||
3023 | private void btnSer2_val3_Click(object sender, RoutedEventArgs e) |
||
3024 | { |
||
3025 | if (textBoxSerial2_val3.Text.Length > 0) |
||
3026 | { |
||
3027 | SerChan2ScaleSlider.Value = Convert.ToInt16(textBoxSerial2_val3.Text); |
||
3028 | } |
||
3029 | } |
||
2350 | - | 3030 | |
3031 | private void SerChan3ScaleSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) |
||
3032 | { |
||
3033 | if (!_init) |
||
3034 | { |
||
3035 | serChan[2] = (int)SerChan3ScaleSlider.Value; |
||
3036 | _sendSerialData(); |
||
3037 | } |
||
3038 | } |
||
3039 | private void textBoxSerial3_TextChanged(object sender, TextChangedEventArgs e) |
||
3040 | { |
||
3041 | if (!_init) |
||
3042 | { |
||
3043 | serChanTitle[2] = textBoxSerial3.Text; |
||
3044 | } |
||
3045 | } |
||
3046 | private void textBoxSerial3_val1_TextChanged(object sender, TextChangedEventArgs e) |
||
3047 | { |
||
3048 | if (textBoxSerial3_val1.Text.Length > 0 & !_init) |
||
3049 | { |
||
3050 | serChan_sub[6] = Convert.ToInt16(textBoxSerial3_val1.Text); |
||
3051 | } |
||
3052 | } |
||
3053 | private void textBoxSerial3_val2_TextChanged(object sender, TextChangedEventArgs e) |
||
3054 | { |
||
3055 | if (textBoxSerial3_val2.Text.Length > 0 & !_init) |
||
3056 | { |
||
3057 | serChan_sub[7] = Convert.ToInt16(textBoxSerial3_val2.Text); |
||
3058 | } |
||
3059 | } |
||
3060 | private void textBoxSerial3_val3_TextChanged(object sender, TextChangedEventArgs e) |
||
3061 | { |
||
3062 | if (textBoxSerial3_val3.Text.Length > 0 & !_init) |
||
3063 | { |
||
3064 | serChan_sub[8] = Convert.ToInt16(textBoxSerial3_val3.Text); |
||
3065 | } |
||
3066 | } |
||
3067 | private void btnSer3_0_Click(object sender, RoutedEventArgs e) |
||
3068 | { |
||
3069 | SerChan3ScaleSlider.Value = 0; |
||
3070 | } |
||
3071 | private void btnSer3_127_Click(object sender, RoutedEventArgs e) |
||
3072 | { |
||
3073 | SerChan3ScaleSlider.Value = 127; |
||
3074 | } |
||
3075 | private void btnSer3_254_Click(object sender, RoutedEventArgs e) |
||
3076 | { |
||
3077 | SerChan3ScaleSlider.Value = 254; |
||
3078 | } |
||
3079 | private void btnSer3_val1_Click(object sender, RoutedEventArgs e) |
||
3080 | { |
||
3081 | if (textBoxSerial3_val1.Text.Length > 0) |
||
3082 | { |
||
3083 | SerChan3ScaleSlider.Value = Convert.ToInt16(textBoxSerial3_val1.Text); |
||
3084 | } |
||
3085 | } |
||
3086 | private void btnSer3_val2_Click(object sender, RoutedEventArgs e) |
||
3087 | { |
||
3088 | if (textBoxSerial3_val2.Text.Length > 0) |
||
3089 | { |
||
3090 | SerChan3ScaleSlider.Value = Convert.ToInt16(textBoxSerial3_val2.Text); |
||
3091 | } |
||
3092 | } |
||
3093 | private void btnSer3_val3_Click(object sender, RoutedEventArgs e) |
||
3094 | { |
||
3095 | if (textBoxSerial3_val3.Text.Length > 0) |
||
3096 | { |
||
3097 | SerChan3ScaleSlider.Value = Convert.ToInt16(textBoxSerial3_val3.Text); |
||
3098 | } |
||
3099 | } |
||
2349 | - | 3100 | /// <summary> |
3101 | /// checks the input of a textbox |
||
3102 | /// for valid data |
||
3103 | /// in this case values 0-254 |
||
3104 | /// </summary> |
||
3105 | /// <param name="sender"></param> |
||
3106 | /// <param name="e"></param> |
||
3107 | private void textBox_serial_KeyPress(object sender, KeyEventArgs e) |
||
3108 | { |
||
3109 | if ("1234567890,\b".IndexOf(e.Key.ToString()) < 0) //general check for valid chars(0-9) and backspace (\b) |
||
3110 | e.Handled = true; |
||
3111 | else |
||
3112 | if ("\b".IndexOf(e.Key.ToString()) < 0) |
||
3113 | if (Convert.ToInt16(((TextBox)sender).Text + e.Key) > 254) //if valid and not backspace, check for upper limit of the resulting number |
||
3114 | e.Handled = true; |
||
3115 | else |
||
3116 | { |
||
3117 | int i = -1; |
||
3118 | switch (((TextBox)sender).Name) |
||
3119 | { |
||
3120 | case "textBoxSerial1_val1": |
||
3121 | i = 0; |
||
3122 | break; |
||
3123 | case "textBoxSerial1_val2": |
||
3124 | i = 1; |
||
3125 | break; |
||
3126 | case "textBoxSerial1_val3": |
||
3127 | i = 2; |
||
3128 | break; |
||
3129 | case "textBoxSerial2_val1": |
||
3130 | i = 3; |
||
3131 | break; |
||
3132 | case "textBoxSerial2_val2": |
||
3133 | i = 4; |
||
3134 | break; |
||
3135 | case "textBoxSerial2_val3": |
||
3136 | i = 5; |
||
3137 | break; |
||
3138 | case "textBoxSerial3_val1": |
||
3139 | i = 6; |
||
3140 | break; |
||
3141 | case "textBoxSerial3_val2": |
||
3142 | i = 7; |
||
3143 | break; |
||
3144 | case "textBoxSerial3_val3": |
||
3145 | i = 8; |
||
3146 | break; |
||
3147 | case "textBoxSerial4_val1": |
||
3148 | i = 9; |
||
3149 | break; |
||
3150 | case "textBoxSerial4_val2": |
||
3151 | i = 10; |
||
3152 | break; |
||
3153 | case "textBoxSerial4_val3": |
||
3154 | i = 11; |
||
3155 | break; |
||
3156 | } |
||
3157 | if (i > -1) |
||
3158 | serChan_sub[i] = Convert.ToInt16(((TextBox)sender).Text + e.Key.ToString()); |
||
3159 | } |
||
3160 | } |
||
3161 | |||
3162 | #endregion serial channels |
||
2315 | - | 3163 | #region WP |
2312 | - | 3164 | void _readWPLFile() |
3165 | { |
||
3166 | Microsoft.Win32.OpenFileDialog fd = new Microsoft.Win32.OpenFileDialog(); |
||
3167 | fd.Filter = "Waypointlists | *.wpl"; |
||
3168 | fd.Multiselect = false; |
||
3169 | if (fd.ShowDialog().Value) |
||
3170 | { |
||
3171 | string file = fd.SafeFileName; |
||
3172 | IniFile ini = new IniFile(fd.SafeFileName); |
||
3173 | ini.path = fd.FileName; |
||
3174 | |||
3175 | try |
||
3176 | { |
||
3177 | string sVal = ini.IniReadValue("General", "FileVersion"); |
||
3178 | if (sVal == "") |
||
3179 | MessageBox.Show("The file has no version declared - can't go on...", "", MessageBoxButton.OK, MessageBoxImage.Information); |
||
3180 | else |
||
3181 | { |
||
3182 | if (Convert.ToInt16(sVal) < 3) |
||
3183 | MessageBox.Show("The file version is not supported - can't go on...", "", MessageBoxButton.OK, MessageBoxImage.Information); |
||
3184 | else |
||
3185 | { |
||
3186 | sVal = ini.IniReadValue("General", "NumberOfWaypoints"); |
||
3187 | if (sVal == "") |
||
3188 | MessageBox.Show("The file has no number of waypoints declared - can't go on...", "", MessageBoxButton.OK, MessageBoxImage.Information); |
||
3189 | else |
||
3190 | { |
||
3191 | int wpnum = Convert.ToInt16(sVal); |
||
3192 | string wp; |
||
3193 | int i; |
||
2313 | - | 3194 | NumberFormatInfo nfi = new NumberFormatInfo(); |
3195 | nfi.NumberDecimalSeparator = "."; |
||
2312 | - | 3196 | dtWaypoints.Rows.Clear(); |
2368 | - | 3197 | _wpEdit = -1;_wpIndex = -1; |
2327 | - | 3198 | _clearMapMarkers(typeof(CustomMarkerWP)); |
2363 | - | 3199 | _clearMapMarkers(typeof(CustomMarkerWPActive)); |
2328 | - | 3200 | wpList.Clear(); |
3201 | if (mRouteWP != null) |
||
3202 | MainMap.Markers.Remove(mRouteWP); |
||
2363 | - | 3203 | //if (wpActiveMarker != null) |
3204 | // MainMap.Markers.Remove(wpActiveMarker); |
||
2328 | - | 3205 | Dispatcher.Invoke(() => lblWPRouteDistance.Content = "0 m"); |
3206 | |||
2312 | - | 3207 | for (int k = 1; k <= wpnum; k++) |
3208 | { |
||
3209 | DataRow dr = dtWaypoints.NewRow(); |
||
3210 | dr.ItemArray = new object[16]; |
||
3211 | object[] o = new object[16]; |
||
3212 | i = 0; |
||
3213 | wp = "Point" + k.ToString(); |
||
3214 | o[i] = k; |
||
3215 | i++; |
||
3216 | sVal = ini.IniReadValue(wp, "Type"); |
||
3217 | if (sVal != "") |
||
2315 | - | 3218 | o[i] = Convert.ToInt16(sVal) - 1; |
2312 | - | 3219 | i++; |
3220 | sVal = ini.IniReadValue(wp, "Prefix"); |
||
3221 | if (sVal != "") |
||
2350 | - | 3222 | o[i] = sVal + k.ToString(); |
3223 | // o[i] = sVal == "0" ? "!" + k.ToString() : sVal + k.ToString(); |
||
2312 | - | 3224 | i++; |
2313 | - | 3225 | sVal = ini.IniReadValue(wp, "Latitude"); |
2312 | - | 3226 | if (sVal != "") |
2313 | - | 3227 | o[i] = Convert.ToDouble(sVal, nfi); |
2312 | - | 3228 | i++; |
2313 | - | 3229 | sVal = ini.IniReadValue(wp, "Longitude"); |
2312 | - | 3230 | if (sVal != "") |
2313 | - | 3231 | o[i] = Convert.ToDouble(sVal, nfi); |
2312 | - | 3232 | i++; |
3233 | sVal = ini.IniReadValue(wp, "Altitude"); |
||
3234 | if (sVal != "") |
||
2313 | - | 3235 | o[i] = Convert.ToDouble(sVal, nfi); |
2312 | - | 3236 | i++; |
3237 | sVal = ini.IniReadValue(wp, "Heading"); |
||
3238 | if (sVal != "") |
||
3239 | o[i] = Convert.ToInt16(sVal); |
||
3240 | i++; |
||
3241 | sVal = ini.IniReadValue(wp, "Speed"); |
||
3242 | if (sVal != "") |
||
2315 | - | 3243 | o[i] = Convert.ToInt16(sVal); |
2312 | - | 3244 | i++; |
3245 | sVal = ini.IniReadValue(wp, "ClimbRate"); |
||
3246 | if (sVal != "") |
||
3247 | o[i] = Convert.ToInt16(sVal); |
||
3248 | i++; |
||
3249 | sVal = ini.IniReadValue(wp, "Radius"); |
||
3250 | if (sVal != "") |
||
3251 | o[i] = Convert.ToInt16(sVal); |
||
3252 | i++; |
||
3253 | sVal = ini.IniReadValue(wp, "DelayTime"); |
||
3254 | if (sVal != "") |
||
3255 | o[i] = Convert.ToInt16(sVal); |
||
3256 | i++; |
||
3257 | sVal = ini.IniReadValue(wp, "AutoTrigger"); |
||
3258 | if (sVal != "") |
||
3259 | o[i] = Convert.ToInt16(sVal); ; |
||
3260 | i++; |
||
3261 | sVal = ini.IniReadValue(wp, "CAM-Nick"); |
||
3262 | if (sVal != "") |
||
2313 | - | 3263 | o[i] = Convert.ToInt16(sVal); |
2312 | - | 3264 | i++; |
3265 | o[i] = 0; |
||
3266 | i++; |
||
3267 | sVal = ini.IniReadValue(wp, "WP_Event_Channel_Value"); |
||
3268 | if (sVal != "") |
||
3269 | o[i] = Convert.ToInt16(sVal); |
||
3270 | i++; |
||
3271 | o[i] = "New"; |
||
3272 | |||
3273 | dr.ItemArray = o; |
||
3274 | dtWaypoints.Rows.Add(dr); |
||
2363 | - | 3275 | _createWP(new PointLatLng((double)o[3], (double)o[4]), (string)dr[2], (int)o[1]); |
2315 | - | 3276 | |
2312 | - | 3277 | Dispatcher.Invoke(() => lblWPIndex.Content = k.ToString()); |
3278 | Dispatcher.Invoke(() => lblWPCount.Content = k.ToString()); |
||
3279 | Dispatcher.Invoke(() => dgvWP.Items.Refresh()); |
||
3280 | Thread.Sleep(10); |
||
3281 | } |
||
2359 | - | 3282 | _routeUpdate(); |
2312 | - | 3283 | } |
3284 | } |
||
3285 | } |
||
3286 | |||
3287 | } |
||
3288 | catch (Exception e) |
||
3289 | { |
||
3290 | |||
3291 | MessageBox.Show("Error parsing wpl-file!" + Environment.NewLine + e.Message, "Read wpl-file", MessageBoxButton.OK, MessageBoxImage.Error); |
||
3292 | } |
||
3293 | |||
3294 | } |
||
3295 | } |
||
2350 | - | 3296 | void _saveWPLFile() |
3297 | { |
||
3298 | if (dtWaypoints.Rows.Count > 0) |
||
3299 | { |
||
3300 | Microsoft.Win32.SaveFileDialog fd = new Microsoft.Win32.SaveFileDialog(); |
||
3301 | fd.Filter = "Waypointlists | *.wpl"; |
||
3302 | fd.AddExtension = true; |
||
3303 | if (fd.ShowDialog().Value) |
||
3304 | { |
||
3305 | string file = fd.SafeFileName; |
||
3306 | IniFile ini = new IniFile(fd.SafeFileName); |
||
3307 | ini.path = fd.FileName; |
||
3308 | NumberFormatInfo nfi = new NumberFormatInfo(); |
||
3309 | nfi.NumberDecimalSeparator = "."; |
||
3310 | |||
3311 | try |
||
3312 | { |
||
3313 | ini.IniWriteValue("General", "FileVersion", "3"); |
||
3314 | ini.IniWriteValue("General", "NumberOfWaypoints", dtWaypoints.Rows.Count.ToString()); |
||
3315 | ini.IniWriteValue("General", "Mapfile", ""); |
||
3316 | for(int i = 1; i<=dtWaypoints.Rows.Count; i++) |
||
3317 | { |
||
3318 | ini.IniWriteValue("Point" + i.ToString(), "Latitude", ((double)(dtWaypoints.Rows[i-1][3])).ToString(nfi)); |
||
3319 | ini.IniWriteValue("Point" + i.ToString(), "Longitude", ((double)(dtWaypoints.Rows[i - 1][4])).ToString(nfi)); |
||
3320 | ini.IniWriteValue("Point" + i.ToString(), "Radius", dtWaypoints.Rows[i - 1][9].ToString()); |
||
3321 | ini.IniWriteValue("Point" + i.ToString(), "Altitude", dtWaypoints.Rows[i - 1][5].ToString()); |
||
3322 | ini.IniWriteValue("Point" + i.ToString(), "ClimbRate", dtWaypoints.Rows[i - 1][8].ToString()); |
||
3323 | ini.IniWriteValue("Point" + i.ToString(), "DelayTime", dtWaypoints.Rows[i - 1][10].ToString()); |
||
3324 | ini.IniWriteValue("Point" + i.ToString(), "WP_Event_Channel_Value", dtWaypoints.Rows[i - 1][14].ToString()); |
||
3325 | ini.IniWriteValue("Point" + i.ToString(), "Heading", dtWaypoints.Rows[i - 1][6].ToString()); |
||
3326 | ini.IniWriteValue("Point" + i.ToString(), "Speed", dtWaypoints.Rows[i - 1][7].ToString()); |
||
3327 | ini.IniWriteValue("Point" + i.ToString(), "CAM-Nick", dtWaypoints.Rows[i - 1][12].ToString()); |
||
3328 | ini.IniWriteValue("Point" + i.ToString(), "Type", ((int)dtWaypoints.Rows[i - 1][1]+1).ToString()); |
||
3329 | ini.IniWriteValue("Point" + i.ToString(), "Prefix", dtWaypoints.Rows[i - 1][2].ToString().Substring(0, 1)); // == "!" ? "0" : dtWaypoints.Rows[i - 1][2].ToString().Substring(0, 1)); |
||
3330 | ini.IniWriteValue("Point" + i.ToString(), "AutoTrigger", dtWaypoints.Rows[i - 1][11].ToString()); |
||
3331 | } |
||
3332 | MessageBox.Show(dtWaypoints.Rows.Count.ToString() + " points saved to " + file, "Waypointlist saved", MessageBoxButton.OK, MessageBoxImage.Information); |
||
3333 | } |
||
3334 | catch { } |
||
3335 | } |
||
3336 | } |
||
3337 | else |
||
3338 | MessageBox.Show("Nothing to save..."); |
||
3339 | } |
||
3340 | private void btnSaveWPLFile_Click(object sender, RoutedEventArgs e) |
||
3341 | { |
||
3342 | _saveWPLFile(); |
||
3343 | } |
||
3344 | /// <summary> |
||
3345 | /// set the selected color for the route |
||
3346 | /// </summary> |
||
3347 | /// <param name="color"></param> |
||
3348 | /// <returns></returns> |
||
2328 | - | 3349 | Brush _getBrush(string color) |
3350 | { |
||
3351 | switch (color) |
||
3352 | { |
||
3353 | case "red": |
||
3354 | return Brushes.Red; |
||
3355 | case "green": |
||
3356 | return Brushes.Lime; |
||
3357 | case "blue": |
||
3358 | return Brushes.Aqua; |
||
3359 | case "pink": |
||
3360 | return Brushes.Magenta; |
||
3361 | case "yellow": |
||
3362 | return Brushes.Yellow; |
||
3363 | default: |
||
3364 | return Brushes.Magenta; |
||
3365 | } |
||
3366 | } |
||
2359 | - | 3367 | void _routeUpdate() |
3368 | { |
||
3369 | Dispatcher.Invoke(() => |
||
3370 | { |
||
3371 | if (comboBoxRouteColor.SelectionBoxItem != null) |
||
3372 | { |
||
3373 | string s = comboBoxRouteColor.SelectionBoxItem.ToString(); |
||
3374 | mRouteWP = new GMapRoute(wpList, _getBrush(s)); |
||
3375 | } |
||
3376 | else |
||
3377 | mRouteWP = new GMapRoute(wpList, null); |
||
3378 | |||
3379 | if (_bShowWPRoute) |
||
2368 | - | 3380 | MainMap.Markers.Add(mRouteWP); |
2359 | - | 3381 | }); |
3382 | |||
3383 | MapRoute mr = new MapRoute(wpList, "WPList"); |
||
3384 | Dispatcher.Invoke(() => lblWPRouteDistance.Content = (mr.Distance * 1000).ToString("0 m")); |
||
3385 | } |
||
2363 | - | 3386 | GMapMarker _createWP(PointLatLng p, string name, int type) |
3387 | { |
||
3388 | GMapMarker wpMarker = new GMapMarker(p); |
||
3389 | wpMarker.Shape = new CustomMarkerWP(this, wpMarker, name, type); |
||
3390 | wpMarker.Offset = new System.Windows.Point(-11.5, -11.5); |
||
3391 | wpMarker.ZIndex = 100; |
||
3392 | _setMarkerColor(wpMarker, type); |
||
3393 | Dispatcher.Invoke(() => MainMap.Markers.Add(wpMarker)); |
||
2372 | - | 3394 | if (type == 0 || type == 3) |
2363 | - | 3395 | wpList.Add(p); |
3396 | return wpMarker; |
||
3397 | } |
||
2315 | - | 3398 | void _setMarkerColor(GMapMarker wpMarker,int iType) |
3399 | { |
||
2369 | - | 3400 | if(wpMarker != null) |
2315 | - | 3401 | Dispatcher.Invoke(() => |
3402 | { |
||
3403 | switch (iType) |
||
3404 | { |
||
3405 | case 0: |
||
3406 | if (comboBoxWPColor.SelectionBoxItem != null) |
||
3407 | { |
||
3408 | string s = comboBoxWPColor.SelectionBoxItem.ToString(); |
||
3409 | ((CustomMarkerWP)(wpMarker.Shape)).setColor(s); |
||
3410 | } |
||
3411 | else |
||
2372 | - | 3412 | ((CustomMarkerWP)(wpMarker.Shape)).setColor("green"); |
2315 | - | 3413 | break; |
3414 | case 1: |
||
3415 | if (comboBoxPOIColor.SelectionBoxItem != null) |
||
3416 | { |
||
3417 | string s = comboBoxPOIColor.SelectionBoxItem.ToString(); |
||
3418 | ((CustomMarkerWP)(wpMarker.Shape)).setColor(s); |
||
3419 | } |
||
3420 | else |
||
2372 | - | 3421 | ((CustomMarkerWP)(wpMarker.Shape)).setColor("pink"); |
2315 | - | 3422 | break; |
3423 | case 2: |
||
3424 | if (comboBoxFSColor.SelectionBoxItem != null) |
||
3425 | { |
||
3426 | string s = comboBoxFSColor.SelectionBoxItem.ToString(); |
||
3427 | ((CustomMarkerWP)(wpMarker.Shape)).setColor(s); |
||
3428 | } |
||
3429 | else |
||
3430 | ((CustomMarkerWP)(wpMarker.Shape)).setColor("red"); |
||
3431 | break; |
||
2372 | - | 3432 | case 3: |
3433 | if (comboBoxLandingColor.SelectionBoxItem != null) |
||
3434 | { |
||
3435 | string s = comboBoxLandingColor.SelectionBoxItem.ToString(); |
||
3436 | ((CustomMarkerWP)(wpMarker.Shape)).setColor(s); |
||
3437 | } |
||
3438 | else |
||
3439 | ((CustomMarkerWP)(wpMarker.Shape)).setColor("blue"); |
||
3440 | break; |
||
2315 | - | 3441 | default: |
3442 | ((CustomMarkerWP)(wpMarker.Shape)).setColor("red"); |
||
3443 | break; |
||
3444 | } |
||
3445 | }); |
||
2312 | - | 3446 | |
2315 | - | 3447 | } |
3448 | private void comboBoxWPColor_DropDownClosed(object sender, EventArgs e) |
||
2312 | - | 3449 | { |
2372 | - | 3450 | _MarkerColorSelection(sender, 0); |
2312 | - | 3451 | } |
2315 | - | 3452 | private void comboBoxPOIColor_DropDownClosed(object sender, EventArgs e) |
3453 | { |
||
2372 | - | 3454 | _MarkerColorSelection(sender, 1); |
2315 | - | 3455 | } |
3456 | private void comboBoxFSColor_DropDownClosed(object sender, EventArgs e) |
||
2287 | - | 3457 | { |
2372 | - | 3458 | _MarkerColorSelection(sender, 2); |
3459 | } |
||
3460 | private void comboBoxLandingColor_DropDownClosed(object sender, EventArgs e) |
||
3461 | { |
||
3462 | _MarkerColorSelection(sender,3); |
||
3463 | } |
||
3464 | void _MarkerColorSelection(object sender,int type) |
||
3465 | { |
||
2315 | - | 3466 | Dispatcher.Invoke(() => |
3467 | { |
||
2372 | - | 3468 | if (((ComboBox)sender).SelectionBoxItem != null) |
2315 | - | 3469 | { |
3470 | for (int k = 0; k < MainMap.Markers.Count; k++) |
||
3471 | { |
||
3472 | GMapMarker p = MainMap.Markers[k]; |
||
2372 | - | 3473 | if (p.Shape != null && p.Shape.GetType() == typeof(CustomMarkerWP)) |
2315 | - | 3474 | { |
2372 | - | 3475 | if (((CustomMarkerWP)p.Shape).WPType == type) |
2315 | - | 3476 | { |
2372 | - | 3477 | string s = ((ComboBox)sender).SelectionBoxItem.ToString(); |
2315 | - | 3478 | ((CustomMarkerWP)(p.Shape)).setColor(s); |
3479 | } |
||
3480 | } |
||
3481 | } |
||
3482 | } |
||
3483 | }); |
||
2287 | - | 3484 | } |
2318 | - | 3485 | private void comboBoxCopterColor_DropDownClosed(object sender, EventArgs e) |
3486 | { |
||
3487 | Dispatcher.Invoke(() => { |
||
3488 | if (comboBoxCopterColor.SelectionBoxItem != null) |
||
3489 | { |
||
3490 | string s = comboBoxCopterColor.SelectionBoxItem.ToString(); |
||
3491 | ((CustomMarkerCopter)(copter.Shape)).setColor(s); |
||
3492 | } |
||
3493 | else |
||
3494 | ((CustomMarkerCopter)(copter.Shape)).setColor("red"); |
||
3495 | }); |
||
3496 | } |
||
2328 | - | 3497 | private void comboBoxRouteColor_DropDownClosed(object sender, EventArgs e) |
3498 | { |
||
3499 | Dispatcher.Invoke(() => |
||
3500 | { |
||
3501 | if (comboBoxRouteColor.SelectionBoxItem != null) |
||
3502 | { |
||
3503 | string s = comboBoxRouteColor.SelectionBoxItem.ToString(); |
||
3504 | MainMap.Markers.Remove(mRouteWP); |
||
3505 | mRouteWP = new GMapRoute(wpList, _getBrush(s)); |
||
3506 | if (_bShowWPRoute) |
||
3507 | MainMap.Markers.Add(mRouteWP); |
||
3508 | } |
||
3509 | }); |
||
3510 | } |
||
3511 | private void checkBoxShowWPRoute_Click(object sender, RoutedEventArgs e) |
||
3512 | { |
||
3513 | _bShowWPRoute = (bool)checkBoxShowWPRoute.IsChecked; |
||
3514 | if (_bShowWPRoute) |
||
3515 | { |
||
3516 | if (mRouteWP != null) |
||
3517 | MainMap.Markers.Add(mRouteWP); |
||
3518 | } |
||
3519 | else |
||
3520 | { |
||
3521 | if (mRouteWP != null) |
||
3522 | MainMap.Markers.Remove(mRouteWP); |
||
3523 | } |
||
3524 | } |
||
2315 | - | 3525 | private void btnLoadWPLFile_Click(object sender, RoutedEventArgs e) |
2287 | - | 3526 | { |
2315 | - | 3527 | _readWPLFile(); |
2287 | - | 3528 | } |
2335 | - | 3529 | private void btnClearWPList_Click(object sender, RoutedEventArgs e) |
3530 | { |
||
3531 | _clearMapMarkers(typeof(CustomMarkerWP)); |
||
2347 | - | 3532 | _clearMapMarkers(typeof(CustomMarkerWPActive)); |
2335 | - | 3533 | wpList.Clear(); |
3534 | if (mRouteWP != null) |
||
3535 | MainMap.Markers.Remove(mRouteWP); |
||
2347 | - | 3536 | //if (wpActiveMarker != null) |
3537 | // MainMap.Markers.Remove(wpActiveMarker); |
||
2335 | - | 3538 | dtWaypoints.Rows.Clear(); |
2356 | - | 3539 | _wpEdit = -1; |
2368 | - | 3540 | _wpIndex = -1; |
2335 | - | 3541 | Dispatcher.Invoke(() => dgvWP.Items.Refresh()); |
3542 | Dispatcher.Invoke(() => lblWPIndex.Content = 0); |
||
3543 | Dispatcher.Invoke(() => lblWPCount.Content = 0); |
||
3544 | Dispatcher.Invoke(() => lblWPRouteDistance.Content = "0 m"); |
||
3545 | } |
||
2340 | - | 3546 | private void btnClearCopterList_Click(object sender, RoutedEventArgs e) |
3547 | { |
||
3548 | Thread t = new Thread(new ThreadStart(clearCopterWPList)); |
||
3549 | t.Start(); |
||
3550 | } |
||
2355 | - | 3551 | private void btnSendActiveWP_Click(object sender, RoutedEventArgs e) |
2340 | - | 3552 | { |
3553 | if (dgvWP.SelectedIndex > -1 && dgvWP.SelectedIndex < dtWaypoints.Rows.Count) |
||
3554 | { |
||
2372 | - | 3555 | if (_wpCount > 0) |
3556 | _sendWayPoint(dtWaypoints.Rows[dgvWP.SelectedIndex], -1, 's'); |
||
3557 | else |
||
3558 | _sendWayPoint(dtWaypoints.Rows[dgvWP.SelectedIndex], 1, 's'); |
||
2363 | - | 3559 | |
2372 | - | 3560 | //int index = dgvWP.SelectedIndex; |
3561 | //Thread t = new Thread(() => _sendWPList(index)); |
||
3562 | //t.Start(); |
||
2354 | - | 3563 | |
3564 | Dispatcher.Invoke(() => { |
||
3565 | DataGridRow row; |
||
2368 | - | 3566 | if (_wpEdit > -1 && _wpEdit < dgvWP.ItemContainerGenerator.Items.Count) |
2354 | - | 3567 | { |
2368 | - | 3568 | row = (DataGridRow)dgvWP.ItemContainerGenerator.ContainerFromIndex(_wpEdit); |
2354 | - | 3569 | row.Background = new SolidColorBrush(Colors.Transparent); |
3570 | row.BorderBrush = new SolidColorBrush(Colors.Transparent); |
||
3571 | row.BorderThickness = new Thickness(0); |
||
3572 | } |
||
2368 | - | 3573 | _wpEdit = dgvWP.SelectedIndex; |
3574 | row = (DataGridRow)dgvWP.ItemContainerGenerator.ContainerFromIndex(_wpEdit); |
||
2366 | - | 3575 | row.Background = new SolidColorBrush(Color.FromArgb(80, 0, 255, 100)); |
3576 | row.BorderBrush = new SolidColorBrush(Colors.SpringGreen); |
||
2354 | - | 3577 | row.BorderThickness = new Thickness(2); |
2355 | - | 3578 | dgvWP.UpdateLayout(); |
2354 | - | 3579 | }); |
2340 | - | 3580 | } |
3581 | } |
||
2355 | - | 3582 | private void dgvWP_MouseUp(object sender, MouseButtonEventArgs e) |
3583 | { |
||
2359 | - | 3584 | _dgvWPselectEditRow(); |
3585 | } |
||
3586 | private void dgvWP_MouseDoubleClick(object sender, MouseButtonEventArgs e) |
||
3587 | { |
||
3588 | } |
||
3589 | void _dgvWPselectEditRow() |
||
3590 | { |
||
2355 | - | 3591 | if (dgvWP.SelectedIndex > -1 && dgvWP.SelectedIndex < dtWaypoints.Rows.Count) |
3592 | { |
||
2368 | - | 3593 | Dispatcher.Invoke(() => { |
2355 | - | 3594 | DataGridRow row; |
2368 | - | 3595 | if (_wpEdit > -1 && _wpEdit < dgvWP.ItemContainerGenerator.Items.Count) |
2355 | - | 3596 | { |
3597 | row = (DataGridRow)dgvWP.ItemContainerGenerator.ContainerFromIndex(_wpEdit); |
||
3598 | row.Background = new SolidColorBrush(Colors.Transparent); |
||
3599 | row.BorderBrush = new SolidColorBrush(Colors.Transparent); |
||
3600 | row.BorderThickness = new Thickness(0); |
||
3601 | } |
||
3602 | _wpEdit = dgvWP.SelectedIndex; |
||
3603 | row = (DataGridRow)dgvWP.ItemContainerGenerator.ContainerFromIndex(_wpEdit); |
||
3604 | row.Background = new SolidColorBrush(Color.FromArgb(80, 0, 100, 255)); |
||
3605 | row.BorderBrush = new SolidColorBrush(Colors.Aqua); |
||
3606 | row.BorderThickness = new Thickness(2); |
||
3607 | dgvWP.UpdateLayout(); |
||
2340 | - | 3608 | |
2355 | - | 3609 | _setWPEditFields(_wpEdit); |
3610 | }); |
||
3611 | } |
||
3612 | } |
||
3613 | void _setWPEditFields(int index) |
||
3614 | { |
||
3615 | int iVal; |
||
3616 | cbWPEditType.SelectedIndex = (int)dtWaypoints.Rows[index][1]; |
||
3617 | tbWPEditPrefix.Text = dtWaypoints.Rows[index][2].ToString().Substring(0,1); |
||
3618 | tbWPEditLat.Text = dtWaypoints.Rows[index][3].ToString(); |
||
3619 | tbWPEditLon.Text = dtWaypoints.Rows[index][4].ToString(); |
||
3620 | tbWPEditAlt.Text = dtWaypoints.Rows[index][5].ToString(); |
||
3621 | iVal = Convert.ToInt16(dtWaypoints.Rows[index][6]); |
||
3622 | if (iVal == 0) |
||
3623 | { |
||
3624 | cbWPEditHeading.SelectedIndex = 0; |
||
3625 | tbWPEditHeading.Text = " - - -"; |
||
3626 | tbWPEditHeading.IsReadOnly = true; |
||
3627 | } |
||
3628 | if (iVal > 0 && iVal < 360) |
||
3629 | { |
||
3630 | cbWPEditHeading.SelectedIndex = 2; |
||
3631 | tbWPEditHeading.Text = iVal.ToString(); |
||
3632 | tbWPEditHeading.IsReadOnly = false; |
||
3633 | } |
||
3634 | if (iVal < 0) |
||
3635 | { |
||
3636 | cbWPEditHeading.SelectedIndex = 1; |
||
3637 | tbWPEditHeading.Text = (Math.Abs(iVal).ToString()); |
||
3638 | tbWPEditHeading.IsReadOnly = false; |
||
3639 | } |
||
3640 | iVal = Convert.ToInt16(dtWaypoints.Rows[index][7]); |
||
3641 | if (iVal == 0) |
||
3642 | { |
||
3643 | cbWPEditSpeed.SelectedIndex = 0; |
||
3644 | tbWPEditSpeed.Text = "MAX"; |
||
3645 | tbWPEditSpeed.IsReadOnly = true; |
||
3646 | } |
||
3647 | if (iVal > 0 && iVal < 248) |
||
3648 | { |
||
3649 | cbWPEditSpeed.SelectedIndex = 1; |
||
3650 | tbWPEditSpeed.Text = ((double)iVal * 0.1).ToString(); |
||
3651 | tbWPEditSpeed.IsReadOnly = false; |
||
3652 | } |
||
3653 | if (iVal > 247) |
||
3654 | { |
||
3655 | cbWPEditSpeed.SelectedIndex = 256 - iVal + 1; |
||
3656 | tbWPEditSpeed.Text = ""; |
||
3657 | tbWPEditSpeed.IsReadOnly = true; |
||
3658 | } |
||
3659 | iVal = Convert.ToInt16(dtWaypoints.Rows[index][8]); |
||
3660 | if (iVal == 255) |
||
3661 | { |
||
3662 | cbWPEditClimbrate.SelectedIndex = 0; |
||
3663 | tbWPEditClimbrate.Text = "AUTO"; |
||
3664 | tbWPEditClimbrate.IsReadOnly = true; |
||
3665 | } |
||
3666 | else |
||
3667 | { |
||
3668 | cbWPEditClimbrate.SelectedIndex = 1; |
||
3669 | tbWPEditClimbrate.Text = (System.Convert.ToDouble(iVal) / 10).ToString("0.0"); |
||
3670 | tbWPEditClimbrate.IsReadOnly = false; |
||
3671 | } |
||
3672 | iVal = Convert.ToInt16(dtWaypoints.Rows[index][9]); |
||
3673 | tbWPEditRadius.Text = iVal.ToString(); |
||
3674 | iVal = Convert.ToInt16(dtWaypoints.Rows[index][10]); |
||
3675 | tbWPEditHoldtime.Text = iVal.ToString(); |
||
3676 | iVal = Convert.ToInt16(dtWaypoints.Rows[index][11]); |
||
3677 | tbWPEditAutoTrigger.Text = iVal.ToString(); |
||
3678 | iVal = Convert.ToInt16(dtWaypoints.Rows[index][12]); |
||
3679 | if (iVal == 0) |
||
3680 | { |
||
3681 | cbWPEditCamAngle.SelectedIndex = 0; |
||
3682 | tbWPEditCamAngle.Text = " - - - "; |
||
3683 | tbWPEditCamAngle.IsReadOnly = true; |
||
3684 | } |
||
3685 | if (iVal < 0 | iVal == 255) |
||
3686 | { |
||
3687 | cbWPEditCamAngle.SelectedIndex = 1; |
||
3688 | tbWPEditCamAngle.Text = "AUTO"; |
||
3689 | tbWPEditCamAngle.IsReadOnly = true; |
||
3690 | } |
||
3691 | if (iVal > 0 & iVal < 255) |
||
3692 | { |
||
3693 | cbWPEditCamAngle.SelectedIndex = 2; |
||
3694 | tbWPEditCamAngle.Text = iVal.ToString(); |
||
3695 | tbWPEditCamAngle.IsReadOnly = false; |
||
3696 | } |
||
3697 | iVal = Convert.ToInt16(dtWaypoints.Rows[index][14]); |
||
3698 | tbWPEditOut1.Text = iVal.ToString(); |
||
3699 | |||
3700 | } |
||
3701 | |||
2361 | - | 3702 | private void btnEditWPSave_Click(object sender, RoutedEventArgs e) |
3703 | { |
||
2363 | - | 3704 | if(dgvWP.SelectedIndex > -1 && dgvWP.SelectedIndex < dtWaypoints.Rows.Count) |
3705 | { |
||
2369 | - | 3706 | string oldName = (string)dtWaypoints.Rows[dgvWP.SelectedIndex][2]; |
2372 | - | 3707 | int oldType = (int)dtWaypoints.Rows[dgvWP.SelectedIndex][1]; |
3708 | PointLatLng pOld = new PointLatLng((double)dtWaypoints.Rows[dgvWP.SelectedIndex][3], (double)dtWaypoints.Rows[dgvWP.SelectedIndex][4]); |
||
3709 | int i = wpList.IndexOf(pOld); |
||
2363 | - | 3710 | dtWaypoints.Rows[dgvWP.SelectedIndex][1] = cbWPEditType.SelectedIndex; |
3711 | dtWaypoints.Rows[dgvWP.SelectedIndex][2] = tbWPEditPrefix.Text + (dgvWP.SelectedIndex + 1).ToString(); |
||
3712 | dtWaypoints.Rows[dgvWP.SelectedIndex][3] = Convert.ToDouble(tbWPEditLat.Text.Replace('.', ',')); |
||
3713 | dtWaypoints.Rows[dgvWP.SelectedIndex][4] = Convert.ToDouble(tbWPEditLon.Text.Replace('.', ',')); |
||
2372 | - | 3714 | if (i > -1) |
3715 | { |
||
3716 | if((int)dtWaypoints.Rows[dgvWP.SelectedIndex][1] == 0 || (int)dtWaypoints.Rows[dgvWP.SelectedIndex][1] == 3) |
||
3717 | wpList[i] = (new PointLatLng((double)dtWaypoints.Rows[dgvWP.SelectedIndex][3], (double)dtWaypoints.Rows[dgvWP.SelectedIndex][4])); |
||
3718 | else |
||
3719 | wpList.Remove(pOld); |
||
3720 | } |
||
3721 | else |
||
3722 | { |
||
3723 | if ((int)dtWaypoints.Rows[dgvWP.SelectedIndex][1] == 0 || (int)dtWaypoints.Rows[dgvWP.SelectedIndex][1] == 3) |
||
3724 | { |
||
3725 | int found = 0; |
||
3726 | for (int k = 0; k < dgvWP.SelectedIndex; k++) |
||
3727 | if ((int)dtWaypoints.Rows[k][1] == 0) |
||
3728 | found++; |
||
3729 | wpList.Insert(found, new PointLatLng((double)dtWaypoints.Rows[dgvWP.SelectedIndex][3], (double)dtWaypoints.Rows[dgvWP.SelectedIndex][4])); |
||
3730 | } |
||
3731 | } |
||
2363 | - | 3732 | dtWaypoints.Rows[dgvWP.SelectedIndex][5] = tbWPEditAlt.Text; |
3733 | switch (cbWPEditHeading.SelectedIndex) |
||
3734 | { |
||
3735 | case 0: |
||
3736 | dtWaypoints.Rows[dgvWP.SelectedIndex][6] = "0"; |
||
3737 | break; |
||
3738 | case 1: |
||
3739 | dtWaypoints.Rows[dgvWP.SelectedIndex][6] = "-" + tbWPEditHeading.Text; |
||
3740 | break; |
||
3741 | case 2: |
||
3742 | dtWaypoints.Rows[dgvWP.SelectedIndex][6] = tbWPEditHeading.Text; |
||
3743 | break; |
||
3744 | } |
||
3745 | switch (cbWPEditSpeed.SelectedIndex) |
||
3746 | { |
||
3747 | case 0: |
||
3748 | dtWaypoints.Rows[dgvWP.SelectedIndex][7] = "0"; |
||
3749 | break; |
||
3750 | case 1: |
||
3751 | dtWaypoints.Rows[dgvWP.SelectedIndex][7] = (System.Convert.ToDouble(tbWPEditSpeed.Text.Replace('.', ',')) * 10).ToString("0"); |
||
3752 | break; |
||
3753 | case 2: |
||
3754 | dtWaypoints.Rows[dgvWP.SelectedIndex][7] = (256 - Convert.ToInt16(tbWPEditSpeed.Text)).ToString(); |
||
3755 | break; |
||
3756 | } |
||
3757 | switch (cbWPEditClimbrate.SelectedIndex) |
||
3758 | { |
||
3759 | case 0: |
||
3760 | dtWaypoints.Rows[dgvWP.SelectedIndex][8] = "255"; |
||
3761 | break; |
||
3762 | case 1: |
||
3763 | dtWaypoints.Rows[dgvWP.SelectedIndex][8] = (System.Convert.ToDouble(tbWPEditClimbrate.Text.Replace('.',',')) * 10).ToString("0"); |
||
3764 | break; |
||
3765 | } |
||
3766 | dtWaypoints.Rows[dgvWP.SelectedIndex][9] = tbWPEditRadius.Text; |
||
3767 | dtWaypoints.Rows[dgvWP.SelectedIndex][10] = tbWPEditHoldtime.Text; |
||
3768 | dtWaypoints.Rows[dgvWP.SelectedIndex][11] = tbWPEditAutoTrigger.Text; |
||
3769 | switch (cbWPEditCamAngle.SelectedIndex) |
||
3770 | { |
||
3771 | case 0: |
||
3772 | dtWaypoints.Rows[dgvWP.SelectedIndex][12] = "0"; |
||
3773 | break; |
||
3774 | case 1: |
||
3775 | dtWaypoints.Rows[dgvWP.SelectedIndex][12] = "255"; |
||
3776 | break; |
||
3777 | case 2: |
||
3778 | dtWaypoints.Rows[dgvWP.SelectedIndex][12] = tbWPEditCamAngle.Text; |
||
3779 | break; |
||
3780 | } |
||
3781 | dtWaypoints.Rows[dgvWP.SelectedIndex][14] = tbWPEditOut1.Text; |
||
2361 | - | 3782 | |
2369 | - | 3783 | // _clearMapMarkers(typeof(CustomMarkerWP)); |
3784 | _repositionWPMarker(new PointLatLng((double)dtWaypoints.Rows[dgvWP.SelectedIndex][3], (double)dtWaypoints.Rows[dgvWP.SelectedIndex][4]),oldName); |
||
3785 | _renameWPMarker(oldName, (string)dtWaypoints.Rows[dgvWP.SelectedIndex][2]); |
||
2363 | - | 3786 | _clearMapMarkers(typeof(CustomMarkerWPActive)); |
2369 | - | 3787 | _setMarkerColor(_findWPMarker((string)dtWaypoints.Rows[dgvWP.SelectedIndex][2]), (int)dtWaypoints.Rows[dgvWP.SelectedIndex][1]); |
2372 | - | 3788 | _WPMarkerSetType((string)dtWaypoints.Rows[dgvWP.SelectedIndex][2], (int)dtWaypoints.Rows[dgvWP.SelectedIndex][1]); |
2369 | - | 3789 | // wpList.Clear(); |
2363 | - | 3790 | if (mRouteWP != null) |
3791 | MainMap.Markers.Remove(mRouteWP); |
||
3792 | |||
2369 | - | 3793 | //for (int k = 0; k < dtWaypoints.Rows.Count; k++) |
3794 | //{ |
||
3795 | // _createWP(new PointLatLng((double)dtWaypoints.Rows[k][3], (double)dtWaypoints.Rows[k][4]), (string)dtWaypoints.Rows[k][2], (int)dtWaypoints.Rows[k][1]); |
||
3796 | //} |
||
2363 | - | 3797 | _routeUpdate(); |
3798 | dgvWP.Items.Refresh(); |
||
3799 | |||
3800 | } |
||
3801 | |||
2361 | - | 3802 | } |
3803 | private void btnEditWPDel_Click(object sender, RoutedEventArgs e) |
||
3804 | { |
||
2368 | - | 3805 | if (dgvWP.SelectedIndex > -1 && dgvWP.SelectedIndex < dtWaypoints.Rows.Count) |
3806 | { |
||
3807 | int index = dgvWP.SelectedIndex; |
||
3808 | Dispatcher.Invoke(() => { |
||
3809 | DataGridRow row; |
||
3810 | if (_wpEdit > -1 && _wpEdit < dgvWP.ItemContainerGenerator.Items.Count) |
||
3811 | { |
||
3812 | row = (DataGridRow)dgvWP.ItemContainerGenerator.ContainerFromIndex(_wpEdit); |
||
3813 | row.Background = new SolidColorBrush(Colors.Transparent); |
||
3814 | row.BorderBrush = new SolidColorBrush(Colors.Transparent); |
||
3815 | row.BorderThickness = new Thickness(0); |
||
3816 | } |
||
2372 | - | 3817 | if ((int)dtWaypoints.Rows[index][1] == 0 || (int)dtWaypoints.Rows[index][1] == 3) |
2368 | - | 3818 | wpList.Remove(new PointLatLng((double)dtWaypoints.Rows[index][3], (double)dtWaypoints.Rows[index][4])); |
3819 | _clearWPMarker((string)dtWaypoints.Rows[index][2]); |
||
2369 | - | 3820 | if (wpActiveMarker != null) |
3821 | MainMap.Markers.Remove(wpActiveMarker); |
||
2368 | - | 3822 | dtWaypoints.Rows[index].Delete(); |
3823 | _wpIndex = -1; |
||
3824 | _wpEdit = -1; |
||
3825 | for (int i = index; i < dtWaypoints.Rows.Count; i++) //change the index of points behind deleted point + rename to new index |
||
3826 | { |
||
3827 | dtWaypoints.Rows[i][0] = i + 1; |
||
3828 | string s1 = (string)dtWaypoints.Rows[i][2]; //old name of WP (Prefix + index) |
||
3829 | string s2 = s1.Substring(0, 1) + (i + 1).ToString(); //new name of WP |
||
3830 | _renameWPMarker(s1, s2); |
||
3831 | dtWaypoints.Rows[i][2] = s2; |
||
3832 | } |
||
3833 | lblWPCount.Content = dtWaypoints.Rows.Count; |
||
3834 | if (mRouteWP != null) |
||
3835 | MainMap.Markers.Remove(mRouteWP); |
||
3836 | _routeUpdate(); |
||
2361 | - | 3837 | |
2368 | - | 3838 | dgvWP.UpdateLayout(); |
3839 | }); |
||
3840 | } |
||
2361 | - | 3841 | } |
2366 | - | 3842 | private void tbWPEdit_TouchDown(object sender, TouchEventArgs e) |
3843 | { |
||
3844 | _wpWEdit(sender); |
||
3845 | } |
||
2361 | - | 3846 | private void tbWPEdit_KeyDown(object sender, KeyEventArgs e) |
3847 | { |
||
2366 | - | 3848 | _wpWEdit(sender); |
3849 | } |
||
2369 | - | 3850 | private void tbWPEdit_MouseDown(object sender, MouseButtonEventArgs e) |
3851 | { |
||
3852 | _wpWEdit(sender); |
||
3853 | } |
||
2366 | - | 3854 | void _wpWEdit(object sender) |
3855 | { |
||
2369 | - | 3856 | // if (!((TextBox)sender).IsReadOnly) |
2361 | - | 3857 | { |
3858 | KeyPad.Keypad k = new KeyPad.Keypad(this); |
||
3859 | |||
2363 | - | 3860 | switch (((TextBox)sender).Name) |
3861 | { |
||
3862 | case "tbWPEditLat": |
||
3863 | k.Title = "Latitude"; |
||
3864 | k.LENGTH = 17; |
||
3865 | k.MAX = 359.9; |
||
3866 | break; |
||
3867 | case "tbWPEditLon": |
||
3868 | k.Title = "Longitude"; |
||
3869 | k.LENGTH = 17; |
||
3870 | k.MAX = 359.9; |
||
3871 | break; |
||
3872 | case "tbWPEditAlt": |
||
3873 | k.Title = "Altitude"; |
||
3874 | k.LENGTH = 3; |
||
3875 | k.MAX = 254; |
||
3876 | k.disableDecimal(); |
||
3877 | break; |
||
3878 | case "tbWPEditHeading": |
||
3879 | k.Title = "Heading"; |
||
3880 | k.LENGTH = 3; |
||
3881 | k.MAX = 359; |
||
3882 | k.MIN = 1; |
||
3883 | k.disableDecimal(); |
||
3884 | break; |
||
3885 | case "tbWPEditSpeed": |
||
3886 | k.Title = "Speed"; |
||
3887 | k.LENGTH = 4; |
||
3888 | k.MAX = 24.7; |
||
3889 | k.MIN = 0.1; |
||
3890 | break; |
||
3891 | case "tbWPEditClimbrate": |
||
3892 | k.Title = "Climbrate"; |
||
3893 | k.LENGTH = 4; |
||
3894 | k.MAX = 25.4; |
||
3895 | k.MIN = 0.1; |
||
3896 | break; |
||
3897 | case "tbWPEditRadius": |
||
3898 | k.Title = "Radius"; |
||
3899 | k.LENGTH = 3; |
||
3900 | k.MAX = 254; |
||
3901 | k.disableDecimal(); |
||
3902 | break; |
||
3903 | case "tbWPEditHoldtime": |
||
3904 | k.Title = "Holdtime"; |
||
3905 | k.LENGTH = 3; |
||
3906 | k.MAX = 254; |
||
3907 | break; |
||
3908 | case "tbWPEditAutoTrigger": |
||
3909 | k.Title = "Autotrigger"; |
||
3910 | k.LENGTH = 3; |
||
3911 | k.MAX = 254; |
||
3912 | k.disableDecimal(); |
||
3913 | break; |
||
3914 | case "tbWPEditCamAngle": |
||
3915 | k.Title = "Camera angle"; |
||
3916 | k.LENGTH = 3; |
||
3917 | k.MAX = 254; |
||
3918 | k.MIN = 1; |
||
3919 | k.disableDecimal(); |
||
3920 | break; |
||
3921 | case "tbWPEditOut1": |
||
3922 | k.Title = "OUT1 timer interval"; |
||
3923 | k.LENGTH = 3; |
||
3924 | k.MAX = 254; |
||
3925 | k.disableDecimal(); |
||
3926 | break; |
||
3927 | } |
||
3928 | k.Result = ((TextBox)sender).Text; |
||
2366 | - | 3929 | if (k.ShowDialog() == true && k.Result.Length > 0) |
2363 | - | 3930 | ((TextBox)sender).Text = k.Result; |
2361 | - | 3931 | } |
2366 | - | 3932 | |
2361 | - | 3933 | } |
2356 | - | 3934 | private void tbWPEditHeading_KeyDown(object sender, KeyEventArgs e) |
3935 | { |
||
3936 | if(!tbWPEditHeading.IsReadOnly) |
||
3937 | { |
||
3938 | //var x = KeyInterop.VirtualKeyFromKey(e.Key); |
||
3939 | KeyConverter x = new KeyConverter(); |
||
3940 | string s = x.ConvertToString(e.Key); |
||
3941 | |||
3942 | if ("1234567890,\b".IndexOf(s) < 0) //general check for valid chars(0-9) and backspace (\b) |
||
3943 | e.Handled = true; |
||
3944 | else |
||
3945 | if ("\b".IndexOf(s) < 0) |
||
3946 | if (Convert.ToInt16(((TextBox)sender).Text + s) > 360) //if valid and not backspace, check for upper limit of the resulting number |
||
3947 | e.Handled = true; |
||
3948 | |||
3949 | } |
||
3950 | } |
||
2361 | - | 3951 | private void btnWPAddCurrentPos_Click(object sender, RoutedEventArgs e) |
2356 | - | 3952 | { |
2359 | - | 3953 | object[] o = new object[16]; |
2356 | - | 3954 | |
2359 | - | 3955 | o[0] = dgvWP.ItemContainerGenerator.Items.Count+1; |
3956 | o[1] = 0; |
||
3957 | // cbWPEditType.SelectedIndex = 0; |
||
3958 | // tbWPEditPrefix.Text = "P"; |
||
3959 | o[2] = "P" + o[0].ToString(); |
||
3960 | // tbWPEditLat.Text = copter.Position.Lat.ToString(); |
||
3961 | o[3] = copter.Position.Lat; |
||
3962 | // tbWPEditLon.Text = copter.Position.Lng.ToString(); |
||
3963 | o[4] = copter.Position.Lng; |
||
3964 | // tbWPEditAlt.Text = ((double)iAnalogData[4] / (double)10).ToString(); |
||
3965 | o[5] = iAnalogData[4].ToString(); |
||
2356 | - | 3966 | |
2359 | - | 3967 | // cbWPEditHeading.SelectedIndex = 2; |
3968 | o[6] = tbWPEditHeading.Text = iAnalogData[10].ToString(); |
||
3969 | // tbWPEditHeading.IsReadOnly = false; |
||
2356 | - | 3970 | |
2359 | - | 3971 | // cbWPEditSpeed.SelectedIndex = 1; |
3972 | // tbWPEditSpeed.Text = "5.0"; |
||
3973 | // tbWPEditSpeed.IsReadOnly = false; |
||
2372 | - | 3974 | o[7] = "10"; |
2356 | - | 3975 | |
2359 | - | 3976 | // cbWPEditClimbrate.SelectedIndex = 1; |
3977 | // tbWPEditClimbrate.Text = "5.0"; |
||
3978 | // tbWPEditClimbrate.IsReadOnly = false; |
||
2372 | - | 3979 | o[8] = "10"; |
2356 | - | 3980 | |
2359 | - | 3981 | // tbWPEditRadius.Text = "10"; |
2372 | - | 3982 | o[9] = "5"; |
2359 | - | 3983 | // tbWPEditHoldtime.Text = "5"; |
3984 | o[10] = "5"; |
||
3985 | // tbWPEditAutoTrigger.Text = "0"; |
||
3986 | o[11] = "0"; |
||
3987 | // cbWPEditCamAngle.SelectedIndex = 1; |
||
3988 | // tbWPEditCamAngle.Text = "AUTO"; |
||
3989 | // tbWPEditCamAngle.IsReadOnly = true; |
||
3990 | o[12] = "255"; |
||
2356 | - | 3991 | |
2359 | - | 3992 | o[13] = "0"; |
3993 | // tbWPEditOut1.Text = "0"; |
||
3994 | o[14] = "0"; |
||
3995 | o[15] = "0"; |
||
3996 | |||
3997 | dtWaypoints.Rows.Add(o); |
||
2368 | - | 3998 | _createWP(new PointLatLng((double)o[3], (double)o[4]), (string)o[2], (int)o[1]); |
2359 | - | 3999 | Dispatcher.Invoke(() => lblWPCount.Content = o[0].ToString()); |
4000 | if (mRouteWP != null) |
||
4001 | MainMap.Markers.Remove(mRouteWP); |
||
4002 | _routeUpdate(); |
||
4003 | Dispatcher.Invoke(() => { |
||
4004 | dgvWP.Items.Refresh(); |
||
4005 | dgvWP.SelectedIndex = (int)o[0] -1; |
||
4006 | dgvWP.UpdateLayout(); |
||
4007 | _dgvWPselectEditRow(); |
||
4008 | }); |
||
2356 | - | 4009 | } |
4010 | |||
2315 | - | 4011 | #endregion WP |
2324 | - | 4012 | #region GPX |
4013 | private void checkBoxGPXLog_Click(object sender, RoutedEventArgs e) |
||
4014 | { |
||
4015 | _bGPXLog = (bool)checkBoxGPXLog.IsChecked; |
||
4016 | } |
||
4017 | void _gpxAdd(double lat,double lon, int elevation) |
||
4018 | { |
||
4019 | DataRow dr = dtGPX.NewRow(); |
||
4020 | dr[0] = dtGPX.Rows.Count - 1; |
||
4021 | dr[1] = lat; |
||
4022 | dr[2] = lon; |
||
4023 | dr[3] = elevation; |
||
4024 | dr[4] = DateTime.UtcNow.ToString("s", System.Globalization.CultureInfo.InvariantCulture); //2011-01-14T01:59:01Z |
||
4025 | dtGPX.Rows.Add(dr); |
||
4026 | } |
||
4027 | void _saveGPXLog() |
||
4028 | { |
||
4029 | if (!Directory.Exists("GPXLog")) |
||
4030 | Directory.CreateDirectory("GPXLog"); |
||
4031 | string SaveFileName = "GPXLog\\" + DateTime.Now.ToString("yyyyMMdd_HHmm") + ".gpx"; |
||
4032 | XmlTextWriter myXmlTextWriter = null; |
||
4033 | myXmlTextWriter = new XmlTextWriter(SaveFileName, null); |
||
4034 | NumberFormatInfo nfi = new NumberFormatInfo(); |
||
4035 | nfi.NumberDecimalSeparator = "."; |
||
2315 | - | 4036 | |
2324 | - | 4037 | try |
4038 | { |
||
4039 | myXmlTextWriter.Formatting = Formatting.Indented; |
||
4040 | |||
4041 | myXmlTextWriter.WriteStartDocument(); |
||
4042 | |||
4043 | myXmlTextWriter.WriteStartElement("gpx"); |
||
4044 | |||
4045 | myXmlTextWriter.WriteAttributeString("version", "1.0"); |
||
4046 | myXmlTextWriter.WriteAttributeString("creator", "MKLiveView v1.0"); |
||
4047 | myXmlTextWriter.WriteAttributeString("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); |
||
4048 | myXmlTextWriter.WriteAttributeString("xmlns", "http://www.topografix.com/GPX/1/1"); |
||
4049 | myXmlTextWriter.WriteAttributeString("xsi:schemaLocation", "http://www.topografix.com/GPX/1/1/gpx.xsd"); |
||
4050 | |||
4051 | myXmlTextWriter.WriteElementString("time", DateTime.UtcNow.ToString("u", System.Globalization.CultureInfo.InvariantCulture)); |
||
4052 | |||
4053 | myXmlTextWriter.WriteStartElement("trk"); |
||
4054 | myXmlTextWriter.WriteStartElement("trkseg"); |
||
4055 | for(int i = 0; i< dtGPX.Rows.Count;i++) |
||
4056 | { |
||
4057 | myXmlTextWriter.WriteStartElement("trkpt"); |
||
4058 | myXmlTextWriter.WriteAttributeString("lat", dtGPX.Rows[i][1].ToString() != "" ? ((double)dtGPX.Rows[i][1]).ToString(nfi) : ""); |
||
4059 | myXmlTextWriter.WriteAttributeString("lon", dtGPX.Rows[i][2].ToString() != "" ? ((double)dtGPX.Rows[i][2]).ToString(nfi) : ""); |
||
4060 | myXmlTextWriter.WriteElementString("ele", dtGPX.Rows[i][3].ToString()); |
||
4061 | myXmlTextWriter.WriteElementString("time", dtGPX.Rows[i][4].ToString()); |
||
4062 | myXmlTextWriter.WriteEndElement(); |
||
4063 | } |
||
4064 | myXmlTextWriter.WriteEndElement(); |
||
4065 | myXmlTextWriter.WriteEndElement(); |
||
4066 | myXmlTextWriter.WriteEndElement(); |
||
4067 | } |
||
4068 | catch (Exception e) |
||
4069 | { |
||
4070 | Console.WriteLine("Exception: {0}", e.ToString()); |
||
4071 | } |
||
4072 | finally |
||
4073 | { |
||
4074 | if (myXmlTextWriter != null) |
||
4075 | { |
||
4076 | myXmlTextWriter.Close(); |
||
4077 | } |
||
4078 | } |
||
4079 | } |
||
2356 | - | 4080 | |
2324 | - | 4081 | private void btnLoadGPXLog_Click(object sender, RoutedEventArgs e) |
4082 | { |
||
4083 | _loadGPXLog(); |
||
4084 | } |
||
2327 | - | 4085 | private void btnClearRoute_Click(object sender, RoutedEventArgs e) |
4086 | { |
||
4087 | _clearMapMarkers(typeof(GMapRoute)); |
||
4088 | } |
||
2324 | - | 4089 | void _loadGPXLog() |
4090 | { |
||
4091 | |||
4092 | Microsoft.Win32.OpenFileDialog fd = new Microsoft.Win32.OpenFileDialog(); |
||
4093 | fd.Filter = "GPX-Logfile | *.gpx"; |
||
4094 | fd.Multiselect = false; |
||
4095 | if (fd.ShowDialog().Value) |
||
4096 | { |
||
4097 | string file = fd.FileName; |
||
4098 | try |
||
4099 | { |
||
4100 | XDocument gpxDoc = XDocument.Load(file); |
||
4101 | XNamespace gpx = XNamespace.Get("http://www.topografix.com/GPX/1/1"); |
||
4102 | |||
4103 | NumberFormatInfo nfi = new NumberFormatInfo(); |
||
4104 | nfi.NumberDecimalSeparator = "."; |
||
4105 | |||
4106 | var tracks = from track in gpxDoc.Descendants(gpx + "trk") |
||
4107 | select new |
||
4108 | { |
||
4109 | Name = track.Element(gpx + "name") != null ? track.Element(gpx + "name").Value : null, |
||
4110 | Segs = ( |
||
4111 | from trackpoint in track.Descendants(gpx + "trkpt") |
||
4112 | select new |
||
4113 | { |
||
4114 | Latitude = trackpoint.Attribute("lat").Value, |
||
4115 | Longitude = trackpoint.Attribute("lon").Value, |
||
4116 | Elevation = trackpoint.Element(gpx + "ele") != null ? |
||
4117 | trackpoint.Element(gpx + "ele").Value : null, |
||
4118 | Time = trackpoint.Element(gpx + "time") != null ? |
||
4119 | trackpoint.Element(gpx + "time").Value : null |
||
4120 | } |
||
4121 | ) |
||
4122 | }; |
||
4123 | |||
4124 | List<PointLatLng> wpl = new List<PointLatLng>(); |
||
4125 | foreach(var trk in tracks) |
||
4126 | { |
||
4127 | foreach(var trkseg in trk.Segs) |
||
4128 | { |
||
4129 | if(trkseg.Latitude != "" && trkseg.Longitude !="") |
||
4130 | wpl.Add(new PointLatLng(Convert.ToDouble(trkseg.Latitude, nfi), Convert.ToDouble(trkseg.Longitude, nfi))); |
||
4131 | } |
||
4132 | |||
4133 | } |
||
4134 | if(wpl.Count() > 0) |
||
4135 | { |
||
2327 | - | 4136 | _clearMapMarkers(typeof(GMapRoute)); |
2324 | - | 4137 | MapRoute mr = new MapRoute(wpl, "flying"); |
2328 | - | 4138 | Dispatcher.Invoke(() => |
4139 | { |
||
4140 | GMapRoute mRoute; |
||
4141 | if (comboBoxRouteColor.SelectionBoxItem != null) |
||
4142 | { |
||
4143 | string s = comboBoxRouteColor.SelectionBoxItem.ToString(); |
||
2366 | - | 4144 | mRoute = new GMapRoute(wpl, _getBrush(s)); |
2328 | - | 4145 | } |
4146 | else |
||
2366 | - | 4147 | mRoute = new GMapRoute(wpl, null); |
2324 | - | 4148 | |
2328 | - | 4149 | MainMap.Markers.Add(mRoute); |
4150 | }); |
||
2324 | - | 4151 | } |
4152 | |||
4153 | } |
||
4154 | catch (Exception e) |
||
4155 | { |
||
4156 | Console.WriteLine("Exception: {0}", e.ToString()); |
||
4157 | } |
||
4158 | } |
||
4159 | } |
||
4160 | #endregion GPX |
||
2315 | - | 4161 | #endregion functions |
2287 | - | 4162 | } |
2315 | - | 4163 | /// <summary> |
4164 | /// formats the wp datatable values for display in datagrid - this is bound in the datagrid as a converter |
||
4165 | /// </summary> |
||
2313 | - | 4166 | public class waypointsConverter : IValueConverter |
4167 | { |
||
4168 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) |
||
4169 | { |
||
4170 | if (value != null) |
||
4171 | { |
||
4172 | switch ((string)parameter) |
||
4173 | { |
||
4174 | case "Latitude": |
||
4175 | return value.ToString() + " °"; |
||
4176 | case "Longitude": |
||
4177 | return value.ToString() + " °"; |
||
4178 | case "Radius": |
||
4179 | return value.ToString() + " m"; |
||
4180 | case "Altitude": |
||
4181 | return value.ToString() + " m"; |
||
4182 | case "ClimbRate": |
||
4183 | return value.ToString() == "255" ? "Auto" : (System.Convert.ToDouble(value) / 10).ToString("0.0 m/s"); |
||
4184 | case "DelayTime": |
||
4185 | return value.ToString() + " s"; |
||
4186 | case "Heading": |
||
4187 | return Waypoints.Heading(System.Convert.ToInt32(value)); |
||
4188 | case "Speed": |
||
4189 | return Waypoints.WPSpeed(System.Convert.ToInt16(value)); |
||
4190 | case "CamAngle": |
||
4191 | return Waypoints.CAMAngle(System.Convert.ToInt16(value)); |
||
4192 | case "Type": |
||
4193 | return ((Waypoints.pointType)(System.Convert.ToInt16(value))).ToString(); |
||
4194 | case "AutoTrigger": |
||
4195 | return value.ToString() == "0" ? "- - -" : value.ToString() + " m"; |
||
4196 | case "Status": |
||
2355 | - | 4197 | return (Waypoints.status)(System.Convert.ToInt16(value)); |
2313 | - | 4198 | } |
4199 | |||
4200 | return value.ToString(); |
||
4201 | } |
||
4202 | else return value; |
||
4203 | } |
||
4204 | |||
4205 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) |
||
4206 | { |
||
4207 | throw new NotImplementedException(); |
||
4208 | } |
||
4209 | } |
||
4210 | |||
2287 | - | 4211 | public class IniFile |
4212 | { |
||
4213 | public string path; |
||
4214 | |||
4215 | [DllImport("kernel32")] |
||
4216 | private static extern long WritePrivateProfileString(string section, |
||
4217 | string key, string val, string filePath); |
||
4218 | |||
4219 | [DllImport("kernel32.dll", CharSet = CharSet.Auto)] |
||
4220 | static extern uint GetPrivateProfileSectionNames(IntPtr lpszReturnBuffer, |
||
4221 | uint nSize, string lpFileName); |
||
4222 | |||
4223 | [DllImport("kernel32")] |
||
4224 | private static extern int GetPrivateProfileString(string section, |
||
4225 | string key, string def, StringBuilder retVal, |
||
4226 | int size, string filePath); |
||
4227 | |||
4228 | public IniFile(string INIPath) |
||
4229 | { |
||
4230 | path = INIPath; |
||
4231 | } |
||
4232 | |||
4233 | public void IniWriteValue(string Section, string Key, string Value) |
||
4234 | { |
||
4235 | WritePrivateProfileString(Section, Key, Value, this.path); |
||
4236 | } |
||
4237 | |||
4238 | public string IniReadValue(string Section, string Key) |
||
4239 | { |
||
4240 | StringBuilder temp = new StringBuilder(255); |
||
4241 | int i = GetPrivateProfileString(Section, Key, "", temp, 255, this.path); |
||
4242 | return temp.ToString(); |
||
4243 | } |
||
4244 | //Ini_sections auslesen in String-Array |
||
4245 | public string[] IniSectionNames() |
||
4246 | { |
||
4247 | |||
4248 | // uint MAX_BUFFER = 32767; |
||
4249 | uint MAX_BUFFER = 8388608; |
||
4250 | IntPtr pReturnedString = Marshal.AllocCoTaskMem((int)MAX_BUFFER); |
||
4251 | uint bytesReturned = GetPrivateProfileSectionNames(pReturnedString, MAX_BUFFER, this.path); |
||
4252 | if (bytesReturned == 0) |
||
4253 | { |
||
4254 | Marshal.FreeCoTaskMem(pReturnedString); |
||
4255 | return null; |
||
4256 | } |
||
4257 | string local = Marshal.PtrToStringAuto(pReturnedString, (int)bytesReturned).ToString(); |
||
4258 | Marshal.FreeCoTaskMem(pReturnedString); |
||
4259 | //use of Substring below removes terminating null for split |
||
4260 | return local.Substring(0, local.Length - 1).Split('\0'); |
||
4261 | |||
4262 | |||
4263 | } |
||
4264 | } |
||
4265 | |||
4266 | /// <summary> |
||
4267 | /// Selected Win AI Function Calls |
||
4268 | /// </summary> |
||
4269 | public class WinApi |
||
4270 | { |
||
4271 | [DllImport("user32.dll", EntryPoint = "GetSystemMetrics")] |
||
4272 | public static extern int GetSystemMetrics(int which); |
||
4273 | [DllImport("user32.dll")] |
||
4274 | public static extern void |
||
4275 | SetWindowPos(IntPtr hwnd, IntPtr hwndInsertAfter, |
||
4276 | int X, int Y, int width, int height, uint flags); |
||
4277 | |||
4278 | private const int SM_CXSCREEN = 0; |
||
4279 | private const int SM_CYSCREEN = 1; |
||
4280 | private static IntPtr HWND_TOP = IntPtr.Zero; |
||
4281 | private const int SWP_SHOWWINDOW = 64; // 0x0040 |
||
4282 | |||
4283 | public static int ScreenX |
||
4284 | { |
||
4285 | get { return GetSystemMetrics(SM_CXSCREEN); } |
||
4286 | } |
||
4287 | |||
4288 | public static int ScreenY |
||
4289 | { |
||
4290 | get { return GetSystemMetrics(SM_CYSCREEN); } |
||
4291 | } |
||
4292 | |||
4293 | public static void SetWinFullScreen(IntPtr hwnd) |
||
4294 | { |
||
4295 | SetWindowPos(hwnd, HWND_TOP, -8, -7, ScreenX+15, ScreenY+14, SWP_SHOWWINDOW); |
||
4296 | } |
||
4297 | } |
||
4298 | /// <summary> |
||
4299 | /// Class used to preserve / restore state of the window |
||
4300 | /// </summary> |
||
4301 | public class WinState |
||
4302 | { |
||
4303 | private WindowState winState; |
||
4304 | private WindowStyle brdStyle; |
||
4305 | private bool topMost; |
||
4306 | private Rect restore; |
||
4307 | private bool IsMaximized = false; |
||
4308 | |||
4309 | public bool isMaximized |
||
4310 | { |
||
4311 | get { return IsMaximized; } |
||
4312 | } |
||
4313 | public void Maximize(Window targetForm) |
||
4314 | { |
||
4315 | if (!IsMaximized) |
||
4316 | { |
||
4317 | IsMaximized = true; |
||
4318 | Save(targetForm); |
||
4319 | targetForm.WindowState = WindowState.Maximized; |
||
4320 | targetForm.WindowStyle = WindowStyle.None; |
||
4321 | targetForm.Topmost = true; |
||
4322 | WinApi.SetWinFullScreen(new WindowInteropHelper(targetForm).Handle); |
||
4323 | } |
||
4324 | } |
||
4325 | |||
4326 | public void Save(Window targetForm) |
||
4327 | { |
||
4328 | winState = targetForm.WindowState; |
||
4329 | brdStyle = targetForm.WindowStyle; |
||
4330 | topMost = targetForm.Topmost; |
||
4331 | restore = targetForm.RestoreBounds; |
||
4332 | } |
||
4333 | public void Restore(Window targetForm) |
||
4334 | { |
||
4335 | targetForm.WindowState = winState; |
||
4336 | targetForm.WindowStyle = brdStyle; |
||
4337 | targetForm.Topmost = topMost; |
||
4338 | |||
4339 | targetForm.Left = restore.Left; |
||
4340 | targetForm.Top = restore.Top; |
||
4341 | targetForm.Height = restore.Height; |
||
4342 | targetForm.Width = restore.Width; |
||
4343 | IsMaximized = false; |
||
4344 | } |
||
4345 | } |
||
4346 | |||
4347 | } |