@@ -56,7 +56,7 @@ const NPG_Ble = () => {
5656 const [ recordingElapsedTime , setRecordingElapsedTime ] = useState < number > ( 0 ) ; // State to store the recording duration
5757 const [ customTimeInput , setCustomTimeInput ] = useState < string > ( "" ) ; // State to store the custom stop time input
5858 const existingRecordRef = useRef < any | undefined > ( undefined ) ;
59- const sampingrateref = useRef < number > ( 500 ) ;
59+ const samplingrateref = useRef < number > ( 500 ) ;
6060 const recordingStartTimeRef = useRef < number > ( 0 ) ;
6161 const endTimeRef = useRef < number | null > ( null ) ; // Ref to store the end time of the recording
6262 const canvasElementCountRef = useRef < number > ( 1 ) ;
@@ -105,6 +105,10 @@ const NPG_Ble = () => {
105105 return ; // Exit if the ref is null
106106 }
107107
108+ // Ensure dataPointCount is calculated from current sampling rate and timeBase
109+ const dpCount = samplingrateref . current * timeBase ;
110+ dataPointCountRef . current = dpCount ;
111+
108112 currentSweepPos . current = new Array ( numChannels ) . fill ( 0 ) ;
109113 sweepPositions . current = new Array ( numChannels ) . fill ( 0 ) ;
110114
@@ -137,7 +141,7 @@ const NPG_Ble = () => {
137141 const opacityDarkMinor = "0.05" ;
138142 const opacityLightMajor = "0.4" ;
139143 const opacityLightMinor = "0.1" ;
140- const distanceminor = sampingrateref . current * 0.04 ;
144+ const distanceminor = samplingrateref . current * 0.04 ;
141145 const numGridLines = ( 500 * 4 ) / distanceminor ;
142146
143147 for ( let j = 1 ; j < numGridLines ; j ++ ) {
@@ -188,10 +192,10 @@ const NPG_Ble = () => {
188192 wglp . gScaleY = Zoom ;
189193
190194
191- const line = new WebglLine ( getLineColor ( channelNumber , theme ) , dataPointCountRef . current ) ;
195+ const line = new WebglLine ( getLineColor ( channelNumber , theme ) , dpCount ) ;
192196 wglp . gOffsetY = 0 ;
193197 line . offsetY = 0 ;
194- line . lineSpaceX ( - 1 , 2 / dataPointCountRef . current ) ;
198+ line . lineSpaceX ( - 1 , 2 / dpCount ) ;
195199
196200 wglp . addLine ( line ) ;
197201 newLines . push ( line ) ;
@@ -314,7 +318,7 @@ const NPG_Ble = () => {
314318 forceUpdate ( ) ; // Trigger re-render
315319 } ;
316320 useEffect ( ( ) => {
317- dataPointCountRef . current = ( sampingrateref . current * timeBase ) ;
321+ dataPointCountRef . current = ( samplingrateref . current * timeBase ) ;
318322 } , [ timeBase ] ) ;
319323 const zoomRef = useRef ( Zoom ) ;
320324
@@ -338,13 +342,13 @@ const NPG_Ble = () => {
338342 const exgFiltersRef = useRef ( Array . from ( { length : maxCanvasElementCountRef . current } , ( ) => new EXGFilter ( ) ) ) ;
339343 const pointoneFilterRef = useRef ( Array . from ( { length : maxCanvasElementCountRef . current } , ( ) => new HighPassFilter ( ) ) ) ;
340344 notchFiltersRef . current . forEach ( ( filter ) => {
341- filter . setbits ( sampingrateref . current ) ;
345+ filter . setbits ( samplingrateref . current ) ;
342346 } ) ;
343347 exgFiltersRef . current . forEach ( ( filter ) => {
344- filter . setbits ( "12" , sampingrateref . current ) ;
348+ filter . setbits ( "12" , samplingrateref . current ) ;
345349 } ) ;
346350 pointoneFilterRef . current . forEach ( ( filter ) => {
347- filter . setSamplingRate ( sampingrateref . current ) ;
351+ filter . setSamplingRate ( samplingrateref . current ) ;
348352 } ) ;
349353
350354 // Inside your component
@@ -1510,6 +1514,7 @@ const NPG_Ble = () => {
15101514 < div className = "relative w-[28rem] flex items-center rounded-lg py-2 border border-gray-300 dark:border-gray-600" >
15111515 { /* Button for setting Time Base to 1 */ }
15121516 < button
1517+ type = "button"
15131518 className = "text-gray-700 dark:text-gray-400 mx-1 px-2 py-1 border rounded hover:bg-gray-200 dark:hover:bg-gray-700"
15141519 onClick = { ( ) => setTimeBase ( 1 ) }
15151520 >
@@ -1528,6 +1533,7 @@ const NPG_Ble = () => {
15281533 />
15291534 { /* Button for setting Time Base to 10 */ }
15301535 < button
1536+ type = "button"
15311537 className = "text-gray-700 dark:text-gray-400 mx-2 px-2 py-1 border rounded hover:bg-gray-200 dark:hover:bg-gray-700"
15321538 onClick = { ( ) => setTimeBase ( 10 ) }
15331539 >
0 commit comments