Skip to content

Commit

Permalink
if using 'muse' within another package, use 'logger' so that messages…
Browse files Browse the repository at this point in the history
… can be redirected to appropriate output stream (#198)

changing default logging stream to stdout to match current behavior of `print` statements
  • Loading branch information
ajmirsky committed Apr 22, 2024
1 parent f899ba3 commit ae5f090
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions muselsl/muse.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import logging
import sys

import bitstring
import pygatt
import numpy as np
Expand All @@ -8,6 +11,9 @@
from . import helper
from .constants import *

logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
logger = logging.getLogger(__name__)


class Muse():
"""Muse 2016 headband"""
Expand Down Expand Up @@ -64,11 +70,11 @@ def connect(self, interface=None):
"""Connect to the device"""
try:
if self.backend == 'bluemuse':
print('Starting BlueMuse.')
logger.info('Starting BlueMuse.')
subprocess.call('start bluemuse:', shell=True)
self.last_timestamp = self.time_func()
else:
print('Connecting to %s: %s...' % (self.name
logger.info('Connecting to %s: %s...' % (self.name
if self.name else 'Muse',
self.address))
if self.backend == 'gatt':
Expand Down Expand Up @@ -145,7 +151,7 @@ def connect(self, interface=None):
return True

else:
print('Connection to', self.address, 'failed')
logger.error('Connection to', self.address, 'failed')
return False

def _write_cmd(self, cmd):
Expand Down Expand Up @@ -260,7 +266,7 @@ def select_preset(self, preset=21):
if preset[0] == 'p':
preset = preset[1:]
if str(preset) != '21':
print('Sending command for non-default preset: p' + preset)
logger.debug('Sending command for non-default preset: p' + preset)
preset = bytes(preset, 'utf-8')
self._write_cmd([0x04, 0x70, *preset, 0x0a])

Expand Down Expand Up @@ -368,7 +374,7 @@ def _handle_eeg(self, handle, data):
if handle == 35:
if tm != self.last_tm + 1:
if (tm - self.last_tm) != -65535: # counter reset
print("missing sample %d : %d" % (tm, self.last_tm))
logger.debug("missing sample %d : %d" % (tm, self.last_tm))
# correct sample index for timestamp estimation
self.sample_index += 12 * (tm - self.last_tm + 1)

Expand Down Expand Up @@ -564,7 +570,7 @@ def _handle_ppg(self, handle, data):
# last data received
if handle == 62:
if tm != self.last_tm_ppg + 1:
print("missing sample %d : %d" % (tm, self.last_tm_ppg))
logger.debug("missing sample %d : %d" % (tm, self.last_tm_ppg))
self.last_tm_ppg = tm

# calculate index of time samples
Expand Down

0 comments on commit ae5f090

Please sign in to comment.