-
Notifications
You must be signed in to change notification settings - Fork 0
/
openstellina.ml
1836 lines (1662 loc) · 53.8 KB
/
openstellina.ml
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
open Js_of_ocaml
open Lwt.Syntax
open Astro_utils
open Telescope
open Lwt.Infix
open Js_of_ocaml_lwt
open Js_of_ocaml_tyxml
open Tyxml_js.Html
open Geolocate
open Utils
type tab_config = {
id: string;
label: string;
description: string;
content: Html_types.div Tyxml_js.Html.elt;
}
(* Control state type definition *)
type control_state = [
| `NoControl (* No one has control *)
| `RequestingControl (* We are requesting control *)
| `HasControl (* We have control *)
| `OtherHasControl of string (* Another client has control *)
]
type action =
| Idle
| TakeControl
| ReleaseControl
| Motor
| Status
| Consume
| Init
| Observe
| Park
| Openarm
(*
type motor_update = {
position: float;
state: string;
calibrated: bool;
at_stop: bool option; (* Only AZ has atStop *)
}
*)
(* Control state tracking variables *)
let control_state = ref (`NoControl:control_state)
let control_owner = ref None
let control_request_time = ref 0.0
let websocket = ref None
let action = ref Idle
let connect = ref false
let canvas_width = 1280.
let canvas_height = 480.
let action_seq = ref 0
let delay_seq = ref 0
let verbose = ref false
let verbose' = ref true
let poll_type = ref true
(* Add control state tracking *)
let has_control = ref false
let control_pending = ref false
let sid = ref ""
let ping_interval = ref 25000
let ping_timeout = ref 60000
let tab_styles = {|
/* Base Layout */
.tabs-container {
width: 100%;
max-width: 1200px; /* Increased from 800px */
margin: 0 auto;
padding: 20px;
}
/* Control Actions Layout */
.control-actions {
display: flex;
flex-wrap: wrap;
gap: 4px;
margin-top: 12px;
justify-content: flex-start;
}
.control-button {
padding: 8px 12px; /* Slightly increased padding */
border-radius: 4px;
border: none;
cursor: pointer;
font-size: 14px;
transition: all 0.2s;
background: #e5e7eb;
color: #374151;
min-width: min-content; /* Ensure buttons take minimum required width */
white-space: nowrap; /* Prevent button text from wrapping */
}
/* Responsive adjustments */
@media (max-width: 768px) {
.tabs-container {
max-width: 100%;
padding: 10px;
}
.control-actions {
flex-wrap: wrap;
}
.control-button {
flex: 1 1 auto;
min-width: calc(50% - 8px); /* Two buttons per row on smaller screens */
}
}
@media (max-width: 480px) {
.control-button {
min-width: 100%; /* Full width buttons on very small screens */
}
}
/* Base Layout */
.tabs-container {
width: 100%;
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
/* Tab Navigation */
.tab-buttons {
display: flex;
gap: 4px;
margin-bottom: -1px;
position: relative;
z-index: 1;
border-bottom: 1px solid #ddd;
}
.tab-button-container {
position: relative;
}
.tab-btn {
padding: 10px 20px;
border: 1px solid #ddd;
border-bottom: none;
border-radius: 8px 8px 0 0;
background: #f0f0f0;
cursor: pointer;
transition: all 0.3s;
font-size: 14px;
}
.tab-btn.active {
background: white;
border-bottom-color: white;
color: #007bff;
}
.tab-tooltip {
display: none;
position: absolute;
bottom: 100%;
left: 50%;
transform: translateX(-50%);
background: #333;
color: white;
padding: 5px 10px;
border-radius: 4px;
font-size: 12px;
white-space: nowrap;
z-index: 20;
}
.tab-content {
background: white;
border: 1px solid #ddd;
border-radius: 0 0 8px 8px;
padding: 20px;
margin-top: -1px;
}
.tab-content-item {
display: none;
}
.tab-content-item.active {
display: block;
}
/* Status Indicators */
.status-pill {
display: inline-block;
padding: 4px 12px;
border-radius: 12px;
font-size: 14px;
margin-bottom: 12px;
}
.connected {
background: #10b981;
color: white;
}
.disconnected {
background: #ef4444;
color: white;
}
/* Message Panel */
.message-panel {
height: 200px;
overflow-y: auto;
background: #f8f9fa;
border: 1px solid #ddd;
border-radius: 4px;
padding: 8px;
margin-top: 12px;
font-family: monospace;
font-size: 13px;
}
.message {
padding: 4px 8px;
margin: 4px 0;
border-radius: 4px;
white-space: pre-wrap;
word-break: break-word;
}
.message.error {
background: #fee2e2;
color: #991b1b;
}
.message.info {
background: #dbeafe;
color: #1e40af;
}
/* Telescope Display */
.telescope-display {
display: flex;
flex-direction: column;
gap: 1rem;
padding: 1rem;
}
.status-section {
background: #fff;
border: 1px solid #ddd;
border-radius: 4px;
padding: 1rem;
margin-bottom: 1rem;
}
.section-title {
font-weight: bold;
margin-bottom: 0.5rem;
color: #2563eb;
}
.status-row {
display: flex;
justify-content: space-between;
padding: 0.25rem 0;
border-bottom: 1px solid #f3f4f6;
}
.status-label {
color: #666;
}
.status-value {
font-family: monospace;
color: #111;
}
/* Control Panel */
.control-status-widget {
background: #f8f9fa;
border: 1px solid #ddd;
border-radius: 4px;
padding: 12px;
margin-bottom: 16px;
}
.control-status-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 8px;
}
.control-indicator {
display: flex;
align-items: center;
gap: 8px;
}
.status-dot {
width: 10px;
height: 10px;
border-radius: 50%;
flex-shrink: 0;
}
.status-dot.no-control { background-color: #666666; }
.status-dot.has-control { background-color: #10b981; }
.status-dot.requesting { background-color: #f59e0b; }
.status-dot.other-control { background-color: #ef4444; }
.control-details {
font-size: 14px;
color: #666;
margin: 8px 0;
}
.control-actions {
display: flex;
gap: 8px;
margin-top: 12px;
}
.control-button {
padding: 6px 12px;
border-radius: 4px;
border: none;
cursor: pointer;
font-size: 14px;
transition: all 0.2s;
background: #e5e7eb;
color: #374151;
}
.control-button:hover:not(:disabled) {
opacity: 0.9;
}
.control-button.take {
background-color: #10b981;
color: white;
}
.control-button.release {
background-color: #ef4444;
color: white;
}
.control-button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.control-warning {
margin: 8px 0;
padding: 8px 12px;
background: #fee2e2;
color: #991b1b;
border-radius: 4px;
font-weight: bold;
}
/* Debug Settings */
.debug-settings {
padding: 16px;
background: #f8f9fa;
border: 1px solid #ddd;
border-radius: 4px;
}
.debug-row {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
}
.debug-checkbox {
width: 16px;
height: 16px;
}
/* Enhanced 3D Tab Effects */
.tab-buttons {
display: flex;
gap: 4px;
margin-bottom: -1px;
position: relative;
z-index: 1;
border-bottom: 1px solid #ddd;
perspective: 1000px;
}
.tab-button-container {
position: relative;
}
.tab-btn {
padding: 10px 20px;
border: 1px solid #ddd;
border-bottom: none;
border-radius: 8px 8px 0 0;
background: #f0f0f0;
cursor: pointer;
transition: all 0.3s cubic-bezier(.25,.8,.25,1);
font-size: 14px;
transform: rotateX(0deg) translateY(15px);
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
}
.tab-btn:not(.active):hover {
transform: rotateX(-2deg) translateY(12px);
box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
}
.tab-btn.active {
background: white;
border-bottom-color: white;
color: #007bff;
transform: rotateX(-5deg);
box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23);
z-index: 10;
}
.tab-content {
background: white;
border: 1px solid #ddd;
border-radius: 0 0 8px 8px;
padding: 20px;
margin-top: -1px;
box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23);
position: relative;
z-index: 1;
}
/* Picker Panels */
.picker-panel {
padding: 20px;
background: #f8f9fa;
border: 1px solid #ddd;
border-radius: 4px;
}
.picker-panel select {
width: 100%;
padding: 8px;
margin: 10px 0;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 14px;
}
.picker-button {
padding: 8px 16px;
background: #007bff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
transition: background-color 0.2s;
}
.picker-button:hover {
background: #0056b3;
}
/* Location Picker */
.location-panel {
padding: 20px;
background: #f8f9fa;
border: 1px solid #ddd;
border-radius: 4px;
}
.location-input {
width: 100%;
padding: 8px;
margin: 10px 0;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 14px;
}
.location-button {
padding: 8px 16px;
background: #28a745;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
margin-right: 8px;
transition: background-color 0.2s;
}
.location-button:hover {
background: #218838;
}
/* Base Layout */
.tabs-container {
width: 100%;
max-width: 800px;
margin: 0 auto;
padding: 20px;
background: white;
display: block !important;
visibility: visible !important;
}
/* Safari-specific fixes */
@supports (-webkit-hyphens:none) {
.control-button {
-webkit-appearance: none;
display: inline-block !important;
visibility: visible !important;
}
.control-actions {
display: -webkit-flex;
display: flex;
-webkit-flex-wrap: wrap;
flex-wrap: wrap;
gap: 8px;
margin-top: 12px;
visibility: visible !important;
}
.tabs-container {
visibility: visible !important;
-webkit-transform: translate3d(0,0,0);
}
}
.secure-connection-panel {
padding: 20px;
background: #f8f9fa;
border: 1px solid #ddd;
border-radius: 4px;
}
.secure-warning {
margin: 16px 0;
padding: 12px;
background: #fff3cd;
border: 1px solid #ffeeba;
border-radius: 4px;
color: #856404;
}
.secure-info {
margin: 16px 0;
padding: 12px;
background: #d4edda;
border: 1px solid #c3e6cb;
border-radius: 4px;
color: #155724;
}
.secure-redirect {
margin-top: 12px;
background-color: #28a745 !important;
color: white !important;
}
.secure-redirect:hover {
background-color: #218838 !important;
}
/* Base Layout */
.tabs-container {
width: 100%;
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
.secure-connection-panel {
padding: 20px;
background: #f8f9fa;
border: 1px solid #ddd;
border-radius: 4px;
}
.secure-warning {
margin: 16px 0;
padding: 12px;
background: #fff3cd;
border: 1px solid #ffeeba;
border-radius: 4px;
color: #856404;
}
.secure-info {
margin: 16px 0;
padding: 12px;
background: #d4edda;
border: 1px solid #c3e6cb;
border-radius: 4px;
color: #155724;
}
.secure-redirect {
margin-top: 12px;
background-color: #28a745 !important;
color: white !important;
}
.http-redirect {
margin-top: 12px;
background-color: #dc3545 !important;
color: white !important;
}
.control-panel.disabled {
opacity: 0.5;
pointer-events: none;
}
.control-disabled-message {
padding: 20px;
background: #f8d7da;
border: 1px solid #f5c6cb;
border-radius: 4px;
color: #721c24;
margin-bottom: 20px;
}
|}
let create_styled_div ?(a=[]) contents =
div ~a contents
let show_error text = add_message "error" text
let show_info text = add_message "info" text
let new_challenge = ref false
let get_session_id (fn:Yojson.Safe.t->unit) =
let headers = Astro_utils.split ["Accept: */*"] in
let params = [
("EIO", "3");
("transport", "polling");
("id", "openstellina-web");
("name", "openstellina-web")
] in
let iter = fun s -> fn (cnv s) in
Astro_utils.get' proto server params headers
(pth3'^"/socket.io/") (cnv' iter) hdrs
(* Release control sequence *)
let release_control () =
if !has_control then begin
(match !websocket with
| Some ws ->
let msg = {|42["message","releaseControl"]|} in
ws##send (Js.string msg);
show_info "Releasing control"
| None ->
has_control := false;
show_info "No websocket connection")
end
(* Add control message constructors *)
let make_take_control_msg () =
{|42["message","takeControl"]|}
let make_release_control_msg () =
{|42["message","releaseControl"]|}
let canvas =
let r = Dom_html.createCanvas Dom_html.document in
r##.width := int_of_float canvas_width;
r##.height := int_of_float canvas_height;
r
type graphics =
| Empty
| Fill of string * float * float
| Font of string
| Stroke of float * float * float * float
let send_message msg =
(match !websocket with
| Some ws ->
if !verbose' then show_info ("WS sending: " ^ msg);
ws##send (Js.string msg);
true
| None ->
show_info "No websocket connection";
false)
let create_status_section titled items =
div ~a:[a_class ["status-section"]] (
div ~a:[a_class ["section-title"]] [txt titled] ::
List.map (fun (label, value_ref) ->
div ~a:[a_class ["status-row"]] [
div ~a:[a_class ["status-label"]] [txt label];
div ~a:[
a_id ("status-" ^ label);
a_class ["status-value"]
] [txt !value_ref]
]
) items
)
let process_json_value path = function
| `Float f ->
begin match path with
| ["sensors"; "temperature"] -> Telescope.tempref := string_of_float f
| ["sensors"; "humidity"] -> Telescope.humref := string_of_float f
| ["dewpointDepression"] -> Telescope.dewpointref := string_of_float f
| ["motors"; "AZ"; "position"] -> Telescope.az_posref := string_of_float f
| ["motors"; "ALT"; "position"] -> Telescope.alt_posref := string_of_float f
| _ -> ()
end
| `String s ->
begin match path with
| ["challenge"] ->
if !Telescope.challengeref <> s then (
new_challenge := true;
show_info ("Challenge: "^s);
Telescope.challengeref := s
)
| ["telescopeId"] ->
if !Telescope.telescopeId <> s then (
new_challenge := true;
show_info ("Telescope ID: "^s);
Telescope.telescopeId := s
)
| ["currentOperation"; "type"] -> Telescope.debugref := s
| ["error"; "name"] -> Telescope.errorref := s
| ["defogStatus"] -> Telescope.defogref := s
| _ -> ()
end
| `Int i ->
begin match path with
| ["bootCount"] ->
if !Telescope.bootCnt <> i then (
new_challenge := true;
show_info ("Boot Count: "^string_of_int i);
Telescope.bootCnt := i
)
| _ -> ()
end
| _ -> ()
let create_telescope_display () =
div ~a:[a_class ["telescope-display"]] [
create_status_section "System" [
("ID", Telescope.telescopeId);
("Model", Telescope.model_ref);
("API Version", Telescope.api_version_ref);
("Version", Telescope.version_ref);
("Boot Count", ref (string_of_int !Telescope.bootCnt));
("Auth", ref "Unknown");
("Challenge", Telescope.challengeref)
];
create_status_section "Slewing" [
("AZ Position", az_posref);
("AZ State", ref !motor_state_ref);
("ALT Position", alt_posref);
("ALT State", ref !motor_state_ref);
(* Target coordinates *)
("Target Name", ref (!get_target_value()));
("Target RA", entry_ra_ref);
("Target DEC", entry_dec_ref);
("Target ALT", entry_alt_ref);
("Target AZ", entry_az_ref);
(* Exposure settings *)
("Exposure", entry_exp_ref);
("DER Position", der_posref);
("DER State", ref !motor_state_ref);
("MAP Position", map_posref);
("MAP State", ref !motor_state_ref)
];
create_status_section "Environment" [
("Temperature", Telescope.tempref);
("Temp Delta", Telescope.temperature_delta_ref);
("Humidity", Telescope.humref);
("Humidity Delta", Telescope.humidity_delta_ref);
("Dew Point", Telescope.dewpointref);
("Dew Point Depression", Telescope.dewpointref);
("Defog Status", Telescope.defogref)
];
create_status_section "Status" [
("Operation", Telescope.debugref);
("Error", Telescope.errorref)
];
create_status_section "Storage" [
("System Size", Telescope.storage_system_size_ref);
("System Available", Telescope.storage_system_avail_ref);
("Data Size", Telescope.storage_data_size_ref);
("Data Available", Telescope.storage_data_avail_ref);
("Network Band", Telescope.storage_band_ref)
];
create_status_section "Updates" [
("Installed Version", Telescope.installed_version_ref);
("Min Compatible", Telescope.min_compat_version_ref);
("State", Telescope.update_state_ref)
];
create_status_section "Current Observation" [
("Target", Telescope.current_target_ref);
("Latitude", Telescope.position_lat_ref);
("Longitude", Telescope.position_lon_ref)
]
]
let debug_mode = ref true
let debug_flag = ref false
let create_debug_settings () =
div ~a:[a_class ["debug-settings"]] [
div ~a:[a_class ["section-title"]] [txt "Debug Settings"];
div ~a:[a_class ["debug-row"]] [
input ~a:[
a_input_type `Checkbox;
a_id "debug-enable";
a_class ["debug-checkbox"];
a_onclick (fun _ ->
debug_flag := not !debug_flag;
Geo.set_cookie "debug" (string_of_bool !debug_flag);
true)
] ();
label ~a:[a_label_for "debug-enable"] [txt "Enable Debug Mode"]
];
div ~a:[a_class ["debug-row"]] [
input ~a:[
a_input_type `Checkbox;
a_id "verbose-enable";
a_class ["debug-checkbox"];
a_onclick (fun _ ->
verbose := not !verbose;
Geo.set_cookie "verbose" (string_of_bool !verbose);
true)
] ();
label ~a:[a_label_for "verbose-enable"] [txt "Enable Verbose Logging"]
]
]
let debug_msg msg =
if !debug_flag then begin
if !verbose then print_endline ("DEBUG: " ^ msg);
show_info msg
end
let verbose_msg msg =
if !verbose then
debug_msg msg
(* Process motor updates from status message *)
let process_motors status =
let open Yojson.Safe.Util in
try
let motors = member "motors" status in
(try
let az = member "AZ" motors in
let az_pos = member "position" az |> to_float in
let az_state = member "state" az |> to_string in
let az_stop = member "atStop" az |> to_bool_option in
let az_cal = member "calibrated" az |> to_bool in
debug_msg ("AZ: " ^ string_of_float az_pos ^ " " ^ az_state);
update_display_value "status-AZ Position" (Printf.sprintf "%.2f°" az_pos);
update_display_value "status-AZ State" az_state;
with _ -> ());
(try
let alt = member "ALT" motors in
let alt_pos = member "position" alt |> to_float in
let alt_state = member "state" alt |> to_string in
let alt_cal = member "calibrated" alt |> to_bool in
debug_msg ("ALT: " ^ string_of_float alt_pos ^ " " ^ alt_state);
update_display_value "status-ALT Position" (Printf.sprintf "%.2f°" alt_pos);
update_display_value "status-ALT State" alt_state;
with _ -> ());
with _ -> ()
let last_ctrl = ref (`OtherHasControl "")
let last_class = ref ""
(* Add button refs to track panel buttons *)
let button_lst =
let trim' a = String.lowercase_ascii (if String.contains a ' ' then String.sub a 0 (String.index a ' ') else a) in
let button' a b =
let c = trim' a in
button ~a:[
a_id (c^"-control-button");
a_class ["control-button"; c];
a_onclick (fun _ ->
action := b;
true)
] [txt a] in
[
button' "Take Control" TakeControl;
button' "Release" ReleaseControl;
button' "Initialize" Init;
button' "Observe" Observe;
button' "Park" Park;
button' "Open arm" Openarm;
button' "Status" Status;
button' "Consume" Consume
]
let panel_warning = ref None
let last_display_state = ref (`NoControl:control_state)
let update_control_display () =
if !control_state <> !last_display_state then begin
show_info (Printf.sprintf "Control state changed from %s to %s"
(match !last_display_state with
| `NoControl -> "NoControl"
| `RequestingControl -> "RequestingControl"
| `HasControl -> "HasControl"
| `OtherHasControl u -> "OtherHasControl:" ^ u)
(match !control_state with
| `NoControl -> "NoControl"
| `RequestingControl -> "RequestingControl"
| `HasControl -> "HasControl"
| `OtherHasControl u -> "OtherHasControl:" ^ u));
last_display_state := !control_state;
(* Rest of display update code *)
end;
let debug_msg s = if !verbose then debug_msg ("Control update: " ^ s) in
(* Update status dot *)
(match Dom_html.getElementById_opt "control-status-dot" with
| Some dot ->
let status_class = match !control_state with
| `NoControl -> "status-dot no-control"
| `RequestingControl -> "status-dot requesting"
| `HasControl -> "status-dot has-control"
| `OtherHasControl _ -> "status-dot other-control"
in
dot##.className := Js.string status_class
| None -> debug_msg "Could not find status dot");
(* Update control panel buttons *)
List.iter (fun btn' -> Js.Opt.iter (Dom_html.CoerceTo.button (Tyxml_js.To_dom.of_button btn')) (fun btn ->
let btn_text = Js.to_string (Js.Opt.get btn##.textContent (fun () -> Js.string "")) in
btn##.disabled := Js.bool (match !control_state with
| `HasControl -> false
| `NoControl -> btn_text <> "Take Control"
| `RequestingControl -> true
| `OtherHasControl _ -> btn##.value = Js.string "Release"
))
) button_lst;
(* Update warning display *)
(match !panel_warning with
| Some warning ->
warning##.style##.display := Js.string (
match !control_state with
| `OtherHasControl device ->
warning##.innerHTML := Js.string ("Telescope is being controlled by: " ^ device);
"block"
| _ -> "none"
)
| None -> ());
(* Update status text *)
(match Dom_html.getElementById_opt "control-status-text" with
| Some text ->
let status_msg = match !control_state with
| `NoControl -> "No Control"
| `RequestingControl -> "Requesting Control"
| `HasControl -> "Has Control"
| `OtherHasControl user -> "Controlled by " ^ user
in
debug_msg ("Setting status text to: " ^ status_msg);
text##.textContent := Js.some (Js.string status_msg)
| None -> debug_msg "Could not find status text");
(* Update detailed message *)
(match Dom_html.getElementById_opt "control-details" with
| Some details ->
let msg = match !control_state with
| `NoControl -> "The telescope is not being controlled"
| `RequestingControl -> "Attempting to take control..."
| `HasControl -> "You are controlling the telescope"
| `OtherHasControl user -> "Telescope is being controlled by " ^ user
in
debug_msg ("Setting details to: " ^ msg);
details##.textContent := Js.some (Js.string msg)
| None -> debug_msg "Could not find details element");
(* Update buttons *)
(match Dom_html.getElementById_opt "take-control-button" with
| Some element ->
Js.Opt.iter (Dom_html.CoerceTo.input element)
(fun btn ->
let should_disable = match !control_state with
| `NoControl -> false
| _ -> true
in