Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/garrettmflynn/brainsatplay.py
Stream data to Brains@Play over Python
https://github.com/garrettmflynn/brainsatplay.py
Last synced: about 1 month ago
JSON representation
Stream data to Brains@Play over Python
- Host: GitHub
- URL: https://github.com/garrettmflynn/brainsatplay.py
- Owner: garrettmflynn
- License: gpl-3.0
- Created: 2021-11-03T20:46:01.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-02-21T16:53:35.000Z (almost 3 years ago)
- Last Synced: 2024-04-23T23:44:54.859Z (8 months ago)
- Language: Python
- Size: 32.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# brainsatplay.py
A Python library for interfacing with Brains@Play> Warning: Not well tested...
* [Installation](#Installation)
* [Support](#Support)## Installation
```bash
pip install brainsatplay
```## Example (with Brainflow)
``` python
import brainsatplay
import time
import math
from brainflow.board_shim import BoardShim, BrainFlowInputParams, LogLevels, BoardIds
from brainflow.data_filter import DataFilter, FilterTypes
import sys, signaldef main():
'''
Connect to the Brainstorm
'''
# Authentication
username = 'guest'
password = ''## Set Connection Details
brainstorm = brainsatplay.Brainstorm('http://localhost','80') # URL, Port## Connect
res = brainstorm.connect(username,password) # All optional (defaults to guest)'''
Subscribe to a Particular Game
'''
# # Connection Settings
appname = 'brainstorm'
devices = []
props = ['raw','times','sps','deviceType','format','eegChannelTags']
sessionid = None
spectating = False # Spectate to view data without sending itres = brainstorm.getSessions(appname)
if res['msg'] != 'appNotFound':
sessionid = res['sessions'][0]['id']
else:
res = brainstorm.createSession(appname, devices, props)
sessionid = res['sessionInfo']['id']# Handle Data from Subscribed Games
def newData(json):
for user in json['userData']:
name = user['username']
print('Data for {}'.format(name))
res = brainstorm.subscribeToSession(sessionid,spectating, newData)
'''
Stream your Data
'''# Setup Brainflow
params = BrainFlowInputParams()
board_id = BoardIds['SYNTHETIC_BOARD'].value
board = BoardShim(board_id, params)
board.rate = BoardShim.get_sampling_rate(board_id)
board.channels = BoardShim.get_eeg_channels(board_id)
board.time_channel = BoardShim.get_timestamp_channel(board_id)
board.eeg_channels = BoardShim.get_eeg_channels(board_id)
board.eeg_names = BoardShim.get_eeg_names(board_id)
board.prepare_session()
board.start_stream(num_samples=450000)# Handle CTRL-C Exit
def onStop():
board.stop_stream()
board.release_session()loopCount = 0
# Start Stream Loop
def streamLoop():
pass_data = []
rate = DataFilter.get_nearest_power_of_two(board.rate)
data = board.get_board_data()
t = data[board.time_channel]data = data[board.eeg_channels]
for entry in data:
pass_data.append((entry).tolist())
data = {}
data['raw'] = pass_data
data['times'] = t.tolist()# Send Metadata on First Loop
if loopCount == 0:
data['sps'] = board.rate
data['deviceType'] = 'eeg'
data['format'] = 'brainflow'
tags = []
for i, channel in enumerate(board.eeg_channels):
tags.append({'ch': channel-1, 'tag': board.eeg_names[i], 'analyze':True})data['eegChannelTags'] = tags
return datares = brainstorm.startStream(streamLoop, onStop)
if __name__ == "__main__":
main()
```## Support
If you are having issues, please email Garrett Flynn at [email protected]