forked from Zive-IT-2025/Solution
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.html
More file actions
1024 lines (905 loc) · 32.6 KB
/
dashboard.html
File metadata and controls
1024 lines (905 loc) · 32.6 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Smart Lighting Control System</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
:root {
--primary: #6366f1;
--primary-dark: #4f46e5;
--primary-light: #818cf8;
--secondary: #ec4899;
--accent: #06b6d4;
--success: #10b981;
--warning: #f59e0b;
--danger: #ef4444;
--bg-dark: #0f172a;
--bg-medium: #1e293b;
--bg-light: #334155;
--text-primary: #f1f5f9;
--text-secondary: #cbd5e1;
--text-muted: #94a3b8;
--border: #475569;
--shadow: rgba(0, 0, 0, 0.3);
}
body {
font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
background: linear-gradient(135deg, var(--bg-dark) 0%, var(--bg-medium) 100%);
color: var(--text-primary);
min-height: 100vh;
overflow-x: hidden;
}
/* Intro Animation */
#intro-screen {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: linear-gradient(135deg, var(--primary-dark) 0%, var(--secondary) 100%);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
z-index: 9999;
animation: fadeOut 0.8s ease-in-out 3s forwards;
}
@keyframes fadeOut {
to {
opacity: 0;
visibility: hidden;
}
}
.intro-logo {
font-size: 4rem;
font-weight: 700;
margin-bottom: 1rem;
animation: logoFloat 2s ease-in-out infinite;
text-shadow: 0 0 30px rgba(255, 255, 255, 0.5);
}
@keyframes logoFloat {
0%, 100% { transform: translateY(0px); }
50% { transform: translateY(-20px); }
}
.intro-text {
font-size: 1.5rem;
font-weight: 300;
letter-spacing: 3px;
opacity: 0;
animation: fadeIn 1s ease-in-out 0.5s forwards;
}
@keyframes fadeIn {
to { opacity: 1; }
}
.loading-bar {
width: 300px;
height: 4px;
background: rgba(255, 255, 255, 0.2);
border-radius: 2px;
margin-top: 2rem;
overflow: hidden;
}
.loading-progress {
height: 100%;
background: linear-gradient(90deg, var(--accent), white);
width: 0;
animation: loadProgress 2.5s ease-in-out forwards;
box-shadow: 0 0 20px rgba(255, 255, 255, 0.8);
}
@keyframes loadProgress {
to { width: 100%; }
}
/* Main Content */
#main-content {
opacity: 0;
animation: contentFadeIn 0.8s ease-in-out 3.2s forwards;
}
@keyframes contentFadeIn {
to { opacity: 1; }
}
/* Header */
header {
background: rgba(15, 23, 42, 0.8);
backdrop-filter: blur(10px);
border-bottom: 1px solid var(--border);
padding: 1.5rem 2rem;
position: sticky;
top: 0;
z-index: 100;
box-shadow: 0 4px 20px var(--shadow);
}
.header-content {
max-width: 1400px;
margin: 0 auto;
display: flex;
justify-content: space-between;
align-items: center;
}
.logo {
display: flex;
align-items: center;
gap: 1rem;
}
.logo-icon {
width: 50px;
height: 50px;
background: linear-gradient(135deg, var(--primary), var(--secondary));
border-radius: 12px;
display: flex;
align-items: center;
justify-content: center;
font-size: 1.8rem;
box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}
.logo-text h1 {
font-size: 1.5rem;
font-weight: 700;
background: linear-gradient(135deg, var(--primary-light), var(--secondary));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.logo-text p {
font-size: 0.75rem;
color: var(--text-muted);
margin-top: 0.25rem;
}
.status-badge {
padding: 0.5rem 1.5rem;
border-radius: 50px;
font-weight: 600;
font-size: 0.9rem;
display: flex;
align-items: center;
gap: 0.5rem;
transition: all 0.3s;
}
.status-badge.active {
background: linear-gradient(135deg, var(--success), #059669);
box-shadow: 0 4px 15px rgba(16, 185, 129, 0.4);
}
.status-badge.inactive {
background: linear-gradient(135deg, var(--danger), #dc2626);
box-shadow: 0 4px 15px rgba(239, 68, 68, 0.4);
}
.status-dot {
width: 10px;
height: 10px;
border-radius: 50%;
background: white;
animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.5; }
}
/* Container */
.container {
max-width: 1400px;
margin: 2rem auto;
padding: 0 2rem;
}
/* Grid Layout */
.dashboard-grid {
display: grid;
grid-template-columns: 1fr;
gap: 2rem;
margin-bottom: 2rem;
}
@media (max-width: 1024px) {
.dashboard-grid {
grid-template-columns: 1fr;
}
}
/* Video stream takes full width */
.video-section {
grid-column: 1 / -1;
}
/* Stats and controls side by side below video */
.bottom-panel {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 2rem;
}
@media (max-width: 1024px) {
.bottom-panel {
grid-template-columns: 1fr;
}
}
/* Cards */
.card {
background: rgba(30, 41, 59, 0.6);
backdrop-filter: blur(10px);
border: 1px solid var(--border);
border-radius: 20px;
padding: 2rem;
box-shadow: 0 8px 32px var(--shadow);
transition: all 0.3s;
}
.card:hover {
transform: translateY(-5px);
box-shadow: 0 12px 40px var(--shadow);
border-color: var(--primary);
}
.card-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 1.5rem;
}
.card-title {
font-size: 1.3rem;
font-weight: 600;
display: flex;
align-items: center;
gap: 0.75rem;
}
.card-title-icon {
width: 40px;
height: 40px;
background: linear-gradient(135deg, var(--primary), var(--primary-dark));
border-radius: 10px;
display: flex;
align-items: center;
justify-content: center;
font-size: 1.2rem;
}
/* Video Stream */
.video-container {
position: relative;
width: 100%;
min-height: 600px;
background: var(--bg-dark);
border-radius: 15px;
overflow: hidden;
box-shadow: 0 8px 32px var(--shadow);
}
#videoStream {
width: 100%;
height: 100%;
object-fit: contain;
}
.video-overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
background: rgba(15, 23, 42, 0.9);
color: var(--text-muted);
font-size: 1.2rem;
}
/* Controls */
.controls {
display: flex;
gap: 1rem;
margin-top: 1.5rem;
flex-wrap: wrap;
}
.btn {
padding: 0.875rem 2rem;
border: none;
border-radius: 12px;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: all 0.3s;
display: flex;
align-items: center;
gap: 0.5rem;
position: relative;
overflow: hidden;
}
.btn::before {
content: '';
position: absolute;
top: 50%;
left: 50%;
width: 0;
height: 0;
border-radius: 50%;
background: rgba(255, 255, 255, 0.3);
transform: translate(-50%, -50%);
transition: width 0.6s, height 0.6s;
}
.btn:hover::before {
width: 300px;
height: 300px;
}
.btn-primary {
background: linear-gradient(135deg, var(--primary), var(--primary-dark));
color: white;
box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}
.btn-primary:hover {
transform: translateY(-2px);
box-shadow: 0 6px 20px rgba(99, 102, 241, 0.6);
}
.btn-success {
background: linear-gradient(135deg, var(--success), #059669);
color: white;
box-shadow: 0 4px 15px rgba(16, 185, 129, 0.4);
}
.btn-success:hover {
transform: translateY(-2px);
box-shadow: 0 6px 20px rgba(16, 185, 129, 0.6);
}
.btn-danger {
background: linear-gradient(135deg, var(--danger), #dc2626);
color: white;
box-shadow: 0 4px 15px rgba(239, 68, 68, 0.4);
}
.btn-danger:hover {
transform: translateY(-2px);
box-shadow: 0 6px 20px rgba(239, 68, 68, 0.6);
}
.btn:disabled {
opacity: 0.5;
cursor: not-allowed;
transform: none;
}
/* Stats Grid */
.stats-grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 1rem;
margin-bottom: 1.5rem;
}
.stat-card {
background: linear-gradient(135deg, var(--bg-light), var(--bg-medium));
padding: 1.5rem;
border-radius: 15px;
border: 1px solid var(--border);
transition: all 0.3s;
}
.stat-card:hover {
border-color: var(--primary);
transform: translateY(-3px);
}
.stat-label {
font-size: 0.875rem;
color: var(--text-muted);
margin-bottom: 0.5rem;
display: flex;
align-items: center;
gap: 0.5rem;
}
.stat-value {
font-size: 2rem;
font-weight: 700;
background: linear-gradient(135deg, var(--primary-light), var(--accent));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
/* Light Control */
.light-control {
display: flex;
flex-direction: column;
gap: 1.5rem;
}
.slider-container {
display: flex;
flex-direction: column;
gap: 1rem;
}
.slider-header {
display: flex;
justify-content: space-between;
align-items: center;
}
.slider-label {
font-size: 1rem;
color: var(--text-secondary);
display: flex;
align-items: center;
gap: 0.5rem;
}
.slider-value {
font-size: 1.5rem;
font-weight: 700;
color: var(--primary-light);
}
input[type="range"] {
width: 100%;
height: 8px;
border-radius: 5px;
background: linear-gradient(90deg, var(--bg-dark), var(--primary));
outline: none;
-webkit-appearance: none;
}
input[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 24px;
height: 24px;
border-radius: 50%;
background: linear-gradient(135deg, var(--primary), var(--secondary));
cursor: pointer;
box-shadow: 0 4px 15px rgba(99, 102, 241, 0.6);
transition: all 0.3s;
}
input[type="range"]::-webkit-slider-thumb:hover {
transform: scale(1.2);
}
input[type="range"]::-moz-range-thumb {
width: 24px;
height: 24px;
border-radius: 50%;
background: linear-gradient(135deg, var(--primary), var(--secondary));
cursor: pointer;
box-shadow: 0 4px 15px rgba(99, 102, 241, 0.6);
border: none;
}
/* Activity Log */
.activity-log {
max-height: 400px;
overflow-y: auto;
}
.activity-log::-webkit-scrollbar {
width: 8px;
}
.activity-log::-webkit-scrollbar-track {
background: var(--bg-dark);
border-radius: 4px;
}
.activity-log::-webkit-scrollbar-thumb {
background: var(--primary);
border-radius: 4px;
}
.activity-item {
padding: 1rem;
background: var(--bg-dark);
border-left: 3px solid var(--primary);
border-radius: 8px;
margin-bottom: 0.75rem;
transition: all 0.3s;
}
.activity-item:hover {
transform: translateX(5px);
border-left-color: var(--accent);
}
.activity-time {
font-size: 0.75rem;
color: var(--text-muted);
margin-bottom: 0.25rem;
}
.activity-message {
font-size: 0.9rem;
color: var(--text-secondary);
}
/* Notifications */
.notification {
position: fixed;
top: 5rem;
right: 2rem;
min-width: 300px;
background: rgba(30, 41, 59, 0.95);
backdrop-filter: blur(10px);
border: 1px solid var(--border);
border-radius: 12px;
padding: 1rem 1.5rem;
box-shadow: 0 8px 32px var(--shadow);
animation: slideIn 0.3s ease-out;
z-index: 1000;
}
@keyframes slideIn {
from {
transform: translateX(400px);
opacity: 0;
}
to {
transform: translateX(0);
opacity: 1;
}
}
.notification.success {
border-left: 4px solid var(--success);
}
.notification.error {
border-left: 4px solid var(--danger);
}
.notification.info {
border-left: 4px solid var(--accent);
}
/* Camera Selection */
.camera-select {
width: 100%;
padding: 0.875rem;
background: var(--bg-dark);
border: 1px solid var(--border);
border-radius: 10px;
color: var(--text-primary);
font-size: 1rem;
cursor: pointer;
transition: all 0.3s;
}
.camera-select:focus {
outline: none;
border-color: var(--primary);
box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}
.camera-select option {
background: var(--bg-dark);
color: var(--text-primary);
}
/* Full width section */
.full-width-section {
grid-column: 1 / -1;
}
/* Footer */
footer {
text-align: center;
padding: 2rem;
color: var(--text-muted);
border-top: 1px solid var(--border);
margin-top: 4rem;
}
/* Loading Spinner */
.spinner {
width: 40px;
height: 40px;
border: 4px solid var(--bg-light);
border-top: 4px solid var(--primary);
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
</style>
</head>
<body>
<!-- Intro Screen -->
<div id="intro-screen">
<div class="intro-logo">💡🎥</div>
<div class="intro-text">SMART LIGHTING CONTROL</div>
<div class="loading-bar">
<div class="loading-progress"></div>
</div>
</div>
<!-- Main Content -->
<div id="main-content">
<!-- Header -->
<header>
<div class="header-content">
<div class="logo">
<div class="logo-icon">💡</div>
<div class="logo-text">
<h1>Smart Lighting Control</h1>
<p>AI-Powered Object Detection System</p>
</div>
</div>
<div class="status-badge inactive" id="systemStatus">
<span class="status-dot"></span>
<span>System Inactive</span>
</div>
</div>
</header>
<!-- Main Dashboard -->
<div class="container">
<!-- Video Stream Section - Full Width -->
<div class="card video-section">
<div class="card-header">
<h2 class="card-title">
<span class="card-title-icon">🎥</span>
Multi-Camera Live Stream
</h2>
</div>
<div class="video-container">
<img id="videoStream" alt="Video Stream" style="display: none;">
<div class="video-overlay" id="videoOverlay">
<div style="text-align: center;">
<div class="spinner" style="margin: 0 auto 1rem;"></div>
<p>Waiting for stream...</p>
</div>
</div>
</div>
<div class="controls">
<button class="btn btn-success" id="startBtn" onclick="startProcessing()">
<span>▶️</span> Start Detection
</button>
<button class="btn btn-danger" id="stopBtn" onclick="stopProcessing()" disabled>
<span>⏹️</span> Stop Detection
</button>
<select class="camera-select" id="cameraSelect" onchange="switchCamera()" style="max-width: 300px;">
<option value="">Select Camera Source</option>
</select>
</div>
</div>
<!-- Bottom Panel: Stats and Controls -->
<div class="bottom-panel">
<!-- Statistics -->
<div class="card">
<div class="card-header">
<h2 class="card-title">
<span class="card-title-icon">📊</span>
Detection Statistics
</h2>
</div>
<div class="stats-grid">
<div class="stat-card">
<div class="stat-label">👥 People Detected</div>
<div class="stat-value" id="peopleCount">0</div>
</div>
<div class="stat-card">
<div class="stat-label">🎯 Total Objects</div>
<div class="stat-value" id="objectCount">0</div>
</div>
<div class="stat-card">
<div class="stat-label">⚡ FPS</div>
<div class="stat-value" id="fpsValue">0</div>
</div>
<div class="stat-card">
<div class="stat-label">💡 Light Status</div>
<div class="stat-value" id="lightStatus">OFF</div>
</div>
</div>
</div>
<!-- Light Control -->
<div class="card">
<div class="card-header">
<h2 class="card-title">
<span class="card-title-icon">💡</span>
Manual Light Control
</h2>
</div>
<div class="light-control">
<div class="slider-container">
<div class="slider-header">
<span class="slider-label">🔆 Brightness</span>
<span class="slider-value" id="brightnessValue">0%</span>
</div>
<input type="range" id="brightnessSlider" min="0" max="100" value="0"
oninput="updateBrightnessDisplay(this.value)">
</div>
<div class="controls">
<button class="btn btn-primary" onclick="setLightBrightness()">
<span>✨</span> Apply Brightness
</button>
<button class="btn btn-danger" onclick="turnOffLights()">
<span>🌙</span> Turn Off
</button>
</div>
</div>
</div>
</div>
<!-- Activity Log -->
<div class="card full-width-section">
<div class="card-header">
<h2 class="card-title">
<span class="card-title-icon">📝</span>
Activity Log
</h2>
<button class="btn btn-primary" onclick="clearLog()" style="padding: 0.5rem 1rem; font-size: 0.875rem;">
Clear Log
</button>
</div>
<div class="activity-log" id="activityLog">
<div class="activity-item">
<div class="activity-time" id="initTime"></div>
<div class="activity-message">System initialized and ready</div>
</div>
</div>
</div>
</div>
<!-- Footer -->
<footer>
<p>Smart Lighting Control System v1.0 | Powered by YOLOv8 & FastAPI</p>
</footer>
</div>
<script>
let updateInterval;
let streamActive = false;
// Initialize
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('initTime').textContent = new Date().toLocaleString();
loadCameras();
startStatusPolling();
});
// Show notification
function showNotification(message, type = 'info') {
const notification = document.createElement('div');
notification.className = `notification ${type}`;
notification.textContent = message;
document.body.appendChild(notification);
setTimeout(() => {
notification.style.animation = 'slideIn 0.3s ease-out reverse';
setTimeout(() => notification.remove(), 300);
}, 3000);
}
// Add activity log
function addActivityLog(message) {
const log = document.getElementById('activityLog');
const item = document.createElement('div');
item.className = 'activity-item';
item.innerHTML = `
<div class="activity-time">${new Date().toLocaleString()}</div>
<div class="activity-message">${message}</div>
`;
log.insertBefore(item, log.firstChild);
// Keep only last 20 items
while (log.children.length > 20) {
log.removeChild(log.lastChild);
}
}
// Clear log
function clearLog() {
const log = document.getElementById('activityLog');
log.innerHTML = `
<div class="activity-item">
<div class="activity-time">${new Date().toLocaleString()}</div>
<div class="activity-message">Log cleared</div>
</div>
`;
}
// Load available cameras
async function loadCameras() {
try {
const response = await fetch('/status');
const data = await response.json();
const select = document.getElementById('cameraSelect');
if (data.available_cameras) {
data.available_cameras.forEach(camera => {
const option = document.createElement('option');
option.value = camera.id;
option.textContent = camera.name;
if (camera.id === data.current_camera) {
option.selected = true;
}
select.appendChild(option);
});
}
} catch (error) {
console.error('Error loading cameras:', error);
}
}
// Switch camera
async function switchCamera() {
const cameraId = document.getElementById('cameraSelect').value;
if (!cameraId) return;
try {
const response = await fetch('/camera/switch', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ camera_id: cameraId })
});
if (response.ok) {
showNotification('Camera switched successfully', 'success');
addActivityLog(`Switched to camera: ${cameraId}`);
} else {
showNotification('Failed to switch camera', 'error');
}
} catch (error) {
showNotification('Error switching camera', 'error');
}
}
// Start processing
async function startProcessing() {
try {
const response = await fetch('/start', { method: 'POST' });
if (response.ok) {
document.getElementById('startBtn').disabled = true;
document.getElementById('stopBtn').disabled = false;
document.getElementById('videoOverlay').style.display = 'none';
document.getElementById('videoStream').style.display = 'block';
document.getElementById('videoStream').src = '/stream?' + new Date().getTime();
streamActive = true;
showNotification('Detection started', 'success');
addActivityLog('Object detection system started');
updateSystemStatus(true);
} else {
showNotification('Failed to start detection', 'error');
}
} catch (error) {
showNotification('Error starting detection', 'error');
}
}
// Stop processing
async function stopProcessing() {
try {
const response = await fetch('/stop', { method: 'POST' });
if (response.ok) {
document.getElementById('startBtn').disabled = false;
document.getElementById('stopBtn').disabled = true;
document.getElementById('videoStream').style.display = 'none';
document.getElementById('videoOverlay').style.display = 'flex';
streamActive = false;
showNotification('Detection stopped', 'info');
addActivityLog('Object detection system stopped');
updateSystemStatus(false);
} else {
showNotification('Failed to stop detection', 'error');
}
} catch (error) {
showNotification('Error stopping detection', 'error');
}
}
// Update system status badge
function updateSystemStatus(active) {
const badge = document.getElementById('systemStatus');
if (active) {
badge.className = 'status-badge active';
badge.querySelector('span:last-child').textContent = 'System Active';
} else {
badge.className = 'status-badge inactive';
badge.querySelector('span:last-child').textContent = 'System Inactive';
}
}
// Update brightness display
function updateBrightnessDisplay(value) {
document.getElementById('brightnessValue').textContent = value + '%';
}
// Set light brightness
async function setLightBrightness() {
const brightness = document.getElementById('brightnessSlider').value;
try {
const response = await fetch('/lights/brightness', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ brightness: parseInt(brightness) })
});
if (response.ok) {
showNotification(`Brightness set to ${brightness}%`, 'success');
addActivityLog(`Light brightness adjusted to ${brightness}%`);
} else {
showNotification('Failed to set brightness', 'error');
}
} catch (error) {
showNotification('Error setting brightness', 'error');
}
}
// Turn off lights
async function turnOffLights() {
try {
const response = await fetch('/lights/off', { method: 'POST' });
if (response.ok) {
document.getElementById('brightnessSlider').value = 0;
updateBrightnessDisplay(0);
showNotification('Lights turned off', 'success');
addActivityLog('Lights turned off manually');
} else {
showNotification('Failed to turn off lights', 'error');
}
} catch (error) {
showNotification('Error turning off lights', 'error');
}
}
// Poll status updates
function startStatusPolling() {
setInterval(async () => {
try {
const response = await fetch('/status');
const data = await response.json();