def _start_muse(self, duration): if sys.platform in ["linux", "linux2", "darwin"]: # Look for muses self.muses = list_muses() # self.muse = muses[0] # Start streaming process self.stream_process = Process(target=stream, args=(self.muses[0]["address"], )) self.stream_process.start() # Create markers stream outlet self.muse_StreamInfo = StreamInfo("Markers", "Markers", 1, 0, "int32", "myuidw43536") self.muse_StreamOutlet = StreamOutlet(self.muse_StreamInfo) # Start a background process that will stream data from the first available Muse print("starting background recording process") print("will save to file: %s" % self.save_fn) self.recording = Process(target=record, args=(duration, self.save_fn)) self.recording.start() time.sleep(5) self.push_sample([99], timestamp=time.time())
def main(address: Optional[str] = None): if address is None: muses = list_muses() assert muses address = muses[0]["address"] s = Thread(target=_stream, args=(address, )) s.start()
def connect_muse(): print( "\n" + r"If using Windows, install Bluemuse from https://github.com/kowalej/BlueMuse" ) muses = list_muses() #on Windows, you need to use Bluemuse if sys.platform.startswith("darwin") or sys.platform.startswith( "linux"): #on linux and mac, use muselsl to start the stream stream_process = Process(target=stream, args=(muses[0]['address'], )) stream_process.start()
def start_stream(address, sources, confirm=True, restart=False): """Return True to indicate success, else False""" if restart is True: end_stream() if len(stream_data["args"]) == 2: (address, sources) = stream_data["args"] if address is None: logger.info("No address provided, searching for muses...") muses = list_muses() if not muses or len(muses) == 0: logger.error("No muses found, quitting.") exit(1) address = muses[0]["address"] logger.debug(f"Found muse with address {address}.") stream_data["args"] = (address, sources) kwargs = { "acc_enabled": SOURCE_ACC in sources, "eeg_disabled": SOURCE_EEG not in sources, "gyro_enabled": SOURCE_GYRO in sources, "ppg_enabled": SOURCE_PPG in sources, } keep_trying = True while keep_trying: logger.info(f"Establishing stream to {address}...") attempt = 0 while attempt < ATTEMPTS_MAX: attempt += 1 logger.info(f"Beginning stream attempt {attempt}...") stream_process = Process(target=stream, args=(address, ), kwargs=kwargs) stream_process.daemon = True stream_process.start() stream_process.join(7) if not stream_process.is_alive(): logger.warning(f"Streaming attempt {attempt} failed.") continue logger.info("Stream established!") stream_data["process"] = stream_process return True logger.error(f"Could not establish stream after {attempt} attempts.") if not confirm: continue keep_trying = str.lower(input("Keep trying? (y/N) ")) in ["y", "yes"] return False
def start(self, filename: str = None, duration=None, extras: dict = None): """ Starts the EEG device. Parameters: filename (str): name of the file to save the sessions data to. """ sources = ["EEG"] # + ["PPG", "ACC", "GYRO"] if not duration: duration = 300 if extras: for source in ["PPG", "ACC", "GYRO"]: if extras.get(source, False): sources += [source] # Not sure why we only do this on *nix # Makes it seem like streaming is only supported on *nix? if not self.started and sys.platform in ["linux", "linux2", "darwin"]: # Look for muses muses = muselsl.list_muses(backend=BACKEND) # FIXME: fix upstream muses = [m for m in muses if m["name"].startswith("Muse")] if not muses: raise Exception("No Muses found") # self.muse = muses[0] # Start streaming process # daemon=False to ensure orderly shutdown/disconnection stream_process = Process( target=stream, args=(muses[0]["address"], sources), daemon=False ) stream_process.start() self.stream_process = stream_process # Create markers stream outlet self.marker_outlet = pylsl.StreamOutlet( pylsl.StreamInfo("Markers", "Markers", 1, 0, "int32", "myuidw43536") ) self.record(sources, duration, filename) # FIXME: What's the purpose of this? (Push sample indicating recording start?) self.push_sample([99], timestamp=time())
def __init__(self): from muselsl import stream, list_muses from pylsl import StreamInlet, resolve_byprop muses = list_muses() # stream module connects with Muse, but doesn't start streaming data self.muse_ble_connect = multiprocessing.Process( target=stream, args=(muses[0]["address"], )) self.muse_ble_connect.start() time.sleep(10) self.streams = resolve_byprop("type", "EEG", timeout=2) self.inlet = StreamInlet(self.streams[0], max_chunklen=1) Helmet.__init__(self) self.channels_number = 4 self.sampling_rate = 256
def _start_muse(self, duration): if sys.platform in ["linux", "linux2", "darwin"]: # Look for muses muses = list_muses() #self.muse = muses[0] # Start streaming process self.stream_process = Process(target=stream, args=(self.muses[0]['address'], )) self.stream_process.start() # Create markers stream outlet self.muse_StreamInfo = StreamInfo('Markers', 'Markers', 1, 0, 'int32', 'myuidw43536') self.muse_StreamOutlet = StreamOutlet(self.muse_StreamInfo) # Start a background process that will stream data from the first available Muse print("starting background recording process") print('will save to file: %s' % self.save_fn) self.recording = Process(target=record, args=(duration, self.save_fn)) self.recording.start()
""" Starting a Stream This example shows how to search for available Muses and create a new stream """ from muselsl import stream, list_muses if __name__ == "__main__": muses = list_muses() stream('00:55:da:b3:d8:4c') if not muses: print('No Muses found') else: print("found muse ", muses[0]['address']) stream(muses[0]['address']) # Note: Streaming is synchronous, so code here will not execute until the stream has been closed print('Stream has ended')
def listmuses(): return {'muses': list_muses()}
def update_devlist(self): muses = list_muses() self.devices = [] for muse in muses: self.devices.append( Device(name=muse['name'], address=muse['address']))