Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with logging fixed. #215

Closed
Closed
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
2 changes: 2 additions & 0 deletions muselsl/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def main():
-n --name Device name (e.g. Muse-41D2).
-b --backend BLE backend to use. can be auto, bluemuse, gatt or bgapi.
-i --interface The interface to use, 'hci0' for gatt or a com port for bgapi.
-t --timeout Length of timeout before giving up on connecting to an identified device.
-p --ppg Include PPG data
-c --acc Include accelerometer data
-g --gyro Include gyroscope data
Expand All @@ -41,6 +42,7 @@ def main():
-n --name Device name (e.g. Muse-41D2).
-b --backend BLE backend to use. can be auto, bluemuse, gatt or bgapi.
-i --interface The interface to use, 'hci0' for gatt or a com port for bgapi.
-t --timeout Length of timeout before giving up on connecting to an identified device.
''')

parser.add_argument('command', help='Command to run.')
Expand Down
9 changes: 5 additions & 4 deletions muselsl/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@ def scan(self, timeout=10):
raise bleak
devices = _wait(bleak.BleakScanner.discover(timeout))
return [{'name':device.name, 'address':device.address} for device in devices]
def connect(self, address):
result = BleakDevice(self, address)
def connect(self, address, connection_timeout=None):
result = BleakDevice(self, address, connection_timeout)
result.connect()
return result

class BleakDevice:
def __init__(self, adapter, address):
def __init__(self, adapter, address, connection_timeout=None):
self._adapter = adapter
self._client = bleak.BleakClient(address)
self._timeout = connection_timeout
self._client = bleak.BleakClient(address, timeout=self._timeout)
def connect(self):
_wait(self._client.connect())
self._adapter.connected.add(self)
Expand Down
18 changes: 16 additions & 2 deletions muselsl/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ def stream(self):
default=None,
help=
"The interface to use, 'hci0' for gatt or a com port for bgapi.")
parser.add_argument(
"-t",
"--timeout",
dest="timeout",
type=float,
default=10.0,
help="Length of timeout before giving up on connecting to an identified device.")
parser.add_argument("-P",
"--preset",
type=int,
Expand Down Expand Up @@ -104,7 +111,7 @@ def stream(self):
from . import stream

stream(args.address, args.backend, args.interface, args.name, args.ppg,
args.acc, args.gyro, args.disable_eeg, args.preset, args.disable_light)
args.acc, args.gyro, args.disable_eeg, args.preset, args.disable_light, args.timeout)

def record(self):
parser = argparse.ArgumentParser(
Expand Down Expand Up @@ -173,6 +180,13 @@ def record_direct(self):
default=None,
help=
"The interface to use, 'hci0' for gatt or a com port for bgapi.")
parser.add_argument(
"-t",
"--timeout",
dest="timeout",
type=float,
default=10.0,
help="Length of timeout before giving up on connecting to an identified device.")
parser.add_argument(
"-d",
"--duration",
Expand All @@ -190,7 +204,7 @@ def record_direct(self):
args = parser.parse_args(sys.argv[2:])
from . import record_direct
record_direct(args.duration, args.address, args.filename, args.backend,
args.interface, args.name)
args.interface, args.name, args.timeout)

def view(self):
parser = argparse.ArgumentParser(
Expand Down
6 changes: 4 additions & 2 deletions muselsl/muse.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def __init__(self,
time_func=time,
name=None,
preset=None,
disable_light=False):
disable_light=False,
timeout=None):
"""Initialize

callback_eeg -- callback for eeg data, function(data, timestamps)
Expand All @@ -45,6 +46,7 @@ def __init__(self,
"""

self.address = address
self.timeout=timeout
self.name = name
self.callback_eeg = callback_eeg
self.callback_telemetry = callback_telemetry
Expand Down Expand Up @@ -87,7 +89,7 @@ def connect(self, interface=None):
serial_port=self.interface)

self.adapter.start()
self.device = self.adapter.connect(self.address)
self.device = self.adapter.connect(self.address, self.timeout)
if(self.preset != None):
self.select_preset(self.preset)

Expand Down
5 changes: 3 additions & 2 deletions muselsl/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ def record_direct(duration,
filename=None,
backend='auto',
interface=None,
name=None):
name=None,
timeout=None):
if backend == 'bluemuse':
raise (NotImplementedError(
'Direct record not supported with BlueMuse backend. Use record after starting stream instead.'
Expand Down Expand Up @@ -211,7 +212,7 @@ def save_eeg(new_samples, new_timestamps):
eeg_samples.append(new_samples)
timestamps.append(new_timestamps)

muse = Muse(address, save_eeg, backend=backend)
muse = Muse(address, save_eeg, backend=backend, timeout=timeout)
muse.connect()
muse.start()

Expand Down
6 changes: 3 additions & 3 deletions muselsl/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def stream(
eeg_disabled=False,
preset=None,
disable_light=False,
timeout=AUTO_DISCONNECT_DELAY,
timeout=None,
):
# If no data types are enabled, we warn the user and return immediately.
if eeg_disabled and not ppg_enabled and not acc_enabled and not gyro_enabled:
Expand Down Expand Up @@ -216,7 +216,7 @@ def push(data, timestamps, outlet):
push_gyro = partial(push, outlet=gyro_outlet) if gyro_enabled else None

muse = Muse(address=address, callback_eeg=push_eeg, callback_ppg=push_ppg, callback_acc=push_acc, callback_gyro=push_gyro,
backend=backend, interface=interface, name=name, preset=preset, disable_light=disable_light)
backend=backend, interface=interface, name=name, preset=preset, disable_light=disable_light, timeout=timeout)

didConnect = muse.connect()

Expand All @@ -232,7 +232,7 @@ def push(data, timestamps, outlet):
print("Streaming%s%s%s%s..." %
(eeg_string, ppg_string, acc_string, gyro_string))

while time() - muse.last_timestamp < timeout:
while time() - muse.last_timestamp < AUTO_DISCONNECT_DELAY:
try:
backends.sleep(1)
except KeyboardInterrupt:
Expand Down
Loading