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