Skip to content

Commit 67d08c7

Browse files
authored
fixing connection issues with ganglion native and brainalive (#644)
Signed-off-by: Andrey Parfenov <a1994ndrey@gmail.com>
1 parent 289d287 commit 67d08c7

File tree

2 files changed

+37
-14
lines changed

2 files changed

+37
-14
lines changed

src/board_controller/brainalive/brainalive.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,26 @@ int BrainAlive::prepare_session ()
105105
simpleble_adapter_scan_stop (brainalive_adapter);
106106
if (res == (int)BrainFlowExitCodes::STATUS_OK)
107107
{
108-
if (simpleble_peripheral_connect (brainalive_peripheral) == SIMPLEBLE_SUCCESS)
108+
// for safety
109+
for (int i = 0; i < 3; i++)
109110
{
110-
safe_logger (spdlog::level::info, "Connected to BrainAlive Device");
111-
}
112-
else
113-
{
114-
safe_logger (spdlog::level::err, "Failed to connect to BrainAlive Device");
115-
res = (int)BrainFlowExitCodes::BOARD_NOT_READY_ERROR;
111+
if (simpleble_peripheral_connect (brainalive_peripheral) == SIMPLEBLE_SUCCESS)
112+
{
113+
safe_logger (spdlog::level::info, "Connected to BrainAlive Device");
114+
res = (int)BrainFlowExitCodes::STATUS_OK;
115+
break;
116+
}
117+
else
118+
{
119+
safe_logger (
120+
spdlog::level::warn, "Failed to connect to BrainAlive Device: {}/3", i);
121+
res = (int)BrainFlowExitCodes::BOARD_NOT_READY_ERROR;
122+
#ifdef _WIN32
123+
Sleep (1000);
124+
#else
125+
sleep (1);
126+
#endif
127+
}
116128
}
117129
}
118130
else

src/board_controller/openbci/ganglion_native.cpp

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,25 @@ int GanglionNative::prepare_session ()
117117
simpleble_adapter_scan_stop (ganglion_adapter);
118118
if (res == (int)BrainFlowExitCodes::STATUS_OK)
119119
{
120-
if (simpleble_peripheral_connect (ganglion_peripheral) == SIMPLEBLE_SUCCESS)
120+
// for safety
121+
for (int i = 0; i < 3; i++)
121122
{
122-
safe_logger (spdlog::level::info, "Connected to GanglionNative Device");
123-
}
124-
else
125-
{
126-
safe_logger (spdlog::level::err, "Failed to connect to GanglionNative Device");
127-
res = (int)BrainFlowExitCodes::BOARD_NOT_READY_ERROR;
123+
if (simpleble_peripheral_connect (ganglion_peripheral) == SIMPLEBLE_SUCCESS)
124+
{
125+
safe_logger (spdlog::level::info, "Connected to Ganglion Device");
126+
res = (int)BrainFlowExitCodes::STATUS_OK;
127+
break;
128+
}
129+
else
130+
{
131+
safe_logger (spdlog::level::warn, "Failed to connect to Ganglion Device: {}/3", i);
132+
res = (int)BrainFlowExitCodes::BOARD_NOT_READY_ERROR;
133+
#ifdef _WIN32
134+
Sleep (1000);
135+
#else
136+
sleep (1);
137+
#endif
138+
}
128139
}
129140
}
130141
else

0 commit comments

Comments
 (0)