-
Notifications
You must be signed in to change notification settings - Fork 0
/
soarSTF.c
1553 lines (1453 loc) · 57.5 KB
/
soarSTF.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <PalmOS.h> // all the system toolbox headers
#include "soaring.h"
#include "soarSTF.h"
#include "soarMath.h"
#include "soarForm.h"
#include "soarDB.h"
#include "soarUtil.h"
#include "soarUMap.h"
#include "soarWay.h"
#include "soarWLst.h"
#include "soarWind.h"
#include "soarTask.h"
#include "soarMem.h"
#include "soarTer.h"
#include "soarComp.h"
#include "soarCAI.h"
#define FINE_MC // controls if the "*" to indicate the MC value moves by whole lines only or not
Int16 MCSelYVal = 0;
double MCCurVal = 0.0;
double MCCurDispVal = 0.0;
Boolean forceupdate = false;
Boolean chgstartaltref = false;
double calcstfhwind;
extern UInt8 glidingtoheight;
extern Boolean clearrect;
extern double MCMult;
extern Int16 MCXVal;
extern Int16 MCYVal;
extern Int16 selectedFltindex;
extern Boolean graphing;
extern Boolean ManualDistChg;
extern Boolean inflight;
extern Boolean recv_data;
extern UInt32 thermalcount;
extern Boolean tasknotfinished;
extern UInt8 thmode;
extern double avgatthstart;
extern Int16 activetskway;
extern IndexedColorType indexGreen, indexRed,indexBlack;
extern Boolean taskonhold;
extern FlightData *fltdata;
extern UInt32 utcsecs;
extern Char timeinfo[15];
extern UInt32 nogpstime;
extern Boolean skipmc;
extern Boolean FltInfoshowMC;
// external variables for terrain
extern Boolean terrainpresent;
extern Boolean terrainvalid;
extern Boolean offterrain;
extern Boolean tskoffterrain;
extern Boolean crash;
extern double crashalt;
extern double crashlat;
extern double crashlon;
extern Boolean crash1;
extern double crashalt1;
extern double crashlat1;
extern double crashlon1;
extern Boolean wptcrash;
extern double wptcrashalt;
extern double wptcrashlat;
extern double wptcrashlon;
extern double *wptterheights;
extern Int32 numwptter;
extern Int32 prevnumwptter;
extern double prevterbear;
extern Boolean tskcrash;
extern double tskcrashalt;
extern double tskcrashlat;
extern double tskcrashlon;
extern double *tskterheights;
extern Int32 numtskter;
extern Int32 prevnumtskter;
extern Boolean sim_gps;
static void final_glide_mc(double inputSi, UInt16 speedFieldID, UInt16 altFieldID)
{
double Vstf, altitude, bearing;
double inSi = 0;
Char tempchar[15];
double wptaalt;
Boolean mcwptcrash = false;
if (data.input.bearing_to_destination.valid==VALID) {
// bearing to current waypoint
bearing = data.input.bearing_to_destination.value;
} else {
// current track
bearing = data.input.magnetic_track.value;
}
// HostTraceOutputTL(appErrorClass, "---------------");
// HostTraceOutputTL(appErrorClass, "Input %s",DblToStr(inputSi,2));
// HostTraceOutputTL(appErrorClass, "const %s",DblToStr(data.input.lftconst,2));
// convert to correct units
inSi = inputSi * MCMult;
// Have to convert inSi to knots as that is what CalcSTFSpedAlt expects
if (CalcSTFSpdAlt(inSi/data.input.lftconst, data.input.distance_to_destination.value,
bearing, data.input.destination_elev,
data.input.inusealt, true, &Vstf, &altitude) == false) {
field_set_value(speedFieldID,"XX");
field_set_value(altFieldID,"XX");
return;
}
// HostTraceOutputTL(appErrorClass, "FG Spd %s",DblToStr(Vstf,2));
if (data.config.showrgs) {
Vstf = Vstf - calcstfhwind;
}
// display speed value
field_set_value(speedFieldID, print_horizontal_speed2(Vstf, 0));
// check for terrain crash en-route to destination at various MC values
if (terrainpresent && terrainvalid && data.config.usefgterrain && (data.input.bearing_to_destination.valid==VALID) && !offterrain) {
CalcSTFSpdAlt2(inSi/data.input.lftconst, data.input.distance_to_destination.value, bearing, &Vstf, &wptaalt);
wptaalt = ConvertAltType(data.input.destination_elev, data.input.inusealt, true, ARVALT, wptaalt);
mcwptcrash = terraincrash(wptterheights, numwptter, data.input.gpslatdbl, data.input.gpslngdbl, data.input.destination_lat, data.input.destination_lon,
data.input.inusealt, wptaalt+data.input.destination_elev, true);
if (mcwptcrash && !offterrain) {
switch (data.config.alttype) {
case REQALT:
altitude = data.input.inusealt - crashalt;
break;
case ARVALT:
// if crash is more than safety height, adjust AAlt figure
if (crashalt + data.config.safealt < 0) {
altitude = crashalt + data.config.safealt;
}
break;
case DLTALT:
altitude = crashalt;
break;
default:
break;
}
}
} else {
crash = false;
crash1 = false;
crashalt = 0.0;
}
// display altitude value
field_set_value(altFieldID, print_altitude(altitude));
if (inputSi == 0.0) { // do once once
// show warning triangle for off terrain under Alt Ref Label
if (offterrain && data.config.usefgterrain) {
// HostTraceOutputTL(appErrorClass, "Triangle on FG");
FntSetFont((FontID)WAYSYMB11);
if (device.colorCapable) {
WinSetTextColor(indexRed);
}
tempchar[0] = 11; // fell off terrain map!
tempchar[1] = '\0';
// under altitude field label
WinDrawChars(tempchar, 1, WIDTH_MIN+63, HEIGHT_MIN+25);
if (device.colorCapable) {
WinSetTextColor(indexBlack);
}
FntSetFont(stdFont);
}
}
// Calculations for "*" placement
MCSelYVal = (Int16)(inputSi/data.config.mcrngmult) * 12 + MCYVal;
// draw warning triangle for terrain crash
if (mcwptcrash && !offterrain) {
// HostTraceOutputTL(appErrorClass, "Triangle on FG");
FntSetFont((FontID)WAYSYMB11);
if (device.colorCapable) {
WinSetTextColor(indexRed);
}
tempchar[0] = 9;
tempchar[1] = '\0';
// between speed and altitude value
WinDrawChars(tempchar, 1, WIDTH_MIN+50, HEIGHT_MIN+1+MCSelYVal);
if (device.colorCapable) {
WinSetTextColor(indexBlack);
}
FntSetFont(stdFont);
} else {
StrCopy(tempchar, " ");
WinDrawChars(tempchar, 6, WIDTH_MIN+50, HEIGHT_MIN+1+MCSelYVal);
}
#ifndef FINE_MC
// HostTraceOutputTL(appErrorClass, "MCsel %s",DblToStr(MCSelYVal,2));
if ((MCCurDispVal >= 0.0) && (inputSi == MCCurDispVal)) {
FntSetFont(largeBoldFont);
WinDrawChars("*", 1, MCXVal-8, MCSelYVal+1);
FntSetFont(stdFont);
} else {
FntSetFont(largeBoldFont);
WinEraseChars("*", 1, MCXVal-8, MCSelYVal+1);
FntSetFont(stdFont);
}
#endif
}
void final_glide_event()
{
Char tempchar[20];
double WaySTF=0.0;
double fgatpdist=0.0, fgatpbear=0.0;
double fgatpalt1=0.0;
double fgatpalt2=0.0;
double startalt=0.0;
double firstaltloss;
double secondaltloss;
static RectangleType rectP;
Int16 TAKEOFFSET, LANDOFFSET;
// double refRng, refBrg;
// HostTraceOutputTL(appErrorClass, "Main Final Glide Event");
if (data.config.usepalmway) {
if (data.input.destination_valid) {
// Find the STF altitude for current distance and bearing
// This function fills in the bearing and range for the waypoints
// the altitude is ignored and recalculated below.
startalt = data.input.inusealt;
// Calculates the STF Speed and Altitude values for the current Waypoint
// CalcSTFSpdAlt expects the first parameter to be in knots
CalcSTFSpdAlt2(MCCurVal, data.input.distance_to_destination.value, data.input.bearing_to_destination.value, &WaySTF, &data.input.destination_aalt);
firstaltloss = data.input.destination_aalt;
fgatpalt1 = ConvertAltType(data.input.destination_elev, startalt, true, REQALT, firstaltloss);
// HostTraceOutputTL(appErrorClass, "fgatpalt1 = %s", DblToStr(fgatpalt1,0));
// Find the STF altitude from current waypoint to:
// The Finish Point if a task is active or
// The HOME waypoint if no task is active
if (data.task.numwaypts > 0) {
if (data.task.hastakeoff) {
TAKEOFFSET = 1;
} else {
TAKEOFFSET = 0;
}
if (data.task.haslanding) {
LANDOFFSET = data.task.numwaypts - 1;
} else {
LANDOFFSET = data.task.numwaypts;
}
// get FGA altitude
fgatpalt2 = data.input.FGAdispalt;
// check task rules
if (data.task.rulesactive && !taskonhold) {
// display info above waypoint arrow
if ((StrLen(timeinfo) > 0) && tasknotfinished) {
if ((data.task.startlocaltime > 0) && (activetskway <= TAKEOFFSET) && inflight) {
// center start time
StrCopy(tempchar, " ");
if (StrCompare(Left(timeinfo,1), "(") != 0) StrCat(tempchar, " ");
StrCat(tempchar, Left(timeinfo,7));
} else {
// center TOT
StrCopy(tempchar, " ");
StrCat(tempchar, Left(timeinfo,7));
}
field_set_value(form_final_glide_fgto1000m, tempchar);
ctl_set_visible(form_final_glide_fgto1000m, true);
} else if (data.task.fgto1000m || (data.task.finishheight > 0.0)) {
// display original finish elevation if changed by task rules
if (!taskonhold && (activetskway == (LANDOFFSET-1)) && (data.task.elevations[LANDOFFSET-1] != data.activetask.finishheight)) {
// indicate final gliding to 1000m below start height
// by showinf original waypoint elevation
StrCopy(tempchar, "(");
StrCat(tempchar, print_altitude(data.task.elevations[LANDOFFSET-1]));
StrCat(tempchar, ")");
field_set_value(form_final_glide_fgto1000m, tempchar);
ctl_set_visible(form_final_glide_fgto1000m, true);
} else {
ctl_set_visible(form_final_glide_fgto1000m, false);
}
} else {
ctl_set_visible(form_final_glide_fgto1000m, false);
}
} else if (taskonhold) {
field_set_value(form_final_glide_fgto1000m, timeinfo);
ctl_set_visible(form_final_glide_fgto1000m, true);
} else {
ctl_set_visible(form_final_glide_fgto1000m, false);
}
// show warning triangle for task crash or off terrain under FGA Label
if (tskcrash || (tskoffterrain && data.config.usefgterrain)) {
// HostTraceOutputTL(appErrorClass, "Triangle on FG");
FntSetFont((FontID)WAYSYMB11);
if (device.colorCapable) {
WinSetTextColor(indexRed);
}
if (tskoffterrain) {
tempchar[0] = 11; // fell off terrain map!
} else {
tempchar[0] = 9;
}
tempchar[1] = '\0';
// under FGA field label
WinDrawChars(tempchar, 1, WIDTH_MIN+147, HEIGHT_MIN+117);
if (device.colorCapable) {
WinSetTextColor(indexBlack);
}
FntSetFont(stdFont);
}
} else {
// HostTraceOutputTL(appErrorClass, "Inside GOTO Waypoint FGA Case");
// Setting fgatpalt2 to fgatpalt1 to cover the case where
// the current waypoint/turnpoint is the HOME/Finish waypoint/turnpoint
// tskcrash = false;
if (data.config.alttype == REQALT) {
fgatpalt2 = fgatpalt1;
} else {
fgatpalt2 = ConvertAltType(data.input.homeElev, startalt, true, data.config.alttype, firstaltloss);
}
if (data.input.destination_lat != data.input.homeLat || data.input.destination_lon != data.input.homeLon) {
LatLonToRangeBearing(data.input.destination_lat, data.input.destination_lon, data.input.homeLat, data.input.homeLon, &fgatpdist, &fgatpbear);
// Convert to Magnetic
fgatpbear = nice_brg(fgatpbear + data.input.deviation.value);
// CalcSTFSpdAlt expects the first parameter to be in knots
CalcSTFSpdAlt2(MCCurVal, fgatpdist, fgatpbear, &WaySTF, &secondaltloss);
fgatpalt2 = ConvertAltType(data.input.homeElev, startalt, true, REQALT, (firstaltloss+secondaltloss));
if (data.config.alttype != REQALT) {
fgatpalt2 = ConvertAltType(data.input.homeElev, startalt, true, data.config.alttype, (firstaltloss+secondaltloss));
}
}
}
// HostTraceOutputTL(appErrorClass, "------------------------");
} else if (!ManualDistChg) {
// clear inuseWaypoint
data.input.destination_name[0] = 0;
data.input.destination_elev = 0.0;
data.input.distance_to_destination.valid = VALID;
data.input.bearing_to_destination.valid = NOT_VALID;
data.input.bearing_to_destination.value = 000.0;
data.input.destination_valid = false;
} else {
// manual distance change
data.input.distance_to_destination.valid = VALID;
data.input.bearing_to_destination.valid = NOT_VALID;
data.input.bearing_to_destination.value = 000.0;
data.input.destination_valid = false;
}
/* if ((data.input.refwpttype != REFNONE) && (data.input.refLat != INVALID_LAT_LON) && (data.input.refLon != INVALID_LAT_LON)) {
// display range and bearing from/to ref point
LatLonToRangeBearing(data.input.gpslatdbl, data.input.gpslngdbl, data.input.refLat, data.input.refLon, &refRng, &refBrg);
refBrg = nice_brg(refBrg + data.input.deviation.value);
StrCopy(tempchar, " ");
if (data.config.RefWptRadial) {
refBrg = RecipCse(refBrg);
StrCat(tempchar, print_direction2(refBrg));
StrCat(tempchar, "R");
} else {
StrCat(tempchar, print_direction2(refBrg));
StrCat(tempchar, "°");
}
if (pround(refRng*data.input.disconst,0) > 999.0) {
StrCat(tempchar, "999");
} else {
StrCat(tempchar, print_distance2(refRng,0));
}
field_set_value(form_final_glide_fgto1000m, Right(tempchar,7));
ctl_set_visible(form_final_glide_fgto1000m, true);
}
*/
}
// Updates the Final Glide Around Turnpoint Value
field_set_value(form_final_glide_fga, print_altitude(fgatpalt2));
// Remark the print functions check the validity of the data
if (!ManualDistChg) {
if ((data.input.distance_to_destination.value*data.input.disconst) < 10.0) {
StrCopy(tempchar, print_distance2(data.input.distance_to_destination.value, 1));
} else if ((data.input.distance_to_destination.value*data.input.disconst) < 1000.0) {
StrCopy(tempchar, print_distance2(data.input.distance_to_destination.value, 0));
} else {
StrCopy(tempchar, "999");
}
field_set_value(form_final_glide_dis, tempchar);
}
ManualDistChg = false;
field_set_value(form_final_glide_gs, print_horizontal_speed(data.input.ground_speed));
field_set_value(form_final_glide_bearing, print_direction(data.input.bearing_to_destination));
field_set_value(form_final_glide_track, print_direction(data.input.magnetic_track));
// Draw the control point bearing and distance if valid and meets criteria
if (((data.config.shownextwpt == NEXTALL) || ((data.config.shownextwpt == NEXTCTL) && data.input.isctlpt)) && (data.input.nextwpt_dist >= 0.0)) {
StrCopy(tempchar," ");
StrCat(tempchar, print_direction2(data.input.nextwpt_bear));
StrCat(tempchar, "° ");
if ((data.input.nextwpt_dist*data.input.disconst) < 10.0) {
StrCat(tempchar, print_distance2(data.input.nextwpt_dist, 1));
// } else if ((data.input.nextwpt_dist*data.input.disconst) < 100.0) {
// StrCat(tempchar, print_distance2(data.input.nextwpt_dist, 1));
} else if ((data.input.nextwpt_dist*data.input.disconst) < 1000.0) {
StrCat(tempchar, print_distance2(data.input.nextwpt_dist, 0));
} else {
StrCat(tempchar, "999");
}
field_set_value(form_final_glide_bearrng, tempchar);
} else {
field_set_value(form_final_glide_bearrng, " ");
}
if (data.input.destination_type & AREA) {
field_set_value(form_final_glide_wptlabel, "Area:");
} else if (data.input.destination_type & CONTROL) {
field_set_value(form_final_glide_wptlabel, "Ctl:");
} else {
field_set_value(form_final_glide_wptlabel, "Wpt:");
}
if (data.config.altreftype == AGL) {
if (terrainvalid) {
field_set_value(form_final_glide_curalt, print_altitude(data.input.inusealt-data.input.terelev));
} else {
field_set_value(form_final_glide_curalt, "N/A");
}
} else if (data.config.altreftype == QFE) {
field_set_value(form_final_glide_curalt, print_altitude(data.input.inusealt-data.config.qfealt));
} else if (data.config.altreftype == PALT) {
// FL always in ft
field_set_value(form_final_glide_curalt, DblToStr(pround(data.logger.pressalt,0),0));
} else {
field_set_value(form_final_glide_curalt, print_altitude(data.input.inusealt));
}
// msr: now displaying thermal average in place of current lift
field_set_value(form_final_glide_lift, DblToStr(pround(data.input.thavglift*data.input.lftconst, data.input.lftprec), data.input.lftprec));
field_set_value(form_final_glide_alift, DblToStr(pround(data.input.avglift*data.input.lftconst, data.input.lftprec), data.input.lftprec));
#ifdef FINE_MC
// clear the place for the * marker for the current MC value
rectP.topLeft.x = MCXVal-8;
rectP.topLeft.y = 36;
rectP.extent.x = 8;
rectP.extent.y = 73;
WinEraseRectangle(&rectP, 0);
tempchar[1] = 0;
// calculate position of "*" in MC / STF grid
FntSetFont(largeBoldFont);
MCCurDispVal = pround(MCCurVal*data.input.lftconst/data.config.mcrngmult/MCMult, 1) * data.config.mcrngmult;
if (MCCurDispVal < 0.0) {
MCCurDispVal = 0.0;
WinDrawChars("*", 1, MCXVal-8, MCYVal+1);
} else if (MCCurDispVal > 5.0*data.config.mcrngmult) {
MCCurDispVal = 5.0*data.config.mcrngmult;
WinDrawChars("*", 1, MCXVal-8, 60 + MCYVal+1);
} else {
WinDrawChars("*", 1, MCXVal-8, (Int16)(MCCurVal*data.input.lftconst/data.config.mcrngmult/MCMult*12) + MCYVal+1);
}
FntSetFont(stdFont);
#else
// calculate position of "*" in MC / STF grid
MCCurDispVal = pround(MCCurVal*data.input.lftconst/data.config.mcrngmult/MCMult, 0) * data.config.mcrngmult;
if (MCCurDispVal < 0.0) {
MCCurDispVal = 0.0;
}
if (MCCurDispVal > 5.0*data.config.mcrngmult) {
MCCurDispVal = 5.0*data.config.mcrngmult;
}
#endif
rectP.topLeft.x = GPSX;
rectP.topLeft.y = GPSY;
rectP.extent.x = GPSXOFF+1;
rectP.extent.y = GPSYOFF;
if (!recv_data || (nogpstime > 0)) {
WinEraseRectangle(&rectP, 0);
FntSetFont(boldFont);
WinDrawInvertedChars(" NO GPS", 7, GPSX, GPSY);
FntSetFont(stdFont);
clearrect = true;
} else if (StrCompare(data.logger.gpsstat, "V") == 0) {
WinEraseRectangle(&rectP, 0);
FntSetFont(boldFont);
WinDrawInvertedChars("NOSATS", 6, GPSX, GPSY);
FntSetFont(stdFont);
clearrect = true;
} else {
if (clearrect) {
WinEraseRectangle(&rectP, 0);
clearrect = false;
}
if (!sim_gps) {
StrCopy(tempchar, "G");
StrCat(tempchar, data.input.gpsnumsats);
field_set_value(form_final_glide_gpsstat, tempchar);
} else {
FntSetFont(boldFont);
WinDrawInvertedChars(" SIM ", 5, GPSX, GPSY);
FntSetFont(stdFont);
}
}
// Update the Headwind Value when it has changed
if (data.config.hwposlabel) {
// HostTraceOutputTL(appErrorClass, "data.input.headwind1 =|%s|", DblToStr(data.input.headwind, 1));
field_set_value(form_final_glide_headwind, DblToStr(pround(data.input.headwind*data.input.wndconst,1),1));
} else {
// HostTraceOutputTL(appErrorClass, "data.input.headwind2 =|%s|", DblToStr(data.input.headwind, 1));
field_set_value(form_final_glide_headwind, DblToStr(pround(data.input.headwind*data.input.wndconst*(-1),1),1));
}
// Update the Course to the Waypoint Arrow
DrawFGWayLine(ARROWCENTX, ARROWCENTY);
}
void final_glide_event0()
{
if (data.input.distance_to_destination.valid == VALID) {
final_glide_mc(0.0*data.config.mcrngmult,form_final_glide_0_speed, form_final_glide_0_alt);
} else {
field_set_value(form_final_glide_0_speed, "");
field_set_value(form_final_glide_0_alt, "");
}
if ((StrCompare(data.input.destination_name, ",") == 0 || StrLen(data.input.destination_name) == 0)) {
field_set_value(form_final_glide_waypt, "Not Selected");
} else {
switch (glidingtoheight) {
case STARTHEIGHT:
// gliding to max start height so change name
field_set_value(form_final_glide_waypt, "Start Height");
break;
case FINISHHEIGHT:
// gliding to min finish height so change name
field_set_value(form_final_glide_waypt, "Finish Height");
break;
case ELEVATION:
default:
// display target name normally
field_set_value(form_final_glide_waypt, data.input.destination_name);
break;
}
if (data.config.usepalmway) {
field_set_value(form_final_glide_wayelev, print_altitude(data.input.destination_elev));
WinDrawChars(data.input.alttext, 2, 51, 123);
} else {
field_set_value(form_final_glide_wayelev, print_altitude(data.input.destination_elev));
}
}
}
void final_glide_event1()
{
double tempdbl, remainder;
if (data.input.distance_to_destination.valid == VALID) {
final_glide_mc(1.0*data.config.mcrngmult,form_final_glide_1_speed,form_final_glide_1_alt);
} else {
field_set_value(form_final_glide_1_speed, "");
field_set_value(form_final_glide_1_alt, "");
}
if (data.config.lftunits == STATUTE) {
tempdbl = pround(data.input.basemc*data.input.lftconst, data.input.lftprec);
remainder = pround(Fmod(tempdbl, data.input.lftincr), data.input.lftprec);
if (remainder > (data.input.lftincr/2.0)) {
tempdbl = tempdbl - remainder + data.input.lftincr;
} else {
tempdbl = tempdbl - remainder;
}
field_set_value(form_final_glide_basemc, DblToStr(pround(tempdbl, data.input.lftprec), data.input.lftprec));
} else {
field_set_value(form_final_glide_basemc,
DblToStr(pround(data.input.basemc*data.input.lftconst, data.input.lftprec),
data.input.lftprec));
}
}
void final_glide_event2()
{
if (data.input.distance_to_destination.valid == VALID) {
final_glide_mc(2.0*data.config.mcrngmult,form_final_glide_2_speed, form_final_glide_2_alt);
} else {
field_set_value(form_final_glide_2_speed, "");
field_set_value(form_final_glide_2_alt, "");
}
}
void final_glide_event3()
{
if (data.input.distance_to_destination.valid == VALID) {
final_glide_mc(3.0*data.config.mcrngmult,form_final_glide_3_speed, form_final_glide_3_alt);
} else {
field_set_value(form_final_glide_3_speed, "");
field_set_value(form_final_glide_3_alt, "");
}
}
void final_glide_event4()
{
if (data.input.distance_to_destination.valid == VALID) {
final_glide_mc(4.0*data.config.mcrngmult,form_final_glide_4_speed, form_final_glide_4_alt);
} else {
field_set_value(form_final_glide_4_speed, "");
field_set_value(form_final_glide_4_alt, "");
}
}
void final_glide_event5()
{
if (data.input.distance_to_destination.valid == VALID) {
final_glide_mc(5.0*data.config.mcrngmult,form_final_glide_5_speed, form_final_glide_5_alt);
} else {
field_set_value(form_final_glide_5_speed, "");
field_set_value(form_final_glide_5_alt, "");
}
}
void Update_Fltinfo(Int16 fltindex, Boolean listactive, Boolean fltinfo)
{
Char tempchar[30];
DateTimeType strtdt, stopdt;
UInt32 startsecs, stopsecs, lengthsecs, elapsedsecs;
MemHandle flt_hand;
MemPtr flt_ptr;
double ld, speed;
UInt16 TAKEOFFSET;
Int16 n, nrecs;
// HostTraceOutputTL(appErrorClass, "Update_Fltinfo");
nrecs = OpenDBCountRecords(flight_db);
if (listactive && (nrecs > 0) && (data.task.numwaypts <= 0)) {
frm_set_title("Flight/Task Info");
// flight selector
ctl_set_enable(form_flt_info_pop1, true);
ctl_set_visible(form_flt_info_flightlbl, true);
ctl_set_visible(form_flt_info_pop1, true);
// graphing buttons
ctl_set_visible(form_flt_info_graphbtn, true);
ctl_set_visible(form_flt_info_graphbtn2, true);
ctl_set_visible(form_flt_info_graphbtn3, true);
// task label / button
ctl_set_visible(form_flt_info_taskbtnlbl, true);
ctl_set_visible(form_flt_info_taskbtn, false);
// glide ratios
ctl_set_visible(form_flt_info_ldilabel, false);
ctl_set_visible(form_flt_info_ldi, false);
ctl_set_visible(form_flt_info_ldalabel, false);
ctl_set_visible(form_flt_info_lda, false);
ctl_set_visible(form_flt_info_ldrlabel, false);
ctl_set_visible(form_flt_info_ldr, false);
// speed fields
ctl_set_visible(form_flt_info_avgtskspd, false);
ctl_set_visible(form_flt_info_speedreqdlbl2, false);
ctl_set_visible(form_flt_info_speedreqd, false);
ctl_set_visible(form_flt_info_speedreqdlbl, false);
// old items
// ctl_set_visible(form_flt_info_resetlbl, false);
// ctl_set_visible(form_flt_info_ldlabel, false);
// ctl_set_visible(form_flt_info_tsketa_label, false);
// ctl_set_visible(form_flt_info_tskstop_label, true);
frm_set_label(form_flt_info_tskspdlbl, "Avg:");
frm_set_label(form_flt_info_spdlbl, data.input.tskspdtext);
FltInfoshowMC = false;
} else {
// current waypoint info
if (data.task.numwaypts <= 0) {
frm_set_title("Flight/Task Info");
} else if ((StrCompare(data.input.destination_name, ",") == 0 || StrLen(data.input.destination_name) == 0)) {
frm_set_title("Not Selected");
} else {
frm_set_title(data.input.destination_name);
}
// flight selectors
if (nrecs > 0) ctl_set_label(form_flt_info_pop1, "Current");
ctl_set_enable(form_flt_info_pop1, false);
ctl_set_visible(form_flt_info_flightlbl, false);
ctl_set_visible(form_flt_info_pop1, false);
// graphing buttons
ctl_set_visible(form_flt_info_graphbtn, false);
ctl_set_visible(form_flt_info_graphbtn2, false);
ctl_set_visible(form_flt_info_graphbtn3, false);
// task label / button
ctl_set_visible(form_flt_info_taskbtn, false);
ctl_set_visible(form_flt_info_taskbtnlbl, true);
// glide ratios
ctl_set_visible(form_flt_info_ldilabel, true);
ctl_set_visible(form_flt_info_ldi, true);
ctl_set_visible(form_flt_info_ldalabel, true);
ctl_set_visible(form_flt_info_lda, true);
ctl_set_visible(form_flt_info_ldrlabel, true);
ctl_set_visible(form_flt_info_ldr, true);
// speed fields
// ctl_set_visible(form_flt_info_avgtskspd, false);
// ctl_set_visible(form_flt_info_speedreqdlbl2, false);
// ctl_set_visible(form_flt_info_speedreqd, false);
// ctl_set_visible(form_flt_info_speedreqdlbl, false);
// old times
// ctl_set_visible(form_flt_info_resetlbl, true);
// ctl_set_visible(form_flt_info_ldlabel, true);
// if (nrecs > 0) {
// ctl_set_visible(form_flt_info_tskstop_label, false);
// ctl_set_visible(form_flt_info_tsketa_label, true);
// }
frm_set_label(form_flt_info_tskspdlbl, "MC:");
frm_set_label(form_flt_info_spdlbl, data.input.lfttext);
FltInfoshowMC = true;
}
if (nrecs > 0) {
OpenDBQueryRecord(flight_db, fltindex, &flt_hand, &flt_ptr);
MemMove(fltdata, flt_ptr, sizeof(FlightData));
MemHandleUnlock(flt_hand);
} else {
MemSet(fltdata, sizeof(FlightData), 0);
}
//****************************************************************************
// FLIGHT INFO
//****************************************************************************
if (fltinfo) { // Update the flight information
// calculate glide angles
/* // instant
if ((data.input.ground_speed.valid == VALID) && (data.input.curlift != 0.0)) {
ld = -data.input.ground_speed.value / data.input.curlift;
n = 1;
if (Fabs(ld) >= 100) n = 0;
if (Fabs(ld) >= 999) ld = 999;
field_set_value(form_flt_info_ldi, DblToStr(ld,n));
} else {
field_set_value(form_flt_info_ldi, "XX");
}
*/
// since last thermal
if (thmode == THERMAL) {
ld = data.input.lastglide;
n = 1;
if (Fabs(ld) >= 100) n = 0;
if (Fabs(ld) >= 999) ld = 999;
field_set_value(form_flt_info_ldi, DblToStr(ld,n));
} else if ((data.input.distance_to_destination.valid == VALID) && ((data.input.startcruisealt - data.input.inusealt) != 0.0)) {
ld = (data.input.startcruisedist - data.input.distance_to_destination.value)*DISTFTCONST / (data.input.startcruisealt - data.input.inusealt);
n = 1;
if (Fabs(ld) >= 100) n = 0;
if (Fabs(ld) >= 999) ld = 999;
field_set_value(form_flt_info_ldi, DblToStr(ld,n));
} else {
field_set_value(form_flt_info_ldi, "XX");
}
// average
if ((data.input.distdone != 0.0) && (data.input.avglift != 0.0)) {
ld = -data.input.distdone*2*60 / data.input.avglift; // assuming 30 sec average
n = 1;
if (Fabs(ld) >= 100) n = 0;
if (Fabs(ld) >= 999) ld = 999;
field_set_value(form_flt_info_lda, DblToStr(ld,n));
} else {
field_set_value(form_flt_info_lda, "XX");
}
// required (including safety height)
if ((data.input.distance_to_destination.valid == VALID) && (data.input.inusealt - (data.input.destination_elev + data.config.safealt) != 0.0)) {
ld = data.input.distance_to_destination.value*DISTFTCONST / (data.input.inusealt - (data.input.destination_elev + data.config.safealt));
n = 1;
if (Fabs(ld) >= 100) n = 0;
if (Fabs(ld) >= 999) ld = 999;
field_set_value(form_flt_info_ldr, DblToStr(ld,n));
} else {
field_set_value(form_flt_info_ldr, "XX");
}
// flight start
// Copy the flight DTG(MMDDYY) into the Start DateTime Structure
// Copy the Start time UTC (HHMMSS) into the Start DateTime Structure
StringToDateAndTime(fltdata->startdtg, fltdata->startutc, &strtdt);
startsecs = TimDateTimeToSeconds(&strtdt);
SecondsToDateOrTimeString(startsecs, tempchar, 1, (Int32)data.config.timezone);
field_set_value(form_flt_info_start, tempchar);
// flight stop
// Copy the flight Stop DTG(MMDDYY) into the Stop DateTime Structure and
// Copy the flight Stop time UTC (HHMMSS) into the Stop DateTime Structure
// If the flight is not in progress.
// If the flight is in progress, use the current GPS DTG and UTC
if (inflight) {
//StringToDateAndTime(data.logger.gpsdtg, data.logger.gpsutc, &stopdt);
//stopsecs = TimDateTimeToSeconds(&stopdt);
stopsecs = utcsecs;
} else {
StringToDateAndTime(fltdata->stopdtg, fltdata->stoputc, &stopdt);
stopsecs = TimDateTimeToSeconds(&stopdt);
}
SecondsToDateOrTimeString(stopsecs, tempchar, 1, (Int32)data.config.timezone);
field_set_value(form_flt_info_stop, tempchar);
// flight length
// Calculate flt length & convert HH:MM:SS for display
if (startsecs > stopsecs) lengthsecs = 0; else lengthsecs = stopsecs - startsecs;
SecondsToDateOrTimeString(lengthsecs, tempchar, 1, 0);
field_set_value(form_flt_info_length,tempchar);
// max alt
if (fltdata->maxalt == -999.9) {
field_set_value(form_flt_info_maxalt,print_altitude(data.input.maxalt));
} else {
field_set_value(form_flt_info_maxalt,print_altitude(fltdata->maxalt));
}
// % thermal
if (inflight) {
if (data.flight.stopidx > data.flight.startidx) {
field_set_value(form_flt_info_pctthermal, DblToStr((((double)thermalcount/(double)(data.flight.stopidx - data.flight.startidx))*100.0), 1));
}else {
field_set_value(form_flt_info_pctthermal, "0.0");
}
} else {
field_set_value(form_flt_info_pctthermal, DblToStr((fltdata->pctthermal*100.0), 1));
}
// terrain height
if (terrainvalid) {
field_set_value(form_flt_info_terelev, print_altitude(data.input.terelev));
} else {
field_set_value(form_flt_info_terelev, "N/A");
}
//****************************************************************************
// TASK INFO
//****************************************************************************
} else { // Update the task information
// HostTraceOutputTL(appErrorClass, "Update_Fltinfo - Logs");
// HostTraceOutputTL(appErrorClass, " fltdata->tskstartutc-|%s|", fltdata->tskstartutc);
// HostTraceOutputTL(appErrorClass, " nrecs-|%hd|", nrecs);
// HostTraceOutputTL(appErrorClass, " fltdata->flttask.numwaypts-|%hu|", fltdata->flttask.numwaypts);
if ((StrCompare(fltdata->tskstartutc, "NT") != 0) && (nrecs > 0) && (fltdata->flttask.numwaypts > 0)) {
// HostTraceOutputTL(appErrorClass, "Update_Fltinfo - Task set so update task info");
//********************
// task started
//********************
// show task button or label when the logger is not running
if (listactive && (data.task.numwaypts <= 0)) {
ctl_set_visible(form_flt_info_taskbtnlbl, false);
ctl_set_visible(form_flt_info_taskbtn, true);
}
// task start time
// Copy the flight DTG(MMDDYY) into the Start & Stop DateTime Structure
// Copy the task Start time utc (HHMMSS) into the Start DateTime Structure
if (tasknotfinished && inflight) {
startsecs = data.activetask.tskstartsecs;
} else {
StringToDateAndTime(fltdata->tskstartdtg, fltdata->tskstartutc, &strtdt);
startsecs = TimDateTimeToSeconds(&strtdt);
}
SecondsToDateOrTimeString(startsecs, tempchar, 1, (Int32)data.config.timezone);
field_set_value(form_flt_info_tskstart, tempchar);
// start height
// Check for request to change start height alt ref
if (chgstartaltref) {
if (fltdata->flttask.startaltref == MSL) {
fltdata->flttask.startaltref = AGL;
} else {
fltdata->flttask.startaltref = MSL;
}
}
// Copy the task start height
if (fltdata->flttask.startaltref == AGL) {
// display above start point value
if (fltdata->flttask.hastakeoff) TAKEOFFSET = 1; else TAKEOFFSET = 0;
StrCopy(tempchar, print_altitude(fltdata->startheight - fltdata->flttask.elevations[TAKEOFFSET]));
ctl_set_visible(form_flt_info_tskstartaltMSL, false);
ctl_set_visible(form_flt_info_tskstartaltAGL, true);
} else {
// display MSL value
StrCopy(tempchar, print_altitude(fltdata->startheight));
ctl_set_visible(form_flt_info_tskstartaltAGL, false);
ctl_set_visible(form_flt_info_tskstartaltMSL, true);
}
// check start height
if ((data.task.numwaypts > 0) && (data.activetask.tskstartsecs == 0)) {
StrCopy(tempchar, "0");
}
field_set_value(form_flt_info_tskstartalt, tempchar);
// task stop
// Copy the task Stop DTG(MMDDYY) into the Stop DateTime Structure and
// Copy the task Stop time UTC (HHMMSS) into the Stop DateTime Structure
// If the task is not in progress.
// If the task is in progress, use the current GPS DTG and UTC
// Copy the task Stop time UTC (HHMMSS) into the Stop DateTime Structure
if (tasknotfinished && inflight) {
fltdata->tskdist = data.flight.tskdist;
fltdata->flttask.ttldist = data.task.ttldist;
fltdata->tskspeed = data.flight.tskspeed;
stopsecs = data.activetask.tskstopsecs;
} else {
StringToDateAndTime(fltdata->tskstopdtg, fltdata->tskstoputc, &stopdt);
stopsecs = TimDateTimeToSeconds(&stopdt);
}
SecondsToDateOrTimeString(stopsecs, tempchar, 1, (Int32)data.config.timezone);
// task elapsed
// Calculate task elapsed time & convert HH:MM:SS for display
if (startsecs > stopsecs) lengthsecs = 0; else lengthsecs = stopsecs - startsecs;
if (startsecs > 0) {
elapsedsecs = lengthsecs;
} else {
elapsedsecs = 0;
}
SecondsToDateOrTimeString(elapsedsecs, tempchar, 1, 0);
field_set_value(form_flt_info_tskelapsed, tempchar);
// task dist done
field_set_value(form_flt_info_tskdist, print_distance2(fltdata->tskdist,1));
// task dist to go
field_set_value(form_flt_info_disttogo, print_distance2(fltdata->flttask.ttldist - fltdata->tskdist,1));
// task total dist or MC
field_set_value(form_flt_info_tskttldist, print_distance2(fltdata->flttask.ttldist,1));
// task speed
if (FltInfoshowMC) {
field_set_value(form_flt_info_tskspd, DblToStr(pround(data.input.basemc*data.input.lftconst, data.input.lftprec), data.input.lftprec));
} else {
field_set_value(form_flt_info_tskspd, DblToStr(pround(fltdata->tskspeed*data.input.tskspdconst,1),1));
}
//********************
// logger not running
//********************
if (listactive) {
// don't show required task speeds or time to go
ctl_set_visible(form_flt_info_speedreqd, false);
ctl_set_visible(form_flt_info_speedreqdlbl, false);
ctl_set_visible(form_flt_info_avgtskspd, false);
ctl_set_visible(form_flt_info_speedreqdlbl2, false);
field_set_value(form_flt_info_timetogo, " ");
// current time on task
SecondsToDateOrTimeString(lengthsecs, tempchar, 1, 0);
field_set_value(form_flt_info_tskarrive,tempchar);
// task finish time
SecondsToDateOrTimeString(stopsecs, tempchar, 1, (Int32)data.config.timezone);
field_set_value(form_flt_info_tskstop, tempchar);
// show variance to specified task time
if (fltdata->flttask.rulesactive && (fltdata->flttask.mintasktime > 0)) {
field_set_value(form_flt_info_early, CalcTOTvar(lengthsecs/60, fltdata->flttask.mintasktime));
field_set_value(form_flt_info_speedtype, "OTA");
} else {
field_set_value(form_flt_info_early, " ");
field_set_value(form_flt_info_speedtype, " ");
}
} else {
//********************
// in flight
//********************
// estimated total time on task
if (!taskonhold) {
if (!tasknotfinished) {
// task finished so show actual task stop time.
SecondsToDateOrTimeString(lengthsecs, tempchar, 1, 0);
field_set_value(form_flt_info_tskarrive, tempchar);
} else if ((data.flight.tskspeed > 0.0) || (data.input.Vxc > 0.0)) {
if (data.activetask.TOTsecs > 0) lengthsecs = data.activetask.TOTsecs; else lengthsecs = 0;
SecondsToDateOrTimeString(lengthsecs, tempchar, 1, 0);
field_set_value(form_flt_info_tskarrive,tempchar);
} else {
// task speed not valid, cannot calculate TOT
field_set_value(form_flt_info_tskarrive,"N/A");
}
} else {
// task on hold
field_set_value(form_flt_info_tskarrive, "On Hold");
}
// estimated task finish
if (!taskonhold) {
if (data.flight.tskspeed > 0.0) {
// Use task speed
SecondsToDateOrTimeString(lengthsecs+startsecs, tempchar, 1, (Int32)data.config.timezone);
field_set_value(form_flt_info_tskstop, tempchar);
} else {
field_set_value(form_flt_info_tskstop, "N/A");
}
} else {
// task on hold
field_set_value(form_flt_info_tskstop, "On Hold");
}
// show variance to specified task time and speed required
if (!taskonhold) {
// speed units
field_set_value(form_flt_info_speedreqdlbl, data.input.tskspdtext);
field_set_value(form_flt_info_speedreqdlbl2, data.input.tskspdtext);
if ((data.flight.tskspeed <= 0.0) && (data.input.Vxc <= 0.0)) {