Skip to content

Commit f3e8928

Browse files
committed
Update FFT
1 parent 8174539 commit f3e8928

File tree

4 files changed

+18
-20
lines changed

4 files changed

+18
-20
lines changed

src/app/muscle-strength/page.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const MuscleStrength = () => {
4848
const currentSweepPos = useRef<number[]>(new Array(6).fill(0)); // Array for sweep positions
4949
const maxCanvasElementCountRef = useRef<number>(3);
5050
const channelNames = Array.from({ length: maxCanvasElementCountRef.current }, (_, i) => `CH${i + 1}`);
51-
let numChannels = 3;
51+
const numChannels = 3;
5252
const [selectedChannels, setSelectedChannels] = useState<number[]>([0, 1, 2]);
5353
const { theme } = useTheme(); // Current theme of the app
5454
const [isConnected, setIsConnected] = useState(false);
@@ -148,9 +148,8 @@ const MuscleStrength = () => {
148148
canvasWrapper.appendChild(badge);
149149
canvasWrapper.appendChild(canvas);
150150
container.appendChild(canvasWrapper);
151-
152-
const wglp = new WebglPlot(canvas);
153151
if (!canvas) return;
152+
const wglp = new WebglPlot(canvas);
154153

155154
// Ensure linesRefs.current[index] is initialized as an array
156155
if (!linesRefs.current[index]) {
@@ -201,7 +200,6 @@ const MuscleStrength = () => {
201200
ro.observe(containerRef.current);
202201
return () => ro.disconnect();
203202
}, [
204-
numChannels,
205203
theme,
206204
timeBase,
207205
selectedChannels,
@@ -914,8 +912,6 @@ const MuscleStrength = () => {
914912
<TooltipProvider>
915913
<Tooltip>
916914
<TooltipTrigger asChild>
917-
<Popover open={open} onOpenChange={setOpen}>
918-
<PopoverTrigger asChild>
919915
<Button
920916
className="flex items-center gap-1 py-2 px-4 rounded-xl font-semibold"
921917
onClick={() => (isConnected ? disconnect() : connectBLE())}
@@ -937,9 +933,6 @@ const MuscleStrength = () => {
937933
</>
938934
)}
939935
</Button>
940-
</PopoverTrigger>
941-
942-
</Popover>
943936
</TooltipTrigger>
944937
<TooltipContent>
945938
<p>{isConnected ? "Disconnect Device" : "Connect Device"}</p>

src/components/BandPowerGraph.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const Graph: React.FC<GraphProps> = ({
5252
THETA_RANGE = [4, 8],
5353
ALPHA_RANGE = [8, 12],
5454
BETA_RANGE = [12, 30],
55-
GAMMA_RANGE = [30, 100];
55+
GAMMA_RANGE = [30, 45];
5656

5757
const FREQ_RESOLUTION = samplingRate / 256;
5858

src/components/Connection.tsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ const Connection: React.FC<ConnectionProps> = ({
9999

100100
// States and Refs for Connection & Recording
101101
const [isDeviceConnected, setIsDeviceConnected] = useState<boolean>(false); // Track if the device is connected
102-
const [isserial, setIsserial] = useState<boolean>(false); // Track if the device is connected
102+
const [isserial, setIsserial] = useState(false); // Track if the device is connected
103103

104104
const [FFTDeviceConnected, setFFTDeviceConnected] = useState<boolean>(false); // Track if the device is connected
105105
const isDeviceConnectedRef = useRef<boolean>(false); // Ref to track if the device is connected
@@ -128,7 +128,7 @@ const Connection: React.FC<ConnectionProps> = ({
128128
const sampingrateref = useRef<number>(0);
129129
const [open, setOpen] = useState(false);
130130
const [openfft, setOpenfft] = useState(false);
131-
const [isPauseSate, setIsPauseState] = useState(false);
131+
const [isPauseState, setIsPauseState] = useState(false);
132132

133133
// UI Themes & Modes
134134
const { theme } = useTheme(); // Current theme of the app
@@ -379,8 +379,13 @@ const Connection: React.FC<ConnectionProps> = ({
379379
});
380380

381381
};
382-
setSelectedChannelsInWorker(selectedChannels)
383-
382+
if (FFTDeviceConnected) {
383+
// If FFT device is connected, send only the selected channel
384+
setSelectedChannelsInWorker([selectedChannel]);
385+
} else {
386+
// Otherwise, send all selected channels
387+
setSelectedChannelsInWorker(selectedChannels);
388+
}
384389
const processBuffer = async (bufferIndex: number, canvasCount: number, selectChannel: number[]) => {
385390
if (!workerRef.current) {
386391
initializeWorker();
@@ -1001,7 +1006,7 @@ const Connection: React.FC<ConnectionProps> = ({
10011006
let prevSampleCounter: number | null = null;
10021007
const samplesReceivedRef = useRef(0);
10031008
let channelData: number[] = [];
1004-
const SINGLE_SAMPLE_LEN = 7; // Each sample is 10 bytes
1009+
const SINGLE_SAMPLE_LEN = 7; // Each sample is 7 bytes: 1 counter + 3 × 2-byte channels
10051010
const BLOCK_COUNT = 10; // 10 samples batched per notification
10061011
const NEW_PACKET_LEN = SINGLE_SAMPLE_LEN * BLOCK_COUNT; // 100 bytes
10071012
interface BluetoothRemoteGATTCharacteristicExtended extends EventTarget {
@@ -1572,7 +1577,7 @@ const Connection: React.FC<ConnectionProps> = ({
15721577
<PopoverTrigger asChild>
15731578
<Button
15741579
className="flex items-center gap-1 py-2 px-4 rounded-xl font-semibold"
1575-
disabled={isfftLoading || isPauseSate}
1580+
disabled={isfftLoading || isPauseState}
15761581
>
15771582
{isfftLoading ? (
15781583
<>
@@ -1685,7 +1690,7 @@ const Connection: React.FC<ConnectionProps> = ({
16851690
<Button
16861691
className="rounded-xl"
16871692
onClick={handleRecord}
1688-
disabled={isPauseSate}
1693+
disabled={isPauseState}
16891694
>
16901695
{isRecordingRef.current ? (
16911696
<CircleStop />
@@ -1782,7 +1787,7 @@ const Connection: React.FC<ConnectionProps> = ({
17821787
<PopoverTrigger asChild>
17831788
<Button
17841789
className="flex items-center justify-center px-3 py-2 select-none min-w-12 whitespace-nowrap rounded-xl"
1785-
disabled={isPauseSate}
1790+
disabled={isPauseState}
17861791
>
17871792
Filter
17881793
</Button>
@@ -2183,7 +2188,7 @@ const Connection: React.FC<ConnectionProps> = ({
21832188
<PopoverTrigger asChild>
21842189
<Button
21852190
className="flex items-center gap-1 py-2 px-4 rounded-xl font-semibold"
2186-
disabled={isfftLoading || isPauseSate}
2191+
disabled={isfftLoading || isPauseState}
21872192
>
21882193
Channels
21892194
</Button>

src/components/FFT.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const FFT = forwardRef(
5252
[]
5353
);
5454
const canvasContainerRef = useRef<HTMLDivElement>(null);
55-
const dataPointCountRef = useRef<number>(1000);
55+
const dataPointCountRef = useRef<number>(2000);
5656
const wglPlotsref = useRef<WebglPlot[]>([]);
5757
const linesRef = useRef<WebglLine[]>([]);
5858
const sweepPositions = useRef<number[]>(new Array(6).fill(0));

0 commit comments

Comments
 (0)