/
saitekpanels.cpp
2724 lines (2095 loc) · 105 KB
/
saitekpanels.cpp
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
// ****** saitekpanels.cpp ***********
// **** William R. Good ***********
// ******** ver 1.46 ***************
// ****** Nov 04 2012 **************
#include "XPLMDisplay.h"
#include "XPLMGraphics.h"
#include "XPLMUtilities.h"
#include "XPLMDataAccess.h"
#include "XPLMProcessing.h"
#include "XPLMPlugin.h"
#include "XPLMPlanes.h"
#include "XPLMMenus.h"
#include "XPWidgets.h"
#include "XPStandardWidgets.h"
#define MSG_ADD_DATAREF 0x01000000
#include "hidapi.h"
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
//#include <string>
#include <string.h>
#include <time.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <list>
#include "saitekpanels.h"
using namespace std;
// ************* Radio Panel Command Ref ****************
XPLMCommandRef Com1StbyFineDn = NULL, Com1StbyFineUp = NULL, Com1StbyCorseDn = NULL, Com1StbyCorseUp = NULL;
XPLMCommandRef Com2StbyFineDn = NULL, Com2StbyFineUp = NULL, Com2StbyCorseDn = NULL, Com2StbyCorseUp = NULL;
XPLMCommandRef Nav1StbyFineDn = NULL, Nav1StbyFineUp = NULL, Nav1StbyCorseDn = NULL, Nav1StbyCorseUp = NULL;
XPLMCommandRef Nav2StbyFineDn = NULL, Nav2StbyFineUp = NULL, Nav2StbyCorseDn = NULL, Nav2StbyCorseUp = NULL;
XPLMCommandRef Afd1StbyHunUp = NULL, Afd1StbyHunDn = NULL, Afd1StbyTensUp = NULL, Afd1StbyTensDn = NULL;
XPLMCommandRef Afd1StbyOnesUp = NULL, Afd1StbyOnesDn = NULL;
XPLMCommandRef Afd2StbyHunUp = NULL, Afd2StbyHunDn = NULL, Afd2StbyTensUp = NULL, Afd2StbyTensDn = NULL;
XPLMCommandRef Afd2StbyOnesUp = NULL, Afd2StbyOnesDn = NULL;
XPLMCommandRef XpdrThUp = NULL, XpdrThDn = NULL, XpdrHunUp = NULL, XpdrHunDn = NULL;
XPLMCommandRef XpdrTensUp = NULL, XpdrTensDn = NULL, XpdrOnesUp = NULL, XpdrOnesDn = NULL;
XPLMCommandRef BaroUp = NULL, BaroDn = NULL, BaroStd = NULL;
XPLMCommandRef Com1ActStby = NULL, Com2ActStby = NULL, Nav1ActStby = NULL, Nav2ActStby = NULL;
XPLMCommandRef Adf1ActStby = NULL, Adf2ActStby = NULL;
// ************* Radio Panel Data Ref ****************
XPLMDataRef Com1ActFreq = NULL, Com2ActFreq = NULL, Nav1ActFreq = NULL, Nav2ActFreq = NULL;
XPLMDataRef Com1StbyFreq = NULL, Com2StbyFreq = NULL, Nav1StbyFreq = NULL, Nav2StbyFreq = NULL;
XPLMDataRef Adf1StbyFreq = NULL, Adf2StbyFreq = NULL;
XPLMDataRef Adf1ActFreq = NULL, Adf2ActFreq = NULL;
XPLMDataRef XpdrCode = NULL, XpdrMode = NULL, BaroSetting = NULL;
XPLMDataRef MetricPress = NULL;
XPLMDataRef DmeMode = NULL, DmeSlvSource = NULL;
XPLMDataRef Nav1DmeNmDist = NULL, Nav1DmeSpeed = NULL;
XPLMDataRef Nav2DmeNmDist = NULL, Nav2DmeSpeed = NULL;
XPLMDataRef DmeFreq = NULL, DmeTime = NULL, DmeSpeed = NULL;
XPLMDataRef AvPwrOn = NULL, BatPwrOn = NULL;
XPLMDataRef Nav1PwrOn = NULL, Nav2PwrOn = NULL, Com1PwrOn = NULL, Com2PwrOn = NULL;
XPLMDataRef Afd1PwrOn = NULL, DmePwrOn = NULL;
XPLMMenuID RadioMenu;
XPLMMenuID RadioMenuId;
XPWidgetID RadioWidgetID = NULL;
XPWidgetID RadioWindow = NULL;
XPWidgetID RadioSpeed1CheckWidget[50] = {NULL};
XPWidgetID RadioSpeed2CheckWidget[50] = {NULL};
XPWidgetID RadioSpeed3CheckWidget[50] = {NULL};
XPWidgetID RadioSpeed4CheckWidget[50] = {NULL};
XPWidgetID RadioSpeed5CheckWidget[50] = {NULL};
XPWidgetID RadioSpeedTextWidget[50] = {NULL};
XPWidgetID RadioAdf1CheckWidget[50] = {NULL};
XPWidgetID RadioAdf2CheckWidget[50] = {NULL};
XPWidgetID RadioAdf1TextWidget[50] = {NULL};
XPWidgetID RadioAdf2TextWidget[50] = {NULL};
XPWidgetID RadioQnh0CheckWidget[50] = {NULL};
XPWidgetID RadioQnh1CheckWidget[50] = {NULL};
XPWidgetID RadioQnh0TextWidget[50] = {NULL};
XPWidgetID RadioQnh1TextWidget[50] = {NULL};
// ****************** Multi Panel Command Ref **********************
XPLMCommandRef ApAltDn = NULL, ApAltUp = NULL, ApVsDn = NULL, ApVsUp = NULL;
XPLMCommandRef ApAsDn = NULL, ApAsUp = NULL, ApHdgDn = NULL, ApHdgUp = NULL;
XPLMCommandRef ApCrsDn = NULL, ApCrsUp = NULL, ApCrsDn2 = NULL, ApCrsUp2 = NULL;
XPLMCommandRef ApMstrBtnUp = NULL, ApMstrBtnDn = NULL, ApMstrBtnOff = NULL;
XPLMCommandRef ApHdgBtn = NULL, ApNavBtn = NULL, ApAltBtn = NULL;
XPLMCommandRef ApIasBtn = NULL;
XPLMCommandRef ApVsBtn = NULL, ApAprBtn = NULL, ApRevBtn = NULL;
XPLMCommandRef FlapsDn = NULL, FlapsUp = NULL;
XPLMCommandRef PitchTrimDn = NULL, PitchTrimUp = NULL, PitchTrimTkOff = NULL;
XPLMCommandRef XpanelsFnButtonCommand = NULL, XpanelsCrsToggleCommand = NULL;
XPLMCommandRef x737mcp_cmd_a_toggle = NULL;
XPLMCommandRef x737mcp_hdg_up = NULL, x737mcp_hdg_down = NULL;
XPLMCommandRef x737mcp_hdg_up_fast = NULL, x737mcp_hdg_down_fast = NULL;
XPLMCommandRef x737mcp_spd_up = NULL, x737mcp_spd_down = NULL;
XPLMCommandRef x737mcp_spd_up_fast = NULL, x737mcp_spd_down_fast = NULL;
XPLMCommandRef x737mcp_alt_up = NULL, x737mcp_alt_down = NULL;
XPLMCommandRef x737mcp_alt_up_fast = NULL, x737mcp_alt_down_fast = NULL;
XPLMCommandRef x737mcp_vvi_up = NULL, x737mcp_vvi_down = NULL;
XPLMCommandRef x737mcp_vvi_up_fast = NULL, x737mcp_vvi_down_fast = NULL;
XPLMCommandRef x737mcp_hdg_toggle = NULL, x737mcp_vorloc_toggle = NULL;
XPLMCommandRef x737mcp_lvlchange_toggle = NULL, x737mcp_alt_toggle = NULL;
XPLMCommandRef x737mcp_vs_toggle = NULL, x737mcp_app_toggle = NULL;
XPLMCommandRef x737mcp_spd_changeover = NULL, x737mcp_lnav_toggle = NULL;
XPLMCommandRef NavButtonRemapableCmd = NULL, AprButtonRemapableCmd = NULL;
XPLMCommandRef RevButtonRemapableCmd = NULL;
XPLMCommandRef ApVsUpRemapableCmd = NULL, ApVsDnRemapableCmd = NULL;
// ***************** Multi Panel Data Ref *********************
XPLMDataRef ApAlt = NULL, ApVs = NULL, ApAs = NULL, ApHdg = NULL, ApCrs = NULL, ApCrs2 = NULL;
XPLMDataRef ApMstrStat = NULL, ApHdgStat = NULL, ApNavStat = NULL, ApIasStat = NULL;
XPLMDataRef ApAltStat = NULL, ApVsStat = NULL, ApAprStat = NULL, ApRevStat = NULL;
XPLMDataRef x737athr_armed = NULL, x737swBatBus = NULL, x737stbyPwr = NULL;
XPLMDataRef ApState = NULL, ApAutThr;
XPLMDataRef Frp = NULL, MHdg = NULL;
XPLMDataRef AirspeedIsMach = NULL, Airspeed = NULL;
XPLMDataRef x737mcp_hdg = NULL, x737mcp_alt = NULL;
XPLMDataRef x737mcp_vs = NULL, x737mcp_vs_arm = NULL;
XPLMDataRef x737mcp_cmd_a_led = NULL;
XPLMDataRef x737mcp_hdg_led = NULL, x737mcp_vorloc_led = NULL, x737mcp_vorloc_armed = NULL;
XPLMDataRef x737mcp_lnav = NULL, x737mcp_lnav_armed = NULL;
XPLMDataRef x737mcp_lvlchange_led = NULL, x737mcp_alt_led = NULL;
XPLMDataRef x737mcp_vvi_led = NULL, x737mcp_vvi_armed_led = NULL, x737mcp_app_led = NULL;
XPLMDataRef HsiSelector = NULL;
XPLMMenuID MultiMenu;
XPLMMenuID MultiMenuId;
XPWidgetID MultiWidgetID = NULL;
XPWidgetID MultiWindow = NULL;
XPWidgetID MultiSpeed1CheckWidget[50] = {NULL};
XPWidgetID MultiSpeed2CheckWidget[50] = {NULL};
XPWidgetID MultiSpeed3CheckWidget[50] = {NULL};
XPWidgetID MultiSpeed4CheckWidget[50] = {NULL};
XPWidgetID MultiSpeed5CheckWidget[50] = {NULL};
XPWidgetID MultiSpeedTextWidget[50] = {NULL};
XPWidgetID MultiTrimSpeed1CheckWidget[50] = {NULL};
XPWidgetID MultiTrimSpeed2CheckWidget[50] = {NULL};
XPWidgetID MultiTrimSpeed3CheckWidget[50] = {NULL};
XPWidgetID MultiTrimSpeedTextWidget[50] = {NULL};
XPWidgetID MultiAt0CheckWidget[50] = {NULL};
XPWidgetID MultiAt1CheckWidget[50] = {NULL};
XPWidgetID MultiAt0TextWidget[50] = {NULL};
XPWidgetID MultiAt1TextWidget[50] = {NULL};
// *************** Switch Panel Command Ref *******************
XPLMCommandRef ClFlOpn = NULL, ClFlCls = NULL;
XPLMCommandRef PtHtOn = NULL, PtHtOff = NULL;
XPLMCommandRef PtHt0On = NULL, PtHt0Off = NULL, PtHt1On = NULL, PtHt1Off = NULL;
XPLMCommandRef AvLtOn = NULL, AvLtOff = NULL, BatOn = NULL, BatOff = NULL;
XPLMCommandRef LnLtOn = NULL, LnLtOff = NULL, TxLtOn = NULL, TxLtOff = NULL;
XPLMCommandRef StLtOn = NULL, StLtOff = NULL, NvLtOn = NULL, NvLtOff = NULL;
XPLMCommandRef BcLtOn = NULL, BcLtOff = NULL, GearUp = NULL, GearDn = NULL;
XPLMCommandRef MagOffSwitchOnCmd = NULL, MagOffSwitchOffCmd = NULL;
XPLMCommandRef MagRightSwitchOnCmd = NULL, MagRightSwitchOffCmd = NULL;
XPLMCommandRef MagLeftSwitchOnCmd = NULL, MagLeftSwitchOffCmd = NULL;
XPLMCommandRef MagBothSwitchOnCmd = NULL, MagBothSwitchOffCmd = NULL;
XPLMCommandRef MagStartSwitchOnCmd = NULL, MagStartSwitchOffCmd = NULL;
XPLMCommandRef BatMasterSwitchOnCmd = NULL, BatMasterSwitchOffCmd = NULL;
XPLMCommandRef AltMasterSwitchOnCmd = NULL, AltMasterSwitchOffCmd = NULL;
XPLMCommandRef AvMasterSwitchOnCmd = NULL, AvMasterSwitchOffCmd = NULL;
XPLMCommandRef FuelPumpOnCmd = NULL, FuelPumpOffCmd = NULL;
XPLMCommandRef DeiceOnCmd = NULL, DeiceOffCmd = NULL;
XPLMCommandRef PitotHeatOnCmd = NULL, PitotHeatOffCmd = NULL;
XPLMCommandRef GearUpCmd = NULL, GearDnCmd = NULL;
XPLMCommandRef CowlFlapsOpenCmd = NULL, CowlFlapsCloseCmd = NULL;
XPLMCommandRef PanelLightsOnCmd = NULL, PanelLightsOffCmd = NULL;
XPLMCommandRef BeaconLightsOnCmd = NULL, BeaconLightsOffCmd = NULL;
XPLMCommandRef NavLightsOnCmd = NULL, NavLightsOffCmd = NULL;
XPLMCommandRef StrobeLightsOnCmd = NULL, StrobeLightsOffCmd = NULL;
XPLMCommandRef TaxiLightsOnCmd = NULL, TaxiLightsOffCmd = NULL;
XPLMCommandRef LandingLightsOnCmd = NULL, LandingLightsOffCmd = NULL;
XPLMCommandRef MagOff1 = NULL, MagOff2 = NULL, MagOff3 = NULL, MagOff4 = NULL;
XPLMCommandRef MagOff5 = NULL, MagOff6 = NULL, MagOff7 = NULL, MagOff8 = NULL;
XPLMCommandRef MagLeft1 = NULL, MagLeft2 = NULL, MagLeft3 = NULL, MagLeft4 = NULL;
XPLMCommandRef MagLeft5 = NULL, MagLeft6 = NULL, MagLeft7 = NULL, MagLeft8 = NULL;
XPLMCommandRef MagRight1 = NULL, MagRight2 = NULL, MagRight3 = NULL, MagRight4 = NULL;
XPLMCommandRef MagRight5 = NULL, MagRight6 = NULL, MagRight7 = NULL, MagRight8 = NULL;
XPLMCommandRef MagBoth1 = NULL, MagBoth2 = NULL, MagBoth3 = NULL, MagBoth4 = NULL;
XPLMCommandRef MagBoth5 = NULL, MagBoth6 = NULL, MagBoth7 = NULL, MagBoth8 = NULL;
XPLMCommandRef EngStart1 = NULL, EngStart2 = NULL, EngStart3 = NULL, EngStart4 = NULL;
XPLMCommandRef EngStart5 = NULL, EngStart6 = NULL, EngStart7 = NULL, EngStart8 = NULL;
XPLMCommandRef BatOn1 = NULL, BatOn2 = NULL, BatOff1 = NULL, BatOff2 = NULL;
XPLMCommandRef GenOn1 = NULL, GenOn2 = NULL, GenOn3 = NULL, GenOn4 = NULL;
XPLMCommandRef GenOn5 = NULL, GenOn6 = NULL, GenOn7 = NULL, GenOn8 = NULL;
XPLMCommandRef GenOff1 = NULL, GenOff2 = NULL, GenOff3 = NULL, GenOff4 = NULL;
XPLMCommandRef GenOff5 = NULL, GenOff6 = NULL, GenOff7 = NULL, GenOff8 = NULL;
XPLMCommandRef FuelPumpOn1 = NULL, FuelPumpOn2 = NULL, FuelPumpOn3 = NULL, FuelPumpOn4 = NULL;
XPLMCommandRef FuelPumpOn5 = NULL, FuelPumpOn6 = NULL, FuelPumpOn7 = NULL, FuelPumpOn8 = NULL;
XPLMCommandRef FuelPumpOff1 = NULL, FuelPumpOff2 = NULL, FuelPumpOff3 = NULL, FuelPumpOff4 = NULL;
XPLMCommandRef FuelPumpOff5 = NULL, FuelPumpOff6 = NULL, FuelPumpOff7 = NULL, FuelPumpOff8 = NULL;
XPLMCommandRef x737gen1_on = NULL, x737gen2_on = NULL;
XPLMCommandRef x737gen1_off = NULL, x737gen2_off = NULL;
XPLMCommandRef x737ice_pitot1_on = NULL, x737ice_pitot2_on = NULL;
XPLMCommandRef x737ice_pitot1_off = NULL, x737ice_pitot2_off = NULL;
XPLMCommandRef x737ice_engine1_on = NULL, x737ice_engine2_on = NULL;
XPLMCommandRef x737ice_engine1_off = NULL, x737ice_engine2_off = NULL;
XPLMCommandRef x737ice_wing_on = NULL, x737ice_wing_off = NULL;
// ******************* Switch Panel Data Ref ********************
XPLMDataRef BatNum = NULL, GenNum = NULL, EngNum = NULL;
XPLMDataRef BatArrayOnDR = NULL;
XPLMDataRef CowlFlaps = NULL, CockpitLights = NULL, AntiIce = NULL;
XPLMDataRef GearRetract = NULL, OnGround = NULL, LandingGearStatus = {NULL};
XPLMDataRef Gear1Fail = NULL, Gear2Fail = NULL, Gear3Fail = NULL;
XPLMMenuID SwitchMenu;
XPLMMenuID SwitchMenuId;
XPWidgetID SwitchWidgetID = NULL;
XPWidgetID SwitchWindow = NULL;
XPWidgetID SwitchEnableCheckWidget[50] = {NULL};
XPWidgetID SwitchDisableCheckWidget[50] = {NULL};
XPWidgetID SwitchRemapCheckWidget[50] = {NULL};
XPWidgetID SwitchBatAltCheckWidget[50] = {NULL};
XPWidgetID SwitchAltBatCheckWidget[50] = {NULL};
XPWidgetID SwitchBatAltTextWidget[50] = {NULL};
XPWidgetID SwitchAltBatTextWidget[50] = {NULL};
XPWidgetID SwitchLabelTextWidget[50] = {NULL};
XPWidgetID SwitchTextWidget[50] = {NULL};
typedef std::vector<XPLMDataRef> aXPLMDataRefID;
static aXPLMDataRefID DataRefID;
// ****************** BIP Panel Command Ref **********************
// ***************** BIP Panel Data Ref *********************
XPLMDataRef gTimeSimIsRunningXDataRef = NULL;
XPLMMenuID XsaitekpanelsMenu;
XPLMMenuID BipMenu;
XPLMMenuID BipMenuId, Bip2MenuId, Bip3MenuId, Bip4MenuId;
XPLMMenuID ConfigMenuId;
XPWidgetID XsaitekpanelsWidgetID = NULL;
XPWidgetID BipWidgetID = NULL;
XPWidgetID Bip2WidgetID = NULL;
XPWidgetID Bip3WidgetID = NULL;
XPWidgetID Bip4WidgetID = NULL;
// ********************** Radio Panel variables ************************
int radcnt = 0, radiores, stopradcnt;
int radres, radnum = 0;
float interval = -1;
static unsigned char blankradiowbuf[4][23];
static unsigned char radiobuf[4][4], radiowbuf[4][23];
unsigned char radbuf[4], radwbuf[21];
std::list<Radio *> radios;
int radspeed, numadf, metricpressenable;
void CreateRadioWidget(int x1, int y1, int w, int h);
int RadioHandler(XPWidgetMessage RadioinMessage, XPWidgetID RadioWidgetID, intptr_t inParam1, intptr_t inParam2);
int radioMenuItem;
char RadioSpeedText[50][200] = {
"FREQ KNOB 1 PULSE PER COMMAND",
"FREQ KNOB 2 PULSES PER COMMAND",
"FREQ KNOB 3 PULSES PER COMMAND",
"FREQ KNOB 4 PULSES PER COMMAND",
"FREQ KNOB 5 PULSES PER COMMAND",
"end"
};
hid_device *radiohandle[4];
// ********************** Multi Panel variables ***********************
int multicnt = 0, multires, stopmulticnt;
static unsigned char blankmultiwbuf[13];
unsigned char multibuf[4], multiwbuf[13];
int loaded737 = 0;
int trimspeed, multispeed, autothrottleswitchenable;
int navbuttonremap, aprbuttonremap, revbuttonremap;
int apvsupremap, apvsdnremap;
int xpanelsfnbutton = 0, xpanelscrstoggle = 0;
void CreateMultiWidget(int x1, int y1, int w, int h);
int MultiHandler(XPWidgetMessage MultiinMessage, XPWidgetID MultiWidgetID, intptr_t inParam1, intptr_t inParam2);
int multiMenuItem;
string nav_button_remapable, apr_button_remapable, rev_button_remapable;
string ap_vs_up_remapable, ap_vs_dn_remapable;
char MultiSpeedText[50][200] = {
"FREQ KNOB 1 PULSE PER COMMAND",
"FREQ KNOB 2 PULSES PER COMMAND",
"FREQ KNOB 3 PULSES PER COMMAND",
"FREQ KNOB 4 PULSES PER COMMAND",
"FREQ KNOB 5 PULSES PER COMMAND",
"end"
};
char MultiTrimSpeedText[50][200] = {
"TRIM X1",
"TRIM X2",
"TRIM X3",
"end"
};
hid_device *multihandle;
// ****************** Switch Panel variables *******************************
int switchcnt = 0, switchres, stopswitchcnt;
int magoffswitchenable, magrightswitchenable, magleftswitchenable;
int magbothswitchenable, magstartswitchenable;
int batmasterswitchenable, altmasterswitchenable;
int avionicsmasterswitchenable, fuelpumpswitchenable;
int deiceswitchenable, pitotheatswitchenable;
int landinggearknobupenable, landinggearknobdnenable;
int cowlflapsenable, panellightswitchenable;
int beaconlightswitchenable, navlightswitchenable;
int strobelightswitchenable, taxilightswitchenable;
int landinglightswitchenable, bataltinverse;
int panellightsenable;
string mag_off_switch_on, mag_off_switch_off;
string mag_right_switch_on, mag_right_switch_off;
string mag_left_switch_on, mag_left_switch_off;
string mag_both_switch_on, mag_both_switch_off;
string mag_start_switch_on, mag_start_switch_off;
string bat_master_switch_on, bat_master_switch_off;
string alt_master_switch_on, alt_master_switch_off;
string av_master_switch_on, av_master_switch_off;
string fuel_pump_switch_on, fuel_pump_switch_off;
string deice_switch_on, deice_switch_off;
string pitot_heat_switch_on, pitot_heat_switch_off;
string gear_switch_up, gear_switch_down;
string cowl_flaps_open, cowl_flaps_close;
string panel_lights_switch_on, panel_lights_switch_off;
string beacon_lights_switch_on, beacon_lights_switch_off;
string nav_lights_switch_on, nav_lights_switch_off;
string strobe_lights_switch_on, strobe_lights_switch_off;
string taxi_lights_switch_on, taxi_lights_switch_off;
string landing_lights_switch_on, landing_lights_switch_off;
const char *GearTestStrUp;
static unsigned char blankswitchwbuf[2];
unsigned char switchbuf[4], switchwbuf[2];
float LandingGearDeployRatio[10];
void SwitchMenuHandler(void *, void *);
void CreateSwitchWidget(int x1, int y1, int w, int h);
int SwitchHandler(XPWidgetMessage SwitchinMessage, XPWidgetID SwitchWidgetID, intptr_t inParam1, intptr_t inParam2);
int switchMenuItem;
int max_items = 20;
int checkable = -1;
char SwitchText[50][200] = {
"MAGS OFF",
"MAGS RIGHT",
"MAGS LEFT",
"MAGS BOTH",
"START ENGINE",
"BATTERY MASTER",
"ALTERNATOR MASTER",
"AVIONICS MASTER",
"FUEL PUMP",
"DEICE SWITCH",
"PITOT HEAT",
"LANDING GEAR UP",
"LANDING GEAR DN",
"COWL FLAPS",
"PANEL LIGHTS",
"BEACON LIGHTS",
"NAV LIGHTS",
"STROBE LIGHTS",
"TAXI LIGHTS",
"LANDING LIGHTS",
"end"
};
hid_device *switchhandle;
// ****************** BIP Panel variables *******************************
int bipcnt = 0, biptmpcnt = 0, bipres, biploop[4], stopbipcnt;
int bipnum = 0;
int bipwcscmp0 = 0, bipwcscmp1 = 1;
unsigned char bipwbuf[4][10];
#define MAX_STR 255
wchar_t wstr[4][MAX_STR];
hid_device *biphandle[4];
// ****************** Saitek Panels variables *******************************
void XsaitekpanelsMenuHandler(void *, void *);
void WriteCSVTableToDisk(void);
//bool ReadConfigFile(std::string PlaneICAO);
int XsaitekpanelsMenuItem;
int BipMenuItem;
int Fps, multi_auto_mul;
int wrgXPlaneVersion = 0;
int wrgXPLMVersion = 0;
int wrgHostID = 0;
void process_radio_panel();
void process_multi_panel();
void process_switch_panel();
void process_bip_panel();
void process_pref_file();
void process_read_ini_file();
void process_radio_panel() {
for (std::list<Radio *>::iterator it = radios.begin(); it != radios.end(); it++) {
(*it)->update();
}
}
// ********************* MyPanelsFlightLoopCallback **************************
float MyPanelsFlightLoopCallback(
float inElapsedSinceLastCall,
float inElapsedTimeSinceLastFlightLoop,
int inCounter,
void * inRefcon);
int XpanelsFnButtonCommandHandler(XPLMCommandRef inCommand, // custom command handler
XPLMCommandPhase inPhase,
void * inRefcon);
void WriteCSVTableToDisk(void);
bool ReadConfigFile(std::string PlaneICAO);
// ******************Plugin Calls ******************
PLUGIN_API int XPluginStart(char * outName,
char * outSig,
char * outDesc)
{
int ConfigSubMenuItem;
int BipSubMenuItem, Bip2SubMenuItem;
int MultiSubMenuItem, RadioSubMenuItem;
int SwitchSubMenuItem;
XPLMGetVersions(&wrgXPlaneVersion, &wrgXPLMVersion, &wrgHostID);
printf("gXPlaneVersion = %d gXPLMVersion = %d gHostID = %d\n", wrgXPlaneVersion, wrgXPLMVersion, wrgHostID);
XPLMDebugString("Xsaitekpanels v1.46\n");
/* First set up our plugin info. */
strcpy(outName, "Xsaitekpanels v1.46");
strcpy(outSig, "saitekpanels.hardware uses hidapi interface");
strcpy(outDesc, "A plugin allows use of Saitek Pro Flight Panels on all platforms");
// ************ Find Radio Panel Commands Ref ******************
Com1StbyFineDn = XPLMFindCommand("sim/radios/stby_com1_fine_down");
Com1StbyFineUp = XPLMFindCommand("sim/radios/stby_com1_fine_up");
Com1StbyCorseDn = XPLMFindCommand("sim/radios/stby_com1_coarse_down");
Com1StbyCorseUp = XPLMFindCommand("sim/radios/stby_com1_coarse_up");
Com2StbyFineDn = XPLMFindCommand("sim/radios/stby_com2_fine_down");
Com2StbyFineUp = XPLMFindCommand("sim/radios/stby_com2_fine_up");
Com2StbyCorseDn = XPLMFindCommand("sim/radios/stby_com2_coarse_down");
Com2StbyCorseUp = XPLMFindCommand("sim/radios/stby_com2_coarse_up");
Nav1StbyFineDn = XPLMFindCommand("sim/radios/stby_nav1_fine_down");
Nav1StbyFineUp = XPLMFindCommand("sim/radios/stby_nav1_fine_up");
Nav1StbyCorseDn = XPLMFindCommand("sim/radios/stby_nav1_coarse_down");
Nav1StbyCorseUp = XPLMFindCommand("sim/radios/stby_nav1_coarse_up");
Nav2StbyFineDn = XPLMFindCommand("sim/radios/stby_nav2_fine_down");
Nav2StbyFineUp = XPLMFindCommand("sim/radios/stby_nav2_fine_up");
Nav2StbyCorseDn = XPLMFindCommand("sim/radios/stby_nav2_coarse_down");
Nav2StbyCorseUp = XPLMFindCommand("sim/radios/stby_nav2_coarse_up");
Afd1StbyHunUp = XPLMFindCommand("sim/radios/stby_adf1_hundreds_up");
Afd1StbyHunDn = XPLMFindCommand("sim/radios/stby_adf1_hundreds_down");
Afd1StbyTensUp = XPLMFindCommand("sim/radios/stby_adf1_tens_up");
Afd1StbyTensDn = XPLMFindCommand("sim/radios/stby_adf1_tens_down");
Afd1StbyOnesUp = XPLMFindCommand("sim/radios/stby_adf1_ones_up");
Afd1StbyOnesDn = XPLMFindCommand("sim/radios/stby_adf1_ones_down");
Afd2StbyHunUp = XPLMFindCommand("sim/radios/stby_adf2_hundreds_up");
Afd2StbyHunDn = XPLMFindCommand("sim/radios/stby_adf2_hundreds_down");
Afd2StbyTensUp = XPLMFindCommand("sim/radios/stby_adf2_tens_up");
Afd2StbyTensDn = XPLMFindCommand("sim/radios/stby_adf2_tens_down");
Afd2StbyOnesUp = XPLMFindCommand("sim/radios/stby_adf2_ones_up");
Afd2StbyOnesDn = XPLMFindCommand("sim/radios/stby_adf2_ones_down");
XpdrThUp = XPLMFindCommand("sim/transponder/transponder_thousands_up");
XpdrThDn = XPLMFindCommand("sim/transponder/transponder_thousands_down");
XpdrHunUp = XPLMFindCommand("sim/transponder/transponder_hundreds_up");
XpdrHunDn = XPLMFindCommand("sim/transponder/transponder_hundreds_down");
XpdrTensUp = XPLMFindCommand("sim/transponder/transponder_tens_up");
XpdrTensDn = XPLMFindCommand("sim/transponder/transponder_tens_down");
XpdrOnesUp = XPLMFindCommand("sim/transponder/transponder_ones_up");
XpdrOnesDn = XPLMFindCommand("sim/transponder/transponder_ones_down");
BaroUp = XPLMFindCommand("sim/instruments/barometer_up");
BaroDn = XPLMFindCommand("sim/instruments/barometer_down");
BaroStd = XPLMFindCommand("sim/instruments/barometer_2992");
Com1ActStby = XPLMFindCommand("sim/radios/com1_standy_flip");
Com2ActStby = XPLMFindCommand("sim/radios/com2_standy_flip");
Nav1ActStby = XPLMFindCommand("sim/radios/nav1_standy_flip");
Nav2ActStby = XPLMFindCommand("sim/radios/nav2_standy_flip");
Adf1ActStby = XPLMFindCommand("sim/radios/adf1_standy_flip");
Adf2ActStby = XPLMFindCommand("sim/radios/adf2_standy_flip");
// ************ Find Radio Panel Data Ref ******************
Com1ActFreq = XPLMFindDataRef("sim/cockpit/radios/com1_freq_hz");
Com2ActFreq = XPLMFindDataRef("sim/cockpit/radios/com2_freq_hz");
Nav1ActFreq = XPLMFindDataRef("sim/cockpit/radios/nav1_freq_hz");
Nav2ActFreq = XPLMFindDataRef("sim/cockpit/radios/nav2_freq_hz");
Com1StbyFreq = XPLMFindDataRef("sim/cockpit/radios/com1_stdby_freq_hz");
Com2StbyFreq = XPLMFindDataRef("sim/cockpit/radios/com2_stdby_freq_hz");
Nav1StbyFreq = XPLMFindDataRef("sim/cockpit/radios/nav1_stdby_freq_hz");
Nav2StbyFreq = XPLMFindDataRef("sim/cockpit/radios/nav2_stdby_freq_hz");
Adf1StbyFreq = XPLMFindDataRef("sim/cockpit/radios/adf1_stdby_freq_hz");
Adf2StbyFreq = XPLMFindDataRef("sim/cockpit/radios/adf2_stdby_freq_hz");
Adf1ActFreq = XPLMFindDataRef("sim/cockpit/radios/adf1_freq_hz");
Adf2ActFreq = XPLMFindDataRef("sim/cockpit/radios/adf2_freq_hz");
XpdrCode = XPLMFindDataRef("sim/cockpit/radios/transponder_code");
XpdrMode = XPLMFindDataRef("sim/cockpit/radios/transponder_mode");
BaroSetting = XPLMFindDataRef("sim/cockpit/misc/barometer_setting");
MetricPress = XPLMFindDataRef("sim/physics/metric_press");
DmeMode = XPLMFindDataRef("sim/cockpit2/radios/actuators/DME_mode");
DmeSlvSource = XPLMFindDataRef("sim/cockpit2/radios/actuators/DME_slave_source");
Nav1DmeNmDist = XPLMFindDataRef("sim/cockpit2/radios/indicators/nav1_dme_distance_nm");
Nav1DmeSpeed = XPLMFindDataRef("sim/cockpit2/radios/indicators/nav1_dme_speed_kts");
Nav2DmeNmDist = XPLMFindDataRef("sim/cockpit2/radios/indicators/nav2_dme_distance_nm");
Nav2DmeSpeed = XPLMFindDataRef("sim/cockpit2/radios/indicators/nav2_dme_speed_kts");
DmeSpeed = XPLMFindDataRef("sim/cockpit2/radios/indicators/dme_dme_speed_kts");
DmeFreq = XPLMFindDataRef("sim/cockpit2/radios/actuators/dme_frequency_hz");
DmeTime = XPLMFindDataRef("sim/cockpit2/radios/indicators/dme_dme_time_min");
AvPwrOn = XPLMFindDataRef("sim/cockpit/electrical/avionics_on");
BatPwrOn = XPLMFindDataRef("sim/cockpit/electrical/battery_on");
Nav1PwrOn = XPLMFindDataRef("sim/cockpit2/radios/actuators/nav1_power");
Nav2PwrOn = XPLMFindDataRef("sim/cockpit2/radios/actuators/nav2_power");
Com1PwrOn = XPLMFindDataRef("sim/cockpit2/radios/actuators/com1_power");
Com2PwrOn = XPLMFindDataRef("sim/cockpit2/radios/actuators/com2_power");
Afd1PwrOn = XPLMFindDataRef("sim/cockpit2/radios/actuators/adf1_power");
DmePwrOn = XPLMFindDataRef("sim/cockpit2/radios/actuators/dme_power");
// ************ Find Multi Panel Commands Ref ***************
ApAltDn = XPLMFindCommand("sim/autopilot/altitude_down");
ApAltUp = XPLMFindCommand("sim/autopilot/altitude_up");
ApVsDn = XPLMFindCommand("sim/autopilot/vertical_speed_down");
ApVsUp = XPLMFindCommand("sim/autopilot/vertical_speed_up");
ApAsDn = XPLMFindCommand("sim/autopilot/airspeed_down");
ApAsUp = XPLMFindCommand("sim/autopilot/airspeed_up");
ApHdgDn = XPLMFindCommand("sim/autopilot/heading_down");
ApHdgUp = XPLMFindCommand("sim/autopilot/heading_up");
ApCrsDn = XPLMFindCommand("sim/radios/obs1_down");
ApCrsUp = XPLMFindCommand("sim/radios/obs1_up");
ApCrsDn2 = XPLMFindCommand("sim/radios/obs2_down");
ApCrsUp2 = XPLMFindCommand("sim/radios/obs2_up");
ApMstrBtnUp = XPLMFindCommand("sim/autopilot/fdir_servos_up_one");
ApMstrBtnDn = XPLMFindCommand("sim/autopilot/fdir_servos_down_one");
ApMstrBtnOff = XPLMFindCommand("sim/autopilot/servos_and_flight_dir_off");
ApHdgBtn = XPLMFindCommand("sim/autopilot/heading");
ApNavBtn = XPLMFindCommand("sim/autopilot/NAV");
ApIasBtn = XPLMFindCommand("sim/autopilot/level_change");
ApAltBtn = XPLMFindCommand("sim/autopilot/altitude_hold");
ApVsBtn = XPLMFindCommand("sim/autopilot/vertical_speed");
ApAprBtn = XPLMFindCommand("sim/autopilot/approach");
ApRevBtn = XPLMFindCommand("sim/autopilot/back_course");
PitchTrimDn = XPLMFindCommand("sim/flight_controls/pitch_trim_down");
PitchTrimUp = XPLMFindCommand("sim/flight_controls/pitch_trim_up");
PitchTrimTkOff = XPLMFindCommand("sim/flight_controls/pitch_trim_takeoff");
FlapsDn = XPLMFindCommand("sim/flight_controls/flaps_down");
FlapsUp = XPLMFindCommand("sim/flight_controls/flaps_up");
XpanelsFnButtonCommand = XPLMCreateCommand("xplugins/xsaitekpanels/x_panels_fn_button","Xpanels Fn Button");
// **************** Find Multi Panel Data Ref ********************
ApAlt = XPLMFindDataRef("sim/cockpit/autopilot/altitude");
ApVs = XPLMFindDataRef("sim/cockpit/autopilot/vertical_velocity");
ApAs = XPLMFindDataRef("sim/cockpit/autopilot/airspeed");
ApHdg = XPLMFindDataRef("sim/cockpit/autopilot/heading_mag");
ApCrs = XPLMFindDataRef("sim/cockpit/radios/nav1_obs_degm");
ApCrs2 = XPLMFindDataRef("sim/cockpit/radios/nav2_obs_degm");
ApMstrStat = XPLMFindDataRef("sim/cockpit2/autopilot/flight_director_mode");
ApState = XPLMFindDataRef("sim/cockpit/autopilot/autopilot_state");
ApHdgStat = XPLMFindDataRef("sim/cockpit2/autopilot/heading_status");
ApNavStat = XPLMFindDataRef("sim/cockpit2/autopilot/nav_status");
ApIasStat = XPLMFindDataRef("sim/cockpit2/autopilot/speed_status");
ApAltStat = XPLMFindDataRef("sim/cockpit2/autopilot/altitude_hold_status");
ApVsStat = XPLMFindDataRef("sim/cockpit2/autopilot/vvi_status");
ApAprStat = XPLMFindDataRef("sim/cockpit2/autopilot/approach_status");
ApRevStat = XPLMFindDataRef("sim/cockpit2/autopilot/backcourse_status");
AvPwrOn = XPLMFindDataRef("sim/cockpit/electrical/avionics_on");
BatPwrOn = XPLMFindDataRef("sim/cockpit/electrical/battery_on");
Frp = XPLMFindDataRef("sim/operation/misc/frame_rate_period");
MHdg = XPLMFindDataRef("sim/flightmodel/position/magpsi");
AirspeedIsMach = XPLMFindDataRef("sim/cockpit/autopilot/airspeed_is_mach");
Airspeed = XPLMFindDataRef("sim/cockpit/autopilot/airspeed");
// **************** Find Switch Panel Commands Ref *******************
ClFlOpn = XPLMFindCommand("sim/flight_controls/cowl_flaps_open");
ClFlCls = XPLMFindCommand("sim/flight_controls/cowl_flaps_closed");
PtHt0On = XPLMFindCommand("sim/ice/pitot_heat0_on");
PtHt0Off = XPLMFindCommand("sim/ice/pitot_heat0_off");
PtHt1On = XPLMFindCommand("sim/ice/pitot_heat1_on");
PtHt1Off = XPLMFindCommand("sim/ice/pitot_heat1_off");
PtHtOn = XPLMFindCommand("sim/ice/pitot_heat_on");
PtHtOff = XPLMFindCommand("sim/ice/pitot_heat_off");
AvLtOn = XPLMFindCommand("sim/systems/avionics_on");
AvLtOff = XPLMFindCommand("sim/systems/avionics_off");
BatOn = XPLMFindCommand("sim/electrical/battery_1_on");
BatOff = XPLMFindCommand("sim/electrical/battery_1_off");
LnLtOn = XPLMFindCommand("sim/lights/landing_lights_on");
LnLtOff = XPLMFindCommand("sim/lights/landing_lights_off");
TxLtOn = XPLMFindCommand("sim/lights/taxi_lights_on");
TxLtOff = XPLMFindCommand("sim/lights/taxi_lights_off");
StLtOn = XPLMFindCommand("sim/lights/strobe_lights_on");
StLtOff = XPLMFindCommand("sim/lights/strobe_lights_off");
NvLtOn = XPLMFindCommand("sim/lights/nav_lights_on");
NvLtOff = XPLMFindCommand("sim/lights/nav_lights_off");
BcLtOn = XPLMFindCommand("sim/lights/beacon_lights_on");
BcLtOff = XPLMFindCommand("sim/lights/beacon_lights_off");
GearUp = XPLMFindCommand("sim/flight_controls/landing_gear_up");
GearDn = XPLMFindCommand("sim/flight_controls/landing_gear_down");
MagOff1 = XPLMFindCommand("sim/magnetos/magnetos_off_1");
MagOff2 = XPLMFindCommand("sim/magnetos/magnetos_off_2");
MagOff3 = XPLMFindCommand("sim/magnetos/magnetos_off_3");
MagOff4 = XPLMFindCommand("sim/magnetos/magnetos_off_4");
MagOff5 = XPLMFindCommand("sim/magnetos/magnetos_off_5");
MagOff6 = XPLMFindCommand("sim/magnetos/magnetos_off_6");
MagOff7 = XPLMFindCommand("sim/magnetos/magnetos_off_7");
MagOff8 = XPLMFindCommand("sim/magnetos/magnetos_off_8");
MagLeft1 = XPLMFindCommand("sim/magnetos/magnetos_left_1");
MagLeft2 = XPLMFindCommand("sim/magnetos/magnetos_left_2");
MagLeft3 = XPLMFindCommand("sim/magnetos/magnetos_left_3");
MagLeft4 = XPLMFindCommand("sim/magnetos/magnetos_left_4");
MagLeft5 = XPLMFindCommand("sim/magnetos/magnetos_left_5");
MagLeft6 = XPLMFindCommand("sim/magnetos/magnetos_left_6");
MagLeft7 = XPLMFindCommand("sim/magnetos/magnetos_left_7");
MagLeft8 = XPLMFindCommand("sim/magnetos/magnetos_left_8");
MagRight1 = XPLMFindCommand("sim/magnetos/magnetos_right_1");
MagRight2 = XPLMFindCommand("sim/magnetos/magnetos_right_2");
MagRight3 = XPLMFindCommand("sim/magnetos/magnetos_right_3");
MagRight4 = XPLMFindCommand("sim/magnetos/magnetos_right_4");
MagRight5 = XPLMFindCommand("sim/magnetos/magnetos_right_5");
MagRight6 = XPLMFindCommand("sim/magnetos/magnetos_right_6");
MagRight7 = XPLMFindCommand("sim/magnetos/magnetos_right_7");
MagRight8 = XPLMFindCommand("sim/magnetos/magnetos_right_8");
MagBoth1 = XPLMFindCommand("sim/magnetos/magnetos_both_1");
MagBoth2 = XPLMFindCommand("sim/magnetos/magnetos_both_2");
MagBoth3 = XPLMFindCommand("sim/magnetos/magnetos_both_3");
MagBoth4 = XPLMFindCommand("sim/magnetos/magnetos_both_4");
MagBoth5 = XPLMFindCommand("sim/magnetos/magnetos_both_5");
MagBoth6 = XPLMFindCommand("sim/magnetos/magnetos_both_6");
MagBoth7 = XPLMFindCommand("sim/magnetos/magnetos_both_7");
MagBoth8 = XPLMFindCommand("sim/magnetos/magnetos_both_8");
EngStart1 = XPLMFindCommand("sim/starters/engage_starter_1");
EngStart2 = XPLMFindCommand("sim/starters/engage_starter_2");
EngStart3 = XPLMFindCommand("sim/starters/engage_starter_3");
EngStart4 = XPLMFindCommand("sim/starters/engage_starter_4");
EngStart5 = XPLMFindCommand("sim/starters/engage_starter_5");
EngStart6 = XPLMFindCommand("sim/starters/engage_starter_6");
EngStart7 = XPLMFindCommand("sim/starters/engage_starter_7");
EngStart8 = XPLMFindCommand("sim/starters/engage_starter_8");
BatOn1 = XPLMFindCommand("sim/electrical/battery_1_on");
BatOn2 = XPLMFindCommand("sim/electrical/battery_2_on");
BatOff1 = XPLMFindCommand("sim/electrical/battery_1_off");
BatOff2 = XPLMFindCommand("sim/electrical/battery_2_off");
GenOn1 = XPLMFindCommand("sim/electrical/generator_1_on");
GenOn2 = XPLMFindCommand("sim/electrical/generator_2_on");
GenOn3 = XPLMFindCommand("sim/electrical/generator_3_on");
GenOn4 = XPLMFindCommand("sim/electrical/generator_4_on");
GenOn5 = XPLMFindCommand("sim/electrical/generator_5_on");
GenOn6 = XPLMFindCommand("sim/electrical/generator_6_on");
GenOn7 = XPLMFindCommand("sim/electrical/generator_7_on");
GenOn8 = XPLMFindCommand("sim/electrical/generator_8_on");
GenOff1 = XPLMFindCommand("sim/electrical/generator_1_off");
GenOff2 = XPLMFindCommand("sim/electrical/generator_2_off");
GenOff3 = XPLMFindCommand("sim/electrical/generator_3_off");
GenOff4 = XPLMFindCommand("sim/electrical/generator_4_off");
GenOff5 = XPLMFindCommand("sim/electrical/generator_5_off");
GenOff6 = XPLMFindCommand("sim/electrical/generator_6_off");
GenOff7 = XPLMFindCommand("sim/electrical/generator_7_off");
GenOff8 = XPLMFindCommand("sim/electrical/generator_8_off");
FuelPumpOn1 = XPLMFindCommand("sim/fuel/fuel_pump_1_on");
FuelPumpOn2 = XPLMFindCommand("sim/fuel/fuel_pump_2_on");
FuelPumpOn3 = XPLMFindCommand("sim/fuel/fuel_pump_3_on");
FuelPumpOn4 = XPLMFindCommand("sim/fuel/fuel_pump_4_on");
FuelPumpOn5 = XPLMFindCommand("sim/fuel/fuel_pump_5_on");
FuelPumpOn6 = XPLMFindCommand("sim/fuel/fuel_pump_6_on");
FuelPumpOn7 = XPLMFindCommand("sim/fuel/fuel_pump_7_on");
FuelPumpOn8 = XPLMFindCommand("sim/fuel/fuel_pump_8_on");
FuelPumpOff1 = XPLMFindCommand("sim/fuel/fuel_pump_1_off");
FuelPumpOff2 = XPLMFindCommand("sim/fuel/fuel_pump_2_off");
FuelPumpOff3 = XPLMFindCommand("sim/fuel/fuel_pump_3_off");
FuelPumpOff4 = XPLMFindCommand("sim/fuel/fuel_pump_4_off");
FuelPumpOff5 = XPLMFindCommand("sim/fuel/fuel_pump_5_off");
FuelPumpOff6 = XPLMFindCommand("sim/fuel/fuel_pump_6_off");
FuelPumpOff7 = XPLMFindCommand("sim/fuel/fuel_pump_7_off");
FuelPumpOff8 = XPLMFindCommand("sim/fuel/fuel_pump_8_off");
// **************** Find Switch Panel Data Ref *******************
AntiIce = XPLMFindDataRef("sim/cockpit/switches/anti_ice_on");
CockpitLights = XPLMFindDataRef("sim/cockpit/electrical/cockpit_lights");
CowlFlaps = XPLMFindDataRef("sim/flightmodel/engine/ENGN_cowl");
GearRetract = XPLMFindDataRef("sim/aircraft/gear/acf_gear_retract");
LandingGearStatus = XPLMFindDataRef("sim/aircraft/parts/acf_gear_deploy");
Gear1Fail = XPLMFindDataRef("sim/operation/failures/rel_lagear1");
Gear2Fail = XPLMFindDataRef("sim/operation/failures/rel_lagear2");
Gear3Fail = XPLMFindDataRef("sim/operation/failures/rel_lagear3");
OnGround = XPLMFindDataRef("sim/flightmodel/failures/onground_any");
BatNum = XPLMFindDataRef("sim/aircraft/electrical/num_batteries");
GenNum = XPLMFindDataRef("sim/aircraft/electrical/num_generators");
EngNum = XPLMFindDataRef("sim/aircraft/engine/acf_num_engines");
BatArrayOnDR = XPLMFindDataRef("sim/cockpit/electrical/battery_array_on");
// ************* Open any Radio that is connected *****************
struct hid_device_info *rad_devs, *rad_cur_dev;
rad_devs = hid_enumerate(0x6a3, 0x0d05);
rad_cur_dev = rad_devs;
while (rad_cur_dev) {
hid_device *handle = hid_open_path(rad_cur_dev->path);
hid_set_nonblocking(handle, 1);
Radio *r = new Radio(handle);
r->update();
radios.push_back(r);
rad_cur_dev = rad_cur_dev->next;
}
hid_free_enumeration(rad_devs);
// *** Find Connected Multi Panel *****
struct hid_device_info *multi_devs, *multi_cur_dev;
multi_devs = hid_enumerate(0x6a3, 0x0d06);
multi_cur_dev = multi_devs;
while (multi_cur_dev) {
multihandle = hid_open_path(multi_cur_dev->path);
hid_set_nonblocking(multihandle, 1);
multires = hid_read(multihandle, multibuf, sizeof(multibuf));
hid_send_feature_report(multihandle, multiwbuf, 13);
multicnt++;
multi_cur_dev = multi_cur_dev->next;
}
hid_free_enumeration(multi_devs);
// *** Find Connected Switch Panel *****
struct hid_device_info *switch_devs, *switch_cur_dev;
switch_devs = hid_enumerate(0x6a3, 0x0d67);
switch_cur_dev = switch_devs;
while (switch_cur_dev) {
switchhandle = hid_open_path(switch_cur_dev->path);
hid_set_nonblocking(switchhandle, 1);
switchres = hid_read(switchhandle, switchbuf, sizeof(switchbuf));
hid_send_feature_report(switchhandle, switchwbuf, 2);
switchcnt++;
switch_cur_dev = switch_cur_dev->next;
}
hid_free_enumeration(switch_devs);
// *** Find Connected BIP Panel *****
struct hid_device_info *bip_devs, *bip_cur_dev;
bip_devs = hid_enumerate(0x6a3, 0xb4e);
bip_cur_dev = bip_devs;
char buf[256];
int result;
// find serial numbers of all BIP's connected
while (bip_cur_dev) {
biphandle[biptmpcnt] = hid_open_path(bip_cur_dev->path);
hid_get_serial_number_string(biphandle[biptmpcnt], wstr[biptmpcnt], MAX_STR);
//sprintf(buf, "biptmpcnt = %d Serial Number String: %ls\n", biptmpcnt, wstr[biptmpcnt]);
//XPLMDebugString(buf);
hid_close(biphandle[biptmpcnt]);
biptmpcnt++;
bip_cur_dev = bip_cur_dev->next;
}
hid_free_enumeration(bip_devs);
if (biptmpcnt > 1) {
result = wcscmp(wstr[0], wstr[1]);
if(result > 0){
//sprintf(buf, "(result > 0) %ls > %ls\n", wstr[0], wstr[1]);
//XPLMDebugString(buf);
biphandle[0] = hid_open(0x6a3, 0xb4e, wstr[0]);
bipwbuf[0][0] = 0xb2; // 0xb2 Report ID for brightness
bipwbuf[0][1] = 100; // Set brightness to 100%
bipres = hid_send_feature_report(biphandle[0], bipwbuf[0], 10);
bipwcscmp0 = 0;
biphandle[1] = hid_open(0x6a3, 0xb4e, wstr[1]);
bipwbuf[1][0] = 0xb2; // 0xb2 Report ID for brightness
bipwbuf[1][1] = 100; // Set brightness to 100%
bipres = hid_send_feature_report(biphandle[1], bipwbuf[1], 10);
bipwcscmp1 = 1;
}else if (result < 0){
//sprintf(buf, "(result < 0) %ls < %ls\n", wstr[0], wstr[1]);
//XPLMDebugString(buf);
biphandle[1] = hid_open(0x6a3, 0xb4e, wstr[0]);
bipwbuf[0][0] = 0xb2; // 0xb2 Report ID for brightness
bipwbuf[0][1] = 100; // Set brightness to 100%
bipres = hid_send_feature_report(biphandle[1], bipwbuf[0], 10);
bipwcscmp0 = 0;
biphandle[0] = hid_open(0x6a3, 0xb4e, wstr[1]);
bipwbuf[1][0] = 0xb2; // 0xb2 Report ID for brightness
bipwbuf[1][1] = 100; // Set brightness to 100%
bipres = hid_send_feature_report(biphandle[0], bipwbuf[1], 10);
bipwcscmp1 = 1;
}
}else if (biptmpcnt == 1){
biphandle[0] = hid_open(0x6a3, 0xb4e, wstr[0]);
bipwbuf[0][0] = 0xb2; // 0xb2 Report ID for brightness
bipwbuf[0][1] = 100; // Set brightness to 100%
bipres = hid_send_feature_report(biphandle[0], bipwbuf[0], 10);
bipwcscmp0 = 0;
}
bipcnt = biptmpcnt;
// * Register our callback for every loop. Positive intervals
// * are in seconds, negative are the negative of sim frames. Zero
// * registers but does not schedule a callback for time.
XPLMRegisterFlightLoopCallback(
MyPanelsFlightLoopCallback, // * Callback *
interval, // * Interval -1 every loop*
NULL); // * refcon not used. *
// Register our custom commands
XPLMRegisterCommandHandler(XpanelsFnButtonCommand, // in Command name
XpanelsFnButtonCommandHandler, // in Handler
1, // Receive input before plugin windows.
(void *) 0); // inRefcon.
// Create our menu
XsaitekpanelsMenuItem = XPLMAppendMenuItem(
XPLMFindPluginsMenu(),
"Xsaitekpanels",
NULL,
1);
XsaitekpanelsMenu = XPLMCreateMenu(
"Xsaitekpanels",
XPLMFindPluginsMenu(),
XsaitekpanelsMenuItem,
XsaitekpanelsMenuHandler,
(void *)0);
ConfigSubMenuItem = XPLMAppendMenuItem(
XsaitekpanelsMenu,
"xsaitekpanels.ini",
NULL,
1);
ConfigMenuId = XPLMCreateMenu(
"xsaitekpanels.ini",
XsaitekpanelsMenu,
ConfigSubMenuItem,
XsaitekpanelsMenuHandler,
(void *)1);
XPLMClearAllMenuItems(ConfigMenuId);
XPLMAppendMenuItem(ConfigMenuId, "Reload xsaitekpanels.ini", (void *) "TRUE", 1);
if (bipcnt > 0) {
if(bipcnt > 0){
BipSubMenuItem = XPLMAppendMenuItem(
XsaitekpanelsMenu,