| 254 | } |
| 255 | |
| 256 | int get_data (void *param) |
| 257 | { |
| 258 | if (!initialized) |
| 259 | { |
| 260 | return (int)BrainFlowExitCodes::BOARD_NOT_CREATED_ERROR; |
| 261 | } |
| 262 | if (should_stop_stream) |
| 263 | { |
| 264 | return (int)BrainFlowExitCodes::EMPTY_BUFFER_ERROR; |
| 265 | } |
| 266 | state = State::GET_DATA_CALLED; |
| 267 | int res = (int)BrainFlowExitCodes::STATUS_OK; |
| 268 | lock.lock (); |
| 269 | if (data_queue.empty ()) |
| 270 | { |
| 271 | res = (int)BrainFlowExitCodes::EMPTY_BUFFER_ERROR; |
| 272 | } |
| 273 | else |
| 274 | { |
| 275 | try |
| 276 | { |
| 277 | double *board_data = (double *)param; |
| 278 | std::array<double, BRAINBIT_BLED_DATA_SIZE> data = data_queue.at ( |
| 279 | 0); // at ensures out of range exception, front has undefined behavior |
| 280 | for (int i = 0; i < BRAINBIT_BLED_DATA_SIZE; i++) |
| 281 | { |
| 282 | board_data[i] = data[i]; |
| 283 | } |
| 284 | data_queue.pop_front (); |
| 285 | } |
| 286 | catch (...) |
| 287 | { |
| 288 | res = (int)BrainFlowExitCodes::EMPTY_BUFFER_ERROR; |
| 289 | } |
| 290 | } |
| 291 | lock.unlock (); |
| 292 | return res; |
| 293 | } |
| 294 | |
| 295 | int release (void *param) |
| 296 | { |