@@ -16,6 +16,8 @@ abstract class BoardBrainFlow extends Board {
1616 protected int [] otherChannelsCache = null ;
1717
1818 protected boolean streaming = false ;
19+ protected double time_last_datapoint = - 1.0 ;
20+ protected boolean data_popup_displayed = false ;
1921
2022 /* Abstract Functions.
2123 * Implement these in your board.
@@ -73,7 +75,7 @@ abstract class BoardBrainFlow extends Board {
7375 }
7476
7577 try {
76- boardShim. start_stream (450000 );
78+ boardShim. start_stream (450000 , brainflowStreamer );
7779 streaming = true ;
7880 }
7981 catch (BrainFlowError e) {
@@ -95,12 +97,17 @@ abstract class BoardBrainFlow extends Board {
9597 try {
9698 boardShim. stop_stream();
9799 streaming = false ;
100+ time_last_datapoint = - 1.0 ;
98101 }
99102 catch (BrainFlowError e) {
100103 println (" ERROR: Exception when stoppping stream" );
101104 e. printStackTrace();
102105 streaming = true ;
103106 }
107+
108+ if (eegDataSource != DATASOURCE_PLAYBACKFILE && eegDataSource != DATASOURCE_STREAMING ) {
109+ dataLogger. fileWriterBF. incrementBrainFlowStreamerFileNumber();
110+ }
104111 }
105112
106113 @Override
@@ -238,7 +245,25 @@ abstract class BoardBrainFlow extends Board {
238245 protected double [][] getNewDataInternal () {
239246 if (streaming) {
240247 try {
241- return boardShim. get_board_data();
248+ double [][] data = boardShim. get_board_data();
249+ if ((data[0 ]. length == 0 ) && (time_last_datapoint > 0 )) {
250+ double cur_time = System . currentTimeMillis() / 1000L ;
251+ double timeout = 5.0 ;
252+ if (cur_time - time_last_datapoint > timeout) {
253+ if (data_popup_displayed == false ) {
254+ PopupMessage msg = new PopupMessage (" Data Streaming Error" ,
255+ " No new data received in " + timeout + " seconds. Please check your device and restart a GUI session." );
256+ }
257+ outputError(" Data Streaming Error: No new data received in " + timeout + " seconds. Please check your device and restart a GUI session." );
258+ data_popup_displayed = true ;
259+ stopRunning();
260+ topNav. resetStartStopButton();
261+ }
262+ } else {
263+ time_last_datapoint = System . currentTimeMillis() / 1000L ;
264+ data_popup_displayed = false ;
265+ }
266+ return data;
242267 } catch (BrainFlowError e) {
243268 println (" WARNING: could not get board data." );
244269 e. printStackTrace();
0 commit comments