-
Notifications
You must be signed in to change notification settings - Fork 0
/
mfdc.js
1643 lines (1458 loc) · 46.1 KB
/
mfdc.js
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
// TODO - currently assumed 8 figure grids, expand to 10.
// Mortar flight calculation is pure example.
// V1.0 functionality
// Resection
// Set ML, including temperature and elevation
// Enter target.
// Shot at target with countdown, and min/max range checks
// Keyboard and screen input, including back button and Run on enter.
// V1.1 Changes:
// Squared up image
// V1.2 Added functionality/fixes:
// Added tooltips for known buttons
// H hour setting/countdown/reset
// Actual time setting (by default uses host time)
// Decimal point enabled (needed for actual time)
// Clear button functionality
// SIM button (within limits of my understanding of its function)
// Back button correctly deals with deleting last digit (i.e. not leaving a minus standing alone)
// WM button - snap shot at range-bearing target
// Blank entry now reports "INPUT REQ'D"
const START_L1="MFDC2-MDP38";
const START_L2="225A-2F4B10A";
const START_L3="L16-L15(4/2)";
const DISPLAY_WIDTH=12;
var on=false; // Device on
var firston=true; // Cold start message
var firstCountdown=0;
var shift=false; // Shift key pressed
var timeOffset=0; // Seconds ahead of PC clock
var img;
var offsetX=5; // Same as padding in img tag
var offsetY=5;
var temperature=21; // Default.
var defaultText="MK 4 NO ML";
var countdown=0;
var mission1=false;
var mission2=false;
var tgt_grid=-1;
var tgt_alt=-1;
var tgt_desig="";
var tgt_brg=-1;
var tgt_range=-1;
var grid=-1; // Location set by resection
var ml_grid=-1;
var ml_alt=-1;
var h_hrs=-1;
var h_mins=-1;
var h_secs=-1;
// Finite State Machine states
const READY=0;
const STARTING1=100;
const STARTING2=101;
const STARTING3=102;
const RESECTION_GR1=1;
const RESECTION_BR1=2;
const RESECTION_GR2=3;
const RESECTION_BR2=4;
const RESECTION_GR3=5;
const RESECTION_BR3=6;
const RESECTION_CALC=7;
const RESECTION_FOUND=8;
const TEMP_UPDATE=9;
const TGT_GRID=10;
const TGT_ALT=11;
const TGT_NO=12;
const ML_GRID=13;
const ML_ALT=14;
const SHOW_ML_GRID=15;
const SHOW_ML_ALT=16;
const GET_GRID=17;
const GET_ALT=18;
const SOLUTION=19;
const SOLUTION_EL=20;
const COUNTDOWN=21;
const CLEAR_ACTIVE=22;
const CLEAR_CONFIRM=23;
const SET_H_HR=24;
const H_HR_COUNTDOWN=25;
const H_HR_COUNTUP=26;
const GET_TGT_BRG=27;
const GET_TGT_RNG=28;
const SETTING_TIME=29;
const SETTING_MET=30;
var resect_gr1;
var resect_gr2;
var resect_gr3;
var resect_br1;
var resect_br2;
var resect_br3;
var state=STARTING1;
const TOO_NEAR="TGT TOO NEAR";
const OUT_RANGE="OUT OF RANGE";
const INVALID_KEY="INVALID KEY";
var keyboardInput="";
function start() {
var disp=document.getElementById('display');
disp.style.visibility='hidden';
shift=false;
on=false;
img = new Image;
img.onload = setup;
img.src = 'images/mfdc.webp';
return false;
}
function setup() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
img.usemap = document.getElementById("buttons");
ctx.drawImage(img,offsetX,offsetY,540,1000);
}
//------------------------------------------------------------------
document.onkeydown= onKeyDown;
function onKeyDown(evt){ // Give me some keyboard control (Enter, backspace,plus/minus and 0-9.)
//if (true) { alert(evt.keyCode); }
if (evt.keyCode==13) {RUN(); return false;}
if (evt.keyCode==8) {Back(); return false;}
else if (evt.keyCode==189){Neg(); return false;}
else if (evt.keyCode==48) {B0(); return false; }
else if (evt.keyCode==49) {B1(); return false; }
else if (evt.keyCode==50) {B2(); return false; }
else if (evt.keyCode==51) {B3(); return false; }
else if (evt.keyCode==52) {B4(); return false; }
else if (evt.keyCode==53) {B5(); return false; }
else if (evt.keyCode==54) {B6(); return false; }
else if (evt.keyCode==55) {B7(); return false; }
else if (evt.keyCode==56) {B8(); return false; }
else if (evt.keyCode==57) {B9(); return false; }
else if (evt.keyCode==190) {Bdp(); return false; }
}
//-------------FOLLOWING BLOCK AUTOGENERATED -------------------------
function overOn() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.rect(10,140,100,80);
ctx.lineWidth=8;
ctx.strokeStyle = '#ff0000';
ctx.stroke();
}
function overGrid() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.rect(38,253,90,89);
ctx.lineWidth=8;
ctx.strokeStyle = '#ff0000';
ctx.stroke();
}
function overWM() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.rect(222,253,90,89);
ctx.lineWidth=8;
ctx.strokeStyle = '#ff0000';
ctx.stroke();
}
function overDATUM() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.rect(314,253,90,89);
ctx.lineWidth=8;
ctx.strokeStyle = '#ff0000';
ctx.stroke();
}
function overTgts() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.rect(38,344,90,89);
ctx.lineWidth=8;
ctx.strokeStyle = '#ff0000';
ctx.stroke();
}
function overSfty() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.rect(130,344,90,89);
ctx.lineWidth=8;
ctx.strokeStyle = '#ff0000';
ctx.stroke();
}
function overMLs() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.rect(222,344,90,89);
ctx.lineWidth=8;
ctx.strokeStyle = '#ff0000';
ctx.stroke();
}
function overMET() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.rect(314,344,90,89);
ctx.lineWidth=8;
ctx.strokeStyle = '#ff0000';
ctx.stroke();
}
function overShift() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.rect(38,435,90,89);
ctx.lineWidth=8;
ctx.strokeStyle = '#ff0000';
ctx.stroke();
}
function overShot() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.rect(406,435,90,89);
ctx.lineWidth=8;
ctx.strokeStyle = '#ff0000';
ctx.stroke();
}
function overNeg() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.rect(222,526,90,89);
ctx.lineWidth=8;
ctx.strokeStyle = '#ff0000';
ctx.stroke();
}
function overML() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.rect(314,526,90,89);
ctx.lineWidth=8;
ctx.strokeStyle = '#ff0000';
ctx.stroke();
}
function overBack() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.rect(406,526,90,89);
ctx.lineWidth=8;
ctx.strokeStyle = '#ff0000';
ctx.stroke();
}
function overSIM() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.rect(42,709,88,89);
ctx.lineWidth=8;
ctx.strokeStyle = '#ff0000';
ctx.stroke();
}
function overCLEAR() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.rect(42,799,88,89);
ctx.lineWidth=8;
ctx.strokeStyle = '#ff0000';
ctx.stroke();
}
function overRESET() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.rect(42,889,88,89);
ctx.lineWidth=8;
ctx.strokeStyle = '#ff0000';
ctx.stroke();
}
function overB0() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.rect(155,889,95,90);
ctx.lineWidth=8;
ctx.strokeStyle = '#ff0000';
ctx.stroke();
}
function overB1() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.rect(155,799,95,90);
ctx.lineWidth=8;
ctx.strokeStyle = '#ff0000';
ctx.stroke();
}
function overB2() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.rect(277,799,95,90);
ctx.lineWidth=8;
ctx.strokeStyle = '#ff0000';
ctx.stroke();
}
function overB3() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.rect(399,799,95,90);
ctx.lineWidth=8;
ctx.strokeStyle = '#ff0000';
ctx.stroke();
}
function overB4() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.rect(155,709,95,90);
ctx.lineWidth=8;
ctx.strokeStyle = '#ff0000';
ctx.stroke();
}
function overB5() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.rect(277,709,95,90);
ctx.lineWidth=8;
ctx.strokeStyle = '#ff0000';
ctx.stroke();
}
function overB6() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.rect(399,709,95,90);
ctx.lineWidth=8;
ctx.strokeStyle = '#ff0000';
ctx.stroke();
}
function overB7() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.rect(155,619,95,90);
ctx.lineWidth=8;
ctx.strokeStyle = '#ff0000';
ctx.stroke();
}
function overB8() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.rect(277,619,95,90);
ctx.lineWidth=8;
ctx.strokeStyle = '#ff0000';
ctx.stroke();
}
function overB9() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.rect(399,619,95,90);
ctx.lineWidth=8;
ctx.strokeStyle = '#ff0000';
ctx.stroke();
}
function overBdp() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.rect(277,889,95,90);
ctx.lineWidth=8;
ctx.strokeStyle = '#ff0000';
ctx.stroke();
}
function overRUN() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.rect(399,889,95,90);
ctx.lineWidth=8;
ctx.strokeStyle = '#ff0000';
ctx.stroke();
}
function outOn() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.clearRect(10,140,100,80);
ctx.drawImage(img,offsetX,offsetY,540,1000);
}
function outGrid() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.clearRect(38,253,90,89);
ctx.drawImage(img,offsetX,offsetY,540,1000);
}
function outWM() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.clearRect(222,253,90,89);
ctx.drawImage(img,offsetX,offsetY,540,1000);
}
function outDATUM() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.clearRect(314,253,90,89);
ctx.drawImage(img,offsetX,offsetY,540,1000);
}
function outTgts() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.clearRect(38,344,90,89);
ctx.drawImage(img,offsetX,offsetY,540,1000);
}
function outSfty() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.clearRect(130,344,90,89);
ctx.drawImage(img,offsetX,offsetY,540,1000);
}
function outMLs() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.clearRect(222,344,90,89);
ctx.drawImage(img,offsetX,offsetY,540,1000);
}
function outMET() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.clearRect(314,344,90,89);
ctx.drawImage(img,offsetX,offsetY,540,1000);
}
function outShift() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.clearRect(38,435,90,89);
ctx.drawImage(img,offsetX,offsetY,540,1000);
}
function outShot() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.clearRect(406,435,90,89);
ctx.drawImage(img,offsetX,offsetY,540,1000);
}
function outNeg() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.clearRect(222,526,90,89);
ctx.drawImage(img,offsetX,offsetY,540,1000);
}
function outML() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.clearRect(314,526,90,89);
ctx.drawImage(img,offsetX,offsetY,540,1000);
}
function outBack() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.clearRect(406,526,90,89);
ctx.drawImage(img,offsetX,offsetY,540,1000);
}
function outSIM() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.clearRect(42,709,88,89);
ctx.drawImage(img,offsetX,offsetY,540,1000);
}
function outCLEAR() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.clearRect(42,799,88,89);
ctx.drawImage(img,offsetX,offsetY,540,1000);
}
function outRESET() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.clearRect(42,889,88,89);
ctx.drawImage(img,offsetX,offsetY,540,1000);
}
function outB0() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.clearRect(155,889,95,90);
ctx.drawImage(img,offsetX,offsetY,540,1000);
}
function outB1() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.clearRect(155,799,95,90);
ctx.drawImage(img,offsetX,offsetY,540,1000);
}
function outB2() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.clearRect(277,799,95,90);
ctx.drawImage(img,offsetX,offsetY,540,1000);
}
function outB3() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.clearRect(399,799,95,90);
ctx.drawImage(img,offsetX,offsetY,540,1000);
}
function outB4() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.clearRect(155,709,95,90);
ctx.drawImage(img,offsetX,offsetY,540,1000);
}
function outB5() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.clearRect(277,709,95,90);
ctx.drawImage(img,offsetX,offsetY,540,1000);
}
function outB6() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.clearRect(399,709,95,90);
ctx.drawImage(img,offsetX,offsetY,540,1000);
}
function outB7() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.clearRect(155,619,95,90);
ctx.drawImage(img,offsetX,offsetY,540,1000);
}
function outB8() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.clearRect(277,619,95,90);
ctx.drawImage(img,offsetX,offsetY,540,1000);
}
function outB9() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.clearRect(399,619,95,90);
ctx.drawImage(img,offsetX,offsetY,540,1000);
}
function outBdp() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.clearRect(277,889,95,90);
ctx.drawImage(img,offsetX,offsetY,540,1000);
}
function outRUN() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.clearRect(399,889,95,90);
ctx.drawImage(img,offsetX,offsetY,540,1000);
}
//-----------------------END AUTOGEN -------------------------------
//------------------------------------------------------------------
function startupMsg() {
if (state==STARTING1) {
document.getElementById('maintext').textContent=START_L1;
state=STARTING2;
setTimeout(startupMsg,1000);
return false;
} else if (state==STARTING2) {
document.getElementById('maintext').textContent=START_L2;
state=STARTING3;
setTimeout(startupMsg,1000);
return false;
} else if (state==STARTING3) {
document.getElementById('maintext').textContent=START_L3;
state=READY;
setTimeout(backToReady,1000);
return false;
}
return false;
}
//------------------------------------------------------------------
function flightCountdown() {
countdown-=1;
if (countdown<0) { // Device seems to use 6s.
document.getElementById('maintext').textContent="SPLASH";
state=SOLUTION;
setTimeout(RUN,5000);
} else {
document.getElementById('maintext').textContent=" "+countdown+" SECS";
setTimeout(flightCountdown,1000);
}
return false;
}
//------------------------------------------------------------------
function Hcountdown() {
if (state!=H_HR_COUNTDOWN) return;
h_secs-=1;
if (h_secs==0 && h_mins==0 && h_hrs==0) {
document.getElementById('maintext').textContent="* H HOUR *";
setTimeout(Hcountup,1000);
state=H_HR_COUNTUP;
return false;
}
if (h_secs<0) {
h_mins-=1;
h_secs=59;
if (h_mins<0) {
h_hrs-=1;
h_mins=59;
}
}
document.getElementById('maintext').textContent="H-"+h_hrs.toString().padStart(2,'0')+":"+h_mins.toString().padStart(2,'0')+":"+h_secs.toString().padStart(2,'0');
setTimeout(Hcountdown,1000);
return false;
}
//------------------------------------------------------------------
function Hcountup() {
if (state!=H_HR_COUNTUP) return;
h_secs+=1;
if (h_secs>59) {
h_mins+=1;
h_secs=0;
if (h_mins>59) {
h_hrs+=1;
h_mins=0;
}
}
document.getElementById('maintext').textContent="H+"+h_hrs.toString().padStart(2,'0')+":"+h_mins.toString().padStart(2,'0')+":"+h_secs.toString().padStart(2,'0');
setTimeout(Hcountup,1000);
return false;
}
//------------------------------------------------------------------
function On() {
on=!on;
if (firston) { startupMsg(); firston=false; }
var disp=document.getElementById('display');
disp.style.visibility=(on)?'visible':'hidden';
var sh=document.getElementById('shift');
sh.style.visibility=(on && shift)?'visible':'hidden';
return false;
}
//------------------------------------------------------------------
function Shift() {
if (!on) return false;
if (state==CLEAR_ACTIVE) {
document.getElementById('maintext').textContent=INVALID_KEY;
state=READY;
setTimeout(backToReady,1000);
return false;
}
shift=!shift;
var sh=document.getElementById('shift');
sh.style.visibility=(shift)?'visible':'hidden';
return false;
}
//------------------------------------------------------------------
function Neg() {
if (!on) return false;
if (state==CLEAR_ACTIVE) {
document.getElementById('maintext').textContent=INVALID_KEY;
state=READY;
setTimeout(backToReady,1000);
return false;
}
if (keyboardInput.length<11) {
if (keyboardInput.substring(0,1)=="-") keyboardInput=keyboardInput.substring(1);
else keyboardInput="-"+keyboardInput;
document.getElementById('maintext').textContent=keyboardInput;
}
return false;
}
//------------------------------------------------------------------
function Sfty() {
if (!on) return false;
if (state==CLEAR_ACTIVE) {
document.getElementById('maintext').textContent="NO RECORD";
state=READY;
setTimeout(backToReady,1000);
return false;
}
if (state!=READY) return false;
document.getElementById('maintext').textContent="NO SFTY DATA"; // TODO allow setting
setTimeout(backToReady,1000);
return false;
}
//------------------------------------------------------------------
function Back() {
if (!on) return false;
if (state==CLEAR_ACTIVE) {
document.getElementById('maintext').textContent=INVALID_KEY;
state=READY;
setTimeout(backToReady,1000);
return false;
}
if (keyboardInput.length>0) {
keyboardInput=keyboardInput.substring(0,keyboardInput.length-1);
if (keyboardInput=='-') keyboardInput=""; // Special case - don't just leave a minus on display
document.getElementById('maintext').textContent=keyboardInput;
}
if (keyboardInput.length==0) {
document.getElementById('maintext').textContent=defaultText;
}
return false;
}
//------------------------------------------------------------------
function Tgts() {
if (!on) return false;
if (state==CLEAR_ACTIVE) {
document.getElementById('maintext').textContent="NO RECORD";
state=READY;
setTimeout(backToReady,1000);
return false;
}
if (state!=READY) return false;
if (shift) {
Shift(); // Cancel shift
keyboardInput=""; // Cleanup
state=TGT_GRID;
document.getElementById('maintext').textContent="STOTGT GRID?";
} else {
if (tgt_grid==-1) {
document.getElementById('maintext').textContent="NO RECORD";
setTimeout(backToReady,1000);
state=READY;
}
}
return false;
}
//------------------------------------------------------------------
function RESET() {
if (!on) return false;
if (state==CLEAR_ACTIVE) {
document.getElementById('maintext').textContent="";
state=READY;
setTimeout(backToReady,1000);
return false;
}
state=READY;
keyboardInput=""; // Cleanup
document.getElementById('maintext').textContent=defaultText;
return false;
}
//------------------------------------------------------------------
function SIM() {
if (!on) return false;
if (state==CLEAR_ACTIVE) {
document.getElementById('maintext').textContent="RUN IF SURE";
state=CLEAR_CONFIRM;
return FALSE;
}
// Seems to toggle missions. If both true, sets to 1
// If neither, does nothing (confirm?)
if (mission2) { mission2=false; mission1=true; }
else if (mission1) { mission1=false; mission2=true; }
showMissions();
keyboardInput="";
document.getElementById('maintext').textContent="MISSION "+(mission1?"1":"2");
setTimeout(confirmTemp,1000);
state=READY;
return false;
}
//------------------------------------------------------------------
function DATUM() {
if (!on) return false;
// Shift has no effect
if (state==CLEAR_ACTIVE) {
document.getElementById('maintext').textContent="MSN CLEARED";
// TODO - clear something ...
state=READY;
setTimeout(backToReady,1000);
return false;
}
keyboardInput="";
document.getElementById('maintext').textContent="NO TARGETS";
setTimeout(confirmTemp,1000);
state=READY;
return false;
}
//------------------------------------------------------------------
function DN() {
if (!on) return false;
if (state==CLEAR_ACTIVE) {
document.getElementById('maintext').textContent=INVALID_KEY;
state=READY;
setTimeout(backToReady,1000);
return false;
}
// TODO - Implement whatever it does ...
return false;
}
//------------------------------------------------------------------
function CLEAR() {
if (!on) return false;
if (state==CLEAR_ACTIVE) { // Can't press it twice
document.getElementById('maintext').textContent=INVALID_KEY;
state=READY;
setTimeout(backToReady,1000);
return false;
}
state=CLEAR_ACTIVE;
keyboardInput="";
document.getElementById('maintext').textContent="CLEAR _";
return false;
}//------------------------------------------------------------------
function ML() {
if (!on) return false;
// Shifted = set a new one, unshifted - show current
keyboardInput=""; // Cleanup
if (state==CLEAR_ACTIVE) {
document.getElementById('maintext').textContent=INVALID_KEY;
state=READY;
setTimeout(backToReady,1000);
return false;
}
if (shift) {
Shift(); // Cancel shift
if (state==RESECTION_FOUND) {
ml_grid=grid;
ml_alt=0; // Seems like a fault in the calculator - doesn't ask for alt after resection
state=TEMP_UPDATE;
defaultText="ML 00 READY"; // In future we show as set
document.getElementById('maintext').textContent="ACTIVE ML 00";
mission1=true;
mission2=true;
showMissions();
setTimeout(confirmTemp,2000);
} else if (state==READY) {
state=ML_GRID;
document.getElementById('maintext').textContent="ML GRID?";
}
} else {
if (ml_grid==-1) {
document.getElementById('maintext').textContent="NO RECORD";
setTimeout(backToReady,1000);
state=READY;
} else {
state=SHOW_ML_GRID;
document.getElementById('maintext').textContent="00 "+ml_grid;
}
}
return false;
}
//------------------------------------------------------------------
function showMissions() { // Not fully understood - the "12" at bottom of display
document.getElementById('one').textContent=(mission1)?"1":"";
document.getElementById('two').textContent=(mission2)?"2":"";
return;
}
//------------------------------------------------------------------
function MLs() {
if (!on) return false;
if (state==CLEAR_ACTIVE) {
document.getElementById('maintext').textContent="NO RECORD";
state=READY;
setTimeout(backToReady,1000);
return false;
}
// Shifted = set a new one, unshifted - show current
keyboardInput=""; // Cleanup
if (shift) {
Shift(); // Cancel shift
if (state==READY) {
state=ML_GRID;
document.getElementById('maintext').textContent="ML GRID?";
}
} else {
if (ml_grid==-1) {
document.getElementById('maintext').textContent="NO RECORD";
state=READY;
setTimeout(backToReady,1000);
} else {
state=SHOW_ML_GRID;
document.getElementById('maintext').textContent="00 "+ml_grid;
}
}
return false;
}
//------------------------------------------------------------------
function MET() {
if (!on) return false;
keyboardInput=""; // Cleanup
if (shift) {
Shift(); // Cancel shift
document.getElementById('maintext').textContent="MET GROUP 3?";
state=SETTING_MET;
} else {
document.getElementById('maintext').textContent="STANDARD MET";
state=READY;
setTimeout(backToReady,1000);
}
return false;
}
//------------------------------------------------------------------
function confirmTemp() {
if (!on) return false;
keyboardInput=""; // Cleanup
state=TEMP_UPDATE;
document.getElementById('maintext').textContent="CH TMP "+temperature+"C?";
return false;
}
//------------------------------------------------------------------
function Grid() {
if (!on) return false;
if (state==CLEAR_ACTIVE) {
document.getElementById('maintext').textContent="MSN CLEARED";
state=READY;
setTimeout(backToReady,1000);
return false;
}
if (state!=READY) return false;
if (ml_grid==-1) {
document.getElementById('maintext').textContent="NO ML";
state=READY;