MCPcopy Create free account
hub / github.com/brainflow-dev/brainflow / release_session

Method release_session

src/board_controller/muse/muse.cpp:495–561  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

493}
494
495int Muse::release_session ()
496{
497 if (initialized)
498 {
499 // repeat it multiple times, failure here may lead to a crash
500 for (int i = 0; i < 2; i++)
501 {
502 stop_stream ();
503 // need to wait for notifications to stop triggered before unsubscribing, otherwise
504 // macos fails inside simpleble with timeout
505#ifdef _WIN32
506 Sleep (2000);
507#else
508 sleep (2);
509#endif
510 for (auto notified : notified_characteristics)
511 {
512 if (simpleble_peripheral_unsubscribe (
513 muse_peripheral, notified.first, notified.second) != SIMPLEBLE_SUCCESS)
514 {
515 safe_logger (spdlog::level::err, "failed to unsubscribe for {} {}",
516 notified.first.value, notified.second.value);
517 }
518 }
519 }
520 free_packages ();
521 initialized = false;
522 }
523 if (muse_peripheral != NULL)
524 {
525 bool is_connected = false;
526 if (simpleble_peripheral_is_connected (muse_peripheral, &is_connected) == SIMPLEBLE_SUCCESS)
527 {
528 if (is_connected)
529 {
530 simpleble_peripheral_disconnect (muse_peripheral);
531 }
532 }
533 simpleble_peripheral_release_handle (muse_peripheral);
534 muse_peripheral = NULL;
535 }
536 if (muse_adapter != NULL)
537 {
538 simpleble_adapter_release_handle (muse_adapter);
539 muse_adapter = NULL;
540 }
541
542 for (size_t i = 0; i < current_default_buf.size (); i++)
543 {
544 current_default_buf[i].clear ();
545 }
546 current_default_buf.clear ();
547 new_eeg_data.clear ();
548 for (size_t i = 0; i < current_aux_buf.size (); i++)
549 {
550 current_aux_buf[i].clear ();
551 }
552 current_aux_buf.clear ();

Callers

nothing calls this directly

Calls 2

stop_streamFunction · 0.50
sleepFunction · 0.50

Tested by

no test coverage detected