Skip to content

Commit 81f770b

Browse files
author
Ritika Mishra
committed
updated values string to integer in board list
1 parent c927517 commit 81f770b

File tree

4 files changed

+72
-74
lines changed

4 files changed

+72
-74
lines changed

src/components/Canvas.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import { WebglPlot, ColorRGBA, WebglLine } from "webgl-plot";
1212

1313
interface CanvasProps {
1414
pauseRef: React.RefObject<boolean>;
15-
selectedBits: BitSelection;
15+
selectedBits?: BitSelection; // Add `?` to make it optional
1616
isDisplay: boolean;
1717
canvasCount?: number;
1818
timeBase?: number;
19-
currentSamplingRate:number;
19+
currentSamplingRate: number;
2020
Zoom: number;
2121
currentSnapshot: number;
2222
snapShotRef: React.MutableRefObject<boolean[]>;
@@ -60,17 +60,17 @@ const Canvas = forwardRef(
6060
//select point
6161
const getpoints = useCallback((bits: BitSelection): number => {
6262
switch (bits) {
63-
case "ten":
63+
case 10:
6464
return 250;
65-
case "twelve":
66-
case "fourteen":
67-
case "sixteen":
65+
case 12:
66+
case 14:
67+
case 16:
6868
return 500;
6969
default:
7070
return 500; // Default fallback
7171
}
7272
}, []);
73-
73+
7474

7575
useEffect(() => {
7676
numXRef.current = (currentSamplingRate * timeBase);
@@ -188,7 +188,7 @@ const Canvas = forwardRef(
188188
const opacityLightMajor = "0.4"; // Opacity for every 5th line in light theme
189189
const opacityLightMinor = "0.1"; // Opacity for other lines in light theme
190190
const distanceminor = samplingRate * 0.04;
191-
const numGridLines = getpoints(selectedBits) * 4 / distanceminor;
191+
const numGridLines = getpoints(selectedBits ?? 10) * 4 / distanceminor;
192192
for (let j = 1; j < numGridLines; j++) {
193193
const gridLineX = document.createElement("div");
194194
gridLineX.className = "absolute bg-[rgb(128,128,128)]";

src/components/Connection.tsx

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ interface ConnectionProps {
4848
onPauseChange: (pause: boolean) => void; // Callback to pass pause state to parent
4949
datastream: (data: number[]) => void;
5050
Connection: (isConnected: boolean) => void;
51-
selectedBits: BitSelection;
51+
selectedBits?: BitSelection; // Add `?` if it's optional
5252
setSelectedBits: React.Dispatch<React.SetStateAction<BitSelection>>;
5353
isDisplay: boolean;
5454
setIsDisplay: React.Dispatch<React.SetStateAction<boolean>>;
@@ -90,7 +90,7 @@ const Connection: React.FC<ConnectionProps> = ({
9090
const isRecordingRef = useRef<boolean>(false); // Ref to track if the device is recording
9191
const [isEndTimePopoverOpen, setIsEndTimePopoverOpen] = useState(false);
9292
const [detectedBits, setDetectedBits] = useState<BitSelection | null>(null); // State to store the detected bits
93-
const detectedBitsRef = React.useRef<BitSelection>("ten");
93+
const detectedBitsRef = React.useRef<BitSelection>(10);
9494
const [datasets, setDatasets] = useState<any[]>([]);
9595
const currentFilenameRef = useRef<string>("");
9696
const [isRecordButtonDisabled, setIsRecordButtonDisabled] = useState(false);
@@ -101,7 +101,7 @@ const Connection: React.FC<ConnectionProps> = ({
101101
const endTimeRef = useRef<number | null>(null); // Ref to store the end time of the recording
102102
const [popoverVisible, setPopoverVisible] = useState(false);
103103
const portRef = useRef<SerialPort | null>(null); // Ref to store the serial port
104-
const [ifBits, setifBits] = useState<BitSelection>("auto");
104+
const [ifBits, setifBits] = useState<BitSelection>(10);
105105
const [showAllChannels, setShowAllChannels] = useState(false);
106106
const [FullZoom, setFullZoom] = useState(false);
107107
const canvasnumbersRef = useRef<number>(1);
@@ -350,19 +350,18 @@ const Connection: React.FC<ConnectionProps> = ({
350350
const board = BoardsList.find(
351351
(b) =>
352352
b.chords_id.toLowerCase() === deviceName.toLowerCase() &&
353-
(!fieldPid || parseInt(b.field_pid, 10) === fieldPid) // Match field_pid if provided
353+
(!fieldPid || (b.field_pid) === fieldPid) // Match field_pid if provided
354354
);
355355

356356
if (board) {
357357
setifBits(board.adc_resolution as BitSelection);
358358
setSelectedBits(board.adc_resolution as BitSelection);
359359
detectedBitsRef.current = board.adc_resolution as BitSelection;
360360

361-
const channel = board.channel_count ? parseInt(board.channel_count, 10) : 0;
361+
const channel = board.channel_count ? (board.channel_count) : 0;
362362
maxCanvasCountRef.current = channel;
363-
364363
if (board.sampling_rate) {
365-
setCurrentSamplingRate(parseInt(board.sampling_rate, 10));
364+
setCurrentSamplingRate(board.sampling_rate);
366365
}
367366

368367
return {
@@ -373,8 +372,8 @@ const Connection: React.FC<ConnectionProps> = ({
373372
),
374373
adcResolution: board.adc_resolution,
375374
channelCount: board.channel_count,
376-
baudRate: parseInt(board.baud_Rate, 10), // Return baudRate
377-
serialTimeout: parseInt(board.serial_timeout, 10), // Return serialTimeout
375+
baudRate: (board.baud_Rate), // Return baudRate
376+
serialTimeout: (board.serial_timeout), // Return serialTimeout
378377
};
379378
}
380379

@@ -405,6 +404,7 @@ const Connection: React.FC<ConnectionProps> = ({
405404
await disconnectDevice();
406405
}
407406

407+
408408
const savedPorts = JSON.parse(localStorage.getItem('savedDevices') || '[]');
409409
let port = null;
410410

@@ -422,8 +422,6 @@ const Connection: React.FC<ConnectionProps> = ({
422422
);
423423
}) || null;
424424
}
425-
// Request a new port if no saved port matches
426-
// port = await navigator.serial.requestPort();
427425

428426
let baudRate;
429427
let serialTimeout
@@ -437,11 +435,11 @@ const Connection: React.FC<ConnectionProps> = ({
437435

438436
// Match the board from BoardsList
439437
const board = BoardsList.find(
440-
(b) => parseInt(b.field_pid, 10) === usbProductId
438+
(b) => (b.field_pid) === usbProductId
441439
);
442440

443-
baudRate = board ? parseInt(board.baud_Rate, 10) : 0;
444-
serialTimeout = board ? parseInt(board.serial_timeout, 10) : 0;
441+
baudRate = board ? (board.baud_Rate) : 0;
442+
serialTimeout = board ? (board.serial_timeout) : 0;
445443

446444
const usbVendorId = newPortInfo.usbVendorId ?? 0;
447445
// const usbProductId = newPortInfo.usbProductId ?? 0;
@@ -706,10 +704,10 @@ const Connection: React.FC<ConnectionProps> = ({
706704
const notchFilters = Array.from({ length: maxCanvasCountRef.current }, () => new Notch());
707705
const EXGFilters = Array.from({ length: maxCanvasCountRef.current }, () => new EXGFilter());
708706
notchFilters.forEach((filter) => {
709-
filter.setbits(detectedBitsRef.current); // Set the bits value for all instances
707+
filter.setbits(detectedBitsRef.current.toString()); // Set the bits value for all instances
710708
});
711709
EXGFilters.forEach((filter) => {
712-
filter.setbits(detectedBitsRef.current); // Set the bits value for all instances
710+
filter.setbits(detectedBitsRef.current.toString()); // Set the bits value for all instances
713711
});
714712
try {
715713
while (isConnectedRef.current) {

src/components/DataPass.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import React, { useState, useCallback, useRef } from "react";
66
import Canvas from "./Canvas";
77
import Navbar from "./Navbar"; // Import the Navbar
88

9-
export type BitSelection = "ten" | "twelve" | "fourteen" | "sixteen" | "auto";
9+
export type BitSelection = 10 | 12 | 14 | 16;
1010

1111
const DataPass = () => {
12-
const [selectedBits, setSelectedBits] = useState<BitSelection>("auto"); // Selected bits
12+
const [selectedBits, setSelectedBits] = useState<BitSelection>(10); // Default to 10
1313
const [isConnected, setIsConnected] = useState<boolean>(false); // Connection status
1414
const [isDisplay, setIsDisplay] = useState<boolean>(true); // Display state
1515
const [canvasCount, setCanvasCount] = useState<number>(1); // Number of canvases

src/components/boards.ts

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,81 +2,81 @@ export const BoardsList = Object.freeze([
22
{
33
chords_id: "UNO-R3",
44
device_name: "Arduino UNO R3",
5-
field_pid: "67",
6-
adc_resolution: "10",
7-
channel_count: "6",
8-
sampling_rate: "250",
9-
serial_timeout: "2000",
10-
baud_Rate: "230400"
5+
field_pid: 67,
6+
adc_resolution: 10,
7+
channel_count: 6,
8+
sampling_rate: 250,
9+
serial_timeout: 2000,
10+
baud_Rate: 230400
1111
},
1212
{
1313
chords_id: "NANO-CLONE",
1414
device_name: "Arduino Nano Clone",
15-
field_pid: "29987",
16-
adc_resolution: "10",
17-
channel_count: "8",
18-
sampling_rate: "250",
19-
serial_timeout: "2000",
20-
baud_Rate: "115200"
15+
field_pid: 29987,
16+
adc_resolution: 10,
17+
channel_count: 8,
18+
sampling_rate: 250,
19+
serial_timeout: 2000,
20+
baud_Rate: 115200
2121
},
2222
{
2323
chords_id: "GENUINO-UNO",
2424
device_name: "Genuino UNO",
25-
field_pid: "579",
26-
adc_resolution: "10",
27-
channel_count: "6",
28-
sampling_rate: "250",
29-
serial_timeout: "2000",
30-
baud_Rate: "230400"
25+
field_pid: 579,
26+
adc_resolution: 10,
27+
channel_count: 6,
28+
sampling_rate: 250,
29+
serial_timeout: 2000,
30+
baud_Rate: 230400
3131
},
3232
{
3333
chords_id: "UNO-R4",
3434
device_name: "Arduino UNO R4 Minima",
35-
field_pid: "105",
36-
adc_resolution: "14",
37-
channel_count: "6",
38-
sampling_rate: "500",
39-
serial_timeout: "100",
40-
baud_Rate: "230400"
35+
field_pid: 105,
36+
adc_resolution: 14,
37+
channel_count: 6,
38+
sampling_rate: 500,
39+
serial_timeout: 100,
40+
baud_Rate: 230400
4141
},
4242
{
4343
chords_id: "UNO-R4",
4444
device_name: "Arduino UNO R4 Wifi",
45-
field_pid: "4098",
46-
adc_resolution: "14",
47-
channel_count: "6",
48-
sampling_rate: "500",
49-
serial_timeout: "100",
50-
baud_Rate: "230400"
45+
field_pid: 4098,
46+
adc_resolution: 14,
47+
channel_count: 6,
48+
sampling_rate: 500,
49+
serial_timeout: 100,
50+
baud_Rate: 230400
5151
},
5252
{
5353
chords_id: "UNO-CLONE",
5454
device_name: "Maker UNO / UNO Clone",
55-
field_pid: "29987",
56-
adc_resolution: "10",
57-
channel_count: "6",
58-
sampling_rate: "250",
59-
serial_timeout: "2000",
60-
baud_Rate: "115200"
55+
field_pid: 29987,
56+
adc_resolution: 10,
57+
channel_count: 6,
58+
sampling_rate: 250,
59+
serial_timeout: 2000,
60+
baud_Rate: 115200
6161
},
6262
{
6363
chords_id: "RPI-PICO-RP2040",
6464
device_name: "Raspberry Pi Pico",
65-
field_pid: "192",
66-
adc_resolution: "12",
67-
channel_count: "3",
68-
sampling_rate: "500",
69-
serial_timeout: "100",
70-
baud_Rate: "230400"
65+
field_pid: 192,
66+
adc_resolution: 12,
67+
channel_count: 3,
68+
sampling_rate: 500,
69+
serial_timeout: 100,
70+
baud_Rate: 230400
7171
},
7272
{
7373
chords_id: "GIGA-R1",
7474
device_name: "Arduino GIGA R1",
75-
field_pid: "614",
76-
adc_resolution: "16",
77-
channel_count: "6",
78-
sampling_rate: "500",
79-
serial_timeout: "100",
80-
baud_Rate: "230400"
75+
field_pid: 614,
76+
adc_resolution: 16,
77+
channel_count: 6,
78+
sampling_rate: 500,
79+
serial_timeout: 100,
80+
baud_Rate: 230400
8181
},
8282
]);

0 commit comments

Comments
 (0)