Skip to content

Commit a5a2494

Browse files
authored
update flag only when last 10 sec is stable (#284)
1 parent 3f7fd9b commit a5a2494

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/explorepy/stream_processor.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ def __init__(self, debug=False):
6565
self._last_packet_rcv_time = 0
6666
self.is_bt_streaming = True
6767
self.debug = debug
68-
self.is_unstable = False
68+
self.unstablility_flag = False
69+
self.last_bt_unstable_time = 0
6970

7071
def subscribe(self, callback, topic):
7172
"""Subscribe a function to a topic
@@ -331,14 +332,25 @@ def send_timestamp(self):
331332

332333
def update_bt_stability_status(self, current_timestamp):
333334
if 'board_id' in self.device_info.keys():
335+
if self._last_packet_timestamp == 0:
336+
return
334337
# device is an explore plus device, check sample timestamps
335338
timestamp_diff = current_timestamp - self._last_packet_timestamp
339+
336340
# allowed time interval is two samples
337341
allowed_time_interval = np.round(2 * (1 / self.device_info['sampling_rate']), 3)
338-
self.is_unstable = timestamp_diff >= allowed_time_interval
342+
is_unstable = timestamp_diff >= allowed_time_interval
339343
else:
340344
# devices is an old device, check if last sample has an earlier timestamp
341-
self.is_unstable = current_timestamp < self._last_packet_timestamp
345+
is_unstable = current_timestamp < self._last_packet_timestamp
346+
347+
current_time = get_local_time()
348+
if is_unstable:
349+
self.unstablility_flag = True
350+
self.last_bt_unstable_time = current_time
351+
else:
352+
if current_time - self.last_bt_unstable_time > 10:
353+
self.unstablility_flag = False
342354

343355
def is_connection_unstable(self):
344-
return self.is_unstable
356+
return self.unstablility_flag

0 commit comments

Comments
 (0)