@@ -4,6 +4,7 @@ import Link from 'next/link'
44import Layout from '../components/layout'
55import { channelNames , EEGReading , MuseClient } from 'muse-js' ;
66import io from 'socket.io-client' ;
7+ import * as Papa from 'papaparse' ;
78
89const socket = io ( 'http://localhost:5000' ) ;
910const museClient = new MuseClient ( ) ;
@@ -12,6 +13,8 @@ function Visualizations() {
1213 const [ testEEGData , setTestEEGData ] = useState ( "" ) ;
1314 const [ blink_state , setBlinkState ] = useState ( "" ) ;
1415
16+ var fileList
17+
1518 async function startMuseConnection ( e ) {
1619 await museClient . connect ( )
1720 await museClient . start ( )
@@ -27,7 +30,21 @@ function Visualizations() {
2730 } ) ;
2831 }
2932
30-
33+ async function streamCSVData ( e ) {
34+ Papa . parse ( fileList [ 0 ] , {
35+ complete : function ( results ) {
36+ var rows = results . data
37+ var i = 0
38+ var interval = setInterval ( function ( ) {
39+ socket . emit ( 'eeg-stream' , rows [ i ] ) ;
40+ i ++ ;
41+ if ( i >= rows . length ) {
42+ clearInterval ( interval )
43+ }
44+ } , 3.90625 )
45+ }
46+ } ) ;
47+ }
3148
3249 useEffect ( ( ) => {
3350 socket . on ( 'connect' , ( msg ) => {
@@ -40,6 +57,13 @@ function Visualizations() {
4057 console . log ( "Blink State: " + msg )
4158 setBlinkState ( msg )
4259 } ) ;
60+
61+ const fileSelector = document . getElementById ( 'file-selector' ) ;
62+
63+ fileSelector . addEventListener ( 'change' , ( event ) => {
64+ fileList = event . target . files ;
65+ console . log ( fileList ) ;
66+ } ) ;
4367 } , [ ] ) ;
4468
4569
@@ -62,6 +86,14 @@ function Visualizations() {
6286 < br > </ br >
6387 < br > </ br >
6488
89+ < input type = "file" id = "file-selector" > </ input >
90+ < button onClick = { streamCSVData } >
91+ TEST!
92+ </ button >
93+
94+ < br > </ br >
95+ < br > </ br >
96+
6597 < form onSubmit = { sendTestEEGData } >
6698 < label >
6799 Send Test Message to Flask: < tab > </ tab >
@@ -74,4 +106,4 @@ function Visualizations() {
74106 ) ;
75107}
76108
77- export default Visualizations ;
109+ export default Visualizations ;
0 commit comments