diff --git a/muselsl/muse.py b/muselsl/muse.py index 448b23f..a7fea4c 100644 --- a/muselsl/muse.py +++ b/muselsl/muse.py @@ -1,3 +1,6 @@ +import logging +import sys + import bitstring import pygatt import numpy as np @@ -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""" @@ -66,11 +72,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, timing out after %s seconds...' % (self.name + logger.info('Connecting to %s: %s...' % (self.name if self.name else 'Muse', self.address, int(self.timeout))) if self.backend == 'gatt': @@ -147,7 +153,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): @@ -262,7 +268,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]) @@ -370,7 +376,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) @@ -566,7 +572,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