Subversion Repositories Projects

Rev

Rev 2313 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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