diff --git a/HISTORY.rst b/HISTORY.rst index 816960d..705d093 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,3 +1,16 @@ +v0.5.0 (2016-09-15) +=================== +- Using MetaWear-CppAPI version 0.5.22 +- Changed building procedure to handle ARM processors +- Updated requirements to make pygatt default, all others extras +- Bluepy backend implemented and partially working +- BL interface selection for all backends +- Magnetometer module +- Barometer module +- Ambient Light module +- Modifying notification wrappers to accommodate Epoch value in the data. +- High speed sampling for accelerometer and gyroscope + v0.4.4 (2016-04-28) =================== - Updated MetaWear-CppAPI submodule version. diff --git a/pymetawear/Metawear-CppAPI b/pymetawear/Metawear-CppAPI index 0b2a3ad..21b15b4 160000 --- a/pymetawear/Metawear-CppAPI +++ b/pymetawear/Metawear-CppAPI @@ -1 +1 @@ -Subproject commit 0b2a3ad4020475f3e9bf18820722853359caaab8 +Subproject commit 21b15b4d78ccdd1c0c9b23f53fdbe14d4340edc8 diff --git a/pymetawear/__init__.py b/pymetawear/__init__.py index 5ea7544..e9e5729 100644 --- a/pymetawear/__init__.py +++ b/pymetawear/__init__.py @@ -12,9 +12,9 @@ from pymetawear.utils import IS_64_BIT # Version information. -__version__ = '0.5.0a4' +__version__ = '0.5.0' version = __version__ # backwards compatibility name -version_info = (0, 5, 0, 'a4') +version_info = (0, 5, 0) if os.environ.get('METAWEAR_LIB_SO_NAME') is not None: libmetawear = cdll.LoadLibrary(os.environ["METAWEAR_LIB_SO_NAME"]) diff --git a/pymetawear/backends/__init__.py b/pymetawear/backends/__init__.py index 41ed0ca..9b33c7c 100644 --- a/pymetawear/backends/__init__.py +++ b/pymetawear/backends/__init__.py @@ -11,6 +11,7 @@ # from __future__ import unicode_literals from __future__ import absolute_import +import os import time from ctypes import byref import uuid @@ -25,14 +26,15 @@ class BLECommunicationBackend(object): - def __init__(self, address, interface=None, async=True, timeout=None, debug=False): + def __init__(self, address, interface=None, + async=True, timeout=None, debug=False): self._address = str(address) self._interface = str(interface) self._async = async self._debug = debug self._timeout = timeout - self._initialized = False + self._initialization_status = -1 self._requester = None @@ -62,6 +64,10 @@ def __init__(self, address, interface=None, async=True, timeout=None, debug=Fals # Now create a libmetawear board object and initialize it. self.board = libmetawear.mbl_mw_metawearboard_create( byref(self._btle_connection)) + + _response_time = os.environ.get('PYMETAWEAR_RESPONSE_TIME', 300) + libmetawear.mbl_mw_metawearboard_set_time_for_response(self.board, int(_response_time)) + libmetawear.mbl_mw_metawearboard_initialize( self.board, self.callbacks.get('initialization')[1]) @@ -76,7 +82,7 @@ def _build_handle_dict(self): @property def initialized(self): - return self._initialized + return self._initialization_status >= 0 @property def requester(self): @@ -153,7 +159,7 @@ def write_gatt_char_by_uuid(self, characteristic_uuid, data_to_send): def _initialized_fcn(self, board, status): if self._debug: print("{0} initialized with status {1}.".format(self, status)) - self._initialized = status == 0 + self._initialization_status = status def handle_notify_char_output(self, handle, value): if self._debug: diff --git a/pymetawear/backends/bluepy/__init__.py b/pymetawear/backends/bluepy/__init__.py index d000091..33a204a 100644 --- a/pymetawear/backends/bluepy/__init__.py +++ b/pymetawear/backends/bluepy/__init__.py @@ -74,7 +74,7 @@ def _is_connected(self): @property def initialized(self): #self.requester.waitForNotifications(0.1) - return self._initialized + return self._initialization_status @property def requester(self): diff --git a/pymetawear/client.py b/pymetawear/client.py index 6546312..f5b5d3d 100644 --- a/pymetawear/client.py +++ b/pymetawear/client.py @@ -21,6 +21,7 @@ from pymetawear import libmetawear, specs from pymetawear.exceptions import * from pymetawear import modules +from pymetawear.mbientlab.metawear.core import Status try: from pymetawear.backends.pygatt import PyGattBackend except ImportError as e: @@ -147,6 +148,15 @@ def __init__(self, address, backend='pygatt', libmetawear.mbl_mw_metawearboard_is_initialized(self.board)): self.backend.sleep(0.1) + # Check if initialization has been completed successfully. + if self.backend.initialized != Status.OK: + if self.backend._initialization_status == Status.ERROR_TIMEOUT: + raise PyMetaWearConnectionTimeout("libmetawear initialization status 16: Timeout") + else: + raise PyMetaWearException("libmetawear initialization status {0}".format( + self.backend._initialization_status)) + + # Read out firmware and model version. self.firmware_version = tuple( [int(x) for x in self.backend.read_gatt_char_by_uuid( specs.DEV_INFO_FIRMWARE_CHAR[1]).decode().split('.')]) @@ -185,7 +195,8 @@ def __init__(self, address, backend='pygatt', self.led = modules.LEDModule(self.board, debug=self._debug) def __str__(self): - return "MetaWearClient, {0}".format(self._address) + return "MetaWearClient, {0}, Model: {1}, Firmware: {2}.{3}.{4}".format( + self._address, self.model_version, *self.firmware_version) def __repr__(self): return "".format(self._address) diff --git a/pymetawear/modules/magnetometer.py b/pymetawear/modules/magnetometer.py index 7edff63..e34a2a2 100644 --- a/pymetawear/modules/magnetometer.py +++ b/pymetawear/modules/magnetometer.py @@ -28,7 +28,7 @@ def require_bmm150(f): def wrapper(*args, **kwargs): if getattr(args[0], 'mag_class', None) is None: raise PyMetaWearException("There is not Magnetometer " - "module of your MetaWear board!") + "module on your MetaWear board!") return f(*args, **kwargs) return wrapper diff --git a/setup.py b/setup.py index 6f6413b..9ab9873 100644 --- a/setup.py +++ b/setup.py @@ -45,7 +45,7 @@ def build_solution(): arch = os.uname()[-1] if arch in ('x86_64', 'amd64'): dist_dir = 'x64' - elif arch == 'armv7l': + elif 'arm' in arch: dist_dir = 'arm' else: dist_dir = 'x86' @@ -65,17 +65,6 @@ def build_solution(): cwd=basedir, stdout=sys.stdout, stderr=sys.stderr) p.communicate() - # Increase TIME_PER_COMMAND in MetaWear-CppAPI by pre-build - # patching of constants.h. - constants_h_file = os.path.join( - pkg_dir, 'Metawear-CppAPI', 'src', 'metawear', - 'core', 'cpp', 'constant.h') - with open(constants_h_file, 'rt') as f: - t = f.read() - t = t.replace('TIME_PER_COMMAND = 150', 'TIME_PER_COMMAND = 300') - with open(constants_h_file, 'wt') as f: - f.write(t) - # Run make file for MetaWear-CppAPI p = subprocess.Popen( ['make', 'clean'], @@ -167,7 +156,8 @@ def read(f): 'build_py': PyMetaWearBuilder, 'develop': PyMetaWearDeveloper }, - packages=find_packages(exclude=['tests', 'docs', 'examples']), + packages=find_packages(exclude=['tests', 'docs', 'examples', 'examples.*']), + include_package_data=True, # Adding MbientLab's Python code as package data since it is copied # to folder after ``find_packages`` is run. package_data={