-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
318 lines (293 loc) · 10.6 KB
/
index.html
File metadata and controls
318 lines (293 loc) · 10.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Quantix - Object Counter Dashboard</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://unpkg.com/lucide@latest"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<style>
@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;900&display=swap");
body {
font-family: "Inter", sans-serif;
color: #000000;
}
.no-scrollbar::-webkit-scrollbar {
display: none;
}
.no-scrollbar {
-ms-overflow-style: none;
scrollbar-width: none;
}
/* Custom Navy Styles */
.text-navy {
color: #000000;
}
.bg-navy {
background-color: #000000;
}
.border-navy {
border-color: #000000;
}
.passing-active {
transform: scale(1.1);
color: #000000 !important;
}
.glow-active {
background-color: rgba(0, 24, 88, 0.15);
filter: blur(20px);
}
</style>
</head>
<body
class="bg-gray-50 h-screen overflow-hidden flex flex-col text-[#000000]"
>
<div
class="max-w-7xl mx-auto w-full h-full flex flex-col p-6 md:p-10 space-y-6"
>
<div
class="flex flex-col md:flex-row md:items-center justify-between gap-4 flex-none"
>
<div>
<h1 class="text-3xl font-bold tracking-tight">Object Counter</h1>
<p class="text-[#000000]/60 text-sm">
IR-based entry counting with Google Sheets logging.
</p>
</div>
<div class="flex items-center gap-3">
<span
id="ir-badge"
class="inline-flex items-center gap-2 px-3 py-1 rounded-full bg-slate-200 text-xs font-medium transition-all duration-300"
>
<i data-lucide="zap" id="zap-icon" class="h-3.5 w-3.5"></i>
IR Sensor: <span id="ir-status">IDLE</span>
</span>
</div>
</div>
<div class="grid gap-6 md:grid-cols-2 lg:grid-cols-3 flex-1 min-h-0 pb-6">
<div
class="rounded-xl border border-[#000000]/10 bg-white shadow-sm flex flex-col overflow-hidden relative"
>
<div class="absolute top-0 right-0 p-6 text-primary">
<i data-lucide="settings-2" class="h-8 w-8 cursor-pointer"></i>
</div>
<div class="p-6 border-b border-gray-50">
<h3 class="font-semibold leading-none tracking-tight">
Live Counter
</h3>
<p class="text-xs text-[#000000]/60 mt-1">
Total objects detected since reset.
</p>
</div>
<div class="flex-1 flex flex-col items-center justify-center p-6">
<div class="relative mb-8">
<div
id="glow"
class="absolute -inset-6 rounded-full transition-all duration-500 bg-transparent"
></div>
<span
id="counter-value"
class="relative text-8xl font-black tabular-nums transition-all duration-300"
>0</span
>
</div>
<button
id="reset-btn"
class="w-full flex items-center justify-center gap-2 border-2 border-dashed border-[#000000]/20 bg-transparent hover:bg-gray-50 text-[#000000]/70 font-medium py-3 rounded-lg transition-all active:scale-95"
>
<i data-lucide="rotate-ccw" class="h-4 w-4"></i>
Reset Counter
</button>
</div>
</div>
<div
class="lg:col-span-2 rounded-xl border border-[#000000]/10 bg-white shadow-sm flex flex-col"
>
<div class="p-6 border-b border-gray-50">
<h3 class="font-semibold leading-none tracking-tight">
Daily Traffic Overview
</h3>
<p class="text-xs text-[#000000]/60 mt-1">
Object counts recorded over the last 7 days.
</p>
</div>
<div class="flex-1 p-6 flex items-center">
<canvas id="trafficChart" class="w-full h-[200px]"></canvas>
</div>
</div>
<div
class="rounded-xl border border-[#000000]/10 bg-white shadow-sm p-5"
>
<h3
class="text-xs font-medium text-[#000000]/40 uppercase tracking-wider"
>
Log Status
</h3>
<div class="flex items-center gap-2 mt-2">
<div
class="h-2 w-2 rounded-full bg-green-500 shadow-[0_0_8px_rgba(34,197,94,0.6)]"
></div>
<span class="text-2xl font-bold">Connected</span>
</div>
<p class="text-[11px] text-[#000000]/40 mt-1">
Google Sheets Sync Active
</p>
</div>
<div
class="rounded-xl border border-[#000000]/10 bg-white shadow-sm p-5"
>
<h3
class="text-xs font-medium text-[#000000]/40 uppercase tracking-wider"
>
Peak Hour
</h3>
<div class="flex items-center gap-2 mt-2">
<i data-lucide="trending-up" class="h-5 w-5"></i>
<span class="text-2xl font-bold">14:00 - 15:00</span>
</div>
<p class="text-[11px] text-[#000000]/40 mt-1">
Average 12 objects/hr
</p>
</div>
<div
class="rounded-xl border border-[#000000]/10 bg-white shadow-sm p-5"
>
<h3
class="text-xs font-medium text-[#000000]/40 uppercase tracking-wider"
>
ESP32 Feedback
</h3>
<div class="flex items-center gap-2 mt-2">
<i data-lucide="activity" class="h-5 w-5"></i>
<span class="text-2xl font-bold">Blink Mode</span>
</div>
<p class="text-[11px] text-[#000000]/40 mt-1">
LED flashes on every count
</p>
</div>
</div>
</div>
<script>
let count = 0;
const dailyData = [45, 52, 38, 65, 48, 24, 18];
const days = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
const counterVal = document.getElementById("counter-value");
const glow = document.getElementById("glow");
const irBadge = document.getElementById("ir-badge");
const irStatus = document.getElementById("ir-status");
const zapIcon = document.getElementById("zap-icon");
const resetBtn = document.getElementById("reset-btn");
// Chart Setup
const ctx = document.getElementById("trafficChart").getContext("2d");
const trafficChart = new Chart(ctx, {
type: "bar",
data: {
labels: days,
datasets: [
{
label: "Objects",
data: dailyData,
backgroundColor: "#000000",
borderRadius: 6,
barThickness: 40,
},
],
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: { legend: { display: false } },
scales: {
y: {
beginAtZero: true,
grid: { display: false },
ticks: { color: "#000000" },
},
x: { grid: { display: false }, ticks: { color: "#000000" } },
},
},
});
// UI Feedback Logic
function triggerDetectionUI() {
irBadge.className =
"inline-flex items-center gap-2 px-3 py-1 rounded-full bg-yellow-500 text-[#000000] text-xs font-bold transition-all duration-300 scale-105";
irStatus.innerText = "DETECTED";
zapIcon.classList.add("animate-bounce");
counterVal.innerText = count;
counterVal.classList.add("passing-active");
glow.classList.add("glow-active");
setTimeout(() => {
irBadge.className =
"inline-flex items-center gap-2 px-3 py-1 rounded-full bg-slate-200 text-xs font-medium transition-all duration-300";
irStatus.innerText = "IDLE";
zapIcon.classList.remove("animate-bounce");
counterVal.classList.remove("passing-active");
glow.classList.remove("glow-active");
}, 800);
}
// Web Serial Logic
let port;
let reader;
let serialBuffer = ""; // Global buffer to hold incoming fragments
async function connectSerial() {
try {
port = await navigator.serial.requestPort();
await port.open({ baudRate: 115200 });
document.querySelector("h1").innerText += " - ONLINE";
document.querySelector("h1").style.color = "green";
const decoder = new TextDecoderStream();
port.readable.pipeTo(decoder.writable);
const inputStream = decoder.readable;
reader = inputStream.getReader();
while (true) {
const { value, done } = await reader.read();
if (done) break;
if (value) {
serialBuffer += value; // Add fragment to buffer
// Check if we have a complete line (ending in newline)
if (serialBuffer.includes("\n")) {
const lines = serialBuffer.split("\n");
// Process all complete lines except the last fragment
for (let i = 0; i < lines.length - 1; i++) {
handleIncomingData(lines[i].trim());
}
// Keep the last incomplete fragment in the buffer
serialBuffer = lines[lines.length - 1];
}
}
}
} catch (error) {
console.error("Serial Connection Failed", error);
}
}
function handleIncomingData(line) {
console.log("Processing Line:", line); // Debugging
if (line.startsWith("COUNT:")) {
const val = parseInt(line.split(":")[1]);
if (!isNaN(val)) {
count = val;
triggerDetectionUI();
}
}
}
// EVENT LISTENERS
// 1. Use the Settings icon (top right) to trigger the connection
document.querySelector(
'[data-lucide="settings-2"]'
).parentElement.onclick = connectSerial;
// 2. Reset Button
resetBtn.addEventListener("click", async () => {
count = 0;
counterVal.innerText = count;
// Optional: Send reset command to ESP32
if (port && port.writable) {
const writer = port.writable.getWriter();
await writer.write(new TextEncoder().encode("RESET\n"));
writer.releaseLock();
}
});
lucide.createIcons();
</script>
</body>
</html>