33import { useEffect , useState , useRef , useCallback } from "react" ;
44import { WebglPlot , WebglLine , ColorRGBA } from "webgl-plot" ;
55import { Button } from "@/components/ui/button" ;
6- import { Checkbox } from "@/components/ui/checkbox" ;
76import Navbar from "@/components/Navbar" ;
87
98interface DataPoint {
@@ -308,15 +307,13 @@ const SerialPlotter = () => {
308307 return (
309308 < div className = "w-full h-screen mx-auto border rounded-2xl shadow-xl flex flex-col gap- overflow-hidden px-4" >
310309 < Navbar isDisplay = { true } />
311- < h1 className = "text-2xl font-bold text-center" > Chords Serial Plotter & Monitor </ h1 >
312310
313311 < div className = "w-full flex flex-col gap-2 flex-grow overflow-hidden" >
314312
315313 { /* Plotter - Adjusts Height Dynamically */ }
316314 { viewMode !== "monitor" && (
317315 < div className = "w-full flex flex-col flex-grow min-h-[40vh]" >
318316 < div className = "border rounded-xl shadow-lg bg-[#1a1a2e] p-2 w-full h-full flex flex-col" >
319- < h2 className = "text-sm font-semibold text-center mb-1 text-white" > Plotter</ h2 >
320317 { /* Canvas Container */ }
321318 < div className = "canvas-container w-full h-full flex items-center justify-center overflow-hidden" >
322319 < canvas ref = { canvasRef } className = "w-full h-full rounded-xl" />
@@ -326,65 +323,37 @@ const SerialPlotter = () => {
326323 ) }
327324 { /* Monitor - Adjusts Height Dynamically */ }
328325 { viewMode !== "plotter" && (
329- < div ref = { rawDataRef } className = { `w-full border rounded-xl shadow-lg bg-[#1a1a2e] text-white overflow-auto flex flex-col flex-grow ${ viewMode === "both" ? "min-h-[55vh]" : "min-h-[50vh]" } ` } >
330- { /* Sticky Top Controls */ }
331- { /* Title */ }
332- < h2 className = "text-sm font-semibold text-center mb-2" >
333- { boardName ? `Connected to: ${ boardName } ` : "Raw Data Output" }
334- </ h2 >
335- < div className = "sticky top-0 right-0 flex items-center justify-end space-x-2 bg-[#1a1a2e] p-2 z-10" >
336- < div className = "flex items-center space-x-1 p-1" >
337- < input
338- type = "text"
339- value = { command }
340- onChange = { ( e ) => setCommand ( e . target . value ) }
341- placeholder = "Enter command (WHORU, START)"
342- className = "w-full p-1 rounded bg-gray-800 text-white border border-gray-600 text-xs"
343- />
344- < Button onClick = { sendCommand } className = "px-2 py-1 text-xs font-semibold" > Send</ Button >
345- </ div >
346- { /* Bits Selector */ }
347- < div className = "flex items-center space-x-2" >
348- < label className = "text-xs font-semibold" > Bits</ label >
349- < select
350- value = { bitsref . current }
351- onChange = { ( e ) => ( bitsref . current = Number ( e . target . value ) ) }
352- className = "p-1 border rounded bg-gray-800 text-white text-xs"
353- >
354- { [ 10 , 12 , 14 , 16 ] . map ( ( Bits ) => (
355- < option key = { Bits } value = { Bits } > { Bits } </ option >
356- ) ) }
357- </ select >
358- </ div >
359- { /* Baud Rate Selector */ }
360- < div className = "flex items-center space-x-2" >
361- < label className = "text-xs font-semibold" > Baud Rate:</ label >
362- < select
363- value = { baudRateref . current }
364- onChange = { ( e ) => handleBaudRateChange ( Number ( e . target . value ) ) }
365- className = "p-1 border rounded bg-gray-800 text-white text-xs"
366- >
367- { [ 9600 , 19200 , 38400 , 57600 , 115200 , 230400 , 460800 , 921600 ] . map ( ( rate ) => (
368- < option key = { rate } value = { rate } > { rate } </ option >
369- ) ) }
370- </ select >
371- </ div >
372- { /* Clear Data Button */ }
373- < button
374- onClick = { ( ) => setRawData ( "" ) }
375- className = "px-2 py-1 text-xs bg-red-600 text-white rounded shadow-md hover:bg-red-700 transition"
376- >
377- Clear
378- </ button >
379- </ div >
380-
326+ < div ref = { rawDataRef } className = { `w-full border rounded-xl shadow-lg bg-[#1a1a2e] text-white overflow-auto flex flex-col flex-grow ${ viewMode === "both" ? "min-h-[55vh]" : "min-h-[50vh]" } ` } >
327+ { /* Title Bar with Input and Buttons */ }
328+ < div className = "sticky top-0 flex items-center justify-between bg-[#1a1a2e] p-2 z-10" >
329+ { /* Input Box (Top Left) */ }
330+ < input
331+ type = "text"
332+ value = { command }
333+ onChange = { ( e ) => setCommand ( e . target . value ) }
334+ placeholder = "Enter command (WHORU, START)"
335+ className = "w-1/3 p-1 rounded bg-gray-800 text-white border border-gray-600 text-xs"
336+ />
337+
338+ { /* Buttons (Top Right) */ }
339+ < div className = "flex items-center space-x-2" >
340+ < Button onClick = { sendCommand } className = "px-2 py-1 text-xs font-semibold" > Send</ Button >
341+ < button
342+ onClick = { ( ) => setRawData ( "" ) }
343+ className = "px-2 py-1 text-xs bg-red-600 text-white rounded shadow-md hover:bg-red-700 transition"
344+ >
345+ Clear
346+ </ button >
347+ </ div >
348+ </ div >
381349
382- < pre className = "text-xs whitespace-pre-wrap break-words px-4 pb-4 flex-grow overflow-auto" >
383- { rawData }
384- </ pre >
350+ { /* Data Display */ }
351+ < pre className = "text-xs whitespace-pre-wrap break-words px-4 pb-4 flex-grow overflow-auto" >
352+ { rawData }
353+ </ pre >
354+ </ div >
355+ ) }
385356
386- </ div >
387- ) }
388357 </ div >
389358 { /* Footer Section */ }
390359 < footer className = "flex flex-col gap-2 sm:flex-row py-2 m-2 w-full shrink-0 items-center justify-center px-2 md:px-4 border-t" >
@@ -410,6 +379,32 @@ const SerialPlotter = () => {
410379 Disconnect
411380 </ Button >
412381 </ div >
382+ { /* Bits Selector */ }
383+ < div className = "flex items-center space-x-2" >
384+ < label className = "text-xs font-semibold" > Bits</ label >
385+ < select
386+ value = { bitsref . current }
387+ onChange = { ( e ) => ( bitsref . current = Number ( e . target . value ) ) }
388+ className = "p-1 border rounded bg-gray-800 text-white text-xs"
389+ >
390+ { [ 10 , 12 , 14 , 16 ] . map ( ( Bits ) => (
391+ < option key = { Bits } value = { Bits } > { Bits } </ option >
392+ ) ) }
393+ </ select >
394+ </ div >
395+ { /* Baud Rate Selector */ }
396+ < div className = "flex items-center space-x-2" >
397+ < label className = "text-xs font-semibold" > Baud Rate:</ label >
398+ < select
399+ value = { baudRateref . current }
400+ onChange = { ( e ) => handleBaudRateChange ( Number ( e . target . value ) ) }
401+ className = "p-1 border rounded bg-gray-800 text-white text-xs"
402+ >
403+ { [ 9600 , 19200 , 38400 , 57600 , 115200 , 230400 , 460800 , 921600 ] . map ( ( rate ) => (
404+ < option key = { rate } value = { rate } > { rate } </ option >
405+ ) ) }
406+ </ select >
407+ </ div >
413408 </ footer >
414409 </ div >
415410 ) ;
0 commit comments