@@ -7,6 +7,7 @@ import React, {
77 useCallback ,
88 useLayoutEffect ,
99} from "react" ;
10+ import { toast } from "sonner" ;
1011
1112import { WebglPlot , ColorRGBA , WebglLine } from "webgl-plot" ;
1213import Navbar from "@/components/Navbar" ;
@@ -749,22 +750,27 @@ const MuscleStrength = () => {
749750 const envelope3 = new EnvelopeFilter ( 64 ) ;
750751
751752 function handledata ( event : Event ) : void {
752- const target = event . target as BluetoothRemoteGATTCharacteristicExtended ;
753- if ( ! target . value ) {
754- console . log ( "Received event with no value." ) ;
755- return ;
756- }
757- const value = target . value ;
758- if ( value . byteLength === NEW_PACKET_LEN ) {
759- for ( let i = 0 ; i < NEW_PACKET_LEN ; i += SINGLE_SAMPLE_LEN ) {
760- const sampleBuffer = value . buffer . slice ( i , i + SINGLE_SAMPLE_LEN ) ;
761- const sampleDataView = new DataView ( sampleBuffer ) ;
762- processSample ( sampleDataView ) ;
753+ try {
754+ const target = event . target as BluetoothRemoteGATTCharacteristicExtended ;
755+ if ( ! target . value ) {
756+ console . log ( "Received event with no value." ) ;
757+ return ;
763758 }
764- } else if ( value . byteLength === SINGLE_SAMPLE_LEN ) {
765- processSample ( new DataView ( value . buffer ) ) ;
766- } else {
767- console . log ( "Unexpected packet length: " + value . byteLength ) ;
759+ const value = target . value ;
760+ if ( value . byteLength === NEW_PACKET_LEN ) {
761+ for ( let i = 0 ; i < NEW_PACKET_LEN ; i += SINGLE_SAMPLE_LEN ) {
762+ const sampleBuffer = value . buffer . slice ( i , i + SINGLE_SAMPLE_LEN ) ;
763+ const sampleDataView = new DataView ( sampleBuffer ) ;
764+ processSample ( sampleDataView ) ;
765+ }
766+ } else if ( value . byteLength === SINGLE_SAMPLE_LEN ) {
767+ processSample ( new DataView ( value . buffer ) ) ;
768+ } else {
769+ console . log ( "Unexpected packet length: " + value . byteLength ) ;
770+ }
771+ } catch ( error ) {
772+ console . error ( "Error processing BLE data:" , error ) ;
773+
768774 }
769775 }
770776
@@ -774,7 +780,8 @@ const MuscleStrength = () => {
774780 setIsLoading ( true ) ;
775781 const nav = navigator as any ;
776782 if ( ! nav . bluetooth ) {
777- console . log ( "Web Bluetooth API is not available in this browser." ) ;
783+ setIsLoading ( false ) ;
784+ toast ( "Web Bluetooth API is not available in your browser. Please use Chrome, Edge, or Opera." ) ;
778785 return ;
779786 }
780787
0 commit comments