Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions muselsl/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def _save(
data = pd.DataFrame(data=res, columns=["timestamps"] + ch_names)

directory = os.path.dirname(filename)
if not os.path.exists(directory):
if directory and not os.path.exists(directory):
os.makedirs(directory)

if inlet_marker and markers:
Expand Down Expand Up @@ -263,7 +263,7 @@ def save_eeg(new_samples, new_timestamps):
recording['timestamps'] = timestamps

directory = os.path.dirname(filename)
if not os.path.exists(directory):
if directory and not os.path.exists(directory):
os.makedirs(directory)

recording.to_csv(filename, float_format='%.3f')
Expand Down
33 changes: 23 additions & 10 deletions muselsl/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,20 @@ def _list_muses_bluetoothctl(timeout, verbose=False):
scan = pexpect.spawn('bluetoothctl scan on')
try:
scan.expect('foooooo', timeout=timeout)
except pexpect.EOF:
before_eof = scan.before.decode('utf-8', 'replace')
msg = f'Unexpected error when scanning: {before_eof}'
raise ValueError(msg)
except pexpect.TIMEOUT:
except (pexpect.EOF, pexpect.TIMEOUT):
# Both EOF and TIMEOUT are expected - the scan completed normally
if verbose:
print(scan.before.decode('utf-8', 'replace').split('\r\n'))
try:
output = scan.before.decode('utf-8', 'replace')
print(output.split('\r\n'))
except:
pass

# Terminate the scan process if still running
try:
scan.terminate(force=True)
except:
pass

# List devices using bluetoothctl
list_devices_cmd = ['bluetoothctl', 'devices']
Expand Down Expand Up @@ -154,8 +161,14 @@ def stream(
address = found_muse['address']
name = found_muse['name']

# Determine LSL stream name: use --name parameter if provided, otherwise default to 'Muse'
# This allows multiple devices to have unique stream names (e.g., "Muse_1", "Muse_2")
stream_name = name if name else 'Muse'

print(f"Creating LSL streams with name: '{stream_name}'")

if not eeg_disabled:
eeg_info = StreamInfo('Muse', 'EEG', MUSE_NB_EEG_CHANNELS, MUSE_SAMPLING_EEG_RATE, 'float32',
eeg_info = StreamInfo(stream_name, 'EEG', MUSE_NB_EEG_CHANNELS, MUSE_SAMPLING_EEG_RATE, 'float32',
'Muse%s' % address)
eeg_info.desc().append_child_value("manufacturer", "Muse")
eeg_channels = eeg_info.desc().append_child("channels")
Expand All @@ -169,7 +182,7 @@ def stream(
eeg_outlet = StreamOutlet(eeg_info, LSL_EEG_CHUNK)

if ppg_enabled:
ppg_info = StreamInfo('Muse', 'PPG', MUSE_NB_PPG_CHANNELS, MUSE_SAMPLING_PPG_RATE,
ppg_info = StreamInfo(stream_name, 'PPG', MUSE_NB_PPG_CHANNELS, MUSE_SAMPLING_PPG_RATE,
'float32', 'Muse%s' % address)
ppg_info.desc().append_child_value("manufacturer", "Muse")
ppg_channels = ppg_info.desc().append_child("channels")
Expand All @@ -183,7 +196,7 @@ def stream(
ppg_outlet = StreamOutlet(ppg_info, LSL_PPG_CHUNK)

if acc_enabled:
acc_info = StreamInfo('Muse', 'ACC', MUSE_NB_ACC_CHANNELS, MUSE_SAMPLING_ACC_RATE,
acc_info = StreamInfo(stream_name, 'ACC', MUSE_NB_ACC_CHANNELS, MUSE_SAMPLING_ACC_RATE,
'float32', 'Muse%s' % address)
acc_info.desc().append_child_value("manufacturer", "Muse")
acc_channels = acc_info.desc().append_child("channels")
Expand All @@ -197,7 +210,7 @@ def stream(
acc_outlet = StreamOutlet(acc_info, LSL_ACC_CHUNK)

if gyro_enabled:
gyro_info = StreamInfo('Muse', 'GYRO', MUSE_NB_GYRO_CHANNELS, MUSE_SAMPLING_GYRO_RATE,
gyro_info = StreamInfo(stream_name, 'GYRO', MUSE_NB_GYRO_CHANNELS, MUSE_SAMPLING_GYRO_RATE,
'float32', 'Muse%s' % address)
gyro_info.desc().append_child_value("manufacturer", "Muse")
gyro_channels = gyro_info.desc().append_child("channels")
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def copy_docs():
"numpy",
"seaborn",
"pexpect",
] +
(["pylsl==1.10.5"] if os.sys.platform.startswith("linux") else ["pylsl"]),
"pylsl>=1.16.2", # Updated for compatibility with modern LSL features
],
extras_require={"Viewer V2": ["mne", "vispy"]},
classifiers=[
# How mature is this project? Common values are
Expand Down